CSmplMeasure.cs 48 KB

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