MeasureMsgManage.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. using MeasureThread;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. namespace HOZProject
  11. {
  12. public class MeasureMsgManage
  13. {
  14. public enum measureType
  15. {
  16. Photo=0,
  17. FIB=1,
  18. PT=2
  19. }
  20. #region 线程消息处理,显示内容
  21. /// <summary>
  22. /// 线程消息处理,显示内容
  23. /// </summary>
  24. /// <param name="formHOZ">主窗体对象</param>
  25. /// <param name="args">消息对象</param>
  26. public static void ShowMsgContent(FormHOZMain formHOZ, ThreadStatusEventArgs args)
  27. {
  28. #region 判断线程是否停止
  29. switch (args.Step_Code)
  30. {
  31. case "0-0":
  32. //停止线程
  33. //if (formHOZ.m_BackgroundWorker.IsBusy)
  34. //{
  35. // formHOZ.m_BackgroundWorker.CancelAsync();
  36. // //是否关闭窗体的标识
  37. // if (formHOZ.IsClose)
  38. // {
  39. // formHOZ.Close();
  40. // }
  41. //}
  42. break;
  43. case "0-1":
  44. //初始化失败
  45. if (formHOZ.m_BackgroundWorker.IsBusy)
  46. {
  47. //修改切孔状态
  48. formHOZ.ChangeCutHoleState(args.HoleName, (int)ThreadState.InProcess);
  49. }
  50. break;
  51. case "0-8":
  52. case "0-9":
  53. if (!args.Picture_Information.Picture_FullPath.Equals(""))
  54. {
  55. ShowStateMessage(formHOZ, args);
  56. formHOZ.pbImage.Image = GetFile(args.Picture_Information.Picture_FullPath);
  57. //流程内容
  58. double Work_Voltage = args.Picture_Information.Work_Voltage / 1000;
  59. double Magnification = args.Picture_Information.Magnification;
  60. double Work_Distance = args.Picture_Information.Work_Distance * 1000;
  61. string semParaContent = "电压:" + Work_Voltage.ToString("f1") + "KV";
  62. semParaContent += " 放大倍数:" + Magnification + "X";
  63. semParaContent += " 工作距离:" + Work_Distance.ToString("f1") + "mm";
  64. formHOZ.lblFlowContent.Text = semParaContent;
  65. }
  66. break;
  67. case "EDSPic":
  68. if (!args.Picture_Information.Picture_FullPath.Equals(""))
  69. {
  70. //ShowStateMessage(formHOZ, args);
  71. formHOZ.pbImage.Image = GetFile(args.Picture_Information.Picture_FullPath);
  72. //流程内容
  73. //double Work_Voltage = args.Picture_Information.Work_Voltage / 1000;
  74. //double Magnification = args.Picture_Information.Magnification;
  75. //double Work_Distance = args.Picture_Information.Work_Distance * 1000;
  76. //string semParaContent = "电压:" + Work_Voltage.ToString("f1") + "KV";
  77. //semParaContent += " 放大倍数:" + Magnification + "X";
  78. //semParaContent += " 工作距离:" + Work_Distance.ToString("f1") + "mm";
  79. //formHOZ.lblFlowContent.Text = semParaContent;
  80. }
  81. break;
  82. }
  83. #endregion
  84. //是否当前编号是流程中有数据的节点
  85. if (IsCutHolePhotoInfo(formHOZ, args))
  86. {
  87. if (!args.Picture_Information.Picture_FullPath.Equals(""))
  88. {
  89. //显示状态信息
  90. ShowStateMessage(formHOZ, args);
  91. //设置图像
  92. //FileStream fileStream = new FileStream(args.Picture_Information.Picture_FullPath, FileMode.Open, FileAccess.Read);
  93. //formHOZ.pbImage.Image = Image.FromStream(fileStream);
  94. //fileStream.Close();
  95. //fileStream.Dispose();
  96. formHOZ.pbImage.Image = GetFile(args.Picture_Information.Picture_FullPath);
  97. //流程内容
  98. double Work_Voltage = args.Picture_Information.Work_Voltage / 1000;
  99. double Magnification = args.Picture_Information.Magnification;
  100. double Work_Distance = args.Picture_Information.Work_Distance * 1000;
  101. string semParaContent = "电压:" + Work_Voltage.ToString("f1") + "KV";
  102. semParaContent += " 放大倍数:" + Magnification + "X";
  103. semParaContent += " 工作距离:" + Work_Distance.ToString("f1") + "mm";
  104. formHOZ.lblFlowContent.Text = semParaContent;
  105. }
  106. }
  107. else
  108. {
  109. if (args.Step_Code!="0-9")
  110. {
  111. formHOZ.lblFlowContent.Text = string.Empty;
  112. }
  113. }
  114. //修改切孔中流程状态
  115. ChageCutHoleFlowNodeState(formHOZ, args);
  116. }
  117. #region 将文件改换为内存流
  118. public static MemoryStream ReadFile(string path)
  119. {
  120. if (!File.Exists(path))
  121. return null;
  122. using (FileStream file = new FileStream(path, FileMode.Open))
  123. {
  124. byte[] b = new byte[file.Length];
  125. file.Read(b, 0, b.Length);
  126. file.Close();
  127. file.Dispose();
  128. MemoryStream stream = new MemoryStream(b);
  129. return stream;
  130. }
  131. }
  132. ///
  133. /// 将内存流转为图片
  134. ///
  135. ///
  136. ///
  137. public static Image GetFile(string path)
  138. {
  139. MemoryStream stream = ReadFile(path);
  140. return stream == null ? null : Image.FromStream(stream);
  141. }
  142. #endregion
  143. /// <summary>
  144. /// 显示状态信息
  145. /// </summary>
  146. /// <param name="formHOZ"></param>
  147. /// <param name="args"></param>
  148. private static void ShowStateMessage(FormHOZMain formHOZ, ThreadStatusEventArgs args)
  149. {
  150. //显示状态信息
  151. if (args.Message == "自动对焦")
  152. {
  153. formHOZ.lblStateMessage.Text = "正在对焦中...请等待";
  154. }
  155. else if (args.Message == "自动像散")
  156. {
  157. formHOZ.lblStateMessage.Text = "正在消像散中...请等待";
  158. }
  159. else if (args.Message == "FIB自动对焦")
  160. {
  161. formHOZ.lblStateMessage.Text = "正在FIB自动对焦中...请等待";
  162. }
  163. else if (args.Message == "自动亮度对比度")
  164. {
  165. formHOZ.lblStateMessage.Text = "正在自动亮度对比度调节中...请等待";
  166. }
  167. else
  168. {
  169. formHOZ.lblStateMessage.Text = "";
  170. }
  171. }
  172. #endregion
  173. #region 显示切孔流程中拍照信息
  174. /// <summary>
  175. /// 是否当前编号是流程中有数据的节点
  176. /// </summary>
  177. /// <param name="formHOZ">主窗体对象</param>
  178. /// <param name="args">线程参数</param>
  179. /// <returns></returns>
  180. public static bool IsCutHolePhotoInfo(FormHOZMain formHOZ, ThreadStatusEventArgs args)
  181. {
  182. if (formHOZ.plPrarInfo.Controls.Count > 0)
  183. {
  184. foreach (Control item in formHOZ.plPrarInfo.Controls)
  185. {
  186. if (item is UserControl)
  187. {
  188. if (item.Name == args.HoleName)
  189. {
  190. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  191. TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
  192. foreach (TimeLineItem tlItem in ParaItem)
  193. {
  194. if (tlItem.Code == args.Step_Code && tlItem.IsData)
  195. {
  196. return true;
  197. }
  198. }
  199. }
  200. }
  201. }
  202. }
  203. return false;
  204. }
  205. #endregion
  206. #region 修改切孔中流程状态
  207. /// <summary>
  208. /// 修改切孔中流程状态
  209. /// </summary>
  210. /// <param name="formHOZ">主窗体对象</param>
  211. /// <param name="cutHoleName">切孔名称</param>
  212. /// <param name="Code">流程编号</param>
  213. /// <param name="state">状态</param>
  214. /// <returns></returns>
  215. public static bool ChageCutHoleFlowNodeState(FormHOZMain formHOZ, ThreadStatusEventArgs args)
  216. {
  217. if (formHOZ.plPrarInfo.Controls.Count > 0)
  218. {
  219. foreach (Control item in formHOZ.plPrarInfo.Controls)
  220. {
  221. if (item is UserControl)
  222. {
  223. if (item.Name == args.HoleName)
  224. {
  225. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  226. TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
  227. //TimeLineItem nextItem=null;
  228. var timelinectrl = uControl_ParaInfo.GetUctrTimeLine();
  229. for (int i=0; i<ParaItem.Count(); i++)
  230. {
  231. var tlItem = ParaItem[i];
  232. if (tlItem.Code == args.Step_Code)//找到与通告步骤号相对应的条目
  233. {
  234. tlItem.State = args.State?1:0;//更新当前完成timeline 条目的状态,仅有1和0。
  235. //if (i + 1 < ParaItem.Count())//如果下一个条目的编号是在条目集合内,就可以找到下一个条目
  236. //{
  237. timelinectrl.twinkleItem = tlItem;//
  238. //}
  239. //if(nextItem!=null)
  240. //timelinectrl.twinkleItem = nextItem;//把下一个条目置为闪烁条目
  241. //把闪烁条目之前的条目全部置为1,也就是全部变为绿色
  242. for (int j = 0; j < i ; j++)
  243. {
  244. ParaItem[j].State = 1;
  245. }
  246. break;
  247. }
  248. }
  249. //更新进度条
  250. uControl_ParaInfo.UpdateCurrentMeasureSchedule();
  251. //重新绘制
  252. uControl_ParaInfo.TimeLineInvalidate();
  253. return true;
  254. }
  255. }
  256. }
  257. }
  258. return false;
  259. }
  260. #endregion
  261. }
  262. }