CSmplMeasure.cs 47 KB

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