CSmplMeasure.cs 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using OTSModelSharp.ServiceCenter;
  5. using static OTSDataType.otsdataconst;
  6. using OTSDataType;
  7. using System.Drawing;
  8. using System.Threading;
  9. using OTSCLRINTERFACE;
  10. using OTSMeasureApp._0_OTSModel.OTSDataType;
  11. using System.Windows.Forms;
  12. using System.Data;
  13. using System.IO;
  14. using OTSMeasureApp._1_OTSMeasure.Measure._3_MeasureFlow;
  15. namespace OTSModelSharp
  16. {
  17. using CHoleBSEImgsList = List<CHoleBSEImg>;
  18. public class CSmplMeasure
  19. {
  20. protected static NLog.Logger log ;
  21. protected bool bSaveThreadWorking;
  22. protected System.Threading.Thread m_thread_ptr;
  23. protected COTSSample m_Sample;
  24. protected COTSSample m_HolePreviewSample;
  25. protected CMeasure m_pMsrThread;
  26. string m_strWorkingFolder;
  27. protected CSmplMsrResult m_pSampleRstFile;
  28. CHoleBSEImgsList m_listHoleBSEImg;
  29. protected ISemController m_SemHardwareMgr;
  30. protected IScanController m_ScanHardwareMgr;
  31. protected IEDSController m_EDSController;
  32. protected Queue<COTSField> fieldQueue=new Queue<COTSField>();
  33. protected IClassifyEngine m_classifyEngine;
  34. private bool m_ifAquireClearParticleImage=false;
  35. public CSmplMeasure( string a_strWorkingFolder, COTSSample a_pSample)
  36. {
  37. m_Sample = a_pSample;
  38. log = NLog.LogManager.GetCurrentClassLogger();
  39. var expC = m_Sample.GetMsrParams().GetXRayParam().GetAnalyExpCount();
  40. var imgwidth = m_Sample.GetMsrParams().GetImageScanParam().GetImageResolutionSize().cx;
  41. var imgheight = m_Sample.GetMsrParams().GetImageScanParam().GetImageResolutionSize().cy;
  42. m_strWorkingFolder = a_strWorkingFolder;
  43. m_pSampleRstFile = new CSmplMsrResult( a_strWorkingFolder, a_pSample);
  44. m_SemHardwareMgr = SemController.GetSEMController();
  45. m_ScanHardwareMgr = ScanController.GetScanController();
  46. var ifautoid = m_Sample.GetMsrParams().GetXRayParam().IfAutoId;
  47. var knownelements = m_Sample.GetMsrParams().GetXRayParam().AnalysisElements;
  48. m_EDSController = EDSController.GetEDSController(imgwidth,imgheight,expC,ifautoid,knownelements);
  49. m_listHoleBSEImg = new CHoleBSEImgsList();
  50. m_Sample = a_pSample;
  51. m_ifAquireClearParticleImage = FileHelper.GetIfAquireClearParticleImage();
  52. }
  53. public void SetSample(COTSSample a_pSample)
  54. {
  55. m_Sample = a_pSample;
  56. m_pSampleRstFile.SetSample(a_pSample);
  57. }
  58. public COTSSample GetSample() { return m_Sample; }
  59. public void SetHolePreviewSample(COTSSample a_pSample)
  60. {
  61. m_HolePreviewSample = a_pSample;
  62. }
  63. public COTSSample GetHolePreviewSample() { return m_HolePreviewSample; }
  64. public void SetMsrThread(CMeasure mt)
  65. {
  66. m_pMsrThread = mt;
  67. }
  68. bool SetSEMDataMrs(COTSSample sample)
  69. {
  70. var pSEMDataMsr = sample.GetSEMDataMsr();
  71. double dMag = pSEMDataMsr.GetMagnification();
  72. double dWorkDis = pSEMDataMsr.GetWorkingDistance();
  73. var pSEMCtrl = m_pMsrThread.GetSEMController();
  74. pSEMCtrl.SetMagnification(dMag);
  75. pSEMCtrl.SetWorkingDistance(dWorkDis);
  76. return true;
  77. }
  78. bool SetSEMExteralOn()
  79. {
  80. var pSEMCtrl = m_SemHardwareMgr;
  81. log.Warn("Set Scan Exteral on!");
  82. pSEMCtrl.SetScanExternal(true);
  83. return true;
  84. }
  85. // set SEM external off
  86. bool SetSEMExteralOff()
  87. {
  88. var pSEMCtrlPtr = m_SemHardwareMgr;
  89. log.Warn("Set SEM Exteral Off!");
  90. pSEMCtrlPtr.SetScanExternal(false);
  91. return true;
  92. }
  93. bool SetBSEParam()
  94. {
  95. // get scan controller
  96. var pScanController = m_ScanHardwareMgr;
  97. // scan parameters
  98. var pMsrParam = m_Sample.GetMsrParams();
  99. var pImgScanParam = pMsrParam.GetImageScanParam();
  100. // get image size
  101. var nImageSizeId = pImgScanParam.GetImageResulotion();
  102. int nResulotionId = RESOLUTION_ID_FIRST_TIE + (int)nImageSizeId;
  103. Size sizePixelImage = RESOLUTION_VALUE[nResulotionId];
  104. // get dwell time
  105. OTS_IMAGE_SCANSPEED_OPTIONS nDwellTime = pImgScanParam.GetScanImageSpeed();
  106. // convert dwell time to bruker dwell time
  107. DwellTimeLevel DwellTimeId;
  108. switch (nDwellTime)
  109. {
  110. case OTS_IMAGE_SCANSPEED_OPTIONS.low:
  111. DwellTimeId = DwellTimeLevel.Low;
  112. break;
  113. case OTS_IMAGE_SCANSPEED_OPTIONS.meddium:
  114. DwellTimeId = DwellTimeLevel.Medium;
  115. break;
  116. case OTS_IMAGE_SCANSPEED_OPTIONS.high:
  117. DwellTimeId = DwellTimeLevel.High;
  118. break;
  119. default:
  120. DwellTimeId = DwellTimeLevel.Low;
  121. break;
  122. }
  123. //long nBrukerDwellTime = OTSDataType.otsdataconst.DWELLTIME_BRUKER_VALUES[DwellTimeId];
  124. if (!pScanController.Init())
  125. {
  126. log.Error("SetBSEParam: failed to get scan control.");
  127. return false;
  128. }
  129. // set dwell time
  130. if (!pScanController.SetDwellTime(DwellTimeId))
  131. {
  132. //log.Error("SetBSEParam: failed to set dwell time (%d) for bruker system.", nBrukerDwellTime);
  133. return false;
  134. }
  135. // set image size
  136. if (!pScanController.SetImageSize(sizePixelImage.Width,sizePixelImage.Height))
  137. {
  138. // failed to set dwell time
  139. log.Error("SetBSEParam: failed to set dwell time (%d).", sizePixelImage.Height);
  140. return false;
  141. }
  142. return true;
  143. }
  144. bool SetHoleBSEParam(COTSSample sample)
  145. {
  146. // get scan controller
  147. var pScanController = m_ScanHardwareMgr;
  148. // scan parameters
  149. var pMsrParam = sample.GetMsrParams();
  150. var pImgScanParam = pMsrParam.GetImageScanParam();
  151. // get image size
  152. var nImageSizeId = pImgScanParam.GetImageResulotion();
  153. int nResulotionId = RESOLUTION_ID_FIRST_TIE + (int)nImageSizeId;
  154. Size sizePixelImage = RESOLUTION_VALUE[nResulotionId];
  155. // get dwell time
  156. OTS_IMAGE_SCANSPEED_OPTIONS nDwellTime = pImgScanParam.GetScanImageSpeed();
  157. // convert dwell time to bruker dwell time
  158. //long nBrukerDwellTime = DWELLTIME_BRUKER_VALUES[2];// choose the third option, so the dwell time will be 4 . there's no need to change here. it shoud be a const.
  159. if (!pScanController.Init())
  160. {
  161. log.Error("SetBSEParam: failed to get scan control.");
  162. return false;
  163. }
  164. // set dwell time
  165. if (!pScanController.SetDwellTime(DwellTimeLevel.Low))
  166. {
  167. //log.Error("SetBSEParam: failed to set dwell time (%d) for bruker system.", nBrukerDwellTime);
  168. return false;
  169. }
  170. // set image size
  171. if (!pScanController.SetImageSize(sizePixelImage.Width/2, sizePixelImage.Height/2))
  172. {
  173. // failed to set dwell time
  174. log.Error("SetBSEParam: failed to set ImageSize");
  175. return false;
  176. }
  177. return true;
  178. }
  179. public void SetWorkingFolder(String a_strWorkingFolder)
  180. {
  181. // add "\\" at the string end if it is not "\\"
  182. if (a_strWorkingFolder.PadRight(1)!="\\")
  183. {
  184. a_strWorkingFolder += "\\";
  185. }
  186. m_strWorkingFolder = a_strWorkingFolder + m_Sample.GetName() + "\\";
  187. }
  188. bool CalculateUnMeasuredHoleImgCenters(COTSSample sample, out List<System.Drawing.Point> a_allpieldcenter, out List<System.Drawing.Point> a_listUnMsrFieldCenter)
  189. {
  190. // sample measure parameters
  191. CSampleParam pMsrParam = sample.GetMsrParams();
  192. COTSImgScanPrm poImageScanParam = pMsrParam.GetImageScanParam();
  193. COTSImageProcParam pImgProcParam = pMsrParam.GetImageProcessParam();
  194. CSEMDataMsr poSEMDataMsr = sample.GetSEMDataMsr();
  195. CMsrSampleStatus pStatus = sample.GetMsrStatus();
  196. // measured field centers list
  197. List<System.Drawing.PointF> listCompletedCenter = pStatus.GetCompletedFieldsCenter();
  198. // field centers list manager
  199. CFieldPositionHelper pFieldMgr = new CFieldPositionHelper();
  200. // init field centers list manager
  201. if (!pFieldMgr.Init(sample.GetMsrDomain(), poImageScanParam,0, poSEMDataMsr, listCompletedCenter))
  202. {
  203. log.Error("CalculateFieldsCenters: failed to init field centres list manager.");
  204. a_listUnMsrFieldCenter = new List<System.Drawing.Point>();
  205. a_allpieldcenter = new List<Point>();
  206. return false;
  207. }
  208. // get field centers list
  209. a_listUnMsrFieldCenter = pFieldMgr.GetUnmeasuredFieldCentrePoints();// GetFieldCentrePoints();
  210. a_allpieldcenter = pFieldMgr.GetFieldCentrePoints();
  211. // ok, return TRUE
  212. return true;
  213. }
  214. protected bool IsAborted()
  215. {
  216. return m_pMsrThread.IsMeasureStopped();
  217. }
  218. protected bool IsPaused()
  219. {
  220. var statu = m_pMsrThread.GetMsrThreadStatus();
  221. if (statu.GetStatus() == OTS_MSR_THREAD_STATUS.PAUSED)
  222. {
  223. return true;
  224. }
  225. else
  226. {
  227. return false;
  228. }
  229. }
  230. bool IsSampleOver(COTSImgScanPrm a_pScanParam)
  231. {
  232. string sStopMode = a_pScanParam.GetStopMode();
  233. int nStopField = a_pScanParam.GetStopParamFields();
  234. // completed fields number
  235. CMsrSampleStatus pMsrSampleStatus = m_Sample.GetMsrStatus();
  236. int nCompeltedField = pMsrSampleStatus.GetCompletedFields();
  237. CMsrResultItems pMsrResults = m_Sample.GetMsrResults();
  238. List<CMsrResultItem> listMsrResult = pMsrResults.GetResultItems();
  239. int nNumParticle = 0;
  240. foreach (var pResult in listMsrResult)
  241. {
  242. if (pResult.GetTypeId() > (int)OTS_PARTICLE_TYPE.NOT_IDENTIFIED)//summarize the number of the identified particle in this condition
  243. {
  244. nNumParticle += (int)pResult.GetNumber();
  245. }
  246. }
  247. TimeSpan timeSpan = pMsrSampleStatus.GetUsedTime();
  248. int nDay = timeSpan.Days;
  249. int nHour = timeSpan.Hours;
  250. int nMin = timeSpan.Minutes;
  251. int nSec = timeSpan.Seconds;
  252. int nUsedTime = nSec + nMin * 60 + nHour * 3600 + nDay * 86400;
  253. int NMeasArea = (int)pMsrResults.GetMeasuredArea();
  254. int nParticlAim = a_pScanParam.GetStopParamParticles();
  255. int nMeasTimeAim = a_pScanParam.GetStopParamMeasTime();
  256. int NMeasAreaAim = a_pScanParam.GetStopParamArea()*1000000 ;
  257. bool bRet = false;
  258. string[] str = sStopMode.Replace(" ", "").Split('+');
  259. for(int i=0;i< str.Length;i++)
  260. {
  261. switch (int.Parse(str[i].Split(':')[0])-1)
  262. {
  263. case (int)OTS_MEASURE_STOP_MODE.CoverMode:
  264. // completed fields number
  265. if (nCompeltedField == m_Sample.GetFieldsData().Count)
  266. {
  267. bRet = true;
  268. }
  269. break;
  270. case (int)OTS_MEASURE_STOP_MODE.FieldMode:
  271. if (nCompeltedField >= nStopField)
  272. {
  273. bRet = true;
  274. }
  275. break;
  276. case (int)OTS_MEASURE_STOP_MODE.ParticleMode:
  277. if (nNumParticle >= nParticlAim)
  278. {
  279. bRet = true;
  280. }
  281. break;
  282. case (int)OTS_MEASURE_STOP_MODE.TimeMode:
  283. if (nUsedTime >= nMeasTimeAim)
  284. {
  285. bRet = true;
  286. }
  287. break;
  288. case (int)OTS_MEASURE_STOP_MODE.AreaMode:
  289. if (NMeasArea >= NMeasAreaAim)
  290. {
  291. bRet = true;
  292. }
  293. break;
  294. default:
  295. break;
  296. }
  297. }
  298. return bRet;
  299. }
  300. // move SEM to the point
  301. bool MoveSEMToPoint(System.Drawing.PointF a_poi)
  302. {
  303. // get SEM controller
  304. var pSEMController = m_SemHardwareMgr;
  305. PointF a_SEMpt = new Point();
  306. CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
  307. int hardWareDelay = a_pCSEMStageData.GetHardWareDelay();
  308. if (!a_pCSEMStageData.ConvertOTSToSEMCoord(a_poi, ref a_SEMpt))
  309. {
  310. return false;
  311. }
  312. log.Info("Begin to move SEM stage to OTScoord:" + a_poi.X + "," + a_poi.Y);
  313. log.Info("Begin to move SEM stage to " + a_SEMpt.X + "," + a_SEMpt.Y);
  314. // move SEM to the position (rotation 0)
  315. if (!pSEMController.MoveSEMToPoint(a_SEMpt.X, a_SEMpt.Y))
  316. {
  317. log.Error("MoveSEMToPoint: failed to call MoveSEMToPoint method.");
  318. return false;
  319. }
  320. CSampleParam pMsrParam = m_Sample.GetMsrParams();
  321. if (pMsrParam.SlopParam.IsUsingSlopParam)
  322. {
  323. double wd = pMsrParam.SlopParam.GetWD(a_SEMpt);
  324. double originWd = 0;
  325. pSEMController.GetWorkingDistance(ref originWd);
  326. if ((wd - originWd) > 2)
  327. {
  328. log.Warn("Working Distance is invalid,outof the moving scope(2cm) wd=" + wd.ToString("F2"));
  329. }
  330. else
  331. {
  332. Thread.Sleep(hardWareDelay);
  333. pSEMController.SetWorkingDistance(wd);
  334. }
  335. }
  336. if (hardWareDelay > 0)
  337. {
  338. Thread.Sleep(hardWareDelay);
  339. }
  340. return true;
  341. }
  342. // Acquire a BSE image
  343. CBSEImgClr AcquireABSEImage()
  344. {
  345. // BSE image
  346. CBSEImgClr pBSEImage = null;
  347. // get scan controller
  348. var pScanController = m_ScanHardwareMgr;
  349. pBSEImage = pScanController.AcquireBSEImage();
  350. return pBSEImage;
  351. }
  352. public bool IsLowCounts(COTSParticleClr particle)
  353. {
  354. COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
  355. if (pXRayParam.GetUsingXray() == true)
  356. {
  357. var thecount = particle.GetXray().GetTotalCount();
  358. var expect = pXRayParam.GetAnalyExpCount();
  359. if (thecount < expect)
  360. {
  361. particle.SetType((int)OTS_PARTICLE_TYPE.LOW_COUNT);
  362. particle.SetClassifyId((int)OTS_PARTICLE_TYPE.LOW_COUNT);
  363. particle.SetTypeColor("#000000");
  364. particle.SetTypeName("LowCounts");
  365. return true;
  366. }
  367. }
  368. return false;
  369. }
  370. public virtual void ClassifyFieldParticles(COTSField curFldData)
  371. {
  372. return;
  373. }
  374. private class SEMStateObject
  375. {
  376. private PointF pos;
  377. private double workingDistance;
  378. private CSEMDataGnr semdata;
  379. private COTSSample originalSample;
  380. private double magnification;
  381. public PointF Pos { get => pos; set => pos = value; }
  382. public double WorkingDistance { get => workingDistance; set => workingDistance = value; }
  383. public CSEMDataGnr Semdata { get => semdata; set => semdata = value; }
  384. public double Magnification { get => magnification; set => magnification = value; }
  385. public COTSSample OriginalSample { get => originalSample; set => originalSample = value; }
  386. }
  387. private class AutoResetSEMControl:IDisposable
  388. {
  389. CSmplMeasure sm;
  390. private SEMStateObject semState=null;
  391. public AutoResetSEMControl(CSmplMeasure s)
  392. {
  393. sm = s;
  394. }
  395. public SEMStateObject SemState
  396. {
  397. get => semState;
  398. set => semState = value;
  399. }
  400. public void Dispose()
  401. {
  402. if (semState != null)
  403. {
  404. sm.SetBSEParam();
  405. sm.m_SemHardwareMgr.SetMagnification(semState.Magnification);
  406. Thread.Sleep(100);
  407. sm.MoveSEMToPoint(semState.Pos);
  408. Thread.Sleep(100);
  409. sm.m_SemHardwareMgr.SetWorkingDistance(semState.WorkingDistance);
  410. }
  411. sm.SetSEMExteralOff();
  412. }
  413. }
  414. private bool GetSEMDataGnrFromHw(ref CSEMDataGnr SemDataGnr)
  415. {
  416. double kv = 0, brightness = 0, contrast = 0;
  417. var hw = SemController.GetSEMController();
  418. hw.GetSemHighTension(ref kv);
  419. hw.GetSemBrightness(ref brightness);
  420. hw.GetSemContrast(ref contrast);
  421. SemDataGnr.SetValue(kv, brightness, contrast);
  422. return true;
  423. }
  424. public void DoMeasureForOneSample()
  425. {
  426. using (AutoResetSEMControl autoReset = new AutoResetSEMControl(this)) //when this method exit ,the SetSEMExternalOff and ResetScan will be called automatically.
  427. {
  428. // let the main thread to know that this sample measurement starts
  429. var pStatus = m_Sample.GetMsrStatus();
  430. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.INPROCESS);
  431. // set current time to current time
  432. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.START);
  433. // let main App know that the sample begin to measure
  434. ST_MSTMsg MsgSmpStart = new ST_MSTMsg(m_Sample);
  435. MsgSmpStart.InitSampleStartMsg();
  436. m_pMsrThread.SendMessageToMeasureGUI(MsgSmpStart);
  437. log.Info(m_Sample.GetName() + " Measurement started!");
  438. // get SEM controller to set magnification and working distance
  439. if (!SetSEMDataMrs(m_Sample))
  440. {
  441. log.Error("DoMeasure: fail to set SEM data.");
  442. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  443. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  444. return;
  445. }
  446. // set the BSE scan param
  447. if (!SetBSEParam())
  448. {
  449. log.Error("DoMeasure: fail to set BSE param.");
  450. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  451. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  452. return;
  453. }
  454. var pSEMDataGnr = new CSEMDataGnr();
  455. log.Info("Get Kv, Brightness and Contrast!");
  456. GetSEMDataGnrFromHw(ref pSEMDataGnr);
  457. m_pSampleRstFile.SetSEMGnr(pSEMDataGnr);
  458. // record SEM data
  459. COTSMsrPrjResultData pProjMgrFile = m_pMsrThread.GetProjResultData();
  460. CSEMStageData pSEMStageData = pProjMgrFile.GetSEMStageData();
  461. m_pSampleRstFile.SetSEMStageData(pSEMStageData);
  462. // record stage
  463. CStage pStage = pProjMgrFile.GetStage();
  464. m_pSampleRstFile.SetSEMStage(pStage);
  465. //-----save the static measure result file data into xml file and the dynamic data of every field will be saved into sqlite database
  466. log.Info("Create result file!");
  467. if (!m_pSampleRstFile.CreateResultFiles())
  468. {// failed to call measure result file Save method
  469. log.Error("DoMeasure: failed to call measure result file Save method.");
  470. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  471. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  472. return;
  473. }
  474. //------
  475. var FldDatas = m_Sample.GetFieldsData();
  476. for (int i = 0; i < FldDatas.Count; ++i)
  477. {// check and break if stop button is clicked
  478. var curFld = FldDatas[i];
  479. if (curFld.GetIsMeasureComplete())
  480. {
  481. continue;
  482. }
  483. if (IsPaused())
  484. {// measure stopped
  485. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.PAUSED);
  486. // record end time
  487. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  488. //must wait for the saving data thread finished,or we'll get null pointer exception when we stop the measure process.
  489. while (fieldQueue.Count() > 0)
  490. {
  491. Thread.Sleep(100);
  492. }
  493. SetSEMExteralOff();
  494. // update thread measure status class, let the main thread know that this sample measurement stopped
  495. ST_MSTMsg MsgSmpStop = new ST_MSTMsg(m_Sample);
  496. MsgSmpStop.InitSamplePausedMsg();
  497. m_pMsrThread.SendMessageToMeasureGUI(MsgSmpStop);
  498. while (IsPaused())
  499. {
  500. Thread.Sleep(300);
  501. }
  502. }
  503. if (IsAborted())
  504. {// measure stopped
  505. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.STOPPED);
  506. // record end time
  507. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  508. //must wait for the saving data thread finished,or we'll get null pointer exception when we stop the measure process.
  509. while (fieldQueue.Count() > 0)
  510. {
  511. Thread.Sleep(100);
  512. }
  513. break;
  514. }
  515. // check if sample measurement completes
  516. COTSImgScanPrm pScanParam = m_Sample.GetMsrParams().GetImageScanParam();
  517. if (IsSampleOver(pScanParam))
  518. {
  519. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
  520. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.COMPLT);
  521. break;
  522. }
  523. // get a field center
  524. System.Drawing.PointF poiFieldCentre = curFld.GetOTSPosition();
  525. // update thread measure status class, let the main thread know that starts a new field
  526. ST_MSTMsg MsgFieldStart = new ST_MSTMsg(m_Sample,curFld);
  527. MsgFieldStart.InitFieldStartMsg();
  528. m_pMsrThread.SendMessageToMeasureGUI(MsgFieldStart);
  529. int fldNo = curFld.GetId();
  530. log.Warn("Current field:" + fldNo.ToString());
  531. // move SEM to the field center
  532. if (!MoveSEMToPoint(poiFieldCentre))
  533. {// failed to move SEM to the position
  534. log.Error("DoMeasure: failed to move SEM to the field centre point.");
  535. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  536. // record end time
  537. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  538. return;
  539. }
  540. log.Info("Begin to Acquire BSE image!");
  541. // take BSE image for the fields
  542. CBSEImgClr pBSEImg = AcquireABSEImage();
  543. // let the main thread to know that image process is completed
  544. if (pBSEImg == null)
  545. {
  546. log.Error("ImageProcess: can't get BSE image.");
  547. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  548. return;
  549. }
  550. curFld.SetBSEImage(pBSEImg);
  551. //BSEData
  552. ST_MSTMsg MsgFieldBSE = new ST_MSTMsg(m_Sample,curFld);
  553. MsgFieldBSE.InitFieldBSEImageMsg();
  554. m_pMsrThread.SendMessageToMeasureGUI(MsgFieldBSE);
  555. log.Info("Acquire BSE image success! Processing image...");
  556. // image process
  557. FieldImageProcess(curFld);
  558. MsgFieldBSE.InitFieldBSEAnalysisPartsDataMsg();
  559. m_pMsrThread.SendMessageToMeasureGUI(MsgFieldBSE);
  560. if (m_ifAquireClearParticleImage)
  561. {
  562. var listAnalysisParts = curFld.GetListAnalysisParticles();
  563. foreach (var p in listAnalysisParts)
  564. {
  565. Rectangle r = (Rectangle)p.GetParticleRect();
  566. var img = m_ScanHardwareMgr.AcquireRectangleBSEImage(r);
  567. if (img != null)
  568. {
  569. curFld.particleImages.Add(img);
  570. }
  571. }
  572. }
  573. COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
  574. if (pXRayParam.GetUsingXray() == true)
  575. {
  576. foreach (var p in curFld.GetListAnalysisParticles())
  577. {
  578. p.SetIsXrayParticle(true);
  579. }
  580. CollectParticlesXrayData(curFld);
  581. }
  582. m_Sample.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
  583. curFld.SetIsMeasureComplete(true);
  584. log.Info("Begin to classify particles! particle num:" + curFld.GetListAnalysisParticles().Count);
  585. ClassifyFieldParticles(curFld);
  586. MsgFieldBSE.InitFieldSTDColoredPartsDataMsg();
  587. m_pMsrThread.SendMessageToMeasureGUI(MsgFieldBSE);
  588. //start db save
  589. StartSaveFileThread(ref curFld);
  590. SendFieldParticlesInfoToGUI(curFld, m_Sample.GetMsrStatus());
  591. }
  592. while (bSaveThreadWorking)//wait untill all the field data has been saved.
  593. {
  594. Thread.Sleep(1000);
  595. log.Warn("db saving!");
  596. }
  597. TheLastWorkOfSampleMeasure();
  598. }
  599. }
  600. public void TheLastWorkOfSampleMeasure()
  601. {
  602. COTSSample theSample = m_Sample;
  603. var pStatus = theSample.GetMsrStatus();
  604. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.COMPLT);
  605. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
  606. // let main thread to know that this sample measurement completes
  607. ST_MSTMsg MsgSmplEnd = new ST_MSTMsg(m_Sample);
  608. MsgSmplEnd.InitSampleCompleteMsg();
  609. m_pMsrThread.SendMessageToMeasureGUI(MsgSmplEnd);
  610. string userdB = m_Sample.GetMsrParams().GetSTDName();
  611. if(userdB.ToLower() != "nostddb" && userdB.ToLower() != "nostddb.db")
  612. {
  613. try
  614. {
  615. string userdBpath= System.Windows.Forms.Application.StartupPath + "\\Config\\SysData\\" + m_Sample.GetMsrParams().GetSTDName() + ".db";
  616. File.Copy(userdBpath, m_pSampleRstFile.GetFieldFileSubFolderStr().Remove(m_pSampleRstFile.GetFieldFileSubFolderStr().IndexOf("FIELD_FILES")) + m_Sample.GetMsrParams().GetSTDName() + ".db", true);
  617. }
  618. catch(Exception ex)
  619. {
  620. MessageBox.Show("userdB copy failed:" + ex.ToString());
  621. }
  622. }
  623. }
  624. public bool DoMEasureForReMeasure()
  625. {
  626. return true;
  627. }
  628. public virtual void FieldImageProcess(COTSField curFldData)
  629. {
  630. PointF fldCenter = curFldData.GetOTSPosition();
  631. CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
  632. PointF semPos = new Point();
  633. a_pCSEMStageData.ConvertOTSToSEMCoord(fldCenter, ref semPos);
  634. curFldData.SetSemPos(semPos);
  635. //first step:remove background of the bse image and compound all the finded particles.
  636. log.Info("Begin to process image and get all particles!");
  637. //according to the ECD scope,filter out the effective particles,remove the noise.
  638. curFldData.GetOriginalParticles(m_Sample.GetMsrParams(), m_Sample.CalculatePixelSize());
  639. log.Info("Begin to filter particles!");
  640. curFldData.FilterParticles(m_Sample.GetMsrParams().GetXRayParam());//filter according to the xraylimit
  641. log.Info("Begin to Calculate the image property of every particle!");
  642. var analysisparts = curFldData.GetListAnalysisParticles();
  643. curFldData.CalParticleImageProp(analysisparts);//calculate particle image property such as feret diameter, DMAX etc.
  644. CSampleParam pMsrParam = m_Sample.GetMsrParams();
  645. COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
  646. curFldData.SelectParticlesAccordingImgProp(pImgProcessParam);
  647. var overlap = pImgProcessParam.GetOverlapParam();
  648. if (overlap > 0)
  649. {
  650. curFldData.RemoveDuplicateOverlapParticles(overlap);
  651. }
  652. curFldData.CalculateParticleAbsolutPos(m_pMsrThread.GetProjResultData().GetSEMStageData());
  653. curFldData.InitParticles(pImgProcessParam);
  654. return ;
  655. }
  656. public virtual void CollectParticlesXrayData(COTSField curFldData)
  657. {
  658. var allParts = curFldData.GetListXrayParticles();
  659. var smallparts = new List<COTSParticleClr>();
  660. var bigparts = new List<COTSParticleClr>();
  661. double quantifyThreshold = m_Sample.GetMsrParams().GetXRayParam().GetFeatureModeMinSize();
  662. foreach (var part in allParts)
  663. {
  664. double equalCircleDiameter = Math.Sqrt(part.GetActualArea() / 3.14159) * 2f;
  665. if (equalCircleDiameter < quantifyThreshold)
  666. {
  667. smallparts.Add(part);
  668. }
  669. else
  670. {
  671. bigparts.Add(part);
  672. }
  673. }
  674. log.Info("SmallQuantifyParts (<" + quantifyThreshold.ToString("f2") + "): " + smallparts.Count);
  675. log.Info("BigQuantifyParts (>=" + quantifyThreshold.ToString("f2") + "): " + bigparts.Count);
  676. curFldData.CreateXrayList(smallparts);
  677. curFldData.CreateXrayList(bigparts);
  678. // get x-ray parameters
  679. COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
  680. var workmode = pXRayParam.GetScanMode();
  681. if (workmode == OTS_X_RAY_SCAN_MODE.PointMode)
  682. {
  683. uint nXRayAQTime;
  684. if (bigparts.Count > 0)
  685. {
  686. nXRayAQTime = (uint)pXRayParam.GetMidAnalyAQTime();
  687. log.Info("Begin to collect xraydata:" + bigparts.Count +"(" +nXRayAQTime.ToString()+") on " + workmode.ToString());
  688. m_EDSController.GetXRayByParts(bigparts, nXRayAQTime, true);
  689. }
  690. if (smallparts.Count > 0)
  691. {
  692. Thread.Sleep(500);//add delay here,or else the eds system will halt.
  693. nXRayAQTime = (uint)pXRayParam.GetSmallPartXrayTime();
  694. log.Info("Begin to collect xraydata:" + smallparts.Count + "(" + nXRayAQTime.ToString() + ") on " + workmode.ToString());
  695. m_EDSController.GetXRayByParts(smallparts, nXRayAQTime, true);
  696. }
  697. }
  698. else if (workmode == OTS_X_RAY_SCAN_MODE.FeatureMode)
  699. {
  700. uint nXRayAQTime;
  701. if (bigparts.Count > 0)
  702. {
  703. log.Info("Begin to collect xraydata:" + bigparts.Count + " on " + OTS_X_RAY_SCAN_MODE.FeatureMode.ToString());
  704. nXRayAQTime = (uint)pXRayParam.GetMidAnalyAQTime();
  705. m_EDSController.GetXRayByFeatures(bigparts, nXRayAQTime, true);
  706. }
  707. if (smallparts.Count > 0)
  708. {
  709. Thread.Sleep(500);
  710. log.Info("Begin to collect xraydata:" + smallparts.Count + " on " + OTS_X_RAY_SCAN_MODE.PointMode.ToString());
  711. nXRayAQTime = (uint)pXRayParam.GetSmallPartXrayTime();
  712. m_EDSController.GetXRayByParts(smallparts, nXRayAQTime, true);
  713. }
  714. }
  715. return;
  716. }
  717. public virtual void QuantifyParticlesXrayData(COTSField curFldData)
  718. {
  719. var parts = curFldData.GetListXrayParticles();
  720. foreach (var p in parts)
  721. {
  722. m_EDSController.QuantifyXrayByPart(p);
  723. }
  724. }
  725. public void DoHolePreview()
  726. {
  727. using (AutoResetSEMControl autoReset = new AutoResetSEMControl(this))
  728. {
  729. //----------memorize the state of sem
  730. var semstate = new SEMStateObject();
  731. double dMagnification = m_Sample.GetSEMDataMsr().GetMagnification();
  732. double wd = m_Sample.GetSEMDataMsr().GetWorkingDistance();
  733. ISemController sem = m_SemHardwareMgr;
  734. double posX=0, posY=0,posR=0;
  735. sem.GetSemPositionXY(ref posX, ref posY, ref posR);
  736. CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
  737. Point pos = new Point((int)posX, (int)posY);
  738. PointF otsPos = new Point(0, 0);
  739. if (!a_pCSEMStageData.ConvertSEMToOTSCoord(pos, ref otsPos))
  740. {
  741. return;
  742. }
  743. semstate.Pos = otsPos;
  744. semstate.Magnification = dMagnification;
  745. semstate.WorkingDistance = wd;
  746. autoReset.SemState = semstate;
  747. //-------------------------------------
  748. // let the main thread to know that this sample measurement starts
  749. CMsrSampleStatus pStatus = m_HolePreviewSample.GetMsrStatus();
  750. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.INPROCESS);
  751. // set current time to current time
  752. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.START);
  753. // get SEM controller to set magnification and working distance
  754. if (!SetSEMDataMrs(m_HolePreviewSample))
  755. {
  756. log.Error("DoHolePreview: fail to set SEM data.");
  757. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  758. // record end time
  759. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  760. return;
  761. }
  762. // set the BSE scan param
  763. if (!SetHoleBSEParam(m_HolePreviewSample))
  764. {
  765. log.Error("DoHolePreview: fail to set BSE param.");
  766. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  767. // record end time
  768. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  769. return;
  770. }
  771. // calculate field centers
  772. List<System.Drawing.Point> listFieldCenter;
  773. List<System.Drawing.Point> alllistFieldCenter ;
  774. if (!CalculateUnMeasuredHoleImgCenters(m_HolePreviewSample, out alllistFieldCenter,out listFieldCenter))
  775. {// failed to calculate field centers
  776. log.Error("DoHolePreview: failed to calculate field centers.");
  777. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  778. // record end time
  779. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  780. return;
  781. }
  782. // go through each field
  783. //int nNewFieldId = 0;
  784. for ( int i = 0; i < listFieldCenter.Count; ++i)
  785. {// check and break if stop button is clicked
  786. if (IsAborted())
  787. {// measure stopped
  788. log.Trace("DoHolePreview: measure thread is stopped.");
  789. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.STOPPED);
  790. // record end time
  791. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  792. return;
  793. }
  794. // check if sample measurement completes
  795. COTSImgScanPrm pScanParam = m_Sample.GetMsrParams().GetImageScanParam();
  796. int nTotalFieldSize = listFieldCenter.Count;
  797. // get a field center
  798. System.Drawing.Point poiFieldCentre = listFieldCenter[i];
  799. // move SEM to the field center
  800. if (!MoveSEMToPoint(poiFieldCentre))
  801. {// failed to move SEM to the position
  802. log.Error("DoHolePreview: failed to move SEM to the field centre point.");
  803. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  804. // record end time
  805. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  806. return;
  807. }
  808. // take BSE image for the fields
  809. CBSEImgClr pBSEIamge = AcquireABSEImage();
  810. if (pBSEIamge==null)
  811. {
  812. // failed to acquire a BSE image
  813. log.Error("DoHolePreview: failed to acquire a BSE image.");
  814. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  815. // record end time
  816. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  817. return;
  818. }
  819. //BSEData
  820. ST_MSTMsg MsgFieldBSE=new ST_MSTMsg(m_HolePreviewSample);
  821. MsgFieldBSE.InitHolePreBSEDataMsg(pBSEIamge,poiFieldCentre);
  822. m_pMsrThread.SendHolePreviewMessageToMeasureGUI(MsgFieldBSE);
  823. if (pStatus.GetStatus() != OTS_MSR_SAMPLE_STATUS.INPROCESS)
  824. {
  825. // measurement failed or stopped
  826. log.Error("DoHolePreview: measurement failed or stopped.");
  827. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  828. // record end time
  829. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  830. return;
  831. }
  832. //save the result to project file
  833. Rectangle oImageRect = (Rectangle)pBSEIamge.GetImageRect();
  834. CHoleBSEImg pHoleBSEImg =new CHoleBSEImg(oImageRect,poiFieldCentre);
  835. pHoleBSEImg.SetImageData( pBSEIamge.GetImageDataPtr(),oImageRect.Width,oImageRect.Height);
  836. m_listHoleBSEImg.Add(pHoleBSEImg);
  837. }
  838. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  839. //calculate measure time
  840. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
  841. // let main thread to know that this sample measurement completes
  842. ST_MSTMsg MsgSmplEnd=new ST_MSTMsg(m_HolePreviewSample);
  843. MsgSmplEnd.InitHolePreSampleEndMsg();
  844. m_pMsrThread.SendHolePreviewMessageToMeasureGUI(MsgSmplEnd);
  845. }
  846. }
  847. // Cumulate field data info
  848. public virtual bool CumulateFieldData( List<COTSParticleClr> listParticles, double a_nMeasuredArea)
  849. {
  850. // get measure result items of the sample
  851. CMsrResultItems pMsrResults = m_Sample.GetMsrResults();
  852. // go through the particles list
  853. foreach (COTSParticleClr pParticle in listParticles)
  854. {
  855. // create a measure result item
  856. pMsrResults.CumulateMeasureResult(pParticle);
  857. }
  858. pMsrResults.CumulateMeasuredArea(a_nMeasuredArea);
  859. // cumulate ratio
  860. double dRatio = pMsrResults.GetTotalParticleArea();
  861. dRatio = dRatio / pMsrResults.GetMeasuredArea();
  862. pMsrResults.SetRatio(dRatio);
  863. m_Sample.SetMsrResults(pMsrResults);
  864. return true;
  865. }
  866. public bool SaveFieldData(COTSField fldData, string filedFileFoler)
  867. {
  868. string strFieldFileFolder = filedFileFoler;
  869. CBSEImageFileMgr pBSEImgFileMgr = new CBSEImageFileMgr();
  870. pBSEImgFileMgr.SetBSEImg(fldData.GetBSEImage());
  871. int nId = fldData.GetId();
  872. string sFieldId;
  873. sFieldId = nId.ToString();
  874. string strBSEFilePathname = strFieldFileFolder + "\\" + m_pSampleRstFile.SMPL_MSR_RESULT_FIELDS_BSE + sFieldId + pBSEImgFileMgr.BMP_IMG_FILE_EXT;
  875. if (!pBSEImgFileMgr.SaveIntoBitmap(strBSEFilePathname))
  876. {
  877. log.Error("SaveFieldFiles: save BSE file failed.");
  878. return false;
  879. }
  880. if (fldData.particleImages.Count > 0)
  881. {
  882. for (int i=0;i<fldData.particleImages.Count;i++)
  883. {
  884. strBSEFilePathname= m_pSampleRstFile.GetParticleImageFolder() + "\\" + sFieldId +"_" +i.ToString()+pBSEImgFileMgr.BMP_IMG_FILE_EXT;
  885. pBSEImgFileMgr.SetBSEImg(fldData.particleImages[i]);
  886. pBSEImgFileMgr.SaveIntoBitmap(strBSEFilePathname);
  887. }
  888. }
  889. // IncA Data list
  890. CIncAFileMgr pDBFileMgr = m_pSampleRstFile.DBFileMgr;
  891. pDBFileMgr.SaveStatusDataToDB();
  892. var fldDB = pDBFileMgr.GetFieldDB();
  893. log.Warn("Start saving particle data.");
  894. var fldcmd = fldDB.GetSavingAFieldcmdObj(fldData.GetId(), fldData.GetOTSPosition(), fldData.GetSemPos());
  895. List<KeyValuePair<string, System.Data.SQLite.SQLiteParameter[]>> fldcmds = new List<KeyValuePair<string, System.Data.SQLite.SQLiteParameter[]>>();
  896. fldcmds.Add(fldcmd);
  897. pDBFileMgr.ExecuteNonQueryBatch(ref fldcmds);
  898. //remomove the invalid particles
  899. var cmds = pDBFileMgr.GetSavingParticleDataToDBCmds(fldData.GetListAnalysisParticles(), fldData.GetOTSPosition());
  900. pDBFileMgr.ExecuteNonQueryBatch(ref cmds);
  901. CPosXrayDBMgr PosXrayDBMgr = pDBFileMgr.GetPosXrayDBMgr();
  902. var listAnalysisPosXray = new List<CPosXrayClr>();
  903. foreach (var p in fldData.GetListXrayParticles())
  904. {
  905. listAnalysisPosXray.Add(p.GetXray());
  906. }
  907. var cmds1 = PosXrayDBMgr.GetSavingXrayCmds(listAnalysisPosXray, true);
  908. pDBFileMgr.ExecuteNonQueryBatch(ref cmds1);
  909. return true;
  910. }
  911. protected void SaveFieldMgrData()
  912. {
  913. while (bSaveThreadWorking)
  914. {
  915. while (fieldQueue.Count() > 0)
  916. {
  917. COTSField f = fieldQueue.Dequeue();
  918. //save to disk first ,then pop . if the size is 0,then we know all the saving work is done.
  919. log.Info("Begin to save particles data! particle num:" + f.GetListAnalysisParticles().Count);
  920. SaveFieldData(f, m_pSampleRstFile.GetFieldFileSubFolderStr());
  921. }
  922. if (fieldQueue.Count() == 0)
  923. {
  924. bSaveThreadWorking = false; //must set this flag,so the main thread can know this thread has exited.
  925. log.Warn("finished batch saving");
  926. return;
  927. }
  928. }
  929. return;
  930. }
  931. private void SendFieldParticlesInfoToGUI(COTSField curFld,CMsrSampleStatus pStatus)
  932. {
  933. double measuredArea = 0; // this area should be the field area
  934. var a_pBSEImg = curFld.GetBSEImage();
  935. double dPixelSize = curFld.GetPixelSize();
  936. measuredArea = a_pBSEImg.GetHeight() * a_pBSEImg.GetWidth() * dPixelSize * dPixelSize; //Get measured area
  937. CumulateFieldData(curFld.GetListAnalysisParticles(), measuredArea);
  938. log.Info("Send field data to screen!");
  939. pStatus.AddCompletedFieldCenter(curFld.GetOTSPosition());
  940. //Field Data
  941. // record end time
  942. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  943. ST_MSTMsg MsgFieldEnd = new ST_MSTMsg(m_Sample,curFld);
  944. MsgFieldEnd.InitFieldDataMsg();
  945. m_pMsrThread.SendMessageToMeasureGUI(MsgFieldEnd);
  946. }
  947. protected void StartSaveFileThread(ref COTSField a_pFieldMgr)
  948. {
  949. fieldQueue.Enqueue(a_pFieldMgr);
  950. if (fieldQueue.Count() > 0) //if there's data in the queue and the previous thread has finished then start a new thread.
  951. {
  952. if (bSaveThreadWorking == false)
  953. {
  954. bSaveThreadWorking = true;
  955. m_thread_ptr = new System.Threading.Thread(this.SaveFieldMgrData);//m_thread_ptr = shared_ptr<thread>(new thread(&CSmplMeasureInc::SaveFieldMgrData, this));
  956. m_thread_ptr.IsBackground = true;
  957. m_thread_ptr.Start();
  958. }
  959. }
  960. }
  961. }
  962. }