RobotCycleViewModel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. using Aitex.Core.UI.MVVM;
  2. using CyberX8_Core;
  3. using CyberX8_MainPages.Roles;
  4. using CyberX8_MainPages.Views;
  5. using MECF.Framework.Common.ControlDataContext;
  6. using MECF.Framework.Common.DataCenter;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.OperationCenter;
  9. using MECF.Framework.Common.Utilities;
  10. using OpenSEMI.ClientBase.Command;
  11. using Prism.Mvvm;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Collections.ObjectModel;
  15. using System.Linq;
  16. using System.Reflection;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Windows.Forms;
  20. using System.Windows.Input;
  21. using System.Windows.Threading;
  22. namespace CyberX8_MainPages.ViewModels
  23. {
  24. public class RobotCycleViewModel : BindableBase
  25. {
  26. #region 内部变量
  27. /// <summary>
  28. /// 选择的LP
  29. /// </summary>
  30. private ModuleName _selectedLPName = ModuleName.LP1;
  31. private ModuleName _selectedAlignerName = ModuleName.Aligner1;
  32. /// <summary>
  33. /// 选择的Dummy
  34. /// </summary>
  35. private ModuleName _selectedDummyName = ModuleName.Dummy1;
  36. private ModuleName _selectedSrdName = ModuleName.SRD1;
  37. private ModuleName _selectedPufName = ModuleName.PUF1;
  38. /// <summary>
  39. /// 输入的Cycle次数
  40. /// </summary>
  41. private int _inPutCycleTimes = 1;
  42. /// <summary>
  43. /// Align调整角度度数
  44. /// </summary>
  45. private int _inPutAlignDegree = 0;
  46. /// <summary>
  47. /// 当前正在执行第几次Cycle
  48. /// </summary>
  49. private int _currentCycle;
  50. /// <summary>
  51. /// 是否选中dummy
  52. /// </summary>
  53. private bool _isDummySelected = false;
  54. /// <summary>
  55. /// 是否选中srd
  56. /// </summary>
  57. private bool _isSrdSelected = false ;
  58. /// <summary>
  59. /// 是否选中puf
  60. /// </summary>
  61. private bool _isPufSelected = false;
  62. private bool _isSrd1Checked = true;
  63. private bool _isSrd2Checked = false;
  64. private bool _isDummy1Checked = true;
  65. private bool _isDummy2Checked = false;
  66. #region 系统数据
  67. /// <summary>
  68. /// 定时器
  69. /// </summary>
  70. DispatcherTimer _timer;
  71. /// <summary>
  72. /// 查询后台数据集合
  73. /// </summary>
  74. private List<string> _rtDataKeys = new List<string>();
  75. /// <summary>
  76. /// rt查询key数值字典
  77. /// </summary>
  78. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  79. #endregion
  80. #endregion
  81. #region 属性
  82. public ModuleName SelectedLPName
  83. {
  84. get { return _selectedLPName; }
  85. set { SetProperty(ref _selectedLPName, value); }
  86. }
  87. public ModuleName SelectedAlignerName
  88. {
  89. get { return _selectedAlignerName; }
  90. set { SetProperty(ref _selectedAlignerName, value); }
  91. }
  92. public ModuleName SelectedDummyName
  93. {
  94. get { return _selectedDummyName; }
  95. set { SetProperty(ref _selectedDummyName, value); }
  96. }
  97. public ModuleName SelectedSrdName
  98. {
  99. get { return _selectedSrdName; }
  100. set { SetProperty(ref _selectedSrdName, value); }
  101. }
  102. public ModuleName SelectedPufName
  103. {
  104. get { return _selectedPufName; }
  105. set { SetProperty(ref _selectedPufName, value); }
  106. }
  107. public int InPutCycleTimes
  108. {
  109. get { return _inPutCycleTimes; }
  110. set { SetProperty(ref _inPutCycleTimes, value); }
  111. }
  112. public int CurrentCycle
  113. {
  114. get { return _currentCycle; }
  115. set { SetProperty(ref _currentCycle, value); }
  116. }
  117. public int InPutAlignDegree
  118. {
  119. get { return _inPutAlignDegree; }
  120. set { SetProperty(ref _inPutAlignDegree, value); }
  121. }
  122. public bool IsDummySelected
  123. {
  124. get { return _isDummySelected; }
  125. set { SetProperty(ref _isDummySelected, value); }
  126. }
  127. public bool IsSrdSelected
  128. {
  129. get { return _isSrdSelected; }
  130. set { SetProperty(ref _isSrdSelected, value); }
  131. }
  132. public bool IsPufSelected
  133. {
  134. get { return _isPufSelected; }
  135. set { SetProperty(ref _isPufSelected, value); }
  136. }
  137. public bool IsSrd1Checkd
  138. {
  139. get { return _isSrd1Checked; }
  140. set { SetProperty(ref _isSrd1Checked, value); }
  141. }
  142. public bool IsSrd2Checkd
  143. {
  144. get { return _isSrd2Checked; }
  145. set { SetProperty(ref _isSrd2Checked, value); }
  146. }
  147. public bool IsDummy1Checkd
  148. {
  149. get { return _isDummy1Checked; }
  150. set { SetProperty(ref _isDummy1Checked, value); }
  151. }
  152. public bool IsDummy2Checkd
  153. {
  154. get { return _isDummy2Checked; }
  155. set { SetProperty(ref _isDummy2Checked, value); }
  156. }
  157. #endregion
  158. #region 命令
  159. public ICommand RobotCycleStartCommand { get; set; }
  160. public ICommand RobotCycleAbortCommand { get; set; }
  161. public ICommand LPChangeCommand { get; set; }
  162. public ICommand AlignerChangeCommand { get; set; }
  163. public ICommand PufChangeCommand { get; set; }
  164. public ICommand DummyChangeCommand { get; set; }
  165. public ICommand SrdChangeCommand { get; set; }
  166. #endregion
  167. /// <summary>
  168. /// 构造器
  169. /// </summary>
  170. public RobotCycleViewModel()
  171. {
  172. RobotCycleStartCommand = new DelegateCommand<object>(RobotCycleStartAction);
  173. RobotCycleAbortCommand = new DelegateCommand<object>(RobotCycleAbortAction);
  174. LPChangeCommand = new DelegateCommand<object>(LPChangeAction);
  175. AlignerChangeCommand = new DelegateCommand<object>(AlignerChangeAction);
  176. //PufChangeCommand = new DelegateCommand<object>(PufChangeAction);
  177. //DummyChangeCommand = new DelegateCommand<object>(DummyChangeAction);
  178. //SrdChangeCommand = new DelegateCommand<object>(SrdChangeAction);
  179. }
  180. private void RobotCycleStartAction(object param)
  181. {
  182. if (!IsDummySelected)
  183. {
  184. SelectedDummyName = ModuleName.Unknown;
  185. }
  186. else
  187. {
  188. if (IsDummy1Checkd)
  189. {
  190. SelectedDummyName = ModuleName.Dummy1;
  191. }
  192. else
  193. {
  194. SelectedDummyName = ModuleName.Dummy2;
  195. }
  196. }
  197. if (!IsSrdSelected)
  198. {
  199. SelectedSrdName = ModuleName.Unknown;
  200. }
  201. else
  202. {
  203. if (IsSrd1Checkd)
  204. {
  205. SelectedSrdName = ModuleName.SRD1;
  206. }
  207. else
  208. {
  209. SelectedSrdName = ModuleName.SRD2;
  210. }
  211. }
  212. if (!IsPufSelected)
  213. {
  214. SelectedPufName = ModuleName.Unknown;
  215. }
  216. else
  217. {
  218. SelectedPufName = ModuleName.PUF1;
  219. }
  220. if (!IsDummySelected && !IsSrdSelected)
  221. {
  222. MessageBox.Show("Selected at least on module between srd and dummy!");
  223. return;
  224. }
  225. List<string> sequences = new List<string>();
  226. sequences.Add(SelectedLPName.ToString());
  227. sequences.Add(SelectedAlignerName.ToString());
  228. if (SelectedPufName != ModuleName.Unknown)
  229. {
  230. sequences.Add(SelectedPufName.ToString());
  231. }
  232. if (SelectedSrdName != ModuleName.Unknown)
  233. {
  234. sequences.Add(SelectedSrdName.ToString());
  235. }
  236. if (SelectedDummyName != ModuleName.Unknown)
  237. {
  238. sequences.Add(SelectedDummyName.ToString());
  239. }
  240. InvokeClient.Instance.Service.DoOperation($"EFEM.{EfemOperation.RobotCycle}",string.Join("-",sequences), InPutCycleTimes, InPutAlignDegree);
  241. }
  242. private void RobotCycleAbortAction(object param)
  243. {
  244. InvokeClient.Instance.Service.DoOperation($"{ModuleName.EfemRobot}.{EfemOperation.Abort}");
  245. }
  246. private void LPChangeAction(object param)
  247. {
  248. if ("LP1".Equals((string)param))
  249. {
  250. SelectedLPName = ModuleName.LP1;
  251. }
  252. else if ("LP2".Equals((string)param))
  253. {
  254. SelectedLPName = ModuleName.LP2;
  255. }
  256. else
  257. {
  258. SelectedLPName = ModuleName.LP3;
  259. }
  260. }
  261. private void AlignerChangeAction(object param)
  262. {
  263. }
  264. private void PufChangeAction(object param)
  265. {
  266. }
  267. private void DummyChangeAction(object param)
  268. {
  269. if ("Dummy1".Equals((string)param))
  270. {
  271. SelectedDummyName = ModuleName.Dummy1;
  272. }
  273. else
  274. {
  275. SelectedDummyName = ModuleName.Dummy2;
  276. }
  277. }
  278. private void SrdChangeAction(object param)
  279. {
  280. if ("SRD1".Equals((string)param))
  281. {
  282. SelectedSrdName = ModuleName.SRD1;
  283. }
  284. else
  285. {
  286. SelectedSrdName = ModuleName.SRD2;
  287. }
  288. }
  289. /// <summary>
  290. /// 加载数据
  291. /// </summary>
  292. public void LoadData(string systemName)
  293. {
  294. _rtDataKeys.Clear();
  295. _rtDataKeys.Add("EFEM.CurrentRobotCycleTime");
  296. if (_timer == null)
  297. {
  298. _timer = new DispatcherTimer();
  299. _timer.Interval = TimeSpan.FromMilliseconds(200);
  300. _timer.Tick += Timer_Tick;
  301. }
  302. _timer.Start();
  303. }
  304. /// <summary>
  305. /// 定时器执行
  306. /// </summary>
  307. /// <param name="sender"></param>
  308. /// <param name="e"></param>
  309. private void Timer_Tick(object sender, EventArgs e)
  310. {
  311. if (_rtDataKeys.Count != 0)
  312. {
  313. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  314. if (_rtDataValueDic != null)
  315. {
  316. CurrentCycle = CommonFunction.GetValue<int>(_rtDataValueDic, $"EFEM.CurrentRobotCycleTime");
  317. }
  318. }
  319. }
  320. /// <summary>
  321. /// 隐藏
  322. /// </summary>
  323. public void Hide()
  324. {
  325. }
  326. }
  327. }