MeasureMsgManage.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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.Step_Code == "1-2")
  116. {
  117. formHOZ.lblStateMessage.Text = "正在对焦中...请等待";
  118. }
  119. else
  120. {
  121. formHOZ.lblStateMessage.Text = "";
  122. }
  123. }
  124. #endregion
  125. #region 显示切孔流程中拍照信息
  126. /// <summary>
  127. /// 是否当前编号是流程中有数据的节点
  128. /// </summary>
  129. /// <param name="formHOZ">主窗体对象</param>
  130. /// <param name="args">线程参数</param>
  131. /// <returns></returns>
  132. public static bool IsCutHolePhotoInfo(FormHOZMain formHOZ, ThreadStatusEventArgs args)
  133. {
  134. if (formHOZ.plPrarInfo.Controls.Count > 0)
  135. {
  136. foreach (Control item in formHOZ.plPrarInfo.Controls)
  137. {
  138. if (item is UserControl)
  139. {
  140. if (item.Name == args.HoleName)
  141. {
  142. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  143. TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
  144. foreach (TimeLineItem tlItem in ParaItem)
  145. {
  146. if (tlItem.Code == args.Step_Code && tlItem.IsData)
  147. {
  148. return true;
  149. }
  150. }
  151. }
  152. }
  153. }
  154. }
  155. return false;
  156. }
  157. #endregion
  158. #region 修改切孔中流程状态
  159. /// <summary>
  160. /// 修改切孔中流程状态
  161. /// </summary>
  162. /// <param name="formHOZ">主窗体对象</param>
  163. /// <param name="cutHoleName">切孔名称</param>
  164. /// <param name="Code">流程编号</param>
  165. /// <param name="state">状态</param>
  166. /// <returns></returns>
  167. public static bool ChageCutHoleFlowNodeState(FormHOZMain formHOZ, ThreadStatusEventArgs args)
  168. {
  169. if (formHOZ.plPrarInfo.Controls.Count > 0)
  170. {
  171. foreach (Control item in formHOZ.plPrarInfo.Controls)
  172. {
  173. if (item is UserControl)
  174. {
  175. if (item.Name == args.HoleName)
  176. {
  177. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  178. TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
  179. foreach (TimeLineItem tlItem in ParaItem)
  180. {
  181. if (tlItem.Code == args.Step_Code)
  182. {
  183. tlItem.State = args.State?1:0;
  184. break;
  185. }
  186. }
  187. //更新进度条
  188. uControl_ParaInfo.UpdateCurrentMeasureSchedule();
  189. //重新绘制
  190. uControl_ParaInfo.TimeLineInvalidate();
  191. return true;
  192. }
  193. }
  194. }
  195. }
  196. return false;
  197. }
  198. #endregion
  199. }
  200. }