RecipePoint.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using Prism.Mvvm;
  2. using System;
  3. using System.Collections.ObjectModel;
  4. namespace SKMC.Api.Recipe.Model
  5. {
  6. /// <summary>
  7. /// 电机点位配置模型
  8. /// 每个点位由1个或多个单轴位置RecipePointPosition组成
  9. /// </summary>
  10. public class RecipePoint : BindableBase, ICloneable
  11. {
  12. private string _code;
  13. /// <summary>
  14. /// 点位码
  15. /// </summary>
  16. public string Code
  17. {
  18. get { return _code; }
  19. set { _code = value; RaisePropertyChanged(); }
  20. }
  21. private string _name;
  22. /// <summary>
  23. /// 点位名称
  24. /// </summary>
  25. public string Name
  26. {
  27. get { return _name; }
  28. set { _name = value; RaisePropertyChanged(); }
  29. }
  30. public string SerialName { get => $"[{Code}]: {Name}"; }
  31. private string speedCode;
  32. public string SpeedCode
  33. {
  34. get { return speedCode; }
  35. set { speedCode = value; RaisePropertyChanged(); }
  36. }
  37. private bool syncArrival;
  38. /// <summary>
  39. /// 多轴是否同步到达
  40. /// </summary>
  41. public bool SyncArrival
  42. {
  43. get { return syncArrival; }
  44. set { syncArrival = value; }
  45. }
  46. private double[] fixset;
  47. /// <summary>
  48. /// 该点位的单轴位置的偏移量数组, 序号与RecipePointPositions的序号一致
  49. /// </summary>
  50. public double[] Fixset
  51. {
  52. get { return fixset; }
  53. set
  54. {
  55. fixset = value;
  56. for (int i = 0; i < fixset.Length; i++)
  57. {
  58. if (RecipePointPositions != null && RecipePointPositions[i] != null)
  59. {
  60. RecipePointPositions[i].FixsetVal = fixset[i];
  61. }
  62. }
  63. }
  64. }
  65. /// <summary>
  66. /// 清除偏移量
  67. /// </summary>
  68. public void ClearFixset()
  69. {
  70. if (fixset != null)
  71. {
  72. for (int i = 0; i < fixset.Length; i++)
  73. {
  74. fixset[i] = 0;
  75. }
  76. }
  77. if (RecipePointPositions != null)
  78. {
  79. foreach (RecipePointPosition pointPosition in RecipePointPositions)
  80. {
  81. pointPosition.FixsetVal = 0;
  82. }
  83. }
  84. }
  85. /// <summary>
  86. /// 点位移动的安全条件 (可以用Lambda写法更方便的获取更多点位信息, 例如位置值)
  87. /// </summary>
  88. public Func<RecipePoint, bool> SafeChecker { get; set; }
  89. /// <summary>
  90. /// 点位单轴位置集合
  91. /// </summary>
  92. public ObservableCollection<RecipePointPosition> RecipePointPositions { get; set; } = new ObservableCollection<RecipePointPosition>();
  93. /// <summary>
  94. /// 获取点位的轴位置值
  95. /// </summary>
  96. /// <param name="index">绑定多轴时的获取的轴序号, 例如按顺序绑定了xy轴, x轴的序号为0、y轴的序号为1</param>
  97. /// <returns></returns>
  98. public double PositionVal(int index = 0)
  99. {
  100. if (index < 0 || index > RecipePointPositions.Count - 1) return 0;
  101. return RecipePointPositions[index].Position;
  102. }
  103. public object Clone()
  104. {
  105. var model = new RecipePoint
  106. {
  107. Code = this.Code,
  108. Name = this.Name,
  109. };
  110. model.RecipePointPositions = new ObservableCollection<RecipePointPosition>();
  111. foreach (var item in RecipePointPositions)
  112. {
  113. model.RecipePointPositions.Add((RecipePointPosition) item.Clone());
  114. }
  115. return model;
  116. }
  117. }
  118. }