using Autofac;
using Bro.Common.Base;
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.Common.Model;
using Bro.Device.AuboRobot;
using Bro.Device.SeerAGV;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace A032.Process
{
public enum TaskState
{
///
/// 新任务
///
New = 0,
///
/// 任务完成
///
Done = 1,
///
/// 任务失败
///
Failed = 2,
///
/// 任务已添加队列,等待执行
///
Queueing = 3,
///
/// 任务已指派
///
Assigned = 4,
///
/// 任务未指派,已取消
///
Cancelled = 5,
}
public enum AGVState
{
///
/// AGV状态不可知
///
Unknown = 0,
///
/// 空闲状态,可接收任务
///
Idle = 1,
///
/// 任务执行中
///
Running = 2,
///
/// 报警中,不可执行任务
///
Warning = 3,
///
/// 充电中,不可执行任务
///
InCharge = 4,
///
/// 空闲充电状态,可接收任务
///
IdleCharge = 5,
}
//public class AGVTaskModel
//{
// public TaskAvailableLevel Level { get; set; } = TaskAvailableLevel.Robot;
// public string MethodName { get; set; }
// public IOperationConfig OpConfig { get; set; }
// public IDevice Device { get; set; }
// //public int Priority { get; set; } = 10;
// public AGVTaskModel() { }
// public AGVTaskModel(TaskAvailableLevel level, string methodName, IOperationConfig opConfig = null, IDevice device = null)
// {
// Level = level;
// MethodName = methodName;
// OpConfig = opConfig ?? new OperationConfigBase();
// Device = device;
// }
//}
public class AGVBindUnit : IComplexDisplay
{
#region 可编辑项目
[Category("设备绑定")]
[Description("绑定Id")]
[Browsable(false)]
public string Id { get; set; } = Guid.NewGuid().ToString();
[Category("设备绑定")]
[Description("绑定AGV")]
[TypeConverter(typeof(AGVDeviceConverter))]
public string AGVId { get; set; }
[Category("设备绑定")]
[Description("绑定Robot")]
[TypeConverter(typeof(RobotDeviceConverter))]
public string RobotId { get; set; }
[Category("设备绑定")]
[Description("绑定Camera")]
[TypeConverter(typeof(CameraDeviceConverter))]
public string CameraId { get; set; }
public string GetDisplayText()
{
using (var scope = GlobalVar.Container.BeginLifetimeScope())
{
ProcessConfig config = scope.Resolve();
string agv = config.AGVConfigCollection.FirstOrDefault(u => u.ID == AGVId)?.Name ?? "未绑定AGV";
string robot = config.RobotConfigCollection.FirstOrDefault(u => u.ID == RobotId)?.Name ?? "未绑定机器人";
string camera = config.CameraConfigCollection.FirstOrDefault(u => u.ID == CameraId)?.Name ?? "未绑定相机";
return agv + "-" + robot + "-" + camera;
}
}
#endregion
#region 后台属性
#region 状态
private AGVState unitState = AGVState.Idle;
[Browsable(false)]
[JsonIgnore]
public AGVState UnitState
{
get => unitState;
set
{
if (value != unitState)
{
var preState = unitState;
unitState = value;
OnUnitStateChanged?.Invoke(this.Id, preState, unitState);
}
}
}
[Browsable(false)]
[JsonIgnore]
public List WarningMsg { get; set; } = new List();
#endregion
#region 设备
[Browsable(false)]
[JsonIgnore]
public SeerAGVDriver AGV { get; set; } = null;
[Browsable(false)]
[JsonIgnore]
public AuboRobotDriver Robot { get; set; } = null;
[Browsable(false)]
[JsonIgnore]
public CameraBase Camera { get; set; } = null;
#endregion
#region 任务信息
[JsonIgnore]
[Browsable(false)]
public string CurrentTaskId { get; set; }
[JsonIgnore]
[Browsable(false)]
public bool IsTaskCancelled { get; set; } = false;
[JsonIgnore]
[Browsable(false)]
public bool IsTaskCancelling { get; set; } = false;
#endregion
#region 事件
[JsonIgnore]
[Browsable(false)]
public Action OnUnitStateChanged { get; set; }
#endregion
#region 托盘信息
[JsonIgnore]
[Browsable(false)]
public int FullTrayNum { get; set; }
[JsonIgnore]
[Browsable(false)]
public int EmptyTrayNum { get; set; }
#endregion
#endregion
public AGVBindUnit()
{
}
public void Reset()
{
WarningMsg.Clear();
UnitState = AGVState.Idle;
AGV.ResetAlarm();
Robot.ResetAlarm();
}
}
public class AGVDeviceConverter : ComboBoxItemTypeConvert
{
public override void GetConvertHash()
{
using (var scope = GlobalVar.Container.BeginLifetimeScope())
{
ProcessConfig config = scope.Resolve();
config.AGVConfigCollection.ForEach(plc =>
{
_hash[plc.ID] = plc.Name;
});
}
}
}
public class RobotDeviceConverter : ComboBoxItemTypeConvert
{
public override void GetConvertHash()
{
using (var scope = GlobalVar.Container.BeginLifetimeScope())
{
ProcessConfig config = scope.Resolve();
config.RobotConfigCollection.ForEach(robot =>
{
_hash[robot.ID] = robot.Name;
});
}
}
}
public class CameraDeviceConverter : ComboBoxItemTypeConvert
{
public override void GetConvertHash()
{
using (var scope = GlobalVar.Container.BeginLifetimeScope())
{
ProcessConfig config = scope.Resolve();
config.CameraConfigCollection.ForEach(camera =>
{
_hash[camera.ID] = camera.Name;
});
}
}
}
public class PLCDeviceConverter : ComboBoxItemTypeConvert
{
public override void GetConvertHash()
{
using (var scope = GlobalVar.Container.BeginLifetimeScope())
{
_hash[""] = "未指定";
ProcessConfig config = scope.Resolve();
config.PLCConfigCollection.ForEach(plc =>
{
_hash[plc.ID] = plc.Name;
});
}
}
}
public class AllDeviceIdConverter : ComboBoxItemTypeConvert
{
public override void GetConvertHash()
{
using (var scope = GlobalVar.Container.BeginLifetimeScope())
{
_hash[""] = "未指定";
List deviceList = scope.Resolve>();
deviceList.ForEach(d =>
{
_hash[d.Id] = d.Name;
});
}
}
}
public class AllDeviceNameConverter : ComboBoxItemTypeConvert
{
public override void GetConvertHash()
{
using (var scope = GlobalVar.Container.BeginLifetimeScope())
{
_hash[""] = "未指定";
List deviceList = scope.Resolve>();
deviceList.ForEach(d =>
{
_hash[d.Name] = d.Name;
});
}
}
}
}