RecipePoint.cs 3.9 KB

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