TempPIDTable.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using Caliburn.Micro.Core;
  2. using RecipeEditorLib.RecipeModel.Params;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace MECF.Framework.UI.Client.CenterViews.Parameter
  10. {
  11. public class TempPIDTable : ParameterTable
  12. {
  13. private ObservableCollection<PIDData> _pIDDataList = new ObservableCollection<PIDData>();
  14. public ObservableCollection<PIDData> PIDDataList
  15. {
  16. get => _pIDDataList;
  17. set
  18. {
  19. _pIDDataList = value;
  20. NotifyOfPropertyChange("PIDDataList");
  21. }
  22. }
  23. public TempPIDTable() : base()
  24. {
  25. }
  26. public TempPIDTable(ParameterDataBase recipeData)
  27. {
  28. if (recipeData.Steps.Count <= 0) return;
  29. SetCurrentRecipeStep(recipeData, recipeData.Steps[0]);
  30. }
  31. public TempPIDTable(ParameterDataBase recipeData, int selectedStepNo)
  32. {
  33. ParameterTable step = recipeData.Steps.Where(x => x.StepNo == selectedStepNo).FirstOrDefault();
  34. SetCurrentRecipeStep(recipeData, step);
  35. }
  36. public void SetTempPIDData(string value)
  37. {
  38. if (string.IsNullOrEmpty(value)) return;
  39. string[] strTempPID = value.Split('|');
  40. foreach (var item in strTempPID)
  41. {
  42. if (string.IsNullOrEmpty(item)) continue;
  43. string[] subTempPID = item.Split(';');
  44. Dictionary<string, string> dictTempPID = new Dictionary<string, string>();
  45. foreach (var pid in subTempPID)
  46. {
  47. if (string.IsNullOrEmpty(item)) continue;
  48. var keyValue = pid.Split(':');
  49. if (keyValue == null || keyValue.Length != 2) continue;
  50. dictTempPID[keyValue[0]] = keyValue[1];
  51. }
  52. var selectPID = PIDDataList.Where(x => x.Name == dictTempPID["Name"]).FirstOrDefault();
  53. if (selectPID != null)
  54. {
  55. selectPID.P.Value = dictTempPID["P"];
  56. selectPID.I.Value = dictTempPID["I"];
  57. selectPID.D.Value = dictTempPID["D"];
  58. }
  59. }
  60. }
  61. }
  62. public class PIDData : PropertyChangedBase
  63. {
  64. private int _index = 1;
  65. public int Index
  66. {
  67. get => _index;
  68. set
  69. {
  70. _index = value;
  71. NotifyOfPropertyChange("Index");
  72. }
  73. }
  74. private string _name = "";
  75. public string Name
  76. {
  77. get => _name;
  78. set
  79. {
  80. _name = value;
  81. NotifyOfPropertyChange("Name");
  82. }
  83. }
  84. private DoubleParam _p;
  85. public DoubleParam P
  86. {
  87. get => _p;
  88. set
  89. {
  90. _p = value;
  91. NotifyOfPropertyChange("P");
  92. }
  93. }
  94. private DoubleParam _i;
  95. public DoubleParam I
  96. {
  97. get => _i;
  98. set
  99. {
  100. _i = value;
  101. NotifyOfPropertyChange("I");
  102. }
  103. }
  104. private DoubleParam _d;
  105. public DoubleParam D
  106. {
  107. get => _d;
  108. set
  109. {
  110. _d = value;
  111. NotifyOfPropertyChange("D");
  112. }
  113. }
  114. public override string ToString()
  115. {
  116. string[] rtnStrList = new string[5];
  117. rtnStrList[0] = $"Index:{Index}";
  118. rtnStrList[1] = $"Name:{Name}";
  119. rtnStrList[2] = $"P:{P.Value}";
  120. rtnStrList[3] = $"I:{I.Value}";
  121. rtnStrList[4] = $"D:{D.Value}";
  122. return string.Join(";", rtnStrList);
  123. }
  124. }
  125. }