| | |
| | | using Bro.Common.Helper; |
| | | using Autofac; |
| | | using Bro.Common.Helper; |
| | | using Bro.Common.Interface; |
| | | using Bro.Common.Model; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.ComponentModel.Design; |
| | | using System.Drawing.Design; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | |
| | | namespace Bro.Common.Base |
| | | { |
| | |
| | | public abstract ResponseMessage MoveToPoint(IOperationConfig opConfig); |
| | | public abstract void ResetAlarm(); |
| | | public abstract ResponseMessage Run(IOperationConfig config); |
| | | |
| | | public void ExcuteMonitorInvok(DateTime dateTime, string invokeDevice, IDevice device, IMonitorSet monitorSet, AsyncCallback OnMethodInvoked) |
| | | { |
| | | OnMonitorInvoke?.BeginInvoke(dateTime, invokeDevice, device, monitorSet, OnMethodInvoked, null); |
| | | } |
| | | |
| | | public void ExcuteMonitorAlarm(DateTime dateTime, IDevice device, IWarningSet warningSet) |
| | | { |
| | | OnMonitorAlarm?.BeginInvoke(dateTime, device, warningSet, null, null); |
| | | } |
| | | |
| | | public virtual MotionCardInitialConfigBase IConfig |
| | | { |
| | | get |
| | | { |
| | | return InitialConfig as MotionCardInitialConfigBase; |
| | | } |
| | | } |
| | | } |
| | | |
| | | public class MotionCardInitialConfigBase : InitialConfigBase, IMonitorConfig |
| | |
| | | public class MotionCardOperationConfigBase : OperationConfigBase, IComplexDisplay |
| | | { |
| | | [Category("IO操作配置")] |
| | | [DisplayName("IO预检查定义集合")] |
| | | [Description("IO预检查定义集合")] |
| | | [TypeConverter(typeof(CollectionCountConvert))] |
| | | [Editor(typeof(IORefrenceItemCollectionEditor),typeof(UITypeEditor))] |
| | | [Editor(typeof(IORefrenceItemCollectionEditor), typeof(UITypeEditor))] |
| | | public List<IORefrenceItem> PreCheckIOCollection { get; set; } = new List<IORefrenceItem>(); |
| | | [Category("IO操作配置")] |
| | | [Description("超时设置,单位:ms")] |
| | | [DisplayName("IO预检查超时")] |
| | | public int PreCheckIOTimeout { get; set; } = 0; |
| | | |
| | | [Category("IO操作配置")] |
| | | [DisplayName("IO输出定义集合")] |
| | | [Description("IO输出定义集合")] |
| | | [TypeConverter(typeof(CollectionCountConvert))] |
| | | public List<IORefrenceItem> IOOutputCollection { get; set; } = new List<IORefrenceItem>(); |
| | | |
| | | [Category("IO操作配置")] |
| | | [DisplayName("IO确认定义集合")] |
| | | [Description("IO确认定义集合")] |
| | | [TypeConverter(typeof(CollectionCountConvert))] |
| | | public List<IORefrenceItem> IOConfirmCollection { get; set; } = new List<IORefrenceItem>(); |
| | | [Category("IO操作配置")] |
| | | [Description("超时设置,单位:ms")] |
| | | [DisplayName("IO确认超时")] |
| | | public int IOConfirmTimeout { get; set; } = 0; |
| | | |
| | | [Category("板卡运动配置")] |
| | | [DisplayName("运动配置集合")] |
| | |
| | | [TypeConverter(typeof(CollectionCountConvert))] |
| | | [Editor(typeof(ComplexCollectionEditor<MovingOption>), typeof(UITypeEditor))] |
| | | public List<MovingOption> MovingOps { get; set; } = new List<MovingOption>(); |
| | | [Category("板卡运动配置")] |
| | | [Description("超时设置,单位:ms")] |
| | | [DisplayName("运动超时")] |
| | | public int MovingTimeout { get; set; } = 0; |
| | | |
| | | public string GetDisplayText() |
| | | { |
| | | throw new NotImplementedException(); |
| | | string preCheck = ""; |
| | | PreCheckIOCollection.ForEach(i => |
| | | { |
| | | preCheck += i.GetDisplayText() + " "; |
| | | }); |
| | | if (preCheck != "") |
| | | { |
| | | preCheck = " 预检:" + preCheck; |
| | | } |
| | | |
| | | string output = ""; |
| | | IOOutputCollection.ForEach(i => |
| | | { |
| | | output += i.GetDisplayText() + " "; |
| | | }); |
| | | if (output != "") |
| | | { |
| | | output = " 输出:" + output; |
| | | } |
| | | string confirm = ""; |
| | | IOConfirmCollection.ForEach(i => |
| | | { |
| | | confirm += i.GetDisplayText() + " "; |
| | | }); |
| | | if (confirm != "") |
| | | { |
| | | confirm = " 确认:" + confirm; |
| | | } |
| | | |
| | | string moving = ""; |
| | | MovingOps.ForEach(i => |
| | | { |
| | | moving += i.GetDisplayText() + " "; |
| | | }); |
| | | if (moving != "") |
| | | { |
| | | moving = " 运动:" + moving; |
| | | } |
| | | |
| | | return (preCheck + output + confirm + moving).Trim(); |
| | | } |
| | | } |
| | | |
| | | |
| | | public class IORefrenceItemCollectionEditor : CollectionEditor |
| | | { |
| | | protected override CollectionForm CreateCollectionForm() |
| | | { |
| | | var form = base.CreateCollectionForm(); |
| | | |
| | | var prop = form.GetType().GetField("propertyBrowser", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); |
| | | |
| | | if (prop != null) |
| | | { |
| | | if (prop.GetValue(form) is PropertyGrid grid) |
| | | { |
| | | grid.HelpVisible = true; |
| | | grid.ToolbarVisible = false; |
| | | } |
| | | } |
| | | |
| | | return form; |
| | | } |
| | | |
| | | protected override object CreateInstance(Type itemType) |
| | | { |
| | | if (itemType == typeof(IORefrenceItem)) |
| | | { |
| | | IORefrenceItem item = new IORefrenceItem(); |
| | | if ((this.Context.Instance is IOperationConfig opConfig) && !string.IsNullOrWhiteSpace(opConfig.DeviceId)) |
| | | { |
| | | using (var scope = GlobalVar.Container.BeginLifetimeScope()) |
| | | { |
| | | List<IDevice> deviceList = scope.Resolve<List<IDevice>>(); |
| | | |
| | | var device = deviceList.FirstOrDefault(u => u.Id == opConfig.DeviceId); |
| | | |
| | | if (device != null && (device is MotionCardBase motionCard)) |
| | | { |
| | | item.IOItemSource = (motionCard.InitialConfig as MotionCardInitialConfigBase).IODefinitionCollection; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return item; |
| | | } |
| | | |
| | | return base.CreateInstance(itemType); |
| | | } |
| | | |
| | | //protected override object[] GetItems(object editValue) |
| | | //{ |
| | | // return base.GetItems(editValue); |
| | | //} |
| | | |
| | | //protected override object SetItems(object editValue, object[] value) |
| | | //{ |
| | | // return base.SetItems(editValue, value); |
| | | //} |
| | | |
| | | public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) |
| | | { |
| | | if (context.Instance is IOperationConfig opConfig) |
| | | { |
| | | if (string.IsNullOrWhiteSpace(opConfig.DeviceId)) |
| | | { |
| | | return base.EditValue(context, provider, value); |
| | | } |
| | | |
| | | using (var scope = GlobalVar.Container.BeginLifetimeScope()) |
| | | { |
| | | List<IDevice> deviceList = scope.Resolve<List<IDevice>>(); |
| | | |
| | | var device = deviceList.FirstOrDefault(u => u.Id == opConfig.DeviceId); |
| | | |
| | | if (device == null) |
| | | { |
| | | return base.EditValue(context, provider, value); |
| | | } |
| | | |
| | | if (device is MotionCardBase motionCard) |
| | | { |
| | | if (value is List<IORefrenceItem> items) |
| | | { |
| | | items.ForEach(item => |
| | | { |
| | | item.IOItemSource = (motionCard.InitialConfig as MotionCardInitialConfigBase).IODefinitionCollection; |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return base.EditValue(context, provider, value); |
| | | } |
| | | |
| | | public IORefrenceItemCollectionEditor(Type type) : base(type) |
| | | { |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 限制一次选一个实例 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | protected override bool CanSelectMultipleInstances() |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 指定创建的对象类型 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | protected override Type CreateCollectionItemType() |
| | | { |
| | | return typeof(IORefrenceItem); |
| | | } |
| | | |
| | | protected override string GetDisplayText(object value) |
| | | { |
| | | if (value is IComplexDisplay) |
| | | { |
| | | return (value as IComplexDisplay).GetDisplayText(); |
| | | } |
| | | |
| | | return base.GetDisplayText(value); |
| | | } |
| | | |
| | | //protected override void DestroyInstance(object instance) |
| | | //{ |
| | | // base.DestroyInstance(instance);//重要!自动删除组件的设计时代码! |
| | | //} |
| | | } |
| | | |
| | | } |