MeasureMsgManage.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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.Failed);
  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. }
  68. #endregion
  69. //是否当前编号是流程中有数据的节点
  70. if (IsCutHolePhotoInfo(formHOZ, args))
  71. {
  72. if (!args.Picture_Information.Picture_FullPath.Equals(""))
  73. {
  74. //显示状态信息
  75. ShowStateMessage(formHOZ, args);
  76. //设置图像
  77. //FileStream fileStream = new FileStream(args.Picture_Information.Picture_FullPath, FileMode.Open, FileAccess.Read);
  78. //formHOZ.pbImage.Image = Image.FromStream(fileStream);
  79. //fileStream.Close();
  80. //fileStream.Dispose();
  81. formHOZ.pbImage.Image = GetFile(args.Picture_Information.Picture_FullPath);
  82. //流程内容
  83. double Work_Voltage = args.Picture_Information.Work_Voltage / 1000;
  84. double Magnification = args.Picture_Information.Magnification;
  85. double Work_Distance = args.Picture_Information.Work_Distance * 1000;
  86. string semParaContent = "电压:" + Work_Voltage.ToString("f1") + "KV";
  87. semParaContent += " 放大倍数:" + Magnification + "X";
  88. semParaContent += " 工作距离:" + Work_Distance.ToString("f1") + "mm";
  89. formHOZ.lblFlowContent.Text = semParaContent;
  90. }
  91. }
  92. else
  93. {
  94. if (args.Step_Code!="0-9")
  95. {
  96. formHOZ.lblFlowContent.Text = string.Empty;
  97. }
  98. }
  99. //修改切孔中流程状态
  100. ChageCutHoleFlowNodeState(formHOZ, args);
  101. }
  102. #region 将文件改换为内存流
  103. public static MemoryStream ReadFile(string path)
  104. {
  105. if (!File.Exists(path))
  106. return null;
  107. using (FileStream file = new FileStream(path, FileMode.Open))
  108. {
  109. byte[] b = new byte[file.Length];
  110. file.Read(b, 0, b.Length);
  111. file.Close();
  112. file.Dispose();
  113. MemoryStream stream = new MemoryStream(b);
  114. return stream;
  115. }
  116. }
  117. ///
  118. /// 将内存流转为图片
  119. ///
  120. ///
  121. ///
  122. public static Image GetFile(string path)
  123. {
  124. MemoryStream stream = ReadFile(path);
  125. return stream == null ? null : Image.FromStream(stream);
  126. }
  127. #endregion
  128. /// <summary>
  129. /// 显示状态信息
  130. /// </summary>
  131. /// <param name="formHOZ"></param>
  132. /// <param name="args"></param>
  133. private static void ShowStateMessage(FormHOZMain formHOZ, ThreadStatusEventArgs args)
  134. {
  135. //显示状态信息
  136. if (args.Message == "自动对焦")
  137. {
  138. formHOZ.lblStateMessage.Text = "正在对焦中...请等待";
  139. }
  140. else if (args.Message == "自动像散")
  141. {
  142. formHOZ.lblStateMessage.Text = "正在消像散中...请等待";
  143. }
  144. else if (args.Message == "FIB自动对焦")
  145. {
  146. formHOZ.lblStateMessage.Text = "正在FIB自动对焦中...请等待";
  147. }
  148. else if (args.Message == "自动亮度对比度")
  149. {
  150. formHOZ.lblStateMessage.Text = "正在自动亮度对比度调节中...请等待";
  151. }
  152. else
  153. {
  154. formHOZ.lblStateMessage.Text = "";
  155. }
  156. }
  157. #endregion
  158. #region 显示切孔流程中拍照信息
  159. /// <summary>
  160. /// 是否当前编号是流程中有数据的节点
  161. /// </summary>
  162. /// <param name="formHOZ">主窗体对象</param>
  163. /// <param name="args">线程参数</param>
  164. /// <returns></returns>
  165. public static bool IsCutHolePhotoInfo(FormHOZMain formHOZ, ThreadStatusEventArgs args)
  166. {
  167. if (formHOZ.plPrarInfo.Controls.Count > 0)
  168. {
  169. foreach (Control item in formHOZ.plPrarInfo.Controls)
  170. {
  171. if (item is UserControl)
  172. {
  173. if (item.Name == args.HoleName)
  174. {
  175. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  176. TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
  177. foreach (TimeLineItem tlItem in ParaItem)
  178. {
  179. if (tlItem.Code == args.Step_Code && tlItem.IsData)
  180. {
  181. return true;
  182. }
  183. }
  184. }
  185. }
  186. }
  187. }
  188. return false;
  189. }
  190. #endregion
  191. #region 修改切孔中流程状态
  192. /// <summary>
  193. /// 修改切孔中流程状态
  194. /// </summary>
  195. /// <param name="formHOZ">主窗体对象</param>
  196. /// <param name="cutHoleName">切孔名称</param>
  197. /// <param name="Code">流程编号</param>
  198. /// <param name="state">状态</param>
  199. /// <returns></returns>
  200. public static bool ChageCutHoleFlowNodeState(FormHOZMain formHOZ, ThreadStatusEventArgs args)
  201. {
  202. if (formHOZ.plPrarInfo.Controls.Count > 0)
  203. {
  204. foreach (Control item in formHOZ.plPrarInfo.Controls)
  205. {
  206. if (item is UserControl)
  207. {
  208. if (item.Name == args.HoleName)
  209. {
  210. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  211. TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
  212. foreach (TimeLineItem tlItem in ParaItem)
  213. {
  214. if (tlItem.Code == args.Step_Code)
  215. {
  216. tlItem.State = args.State?1:0;
  217. break;
  218. }
  219. }
  220. //更新进度条
  221. uControl_ParaInfo.UpdateCurrentMeasureSchedule();
  222. //重新绘制
  223. uControl_ParaInfo.TimeLineInvalidate();
  224. return true;
  225. }
  226. }
  227. }
  228. }
  229. return false;
  230. }
  231. #endregion
  232. }
  233. }