CSmplMeasure.cs 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400
  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 (8, 16, 32)
  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 (6, 16, 32)
  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 CalculateUnMeasuredFieldsCenters(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. CFieldPositionMgr pFieldMgr = new CFieldPositionMgr();
  196. // init field centers list manager
  197. if (!pFieldMgr.Init(sample.GetMsrDomain(), poImageScanParam, pImgProcParam.GetOverlapParam(), 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.SetTypeColor("#000000");
  359. particle.SetTypeName("LowCounts");
  360. return true;
  361. }
  362. }
  363. return false;
  364. }
  365. public virtual void ClassifyFieldParticles(COTSField curFldData)
  366. {
  367. return;
  368. }
  369. private class SEMStateObject
  370. {
  371. private PointF pos;
  372. private double workingDistance;
  373. private CSEMDataGnr semdata;
  374. private COTSSample originalSample;
  375. private double magnification;
  376. public PointF Pos { get => pos; set => pos = value; }
  377. public double WorkingDistance { get => workingDistance; set => workingDistance = value; }
  378. public CSEMDataGnr Semdata { get => semdata; set => semdata = value; }
  379. public double Magnification { get => magnification; set => magnification = value; }
  380. public COTSSample OriginalSample { get => originalSample; set => originalSample = value; }
  381. }
  382. private class AutoResetSEMControl:IDisposable
  383. {
  384. CSmplMeasure sm;
  385. private SEMStateObject semState=null;
  386. public AutoResetSEMControl(CSmplMeasure s)
  387. {
  388. sm = s;
  389. }
  390. public SEMStateObject SemState
  391. {
  392. get => semState;
  393. set => semState = value;
  394. }
  395. public void Dispose()
  396. {
  397. if (semState != null)
  398. {
  399. sm.SetBSEParam();
  400. sm.m_SemHardwareMgr.SetMagnification(semState.Magnification);
  401. Thread.Sleep(100);
  402. sm.MoveSEMToPoint(semState.Pos);
  403. Thread.Sleep(100);
  404. sm.m_SemHardwareMgr.SetWorkingDistance(semState.WorkingDistance);
  405. }
  406. sm.SetSEMExteralOff();
  407. }
  408. }
  409. private bool GetSEMDataGnrFromHw(ref CSEMDataGnr SemDataGnr)
  410. {
  411. double kv = 0, brightness = 0, contrast = 0;
  412. var hw = SemController.GetSEMController();
  413. hw.GetSemHighTension(ref kv);
  414. hw.GetSemBrightness(ref brightness);
  415. hw.GetSemContrast(ref contrast);
  416. SemDataGnr.SetValue(kv, brightness, contrast);
  417. return true;
  418. }
  419. public void DoMeasureForOneSample()
  420. {
  421. using (AutoResetSEMControl autoReset = new AutoResetSEMControl(this)) //when this method exit ,the SetSEMExternalOff and ResetScan will be called automatically.
  422. {
  423. // let the main thread to know that this sample measurement starts
  424. var pStatus = m_Sample.GetMsrStatus();
  425. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.INPROCESS);
  426. // set current time to current time
  427. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.START);
  428. // let main App know that the sample begin to measure
  429. ST_MSTMsg MsgSmpStart = new ST_MSTMsg(m_Sample);
  430. MsgSmpStart.InitSampleStartMsg();
  431. m_pMsrThread.SendMessageToMeasureGUI(MsgSmpStart);
  432. log.Info(m_Sample.GetName() + " Measurement started!");
  433. // get SEM controller to set magnification and working distance
  434. if (!SetSEMDataMrs(m_Sample))
  435. {
  436. log.Error("DoMeasure: fail to set SEM data.");
  437. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  438. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  439. return;
  440. }
  441. // set the BSE scan param
  442. if (!SetBSEParam())
  443. {
  444. log.Error("DoMeasure: fail to set BSE param.");
  445. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  446. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  447. return;
  448. }
  449. var pSEMDataGnr = new CSEMDataGnr();
  450. log.Info("Get Kv, Brightness and Contrast!");
  451. GetSEMDataGnrFromHw(ref pSEMDataGnr);
  452. m_pSampleRstFile.SetSEMGnr(pSEMDataGnr);
  453. // record SEM data
  454. COTSMsrPrjResultData pProjMgrFile = m_pMsrThread.GetProjResultData();
  455. CSEMStageData pSEMStageData = pProjMgrFile.GetSEMStageData();
  456. m_pSampleRstFile.SetSEMStageData(pSEMStageData);
  457. // record stage
  458. CStage pStage = pProjMgrFile.GetStage();
  459. m_pSampleRstFile.SetSEMStage(pStage);
  460. //-----save the static measure result file data into xml file and the dynamic data of every field will be saved into sqlite database
  461. log.Info("Create result file!");
  462. if (!m_pSampleRstFile.CreateResultFiles())
  463. {// failed to call measure result file Save method
  464. log.Error("DoMeasure: failed to call measure result file Save method.");
  465. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  466. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  467. return;
  468. }
  469. //------
  470. var FldDatas = m_Sample.GetFieldsData();
  471. for (int i = 0; i < FldDatas.Count; ++i)
  472. {// check and break if stop button is clicked
  473. var curFld = FldDatas[i];
  474. if (curFld.GetIsMeasureComplete())
  475. {
  476. continue;
  477. }
  478. if (IsPaused())
  479. {// measure stopped
  480. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.PAUSED);
  481. // record end time
  482. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  483. //must wait for the saving data thread finished,or we'll get null pointer exception when we stop the measure process.
  484. while (fieldQueue.Count() > 0)
  485. {
  486. Thread.Sleep(100);
  487. }
  488. SetSEMExteralOff();
  489. // update thread measure status class, let the main thread know that this sample measurement stopped
  490. ST_MSTMsg MsgSmpStop = new ST_MSTMsg(m_Sample);
  491. MsgSmpStop.InitSamplePausedMsg();
  492. m_pMsrThread.SendMessageToMeasureGUI(MsgSmpStop);
  493. while (IsPaused())
  494. {
  495. Thread.Sleep(300);
  496. }
  497. }
  498. if (IsAborted())
  499. {// measure stopped
  500. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.STOPPED);
  501. // record end time
  502. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  503. //must wait for the saving data thread finished,or we'll get null pointer exception when we stop the measure process.
  504. while (fieldQueue.Count() > 0)
  505. {
  506. Thread.Sleep(100);
  507. }
  508. break;
  509. }
  510. // check if sample measurement completes
  511. COTSImgScanPrm pScanParam = m_Sample.GetMsrParams().GetImageScanParam();
  512. if (IsSampleOver(pScanParam))
  513. {
  514. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
  515. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.COMPLT);
  516. break;
  517. }
  518. // get a field center
  519. System.Drawing.PointF poiFieldCentre = curFld.GetOTSPosition();
  520. // update thread measure status class, let the main thread know that starts a new field
  521. ST_MSTMsg MsgFieldStart = new ST_MSTMsg(m_Sample,curFld);
  522. MsgFieldStart.InitFieldStartMsg();
  523. m_pMsrThread.SendMessageToMeasureGUI(MsgFieldStart);
  524. int fldNo = curFld.GetId();
  525. log.Warn("Current field:" + fldNo.ToString());
  526. // move SEM to the field center
  527. if (!MoveSEMToPoint(poiFieldCentre))
  528. {// failed to move SEM to the position
  529. log.Error("DoMeasure: failed to move SEM to the field centre point.");
  530. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  531. // record end time
  532. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  533. return;
  534. }
  535. log.Info("Begin to Acquire BSE image!");
  536. // take BSE image for the fields
  537. CBSEImgClr pBSEImg = AcquireABSEImage();
  538. // let the main thread to know that image process is completed
  539. if (pBSEImg == null)
  540. {
  541. log.Error("ImageProcess: can't get no background image.");
  542. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  543. return;
  544. }
  545. curFld.SetBSEImage(pBSEImg);
  546. //BSEData
  547. ST_MSTMsg MsgFieldBSE = new ST_MSTMsg(m_Sample,curFld);
  548. MsgFieldBSE.InitFieldBSEImageMsg();
  549. m_pMsrThread.SendMessageToMeasureGUI(MsgFieldBSE);
  550. log.Info("Acquire BSE image success! Processing image...");
  551. // image process
  552. FieldImageProcess(curFld);
  553. COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
  554. if (pXRayParam.GetUsingXray() == true)
  555. {
  556. CollectParticlesXrayData(curFld);
  557. }
  558. m_Sample.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
  559. curFld.SetIsMeasureComplete(true);
  560. log.Info("Begin to classify particles! particle num:" + curFld.GetListAnalysisParticles().Count);
  561. ClassifyFieldParticles(curFld);
  562. //start db save
  563. StartSaveFileThread(ref curFld);
  564. SendFieldParticlesInfoToGUI(curFld, m_Sample.GetMsrStatus());
  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. TheLastWorkOfSampleMeasure();
  572. }
  573. }
  574. public void TheLastWorkOfSampleMeasure()
  575. {
  576. COTSSample theSample = m_Sample;
  577. var pStatus = theSample.GetMsrStatus();
  578. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.COMPLT);
  579. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
  580. // let main thread to know that this sample measurement completes
  581. ST_MSTMsg MsgSmplEnd = new ST_MSTMsg(m_Sample);
  582. MsgSmplEnd.InitSampleCompleteMsg();
  583. m_pMsrThread.SendMessageToMeasureGUI(MsgSmplEnd);
  584. string userdB = m_Sample.GetMsrParams().GetSTDName();
  585. if(userdB.ToLower() != "nostddb" && userdB.ToLower() != "nostddb.db")
  586. {
  587. try
  588. {
  589. string userdBpath= Application.StartupPath + "\\Config\\SysData\\" + m_Sample.GetMsrParams().GetSTDName() + ".db";
  590. File.Copy(userdBpath, m_pSampleRstFile.GetFieldFileSubFolderStr().Remove(m_pSampleRstFile.GetFieldFileSubFolderStr().IndexOf("FIELD_FILES")) + m_Sample.GetMsrParams().GetSTDName() + ".db", true);
  591. }
  592. catch(Exception ex)
  593. {
  594. MessageBox.Show("userdB copy failed:" + ex.ToString());
  595. }
  596. }
  597. }
  598. public bool DoMEasureForReMeasure()
  599. {
  600. return true;
  601. }
  602. public virtual void FieldImageProcess(COTSField curFldData)
  603. {
  604. PointF fldCenter = curFldData.GetOTSPosition();
  605. CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
  606. PointF semPos = new Point();
  607. a_pCSEMStageData.ConvertOTSToSEMCoord(fldCenter, ref semPos);
  608. curFldData.SetSemPos(semPos);
  609. //first step:remove background of the bse image and compound all the finded particles.
  610. log.Info("Begin to process image and get all particles!");
  611. GetOriginalParticles(ref curFldData);
  612. // second step :filter the finded particles.
  613. log.Info("Begin to filter particles!");
  614. FilterParticles(ref curFldData);
  615. CalculateParticleAbsolutPos(ref curFldData);
  616. log.Info("Begin to Calculate the image property of every particle!");
  617. var analysisparts = curFldData.GetListAnalysisParticles();
  618. curFldData.CalParticleImageProp(analysisparts);//calculate particle image property such as feret diameter, DMAX etc.
  619. return ;
  620. }
  621. private void FilterParticles(ref COTSField curFldData)
  622. {
  623. var listXray = curFldData.GetAllParticles().OrderByDescending(x => x.GetActualArea()).ToList();
  624. var listXray1 = new List<COTSParticleClr>();
  625. var pXRayParam =m_Sample.GetMsrParams().GetXRayParam();
  626. if (listXray.Count > pXRayParam.GetXrayLimit())
  627. {
  628. for (var i = 0; i < pXRayParam.GetXrayLimit(); i++)
  629. {
  630. listXray1.Add(listXray[i]);
  631. }
  632. }
  633. else
  634. {
  635. listXray1 = listXray;
  636. }
  637. curFldData.SetListAnalysisParticles(listXray1);
  638. log.Info("Analysis particles:" + listXray1.Count);
  639. }
  640. public void GetOriginalParticles(ref COTSField curFldData)
  641. {
  642. // get image process parameter
  643. CSampleParam pMsrParam = m_Sample.GetMsrParams();
  644. COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
  645. var specialPartsparam = pMsrParam.GetSpecialGrayRangeParam();
  646. var pixelsize = m_Sample.CalculatePixelSize();
  647. if (specialPartsparam != null && specialPartsparam.GetIsToRun())
  648. {
  649. List<CSpecialGrayRange> ranges = pMsrParam.GetSpecialGrayRangeParam().GetSpecialGreyRanges();
  650. foreach (var grayRange in ranges)
  651. {
  652. CIntRangeClr range = new CIntRangeClr(grayRange.range.GetStart(), grayRange.range.GetEnd());
  653. CDoubleRangeClr diaRange = new CDoubleRangeClr(grayRange.diameterRange.GetStart(), grayRange.diameterRange.GetEnd());
  654. curFldData.GetPartsBySpecialGray(range, diaRange, pixelsize, grayRange.ifCollectXray);
  655. }
  656. }
  657. var ifCollectxray = pMsrParam.GetXRayParam().GetUsingXray();
  658. // remove BES image background
  659. curFldData.RemoveImgBGAndGetParticles(pImgProcessParam, pixelsize, ifCollectxray);
  660. // check if this is an empty image
  661. if (curFldData.NoParticle())
  662. { // empty fields
  663. log.Info("ImageProcess: empty field.");
  664. return;
  665. }
  666. double dPixelSize = m_Sample.CalculatePixelSize();
  667. curFldData.InitParticles(pImgProcessParam, dPixelSize);
  668. return;
  669. }
  670. public virtual void CollectParticlesXrayData(COTSField curFldData)
  671. {
  672. var allParts = curFldData.GetListXrayParticles();
  673. var smallparts = new List<COTSParticleClr>();
  674. var bigparts = new List<COTSParticleClr>();
  675. double quantifyThreshold = m_Sample.GetMsrParams().GetXRayParam().GetFeatureModeMinSize();
  676. foreach (var part in allParts)
  677. {
  678. double equalCircleDiameter = Math.Sqrt(part.GetActualArea() / 3.14159) * 2f;
  679. if (equalCircleDiameter < quantifyThreshold)
  680. {
  681. smallparts.Add(part);
  682. }
  683. else
  684. {
  685. bigparts.Add(part);
  686. }
  687. }
  688. log.Info("SmallQuantifyParts (<" + quantifyThreshold.ToString("f2") + "): " + smallparts.Count);
  689. log.Info("BigQuantifyParts (>=" + quantifyThreshold.ToString("f2") + "): " + bigparts.Count);
  690. curFldData.CreateXrayList(smallparts);
  691. curFldData.CreateXrayList(bigparts);
  692. // get x-ray parameters
  693. COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
  694. var workmode = pXRayParam.GetScanMode();
  695. if (workmode == OTS_X_RAY_SCAN_MODE.PointMode)
  696. {
  697. uint nXRayAQTime;
  698. if (bigparts.Count > 0)
  699. {
  700. nXRayAQTime = (uint)pXRayParam.GetMidAnalyAQTime();
  701. log.Info("Begin to collect xraydata:" + bigparts.Count +"(" +nXRayAQTime.ToString()+") on " + workmode.ToString());
  702. m_EDSController.GetXRayByParts(bigparts, nXRayAQTime, true);
  703. }
  704. if (smallparts.Count > 0)
  705. {
  706. Thread.Sleep(500);//add delay here,or else the eds system will halt.
  707. nXRayAQTime = (uint)pXRayParam.GetSmallPartXrayTime();
  708. log.Info("Begin to collect xraydata:" + smallparts.Count + "(" + nXRayAQTime.ToString() + ") on " + workmode.ToString());
  709. m_EDSController.GetXRayByParts(smallparts, nXRayAQTime, true);
  710. }
  711. }
  712. else if (workmode == OTS_X_RAY_SCAN_MODE.FeatureMode)
  713. {
  714. uint nXRayAQTime;
  715. if (bigparts.Count > 0)
  716. {
  717. log.Info("Begin to collect xraydata:" + bigparts.Count + " on " + OTS_X_RAY_SCAN_MODE.FeatureMode.ToString());
  718. nXRayAQTime = (uint)pXRayParam.GetMidAnalyAQTime();
  719. m_EDSController.GetXRayByFeatures(bigparts, nXRayAQTime, true);
  720. }
  721. if (smallparts.Count > 0)
  722. {
  723. Thread.Sleep(500);
  724. log.Info("Begin to collect xraydata:" + smallparts.Count + " on " + OTS_X_RAY_SCAN_MODE.PointMode.ToString());
  725. nXRayAQTime = (uint)pXRayParam.GetSmallPartXrayTime();
  726. m_EDSController.GetXRayByParts(smallparts, nXRayAQTime, true);
  727. }
  728. }
  729. return;
  730. }
  731. public virtual void QuantifyParticlesXrayData(COTSField curFldData)
  732. {
  733. var parts = curFldData.GetListXrayParticles();
  734. foreach (var p in parts)
  735. {
  736. m_EDSController.QuantifyXrayByPart(p);
  737. }
  738. }
  739. public void DoHolePreview()
  740. {
  741. using (AutoResetSEMControl autoReset = new AutoResetSEMControl(this))
  742. {
  743. //----------memorize the state of sem
  744. var semstate = new SEMStateObject();
  745. double dMagnification = m_Sample.GetSEMDataMsr().GetMagnification();
  746. double wd = m_Sample.GetSEMDataMsr().GetWorkingDistance();
  747. ISemController sem = m_SemHardwareMgr;
  748. double posX=0, posY=0,posR=0;
  749. sem.GetSemPositionXY(ref posX, ref posY, ref posR);
  750. CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
  751. Point pos = new Point((int)posX, (int)posY);
  752. PointF otsPos = new Point(0, 0);
  753. if (!a_pCSEMStageData.ConvertSEMToOTSCoord(pos, ref otsPos))
  754. {
  755. return;
  756. }
  757. semstate.Pos = otsPos;
  758. semstate.Magnification = dMagnification;
  759. semstate.WorkingDistance = wd;
  760. autoReset.SemState = semstate;
  761. //-------------------------------------
  762. // let the main thread to know that this sample measurement starts
  763. CMsrSampleStatus pStatus = m_HolePreviewSample.GetMsrStatus();
  764. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.INPROCESS);
  765. // set current time to current time
  766. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.START);
  767. // get SEM controller to set magnification and working distance
  768. if (!SetSEMDataMrs(m_HolePreviewSample))
  769. {
  770. log.Error("DoHolePreview: fail to set SEM data.");
  771. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  772. // record end time
  773. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  774. return;
  775. }
  776. // set the BSE scan param
  777. if (!SetHoleBSEParam(m_HolePreviewSample))
  778. {
  779. log.Error("DoHolePreview: fail to set BSE param.");
  780. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  781. // record end time
  782. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  783. return;
  784. }
  785. // calculate field centers
  786. List<System.Drawing.Point> listFieldCenter;
  787. List<System.Drawing.Point> alllistFieldCenter ;
  788. if (!CalculateUnMeasuredFieldsCenters(m_HolePreviewSample, out alllistFieldCenter,out listFieldCenter))
  789. {// failed to calculate field centers
  790. log.Error("DoHolePreview: failed to calculate field centers.");
  791. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  792. // record end time
  793. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  794. return;
  795. }
  796. // go through each field
  797. //int nNewFieldId = 0;
  798. for ( int i = 0; i < listFieldCenter.Count; ++i)
  799. {// check and break if stop button is clicked
  800. if (IsAborted())
  801. {// measure stopped
  802. log.Trace("DoHolePreview: measure thread is stopped.");
  803. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.STOPPED);
  804. // record end time
  805. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  806. return;
  807. }
  808. // check if sample measurement completes
  809. COTSImgScanPrm pScanParam = m_Sample.GetMsrParams().GetImageScanParam();
  810. int nTotalFieldSize = listFieldCenter.Count;
  811. // get a field center
  812. System.Drawing.Point poiFieldCentre = listFieldCenter[i];
  813. // move SEM to the field center
  814. if (!MoveSEMToPoint(poiFieldCentre))
  815. {// failed to move SEM to the position
  816. log.Error("DoHolePreview: failed to move SEM to the field centre point.");
  817. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  818. // record end time
  819. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  820. return;
  821. }
  822. // take BSE image for the fields
  823. CBSEImgClr pBSEIamge = AcquireABSEImage();
  824. if (pBSEIamge==null)
  825. {
  826. // failed to acquire a BSE image
  827. log.Error("DoHolePreview: failed to acquire a BSE image.");
  828. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  829. // record end time
  830. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  831. return;
  832. }
  833. //BSEData
  834. ST_MSTMsg MsgFieldBSE=new ST_MSTMsg(m_HolePreviewSample);
  835. MsgFieldBSE.InitHolePreBSEDataMsg(pBSEIamge,poiFieldCentre);
  836. m_pMsrThread.SendHolePreviewMessageToMeasureGUI(MsgFieldBSE);
  837. if (pStatus.GetStatus() != OTS_MSR_SAMPLE_STATUS.INPROCESS)
  838. {
  839. // measurement failed or stopped
  840. log.Error("DoHolePreview: measurement failed or stopped.");
  841. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
  842. // record end time
  843. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  844. return;
  845. }
  846. //save the result to project file
  847. Rectangle oImageRect = (Rectangle)pBSEIamge.GetImageRect();
  848. CHoleBSEImg pHoleBSEImg =new CHoleBSEImg(oImageRect,poiFieldCentre);
  849. pHoleBSEImg.SetImageData( pBSEIamge.GetImageDataPtr(),oImageRect.Width,oImageRect.Height);
  850. m_listHoleBSEImg.Add(pHoleBSEImg);
  851. }
  852. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  853. //calculate measure time
  854. pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
  855. // let main thread to know that this sample measurement completes
  856. ST_MSTMsg MsgSmplEnd=new ST_MSTMsg(m_HolePreviewSample);
  857. MsgSmplEnd.InitHolePreSampleEndMsg();
  858. m_pMsrThread.SendHolePreviewMessageToMeasureGUI(MsgSmplEnd);
  859. }
  860. }
  861. // Cumulate field data info
  862. public virtual bool CumulateFieldData( List<COTSParticleClr> listParticles, double a_nMeasuredArea)
  863. {
  864. // get measure result items of the sample
  865. CMsrResultItems pMsrResults = m_Sample.GetMsrResults();
  866. // cumulate field data info
  867. pMsrResults.CumulateMeasuredArea(a_nMeasuredArea);
  868. // cumulate ratio
  869. double dRatio = 10000 * pMsrResults.GetTotalParticleArea();
  870. dRatio = dRatio / pMsrResults.GetMeasuredArea();
  871. pMsrResults.SetRatio(dRatio);
  872. // go through the particles list
  873. foreach (COTSParticleClr pParticle in listParticles)
  874. {
  875. // create a measure result item
  876. pMsrResults.CumulateMeasureResult(pParticle);
  877. }
  878. m_Sample.SetMsrResults(pMsrResults);
  879. // ok, return TRUE
  880. return true;
  881. }
  882. public bool SaveFieldData(COTSField fldData, string filedFileFoler)
  883. {
  884. string strFieldFileFolder = filedFileFoler;
  885. CBSEImageFileMgr pBSEImgFileMgr = new CBSEImageFileMgr();
  886. pBSEImgFileMgr.SetBSEImg(fldData.GetBSEImage());
  887. int nId = fldData.GetId();
  888. string sFieldId;
  889. sFieldId = nId.ToString();
  890. string strBSEFilePathname = strFieldFileFolder + "\\" + m_pSampleRstFile.SMPL_MSR_RESULT_FIELDS_BSE + sFieldId + pBSEImgFileMgr.BMP_IMG_FILE_EXT;
  891. if (!pBSEImgFileMgr.SaveIntoBitmap(strBSEFilePathname))
  892. {
  893. log.Error("SaveFieldFiles: save BSE file failed.");
  894. return false;
  895. }
  896. // IncA Data list
  897. CIncAFileMgr pDBFileMgr = m_pSampleRstFile.DBFileMgr;
  898. pDBFileMgr.SaveStatusDataToDB();
  899. var fldDB = pDBFileMgr.GetFieldDB();
  900. log.Warn("Start saving particle data.");
  901. var fldcmd = fldDB.GetSavingAFieldcmdObj(fldData.GetId(), fldData.GetOTSPosition(), fldData.GetSemPos());
  902. List<KeyValuePair<string, System.Data.SQLite.SQLiteParameter[]>> fldcmds = new List<KeyValuePair<string, System.Data.SQLite.SQLiteParameter[]>>();
  903. fldcmds.Add(fldcmd);
  904. pDBFileMgr.ExecuteNonQueryBatch(ref fldcmds);
  905. //remomove the invalid particles
  906. var cmds = pDBFileMgr.GetSavingParticleDataToDBCmds(fldData.GetListAnalysisParticles(), fldData.GetOTSPosition());
  907. pDBFileMgr.ExecuteNonQueryBatch(ref cmds);
  908. CPosXrayDBMgr PosXrayDBMgr = pDBFileMgr.GetPosXrayDBMgr();
  909. var listAnalysisPosXray = new List<CPosXrayClr>();
  910. foreach (var p in fldData.GetListXrayParticles())
  911. {
  912. listAnalysisPosXray.Add(p.GetXray());
  913. }
  914. var cmds1 = PosXrayDBMgr.GetSavingXrayCmds(listAnalysisPosXray, true);
  915. pDBFileMgr.ExecuteNonQueryBatch(ref cmds1);
  916. return true;
  917. }
  918. protected void SaveFieldMgrData()
  919. {
  920. while (bSaveThreadWorking)
  921. {
  922. while (fieldQueue.Count() > 0)
  923. {
  924. COTSField f = fieldQueue.Dequeue();
  925. //save to disk first ,then pop . if the size is 0,then we know all the saving work is done.
  926. log.Info("Begin to save particles data! particle num:" + f.GetListAnalysisParticles().Count);
  927. SaveFieldData(f, m_pSampleRstFile.GetFieldFileSubFolderStr());
  928. }
  929. if (fieldQueue.Count() == 0)
  930. {
  931. bSaveThreadWorking = false; //must set this flag,so the main thread can know this thread has exited.
  932. log.Warn("finished batch saving");
  933. return;
  934. }
  935. }
  936. return;
  937. }
  938. private void SendFieldParticlesInfoToGUI(COTSField curFld,CMsrSampleStatus pStatus)
  939. {
  940. double measuredArea = 0; // this area should be the field area
  941. var a_pBSEImg = curFld.GetBSEImage();
  942. double dPixelSize = curFld.GetPixelSize();
  943. measuredArea = a_pBSEImg.GetHeight() * a_pBSEImg.GetWidth() * dPixelSize * dPixelSize; //Get measured area
  944. CumulateFieldData(curFld.GetListAnalysisParticles(), measuredArea);
  945. log.Info("Send field data to screen!");
  946. pStatus.AddCompletedFieldCenter(curFld.GetOTSPosition());
  947. //Field Data
  948. // record end time
  949. pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
  950. ST_MSTMsg MsgFieldEnd = new ST_MSTMsg(m_Sample,curFld);
  951. MsgFieldEnd.InitFieldDataMsg();
  952. m_pMsrThread.SendMessageToMeasureGUI(MsgFieldEnd);
  953. }
  954. protected void StartSaveFileThread(ref COTSField a_pFieldMgr)
  955. {
  956. fieldQueue.Enqueue(a_pFieldMgr);
  957. if (fieldQueue.Count() > 0) //if there's data in the queue and the previous thread has finished then start a new thread.
  958. {
  959. if (bSaveThreadWorking == false)
  960. {
  961. bSaveThreadWorking = true;
  962. m_thread_ptr = new System.Threading.Thread(this.SaveFieldMgrData);//m_thread_ptr = shared_ptr<thread>(new thread(&CSmplMeasureInc::SaveFieldMgrData, this));
  963. m_thread_ptr.IsBackground = true;
  964. m_thread_ptr.Start();
  965. }
  966. }
  967. }
  968. public void ParticleSpecialTreatment(ref COTSField fld)
  969. {
  970. //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.
  971. Dictionary<COTSParticleClr, int> mapPartXray = new Dictionary<COTSParticleClr, int>();
  972. double edsTime = 0; //to store the EDSTime returned from the engine.
  973. var bigparts = fld.GetListXrayParticles();
  974. var m_ClassifyEngine = new CClassifyEngine();
  975. for (int i = 0; i < bigparts.Count(); i++)
  976. {
  977. var engine = m_ClassifyEngine.GetExpressionClassifyEngine(m_Sample.GetMsrParams().GetSTDName());
  978. var p = bigparts[i];
  979. // 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.
  980. //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.
  981. edsTime = engine.IfNeedMaxEDS(p);
  982. if (edsTime > 0)
  983. {
  984. mapPartXray[p] = i;
  985. }
  986. }
  987. List<COTSParticleClr> partsMax = new List<COTSParticleClr>();
  988. if (mapPartXray.Count() > 0)
  989. {
  990. foreach (var p in mapPartXray)
  991. {
  992. partsMax.Add(p.Key);
  993. }
  994. List<CPosXrayClr> maxEDSXrays = new List<CPosXrayClr>();
  995. m_EDSController.GetXRayByFeatures(partsMax, edsTime, true);
  996. }
  997. }
  998. public void CalculateParticleAbsolutPos(ref COTSField curFldData)
  999. {
  1000. double dPixelSize = m_Sample.CalculatePixelSize();
  1001. CSEMStageData pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
  1002. foreach (var p in curFldData.GetListAnalysisParticles())
  1003. {
  1004. //Point fldOtsPos = new Point((curFldData.OTSPos.X, curFldData.OTSPos.Y);
  1005. PointF semP = new PointF(); ;
  1006. Point semPos = new Point();
  1007. pCSEMStageData.ConvertOTSToSEMCoord(curFldData.GetOTSPosition(), ref semP);
  1008. semPos.X = (int)semP.X;
  1009. semPos.Y = (int)semP.Y;
  1010. p.SetAbsolutPos(semPos);
  1011. }
  1012. }
  1013. }
  1014. }