From 1e12238d9d6ea02f89aa7150f8507c9d8368a429 Mon Sep 17 00:00:00 2001 From: xcd <834800634@qq.com> Date: 星期四, 09 七月 2020 14:29:15 +0800 Subject: [PATCH] 板卡操作配置编辑时传递轴号和轴名称 --- src/Bro.Common.Model/Model/MotionCardRelated.cs | 314 +++++++++++++++++++++++++++++++--------------------- 1 files changed, 187 insertions(+), 127 deletions(-) diff --git a/src/Bro.Common.Model/Model/MotionCardRelated.cs b/src/Bro.Common.Model/Model/MotionCardRelated.cs index 6342b0a..7083a14 100644 --- a/src/Bro.Common.Model/Model/MotionCardRelated.cs +++ b/src/Bro.Common.Model/Model/MotionCardRelated.cs @@ -1,9 +1,11 @@ 锘縰sing Bro.Common.Helper; using Newtonsoft.Json; using System; +using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Drawing.Design; +using System.Globalization; using System.Linq; using System.Text; using System.Threading; @@ -241,115 +243,129 @@ /// <summary> /// 杩愬姩瀵硅薄 /// </summary> - public class MovingOption : INotifyPropertyChanged, IComplexDisplay + public class MovingOption : IComplexDisplay { - private int axisIndex = 0; [Category("杩愬姩閰嶇疆")] [DisplayName("杩愬姩杞寸储寮�")] [Description("AxisIndex锛氳繍鍔ㄨ酱绱㈠紩")] [TypeConverter(typeof(AxisIndexConvert))] + public string AxisIndexStr { get; set; } = "0"; + + [Browsable(false)] + [JsonIgnore] public int AxisIndex { - get => axisIndex; - set - { - if (axisIndex != value) - { - axisIndex = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("AxisIndex")); - } - axisIndex = value; - } + get => int.Parse(AxisIndexStr); + set => AxisIndexStr = value.ToString(); } - private MotionMode moveMode = MotionMode.Normal; + //private int axisIndex = 0; + //[Category("杩愬姩閰嶇疆")] + //[DisplayName("杩愬姩杞寸储寮�")] + //[Description("AxisIndex锛氳繍鍔ㄨ酱绱㈠紩")] + //[TypeConverter(typeof(AxisIndexConvert))] + //public int AxisIndex { get; set; } + //{ + // get => axisIndex; + // set + // { + // if (axisIndex != value) + // { + // axisIndex = value; + // PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("AxisIndex")); + // } + // axisIndex = value; + // } + //} + + //private MotionMode moveMode = MotionMode.Normal; [Category("杩愬姩閰嶇疆")] [DisplayName("杩愬姩妯″紡")] [Description("MoveMode锛氳繍鍔ㄦā寮�")] - public MotionMode MoveMode - { - get => moveMode; - set - { - if (moveMode != value) - { - moveMode = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("MoveMode")); - } + public MotionMode MoveMode { get; set; } = MotionMode.Normal; + //{ + // get => moveMode; + // set + // { + // if (moveMode != value) + // { + // moveMode = value; + // PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("MoveMode")); + // } - moveMode = value; - } - } + // moveMode = value; + // } + //} - private bool isAbsolute = true; + //private bool isAbsolute = true; [Category("杩愬姩閰嶇疆")] [DisplayName("鏄惁缁濆杩愬姩")] [Description("IsAbsolute锛氭槸鍚︾粷瀵硅繍鍔�")] - public bool IsAbsolute - { - get => isAbsolute; - set - { - if (isAbsolute != value) - { - isAbsolute = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsAbsolute")); - } + public bool IsAbsolute { get; set; } = true; + //{ + // get => isAbsolute; + // set + // { + // if (isAbsolute != value) + // { + // isAbsolute = value; + // PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsAbsolute")); + // } - isAbsolute = value; - } - } + // isAbsolute = value; + // } + //} - private int destination = 0; + //private int destination = 0; [Category("杩愬姩閰嶇疆")] [DisplayName("鐩殑鍦�")] [Description("Destination锛氱洰鐨勫湴")] - public int Destination - { - get => destination; - set - { - if (destination != value) - { - destination = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Destination")); - } + public int Destination { get; set; } + //{ + // get => destination; + // set + // { + // if (destination != value) + // { + // destination = value; + // PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Destination")); + // } - destination = value; - } - } + // destination = value; + // } + //} - private VelocityPara velocityPara = new VelocityPara(); + //private VelocityPara velocityPara = new VelocityPara(); [Category("杩愬姩閰嶇疆")] [DisplayName("閫熷害鍙傛暟")] [Description("VelocityPara锛氶�熷害鍙傛暟")] [TypeConverter(typeof(ComplexObjectConvert))] [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))] - public VelocityPara VelocityPara - { - get => velocityPara; - set - { - velocityPara = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("VelocityPara")); - } - } + public VelocityPara VelocityPara { get; set; } = new VelocityPara(); + //{ + // get => velocityPara; + // set + // { + // velocityPara = value; + // PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("VelocityPara")); + // } + //} - private GoHomePara goHomePara = new GoHomePara(); + //private GoHomePara goHomePara = new GoHomePara(); [Category("杩愬姩閰嶇疆")] [DisplayName("鍥炲師鐐瑰弬鏁�")] [Description("GoHomePara锛氶�熷害鍙傛暟")] [TypeConverter(typeof(ComplexObjectConvert))] [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))] - public GoHomePara GoHomePara - { - get => goHomePara; - set - { - goHomePara = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("GoHomePara")); - } - } + public GoHomePara GoHomePara { get; set; } = new GoHomePara(); + //{ + // get => goHomePara; + // set + // { + // goHomePara = value; + // PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("GoHomePara")); + // } + //} [Category("鏉垮崱杩愬姩閰嶇疆")] [Description("瓒呮椂璁剧疆锛屽崟浣嶏細ms")] @@ -357,6 +373,7 @@ public int MovingTimeout { get; set; } = 0; internal List<AxisSetting> _axisSettingList = new List<AxisSetting>(); + public void SetAxisSetting(List<AxisSetting> settings) { if (settings != null) @@ -365,7 +382,7 @@ public string GetDisplayText() { - string axisName = AxisIndex.ToString(); + string axisName = AxisIndexStr; var axisSet = _axisSettingList.FirstOrDefault(a => a.AxisIndex == AxisIndex); if (axisSet != null) { @@ -373,70 +390,113 @@ } return axisName + "," + MoveMode.ToString() + "," + (IsAbsolute ? "Abs" : "Rel") + "," + Destination; } - public event PropertyChangedEventHandler PropertyChanged; + //public event PropertyChangedEventHandler PropertyChanged; } - public class AxisIndexConvert : TypeConverter + public class AxisIndexConvert : ComboBoxItemTypeConvert { - Dictionary<int, string> _indexNameDict = new Dictionary<int, string>(); - - public override bool GetStandardValuesSupported(ITypeDescriptorContext context) + public override Hashtable GetConvertHash(ITypeDescriptorContext context) { - return true; - } - - public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) - { - MovingOption mo = context.Instance as MovingOption; - - _indexNameDict = mo._axisSettingList.ToDictionary(a => a.AxisIndex, a => a.AxisIndex + "-" + a.AxisName); - - return new StandardValuesCollection(_indexNameDict.Keys); - } - - public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) - { - if (sourceType == typeof(string)) + Hashtable table = new Hashtable(); + if (context.Instance is MovingOption op) { - return true; - } - return base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object v) - { - if (v is string) - { - foreach (var indexName in _indexNameDict) + op._axisSettingList.ForEach(a => { - if (indexName.Value == v.ToString()) - { - return indexName.Key; - } - } - return Convert.ToInt32(v); + table[a.AxisIndex.ToString()] = a.AxisName; + }); } - return base.ConvertFrom(context, culture, v); + + return table; } - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object v, Type destinationType) - { - if (destinationType == typeof(string)) - { - if (_indexNameDict.ContainsKey(Convert.ToInt32(v))) - { - return _indexNameDict[Convert.ToInt32(v)]; - } - } - return base.ConvertTo(context, culture, v, destinationType); - } + //public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + //{ + // bool flag = base.CanConvertFrom(context, sourceType); + // return flag; + //} - public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) - { - return false; - } + //public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) + //{ + // return base.CanConvertTo(context, destinationType); + //} + + //public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object v) + //{ + // //if (string.IsNullOrWhiteSpace(v.ToString())) + // //{ + // // return 0; + // //} + + // return base.ConvertFrom(context, culture, Convert.ToInt32(v)); + //} + + //public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object v, Type destinationType) + //{ + // return base.ConvertTo(context, culture, v, destinationType); + //} } + //public class AxisIndexConvert : TypeConverter + //{ + // Dictionary<int, string> _indexNameDict = new Dictionary<int, string>(); + + // public override bool GetStandardValuesSupported(ITypeDescriptorContext context) + // { + // return true; + // } + + // public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) + // { + // MovingOption mo = context.Instance as MovingOption; + + // _indexNameDict = mo._axisSettingList.ToDictionary(a => a.AxisIndex, a => a.AxisIndex + "-" + a.AxisName); + + // return new StandardValuesCollection(_indexNameDict.Keys); + // } + + // public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + // { + // if (sourceType == typeof(string)) + // { + // return true; + // } + // return base.CanConvertFrom(context, sourceType); + // } + + // public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object v) + // { + // if (v is string) + // { + // foreach (var indexName in _indexNameDict) + // { + // if (indexName.Value == v.ToString()) + // { + // return indexName.Key; + // } + // } + // return Convert.ToInt32(v); + // } + // return base.ConvertFrom(context, culture, v); + // } + + // public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object v, Type destinationType) + // { + // if (destinationType == typeof(string)) + // { + // if (_indexNameDict.ContainsKey(Convert.ToInt32(v))) + // { + // return _indexNameDict[Convert.ToInt32(v)]; + // } + // } + // return base.ConvertTo(context, culture, v, destinationType); + // } + + // public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) + // { + // return false; + // } + //} + public class AxisConflictSet : IComplexDisplay { [Category("1.杞村啿绐佹潯浠�")] -- Gitblit v1.8.0