领胜LDS 键盘AOI检测项目
wells.liu
2020-07-02 34ee2c9c1e7287ca1002ede66a70bdbf9268cd27
src/Bro.Common.Model/Model/IOItem.cs
@@ -1,6 +1,9 @@
using Bro.Common.Helper;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using static Bro.Common.Helper.EnumHelper;
namespace Bro.Common.Model
@@ -10,21 +13,81 @@
        /// <summary>
        /// IO点编号
        /// </summary>
        public int IONum { get; set; }
        [Category("IO配置")]
        [Description("IO点编号")]
        public virtual int IONum { get; set; }
        /// <summary>
        /// IO点的值
        /// </summary>
        public int Value { get; set; }
        [Category("IO配置")]
        [Description("IO数值")]
        public virtual int Value { get; set; }
        /// <summary>
        /// IO点是in还是out
        /// </summary>   
        public IOModel Model { get; set; }
        [Category("IO配置")]
        [Description("IO类型")]
        public virtual IOType IOType { get; set; }
        public string GetDisplayText()
        {
            return $"{Model.GetEnumDescription()},编号{IONum},IO点的值{Value}";
            return $"{IOType.GetEnumDescription()},编号{IONum},IO点的值{Value}";
        }
    }
    public class IODefinition : IOItem
    {
        [Category("IO配置")]
        [Description("IO用途描述")]
        public string IODesc { get; set; }
        [Category("IO配置")]
        [Description("备注说明")]
        public string Remark { get; set; }
        [Browsable(false)]
        [JsonIgnore]
        public override int Value { get; set; }
        public new string GetDisplayText()
        {
            return $"{IODesc} {IOType.GetEnumDescription()} {IONum}";
        }
    }
    public class IORefrenceItem
    {
        [Category("IO操作配置")]
        [Description("需要操作的IO")]
        [TypeConverter(typeof(IORefrenceItemSourceConverter))]
        public IOItem IOItem { get; set; } = new IOItem();
        [Category("IO操作配置")]
        [Description("需要操作的IO的数值")]
        public int CheckValue { get => IOItem.Value; set => IOItem.Value = value; }
        [Browsable(false)]
        [JsonIgnore]
        public List<IODefinition> IOItemSource { get; set; } = new List<IODefinition>();
    }
    public class IORefrenceItemSourceConverter : ComboBoxItemTypeConvert
    {
        public override Hashtable GetConvertHash(ITypeDescriptorContext context)
        {
            Hashtable table = new Hashtable();
            if (context.Instance is IORefrenceItem item)
            {
                item.IOItemSource.ForEach(i =>
                {
                    table[i.IODesc + i.IOType.GetEnumDescription() + i.IONum] = i as IOItem;
                });
            }
            return table;
        }
    }
}