CSmplMeasure.cs 50 KB

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