SystemConfigItem.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Caliburn.Micro.Core;
  4. using RecipeEditorLib.RecipeModel.Params;
  5. using SciChart.Core.Extensions;
  6. namespace MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig
  7. {
  8. public enum DataType
  9. {
  10. Unknown,
  11. Int,
  12. Double,
  13. Bool,
  14. String
  15. };
  16. public class ConfigNode : PropertyChangedBase
  17. {
  18. private string name = string.Empty;
  19. public string Name
  20. {
  21. get { return name; }
  22. set { name = value; NotifyOfPropertyChange("Name"); }
  23. }
  24. private string path = string.Empty;
  25. public string Path
  26. {
  27. get { return path; }
  28. set { path = value; NotifyOfPropertyChange("Path"); }
  29. }
  30. private string _display = string.Empty;
  31. public string Display
  32. {
  33. get { return _display; }
  34. set { _display = value; NotifyOfPropertyChange("Display"); }
  35. }
  36. private bool _isExpanded;
  37. public bool IsExpanded
  38. {
  39. get { return _isExpanded; }
  40. set { _isExpanded = value; NotifyOfPropertyChange("IsExpanded"); }
  41. }
  42. private bool _isVisible=true;
  43. public bool IsVisible
  44. {
  45. get { return _isVisible; }
  46. set { _isVisible = value; NotifyOfPropertyChange("IsVisible"); }
  47. }
  48. private bool _isMatch;
  49. public bool IsMatch
  50. {
  51. get { return _isMatch; }
  52. set { _isMatch = value; NotifyOfPropertyChange("IsMatch"); }
  53. }
  54. private bool _isSelected;
  55. public bool IsSelected
  56. {
  57. get { return _isSelected; }
  58. set { _isSelected = value; NotifyOfPropertyChange("IsSelected"); }
  59. }
  60. private bool _bvalue = false;
  61. public bool ProfileBoolValue
  62. {
  63. get { return _bvalue; }
  64. set { _bvalue = value; NotifyOfPropertyChange("ProfileBoolValue"); }
  65. }
  66. public bool PIDBoolValue
  67. {
  68. get { return _bvalue; }
  69. set { _bvalue = value; NotifyOfPropertyChange("PIDBoolValue"); }
  70. }
  71. public bool StabilizeBoolValue
  72. {
  73. get { return _bvalue; }
  74. set { _bvalue = value; NotifyOfPropertyChange("StabilizeBoolValue"); }
  75. }
  76. public bool TempSttingBoolValue
  77. {
  78. get { return _bvalue; }
  79. set { _bvalue = value; NotifyOfPropertyChange("TempSttingBoolValue"); }
  80. }
  81. public bool PressureStabilizeBoolValue
  82. {
  83. get { return _bvalue; }
  84. set { _bvalue = value; NotifyOfPropertyChange("PressureStabilizeBoolValue"); }
  85. }
  86. public bool AlarmWatchBoolValue
  87. {
  88. get { return _bvalue; }
  89. set { _bvalue = value; NotifyOfPropertyChange("PressureStabilizeBoolValue"); }
  90. }
  91. public bool TempAlarmBoolValue
  92. {
  93. get { return _bvalue; }
  94. set { _bvalue = value; NotifyOfPropertyChange("TempAlarmBoolValue"); }
  95. }
  96. public bool FlowAlarmBoolValue
  97. {
  98. get { return _bvalue; }
  99. set { _bvalue = value; NotifyOfPropertyChange("FlowAlarmBoolValue"); }
  100. }
  101. public bool PressureAlarmBoolValue
  102. {
  103. get { return _bvalue; }
  104. set { _bvalue = value; NotifyOfPropertyChange("PressureAlarmBoolValue"); }
  105. }
  106. private List<ConfigNode> _subNodes = null;
  107. public List<ConfigNode> SubNodes
  108. {
  109. get { return _subNodes; }
  110. set { _subNodes = value; NotifyOfPropertyChange("SubNodes"); }
  111. }
  112. private ConfigNode _parentNode;
  113. public ConfigNode ParentNode
  114. {
  115. get { return _parentNode; }
  116. set { _parentNode = value; NotifyOfPropertyChange("ParentNode"); }
  117. }
  118. private List<ConfigItem> _items = null;
  119. public List<ConfigItem> Items
  120. {
  121. get { return _items; }
  122. set { _items = value; NotifyOfPropertyChange("Items"); }
  123. }
  124. private bool IsCriteriaMatched(string criteria)
  125. {
  126. bool matched = string.IsNullOrEmpty(criteria) || name.Contains(criteria) || name.ToLower().Contains(criteria.ToLower());
  127. if (matched)
  128. return true;
  129. foreach (var configItem in Items)
  130. {
  131. if (configItem.Name.Contains(criteria))
  132. return true;
  133. if (configItem.Name.ToLower().Contains(criteria.ToLower()))
  134. return true;
  135. }
  136. return false;
  137. }
  138. private void CheckChildren(string criteria, ConfigNode parent)
  139. {
  140. foreach (var child in parent.SubNodes)
  141. {
  142. if (!child.IsCriteriaMatched(criteria))
  143. {
  144. child.IsMatch = false;
  145. }
  146. CheckChildren(criteria, child);
  147. }
  148. }
  149. public void ApplyCriteria(string criteria, Stack<ConfigNode> ancestors)
  150. {
  151. if (IsCriteriaMatched(criteria))
  152. {
  153. IsMatch = true;
  154. foreach (var ancestor in ancestors)
  155. {
  156. ancestor.IsMatch = true;
  157. ancestor.IsExpanded = !string.IsNullOrEmpty(criteria);
  158. //CheckChildren(criteria, ancestor);
  159. }
  160. IsExpanded = true;
  161. }
  162. else
  163. IsMatch = false;
  164. ancestors.Push(this);
  165. foreach (var child in SubNodes)
  166. child.ApplyCriteria(criteria, ancestors);
  167. ancestors.Pop();
  168. }
  169. }
  170. public class ConfigItem : PropertyChangedBase
  171. {
  172. private string name = string.Empty;
  173. public string Name
  174. {
  175. get { return name; }
  176. set { name = value; NotifyOfPropertyChange("Name"); }
  177. }
  178. private string description = string.Empty;
  179. public string Description
  180. {
  181. get { return description; }
  182. set { description = value; NotifyOfPropertyChange("Description"); }
  183. }
  184. private string _display = string.Empty;
  185. public string Display
  186. {
  187. get { return _display; }
  188. set { _display = value; NotifyOfPropertyChange("Display"); }
  189. }
  190. private DataType type = DataType.Unknown;
  191. public DataType Type
  192. {
  193. get { return type; }
  194. set { type = value; NotifyOfPropertyChange("Type"); }
  195. }
  196. private string defaultValue = string.Empty;
  197. public string DefaultValue
  198. {
  199. get { return defaultValue; }
  200. set { defaultValue = value; NotifyOfPropertyChange("DefaultValue"); }
  201. }
  202. private double max = double.NaN;
  203. public double Max
  204. {
  205. get { return max; }
  206. set { max = value; NotifyOfPropertyChange("Max"); }
  207. }
  208. private double min = double.NaN;
  209. public double Min
  210. {
  211. get { return min; }
  212. set { min = value; NotifyOfPropertyChange("Min"); }
  213. }
  214. private string parameter = string.Empty;
  215. public string Parameter
  216. {
  217. get { return parameter; }
  218. set { parameter = value; NotifyOfPropertyChange("Parameter"); }
  219. }
  220. private string tag = string.Empty;
  221. public string Tag
  222. {
  223. get { return tag; }
  224. set { tag = value; NotifyOfPropertyChange("Tag"); }
  225. }
  226. private string unit = string.Empty;
  227. public string Unit
  228. {
  229. get { return unit; }
  230. set { unit = value; NotifyOfPropertyChange("Unit"); }
  231. }
  232. private bool visible = true;
  233. public bool Visible
  234. {
  235. get { return visible; }
  236. set { visible = value; NotifyOfPropertyChange("Visible"); }
  237. }
  238. private bool _isExpanded;
  239. public bool IsExpanded
  240. {
  241. get { return _isExpanded; }
  242. set { _isExpanded = value; NotifyOfPropertyChange("IsExpanded"); }
  243. }
  244. private string cvalue = string.Empty;
  245. public string CurrentValue
  246. {
  247. get { return cvalue; }
  248. set { cvalue = value; NotifyOfPropertyChange("CurrentValue"); }
  249. }
  250. private StringParam cvalueParam = new StringParam() { Name = "CurrentValue", Value = "" };
  251. public StringParam CurrentValueParam
  252. {
  253. get { return cvalueParam; }
  254. set { cvalueParam = value; NotifyOfPropertyChange("CurrentValueParam"); }
  255. }
  256. private bool _bvalue = false;
  257. public bool BoolValue
  258. {
  259. get { return _bvalue; }
  260. set { _bvalue = value; NotifyOfPropertyChange("BoolValue"); }
  261. }
  262. private string _sValue = string.Empty;
  263. public string StringValue
  264. {
  265. get { return _sValue; }
  266. set { _sValue = value; NotifyOfPropertyChange("StringValue"); }
  267. }
  268. private bool _textSaved = true;
  269. public bool TextSaved
  270. {
  271. get { return _textSaved; }
  272. set { _textSaved = value; NotifyOfPropertyChange("TextSaved"); }
  273. }
  274. private string _path = string.Empty;
  275. public string Path
  276. {
  277. get { return _path; }
  278. set { _path = value; NotifyOfPropertyChange("Path"); }
  279. }
  280. public List<Option> Options
  281. {
  282. get
  283. {
  284. List<Option> options = new List<Option>();
  285. foreach (var item in Parameter.Split(';').ToList())
  286. {
  287. Option o = new Option();
  288. o.Name = item;
  289. o.IsChecked = CurrentValue == item;
  290. options.Add(o);
  291. }
  292. return options;
  293. }
  294. }
  295. }
  296. public class Option: PropertyChangedBase
  297. {
  298. private string _Name;
  299. public string Name
  300. {
  301. get { return _Name; }
  302. set { _Name = value; this.NotifyOfPropertyChange(nameof(Name)); }
  303. }
  304. private string _Thick;
  305. public string Thick
  306. {
  307. get { return _Thick; }
  308. set { _Thick = value; this.NotifyOfPropertyChange(nameof(Thick)); }
  309. }
  310. private bool _IsChecked;
  311. public bool IsChecked
  312. {
  313. get { return _IsChecked; }
  314. set { _IsChecked = value; this.NotifyOfPropertyChange(nameof(IsChecked)); }
  315. }
  316. private bool _IsEnable=true;
  317. public bool IsEnable
  318. {
  319. get { return _IsEnable; }
  320. set { _IsEnable = value; this.NotifyOfPropertyChange(nameof(IsEnable)); }
  321. }
  322. private int _Index;
  323. public int Index
  324. {
  325. get { return _Index; }
  326. set { _Index = value; this.NotifyOfPropertyChange(nameof(Index)); }
  327. }
  328. }
  329. }