版博士V2.0程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

88 satır
4.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Xml.Linq;
  9. using Advantech.Motion;
  10. using Newtonsoft.Json;
  11. using Newtonsoft.Json.Serialization;
  12. using ProductionControl.UI.PropExtend;
  13. using static ProductionControl.UI.UIAxisDev;
  14. namespace ProductionControl.UI
  15. {
  16. //[TypeConverter(typeof(PropertySorter))] //此属性使类无法序列化和反序列化
  17. public class DefectLibProp
  18. {
  19. public DefectLibProp(Size cut_size, Size resize,float thresholds) {
  20. CutSize = cut_size;
  21. Resize=resize;
  22. Thresholds = thresholds;
  23. }
  24. [PropertyOrder(1), Browsable(true), Category("1 数据"), DisplayName("源图"), JsonIgnore, Description("源图")]
  25. public string BmpPath { get; set; }
  26. [PropertyOrder(11), Browsable(true), Category("2 参数"), DisplayName("2.1 切割大小"), Description("切割大小")]
  27. public Size CutSize { get;set; }
  28. [PropertyOrder(12), Browsable(true), Category("2 参数"), DisplayName("2.2 重置大小"), Description("重置大小")]
  29. public Size Resize { get; set; }
  30. [PropertyOrder(13), Browsable(true), Category("2 参数"), DisplayName("2.3 阀值"), Description("阀值")]
  31. public float Thresholds { get; set; }
  32. [PropertyOrder(13), Browsable(true), Category("2 参数"), DisplayName("2.4 种类阀值"), Description("多个用半号逗号(,)或分号(;)分隔")]
  33. public string ThresholdsClass { get; set; }
  34. [PropertyOrder(13), Browsable(true), Category("2 参数"), DisplayName("2.5 种类个数"), Description("种类阀值的数量")]
  35. public int ThresholdsClassCount { get; set; }
  36. [PropertyOrder(15), Browsable(true), Category("3 结果"), DisplayName("结果"), JsonIgnore, Description("结果"), ReadOnly(true)]
  37. public string InformationList { get; set; }
  38. //public List<Dictionary<int, List<string>[]>> InformationList { get; set; }
  39. [PropertyOrder(15), Browsable(true), Category("3 结果"), DisplayName("信息"), JsonIgnore, Description("信息"), ReadOnly(true)]
  40. public string resultInfo { get; set; }
  41. [PropertyOrder(91), Browsable(true), Category("4 阀值"), DisplayName("阀值上限"), Description("阀值上限")]
  42. public double LimitThresholdVal { get; set; }
  43. [PropertyOrder(92), Browsable(true), Category("4 阀值"), DisplayName("阀值下限"), Description("阀值下限")]
  44. public double LowerThresholdVal { get; set; }
  45. [PropertyOrder(25), Browsable(true), Category("5 控制"), DisplayName("5.1 运行前Sleep(ms)"), Description("休息时间")]
  46. public uint SleepPre { get; set; }
  47. [PropertyOrder(26), Browsable(true), Category("5 控制"), DisplayName("5.2 运行后Sleep(ms)"), Description("休息时间")]
  48. public uint SleepLater { get; set; }
  49. [PropertyOrder(27), Browsable(true), Category("5 控制"), DisplayName("5.4 禁用工序"), Description("禁用本工序(True-是;False-否)")]
  50. public bool Disable { get; set; }
  51. /// <summary>
  52. /// 序列化
  53. /// </summary>
  54. /// <param name="obj"></param>
  55. /// <returns></returns>
  56. public string serialize()
  57. {
  58. return JsonConvert.SerializeObject(this);
  59. }
  60. /// <summary>
  61. /// 反序列化
  62. /// </summary>
  63. /// <param name="json"></param>
  64. /// <returns></returns>
  65. public void deserialize(string json)
  66. {
  67. var o= JsonConvert.DeserializeObject<DefectLibProp>(json);
  68. Type type = o.GetType();
  69. System.Reflection.PropertyInfo[] properties = type.GetProperties();
  70. foreach (System.Reflection.PropertyInfo property in properties)
  71. {
  72. string name = property.Name;
  73. if (!type.GetProperty(name).IsDefined(typeof(JsonIgnoreAttribute), true))
  74. {
  75. var value = property.GetValue(o);
  76. this.GetType().GetProperty(name).SetValue(this, value);
  77. }
  78. }
  79. }
  80. }
  81. }