PartialPressureViewModel.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. using LiveCharts;
  2. using MECF.Framework.Common.DataCenter;
  3. using MECF.Framework.Common.OperationCenter;
  4. using Microsoft.Win32;
  5. using Prism.Commands;
  6. using Prism.Mvvm;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Threading;
  15. using Venus_Core;
  16. //using Venus_Core;
  17. using Venus_MainPages.Unity;
  18. using Venus_Unity;
  19. namespace Venus_MainPages.ViewModels
  20. {
  21. internal class PartialPressureViewModel : BindableBase
  22. {
  23. #region 私有字段
  24. private Dictionary<int, string> m_GasFlows = new Dictionary<int, string>();
  25. //private object[] m_GasPressures = new object[10];
  26. public string ModuleName;
  27. private int m_GasIndex;
  28. ChartValues<double> m_CurrentLineSeries= new ChartValues<double>();
  29. ChartValues<double> m_ReferenceLineSeries = new ChartValues<double>();
  30. Dictionary<int, string> CurrentGasFlows = new Dictionary<int, string>();
  31. DispatcherTimer timer = new DispatcherTimer();
  32. private int m_GasTime;
  33. private string m_GasName;
  34. private PartialPressureResult m_partialPressureResult;
  35. string value;
  36. int maxScale;
  37. ObservableCollection<string> m_ReferenceFlow = new ObservableCollection<string>();
  38. private bool m_MFC7IsEnable;
  39. private bool m_MFC8IsEnable;
  40. private bool m_MFC9IsEnable;
  41. private bool m_MFC10IsEnable;
  42. private bool m_MFC11IsEnable;
  43. private bool m_MFC12IsEnable;
  44. private bool m_IsAutoMode;
  45. private PressureType m_PressureType;
  46. #endregion
  47. #region 属性
  48. public PressureType PressureType
  49. {
  50. get { return m_PressureType; }
  51. set { SetProperty(ref m_PressureType, value); }
  52. }
  53. public ObservableCollection<string> ReferenceFlow
  54. {
  55. get { return m_ReferenceFlow; }
  56. set { SetProperty(ref m_ReferenceFlow, value); }
  57. }
  58. public Dictionary<int, string> GasFlows
  59. {
  60. get { return m_GasFlows; }
  61. set { SetProperty(ref m_GasFlows, value); }
  62. }
  63. public ChartValues<double> CurrentLineSeries
  64. {
  65. get { return m_CurrentLineSeries; }
  66. set { SetProperty(ref m_CurrentLineSeries, value); }
  67. }
  68. public ChartValues<double> ReferenceLineSeries
  69. {
  70. get { return m_ReferenceLineSeries; }
  71. set { SetProperty(ref m_ReferenceLineSeries, value); }
  72. }
  73. public int GasTime
  74. {
  75. get { return m_GasTime; }
  76. set { SetProperty(ref m_GasTime, value); }
  77. }
  78. public string GasName
  79. {
  80. get { return m_GasName; }
  81. set { SetProperty(ref m_GasName, value); }
  82. }
  83. public bool MFC7IsEnable
  84. {
  85. get { return m_MFC7IsEnable; }
  86. set { SetProperty(ref m_MFC7IsEnable, value); }
  87. }
  88. public bool MFC8IsEnable
  89. {
  90. get { return m_MFC8IsEnable; }
  91. set { SetProperty(ref m_MFC8IsEnable, value); }
  92. }
  93. public bool MFC9IsEnable
  94. {
  95. get { return m_MFC9IsEnable; }
  96. set { SetProperty(ref m_MFC9IsEnable, value); }
  97. }
  98. public bool MFC10IsEnable
  99. {
  100. get { return m_MFC10IsEnable; }
  101. set { SetProperty(ref m_MFC10IsEnable, value); }
  102. }
  103. public bool MFC11IsEnable
  104. {
  105. get { return m_MFC11IsEnable; }
  106. set { SetProperty(ref m_MFC11IsEnable, value); }
  107. }
  108. public bool MFC12IsEnable
  109. {
  110. get { return m_MFC12IsEnable; }
  111. set { SetProperty(ref m_MFC12IsEnable, value); }
  112. }
  113. public bool IsAutoMode
  114. {
  115. get { return m_IsAutoMode; }
  116. set { SetProperty(ref m_IsAutoMode, value); }
  117. }
  118. #endregion
  119. #region 命令
  120. private DelegateCommand<object> _SelectGasCommand;
  121. public DelegateCommand<object> SelectGasCommand =>
  122. _SelectGasCommand ?? (_SelectGasCommand = new DelegateCommand<object>(OnSelectGas));
  123. private DelegateCommand _StartCommand;
  124. public DelegateCommand StartCommand =>
  125. _StartCommand ?? (_StartCommand = new DelegateCommand(OnStart));
  126. private DelegateCommand _SaveCommand;
  127. public DelegateCommand SaveCommand =>
  128. _SaveCommand ?? (_SaveCommand = new DelegateCommand(OnSave));
  129. private DelegateCommand _LoadReferenceCommand;
  130. public DelegateCommand LoadReferenceCommand =>
  131. _LoadReferenceCommand ?? (_LoadReferenceCommand = new DelegateCommand(OnLoadReference));
  132. private DelegateCommand _AbortCommand;
  133. public DelegateCommand AbortCommand =>
  134. _AbortCommand ?? (_AbortCommand = new DelegateCommand(OnAbort));
  135. private DelegateCommand _LoadCommand;
  136. public DelegateCommand LoadCommand =>
  137. _LoadCommand ?? (_LoadCommand = new DelegateCommand(OnLoad));
  138. #endregion
  139. #region 构造函数
  140. public PartialPressureViewModel()
  141. {
  142. GasTime = 60;
  143. for (int i = 1; i < 11; i++)
  144. {
  145. GasFlows.Add(i, (10 * i).ToString());
  146. }
  147. timer.Interval = TimeSpan.FromSeconds(1);
  148. timer.Tick += Timer_Tick;
  149. }
  150. #endregion
  151. #region 命令方法
  152. private void OnLoad()
  153. {
  154. var jetChamber = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.ChamberType").ToString());
  155. if (jetChamber == JetChamber.Kepler2200A || jetChamber == JetChamber.Kepler2200B)
  156. {
  157. PressureType = PressureType.Pa;
  158. }
  159. }
  160. private void OnSelectGas(object obj)
  161. {
  162. CurrentGasFlows.Clear();
  163. value = $"MfcGas{obj.ToString()}";
  164. maxScale= Convert.ToInt32(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.{value}.MfcN2Scale"));
  165. var xishu = Convert.ToDouble(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.{value}.MfcScaleFactor"));
  166. GasName = QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.{value}.GasName").ToString();
  167. for (int i = 1; i < 11; i++)
  168. {
  169. CurrentGasFlows.Add(i, (maxScale * xishu / 10 * i).ToString());
  170. }
  171. GasFlows = CurrentGasFlows;
  172. m_GasIndex = Convert.ToInt32(obj);
  173. }
  174. private void OnStart()
  175. {
  176. timer.Start();
  177. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.PartialPressureTest", m_GasIndex,1000* GasTime);
  178. }
  179. private void OnSave()
  180. {
  181. SerializeHelper.Instance.WriteToJsonFile<PartialPressureResult>(m_partialPressureResult, $"PartialPressureResult/{m_partialPressureResult.GasName}/{DateTime.Now.ToString("yyyyMMddHHmm")}.json");
  182. }
  183. private void OnLoadReference()
  184. {
  185. OpenFileDialog dialog = new OpenFileDialog();
  186. dialog.Filter = ".json|*.json";
  187. dialog.InitialDirectory = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "PartialPressureResult");
  188. if (dialog.ShowDialog() == true)
  189. {
  190. string SelectedPath = dialog.FileName;
  191. var value = SerializeHelper.Instance.ReadFromJsonFile<PartialPressureResult>(SelectedPath);
  192. ReferenceLineSeries.Clear();
  193. ReferenceFlow.Clear();
  194. value.ValuePairs.ForEach(x =>
  195. {
  196. ReferenceFlow.Add(x.Flow);
  197. ReferenceLineSeries.Add(x.Pressure);
  198. });
  199. }
  200. else
  201. {
  202. ReferenceLineSeries.Clear();
  203. //ReferenceLineSeries.Insert(20, 0);
  204. ReferenceLineSeries.Add(0);
  205. ReferenceFlow.Clear();
  206. }
  207. }
  208. private void OnAbort()
  209. {
  210. timer.Stop();
  211. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Abort");
  212. CurrentLineSeries = new ChartValues<double>();
  213. }
  214. #endregion
  215. #region 私有方法
  216. private void Timer_Tick(object sender, EventArgs e)
  217. {
  218. CurrentLineSeries.Clear();
  219. var values = QueryDataClient.Instance.Service.GetData($"{ModuleName}.PartialPressureResult").ToString();
  220. values.Split(',').ToList().ForEach(x =>
  221. {
  222. if (x != "")
  223. {
  224. CurrentLineSeries.Add(Math.Round(Convert.ToDouble(x), 3));
  225. }
  226. });
  227. if (CurrentLineSeries.Count == 10)
  228. {
  229. timer.Stop();
  230. }
  231. IsAutoMode = (bool)QueryDataClient.Instance.Service.GetData($"{ModuleName}.IsOnline");
  232. }
  233. public void Init()
  234. {
  235. var jetChamber = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.ChamberType").ToString());
  236. if (jetChamber != JetChamber.Kepler2200A && jetChamber != JetChamber.Kepler2200B)
  237. {
  238. MFC7IsEnable = (bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas7.Enable");
  239. MFC8IsEnable = (bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas8.Enable");
  240. }
  241. if (jetChamber == JetChamber.VenusSE|| jetChamber == JetChamber.VenusDE)
  242. {
  243. MFC9IsEnable = (bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas9.Enable");
  244. MFC10IsEnable = (bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas10.Enable");
  245. MFC11IsEnable = (bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas11.Enable");
  246. MFC12IsEnable = (bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas12.Enable");
  247. }
  248. }
  249. #endregion
  250. }
  251. }