12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using OTSModelSharp.ServiceInterface;
- using static OTSDataType.otsdataconst;
- using OTSDataType;
- using System.Diagnostics;
- using System.Drawing;
- using System.Threading;
- using OTSModelSharp.DTLBase;
- using OTSCLRINTERFACE;
- using OTSModelSharp.ServiceCenter;
- using OTSMeasureApp._0_OTSModel.Measure.ParamData;
- namespace OTSModelSharp
- {
- using CHoleBSEImgsList = List<CHoleBSEImg>;
- class CSmplMeasure
- {
- protected static NLog.Logger log ;
- protected bool bSaveThreadWorking;
- protected System.Threading.Thread m_thread_ptr;
-
- protected COTSSample m_Sample;
- protected CMeasure m_pMsrThread;
- string m_strWorkingFolder;
- protected CSmplMsrResult m_pSampleRstFile;
- CHoleBSEImgsList m_listHoleBSEImg;
- //CFunExportClass loger;
- protected SemController m_SemHardwareMgr;
- protected ScanController m_ScanHardwareMgr;
- protected EDSController m_EDSHardwareMgr;
-
- protected Queue<COTSFieldData> fieldQueue=new Queue<COTSFieldData>();
- protected COTSFieldData curFldData;
- protected IClassifyEngine m_classifyEngine;
- public CSmplMeasure()
- {
-
- log = NLog.LogManager.GetCurrentClassLogger();
-
- m_pSampleRstFile = new CSmplMsrResult();
- m_SemHardwareMgr = SemController.GetSEMController();
- m_ScanHardwareMgr = ScanController.GetScanController();
- m_EDSHardwareMgr = EDSController.GetEDSController();
- m_listHoleBSEImg = new CHoleBSEImgsList();
- }
- public CSmplMeasure( string a_strWorkingFolder, COTSSample a_pSample)
- {
-
- log = NLog.LogManager.GetCurrentClassLogger();
-
- m_strWorkingFolder = a_strWorkingFolder;
- m_pSampleRstFile = new CSmplMsrResult( a_strWorkingFolder, a_pSample);// new CSmplMsrResultFile(m_strWorkingFolder,a_pSample);
- m_SemHardwareMgr = SemController.GetSEMController();
- m_ScanHardwareMgr = ScanController.GetScanController();
- m_EDSHardwareMgr = EDSController.GetEDSController();
- m_listHoleBSEImg = new CHoleBSEImgsList();
- m_Sample = a_pSample;
-
- }
- public void SetSample(COTSSample a_pSample)
- {
-
- m_Sample = a_pSample;
- m_pSampleRstFile.SetSample(a_pSample);
- }
- public void SetMsrThread(CMeasure mt)
- {
- m_pMsrThread = mt;
-
-
- }
- bool SetSEMDataMrs()
- {
- var pSEMDataMsr = m_Sample.GetSEMDataMsr();
- //ASSERT(pSEMDataMsr);
- double dMag = pSEMDataMsr.GetMagnification();
- double dWorkDis = pSEMDataMsr.GetWorkingDistance();
- //CSemBasePtr pSEMCtrlPtr = GetSEMControl();
- var pSEMCtrl = m_pMsrThread.GetSEMController();
- // get SEM controller
- if (!pSEMCtrl.IsConnected())
- {
- if (!pSEMCtrl.Connect())
- {
- log.Error("SetSEMDataMrs: can't connect SEM.");
- return false;
- }
- }
-
- pSEMCtrl.SetMagnification(dMag);
- pSEMCtrl.SetWorkingDistance(dWorkDis);
- return true;
- }
- bool SetSEMExteralOn()
- {
- var pSEMCtrl = m_SemHardwareMgr;
- // get SEM controller
- if (!pSEMCtrl.IsConnected())
- {
- if (!pSEMCtrl.Connect())
- {
- log.Error("SetSEMExteralOn: can't connect SEM.");
- return false;
- }
- }
- log.Warn("Set Scan Exteral on!");
- pSEMCtrl.SetScanExternal(true);
- return true;
- }
- // set SEM external off
- bool SetSEMExteralOff()
- {
- var pSEMCtrlPtr = m_SemHardwareMgr;
- // get SEM controller
- if (!pSEMCtrlPtr.IsConnected())
- {
- if (!pSEMCtrlPtr.Connect())
- {
- log.Error("SetSEMExteralOff: can't connect SEM.");
- return false;
- }
- }
- log.Warn("Set SEM Exteral Off!");
- pSEMCtrlPtr.SetScanExternal(false);
- return true;
- }
- bool SetBSEParam()
- {
- // get SEM controller
- var pSEMController = m_SemHardwareMgr;
- // get scan controller
- var pScanController = m_ScanHardwareMgr;
- // scan parameters
- var pMsrParam = m_Sample.GetMsrParams();
- var pImgScanParam = pMsrParam.GetImageScanParam();
- // get image size
- var nImageSizeId = pImgScanParam.GetImageResulotion();
- int nResulotionId = RESOLUTION_ID_FIRST_TIE + (int)nImageSizeId;
- Size sizePixelImage = RESOLUTION_VALUE[nResulotionId];
- // get SEM controller
- if (!pSEMController.IsConnected())
- {
- if (!pSEMController.Connect())
- {
- log.Error("SetBSEParam: can't connect SEM.");
- return false;
- }
- }
- // get dwell time
- OTS_IMAGE_SCANSPEED_OPTIONS nDwellTime = pImgScanParam.GetScanImageSpeed();
- // convert dwell time to bruker dwell time (8, 16, 32)
- int nBrukerDwellTimeId=3;
- switch (nDwellTime)
- {
- case OTS_IMAGE_SCANSPEED_OPTIONS.low:
- nBrukerDwellTimeId = 3;
- break;
- case OTS_IMAGE_SCANSPEED_OPTIONS.meddium:
- nBrukerDwellTimeId = 4;
- break;
- case OTS_IMAGE_SCANSPEED_OPTIONS.high:
- nBrukerDwellTimeId = 5;
- break;
- default:
- nBrukerDwellTimeId = 3;
- break;
- }
- long nBrukerDwellTime = OTSDataType.otsdataconst.DWELLTIME_BRUKER_VALUES[nBrukerDwellTimeId];
- if (!pScanController.Init())
- {
- log.Error("SetBSEParam: failed to get scan control.");
-
- return false;
- }
- // set dwell time
- if (!pScanController.SetDwellTime(nBrukerDwellTime))
- {
- log.Error("SetBSEParam: failed to set dwell time (%d) for bruker system.", nBrukerDwellTime);
- return false;
- }
- // set image size
- if (!pScanController.SetImageSize(sizePixelImage.Width,sizePixelImage.Height))
- {
- // failed to set dwell time
- log.Error("SetBSEParam: failed to set dwell time (%d).", sizePixelImage.Height);
- return false;
- }
- return true;
- }
- bool SetHoleBSEParam()
- {
- // get SEM controller
- var pSEMController = m_SemHardwareMgr;
- // get scan controller
- var pScanController = m_ScanHardwareMgr;
- // scan parameters
- var pMsrParam = m_Sample.GetMsrParams();
- var pImgScanParam = pMsrParam.GetImageScanParam();
- // get image size
- var nImageSizeId = pImgScanParam.GetImageResulotion();
- int nResulotionId = RESOLUTION_ID_FIRST_TIE + (int)nImageSizeId;
- Size sizePixelImage = RESOLUTION_VALUE[nResulotionId];
- // get SEM controller
- if (!pSEMController.IsConnected())
- {
- if (!pSEMController.Connect())
- {
- log.Error("SetBSEParam: can't connect SEM.");
- return false;
- }
- }
- // get dwell time
- OTS_IMAGE_SCANSPEED_OPTIONS nDwellTime = pImgScanParam.GetScanImageSpeed();
- // convert dwell time to bruker dwell time (6, 16, 32)
- 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.
- if (!pScanController.Init())
- {
- log.Error("SetBSEParam: failed to get scan control.");
- return false;
- }
- // set dwell time
- if (!pScanController.SetDwellTime(nBrukerDwellTime))
- {
- log.Error("SetBSEParam: failed to set dwell time (%d) for bruker system.", nBrukerDwellTime);
- return false;
- }
- // set image size
- if (!pScanController.SetImageSize(sizePixelImage.Width/2, sizePixelImage.Height/2))
- {
- // failed to set dwell time
- log.Error("SetBSEParam: failed to set dwell time (%d).", sizePixelImage.Height);
- return false;
- }
- return true;
- }
-
- public void SetWorkingFolder(String a_strWorkingFolder)
- {
- // add "\\" at the string end if it is not "\\"
- if (a_strWorkingFolder.PadRight(1)!="\\")
- {
- a_strWorkingFolder += "\\";
- }
- m_strWorkingFolder = a_strWorkingFolder + m_Sample.GetName() + "\\";
- }
- bool CalculateUnMeasuredFieldsCenters(out List<System.Drawing.Point> a_allpieldcenter,out List<System.Drawing.Point> a_listFieldCenter)
- {
- // sample measure parameters
- CSampleParam pMsrParam = m_Sample.GetMsrParams();
- COTSImgScanPrm poImageScanParam = pMsrParam.GetImageScanParam();
- CSEMDataMsr poSEMDataMsr = m_Sample.GetSEMDataMsr();
- CMsrSampleStatus pStatus = m_Sample.GetMsrStatus();
- // measured field centers list
- List<System.Drawing.Point> listCompletedCenter = pStatus.GetCompletedFieldsCenter();
- // field centers list manager
- CFieldPositionMgr pFieldMgr = new CFieldPositionMgr();
- // init field centers list manager
- if (!pFieldMgr.Init(m_Sample.GetMsrArea(), poImageScanParam, poSEMDataMsr, listCompletedCenter))
- {
- log.Error("CalculateFieldsCenters: failed to init field centres list manager.");
- a_listFieldCenter = new List<System.Drawing.Point>();
- a_allpieldcenter = new List<Point>();
- return false;
- }
- // get field centers list
- a_listFieldCenter = pFieldMgr.GetUnmeasuredFieldCentrePoints();// GetFieldCentrePoints();
- a_allpieldcenter = pFieldMgr.GetFieldCentrePoints();
- // ok, return TRUE
- return true;
- }
- protected bool IsAborted()
- {
- //Debug.Assert(m_pMsrThread == null);
- return m_pMsrThread.IsMeasureStopped();
- }
- bool IsSampleOver(COTSImgScanPrm a_pScanParam, int a_nTotalFields)
- {
-
- string sStopMode = a_pScanParam.GetStopMode();
- int nStopField = a_pScanParam.GetStopParamFields();
- // completed fields number
- CMsrSampleStatus pMsrSampleStatus = m_Sample.GetMsrStatus();
- int nCompeltedField = pMsrSampleStatus.GetCompletedFields();
- CMsrDisplayResults pMsrResults = m_Sample.GetMsrResults();
- List<CMsrResultItem> listMsrResult = pMsrResults.GetResultItems();
- int nNumParticle = 0;
- foreach (var pResult in listMsrResult)
- {
- if (pResult.GetTypeId() > (int)OTS_PARTCLE_TYPE.NOT_IDENTIFIED)//summarize the number of the identified particle in this condition
- {
- nNumParticle += (int)pResult.GetNumber();
- }
- }
- TimeSpan timeSpan = pMsrSampleStatus.GetUsedTime();
- int nDay = timeSpan.Days;
- int nHour = timeSpan.Hours;
- int nMin = timeSpan.Minutes;
- int nSec = timeSpan.Seconds;
- int nUsedTime = nSec + nMin * 60 + nHour * 3600 + nDay * 86400;
- int NMeasArea = (int)pMsrResults.GetMeasuredArea();
- int nParticlAim = a_pScanParam.GetStopParamParticles();
- int nMeasTimeAim = a_pScanParam.GetStopParamMeasTime();
- int NMeasAreaAim = a_pScanParam.GetStopParamArea()*1000000 ;
- bool bRet = false;
- string[] str = sStopMode.Replace(" ", "").Split('+');
- for(int i=0;i< str.Length;i++)
- {
- switch (int.Parse(str[i].Split(':')[0])-1)
- {
- case (int)OTS_MEASURE_STOP_MODE.CoverMode:
- // completed fields number
- if (nCompeltedField == a_nTotalFields)
- {
- bRet = true;
- }
- break;
- case (int)OTS_MEASURE_STOP_MODE.FieldMode:
- if (nCompeltedField >= nStopField)
- {
- bRet = true;
- }
- break;
- case (int)OTS_MEASURE_STOP_MODE.ParticleMode:
- if (nNumParticle >= nParticlAim)
- {
- bRet = true;
- }
- break;
- case (int)OTS_MEASURE_STOP_MODE.TimeMode:
- if (nUsedTime >= nMeasTimeAim)
- {
- bRet = true;
- }
- break;
- case (int)OTS_MEASURE_STOP_MODE.AreaMode:
- if (NMeasArea >= NMeasAreaAim)
- {
- bRet = true;
- }
- break;
- default:
- break;
- }
- }
- return bRet;
- }
- // move SEM to the point
- bool MoveSEMToPoint(System.Drawing.Point a_poi)
- {
- // get SEM controller
- var pSEMController = m_SemHardwareMgr;
-
- Point a_SEMpt = new Point();
-
- CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
- int hardWareDelay = a_pCSEMStageData.GetHardWareDelay();
- if (!a_pCSEMStageData.ConverOTSToSEMPoint(a_poi, ref a_SEMpt))
- {
- return false;
- }
- if (!pSEMController.IsConnected())
- {
- if (!pSEMController.Connect())
- {
- log.Error("MoveSEMToPoint: can't connect SEM.");
- return false;
- }
- }
- log.Info("Begin to move SEM stage to " + a_SEMpt.X + "," + a_SEMpt.Y);
-
- // move SEM to the position (rotation 0)
- if (!pSEMController.MoveSEMToPoint(a_SEMpt))
- {
- log.Error("MoveSEMToPoint: failed to call MoveSEMToPoint method.");
- return false;
- }
- CSampleParam pMsrParam = m_Sample.GetMsrParams();
- if (pMsrParam.SlopParam.IsUsingSlopParam)
- {
- double wd = pMsrParam.SlopParam.GetWD(a_SEMpt);
- double originWd = 0;
- pSEMController.GetWorkingDistance(ref originWd);
- if ((wd - originWd) > 2)
- {
- log.Warn("Working Distance is invalid,outof the moving scope(2cm) wd=" + wd.ToString("F2"));
- }
- else
- {
- Thread.Sleep(hardWareDelay);
- pSEMController.SetWorkingDistance(wd);
- }
-
- }
- Thread.Sleep(hardWareDelay);
- return true;
- }
- // Acquire a BSE image
- CBSEImgClr AcquireABSEImage()
- {
- // BSE image
- CBSEImgClr pBSEImage = null;
- // get scan controller
- var pScanController = m_ScanHardwareMgr;
- pBSEImage = pScanController.AcquireBSEImage(0, 0, 2);
-
- return pBSEImage;
- }
- //public virtual bool FieldImageProcess(Point fldCenter, CBSEImgClr imageData)
- //{
- // return true;
- //}
- public virtual void ClassifyFieldParticles()
- {
- return;
- }
- public virtual void ClassifyMergedParticles(List<COTSParticleClr> parts)
- {
- return;
- }
- private class AutoResetSEMControl:IDisposable
- {
- CSmplMeasure sm;
- public AutoResetSEMControl(CSmplMeasure s)
- {
- sm = s;
- }
-
- public void Dispose()
- {
- sm.SetSEMExteralOff();
- }
- }
- public void DoMeasureForOneSample()
- {
- using (AutoResetSEMControl autoReset = new AutoResetSEMControl(this)) //when this method exit ,the SetSEMExternalOff and ResetScan will be called automatically.
- {
- // let the main thread to know that this sample measurement starts
- var pStatus = m_Sample.GetMsrStatus();
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.INPROCESS);
- // set current time to current time
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.START);
- // let main App know that the sample begin to measure
- ST_MSTMsg MsgSmpStart = new ST_MSTMsg();
- MsgSmpStart.iMsgType = ENUM_MSG_TYPE.MSAMPLESTATUS;
- MsgSmpStart.STMSampleStu.iMsrSampleStatu = OTS_MSR_SAMPLE_STATUS.INPROCESS;
- MsgSmpStart.STMSampleStu.cSampleName = m_Sample.GetName();
- m_pMsrThread.SendMessageToMeasureApp(MsgSmpStart);
- log.Info(m_Sample.GetName() + " Measurement started!");
- // get SEM controller to set magnification and working distance
- if (!SetSEMDataMrs())
- {
- log.Error("DoMeasure: fail to set SEM data.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- return;
- }
-
- // set the BSE scan param
- if (!SetBSEParam())
- {
- log.Error("DoMeasure: fail to set BSE param.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- return;
- }
-
-
- var pSEMDataGnr = new CSEMDataGnr();
- log.Info("Get Kv, Brightness and Contrast!");
- m_SemHardwareMgr.GetSEMDataGnrFromHw(ref pSEMDataGnr);
- m_pSampleRstFile.SetSEMGnr(pSEMDataGnr);
- // record SEM data
- COTSMsrPrjResultData pProjMgrFile = m_pMsrThread.GetProjResultData();
- CSEMStageData pSEMStageData = pProjMgrFile.GetSEMStageData();
-
- m_pSampleRstFile.SetSEMStageData(pSEMStageData);
- // record stage
- CStage pStage = pProjMgrFile.GetStage();
-
- m_pSampleRstFile.SetSEMStage(pStage);
-
- // calculate field centers
- List<System.Drawing.Point> umMeasuredlistFieldCenter;
- List<System.Drawing.Point> alllistFieldCenter;
- if (!CalculateUnMeasuredFieldsCenters(out alllistFieldCenter,out umMeasuredlistFieldCenter))
- {// failed to calculate field centers
- log.Error("DoMeasure: failed to calculate field centers.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
- // record end time
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- return;
- }
- //-----save the static measure result file data into xml file and the dynamic data of every field will be saved into sqlite database
- log.Info("Create result file!");
- if (!m_pSampleRstFile.CreateResultFiles())
- {// failed to call measure result file Save method
- log.Error("DoMeasure: failed to call measure result file Save method.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- return;
- }
- //------
- int nNewFieldId = 0;
- int numOfAllFields = pStatus.GetCompletedFields() + umMeasuredlistFieldCenter.Count;//
- int completedFields = pStatus.GetCompletedFields();
- log.Info("Unmeasured fields:" + umMeasuredlistFieldCenter.Count);
- for (int i = 0; i < (int)umMeasuredlistFieldCenter.Count; ++i)
- {// check and break if stop button is clicked
- if (IsAborted())
- {// measure stopped
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.STOPPED);
- // record end time
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- //must wait for the saving data thread finished,or we'll get null pointer exception when we stop the measure process.
- while (fieldQueue.Count() > 0)
- {
- Thread.Sleep(100);
- }
- return;
- }
- // check if sample measurement completes
- COTSImgScanPrm pScanParam = m_Sample.GetMsrParams().GetImageScanParam();
- int nTotalFieldSize = (int)umMeasuredlistFieldCenter.Count;
- if (IsSampleOver(pScanParam, numOfAllFields))
- {
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- break;
- }
- // get a field center
- System.Drawing.Point poiFieldCentre = umMeasuredlistFieldCenter[i];
- // update thread measure status class, let the main thread know that starts a new field
-
- ST_MSTMsg MsgFieldStart = new ST_MSTMsg();
- MsgFieldStart.iMsgType = ENUM_MSG_TYPE.MSAMPLERESULT;
- MsgFieldStart.STMSampleRetData.iRetDataType = MSAMPLE_RET.START_MSR_FIELD;
- MsgFieldStart.STMSampleRetData.SMsrField.FieldPos = poiFieldCentre;
- m_pMsrThread.SendMessageToMeasureApp(MsgFieldStart);
- int fldNo = completedFields + i + 1;
- log.Warn("Current field:" + fldNo.ToString());
-
- // move SEM to the field center
- if (!MoveSEMToPoint(poiFieldCentre))
- {// failed to move SEM to the position
- log.Error("DoMeasure: failed to move SEM to the field centre point.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
- // record end time
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- return;
- }
- log.Info("Begin to Acquire BSE image!");
- // take BSE image for the fields
- CBSEImgClr pBSEImg = AcquireABSEImage();
- // let the main thread to know that image process is completed
-
- if (pBSEImg == null)
- {
- log.Error("ImageProcess: can't get no background image.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
- return;
- }
-
- //BSEData
- ST_MSTMsg MsgFieldBSE = new ST_MSTMsg();
- MsgFieldBSE.iMsgType = ENUM_MSG_TYPE.MSAMPLERESULT;
- MsgFieldBSE.STMSampleRetData.iRetDataType = MSAMPLE_RET.BSE_DATA;
- MsgFieldBSE.STMSampleRetData.BSEData.pos.X = poiFieldCentre.X;
- MsgFieldBSE.STMSampleRetData.BSEData.pos.Y = poiFieldCentre.Y;
- MsgFieldBSE.STMSampleRetData.BSEData.iBSEDataHeight = pBSEImg.GetHeight();
- MsgFieldBSE.STMSampleRetData.BSEData.iBSEDataWidth = pBSEImg.GetWidth();
- byte[] pImgData = pBSEImg.GetImageDataPtr();
- MsgFieldBSE.STMSampleRetData.BSEData.lpBSEData = pImgData;
- m_pMsrThread.SendMessageToMeasureApp(MsgFieldBSE);
- // get a new field id
- log.Info("Acquire BSE image success! Processing image...");
- // image process
- var rst = FieldImageProcess(poiFieldCentre, pBSEImg);
- if (rst == true)
- {
-
- // add the field into the field
- m_pSampleRstFile.AddAField(curFldData);
-
- }
-
- ++nNewFieldId;
- double measuredArea = 0; // this area should be the field area
- var a_pBSEImg = curFldData.GetBSEImage();
-
- double dPixelSize = m_Sample.CalculatePixelSize();
-
- measuredArea = a_pBSEImg.GetHeight() * a_pBSEImg.GetWidth()* dPixelSize * dPixelSize + 0.5; //Get measured area
- if (!CumulateFieldData(curFldData.GetListAnalysisParticles(), measuredArea))
- { // failed to call SaveFieldFile method
- log.Error("ImageProcess: call CumulateFieldData method.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
- return;
- }
- log.Info("Send field data to screen!");
- // completed fields
- pStatus.SetCompletedFields(pStatus.GetCompletedFields() + 1);
- // completed fieldCenter
- List<System.Drawing.Point> listCpltedCenter = pStatus.GetCompletedFieldsCenter();
- listCpltedCenter.Add(poiFieldCentre);
- //Field Data
- // record end time
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- ST_MSTMsg MsgFieldEnd = new ST_MSTMsg();
- MsgFieldEnd.iMsgType = ENUM_MSG_TYPE.MSAMPLERESULT;
- MsgFieldEnd.STMSampleRetData.iRetDataType = MSAMPLE_RET.FIELD_DATA;
- MsgFieldEnd.STMSampleRetData.SFieldData.iCompleteFieldCount = pStatus.GetCompletedFields();
- MsgFieldEnd.STMSampleRetData.SFieldData.iMeasureFieldCount = numOfAllFields;
- MsgFieldEnd.STMSampleRetData.SFieldData.iSParticleCount = (int)curFldData.GetListAnalysisParticles().Count;
- MsgFieldEnd.STMSampleRetData.SFieldData.FieldPos.X = Convert.ToInt32(poiFieldCentre.X);
- MsgFieldEnd.STMSampleRetData.SFieldData.FieldPos.Y = Convert.ToInt32(poiFieldCentre.Y);
- m_pMsrThread.SendMessageToMeasureApp(MsgFieldEnd);
-
- }
- while (bSaveThreadWorking)//wait untill all the field data has been saved.
- {
- Thread.Sleep(1000);
- log.Warn("db saving!");
- }
- //merging particles
- log.Info("Merging big particles which are crossing the field edge!");
- CImageHandler imgpro = new CImageHandler();
- int scanfldsize = m_Sample.GetSEMDataMsr().GetScanFieldSize();
- List<COTSParticleClr> mergedParticles = new List<COTSParticleClr>();
- double pixelSize = m_Sample.CalculatePixelSize();
- imgpro.MergeBigBoundaryParticles(m_pSampleRstFile.GetFieldData(), pixelSize, scanfldsize, m_Sample.GetResolutionSize(), ref mergedParticles);
-
- CalculateMergedPartProperty(mergedParticles,pixelSize);
- ClassifyMergedParticles(mergedParticles);
- log.Info("begin merged particle data db saving...");
-
-
- SaveMergedParticles(mergedParticles);
-
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.COMPLT);
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
- // let main thread to know that this sample measurement completes
- ST_MSTMsg MsgSmplEnd = new ST_MSTMsg();
- MsgSmplEnd.iMsgType = ENUM_MSG_TYPE.MSAMPLESTATUS;
- MsgSmplEnd.STMSampleStu.iMsrSampleStatu = OTS_MSR_SAMPLE_STATUS.SUCCESSED;
- MsgSmplEnd.STMSampleStu.cSampleName = m_Sample.GetName();
- m_pMsrThread.SendMessageToMeasureApp(MsgSmplEnd);
- }
- }
- private void CalculateMergedPartProperty(List<COTSParticleClr> mergedParticles,double pixelSize)
- {
- var m_ImagePro = new CImageHandler();
- foreach (COTSParticleClr part in mergedParticles)
- {
- m_ImagePro.CalParticleImageProp(part, pixelSize);
- }
-
- }
- public bool FieldImageProcess(Point fldCenter, CBSEImgClr a_pBSEImg)
- {
- int nNewFieldId;
- nNewFieldId = m_pSampleRstFile.GetIdForANewField();
- // create a field
- curFldData = new COTSFieldData(a_pBSEImg, m_Sample.CalculatePixelSize());
- curFldData.SetId(nNewFieldId);
- curFldData.SetOTSPosition(fldCenter);
- CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
- Point semPos = new Point();
- a_pCSEMStageData.ConverOTSToSEMPoint(fldCenter, ref semPos);
- curFldData.SemPos = semPos;
- //first step:remove background of the bse image and compound all the finded particles.
- log.Info("Begin to process image and get all particles!");
- GetOriginalParticles();
- // second step :filter the finded particles.
- log.Info("Begin to filter particles!");
- FilterParticles(curFldData);
- CalculateParticleAbsolutPos();
- log.Info("Begin to Calculate the image property of every particle!");
- var analysisparts = curFldData.GetListAnalysisParticles();
- curFldData.CalParticleImageProp(analysisparts);//calculate particle image property such as feret diameter, DMAX etc.
- COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
- if (pXRayParam.GetUsingXray() == true)
- {
- log.Info("Begin to collect particle's xray data!");
- Thread.Sleep(100);
- CollectParticlesXrayData(curFldData);
- Thread.Sleep(100);
- }
- log.Info("Begin to classify particles! particle num:" + curFldData.GetListAnalysisParticles().Count);
- ClassifyFieldParticles();
- // save field files
- m_Sample.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
- StartSaveFileThread(curFldData);
- return true;
- }
- public void GetOriginalParticles()
- {
- // measure status
- CMsrSampleStatus pStatus = m_Sample.GetMsrStatus();
- // get image process parameter
- CSampleParam pMsrParam = m_Sample.GetMsrParams();
- COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
- var specialPartsparam = pMsrParam.GetSpecialGrayRangeParam();
- var pixelsize = m_Sample.CalculatePixelSize();
- if (specialPartsparam.GetIsToRun())
- {
- List<CSpecialGrayRange> ranges = pMsrParam.GetSpecialGrayRangeParam().GetSpecialGreyRanges();
- foreach (var grayRange in ranges)
- {
- CIntRangeClr range = new CIntRangeClr(grayRange.range.GetStart(), grayRange.range.GetEnd());
- CDoubleRangeClr diaRange = new CDoubleRangeClr(grayRange.diameterRange.GetStart(), grayRange.diameterRange.GetEnd());
- curFldData.GetPartsBySpecialGray(range, diaRange, pixelsize, grayRange.ifCollectXray);
- }
- }
- var ifCollectxray = pMsrParam.GetXRayParam().GetUsingXray();
- // remove BES image background
- curFldData.RemoveImgBGAndGetParticles(pImgProcessParam, pixelsize, ifCollectxray);
- // check if this is an empty image
- if (curFldData.NoParticle())
- { // empty fields
- log.Info("ImageProcess: empty field.");
- }
- return;
- }
- public void FilterParticles(COTSFieldData fld)
- {
- if (fld.NoAnalysisParticle())
- {
- log.Warn("There's no analysis particles!");
- return;
- }
- CSampleParam pMsrParam = m_Sample.GetMsrParams();
- COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
- double dPixelSize = m_Sample.CalculatePixelSize();
- curFldData.InitParticles(pImgProcessParam, dPixelSize);
-
-
- var listXray = curFldData.GetAllParticles().OrderByDescending(x => x.GetActualArea()).ToList();
- var listXray1 = new List<COTSParticleClr>();
- var pXRayParam = pMsrParam.GetXRayParam();
- if (listXray.Count > pXRayParam.GetXrayLimit())
- {
- for (var i = 0; i < pXRayParam.GetXrayLimit(); i++)
- {
- listXray1.Add(listXray[i]);
- }
- }
- else
- {
- listXray1 = listXray;
- }
- curFldData.SetListAnalysisParticles(listXray1);
- log.Info("Analysis particles:"+ listXray1.Count);
-
-
- //2) according to the quantify threshold size value saperate the analysis particles into two group :the bigparticles and the smallparticles.
- double quantifyThreshold = m_Sample.GetMsrParams().GetXRayParam().GetFeatureModeMinSize();
- var smallparts = fld.ListSmallParticles;
- var bigparts = fld.ListBigParticles;
- foreach (var part in listXray1)
- {
- double equalCircleDiameter = Math.Sqrt(part.GetActualArea() / 3.14159) * 2f;
- if (equalCircleDiameter < quantifyThreshold)
- {
- smallparts.Add(part);
- }
- else
- {
- bigparts.Add(part);
- }
- }
- fld.ListSmallParticles = smallparts;
- fld.ListBigParticles = bigparts;
- //fld.SmallParticlePercentage=percentage;
- log.Info("SmallQuantifyParts (<" + quantifyThreshold.ToString("f2") + "): " + smallparts.Count);
- log.Info("BigQuantifyParts (>=" + quantifyThreshold.ToString("f2") + "): " + bigparts.Count);
- return;
- }
- public void CollectParticlesXrayData(COTSFieldData fld)
- {
- // get x-ray parameters
- COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
- // calculate search x-ray acquire time
- uint nXRayAQTime;
- List<COTSParticleClr> smallparts = new List<COTSParticleClr>();
- List<COTSParticleClr> bigparts = new List<COTSParticleClr>();
- foreach (var p in fld.ListSmallParticles)
- {
- if (p.IsXrayParticle())
- {
- smallparts.Add(p);
- }
- }
- foreach (var p in fld.ListBigParticles)
- {
- if (p.IsXrayParticle())
- {
- bigparts.Add(p);
- }
- }
-
- var pStatus = m_Sample.GetMsrStatus();
- curFldData.CreateXrayList(bigparts); // big particle using the full xray strategy.
- curFldData.CreateXrayList(smallparts); //small particle using the fast xray strategy
- if (bigparts.Count > 0)
- {
- var workmode = pXRayParam.GetScanMode();
- // get x-ray list (analysis) by particle features
- if (workmode == OTS_X_RAY_SCAN_MODE.FeatureMode)
- {
- nXRayAQTime = (uint)pXRayParam.GetMidAnalyAQTime();
- m_EDSHardwareMgr.GetXRayByFeatures(bigparts, nXRayAQTime, true);
- }
- else
- {
- nXRayAQTime = (uint)pXRayParam.GetMidAnalyAQTime();
- m_EDSHardwareMgr.GetXRayByPoints(bigparts, nXRayAQTime, true);
- }
- }
- if (smallparts.Count > 0)
- {
- nXRayAQTime = (uint)pXRayParam.GetFastXrayTime();
- // get x-ray list (analysis) by points
- m_EDSHardwareMgr.GetXRayByPoints(smallparts, nXRayAQTime, true);
- }
- return;
- }
- public void DoHolePreview(int a_nHoleID)
- {
- using (AutoResetSEMControl autoReset = new AutoResetSEMControl(this))
- {
- // let the main thread to know that this sample measurement starts
- CMsrSampleStatus pStatus = m_Sample.GetMsrStatus();
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.INPROCESS);
- // set current time to current time
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.START);
- // let main App know that the sample begin to measure
- ST_MSTMsg MsgSmpStart=new ST_MSTMsg();
- MsgSmpStart.iMsgType = ENUM_MSG_TYPE.MSAMPLESTATUS;
- MsgSmpStart.STMSampleStu.iMsrSampleStatu = OTS_MSR_SAMPLE_STATUS.INPROCESS;
- MsgSmpStart.STMSampleStu.cSampleName=m_Sample.GetName();
- // get SEM controller to set magnification and working distance
- if (!SetSEMDataMrs())
- {
- log.Error("DoHolePreview: fail to set SEM data.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
- // record end time
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- return;
- }
-
- // set the BSE scan param
- if (!SetHoleBSEParam())
- {
- log.Error("DoMeasure: fail to set BSE param.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
- // record end time
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- return;
- }
-
- // check if measurement is aborted
- if (IsAborted())
- {// measurement aborted
- log.Trace("DoHolePreview: measurement aborted before get SEM condition.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.STOPPED);
- // record end time
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- return;
- }
- // calculate field centers
- List<System.Drawing.Point> listFieldCenter=new List<System.Drawing.Point>();
- List<System.Drawing.Point> alllistFieldCenter = new List<System.Drawing.Point>();
- // listFieldCenter.clear();
- if (!CalculateUnMeasuredFieldsCenters(out alllistFieldCenter,out listFieldCenter))
- {// failed to calculate field centers
- log.Error("DoHolePreview: failed to calculate field centers.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
- // record end time
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- return;
- }
- // go through each field
- int nNewFieldId = 0;
- for ( int i = 0; i < listFieldCenter.Count; ++i)
- {// check and break if stop button is clicked
- if (IsAborted())
- {// measure stopped
- log.Trace("DoHolePreview: measure thread is stopped.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.STOPPED);
- // record end time
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- return;
- }
- // check if sample measurement completes
- COTSImgScanPrm pScanParam = m_Sample.GetMsrParams().GetImageScanParam();
- int nTotalFieldSize = listFieldCenter.Count;
-
-
- if (IsSampleOver(pScanParam, nTotalFieldSize))
- {
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- break;
- }
- // get a field center
- System.Drawing.Point poiFieldCentre = listFieldCenter[i];
-
- // update thread measure status class, let the main thread know that starts a new field
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- ST_MSTMsg MsgFieldStart=new ST_MSTMsg();
- MsgFieldStart.iMsgType = ENUM_MSG_TYPE.MSAMPLERESULT;
- MsgFieldStart.STMSampleRetData.iRetDataType = MSAMPLE_RET.START_MSR_FIELD;
- MsgFieldStart.STMSampleRetData.SMsrField.FieldPos = poiFieldCentre;
- m_pMsrThread.SendMessageToMeasureApp(MsgFieldStart);
- // move SEM to the field center
- if (!MoveSEMToPoint(poiFieldCentre))
- {// failed to move SEM to the position
- log.Error("DoHolePreview: failed to move SEM to the field centre point.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
- // record end time
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- return;
- }
- // take BSE image for the fields
- CBSEImgClr pBSEIamge = AcquireABSEImage();
- if (pBSEIamge==null)
- {
- // failed to acquire a BSE image
- log.Error("DoHolePreview: failed to acquire a BSE image.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
- // record end time
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- return;
- }
- //BSEData
- ST_MSTMsg MsgFieldBSE=new ST_MSTMsg();
- // memset(&MsgFieldBSE, 0, sizeof(ST_MSTMsg));
- MsgFieldBSE.iMsgType = ENUM_MSG_TYPE.MSAMPLERESULT;
- MsgFieldBSE.STMSampleRetData.iRetDataType = MSAMPLE_RET.BSE_DATA;
- MsgFieldBSE.STMSampleRetData.BSEData.pos = poiFieldCentre;
- //MsgFieldBSE.STMSampleRetData.BSEData.pos.y = poiFieldCentre.y;
- MsgFieldBSE.STMSampleRetData.BSEData.iBSEDataHeight = pBSEIamge.GetHeight();
- MsgFieldBSE.STMSampleRetData.BSEData.iBSEDataWidth = pBSEIamge.GetWidth();
- byte[] pImgData = pBSEIamge.GetImageDataPtr();
- MsgFieldBSE.STMSampleRetData.BSEData.lpBSEData = pImgData;
- m_pMsrThread.SendMessageToMeasureApp(MsgFieldBSE);
- if (pStatus.GetStatus() != OTS_MSR_SAMPLE_STATUS.INPROCESS)
- {
- // measurement failed or stopped
- log.Error("DoHolePreview: measurement failed or stopped.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
- // record end time
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- return;
- }
- //save the result to project file
- Rectangle oImageRect = (Rectangle)pBSEIamge.GetImageRect();
- CHoleBSEImg pHoleBSEImg =new CHoleBSEImg(oImageRect,a_nHoleID, poiFieldCentre);
-
- pHoleBSEImg.SetImageData( pBSEIamge.GetImageDataPtr(),oImageRect.Width,oImageRect.Height);
- m_listHoleBSEImg.Add(pHoleBSEImg);
- COTSMsrPrjResultData pProjMgrFile = m_pMsrThread.GetProjResultData();
- pProjMgrFile.SetHoleBESImgList(m_listHoleBSEImg,true);
- // prepare for the next
- ++nNewFieldId;
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- ST_MSTMsg MsgFieldEnd=new ST_MSTMsg();
-
- MsgFieldEnd.iMsgType = ENUM_MSG_TYPE.MSAMPLERESULT;
- MsgFieldEnd.STMSampleRetData.iRetDataType = MSAMPLE_RET.FIELD_DATA;
- MsgFieldEnd.STMSampleRetData.SFieldData.iCompleteFieldCount = (i + 1);
- MsgFieldEnd.STMSampleRetData.SFieldData.iMeasureFieldCount = listFieldCenter.Count;
- MsgFieldEnd.STMSampleRetData.SFieldData.iSParticleCount = 0;
- MsgFieldEnd.STMSampleRetData.SFieldData.FieldPos = poiFieldCentre;
-
- m_pMsrThread.SendMessageToMeasureApp(MsgFieldEnd);
- //break;
- }
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- //calculate measure time
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
- // let main thread to know that this sample measurement completes
- ST_MSTMsg MsgSmplEnd=new ST_MSTMsg();
- MsgSmplEnd.iMsgType = ENUM_MSG_TYPE.MTHREADSTATUS;
- MsgSmplEnd.STMThreadStu.iMsrStatu = OTS_MSR_THREAD_STATUS.COMPLETED;
-
- m_pMsrThread.SendMessageToMeasureApp(MsgSmplEnd);
- }
- }
- // Cumulate field data info
- public virtual bool CumulateFieldData( List<COTSParticleClr> listParticles, double a_nMeasuredArea)
- {
- // get measure result items of the sample
- CMsrDisplayResults pMsrResults = m_Sample.GetMsrResults();
- // cumulate field data info
-
- pMsrResults.CumulateMeasuredArea(a_nMeasuredArea);
- // cumulate ratio
- double dRatio = 10000 * pMsrResults.GetTotalParticleArea();
- dRatio = dRatio / pMsrResults.GetMeasuredArea();
- pMsrResults.SetRatio(dRatio);
-
- // go through the particles list
- foreach (COTSParticleClr pParticle in listParticles)
- {
- // create a measure result item
- pMsrResults.CumulateMeasureResult(pParticle);
- }
- // ok, return TRUE
- return true;
- }
- // hole BSE images list
- void SetHoleBESImgList(CHoleBSEImgsList a_listHoleBSEImg, bool a_bClear/* = TRUE*/)
- {// clear the hole BSE image list if necessary
- if (a_bClear)
- {
- m_listHoleBSEImg.Clear();
- }
- // go through the input list
- foreach (var pHoleBSEImg in a_listHoleBSEImg)
- {// add the new hole BSE image into HoleBSEImage list
- m_listHoleBSEImg.Add(pHoleBSEImg);
- }
- }
- public bool SaveMergedParticles(List<COTSParticleClr> mergedParts)
- {
- CIncAFileMgr pDBFileMgr = m_pSampleRstFile.DBFileMgr;
- var mergedpartdb = pDBFileMgr.GetMergedParticleDB();
-
-
- foreach (COTSParticleClr part in mergedParts)
- {
- mergedpartdb.SaveAParticle(part, part.GetXray(), (Point)part.GetAbsolutPos());
- }
- CPosXrayDBMgr pXrayDBMgr = pDBFileMgr.GetPosXrayDBMgr();
- CElementChemistryDB xraydb = pXrayDBMgr.GetElementChemistryDB();
- List<CPosXrayClr> ches = new List<CPosXrayClr>();
- foreach (COTSParticleClr part in mergedParts)
- {
- ches.Add(part.GetXray());
- }
- xraydb.SaveElementChemistriesList(ches);
- return true;
- }
- public bool SaveFieldData(COTSFieldData fldData, string filedFileFoler)
- {
- //loger.Warn("begin bitmap saving...");
- string strFieldFileFolder = filedFileFoler;
- CBSEImageFileMgr pBSEImgFileMgr = new CBSEImageFileMgr();
- pBSEImgFileMgr.SetBSEImg(fldData.GetBSEImage());
- int nId = fldData.GetId();
- string sFieldId;
- sFieldId = nId.ToString();
- string strBSEFilePathname = strFieldFileFolder + "\\" + m_pSampleRstFile.SMPL_MSR_RESULT_FIELDS_BSE + sFieldId + pBSEImgFileMgr.BMP_IMG_FILE_EXT;
- if (!pBSEImgFileMgr.SaveIntoBitmap(strBSEFilePathname))
- {
- log.Error("SaveFieldFiles: save BSE file failed.");
- return false;
- }
- // IncA Data list
- CIncAFileMgr pDBFileMgr = m_pSampleRstFile.DBFileMgr;
- pDBFileMgr.SaveStatusDataToDB();
- var fldDB = pDBFileMgr.GetFieldDB();
- log.Warn("Start saving particle data.");
- var fldcmd = fldDB.GetSavingAFieldcmdObj(fldData.GetId(), fldData.GetOTSPosition(), fldData.SemPos);
- List<KeyValuePair<string, System.Data.SQLite.SQLiteParameter[]>> fldcmds = new List<KeyValuePair<string, System.Data.SQLite.SQLiteParameter[]>>();
- fldcmds.Add(fldcmd);
- pDBFileMgr.ExecuteNonQueryBatch(ref fldcmds);
- //remomove the invalid particles
- var cmds = pDBFileMgr.GetSavingIncADataToDBCmds(curFldData.GetListAnalysisParticles(), fldData.GetOTSPosition());
- pDBFileMgr.ExecuteNonQueryBatch(ref cmds);
- CPosXrayDBMgr PosXrayDBMgr = pDBFileMgr.GetPosXrayDBMgr();
- var listAnalysisPosXray = new List<CPosXrayClr>();
- foreach (var p in curFldData.GetListXrayParticles())
- {
- listAnalysisPosXray.Add(p.GetXray());
- }
- var cmds1 = PosXrayDBMgr.GetSavingXrayCmds(listAnalysisPosXray, true);
- pDBFileMgr.ExecuteNonQueryBatch(ref cmds1);
- return true;
- }
- protected void SaveFieldMgrData()
- {
- while (bSaveThreadWorking)
- {
- while (fieldQueue.Count() > 0)
- {
- COTSFieldData f = fieldQueue.Dequeue();
- //save to disk first ,then pop . if the size is 0,then we know all the saving work is done.
- SaveFieldData(f, m_pSampleRstFile.GetFieldFileSubFolderStr());
- }
- if (fieldQueue.Count() == 0)
- {
- bSaveThreadWorking = false; //must set this flag,so the main thread can know this thread has exited.
- log.Warn("finished batch saving");
- return;
- }
- }
- return;
- }
- protected void StartSaveFileThread(COTSFieldData a_pFieldMgr)
- {
- fieldQueue.Enqueue(a_pFieldMgr);
- if (fieldQueue.Count() > 0) //if there's data in the queue and the previous thread has finished then start a new thread.
- {
- if (bSaveThreadWorking == false)
- {
- bSaveThreadWorking = true;
- m_thread_ptr = new System.Threading.Thread(this.SaveFieldMgrData);//m_thread_ptr = shared_ptr<thread>(new thread(&CSmplMeasureInc::SaveFieldMgrData, this));
- m_thread_ptr.IsBackground = true;
- m_thread_ptr.Start();
- }
- }
- }
- public void ParticleSpecialTreatment(COTSFieldData fld)
- {
- //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.
- Dictionary<COTSParticleClr, int> mapPartXray = new Dictionary<COTSParticleClr, int>(); //std.map<COTSParticlePtr, int> mapPartXray = new std.map<COTSParticlePtr, int>();
- double edsTime = 0; //to store the EDSTime returned from the engine.
- var bigparts = fld.GetListXrayParticles();
- var m_ClassifyEngine = new CClassifyEngine();
- for (int i = 0; i < bigparts.Count(); i++)
- {
- var engine = m_ClassifyEngine.GetParticleEngine(m_Sample.GetMsrParams().GetSTDName());
- var p = bigparts[i];
- // 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.
- //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.
- edsTime = engine.IfNeedMaxEDS(p);
- if (edsTime > 0)
- {
- mapPartXray[p] = i;
- }
- }
- List<COTSParticleClr> partsMax = new List<COTSParticleClr>();
- if (mapPartXray.Count() > 0)
- {
- foreach (var p in mapPartXray)
- {
- partsMax.Add(p.Key);
- }
- List<CPosXrayClr> maxEDSXrays = new List<CPosXrayClr>();
- m_EDSHardwareMgr.GetXRayByFeatures(partsMax, edsTime, true);
- }
- }
- public void CalculateParticleAbsolutPos()
- {
- double dPixelSize = m_Sample.CalculatePixelSize();
- CSEMStageData pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
- foreach (var p in curFldData.GetListAnalysisParticles())
- {
- Point fldOtsPos = new Point(curFldData.OTSPos.X, curFldData.OTSPos.Y);
- Point semPos = new Point();
- pCSEMStageData.ConverOTSToSEMPoint(fldOtsPos, ref semPos);
- p.SetAbsolutPos(semPos);
- }
- }
- }
- }
|