MeasureMsgManage.cs 7.9 KB

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