RecipePoint.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 double[] fixset;
  38. /// <summary>
  39. /// 该点位的单轴位置的偏移量数组, 序号与RecipePointPositions的序号一致
  40. /// </summary>
  41. public double[] Fixset
  42. {
  43. get { return fixset; }
  44. set
  45. {
  46. fixset = value;
  47. for (int i = 0; i < fixset.Length; i++)
  48. {
  49. if (RecipePointPositions != null && RecipePointPositions[i] != null)
  50. {
  51. RecipePointPositions[i].FixsetVal = fixset[i];
  52. }
  53. }
  54. }
  55. }
  56. /// <summary>
  57. /// 清除偏移量
  58. /// </summary>
  59. public void ClearFixset()
  60. {
  61. if (fixset != null)
  62. {
  63. for (int i = 0; i < fixset.Length; i++)
  64. {
  65. fixset[i] = 0;
  66. }
  67. }
  68. if (RecipePointPositions != null)
  69. {
  70. foreach (RecipePointPosition pointPosition in RecipePointPositions)
  71. {
  72. pointPosition.FixsetVal = 0;
  73. }
  74. }
  75. }
  76. /// <summary>
  77. /// 点位移动的安全条件 (可以用Lambda写法更方便的获取更多点位信息, 例如位置值)
  78. /// </summary>
  79. public Func<RecipePoint, bool> SafeChecker { get; set; }
  80. /// <summary>
  81. /// 点位单轴位置集合
  82. /// </summary>
  83. public ObservableCollection<RecipePointPosition> RecipePointPositions { get; set; } = new ObservableCollection<RecipePointPosition>();
  84. /// <summary>
  85. /// 获取点位的轴位置值
  86. /// </summary>
  87. /// <param name="index">绑定多轴时的获取的轴序号, 例如按顺序绑定了xy轴, x轴的序号为0、y轴的序号为1</param>
  88. /// <returns></returns>
  89. public double PositionVal(int index = 0)
  90. {
  91. if (index < 0 || index > RecipePointPositions.Count - 1) return 0;
  92. return RecipePointPositions[index].Position;
  93. }
  94. public object Clone()
  95. {
  96. var model = new RecipePoint
  97. {
  98. Code = this.Code,
  99. Name = this.Name,
  100. };
  101. model.RecipePointPositions = new ObservableCollection<RecipePointPosition>();
  102. foreach (var item in RecipePointPositions)
  103. {
  104. model.RecipePointPositions.Add((RecipePointPosition) item.Clone());
  105. }
  106. return model;
  107. }
  108. }
  109. }