123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using OTSModelSharp.ServiceCenter;
- using static OTSDataType.otsdataconst;
- using OTSDataType;
- using System.Diagnostics;
- using System.Drawing;
- using System.Threading;
- using OTSModelSharp.DTLBase;
- using OTSCLRINTERFACE;
- using OTSMeasureApp._0_OTSModel.Measure.ParamData;
- using System.Windows.Forms;
- using System.Data;
- namespace OTSModelSharp
- {
- using CHoleBSEImgsList = List<CHoleBSEImg>;
- public class CSmplMeasure
- {
- protected static NLog.Logger log ;
- protected bool bSaveThreadWorking;
- protected System.Threading.Thread m_thread_ptr;
-
- protected COTSSample m_Sample;
- protected COTSSample m_HolePreviewSample;
- protected CMeasure m_pMsrThread;
- string m_strWorkingFolder;
- protected CSmplMsrResult m_pSampleRstFile;
- CHoleBSEImgsList m_listHoleBSEImg;
-
- protected ISemController m_SemHardwareMgr;
- protected IScanController m_ScanHardwareMgr;
- protected IEDSController m_EDSHardwareMgr;
-
- protected Queue<COTSFieldData> fieldQueue=new Queue<COTSFieldData>();
-
- protected IClassifyEngine m_classifyEngine;
-
- public CSmplMeasure( string a_strWorkingFolder, COTSSample a_pSample)
- {
- m_Sample = a_pSample;
- log = NLog.LogManager.GetCurrentClassLogger();
- var expC = m_Sample.GetMsrParams().GetXRayParam().GetAnalyExpCount();
- var imgwidth = m_Sample.GetMsrParams().GetImageScanParam().GetImageResolutionSize().cx;
- var imgheight = m_Sample.GetMsrParams().GetImageScanParam().GetImageResolutionSize().cy;
- m_strWorkingFolder = a_strWorkingFolder;
- m_pSampleRstFile = new CSmplMsrResult( a_strWorkingFolder, a_pSample);
- m_SemHardwareMgr = SemController.GetSEMController();
- m_ScanHardwareMgr = ScanController.GetScanController();
- m_EDSHardwareMgr = EDSController.GetEDSController(imgwidth,imgheight,expC);
- m_listHoleBSEImg = new CHoleBSEImgsList();
- m_Sample = a_pSample;
-
- }
- public void SetSample(COTSSample a_pSample)
- {
-
- m_Sample = a_pSample;
- m_pSampleRstFile.SetSample(a_pSample);
- }
- public COTSSample GetSample() { return m_Sample; }
- public void SetHolePreviewSample(COTSSample a_pSample)
- {
- m_HolePreviewSample = a_pSample;
-
- }
- public COTSSample GetHolePreviewSample() { return m_HolePreviewSample; }
- public void SetMsrThread(CMeasure mt)
- {
- m_pMsrThread = mt;
-
-
- }
- bool SetSEMDataMrs(COTSSample sample)
- {
- var pSEMDataMsr = sample.GetSEMDataMsr();
-
- double dMag = pSEMDataMsr.GetMagnification();
- double dWorkDis = pSEMDataMsr.GetWorkingDistance();
-
- var pSEMCtrl = m_pMsrThread.GetSEMController();
-
-
- pSEMCtrl.SetMagnification(dMag);
- pSEMCtrl.SetWorkingDistance(dWorkDis);
- return true;
- }
- bool SetSEMExteralOn()
- {
- var pSEMCtrl = m_SemHardwareMgr;
- log.Warn("Set Scan Exteral on!");
- pSEMCtrl.SetScanExternal(true);
- return true;
- }
- // set SEM external off
- bool SetSEMExteralOff()
- {
- var pSEMCtrlPtr = m_SemHardwareMgr;
-
- log.Warn("Set SEM Exteral Off!");
- pSEMCtrlPtr.SetScanExternal(false);
- return true;
- }
- bool SetBSEParam()
- {
-
- // 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 dwell time
- OTS_IMAGE_SCANSPEED_OPTIONS nDwellTime = pImgScanParam.GetScanImageSpeed();
- // convert dwell time to bruker dwell time (8, 16, 32)
- int nBrukerDwellTimeId;
- switch (nDwellTime)
- {
- case OTS_IMAGE_SCANSPEED_OPTIONS.low:
- nBrukerDwellTimeId = 1;
- break;
- case OTS_IMAGE_SCANSPEED_OPTIONS.meddium:
- nBrukerDwellTimeId = 2;
- break;
- case OTS_IMAGE_SCANSPEED_OPTIONS.high:
- nBrukerDwellTimeId = 3;
- break;
- default:
- nBrukerDwellTimeId = 1;
- 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(COTSSample sample)
- {
- // get SEM controller
- //var pSEMController = m_SemHardwareMgr;
- // get scan controller
- var pScanController = m_ScanHardwareMgr;
- // scan parameters
- var pMsrParam = 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 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 ImageSize");
- 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(COTSSample sample, out List<System.Drawing.Point> a_allpieldcenter, out List<System.Drawing.Point> a_listUnMsrFieldCenter)
- {
- // sample measure parameters
- CMeasureParam pMsrParam = sample.GetMsrParams();
- COTSImgScanPrm poImageScanParam = pMsrParam.GetImageScanParam();
- COTSImageProcParam pImgProcParam = pMsrParam.GetImageProcessParam();
- CSEMDataMsr poSEMDataMsr = m_Sample.GetSEMDataMsr();
- CMsrSampleStatus pStatus = m_Sample.GetMsrStatus();
- //CSEMDataMsr poSEMDataMsr = sample.GetSEMDataMsr();
- //CMsrSampleStatus pStatus = sample.GetMsrStatus();
- // measured field centers list
- List<System.Drawing.PointF> listCompletedCenter = pStatus.GetCompletedFieldsCenter();
- // field centers list manager
- CFieldPositionMgr pFieldMgr = new CFieldPositionMgr();
- // init field centers list manager
- if (!pFieldMgr.Init(sample.GetMsrDomain(), poImageScanParam, pImgProcParam, poSEMDataMsr, listCompletedCenter))
- {
- log.Error("CalculateFieldsCenters: failed to init field centres list manager.");
- a_listUnMsrFieldCenter = new List<System.Drawing.Point>();
- a_allpieldcenter = new List<Point>();
- return false;
- }
- // get field centers list
- a_listUnMsrFieldCenter = pFieldMgr.GetUnmeasuredFieldCentrePoints();// GetFieldCentrePoints();
- a_allpieldcenter = pFieldMgr.GetFieldCentrePoints();
- // ok, return TRUE
- return true;
- }
- protected bool IsAborted()
- {
-
- return m_pMsrThread.IsMeasureStopped();
- }
- protected bool IsPaused()
- {
- //Debug.Assert(m_pMsrThread == null);
- var statu = m_pMsrThread.GetMsrThreadStatus();
- if (statu.GetStatus() == OTS_MSR_THREAD_STATUS.PAUSED)
- {
- return true;
- }
- else
- {
- return false;
- }
-
- }
- bool IsSampleOver(COTSImgScanPrm a_pScanParam)
- {
-
- string sStopMode = a_pScanParam.GetStopMode();
- int nStopField = a_pScanParam.GetStopParamFields();
- // completed fields number
- CMsrSampleStatus pMsrSampleStatus = m_Sample.GetMsrStatus();
- int nCompeltedField = pMsrSampleStatus.GetCompletedFields();
- CMsrResultItems 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 == m_Sample.GetFieldsData().Count)
- {
- 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.PointF a_poi)
- {
- // get SEM controller
- var pSEMController = m_SemHardwareMgr;
-
- PointF a_SEMpt = new Point();
-
- CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
- int hardWareDelay = a_pCSEMStageData.GetHardWareDelay();
- if (!a_pCSEMStageData.ConvertOTSToSEMCoord(a_poi, ref a_SEMpt))
- {
- return false;
- }
- log.Info("Begin to move SEM stage to OTScoord:" + a_poi.X + "," + a_poi.Y);
- 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.X, a_SEMpt.Y))
- {
- log.Error("MoveSEMToPoint: failed to call MoveSEMToPoint method.");
- return false;
- }
- CMeasureParam 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();
-
- return pBSEImage;
- }
-
- public virtual void ClassifyFieldParticles(COTSFieldData curFldData)
- {
- return;
- }
- public virtual void ClassifyMergedParticles(List<COTSParticleClr> parts)
- {
- return;
- }
- private class SEMStateObject
- {
- private PointF pos;
- private double workingDistance;
- private CSEMDataGnr semdata;
- private COTSSample originalSample;
- private double magnification;
- public PointF Pos { get => pos; set => pos = value; }
- public double WorkingDistance { get => workingDistance; set => workingDistance = value; }
- public CSEMDataGnr Semdata { get => semdata; set => semdata = value; }
- public double Magnification { get => magnification; set => magnification = value; }
- public COTSSample OriginalSample { get => originalSample; set => originalSample = value; }
- }
- private class AutoResetSEMControl:IDisposable
- {
- CSmplMeasure sm;
- private SEMStateObject semState=null;
- public AutoResetSEMControl(CSmplMeasure s)
- {
- sm = s;
- }
- public SEMStateObject SemState
- {
- get => semState;
- set => semState = value;
- }
- public void Dispose()
- {
- if (semState != null)
- {
- sm.SetBSEParam();
-
- sm.m_SemHardwareMgr.SetMagnification(semState.Magnification);
- sm.MoveSEMToPoint(semState.Pos);
- sm.m_SemHardwareMgr.SetWorkingDistance(semState.WorkingDistance);
-
- }
- sm.SetSEMExteralOff();
- }
- }
- private bool GetSEMDataGnrFromHw(ref CSEMDataGnr SemDataGnr)
- {
- double kv = 0, brightness = 0, contrast = 0;
-
- var hw = SemController.GetSEMController();
- hw.GetSemHighTension(ref kv);
- hw.GetSemBrightness(ref brightness);
- hw.GetSemContrast(ref contrast);
-
- SemDataGnr.SetValue(kv, brightness, contrast);
- return true;
- }
- 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(m_Sample))
- {
- 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!");
- 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);
-
- //-----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;
- }
- //------
- var FldDatas = m_Sample.GetFieldsData();
-
- if (m_EDSHardwareMgr.GetEDSType()==EDSTYPE.BRUKER && m_Sample.GetMsrParams().GetXRayParam().GetUseFilter())
- {
- List<string> KeyNameList = new List<string>();
- string DBAddress = Application.StartupPath + "\\Config\\SysData\\" + m_Sample.GetMsrParams().GetSTDName() + ".db";
- SQLiteHelper sQLiteHelper = new SQLiteHelper(DBAddress);//
- KeyNameList = sQLiteHelper.GetDBKeyElementList("ClassifySTD", "KeyElementList");
- m_EDSHardwareMgr.SetFilterKeyEleNames( KeyNameList);//will decide if do the quantification according to this keyelelist.
- }
-
- for (int i = 0; i < FldDatas.Count; ++i)
- {// check and break if stop button is clicked
-
- var curFld = FldDatas[i];
- if (curFld.GetIsMeasureComplete())
- {
- continue;
- }
- if (IsPaused())
- {// measure stopped
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.PAUSED);
- // 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);
- }
- SetSEMExteralOff();
- // update thread measure status class, let the main thread know that this sample measurement stopped
- ST_MSTMsg MsgSmpStop = new ST_MSTMsg();
- MsgSmpStop.iMsgType = ENUM_MSG_TYPE.MSAMPLESTATUS;
- MsgSmpStop.STMThreadStu.iMsrStatu = OTS_MSR_THREAD_STATUS.PAUSED;
- MsgSmpStop.STMSampleStu.iMsrSampleStatu = OTS_MSR_SAMPLE_STATUS.PAUSED;
- MsgSmpStop.STMThreadStu.csMsrEndTime = DateTime.Now.ToShortDateString();
- MsgSmpStop.STMThreadStu.iMsrStatu = OTS_MSR_THREAD_STATUS.PAUSED;
- m_pMsrThread.SendMessageToMeasureApp(MsgSmpStop);
- while (IsPaused())
- {
- Thread.Sleep(300);
-
- }
-
- }
- 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);
- }
- break;
- }
-
- // check if sample measurement completes
- COTSImgScanPrm pScanParam = m_Sample.GetMsrParams().GetImageScanParam();
-
- if (IsSampleOver(pScanParam))
- {
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.COMPLT);
- break;
- }
- // get a field center
- System.Drawing.PointF poiFieldCentre = curFld.GetOTSPosition();
- // 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 = new Point((int)poiFieldCentre.X,(int)poiFieldCentre.Y);
- m_pMsrThread.SendMessageToMeasureApp(MsgFieldStart);
- int fldNo = curFld.GetId();
- 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 = (int)poiFieldCentre.X;
- MsgFieldBSE.STMSampleRetData.BSEData.pos.Y = (int)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);
-
- log.Info("Acquire BSE image success! Processing image...");
- // image process
- var rst = FieldImageProcess(curFld, pBSEImg);
- if (rst == true)
- {
- curFld.SetIsMeasureComplete(true);
- }
- else
- {
- return;
- }
- //start db save
- StartSaveFileThread(ref curFld);
- double measuredArea = 0; // this area should be the field area
- var a_pBSEImg = curFld.GetBSEImage();
- double dPixelSize = curFld.GetPixelSize();
- measuredArea = a_pBSEImg.GetHeight() * a_pBSEImg.GetWidth()* dPixelSize * dPixelSize + 0.5; //Get measured area
- CumulateFieldData(curFld.GetListAnalysisParticles(), measuredArea);
- log.Info("Send field data to screen!");
-
- pStatus.AddCompletedFieldCenter(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 = m_Sample.GetFieldsData().Count;
- MsgFieldEnd.STMSampleRetData.SFieldData.iSParticleCount = (int)curFld.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!");
- }
- TheLastWorkOfSampleMeasure();
- }
- }
- public void TheLastWorkOfSampleMeasure()
- {
- COTSSample theSample = m_Sample;
- var pStatus = theSample.GetMsrStatus();
- //merging particles
- log.Info("Merging big particles which are crossing the field edge!");
- CImageHandler imgpro = new CImageHandler();
- int scanfldsize = theSample.GetSEMDataMsr().GetScanFieldSize();
- List<COTSParticleClr> mergedParticles = new List<COTSParticleClr>();
- double pixelSize = theSample.CalculatePixelSize();
- imgpro.MergeBigBoundaryParticles(theSample.GetFieldsData(), pixelSize, scanfldsize, theSample.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 = theSample.GetName();
- m_pMsrThread.SendMessageToMeasureApp(MsgSmplEnd);
- }
- public bool DoMEasureForReMeasure()
- {
- return true;
- }
- private void CalculateMergedPartProperty(List<COTSParticleClr> mergedParticles,double pixelSize)
- {
- var m_ImagePro = new CImageHandler();
- foreach (COTSParticleClr part in mergedParticles)
- {
- m_ImagePro.CalParticleImageProp(part, pixelSize);
- }
-
- }
- public virtual bool FieldImageProcess(COTSFieldData curFldData, CBSEImgClr a_pBSEImg)
- {
- PointF fldCenter = curFldData.OTSPos;
-
- curFldData.SetBSEImage(a_pBSEImg);
- CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
- PointF semPos = new Point();
- a_pCSEMStageData.ConvertOTSToSEMCoord(fldCenter, ref semPos);
- curFldData.SetSemPos(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(ref curFldData);
- // second step :filter the finded particles.
- log.Info("Begin to filter particles!");
- FilterParticles(ref curFldData);
- CalculateParticleAbsolutPos(ref curFldData);
- 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(curFldData);
-
- m_Sample.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
-
- return true;
- }
- public void GetOriginalParticles(ref COTSFieldData curFldData)
- {
- // measure status
- //CMsrSampleStatus pStatus = m_Sample.GetMsrStatus();
- // get image process parameter
- CMeasureParam pMsrParam = m_Sample.GetMsrParams();
- COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
- var specialPartsparam = pMsrParam.GetSpecialGrayRangeParam();
- var pixelsize = m_Sample.CalculatePixelSize();
- if (specialPartsparam != null && 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(ref COTSFieldData curFldData)
- {
- if (curFldData.NoAnalysisParticle())
- {
- log.Warn("There's no analysis particles!");
- return;
- }
- CMeasureParam 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 separate the analysis particles into two group :the bigparticles and the smallparticles.
- double quantifyThreshold = m_Sample.GetMsrParams().GetXRayParam().GetFeatureModeMinSize();
- var smallparts = curFldData.ListSmallParticles;
- var bigparts = curFldData.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);
- }
- }
- curFldData.ListSmallParticles = smallparts;
- curFldData.ListBigParticles = bigparts;
- //fld.SmallParticlePercentage=percentage;
- log.Info("SmallQuantifyParts (<" + quantifyThreshold.ToString("f2") + "): " + smallparts.Count);
- log.Info("BigQuantifyParts (>=" + quantifyThreshold.ToString("f2") + "): " + bigparts.Count);
- return;
- }
- public virtual void CollectParticlesXrayData(COTSFieldData curFldData)
- {
- // 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 curFldData.ListSmallParticles)
- {
- if (p.IsXrayParticle())
- {
- smallparts.Add(p);
- }
- }
- foreach (var p in curFldData.ListBigParticles)
- {
- if (p.IsXrayParticle())
- {
- bigparts.Add(p);
- }
- }
-
-
- 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 if(workmode==OTS_X_RAY_SCAN_MODE.PointMode)
- {
- nXRayAQTime = (uint)pXRayParam.GetMidAnalyAQTime();
- m_EDSHardwareMgr.GetXRayByParts(bigparts, nXRayAQTime, true);
- }
-
- }
- if (smallparts.Count > 0)
- {
- nXRayAQTime = (uint)pXRayParam.GetFastXrayTime();
- // get x-ray list (analysis) by points
- m_EDSHardwareMgr.GetXRayByParts(smallparts, nXRayAQTime, true);
- }
- return;
- }
- public void DoHolePreview()
- {
- using (AutoResetSEMControl autoReset = new AutoResetSEMControl(this))
- {
- //----------memorize the state of sem
- var semstate = new SEMStateObject();
-
- double dMagnification = m_Sample.GetSEMDataMsr().GetMagnification();
- double wd = m_Sample.GetSEMDataMsr().GetWorkingDistance();
- ISemController sem = m_SemHardwareMgr;
- double posX=0, posY=0,posR=0;
- sem.GetSemPositionXY(ref posX, ref posY, ref posR);
- CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
- Point pos = new Point((int)posX, (int)posY);
- PointF otsPos = new Point(0, 0);
- if (!a_pCSEMStageData.ConvertSEMToOTSCoord(pos, ref otsPos))
- {
- return;
- }
- semstate.Pos = otsPos;
- semstate.Magnification = dMagnification;
- semstate.WorkingDistance = wd;
- autoReset.SemState = semstate;
- //-------------------------------------
- // let the main thread to know that this sample measurement starts
- CMsrSampleStatus pStatus = m_HolePreviewSample.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(m_HolePreviewSample))
- {
- 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(m_HolePreviewSample))
- {
- log.Error("DoHolePreview: fail to set BSE param.");
- pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
- // record end time
- pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
- return;
- }
-
- // calculate field centers
- List<System.Drawing.Point> listFieldCenter;
- List<System.Drawing.Point> alllistFieldCenter ;
-
- if (!CalculateUnMeasuredFieldsCenters(m_HolePreviewSample, 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;
-
-
- // 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();
-
- MsgFieldBSE.iMsgType = ENUM_MSG_TYPE.MSAMPLERESULT;
- MsgFieldBSE.STMSampleRetData.iRetDataType = MSAMPLE_RET.BSE_DATA;
- MsgFieldBSE.STMSampleRetData.BSEData.pos = poiFieldCentre;
-
- 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,poiFieldCentre);
-
- pHoleBSEImg.SetImageData( pBSEIamge.GetImageDataPtr(),oImageRect.Width,oImageRect.Height);
- m_listHoleBSEImg.Add(pHoleBSEImg);
-
- // 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);
- }
- 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
- CMsrResultItems 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;
- }
-
- 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)
- {
-
- 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.GetSemPos());
- 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.GetSavingParticleDataToDBCmds(fldData.GetListAnalysisParticles(), fldData.GetOTSPosition());
- pDBFileMgr.ExecuteNonQueryBatch(ref cmds);
- CPosXrayDBMgr PosXrayDBMgr = pDBFileMgr.GetPosXrayDBMgr();
- var listAnalysisPosXray = new List<CPosXrayClr>();
- foreach (var p in fldData.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(ref 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(ref 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>();
- 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(ref COTSFieldData curFldData)
- {
- 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);
- PointF semP = new PointF(); ;
- Point semPos = new Point();
- pCSEMStageData.ConvertOTSToSEMCoord(curFldData.OTSPos, ref semP);
- semPos.X = (int)semP.X;
- semPos.Y = (int)semP.Y;
- p.SetAbsolutPos(semPos);
- }
- }
- }
- }
|