MeasureMsgManage.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. file.Close();
  93. file.Dispose();
  94. MemoryStream stream = new MemoryStream(b);
  95. return stream;
  96. }
  97. }
  98. ///
  99. /// 将内存流转为图片
  100. ///
  101. ///
  102. ///
  103. public static Image GetFile(string path)
  104. {
  105. MemoryStream stream = ReadFile(path);
  106. return stream == null ? null : Image.FromStream(stream);
  107. }
  108. #endregion
  109. /// <summary>
  110. /// 显示状态信息
  111. /// </summary>
  112. /// <param name="formHOZ"></param>
  113. /// <param name="args"></param>
  114. private static void ShowStateMessage(FormHOZMain formHOZ, ThreadStatusEventArgs args)
  115. {
  116. //显示状态信息
  117. if (args.Message == "自动对焦")
  118. {
  119. formHOZ.lblStateMessage.Text = "正在对焦中...请等待";
  120. }
  121. else if (args.Message == "自动像散")
  122. {
  123. formHOZ.lblStateMessage.Text = "正在消像散中...请等待";
  124. }
  125. else if (args.Message == "FIB自动对焦")
  126. {
  127. formHOZ.lblStateMessage.Text = "正在FIB自动对焦中...请等待";
  128. }
  129. else
  130. {
  131. formHOZ.lblStateMessage.Text = "";
  132. }
  133. }
  134. #endregion
  135. #region 显示切孔流程中拍照信息
  136. /// <summary>
  137. /// 是否当前编号是流程中有数据的节点
  138. /// </summary>
  139. /// <param name="formHOZ">主窗体对象</param>
  140. /// <param name="args">线程参数</param>
  141. /// <returns></returns>
  142. public static bool IsCutHolePhotoInfo(FormHOZMain formHOZ, ThreadStatusEventArgs args)
  143. {
  144. if (formHOZ.plPrarInfo.Controls.Count > 0)
  145. {
  146. foreach (Control item in formHOZ.plPrarInfo.Controls)
  147. {
  148. if (item is UserControl)
  149. {
  150. if (item.Name == args.HoleName)
  151. {
  152. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  153. TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
  154. foreach (TimeLineItem tlItem in ParaItem)
  155. {
  156. if (tlItem.Code == args.Step_Code && tlItem.IsData)
  157. {
  158. return true;
  159. }
  160. }
  161. }
  162. }
  163. }
  164. }
  165. return false;
  166. }
  167. #endregion
  168. #region 修改切孔中流程状态
  169. /// <summary>
  170. /// 修改切孔中流程状态
  171. /// </summary>
  172. /// <param name="formHOZ">主窗体对象</param>
  173. /// <param name="cutHoleName">切孔名称</param>
  174. /// <param name="Code">流程编号</param>
  175. /// <param name="state">状态</param>
  176. /// <returns></returns>
  177. public static bool ChageCutHoleFlowNodeState(FormHOZMain formHOZ, ThreadStatusEventArgs args)
  178. {
  179. if (formHOZ.plPrarInfo.Controls.Count > 0)
  180. {
  181. foreach (Control item in formHOZ.plPrarInfo.Controls)
  182. {
  183. if (item is UserControl)
  184. {
  185. if (item.Name == args.HoleName)
  186. {
  187. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  188. TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
  189. foreach (TimeLineItem tlItem in ParaItem)
  190. {
  191. if (tlItem.Code == args.Step_Code)
  192. {
  193. tlItem.State = args.State?1:0;
  194. break;
  195. }
  196. }
  197. //更新进度条
  198. uControl_ParaInfo.UpdateCurrentMeasureSchedule();
  199. //重新绘制
  200. uControl_ParaInfo.TimeLineInvalidate();
  201. return true;
  202. }
  203. }
  204. }
  205. }
  206. return false;
  207. }
  208. #endregion
  209. }
  210. }