CSmplMeasure.cs 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using OTSModelSharp.ServiceInterface;
  7. using static OTSDataType.otsdataconst;
  8. using OTSDataType;
  9. using System.Diagnostics;
  10. using System.Drawing;
  11. using System.Threading;
  12. using OTSModelSharp.DTLBase;
  13. using OTSCLRINTERFACE;
  14. using OTSModelSharp.ServiceCenter;
  15. namespace OTSModelSharp
  16. {
  17. using CHoleBSEImgsList = List<CHoleBSEImg>;
  18. 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 CMeasure m_pMsrThread;
  25. string m_strWorkingFolder;
  26. protected CSmplMsrResult m_pSampleRstFile;
  27. CHoleBSEImgsList m_listHoleBSEImg;
  28. //CFunExportClass loger;
  29. protected SemController m_SemHardwareMgr;
  30. protected ScanController m_ScanHardwareMgr;
  31. protected EDSController m_EDSHardwareMgr;
  32. protected Queue<COTSFieldData> fieldQueue=new Queue<COTSFieldData>();
  33. protected COTSFieldData curFldData;
  34. protected IClassifyEngine m_classifyEngine;
  35. public CSmplMeasure()
  36. {
  37. log = NLog.LogManager.GetCurrentClassLogger();
  38. m_pSampleRstFile = new CSmplMsrResult();
  39. m_SemHardwareMgr = SemController.GetSEMController();
  40. m_ScanHardwareMgr = ScanController.GetScanController();
  41. m_EDSHardwareMgr = EDSController.GetEDSController();
  42. m_listHoleBSEImg = new CHoleBSEImgsList();
  43. }
  44. public CSmplMeasure( string a_strWorkingFolder, COTSSample a_pSample)
  45. {
  46. log = NLog.LogManager.GetCurrentClassLogger();
  47. m_strWorkingFolder = a_strWorkingFolder;
  48. m_pSampleRstFile = new CSmplMsrResult( a_strWorkingFolder, a_pSample);// new CSmplMsrResultFile(m_strWorkingFolder,a_pSample);
  49. m_SemHardwareMgr = SemController.GetSEMController();
  50. m_ScanHardwareMgr = ScanController.GetScanController();
  51. m_EDSHardwareMgr = EDSController.GetEDSController();
  52. m_listHoleBSEImg = new CHoleBSEImgsList();
  53. m_Sample = a_pSample;
  54. }
  55. public void SetSample(COTSSample a_pSample)
  56. {
  57. m_Sample = a_pSample;
  58. m_pSampleRstFile.SetSample(a_pSample);
  59. }
  60. public void SetMsrThread(CMeasure mt)
  61. {
  62. m_pMsrThread = mt;
  63. }
  64. bool SetSEMDataMrs()
  65. {
  66. var pSEMDataMsr = m_Sample.GetSEMDataMsr();
  67. //ASSERT(pSEMDataMsr);
  68. double dMag = pSEMDataMsr.GetMagnification();
  69. double dWorkDis = pSEMDataMsr.GetWorkingDistance();
  70. //CSemBasePtr pSEMCtrlPtr = GetSEMControl();
  71. var pSEMCtrl = m_pMsrThread.GetSEMController();
  72. // get SEM controller
  73. if (!pSEMCtrl.IsConnected())
  74. {
  75. if (!pSEMCtrl.Connect())
  76. {
  77. log.Error("SetSEMDataMrs: can't connect SEM.");
  78. return false;
  79. }
  80. }
  81. log.Info("set magnification:" + dMag.ToString());
  82. log.Info("set Working Distance:" + dWorkDis.ToString());
  83. pSEMCtrl.SetMagnification(dMag);
  84. pSEMCtrl.SetWorkingDistance(dWorkDis);
  85. return true;
  86. }
  87. bool SetSEMExteralOn()
  88. {
  89. var pSEMCtrl = m_SemHardwareMgr;
  90. // get SEM controller
  91. if (!pSEMCtrl.IsConnected())
  92. {
  93. if (!pSEMCtrl.Connect())
  94. {
  95. log.Error("SetSEMExteralOn: can't connect SEM.");
  96. return false;
  97. }
  98. }
  99. log.Warn("Set Scan Exteral on!");
  100. pSEMCtrl.SetScanExternal(true);
  101. return true;
  102. }
  103. // set SEM external off
  104. bool SetSEMExteralOff()
  105. {
  106. var pSEMCtrlPtr = m_SemHardwareMgr;
  107. // get SEM controller
  108. if (!pSEMCtrlPtr.IsConnected())
  109. {
  110. if (!pSEMCtrlPtr.Connect())
  111. {
  112. log.Error("SetSEMExteralOff: can't connect SEM.");
  113. return false;
  114. }
  115. }
  116. log.Warn("Set SEM Exteral Off!");
  117. pSEMCtrlPtr.SetScanExternal(false);
  118. return true;
  119. }
  120. bool SetBSEParam()
  121. {
  122. // get SEM controller
  123. var pSEMController = m_SemHardwareMgr;
  124. // get scan controller
  125. var pScanController = m_ScanHardwareMgr;
  126. // scan parameters
  127. var pMsrParam = m_Sample.GetMsrParams();
  128. var pImgScanParam = pMsrParam.GetImageScanParam();
  129. // get image size
  130. var nImageSizeId = pImgScanParam.GetImageResulotion();
  131. int nResulotionId = RESOLUTION_ID_FIRST_TIE + (int)nImageSizeId;
  132. Size sizePixelImage = RESOLUTION_VALUE[nResulotionId];
  133. // get SEM controller
  134. if (!pSEMController.IsConnected())
  135. {
  136. if (!pSEMController.Connect())
  137. {
  138. log.Error("SetBSEParam: can't connect SEM.");
  139. return false;
  140. }
  141. }
  142. // get dwell time
  143. OTS_IMAGE_SCANSPEED_OPTIONS nDwellTime = pImgScanParam.GetScanImageSpeed();
  144. // convert dwell time to bruker dwell time (8, 16, 32)
  145. int nBrukerDwellTimeId=3;
  146. switch (nDwellTime)
  147. {
  148. case OTS_IMAGE_SCANSPEED_OPTIONS.low:
  149. nBrukerDwellTimeId = 3;
  150. break;
  151. case OTS_IMAGE_SCANSPEED_OPTIONS.meddium:
  152. nBrukerDwellTimeId = 4;
  153. break;
  154. case OTS_IMAGE_SCANSPEED_OPTIONS.high:
  155. nBrukerDwellTimeId = 5;
  156. break;
  157. default:
  158. nBrukerDwellTimeId = 3;
  159. break;
  160. }
  161. long nBrukerDwellTime = OTSDataType.otsdataconst.DWELLTIME_BRUKER_VALUES[nBrukerDwellTimeId];
  162. if (!pScanController.Init())
  163. {
  164. log.Error("SetBSEParam: failed to get scan control.");
  165. return false;
  166. }
  167. // set dwell time
  168. if (!pScanController.SetDwellTime(nBrukerDwellTime))
  169. {
  170. log.Error("SetBSEParam: failed to set dwell time (%d) for bruker system.", nBrukerDwellTime);
  171. return false;
  172. }
  173. // set image size
  174. if (!pScanController.SetImageSize(sizePixelImage.Width,sizePixelImage.Height))
  175. {
  176. // failed to set dwell time
  177. log.Error("SetBSEParam: failed to set dwell time (%d).", sizePixelImage.Height);
  178. return false;
  179. }
  180. return true;
  181. }
  182. bool SetHoleBSEParam()
  183. {
  184. // get SEM controller
  185. var pSEMController = m_SemHardwareMgr;
  186. // get scan controller
  187. var pScanController = m_ScanHardwareMgr;
  188. // scan parameters
  189. var pMsrParam = m_Sample.GetMsrParams();
  190. var pImgScanParam = pMsrParam.GetImageScanParam();
  191. // get image size
  192. var nImageSizeId = pImgScanParam.GetImageResulotion();
  193. int nResulotionId = RESOLUTION_ID_FIRST_TIE + (int)nImageSizeId;
  194. Size sizePixelImage = RESOLUTION_VALUE[nResulotionId];
  195. // get SEM controller
  196. if (!pSEMController.IsConnected())
  197. {
  198. if (!pSEMController.Connect())
  199. {
  200. log.Error("SetBSEParam: can't connect SEM.");
  201. return false;
  202. }
  203. }
  204. // get dwell time
  205. OTS_IMAGE_SCANSPEED_OPTIONS nDwellTime = pImgScanParam.GetScanImageSpeed();
  206. // convert dwell time to bruker dwell time (6, 16, 32)
  207. 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.
  208. if (!pScanController.Init())
  209. {
  210. log.Error("SetBSEParam: failed to get scan control.");
  211. return false;
  212. }
  213. // set dwell time
  214. if (!pScanController.SetDwellTime(nBrukerDwellTime))
  215. {
  216. log.Error("SetBSEParam: failed to set dwell time (%d) for bruker system.", nBrukerDwellTime);
  217. return false;
  218. }
  219. // set image size
  220. if (!pScanController.SetImageSize(sizePixelImage.Width/2, sizePixelImage.Height/2))
  221. {
  222. // failed to set dwell time
  223. log.Error("SetBSEParam: failed to set dwell time (%d).", sizePixelImage.Height);
  224. return false;
  225. }
  226. return true;
  227. }
  228. public void SetWorkingFolder(String a_strWorkingFolder)
  229. {
  230. // add "\\" at the string end if it is not "\\"
  231. if (a_strWorkingFolder.PadRight(1)!="\\")
  232. {
  233. a_strWorkingFolder += "\\";
  234. }
  235. m_strWorkingFolder = a_strWorkingFolder + m_Sample.GetName() + "\\";
  236. }
  237. bool CalculateUnMeasuredFieldsCenters(out List<System.Drawing.Point> a_allpieldcenter,out List<System.Drawing.Point> a_listFieldCenter)
  238. {
  239. // sample measure parameters
  240. CSampleParam pMsrParam = m_Sample.GetMsrParams();
  241. COTSImgScanPrm poImageScanParam = pMsrParam.GetImageScanParam();
  242. CSEMDataMsr poSEMDataMsr = m_Sample.GetSEMDataMsr();
  243. CMsrSampleStatus pStatus = m_Sample.GetMsrStatus();
  244. // measured field centers list
  245. List<System.Drawing.Point> listCompletedCenter = pStatus.GetCompletedFieldsCenter();
  246. // field centers list manager
  247. CFieldPositionMgr pFieldMgr = new CFieldPositionMgr();
  248. // init field centers list manager
  249. if (!pFieldMgr.Init(m_Sample.GetMsrArea(), poImageScanParam, poSEMDataMsr, listCompletedCenter))
  250. {
  251. log.Error("CalculateFieldsCenters: failed to init field centres list manager.");
  252. a_listFieldCenter = new List<System.Drawing.Point>();
  253. a_allpieldcenter = new List<Point>();
  254. return false;
  255. }
  256. // get field centers list
  257. a_listFieldCenter = pFieldMgr.GetUnmeasuredFieldCentrePoints();// GetFieldCentrePoints();
  258. a_allpieldcenter = pFieldMgr.GetFieldCentrePoints();
  259. // ok, return TRUE
  260. return true;
  261. }
  262. protected bool IsAborted()
  263. {
  264. //Debug.Assert(m_pMsrThread == null);
  265. return m_pMsrThread.IsMeasureStopped();
  266. }
  267. bool IsSampleOver(COTSImgScanPrm a_pScanParam, int a_nTotalFields)
  268. {
  269. int nStopMode = (int)a_pScanParam.GetStopMode();
  270. int nStopField = a_pScanParam.GetStopParamFields();
  271. // completed fields number
  272. CMsrSampleStatus pMsrSampleStatus = m_Sample.GetMsrStatus();
  273. int nCompeltedField = pMsrSampleStatus.GetCompletedFields();
  274. CMsrDisplayResults pMsrResults = m_Sample.GetMsrResults();
  275. List<CMsrResultItem> listMsrResult = pMsrResults.GetResultItems();
  276. int nNumParticle = 0;
  277. foreach (var pResult in listMsrResult)
  278. {
  279. if (pResult.GetTypeId() > (int)OTS_PARTCLE_TYPE.NO_ANALYSIS_X_RAY)//summarize the number of the identified particle in this condition
  280. {
  281. nNumParticle += (int)pResult.GetNumber();
  282. }
  283. }
  284. TimeSpan timeSpan = pMsrSampleStatus.GetUsedTime();
  285. int nDay = timeSpan.Days;
  286. int nHour = timeSpan.Hours;
  287. int nMin = timeSpan.Minutes;
  288. int nSec = timeSpan.Seconds;
  289. int nUsedTime = nSec + nMin * 60 + nHour * 3600 + nDay * 86400;
  290. int nParticlAim = a_pScanParam.GetStopParamParticles();
  291. int nMeasTimeAim = a_pScanParam.GetStopParamMeasTime();
  292. bool bRet = true;
  293. switch (nStopMode)
  294. {
  295. case (int)OTS_MEASURE_STOP_MODE.CoverMode:
  296. // completed fields number
  297. if (nCompeltedField < a_nTotalFields)
  298. {
  299. bRet = false;
  300. }
  301. break;
  302. case (int)OTS_MEASURE_STOP_MODE.FieldMode:
  303. if (nCompeltedField < nStopField)
  304. {
  305. bRet = false;
  306. }
  307. break;
  308. case (int)OTS_MEASURE_STOP_MODE.ParticleMode:
  309. if (nNumParticle < nParticlAim)
  310. {
  311. bRet = false;
  312. }
  313. break;
  314. case (int)OTS_MEASURE_STOP_MODE.TimeMode:
  315. if (nUsedTime < nMeasTimeAim)
  316. {
  317. bRet = false;
  318. }
  319. break;
  320. default:
  321. break;
  322. }
  323. return bRet;
  324. }
  325. // move SEM to the point
  326. bool MoveSEMToPoint(System.Drawing.Point a_poi)
  327. {
  328. // get SEM controller
  329. var pSEMController = m_SemHardwareMgr;
  330. Point a_SEMpt = new Point();
  331. CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
  332. int hardWareDelay = a_pCSEMStageData.GetHardWareDelay();
  333. if (!a_pCSEMStageData.ConverOTSToSEMPoint(a_poi, ref a_SEMpt))
  334. {
  335. return false;
  336. }
  337. if (!pSEMController.IsConnected())
  338. {
  339. if (!pSEMController.Connect())
  340. {
  341. log.Error("MoveSEMToPoint: can't connect SEM.");
  342. return false;
  343. }
  344. }
  345. log.Info("Begin to move SEM stage to " + a_SEMpt.X + "," + a_SEMpt.Y);
  346. // move SEM to the position (rotation 0)
  347. if (!pSEMController.MoveSEMToPoint(a_SEMpt))
  348. {
  349. log.Error("MoveSEMToPoint: failed to call MoveSEMToPoint method.");
  350. return false;
  351. }
  352. Thread.Sleep(hardWareDelay);
  353. return true;
  354. }
  355. // Acquire a BSE image
  356. CBSEImgClr AcquireABSEImage()
  357. {
  358. // BSE image
  359. CBSEImgClr pBSEImage = null;
  360. // get scan controller
  361. var pScanController = m_ScanHardwareMgr;
  362. pBSEImage = pScanController.AcquireBSEImage(0, 0, 2);
  363. return pBSEImage;
  364. }
  365. public virtual bool FieldImageProcess(Point fldCenter, CBSEImgClr imageData)
  366. {
  367. return true;
  368. }
  369. public virtual void ClassifyFieldParticles()
  370. {
  371. return;
  372. }
  373. public virtual void ClassifyMergedParticles(List<COTSParticleClr> parts)
  374. {
  375. return;
  376. }
  377. private class AutoResetSEMControl:IDisposable
  378. {
  379. CSmplMeasure sm;
  380. public AutoResetSEMControl(CSmplMeasure s)
  381. {
  382. sm = s;
  383. }
  384. public void Dispose()
  385. {
  386. sm.SetSEMExteralOff();
  387. }
  388. }
  389. public void DoMeasureForOneSample()
  390. {
  391. using (AutoResetSEMControl autoReset = new AutoResetSEMControl(this)) //when this method exit ,the SetSEMExternalOff and ResetScan will be called automatically.
  392. {
  393. // let the main thread to know that this sample measurement starts
  394. var pStatus = m_Sample.GetMsrStatus();
  395. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.INPROCESS);
  396. // set current time to current time
  397. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.START);
  398. // let main App know that the sample begin to measure
  399. ST_MSTMsg MsgSmpStart = new ST_MSTMsg();
  400. MsgSmpStart.iMsgType = ENUM_MSG_TYPE.MSAMPLESTATUS;
  401. MsgSmpStart.STMSampleStu.iMsrSampleStatu = OTS_MSR_SAMPLE_STATUS.INPROCESS;
  402. MsgSmpStart.STMSampleStu.cSampleName = m_Sample.GetName();
  403. m_pMsrThread.SendMessageToMeasureApp(MsgSmpStart);
  404. log.Info(m_Sample.GetName() + " Measurement started!");
  405. // get SEM controller to set magnification and working distance
  406. if (!SetSEMDataMrs())
  407. {
  408. log.Error("DoMeasure: fail to set SEM data.");
  409. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  410. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  411. return;
  412. }
  413. // get SEM external controll on
  414. //if (!SetSEMExteralOn())
  415. //{
  416. // log.Error("DoMeasure: fail to set SEM external.");
  417. // pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  418. // pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  419. // return;
  420. //}
  421. // set the BSE scan param
  422. if (!SetBSEParam())
  423. {
  424. log.Error("DoMeasure: fail to set BSE param.");
  425. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  426. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  427. return;
  428. }
  429. var pSEMDataGnr = new CSEMDataGnr();
  430. log.Info("Get Kv, Brightness and Contrast!");
  431. m_SemHardwareMgr.GetSEMDataGnrFromHw(ref pSEMDataGnr);
  432. m_pSampleRstFile.SetSEMGnr(pSEMDataGnr);
  433. // record SEM data
  434. COTSMsrPrjResultData pProjMgrFile = m_pMsrThread.GetProjResultData();
  435. CSEMStageData pSEMStageData = pProjMgrFile.GetSEMStageData();
  436. m_pSampleRstFile.SetSEMStageData(pSEMStageData);
  437. // record stage
  438. CStage pStage = pProjMgrFile.GetStage();
  439. m_pSampleRstFile.SetSEMStage(pStage);
  440. // calculate field centers
  441. List<System.Drawing.Point> umMeasuredlistFieldCenter;
  442. List<System.Drawing.Point> alllistFieldCenter;
  443. if (!CalculateUnMeasuredFieldsCenters(out alllistFieldCenter,out umMeasuredlistFieldCenter))
  444. {// failed to calculate field centers
  445. log.Error("DoMeasure: failed to calculate field centers.");
  446. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  447. // record end time
  448. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  449. return;
  450. }
  451. //-----save the static measure result file data into xml file and the dynamic data of every field will be saved into sqlite database
  452. log.Info("Create result file!");
  453. if (!m_pSampleRstFile.CreateResultFiles())
  454. {// failed to call measure result file Save method
  455. log.Error("DoMeasure: failed to call measure result file Save method.");
  456. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  457. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  458. return;
  459. }
  460. //------
  461. int nNewFieldId = 0;
  462. int numOfAllFields = pStatus.GetCompletedFields() + umMeasuredlistFieldCenter.Count;//
  463. int completedFields = pStatus.GetCompletedFields();
  464. log.Info("Unmeasured fields:" + umMeasuredlistFieldCenter.Count);
  465. for (int i = 0; i < (int)umMeasuredlistFieldCenter.Count; ++i)
  466. {// check and break if stop button is clicked
  467. if (IsAborted())
  468. {// measure stopped
  469. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.STOPPED);
  470. // record end time
  471. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  472. //must wait for the saving data thread finished,or we'll get null pointer exception when we stop the measure process.
  473. while (fieldQueue.Count() > 0)
  474. {
  475. Thread.Sleep(100);
  476. }
  477. return;
  478. }
  479. // check if sample measurement completes
  480. COTSImgScanPrm pScanParam = m_Sample.GetMsrParams().GetImageScanParam();
  481. int nTotalFieldSize = (int)umMeasuredlistFieldCenter.Count;
  482. if (IsSampleOver(pScanParam, numOfAllFields))
  483. {
  484. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  485. break;
  486. }
  487. // get a field center
  488. System.Drawing.Point poiFieldCentre = umMeasuredlistFieldCenter[i];
  489. // update thread measure status class, let the main thread know that starts a new field
  490. ST_MSTMsg MsgFieldStart = new ST_MSTMsg();
  491. MsgFieldStart.iMsgType = ENUM_MSG_TYPE.MSAMPLERESULT;
  492. MsgFieldStart.STMSampleRetData.iRetDataType = MSAMPLE_RET.START_MSR_FIELD;
  493. MsgFieldStart.STMSampleRetData.SMsrField.FieldPos = poiFieldCentre;
  494. m_pMsrThread.SendMessageToMeasureApp(MsgFieldStart);
  495. int fldNo = completedFields + i + 1;
  496. log.Warn("Current field:" + fldNo.ToString());
  497. // move SEM to the field center
  498. if (!MoveSEMToPoint(poiFieldCentre))
  499. {// failed to move SEM to the position
  500. log.Error("DoMeasure: failed to move SEM to the field centre point.");
  501. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  502. // record end time
  503. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  504. return;
  505. }
  506. log.Info("Begin to Acquire BSE image!");
  507. // take BSE image for the fields
  508. CBSEImgClr pBSEImg = AcquireABSEImage();
  509. // let the main thread to know that image process is completed
  510. if (pBSEImg == null)
  511. {
  512. log.Error("ImageProcess: can't get no background image.");
  513. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  514. return;
  515. }
  516. //BSEData
  517. ST_MSTMsg MsgFieldBSE = new ST_MSTMsg();
  518. MsgFieldBSE.iMsgType = ENUM_MSG_TYPE.MSAMPLERESULT;
  519. MsgFieldBSE.STMSampleRetData.iRetDataType = MSAMPLE_RET.BSE_DATA;
  520. MsgFieldBSE.STMSampleRetData.BSEData.pos.X = poiFieldCentre.X;
  521. MsgFieldBSE.STMSampleRetData.BSEData.pos.Y = poiFieldCentre.Y;
  522. MsgFieldBSE.STMSampleRetData.BSEData.iBSEDataHeight = pBSEImg.GetHeight();
  523. MsgFieldBSE.STMSampleRetData.BSEData.iBSEDataWidth = pBSEImg.GetWidth();
  524. byte[] pImgData = pBSEImg.GetImageDataPtr();
  525. MsgFieldBSE.STMSampleRetData.BSEData.lpBSEData = pImgData;
  526. m_pMsrThread.SendMessageToMeasureApp(MsgFieldBSE);
  527. // get a new field id
  528. log.Info("Acquire BSE image success! Processing image...");
  529. // image process
  530. var rst = FieldImageProcess(poiFieldCentre, pBSEImg);
  531. if (rst == true)
  532. {
  533. // add the field into the field
  534. m_pSampleRstFile.AddAField(curFldData);
  535. }
  536. ++nNewFieldId;
  537. double measuredArea = 0; // this area should be the field area
  538. var a_pBSEImg = curFldData.GetBSEImage();
  539. double dPixelSize = m_Sample.CalculatePixelSize();
  540. measuredArea = a_pBSEImg.GetHeight() * a_pBSEImg.GetWidth()* dPixelSize * dPixelSize + 0.5; //Get measured area
  541. if (!CumulateFieldData(curFldData.GetListAnalysisParticles(), measuredArea))
  542. { // failed to call SaveFieldFile method
  543. log.Error("ImageProcess: call CumulateFieldData method.");
  544. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  545. return;
  546. }
  547. log.Info("Send field data to screen!");
  548. // completed fields
  549. pStatus.SetCompletedFields(pStatus.GetCompletedFields() + 1);
  550. // completed fieldCenter
  551. List<System.Drawing.Point> listCpltedCenter = pStatus.GetCompletedFieldsCenter();
  552. listCpltedCenter.Add(poiFieldCentre);
  553. //Field Data
  554. // record end time
  555. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  556. ST_MSTMsg MsgFieldEnd = new ST_MSTMsg();
  557. MsgFieldEnd.iMsgType = ENUM_MSG_TYPE.MSAMPLERESULT;
  558. MsgFieldEnd.STMSampleRetData.iRetDataType = MSAMPLE_RET.FIELD_DATA;
  559. MsgFieldEnd.STMSampleRetData.SFieldData.iCompleteFieldCount = pStatus.GetCompletedFields();
  560. MsgFieldEnd.STMSampleRetData.SFieldData.iMeasureFieldCount = numOfAllFields;
  561. MsgFieldEnd.STMSampleRetData.SFieldData.iSParticleCount = (int)curFldData.GetListAnalysisParticles().Count;
  562. MsgFieldEnd.STMSampleRetData.SFieldData.FieldPos.X = Convert.ToInt32(poiFieldCentre.X);
  563. MsgFieldEnd.STMSampleRetData.SFieldData.FieldPos.Y = Convert.ToInt32(poiFieldCentre.Y);
  564. m_pMsrThread.SendMessageToMeasureApp(MsgFieldEnd);
  565. }
  566. while (bSaveThreadWorking)//wait untill all the field data has been saved.
  567. {
  568. Thread.Sleep(1000);
  569. log.Warn("db saving!");
  570. }
  571. //merging particles
  572. log.Info("Merging big particles which are crossing the field edge!");
  573. CImageHandler imgpro = new CImageHandler();
  574. int scanfldsize = m_Sample.GetSEMDataMsr().GetScanFieldSize();
  575. List<COTSParticleClr> mergedParticles = new List<COTSParticleClr>();
  576. double pixelSize = m_Sample.CalculatePixelSize();
  577. imgpro.MergeBigBoundaryParticles(m_pSampleRstFile.GetFieldData(), pixelSize, scanfldsize, m_Sample.GetResolutionSize(), ref mergedParticles);
  578. CalculateMergedPartProperty(mergedParticles,pixelSize);
  579. ClassifyMergedParticles(mergedParticles);
  580. log.Info("begin merged particle data db saving...");
  581. SaveMergedParticles(mergedParticles);
  582. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.COMPLT);
  583. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
  584. // let main thread to know that this sample measurement completes
  585. ST_MSTMsg MsgSmplEnd = new ST_MSTMsg();
  586. MsgSmplEnd.iMsgType = ENUM_MSG_TYPE.MSAMPLESTATUS;
  587. MsgSmplEnd.STMSampleStu.iMsrSampleStatu = OTS_MSR_SAMPLE_STATUS.SUCCESSED;
  588. MsgSmplEnd.STMSampleStu.cSampleName = m_Sample.GetName();
  589. m_pMsrThread.SendMessageToMeasureApp(MsgSmplEnd);
  590. }
  591. }
  592. private void CalculateMergedPartProperty(List<COTSParticleClr> mergedParticles,double pixelSize)
  593. {
  594. var m_ImagePro = new CImageHandler();
  595. foreach (COTSParticleClr part in mergedParticles)
  596. {
  597. m_ImagePro.CalParticleImageProp(part, pixelSize);
  598. }
  599. }
  600. public void DoHolePreview(int a_nHoleID)
  601. {
  602. using (AutoResetSEMControl autoReset = new AutoResetSEMControl(this))
  603. {
  604. // let the main thread to know that this sample measurement starts
  605. CMsrSampleStatus pStatus = m_Sample.GetMsrStatus();
  606. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.INPROCESS);
  607. // set current time to current time
  608. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.START);
  609. // let main App know that the sample begin to measure
  610. ST_MSTMsg MsgSmpStart=new ST_MSTMsg();
  611. MsgSmpStart.iMsgType = ENUM_MSG_TYPE.MSAMPLESTATUS;
  612. MsgSmpStart.STMSampleStu.iMsrSampleStatu = OTS_MSR_SAMPLE_STATUS.INPROCESS;
  613. MsgSmpStart.STMSampleStu.cSampleName=m_Sample.GetName();
  614. // get SEM controller to set magnification and working distance
  615. if (!SetSEMDataMrs())
  616. {
  617. log.Error("DoHolePreview: fail to set SEM data.");
  618. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  619. // record end time
  620. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  621. return;
  622. }
  623. // get SEM external controll on
  624. //if (!SetSEMExteralOn())
  625. //{
  626. // log.Error("DoMeasure: fail to set SEM external.");
  627. // pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  628. // // record end time
  629. // pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  630. // return;
  631. //}
  632. // set the BSE scan param
  633. if (!SetHoleBSEParam())
  634. {
  635. log.Error("DoMeasure: fail to set BSE param.");
  636. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  637. // record end time
  638. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  639. return;
  640. }
  641. // check if measurement is aborted
  642. if (IsAborted())
  643. {// measurement aborted
  644. log.Trace("DoHolePreview: measurement aborted before get SEM condition.");
  645. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.STOPPED);
  646. // record end time
  647. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  648. return;
  649. }
  650. // calculate field centers
  651. List<System.Drawing.Point> listFieldCenter=new List<System.Drawing.Point>();
  652. List<System.Drawing.Point> alllistFieldCenter = new List<System.Drawing.Point>();
  653. // listFieldCenter.clear();
  654. if (!CalculateUnMeasuredFieldsCenters(out alllistFieldCenter,out listFieldCenter))
  655. {// failed to calculate field centers
  656. log.Error("DoHolePreview: failed to calculate field centers.");
  657. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  658. // record end time
  659. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  660. return;
  661. }
  662. // go through each field
  663. int nNewFieldId = 0;
  664. for ( int i = 0; i < listFieldCenter.Count; ++i)
  665. {// check and break if stop button is clicked
  666. if (IsAborted())
  667. {// measure stopped
  668. log.Trace("DoHolePreview: measure thread is stopped.");
  669. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.STOPPED);
  670. // record end time
  671. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  672. return;
  673. }
  674. // check if sample measurement completes
  675. COTSImgScanPrm pScanParam = m_Sample.GetMsrParams().GetImageScanParam();
  676. int nTotalFieldSize = listFieldCenter.Count;
  677. if (IsSampleOver(pScanParam, nTotalFieldSize))
  678. {
  679. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  680. break;
  681. }
  682. // get a field center
  683. System.Drawing.Point poiFieldCentre = listFieldCenter[i];
  684. // update thread measure status class, let the main thread know that starts a new field
  685. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  686. ST_MSTMsg MsgFieldStart=new ST_MSTMsg();
  687. MsgFieldStart.iMsgType = ENUM_MSG_TYPE.MSAMPLERESULT;
  688. MsgFieldStart.STMSampleRetData.iRetDataType = MSAMPLE_RET.START_MSR_FIELD;
  689. MsgFieldStart.STMSampleRetData.SMsrField.FieldPos = poiFieldCentre;
  690. m_pMsrThread.SendMessageToMeasureApp(MsgFieldStart);
  691. // move SEM to the field center
  692. if (!MoveSEMToPoint(poiFieldCentre))
  693. {// failed to move SEM to the position
  694. log.Error("DoHolePreview: failed to move SEM to the field centre point.");
  695. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  696. // record end time
  697. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  698. return;
  699. }
  700. // take BSE image for the fields
  701. CBSEImgClr pBSEIamge = AcquireABSEImage();
  702. if (pBSEIamge==null)
  703. {
  704. // failed to acquire a BSE image
  705. log.Error("DoHolePreview: failed to acquire a BSE image.");
  706. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  707. // record end time
  708. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  709. return;
  710. }
  711. //BSEData
  712. ST_MSTMsg MsgFieldBSE=new ST_MSTMsg();
  713. // memset(&MsgFieldBSE, 0, sizeof(ST_MSTMsg));
  714. MsgFieldBSE.iMsgType = ENUM_MSG_TYPE.MSAMPLERESULT;
  715. MsgFieldBSE.STMSampleRetData.iRetDataType = MSAMPLE_RET.BSE_DATA;
  716. MsgFieldBSE.STMSampleRetData.BSEData.pos = poiFieldCentre;
  717. //MsgFieldBSE.STMSampleRetData.BSEData.pos.y = poiFieldCentre.y;
  718. MsgFieldBSE.STMSampleRetData.BSEData.iBSEDataHeight = pBSEIamge.GetHeight();
  719. MsgFieldBSE.STMSampleRetData.BSEData.iBSEDataWidth = pBSEIamge.GetWidth();
  720. byte[] pImgData = pBSEIamge.GetImageDataPtr();
  721. MsgFieldBSE.STMSampleRetData.BSEData.lpBSEData = pImgData;
  722. m_pMsrThread.SendMessageToMeasureApp(MsgFieldBSE);
  723. if (pStatus.GetStatus() != OTS_MSR_SAMPLE_STATUS.INPROCESS)
  724. {
  725. // measurement failed or stopped
  726. log.Error("DoHolePreview: measurement failed or stopped.");
  727. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  728. // record end time
  729. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  730. return;
  731. }
  732. //save the result to project file
  733. Rectangle oImageRect = (Rectangle)pBSEIamge.GetImageRect();
  734. CHoleBSEImg pHoleBSEImg =new CHoleBSEImg(oImageRect,a_nHoleID, poiFieldCentre);
  735. pHoleBSEImg.SetImageData( pBSEIamge.GetImageDataPtr(),oImageRect.Width,oImageRect.Height);
  736. m_listHoleBSEImg.Add(pHoleBSEImg);
  737. COTSMsrPrjResultData pProjMgrFile = m_pMsrThread.GetProjResultData();
  738. pProjMgrFile.SetHoleBESImgList(m_listHoleBSEImg,true);
  739. // prepare for the next
  740. ++nNewFieldId;
  741. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  742. ST_MSTMsg MsgFieldEnd=new ST_MSTMsg();
  743. MsgFieldEnd.iMsgType = ENUM_MSG_TYPE.MSAMPLERESULT;
  744. MsgFieldEnd.STMSampleRetData.iRetDataType = MSAMPLE_RET.FIELD_DATA;
  745. MsgFieldEnd.STMSampleRetData.SFieldData.iCompleteFieldCount = (i + 1);
  746. MsgFieldEnd.STMSampleRetData.SFieldData.iMeasureFieldCount = listFieldCenter.Count;
  747. MsgFieldEnd.STMSampleRetData.SFieldData.iSParticleCount = 0;
  748. MsgFieldEnd.STMSampleRetData.SFieldData.FieldPos = poiFieldCentre;
  749. m_pMsrThread.SendMessageToMeasureApp(MsgFieldEnd);
  750. //break;
  751. }
  752. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  753. //calculate measure time
  754. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
  755. // let main thread to know that this sample measurement completes
  756. ST_MSTMsg MsgSmplEnd=new ST_MSTMsg();
  757. MsgSmplEnd.iMsgType = ENUM_MSG_TYPE.MTHREADSTATUS;
  758. MsgSmplEnd.STMThreadStu.iMsrStatu = OTS_MSR_THREAD_STATUS.COMPLETED;
  759. m_pMsrThread.SendMessageToMeasureApp(MsgSmplEnd);
  760. }
  761. }
  762. // Cumulate field data info
  763. public virtual bool CumulateFieldData( List<COTSParticleClr> listParticles, double a_nMeasuredArea)
  764. {
  765. // get measure result items of the sample
  766. CMsrDisplayResults pMsrResults = m_Sample.GetMsrResults();
  767. // cumulate field data info
  768. //pMsrResults.CumulateMeasureResults(listResultItems);
  769. pMsrResults.CumulateMeasuredArea(a_nMeasuredArea);
  770. // cumulate ratio
  771. double dRatio = 10000 * pMsrResults.GetTotalParticleArea();
  772. dRatio = dRatio / pMsrResults.GetMeasuredArea();
  773. pMsrResults.SetRatio(dRatio);
  774. // go through the particles list
  775. foreach (COTSParticleClr pParticle in listParticles)
  776. {
  777. // create a measure result item
  778. pMsrResults.CumulateMeasureResult(pParticle);
  779. }
  780. // ok, return TRUE
  781. return true;
  782. }
  783. // hole BSE images list
  784. void SetHoleBESImgList(CHoleBSEImgsList a_listHoleBSEImg, bool a_bClear/* = TRUE*/)
  785. {// clear the hole BSE image list if necessary
  786. if (a_bClear)
  787. {
  788. m_listHoleBSEImg.Clear();
  789. }
  790. // go through the input list
  791. foreach (var pHoleBSEImg in a_listHoleBSEImg)
  792. {// add the new hole BSE image into HoleBSEImage list
  793. m_listHoleBSEImg.Add(pHoleBSEImg);
  794. }
  795. }
  796. public bool SaveMergedParticles(List<COTSParticleClr> mergedParts)
  797. {
  798. CIncAFileMgr pDBFileMgr = m_pSampleRstFile.DBFileMgr;
  799. var mergedpartdb = pDBFileMgr.GetMergedParticleDB();
  800. foreach (COTSParticleClr part in mergedParts)
  801. {
  802. mergedpartdb.SaveAParticle(part, part.GetXray(), (Point)part.GetAbsolutPos());
  803. }
  804. CPosXrayDBMgr pXrayDBMgr = pDBFileMgr.GetPosXrayDBMgr();
  805. CElementChemistryDB xraydb = pXrayDBMgr.GetElementChemistryDB();
  806. List<CPosXrayClr> ches = new List<CPosXrayClr>();
  807. foreach (COTSParticleClr part in mergedParts)
  808. {
  809. ches.Add(part.GetXray());
  810. }
  811. xraydb.SaveElementChemistriesList(ches);
  812. return true;
  813. }
  814. public bool SaveFieldData(COTSFieldData fldData, string filedFileFoler)
  815. {
  816. //loger.Warn("begin bitmap saving...");
  817. string strFieldFileFolder = filedFileFoler;
  818. CBSEImageFileMgr pBSEImgFileMgr = new CBSEImageFileMgr();
  819. pBSEImgFileMgr.SetBSEImg(fldData.GetBSEImage());
  820. int nId = fldData.GetId();
  821. string sFieldId;
  822. sFieldId = nId.ToString();
  823. string strBSEFilePathname = strFieldFileFolder + "\\" + m_pSampleRstFile.SMPL_MSR_RESULT_FIELDS_BSE + sFieldId + pBSEImgFileMgr.BMP_IMG_FILE_EXT;
  824. if (!pBSEImgFileMgr.SaveIntoBitmap(strBSEFilePathname))
  825. {
  826. log.Error("SaveFieldFiles: save BSE file failed.");
  827. return false;
  828. }
  829. // IncA Data list
  830. CIncAFileMgr pDBFileMgr = m_pSampleRstFile.DBFileMgr;
  831. pDBFileMgr.SaveStatusDataToDB();
  832. var fldDB = pDBFileMgr.GetFieldDB();
  833. log.Warn("Start saving particle data.");
  834. var fldcmd = fldDB.GetSavingAFieldcmdObj(fldData.GetId(), fldData.GetOTSPosition(), fldData.SemPos);
  835. List<KeyValuePair<string, System.Data.SQLite.SQLiteParameter[]>> fldcmds = new List<KeyValuePair<string, System.Data.SQLite.SQLiteParameter[]>>();
  836. fldcmds.Add(fldcmd);
  837. pDBFileMgr.ExecuteNonQueryBatch(ref fldcmds);
  838. //remomove the invalid particles
  839. var cmds = pDBFileMgr.GetSavingIncADataToDBCmds(curFldData.GetListAnalysisParticles(), fldData.GetOTSPosition());
  840. pDBFileMgr.ExecuteNonQueryBatch(ref cmds);
  841. CPosXrayDBMgr PosXrayDBMgr = pDBFileMgr.GetPosXrayDBMgr();
  842. var listAnalysisPosXray = new List<CPosXrayClr>();
  843. foreach (var p in curFldData.GetListXrayParticles())
  844. {
  845. listAnalysisPosXray.Add(p.GetXray());
  846. }
  847. var cmds1 = PosXrayDBMgr.GetSavingXrayCmds(listAnalysisPosXray, true);
  848. pDBFileMgr.ExecuteNonQueryBatch(ref cmds1);
  849. return true;
  850. }
  851. protected void SaveFieldMgrData()
  852. {
  853. while (bSaveThreadWorking)
  854. {
  855. while (fieldQueue.Count() > 0)
  856. {
  857. COTSFieldData f = fieldQueue.Dequeue();
  858. //save to disk first ,then pop . if the size is 0,then we know all the saving work is done.
  859. SaveFieldData(f, m_pSampleRstFile.GetFieldFileSubFolderStr());
  860. }
  861. if (fieldQueue.Count() == 0)
  862. {
  863. bSaveThreadWorking = false; //must set this flag,so the main thread can know this thread has exited.
  864. log.Warn("finished batch saving");
  865. return;
  866. }
  867. }
  868. return;
  869. }
  870. protected void StartSaveFileThread(COTSFieldData a_pFieldMgr)
  871. {
  872. fieldQueue.Enqueue(a_pFieldMgr);
  873. if (fieldQueue.Count() > 0) //if there's data in the queue and the previous thread has finished then start a new thread.
  874. {
  875. if (bSaveThreadWorking == false)
  876. {
  877. bSaveThreadWorking = true;
  878. m_thread_ptr = new System.Threading.Thread(this.SaveFieldMgrData);//m_thread_ptr = shared_ptr<thread>(new thread(&CSmplMeasureInc::SaveFieldMgrData, this));
  879. m_thread_ptr.IsBackground = true;
  880. m_thread_ptr.Start();
  881. }
  882. }
  883. }
  884. public void ParticleSpecialTreatment(COTSFieldData fld)
  885. {
  886. //we adopt such a strategy here:if some particles satisfy the predefined condition then we go through the second collecting with max EDS time,so that we got a more acurate result.
  887. Dictionary<COTSParticleClr, int> mapPartXray = new Dictionary<COTSParticleClr, int>(); //std.map<COTSParticlePtr, int> mapPartXray = new std.map<COTSParticlePtr, int>();
  888. double edsTime = 0; //to store the EDSTime returned from the engine.
  889. var bigparts = fld.GetListXrayParticles();
  890. var m_ClassifyEngine = new CClassifyEngine();
  891. for (int i = 0; i < bigparts.Count(); i++)
  892. {
  893. var engine = m_ClassifyEngine.GetParticleEngine(m_Sample.GetMsrParams().GetSTDName());
  894. var p = bigparts[i];
  895. // there will be very less particle satisfied the condition ,so we use only one MaxEDS time,though we set MaxEDSTime for every rule separately .Here we store the last one.
  896. //if the particle satisfied the MaxEDS condition then we go through the second colleting.Here we record the particle and the EDSTime and the corresponding xray position.
  897. edsTime = engine.IfNeedMaxEDS(p);
  898. if (edsTime > 0)
  899. {
  900. mapPartXray[p] = i;
  901. }
  902. }
  903. List<COTSParticleClr> partsMax = new List<COTSParticleClr>();
  904. if (mapPartXray.Count() > 0)
  905. {
  906. foreach (var p in mapPartXray)
  907. {
  908. partsMax.Add(p.Key);
  909. }
  910. List<CPosXrayClr> maxEDSXrays = new List<CPosXrayClr>();
  911. m_EDSHardwareMgr.GetXRayByFeatures(partsMax, edsTime, true);
  912. }
  913. }
  914. public void CalculateParticleAbsolutPos()
  915. {
  916. double dPixelSize = m_Sample.CalculatePixelSize();
  917. CSEMStageData pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
  918. foreach (var p in curFldData.GetListAnalysisParticles())
  919. {
  920. Point fldOtsPos = new Point(curFldData.OTSPos.X, curFldData.OTSPos.Y);
  921. Point semPos = new Point();
  922. pCSEMStageData.ConverOTSToSEMPoint(fldOtsPos, ref semPos);
  923. p.SetAbsolutPos(semPos);
  924. }
  925. }
  926. }
  927. }