RecipeConfigViewModel.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Input;
  8. using System.Windows.Media;
  9. using Aitex.Core.RT.Log;
  10. using Caliburn.Micro;
  11. using Caliburn.Micro.Core;
  12. using MECF.Framework.Common.CommonData;
  13. using MECF.Framework.Common.DataCenter;
  14. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  15. using MECF.Framework.UI.Client.CenterViews.Editors.Sequence;
  16. using MECF.Framework.UI.Client.ClientBase;
  17. using OpenSEMI.ClientBase;
  18. using OpenSEMI.ClientBase.Command;
  19. using RecipeEditorLib.DGExtension.CustomColumn;
  20. using RecipeEditorLib.RecipeModel.Params;
  21. using SciChart.Core.Extensions;
  22. namespace MECF.Framework.UI.Client.CenterViews.Editors.RecipeConfig
  23. {
  24. public class RecipeConfigViewModel : BaseModel
  25. {
  26. public class RecipeConfigItem : NotifiableItem
  27. {
  28. public string ControlName { get; set; }
  29. public string DisplayName { get; set; }
  30. public float DefaultValue { get; set; }
  31. public float MinValue { get; set; }
  32. public float MaxValue { get; set; }
  33. public float WarnValue { get; set; }
  34. public float AlarmValue { get; set; }
  35. public bool EnableDefaultValue { get; set; }
  36. public bool EnableMinValue { get; set; }
  37. public bool EnableMaxValue { get; set; }
  38. public bool EnableWarnValue { get; set; }
  39. public bool EnableAlarmValue { get; set; }
  40. public RecipeConfigItem()
  41. {
  42. EnableDefaultValue = true;
  43. EnableMinValue = true;
  44. EnableMaxValue = true;
  45. EnableWarnValue = true;
  46. EnableAlarmValue = true;
  47. }
  48. }
  49. public bool IsPermission { get => this.Permission == 3; }//&& RtStatus != "AutoRunning";
  50. public ObservableCollection<ProcessTypeFileItem> ProcessTypeFileList { get; set; }
  51. public RecipeData CurrentRecipe { get; private set; }
  52. public FileNode CurrentFileNode { get; set; }
  53. private bool IsChanged
  54. {
  55. get
  56. {
  57. return editMode == EditMode.Edit || CurrentRecipe.IsChanged;
  58. }
  59. }
  60. public ObservableCollection<EditorDataGridTemplateColumnBase> Columns { get; set; }
  61. public bool EnableNew { get; set; }
  62. public bool EnableReName { get; set; }
  63. public bool EnableCopy { get; set; }
  64. public bool EnableDelete { get; set; }
  65. public bool EnableSave { get; set; }
  66. public bool EnableStep { get; set; }
  67. public bool EnableReload { get; set; }
  68. public bool EnableSaveToAll { get; set; }
  69. public bool EnableSaveTo { get; set; }
  70. private RecipeFormatBuilder _columnBuilder = new RecipeFormatBuilder();
  71. private EditMode editMode;
  72. private RecipeProvider _recipeProvider = new RecipeProvider();
  73. public ObservableCollection<RecipeConfigItem> StepParameters { get; set; }
  74. public ObservableCollection<RecipeConfigItem> OesParameters { get; set; }
  75. public ObservableCollection<RecipeConfigItem> VatParameters { get; set; }
  76. public ObservableCollection<RecipeConfigItem> FineTuningParameters { get; set; }
  77. public ObservableCollection<string> ChamberType { get; set; }
  78. public int ChamberTypeIndexSelection { get; set; }
  79. public string CurrentChamberType
  80. {
  81. get
  82. {
  83. return ChamberType[ChamberTypeIndexSelection];
  84. }
  85. }
  86. public Visibility OesVisibility { get; set; }
  87. public Visibility VatVisibility { get; set; }
  88. public Visibility FineTuningVisibility { get; set; }
  89. protected override void OnInitialize()
  90. {
  91. base.OnInitialize();
  92. var chamberType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.RecipeChamberType");
  93. if (chamberType == null)
  94. {
  95. ChamberType = new ObservableCollection<string>() { "Default" };
  96. }
  97. else
  98. {
  99. ChamberType = new ObservableCollection<string>(((string)(chamberType)).Split(','));
  100. }
  101. ChamberTypeIndexSelection = 0;
  102. this.Columns = this._columnBuilder.Build(CurrentChamberType);
  103. OesVisibility = _columnBuilder.OesConfig.Count > 0 ? Visibility.Visible : Visibility.Hidden;
  104. VatVisibility = _columnBuilder.VatConfig.Count > 0 ? Visibility.Visible : Visibility.Hidden;
  105. FineTuningVisibility = _columnBuilder.FineTuningConfig.Count > 0 ? Visibility.Visible : Visibility.Hidden;
  106. this.CurrentRecipe = new RecipeData();
  107. CurrentRecipe.RecipeChamberType = _columnBuilder.RecipeChamberType;
  108. CurrentRecipe.RecipeVersion = _columnBuilder.RecipeVersion;
  109. this.editMode = EditMode.None;
  110. InitStepParameter();
  111. InitOesParameter();
  112. InitVatParameter();
  113. InitFineTuningParameter();
  114. }
  115. private void InitStepParameter()
  116. {
  117. //name1,default,min,max,warn,alarm; name2,default,min,max,warn,alarm;
  118. StepParameters = new ObservableCollection<RecipeConfigItem>();
  119. var stepParameterConfig = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.StepParameter_{CurrentChamberType}");
  120. var stepParameterValues = new Dictionary<string, string[]>();
  121. if (stepParameterConfig != null)
  122. {
  123. string[] parameters = stepParameterConfig.ToString().Split(';');
  124. foreach (var parameter in parameters)
  125. {
  126. string[] values = parameter.Split(',');
  127. if (values.Length != 6)
  128. continue;
  129. stepParameterValues[values[0]] = values;
  130. }
  131. }
  132. foreach (var col in Columns)
  133. {
  134. if (col.ControlName.IsNullOrEmpty())
  135. continue;
  136. if (!col.EnableConfig)
  137. continue;
  138. var item = new RecipeConfigItem();
  139. item.ControlName = col.ControlName;
  140. item.DisplayName = col.DisplayName;
  141. if (stepParameterValues.ContainsKey(item.ControlName))
  142. {
  143. string[] values = stepParameterValues[item.ControlName];
  144. if (float.TryParse(values[1], out float defaultValue))
  145. item.DefaultValue = defaultValue;
  146. if (float.TryParse(values[1], out float minValue))
  147. item.MinValue = minValue;
  148. if (float.TryParse(values[1], out float maxValue))
  149. item.MaxValue = maxValue;
  150. if (float.TryParse(values[1], out float warnValue))
  151. item.WarnValue = warnValue;
  152. if (float.TryParse(values[1], out float alarmValue))
  153. item.AlarmValue = alarmValue;
  154. }
  155. StepParameters.Add(item);
  156. }
  157. }
  158. private void InitOesParameter()
  159. {
  160. OesParameters = GetParameters(QueryDataClient.Instance.Service.GetConfig($"System.Recipe.OesParameter_{CurrentChamberType}"), _columnBuilder.OesConfig);
  161. }
  162. private void InitVatParameter()
  163. {
  164. VatParameters = GetParameters(QueryDataClient.Instance.Service.GetConfig($"System.Recipe.VatParameter_{CurrentChamberType}"), _columnBuilder.VatConfig);
  165. }
  166. private void InitFineTuningParameter()
  167. {
  168. FineTuningParameters = GetParameters(QueryDataClient.Instance.Service.GetConfig($"System.Recipe.FineTuningParameter_{CurrentChamberType}"), _columnBuilder.FineTuningConfig);
  169. }
  170. private ObservableCollection<RecipeConfigItem> GetParameters(object config, ObservableCollection<Param> Configs)
  171. {
  172. //name1,default,min,max,warn,alarm; name2,default,min,max,warn,alarm;
  173. ObservableCollection<RecipeConfigItem> Parameters = new ObservableCollection<RecipeConfigItem>();
  174. var dicConfig = new Dictionary<string, string[]>();
  175. if (config != null)
  176. {
  177. string[] parameters = config.ToString().Split(';');
  178. foreach (var parameter in parameters)
  179. {
  180. string[] values = parameter.Split(',');
  181. if (values.Length != 6)
  182. continue;
  183. dicConfig[values[0]] = values;
  184. }
  185. }
  186. foreach (var col in Configs)
  187. {
  188. var item = new RecipeConfigItem();
  189. item.ControlName = col.Name;
  190. item.DisplayName = col.DisplayName;
  191. if (dicConfig.ContainsKey(item.ControlName))
  192. {
  193. string[] values = dicConfig[item.ControlName];
  194. if (float.TryParse(values[1], out float defaultValue))
  195. item.DefaultValue = defaultValue;
  196. if (float.TryParse(values[1], out float minValue))
  197. item.MinValue = minValue;
  198. if (float.TryParse(values[1], out float maxValue))
  199. item.MaxValue = maxValue;
  200. if (float.TryParse(values[1], out float warnValue))
  201. item.WarnValue = warnValue;
  202. if (float.TryParse(values[1], out float alarmValue))
  203. item.AlarmValue = alarmValue;
  204. }
  205. Parameters.Add(item);
  206. }
  207. return Parameters;
  208. }
  209. protected override void OnActivate()
  210. {
  211. base.OnActivate();
  212. }
  213. protected override void OnDeactivate(bool close)
  214. {
  215. base.OnDeactivate(close);
  216. }
  217. private void ClearData()
  218. {
  219. this.editMode = EditMode.None;
  220. this.CurrentRecipe.Clear();
  221. this.CurrentRecipe.Name = string.Empty;
  222. this.CurrentRecipe.Description = string.Empty;
  223. }
  224. }
  225. }