OTSMeasureDisplayResult.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. 
  2. using OTSModelSharp;
  3. using OTSDataType;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Drawing;
  9. using System.Windows.Forms;
  10. using static OTSDataType.otsdataconst;
  11. using OTSMeasureApp._1_OTSMeasure.Measure._3_MeasureFlow;
  12. using OTSModelSharp.ServiceCenter;
  13. namespace OTSMeasureApp
  14. {
  15. class OTSMeasureDisplayResult
  16. {
  17. NLog.Logger log ;
  18. public enum ProgressState
  19. {
  20. MeasureCheckReport = 1,
  21. MeasureResult = 2
  22. }
  23. #region 变量生成汇总
  24. OTSIncAMeasureAppForm m_MeasureApp = null;
  25. //样品台窗口对象
  26. public OTSSamplespaceWindow m_OTSSamplespaceWindow = null;
  27. //测量进度信息窗口对象
  28. public MeasureCheckResultInfoWindow m_MeasureCheckReportInfoWindow = null;
  29. //测量结果信息窗口对象
  30. public OTSMeasureResultWindow m_OTSMeasureResultWindow = null;
  31. //在窗体TAB测量状态中显示BSE图
  32. public OTSMeasureStatusWindow m_OTSMeasureStatusWindow = null;
  33. public OTSPropertyWindow m_SPropertyWindows = null;
  34. public System.ComponentModel.BackgroundWorker m_bgWorker;
  35. ST_MSTMsg MeasureResultMsrData;
  36. #endregion
  37. #region 构造方法
  38. public OTSMeasureDisplayResult( OTSIncAMeasureAppForm m_MeasureApps ,BackgroundWorker a_bgWorker)
  39. {
  40. log = NLog.LogManager.GetCurrentClassLogger();
  41. m_MeasureApp = m_MeasureApps;
  42. m_OTSSamplespaceWindow = m_MeasureApps.m_SamplepaceWindow;
  43. m_OTSMeasureResultWindow = m_MeasureApp.m_MeasureResultWindow;
  44. m_SPropertyWindows = m_MeasureApp.m_SPropertyWindows;
  45. m_OTSMeasureStatusWindow = m_MeasureApp.m_MessureStatuWindow;
  46. Control.CheckForIllegalCrossThreadCalls = false;
  47. //测量结束信息窗口对象
  48. m_MeasureCheckReportInfoWindow = new MeasureCheckResultInfoWindow();
  49. m_bgWorker = a_bgWorker;
  50. //设置报告更新是否可用
  51. m_bgWorker.WorkerReportsProgress = true;
  52. //设置支持取消操作是否可用
  53. m_bgWorker.WorkerSupportsCancellation = true;
  54. m_bgWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
  55. }
  56. private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
  57. {
  58. ReportProgress((ProgressState)e.ProgressPercentage);
  59. }
  60. #endregion
  61. #region 修改窗体控件的响应事件_ProgressChanged
  62. //这里就是通过响应消息,来处理界面的显示工作
  63. private void ReportProgress(ProgressState state)
  64. {
  65. try
  66. {
  67. if (state == ProgressState.MeasureCheckReport)
  68. {
  69. DisMeasureResultInfo(MeasureResultMsrData);
  70. }
  71. //测量结果
  72. if (state == ProgressState.MeasureResult)
  73. {
  74. if (m_OTSMeasureResultWindow == null)
  75. {
  76. //实例窗体
  77. m_OTSMeasureResultWindow = m_MeasureApp.m_MeasureResultWindow;
  78. }
  79. //获取工作样品信息
  80. COTSSample WSample = m_MeasureApp.m_ProjParam.GetWorkSample();
  81. CMsrResultItems MsrResults = WSample.GetMsrResults();
  82. //获取结果文件 颗粒列表信息
  83. List<CMsrResultItem> cMsrResultItemClrList = MsrResults.GetResultItems();
  84. //设置测量状态数据列表
  85. m_OTSMeasureResultWindow.SetMeasureListInfo(cMsrResultItemClrList);
  86. }
  87. }
  88. catch (Exception ex)
  89. {
  90. log.Error(ex.ToString());
  91. }
  92. }
  93. #endregion
  94. #region 打开测量结果窗口
  95. /// <summary>
  96. /// 打开测量结果窗口
  97. /// </summary>
  98. public void DisMeasureResultInfo(ST_MSTMsg sMSR)
  99. {
  100. //打开测量结果窗体
  101. if (m_MeasureCheckReportInfoWindow.IsDisposed)
  102. {
  103. m_MeasureCheckReportInfoWindow = new MeasureCheckResultInfoWindow();
  104. }
  105. SetMeasureResultInfo(sMSR);
  106. m_MeasureCheckReportInfoWindow.Activate();
  107. m_MeasureCheckReportInfoWindow.Show();
  108. }
  109. #endregion
  110. #region 显示BSE图片
  111. public double[] GetStaticGaryData(byte[] Imagedata, double[] GrayLevelData)
  112. {
  113. try
  114. {
  115. //获得下标每一点的灰度值,并在数组里加一
  116. for (int i = 0; i < Imagedata.Length; i++)
  117. {
  118. byte graylevel = Imagedata[i];
  119. if (graylevel > 0 && graylevel < 255)
  120. {
  121. GrayLevelData[graylevel] += 1;
  122. }
  123. }
  124. return GrayLevelData;
  125. }
  126. catch (Exception ex)
  127. {
  128. log.Error(ex.ToString());
  129. return null;
  130. }
  131. }
  132. #endregion
  133. #region 设置测量结束窗体中信息内容
  134. public void SetMeasureResultInfo(ST_MSTMsg SMsrData)
  135. {
  136. //设置开始时间
  137. string startTime = SMsrData.STMThreadStu.SMsrCompleteData.csMsrStartTime;
  138. //设置结束时间
  139. string endTime = SMsrData.STMThreadStu.SMsrCompleteData.csMsrEndTime;
  140. //设置测量数
  141. int completeSampleCount = SMsrData.STMThreadStu.SMsrCompleteData.iMsrCompleteSampleCount;
  142. //设置帧图数
  143. int completeFieldCount = SMsrData.STMThreadStu.SMsrCompleteData.iMsrCompleteFieldCount;
  144. //颗粒数
  145. int particleCount = SMsrData.STMThreadStu.SMsrCompleteData.iParticleCount;
  146. //用时
  147. TimeSpan measureTime = SMsrData.STMThreadStu.SMsrCompleteData.MsrUsedTime;
  148. string measureState = string.Empty;
  149. OTSCommon.Language lan = new OTSCommon.Language();
  150. Hashtable table= lan.GetNameTable("OTSMeasureResultWindow");
  151. //状态
  152. switch (SMsrData.STMThreadStu.iMsrStatu)
  153. {
  154. case OTS_MSR_THREAD_STATUS.COMPLETED:
  155. measureState = table["state1"].ToString();
  156. break;
  157. case OTS_MSR_THREAD_STATUS.FAILED:
  158. measureState = table["state2"].ToString();
  159. break;
  160. case OTS_MSR_THREAD_STATUS.STOPPED:
  161. measureState = table["state3"].ToString();
  162. break;
  163. }
  164. //设置测量结果窗体信息
  165. string measureTimes = string.Empty;
  166. m_MeasureCheckReportInfoWindow.SetMeasureStateInfo(measureState, completeSampleCount, completeFieldCount, particleCount, startTime, measureTime, endTime, ref measureTimes);
  167. }
  168. #endregion
  169. public void MeasureComplete(ST_MSTMsg SMsrData)
  170. {
  171. string inprocessEndTime = SMsrData.STMThreadStu.csMsrEndTime;
  172. //获取需显示的grid信息
  173. var sample = m_MeasureApp.m_ProjParam.GetWorkSample();
  174. var stype = m_MeasureApp.m_ProjParam.GetDefaultParam().GetSysType();
  175. OTSSampleVisualPropertyInfo MeasureInfo = new OTSSampleVisualPropertyInfo(sample, stype);
  176. m_MeasureApp.m_SPropertyWindows.DisplaySampleMeasureInfo(MeasureInfo);
  177. SetMeasureResultInfo(SMsrData);
  178. MeasureResultMsrData = SMsrData;
  179. m_bgWorker.ReportProgress((int)ProgressState.MeasureCheckReport);
  180. }
  181. #region 测量方法
  182. public void Field_START_MSR(ST_MSTMsg SMsrData)
  183. {
  184. var sam1 = m_MeasureApp.m_SamplepaceWindow.GetWorkingVisualSample();
  185. m_MeasureApp.m_SamplepaceWindow.ChangeMeasureFieldColor(sam1, SMsrData.STMSampleRetData.SMsrField.FieldPos, Color.Yellow);
  186. m_MeasureApp.m_SamplepaceWindow.Invalidate();
  187. }
  188. public void Field_DATA(ST_MSTMsg SMsrData)
  189. {
  190. m_OTSMeasureResultWindow.SetMeasureTime(SMsrData.STMSampleRetData.SFieldData.TUsedTime);
  191. //---------update the progress bar测量状态进度窗口
  192. var FieldData =SMsrData.STMSampleRetData.SFieldData;
  193. //样品测量中的总帧图数
  194. int MeasureFieldTotalCount = FieldData.iMeasureFieldCount;
  195. //样品测量中当前已测量的帧图数
  196. int CompleteFieldCount = FieldData.iCompleteFieldCount;
  197. int ParticleCount = FieldData.iSParticleCount;
  198. if (CompleteFieldCount >= 0 && MeasureFieldTotalCount >= 0)
  199. {
  200. m_bgWorker.ReportProgress((int)ProgressState.MeasureResult);
  201. //设置当前进度信息(当前Field数量与Field总数)
  202. m_OTSMeasureResultWindow.SetCurrentProgressInfo(CompleteFieldCount, MeasureFieldTotalCount, ParticleCount);
  203. }
  204. //-----------
  205. var sam = m_MeasureApp.m_SamplepaceWindow.GetWorkingVisualSample();
  206. m_MeasureApp.m_SamplepaceWindow.ChangeMeasureFieldColor(sam, SMsrData.STMSampleRetData.SFieldData.FieldPos, Color.Green);
  207. m_MeasureApp.m_SamplepaceWindow.Invalidate();
  208. }
  209. public void Dis_Field_BSE_DATA(byte[] ImageData,int width,int height)
  210. {
  211. //设置图像数据与状态
  212. OTSMeasureStatusWindow.bfResult = true;
  213. m_MeasureApp.m_MessureStatuWindow.originalBseData = ImageData;
  214. //删除点标记
  215. m_MeasureApp.m_MessureStatuWindow.DelElementPointGDIObjects();
  216. Bitmap bitmap = CImageHandler.ToGrayBitmap(ImageData, width, height);
  217. //显示BSE图
  218. m_MeasureApp.m_MessureStatuWindow.ShowDoubleImage(bitmap, null);
  219. }
  220. public void Dis_Field_BSE_REMOVEBG_DATA(Bitmap ImageData)
  221. {
  222. m_MeasureApp.m_MessureStatuWindow.ShowDoubleImage(null, ImageData);
  223. }
  224. public void SampleStart(ST_MSTMsg SMsrData)
  225. {
  226. //获取样品名称
  227. string sampleName = SMsrData.STMSampleStu.cSampleName;
  228. //样品测量开始时间
  229. string csSampleMsrStartTime = SMsrData.STMSampleStu.csSampleMsrStartTime;
  230. //设置样品名称
  231. if (sampleName != "")
  232. {
  233. m_MeasureApp.m_SamplepaceWindow.SetSampleOrder(sampleName);
  234. if (m_MeasureApp.GetRunType() == MSR_RUN_TYPE.RUNMEASURE)
  235. {
  236. m_OTSMeasureResultWindow.SetSampleName(sampleName);
  237. }
  238. m_MeasureApp.m_SamplepaceWindow.Invalidate();
  239. //设置开始时间
  240. m_OTSMeasureResultWindow.SetStartTime(csSampleMsrStartTime);
  241. }
  242. //切换样品
  243. m_MeasureApp.SwitchWSample(sampleName);
  244. //设置样品名称
  245. m_OTSMeasureResultWindow.SetSampleName(sampleName);
  246. }
  247. public void MeasureStopped(ST_MSTMsg SMsrData)
  248. {
  249. string stopEndTime = SMsrData.STMThreadStu.csMsrEndTime;
  250. //打开测量结果窗口
  251. SetMeasureResultInfo(SMsrData);
  252. MeasureResultMsrData = SMsrData;
  253. m_bgWorker.ReportProgress((int)ProgressState.MeasureCheckReport);
  254. //测量停止,更新Grid显示的测量信息
  255. //获取需显示的grid信息
  256. var sample = m_MeasureApp.m_ProjParam.GetWorkSample();
  257. var stype = m_MeasureApp.m_ProjParam.GetDefaultParam().GetSysType();
  258. OTSSampleVisualPropertyInfo MeasureInfo = new OTSSampleVisualPropertyInfo(sample, stype);
  259. m_MeasureApp.m_SPropertyWindows.DisplaySampleMeasureInfo(MeasureInfo);
  260. }
  261. public void MeasureFailed(ST_MSTMsg SMsrData)
  262. {
  263. string failedEndTime = SMsrData.STMThreadStu.csMsrEndTime;
  264. SetMeasureResultInfo(SMsrData);
  265. MeasureResultMsrData = SMsrData;
  266. m_bgWorker.ReportProgress((int)ProgressState.MeasureCheckReport);
  267. //测量失败,更新Grid显示的测量信息
  268. //获取需显示的grid信息
  269. var sample = m_MeasureApp.m_ProjParam.GetWorkSample();
  270. var stype = m_MeasureApp.m_ProjParam.GetDefaultParam().GetSysType();
  271. OTSSampleVisualPropertyInfo MeasureInfo = new OTSSampleVisualPropertyInfo(sample, stype);
  272. m_MeasureApp.m_SPropertyWindows.DisplaySampleMeasureInfo(MeasureInfo);
  273. }
  274. #endregion
  275. }
  276. }