| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883 |
- using OTSDataType;
- using OTSIncAMeasureApp.OTSMeasureControl;
- using OTSModelSharp.DTL;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Forms;
- using System.Xml;
- using static OTSDataType.otsdataconst;
- namespace OTSModelSharp
- {
- public class COTSProjMgrFile
- {
- // SEM stage data
- CSEMStageData m_pSEMStageData;
- // stage
- CStage m_pStage;
- COTSGeneralParameters m_DefaultParameters;
- // sample list
- List<COTSSample> m_listSamples = new List<COTSSample>();
- List<CHoleBSEImg> m_listHoleBSEImg = new List<CHoleBSEImg>();
- bool m_bModify;
- // path name
- String m_strPathName;
- // working sample index
- int m_nWorkingSampeIndex;
- const String UNTITLED_FILE_NAME = "Untitled";
- //以下这两个原来在SmplMsrResultFile中
- // fields file sub-directory string
- const String SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER = "FIELD_FILES";
- // Inclusion file name
- const String SMPL_MSR_RESULT_INCLUSION_FILE = "Inclusion.db";//put all the table in one db file so that report can make join query.
- // CDBStoreBase m_datastorePtr;
- CSQLiteDBFile m_datastore;
- IMeasureHardware m_HardwareMgr;
- public OTS_MSR_SAMPLE_STATUS m_nStatus;
- CIncAFileMgr m_IncAFileMgr = new CIncAFileMgr("");
-
- CIncADataDB m_IncADataDB ;
- CSegmentDB m_Segment ;
- CSQLiteDB m_generalInfoTable;
- // OTSControl.OTSController control = new OTSControl.OTSController();
- // project file mark
- public const int PROJ_MGR_FILE_MARK = 'P' + 'R' + 'O' + 'J' + 'E' + 'T' + 'M' + 'A' + 'N' + 'A' + 'G' + 'E' + 'R';
- // project file version string
- public const String PROJ_MGR_FILE_VERSION = "1.1.1";
- public COTSProjMgrFile()
- {
- Init();
- // m_HardwareMgr = new MeasureHardware();
- }
- // initialization
- public void Init()
- {
- m_pSEMStageData = new CSEMStageData();
- m_pStage = new CStage();
-
- m_DefaultParameters = new COTSGeneralParameters();
- m_listSamples.Clear();
- m_listHoleBSEImg.Clear();
- //m_listSysSTDItem.clear();
- m_bModify = false;
- m_strPathName = "";
- m_nWorkingSampeIndex = -1;
- }
- public void OTSProjMgrFile(COTSProjMgrFile a_oSource)
- {
- // can't copy itself
- if (a_oSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(a_oSource);
- }
- // duplication
- public void Duplicate( COTSProjMgrFile a_oSource)
- {
- // initialization
- Init();
- // copy data over
- m_pSEMStageData = new CSEMStageData(a_oSource.m_pSEMStageData);
- m_pStage = new CStage(a_oSource.m_pStage);
- m_DefaultParameters = new COTSGeneralParameters(a_oSource.m_DefaultParameters);
-
- foreach (var pHoleBSEImg in a_oSource.m_listHoleBSEImg)
- {
- CHoleBSEImg pHoleBSEImgNew =(new CHoleBSEImg(pHoleBSEImg));
- m_listHoleBSEImg.Add(pHoleBSEImgNew);
- }
- foreach (var pSample in a_oSource.m_listSamples)
- {
- COTSSample pSampleNew =new COTSSample();
- m_listSamples.Add(pSampleNew);
- }
- m_bModify = a_oSource.m_bModify;
- m_strPathName = a_oSource.m_strPathName;
- m_nWorkingSampeIndex = a_oSource.m_nWorkingSampeIndex;
- }
- // file
- public bool NewFile()
- {
- // file invalidation
- if (!IsValid())
- {
- // shouldn't happen, file is invalid
- return false;
- }
- // set file name
- SetPathName(UNTITLED_FILE_NAME);
- // Ok, return TRUE
- return true;
- }
- public bool IsValid()
- {
- if (m_pSEMStageData!=null || m_pSEMStageData == null)
- {
- return false;
- }
- else if (m_pStage!=null || m_pStage == null)
- {
- return false;
- }
- else if (m_DefaultParameters!=null)
- {
- return false;
- }
- // Ok, return TRUE
- return true;
- }
- public void SetPathName(String a_strPathName) { m_strPathName = a_strPathName; }
- public bool GetNewProjMgrClr() { return false; }
- public bool Load()
- {
- // use dll resource
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // get file name
- String strPathName = "";
- // check file pathname
- strPathName.Trim();
- if (strPathName == "")
- {
- // file open dialog
- OpenFileDialog openFileDialog = new OpenFileDialog();
- if (openFileDialog.ShowDialog() != DialogResult.OK)
- {
- return false;
- }
- // get file pathname
- strPathName = openFileDialog.FileName;
- }
- //Init data
- Cleanup();
- // check if the file exist
- if (!Exists(strPathName))
- {
- // shouldn't happen, file does not exist
- return false;
- }
-
- //-------------
- foreach (var smpl in m_listSamples)
- {
- // get path of the pathname
- String strFilePath = GetFolderName(strPathName);
- if (strFilePath=="")
- {
- // file path string is an empty string
- return false;
- }
- // field file sub folder string
- String strFieldFileSubFolder = strFilePath + "\\" + smpl.GetName() + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
- // check if the field file sub folder exists
- if (!Exists(strFieldFileSubFolder))
- {// field files folder doesn't exist
- return false;
- }
- String strIncAFilename = strFieldFileSubFolder + "\\" + SMPL_MSR_RESULT_INCLUSION_FILE;
- CIncAFileMgr pIncAFileMgr = new CIncAFileMgr(strIncAFilename);
- List<COTSFieldData> allFlds = new List<COTSFieldData>();
- CMsrSampleStatus poMsrStatus = new CMsrSampleStatus();
- poMsrStatus.GetStatus();
- CMsrResults poMsrResults = smpl.GetMsrResults();
- double aFldArea = smpl.CalculateAFieldArea();
- if (GetAllFieldsFromDB(ref allFlds, poMsrStatus, poMsrResults, aFldArea))
- {
- smpl.SetFieldsData(allFlds);
- // file validation
- if (m_pSEMStageData!= new CSEMStageData() || (m_pSEMStageData) == new CSEMStageData())
- {
- // invalid SME stage data
- return false;
- }
- if (m_pStage!= new CStage() || (m_pStage) == new CStage())
- {
- // invalid stage
- return false;
- }
- // set modify flag
- SetModify(false);
- // set pathname
- SetPathName(strPathName);
- // set working sample
- if (m_listSamples.Count > 0)
- {
- m_nWorkingSampeIndex = 0;
- }
- else
- {
- m_nWorkingSampeIndex = -1;
- }
- }
- else
- {
- return false;
- }
- }
- //-----------------------------------------
- return true;
- }
- // gets the name of the folder
- public String GetFolderName(String a_strPathName)
- {
- string str = "";
- char[] sPath=new char[otsdataconst.MAX_PATH];
- str.CopyTo(0,sPath, 0, Convert.ToInt32(a_strPathName));
-
- return sPath.ToString();
- }
- // check if the file exists or not
- public bool Exists(string a_sPath)
- {
- return true;
- }
- // cleanup
- public void Cleanup()
- {
- m_listHoleBSEImg.Clear();
- m_listSamples.Clear();
-
- m_bModify = false;
- m_strPathName = "";
- m_nWorkingSampeIndex = -1;
- }
- // set modify flag
- public void SetModify(bool a_bModify = true) { m_bModify = a_bModify; }
- // file pathname
- public String GetPathName() { return m_strPathName; }
- public bool GetAllFieldsFromDB(ref List<COTSFieldData > allFlds, CMsrSampleStatus status, CMsrResults rst, double aFieldArea)
- {
- String sDatabaseName = GetPathName();
- if (Exists(sDatabaseName))
- {
- if (!Open(m_strPathName, false))
- {
-
- return false;
- }
- }
- List<System.Drawing.Point> completedflds = new List<System.Drawing.Point>();
- CIncAFileMgr IncADataDBs = m_IncAFileMgr.GetIncADB();
- m_IncADataDB.GetAllFieldsRecord(ref allFlds);
- CSegmentDB SegmentDB = m_IncAFileMgr.GetSegmentDB();
- double msrFldsArea = 0;
- List<COTSParticle> mapTypeParticles=new List<COTSParticle>();//record typeId relevants particlelist;
- // std::map<std::vector<int>, COTSSegmentsList> AllSegments;
- List<COTSSegment> AllSegments = new List<COTSSegment>();
- Dictionary<List<int>, List<COTSSegment>> mapSegments = new Dictionary<List<int>, List<COTSSegment>>();
- if (SegmentDB.GetAllSegmentsRecord(mapSegments))
- {
- int nCol;
- foreach(var fld in allFlds)
-
- {
- int fldId = fld.GetId();
- List<COTSParticle> parts = fld.GetParticleList();
- foreach(var part in parts)
-
- {
- List<int> fldvec = new List<int>();
- fldvec.Add(fldId);
- fldvec.Add(part.GetTagId());
- var itr = AllSegments.Find(
- delegate(COTSSegment segment)
- {
- return segment.Equals(sDatabaseName);
- });
- if (itr != AllSegments.Last())
- {
- COTSFeature f = new COTSFeature();
- f.SetSegmentsList(AllSegments, true);
- part.SetFeature(f);
- }
- mapTypeParticles[part.GetType()].GetDMax();
- }
- completedflds.Add(fld.GetPosition());
- msrFldsArea += aFieldArea;
- }
-
- }
- // get MsrStatus info from DB.
- var GenDB = GetGeneralInfoDB();//DBStoreFile类
- String strTimeStart = "";
- String strTimeEnd = "";
- String strRstStatus = "";
- GenDB.GetDatastore();
- GenDB.GetTableQuery(strTimeStart);
- GenDB.GetTableQuery(strTimeEnd);
- GenDB.GetTableQuery(strRstStatus);
- status.SetCompletedFieldsCenter(completedflds);
- status.SetCompletedFields(completedflds.Count);
- DateTime timeStart, timeEnd;
- TimeSpan timeSpan ;
- timeStart = GetDateTimeFromString(strTimeStart);
- timeEnd = GetDateTimeFromString(strTimeEnd);
- status.SetStartTime(timeStart);
- status.SetEndTime(timeEnd);
- status.SetUsedTime(timeEnd - timeStart);
- status.SetStatus(m_nStatus);
- //get MsrResults data from map.
- List<CMsrResultItem> rstItms = new List<CMsrResultItem>();
- double allPartArea = 0;
- foreach (var typeParticles in mapTypeParticles)
- {
- CMsrResultItem rstItm = new CMsrResultItem();
- int typeNum = 0;
- double typeArea = 0;
- foreach (var p in mapTypeParticles)
- {
- typeNum += 1;
- typeArea += p.GetArea();
- }
- rstItm.SetTypeId(typeParticles.GetType());
- rstItm.SetNumber((uint)typeNum);
- rstItm.SetArea((uint)typeArea);
- rstItms.Add(rstItm);
- allPartArea += typeArea;
- }
- rst.SetResultItems(rstItms);
- rst.SetMeasuredArea(Convert.ToUInt32(msrFldsArea * 1000000));
- rst.SetRadio(allPartArea / (msrFldsArea * 1000000));
- return true;
- }
- public CSQLiteDB GetGeneralInfoDB()
- {
- if (m_generalInfoTable!=null)
- {
- var datastorePtr = GetDatastore();
- if (datastorePtr!=null)
- {
- m_generalInfoTable.GetDatastore();
- }
- }
-
- return m_generalInfoTable;
- }
- //public CGenInfoDB GetGeneralInfoDB()
- // {
- // if (m_generalInfoTable!=null)
- // {
- // var datastorePtr = GetDatastore();
- // if (datastorePtr)
- // {
- // m_generalInfoTable.reset(new CGenInfoDB(datastorePtr));
- // }
- // }
- // return m_generalInfoTable;
- // }
- public DateTime GetDateTimeFromString( String a_DateTime)
- {
- DateTime ole_time = new DateTime();
- ole_time.ToLocalTime();
- return ole_time;
- }
- //此方法为OTSSQLiteDLl中的DBStoreFile类
- public bool Open(string a_sFileName, bool a_bForce /*= TRUE*/)
- {
-
- var datastorePtr = GetDatastore();
- return datastorePtr.Open(a_sFileName, a_bForce);
- }
- public CSQLiteDBFile GetDatastore()
- {
- if (m_datastore!=null)
- {
- m_datastore = CreateNewSQLiteStore();
- }
- return m_datastore;
- }
- public CSQLiteDBFile CreateNewSQLiteStore()
- {
- CSQLiteDBFile SQLiteDBFile = new CSQLiteDBFile();
- return SQLiteDBFile;
- }
- public bool Save()
- {
- // Save or Save As, if strPathName is not empty, it is exist in the computer, this is a save action
- String strPathName = GetPathName();
- // is this a new file?
- strPathName.Trim();
- if (strPathName.CompareTo(UNTITLED_FILE_NAME) == 0)
- {
- // this is a new file
- // return save as result
- return SaveAs();
- }
-
- // set file modify flag
- SetModify(false);
- // Ok, return TRUE
- return true;
- }
- public bool SaveAs()
- {
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // save file dialog
- String strFileName = "";
- if (m_strPathName!="")
- {
- strFileName = GetFileName(m_strPathName);
- }
- // get file name
- String strPathName = "";
- // check file pathname
- strPathName.Trim();
- if (strPathName == "")
- {
- // file open dialog
- OpenFileDialog openFileDialog = new OpenFileDialog();
- if (openFileDialog.ShowDialog() != DialogResult.OK)
- {
- return false;
- }
- // get file pathname
- strPathName = openFileDialog.FileName;
- }
- // set file modify flag
- m_bModify = false;
- // Set project Path
- SetPathName(strPathName);
- // Ok, return TRUE
- return true;
- }
- // Gets the name of the file.
- public String GetFileName(string a_strPathName)
- {
- return a_strPathName;
- }
- // SEM stage data
- public CSEMStageData GetSEMStageData() { return m_pSEMStageData; }
- // SEM stage data
- public void SetSEMStageData(CSEMStageData a_pCSEMStageData)
- {
- // safety check
-
- if (a_pCSEMStageData!=null)
- {
- // invalid stage data pointer
-
- return;
- }
- m_pSEMStageData = new CSEMStageData(a_pCSEMStageData);
- }
- // stage
- public CStage GetStage() { return m_pStage; }
- public void SetStage(CStage a_pStage)
- {
- // safety check
-
- if (a_pStage!=null)
- {
- // invalid input
- return;
- }
- m_pStage = new CStage(a_pStage);
- }
- // samples list
- public List< COTSSample> GetSampleList() { return m_listSamples; }
- // samples list
- public bool SetSampleList(List<COTSSample> a_listSample, bool a_bClear/* = TRUE*/)
- {
- // clear samples list if necessary
- if (a_bClear)
- {
- m_listSamples.Clear();
- }
- // go through the sample list of the source
- foreach (var pSample in a_listSample)
- {
- // add the new sample into sample list
- m_listSamples.Add(pSample);
- }
- return true;
- }
- public COTSSample GetSampleByIndex(int a_nIndex)
- {
- // safe check
- if (a_nIndex < 0 || a_nIndex >= (int)m_listSamples.Count)
- {
- // invalid sample id
- return null;
- }
- // get the matching sample
- COTSSample pSample = m_listSamples[a_nIndex];
- // return the sample
- return pSample;
- }
- public COTSSample GetSampleByName(String a_strSampleName)
- {
-
- bool IsChanged = false;
- for (int itr = 0; itr < m_listSamples.Count; itr++)
- {
- if (m_listSamples[itr].GetName() == a_strSampleName)
- {
- COTSSample pOTSSample = m_listSamples[itr];
- m_listSamples.RemoveAt(itr);
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return m_listSamples[0];
- }
- return m_listSamples[0];
- }
- public COTSSample AddSample(String a_strHoleName)
- {
- // this file is valid, pass the test will make sure all the parameters are ok.
- if (!IsValid())
- {
- // shouldn't be here, invalid file
- return null;
- }
- // get new sample name
- String strNewSampleName = GetNewSampleName();
- // make sure the new sample name is not an empty string
- strNewSampleName.Trim();
- // get a suitable sample hole for the new sample
- CHole pHole = SelectASmpleHole(a_strHoleName);
- // check the sample hole
- if (pHole!=null)
- {
- // failed to get sample hole for the new sample
- return null;
- }
- // measure data parameters containing particle analysis std, image scan parameter, image process parameter and x-ray parameter
- CMsrParams poMsrParams = new CMsrParams();
- MEMBRANE_TYPE a_nVal = (MEMBRANE_TYPE)m_DefaultParameters.GetMembraneType();
- poMsrParams.SetImageScanParam(m_DefaultParameters.GetMsrParam().GetImageScanParam());
- poMsrParams.SetImageProcessParam(m_DefaultParameters.GetMsrParam().GetImageProcessParam());
- poMsrParams.SetXRayParam(m_DefaultParameters.GetMsrParam().GetXRayParam());
- String sSTDName = m_DefaultParameters.GetPartSTDLibFileName();
- poMsrParams.SetSTDName(sSTDName);
- // measurement area
- //CDomainPtr pMsrArea = CalculateMsrArea(pHole);
- CDomain pMsrArea = CalculateDefaultArea(pHole);
- // create a sample
- COTSSample pSample = new COTSSample();
- // set sample parameters
- pSample.SetName(strNewSampleName);
- pSample.SetSampleHoleName(pHole.GetName());
- pSample.SetSwitch(m_DefaultParameters.GetMeasurementSwitch());
- pSample.SetMsrParams(poMsrParams);
- pSample.SetMsrArea(pMsrArea);
- pSample.SetMembraneType(a_nVal);
- // add the new sample into the samples list
- m_listSamples.Add(pSample);
- // set the project file modified.
- SetModify();
- // set the new as working sample
- m_nWorkingSampeIndex = (int)m_listSamples.Count - 1;
- // return the new sample
- return pSample;
- }
- // select a suitable sample hole for a new sample
- public CHole SelectASmpleHole(String a_strHoleName /*= _T("")*/)
- {
-
- // get holes list of the stage
- List< CHole > listHoles = m_pStage.GetHoleList();
- // make sure the holes list is not empty
- if (listHoles.Count == 0)
- {
- // shouldn't happen, stage have no hole.
- return null;
- }
- // check the input hole name
- a_strHoleName.Trim();
- if (a_strHoleName!="")
- {
- // try to find matched hole
-
- bool IsChanged = false;
- for (int itr = 0; itr < listHoles.Count; itr++)
- {
- if (listHoles[itr].GetName() == a_strHoleName)
- {
- CHole pElementChemistry = listHoles[itr];
- listHoles.RemoveAt(itr);
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return listHoles[0];
- }
- }
- // can't find a matched hole, then pick the first empty hole
- // go through the holes list
- foreach (var pHole in listHoles)
- {
- // has this hole any sample in it?
- String strHoleName = pHole.GetName();
- bool IsChanged = false;
- for (int itr = 0; itr < listHoles.Count; itr++)
- {
- if (listHoles[itr].GetName() == a_strHoleName)
- {
- CHole pElementChemistry = listHoles[itr];
- listHoles.RemoveAt(itr);
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return listHoles[0];
- }
- }
- // no empty hole, then the first hole will be the one
- return listHoles[0];
- }
- public CDomain CalculateDefaultArea(CHole a_pHole)
- {
-
- Rectangle rectHole = a_pHole.GetDomainRect();
- System.Drawing.Point ptCenter = rectHole.Location;
- DOMAIN_SHAPE nShape = m_DefaultParameters.GetShape();
- double dArea = m_DefaultParameters.GetArea() * 1000000;
- System.Drawing.Point ptLeftTop = new System.Drawing.Point();
- System.Drawing.Size ptRightBottom = new System.Drawing.Size();
- int nEdge = 0;
- int nRadius = 0;
- switch ((int)nShape)
- {
- case (int)DOMAIN_SHAPE.RECTANGLE:
- nEdge = (int)Math.Sqrt(dArea) / 2;
- ptLeftTop.X = ptCenter.X - nEdge;
- ptLeftTop.Y = ptCenter.Y - nEdge;
- ptRightBottom.Width = ptCenter.X + nEdge;
- ptRightBottom.Height = ptCenter.Y + nEdge;
- break;
- case (int)DOMAIN_SHAPE.ROUND:
- nRadius = (int)Math.Sqrt(dArea / 3.1415926);
- ptLeftTop.X = ptCenter.X - nRadius;
- ptLeftTop.Y = ptCenter.Y - nRadius;
- ptRightBottom.Width = ptCenter.X + nRadius;
- ptRightBottom.Height = ptCenter.Y + nRadius;
- break;
- }
- Rectangle MsrRect = new Rectangle(ptLeftTop, ptRightBottom);
- CDomain pMsrArea = new CDomain(nShape, MsrRect);
- // return measurement area
- return pMsrArea;
- }
- // get new sample name
- public String GetNewSampleName()
- {
- // new sample name
- String strNewSmplName = "";
- // safety check
-
- if (m_DefaultParameters!=null)
- {
- // shouldn't happen, invalid general parameter pointer.
-
- return strNewSmplName;
- }
- // new sample name base
- String strNewSmplNameBase = m_DefaultParameters.GetSampleName() + "%d";
- int nIndex = 1;
- do
- {
- // new sample name is new sample name base + number string
- string.Format(strNewSmplNameBase, nIndex);
- ++nIndex;
- }
- // make sure that the new sample name is not same with any sample in the samples list
- while (SameNameInList(strNewSmplName,0));
- // new sample name
- return strNewSmplName;
- }
- public bool SameNameInList(String a_strSampleName, int a_nExclude /*= -1*/)
- {
- // make sure the input sample name is not empty
- a_strSampleName.Trim();
- if (a_strSampleName=="")
- {
- // shouldn't happen, input name is an empty string
- return false;
- }
- // go through sample list
- int nIndex = 0;
- foreach (var pSample in m_listSamples)
- {
- // return TRUE if this is not an exclude sample and its name is same with input
- String strSampleName = pSample.GetName();
- if (nIndex != a_nExclude && strSampleName.CompareTo(a_strSampleName) == 0)
- {
- // find a same name sample
- return true;
- }
- ++nIndex;
- }
- // no, same name sample in the same list, return FALSE
- return false;
- }
- public bool DeleteSampleByIndex(int a_nIndex)
- {
- // check the index
- if (a_nIndex < 0 || a_nIndex >= (int)m_listSamples.Count)
- {
- // invalid input sample index
-
- return true;
- }
- // calculate new working sample index
- int nNewWorkingSampeIndex;
- if (a_nIndex < m_nWorkingSampeIndex)
- {
- nNewWorkingSampeIndex = m_nWorkingSampeIndex - 1;
- }
- else if (a_nIndex > m_nWorkingSampeIndex)
- {
- nNewWorkingSampeIndex = m_nWorkingSampeIndex;
- }
- else
- {
- // deleting working sample.
- if (a_nIndex == (int)m_listSamples.Count - 1)
- {
- // this is the last sample, select the above sample as working sample
- // if this is only sample in the list working sample index will be -1;
- nNewWorkingSampeIndex = m_nWorkingSampeIndex - 1;
- }
- else
- {
- // select next sample as working sample
- nNewWorkingSampeIndex = m_nWorkingSampeIndex;
- }
- }
- // delete the sample
-
- for (int i = 0; i < m_listSamples.Count; i++)
- {
- m_listSamples.Remove(m_listSamples[i]);
-
- }
-
- // the file is modified.
- SetModify();
- // reset working sample index
- m_nWorkingSampeIndex = nNewWorkingSampeIndex;
- // ok, return TRUE
- return true;
- }
- public bool DeleteSampleByName(String a_strSampleName)
- {
- // check input sample name
- a_strSampleName.Trim();
- if (a_strSampleName=="")
- {
- // input sample name is empty
- return false;
- }
- // go through sample list
- int nIndex = 0;
- foreach (var pSample in m_listSamples)
- {
- // return TRUE if this is not an exclude sample and its name is same with input
- String strSampleName = pSample.GetName();
- if (strSampleName.CompareTo(a_strSampleName) == 0)
- {
- // find the sample, return deleting result
- return DeleteSampleByIndex(nIndex);
- }
- ++nIndex;
- }
- // can't find the sample in the samples list, return FALSE
- return false;
- }
- public bool ResetSamplesListOrder(List<String> a_listSampleNames)
- {
- // no sample in the samples list; shouldn't be here
- if (m_listSamples.Count == 0)
- {
- return false;
- }
- // make sure that input sample names list size is same with the samples list
- if (m_listSamples.Count != a_listSampleNames.Count)
- {
- return false;
- }
- // new sample list
- List<COTSSample> listSamples = new List<COTSSample>();
- // go through the sample names list
- foreach (var strSampleName in a_listSampleNames)
- {
- // find the sample
- // var itr = find_if(m_listSamples.begin(), m_listSamples.end(), [strSampleName](COTSSamplePtr p) { return p->GetName().CompareNoCase(strSampleName) == 0; });
- //if (itr == m_listSamples.end())
- //{
- // // failed to find the sample
- // return false;
- //}
- //// add the sample into the new list
- //listSamples.Add(itr);
- bool IsChanged = false;
- for (int itr = 0; itr < m_listSamples.Count; itr++)
- {
- if (m_listSamples[itr].GetName() == strSampleName)
- {
- COTSSample pElementChemistry = m_listSamples[itr];
- m_listSamples.RemoveAt(itr);
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return false;
- }
- }
- // reset the samples list
- m_listSamples.Clear();
- foreach (var pSample in listSamples)
- {
- m_listSamples.Add(pSample);
- }
- // set modify flag
- SetModify();
- // Ok, return TRUE
- return true;
- }
- public bool InsrtSample(COTSSample a_pSample, int a_nIndex)
- {
- // input check
-
- if (a_pSample!=null)
- {
- // invalid input sample pointer
- return false;
- }
- if (m_listSamples.Count == 0 || a_nIndex >= (int)m_listSamples.Count)
- {
- m_listSamples.Add(a_pSample);
- }
- else if (a_nIndex <= 0)
- {
- m_listSamples.Insert(Convert.ToInt32(m_listSamples[a_nIndex]), a_pSample);
- }
- else
- {
- m_listSamples.Insert(Convert.ToInt32(m_listSamples[a_nIndex]) + a_nIndex, a_pSample);
- }
- // Ok, return TRUE
- return true;
- }
- public bool ChangeSamplePosition(int a_nIndexFrom, int a_nIndexTo)
- {
- // make sure both index are valid
- if (a_nIndexFrom < 0 || a_nIndexFrom >= (int)m_listSamples.Count)
- {
- // invalid from index
- return false;
- }
- if (a_nIndexTo < 0 || a_nIndexTo >= (int)m_listSamples.Count)
- {
- // invalid to index
- return false;
- }
- // need to do nothing if the two indexes are the same
- if (a_nIndexFrom != a_nIndexTo)
- {
- // move to last?
- bool bLast = (a_nIndexTo == ((int)m_listSamples.Count - 1));
- // get the sample
- COTSSample pSample = m_listSamples[a_nIndexFrom];
-
- // remove it from the samples list
- m_listSamples.Remove(pSample);
- // put the sample back in
- if (bLast)
- {
- m_listSamples.Add(pSample);
- }
- else
- {
- m_listSamples.Insert(Convert.ToInt32(m_listSamples[a_nIndexTo]) + a_nIndexTo, pSample);
- }
- }
- // Ok, return TRUE
- return true;
- }
- public bool MoveSamplePosition(COTSSample a_pTargetSample, COTSSample a_RefpSample, bool a_bBefore /*= TRUE*/)
- {
- // check input
-
- if (a_pTargetSample!=null)
- {
- // invalid input target sample pointer
- return false;
- }
-
- if (a_RefpSample!=null)
- {
- // invalid input ref sample pointer
- return false;
- }
-
- bool IsChanged = false;
- for (int itr = 0; itr < m_listSamples.Count; itr++)
- {
- if (m_listSamples[itr].GetName() == a_pTargetSample.GetName())
- {
- COTSSample pElementChemistry = m_listSamples[itr];
-
- m_listSamples.RemoveAt(itr);
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return false;
- }
-
- for (int itr = 0; itr < m_listSamples.Count; itr++)
- {
- if (m_listSamples[itr].GetName() == a_RefpSample.GetName())
- {
- COTSSample pElementChemistry = m_listSamples[itr];
- m_listSamples.RemoveAt(itr);
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return false;
- }
- // need to do nothing if the two sample are same
-
- // remove the sample from the samples list
-
- for (int itr = 0; itr < m_listSamples.Count; itr++)
- {
- if (m_listSamples[itr].GetName() == a_RefpSample.GetName())
- {
- COTSSample pElementChemistry = m_listSamples[itr];
- m_listSamples.RemoveAt(itr);
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return false;
- }
- // put the sample back in
- if (a_bBefore)
- {
- m_listSamples.Insert(0, a_pTargetSample);
- }
- else
- {
- m_listSamples.Insert(1, a_pTargetSample);
- }
-
- // Ok, return TRUE
- return true;
- }
- public bool MoveSamplePosition(String a_strTargetSampleName, String a_strRefSampleName, bool a_bBefore /*= TRUE*/)
- {
- // input check
- a_strTargetSampleName.Trim();
- if (a_strTargetSampleName=="")
- {
- // input target sample is an empty string
- return false;
- }
- a_strRefSampleName.Trim();
- if (a_strRefSampleName=="")
- {
- // input ref sample is an empty string
- return false;
- }
- // var itr = std::find_if(m_listSamples.begin(), m_listSamples.end(), [a_strTargetSampleName](COTSSamplePtr p) { return p->GetName().CompareNoCase(a_strTargetSampleName) == 0; });
- //if (itr == m_listSamples.end())
- //{
- // // target sample name is not the name of any sample in the samples list
- // return false;
- //}
- bool IsChanged = false;
- for (int itr = 0; itr < m_listSamples.Count; itr++)
- {
- if (m_listSamples[itr].GetName() == a_strTargetSampleName)
- {
- COTSSample pElementChemistry = m_listSamples[itr];
- m_listSamples.RemoveAt(itr);
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return false;
- }
- COTSSample pTargetSample = m_listSamples[0];
- // itr = std::find_if(m_listSamples.begin(), m_listSamples.end(), [a_strRefSampleName](COTSSamplePtr p) { return p->GetName().CompareNoCase(a_strRefSampleName) == 0; });
- //if (itr == m_listSamples.end())
- //{
- // // ref sample name is not the name of any sample in the samples list
- // return false;
- //}
-
- for (int itr = 0; itr < m_listSamples.Count; itr++)
- {
- if (m_listSamples[itr].GetName() == a_strTargetSampleName)
- {
- COTSSample pElementChemistry = m_listSamples[itr];
- m_listSamples.RemoveAt(itr);
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return false;
- }
- COTSSample pRefSample = pTargetSample;
- // need to do nothing if the two name are same
- if (a_strTargetSampleName.CompareTo(a_strRefSampleName) != 0)
- {
- return MoveSamplePosition(pTargetSample, pRefSample, a_bBefore);
- }
- // Ok, return TRUE
- return true;
- }
- public COTSSample GetWorkingSample()
- {
- // check if the working sample index
- if (m_nWorkingSampeIndex < 0 || m_nWorkingSampeIndex >= (int)m_listSamples.Count)
- {
- // invalid working sample index
- return null;
- }
- return GetSampleByIndex(m_nWorkingSampeIndex);
- }
- int GetWorkingSampleIndex() { return m_nWorkingSampeIndex; }
- void SetWorkingSampleIndex(int a_nWorkingSampleIndex) { m_nWorkingSampeIndex = a_nWorkingSampleIndex; }
- public bool SetWorkingSampleByIndex(int a_nIndex)
- {
- // special treatment
- if (a_nIndex == -1 && m_listSamples.Count == 0)
- {
- m_nWorkingSampeIndex = -1;
- return true;
- }
- // check if the working sample index
- if (0 > a_nIndex || a_nIndex >= (int)m_listSamples.Count)
- {
- // invalid sample index
- return false;
- }
- m_nWorkingSampeIndex = a_nIndex;
- return true;
- }
- public bool SetWorkingSampleByName(String a_pSampleName)
- {
- // check input sample name
- a_pSampleName.Trim();
- if (a_pSampleName=="")
- {
- // input sample name is empty
- return false;
- }
- // go through sample list
- int nIndex = 0;
- foreach (var pSample in m_listSamples)
- {
- // return TRUE if this is not an exclude sample and its name is same with input
- String strSampleName = pSample.GetName();
- if (strSampleName.CompareTo(a_pSampleName) == 0)
- {
- // find the sample, return deleting result
- return SetWorkingSampleByIndex(nIndex);
- }
- ++nIndex;
- }
- // failed to find the named sample
- // failed to find the named sample return FALSE
- return false;
- }
- public bool DeleteWorkingSample()
- {
- // check if the working sample index
- if (m_nWorkingSampeIndex < 0 || m_nWorkingSampeIndex >= (int)m_listSamples.Count)
- {
- // invalid working sample index
- return false;
- }
- // return the result of DeleteSampleByIndex
- return DeleteSampleByIndex(m_nWorkingSampeIndex);
- }
- // Sample hole BSE image list
- public List< CHoleBSEImg> GetHoleBESImgList() { return m_listHoleBSEImg; }
- // hole BSE images list
- public void SetHoleBESImgList(List<CHoleBSEImg> 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)
- {
- // create a hole BSE image copy
- CHoleBSEImg pHoleBSEImgNew=(new CHoleBSEImg(pHoleBSEImg));
- // add the new hole BSE image into HoleBSEImage list
- m_listHoleBSEImg.Add(pHoleBSEImgNew);
- }
- if (m_nWorkingSampeIndex != -1)
- {
- COTSSample pSample = GetWorkingSample();
-
- }
- }
- // get modify flag
- public bool IsModified() { return m_bModify; }
- // file name
- public String GetFileName()
- {
- // make a copy of file path name
- String strPathName = m_strPathName;
- // is this a new file?
- strPathName.Trim();
- if (strPathName.CompareTo(UNTITLED_FILE_NAME) == 0)
- {
- return strPathName;
- }
- // get file name
- String strFileName = GetFileNameWithoutExtension(strPathName);
- strFileName = GetFileName(strFileName);
- // return file name
- return strFileName;
- }
- // get file name without extension
- public String GetFileNameWithoutExtension(String a_strPathName)
- {
- // string str = "";
- Char[] sPath = new Char[otsdataconst.MAX_PATH + 4];
- // str.CopyTo(0, sPath, 0, Convert.ToInt32(a_strPathName));
- System.IO.Path.GetFileNameWithoutExtension(sPath.ToString());
- return sPath.ToString();
- }
- // if the new sample name can be used.
- public bool IsValidSampleName(String a_sName)
- {
- int nindex = -1;
- foreach (var pSample in m_listSamples)
- {
- nindex++;
- String sSampleName = pSample.GetName();
- if (a_sName.CompareTo(sSampleName)!=0)
- {
- if (nindex != m_nWorkingSampeIndex)
- {
- return false;
- }
- }
- }
- return true;
- }
- // get std file list, a_nPos = -1, current do not use any STD lib, a_nPos = 0, current use STD lib.
- public bool GetSTDFileList(int a_nPos, List<String> a_listSTDLibName)
- {
-
- String a_strFolderName = m_DefaultParameters.GetPartSTDLibFolderName();
- if (a_strFolderName == "")
- {
-
- return false;
- }
- // lib name list
- a_listSTDLibName.Clear();
- // file list
- List<String> listSTDFile = new List<string>();
- listSTDFile.Clear();
- const String STD_LIB_EXT = ".db";
- // get file list
- if (!GetFileNameList(a_strFolderName, STD_LIB_EXT, listSTDFile))
- {
- return false;
- }
- foreach (var file in listSTDFile)
- {
- //CString fileName = file.Left(file.GetLength() - 3);
- String fileName = file;
- a_listSTDLibName.Add(fileName);
- }
- //before the use choose one STD, always should be null.
- a_nPos = -1;
- String sCurrentSTD;
- CMsrParams pCurrentParam;
- COTSSample pSample = GetWorkingSample();
- if (pSample == null)
- {
-
- }
- else
- {
- pCurrentParam = pSample.GetMsrParams();
- if (pCurrentParam == null)
- {
-
- }
- //将当前使用的数据库的名字与下拉菜单的名字对应起来
- sCurrentSTD = pCurrentParam.GetSTDName();
- for (int i = 0; i < (int)a_listSTDLibName.Count; i++)
- {
- a_nPos++;
- if (a_listSTDLibName[i].CompareTo(sCurrentSTD) == 0)
- break;
- }
- }
- return true;
- }
- // get file name list in a folder
- public bool GetFileNameList(String a_strFolderName, String a_strFileType, List<String> a_listFileName)
- {
- // get file name
- a_strFolderName += "*";
- a_strFolderName += a_strFileType;
- try
- {
- //find first file
- int FindFileData = 0;
- // int file = FindFirstFile(a_strFolderName, FindFileData);
- string path = a_strFolderName;
- string filename = a_strFileType;
- List<string> lineStringList = new List<string>();//存储所有读取到的文件
- DirectoryInfo[] dateDirArr = new DirectoryInfo(path).GetDirectories(); //取指定路径下的所有目录
- foreach (DirectoryInfo directoryInfo in dateDirArr)
- {
- string fullName = directoryInfo.Name + "\\" + filename;
- if (!File.Exists(fullName))
- {
- continue;//目录下不存在此文件,返回。
- }
- FileInfo file = new FileInfo(fullName);
- StreamReader reader = new StreamReader(file.FullName);
- while (!reader.EndOfStream)//判断是否读取完成
- {
- lineStringList.Add(reader.ReadLine());
- }
- reader.Close();
-
- }
- int INVALID_HANDLE_VALUE = 0;
- //find other file
- if (FindFileData!= INVALID_HANDLE_VALUE)
- {
- a_listFileName.Add(FindFileData.ToString());
- bool bState = false;
-
- FindFile(a_strFolderName, FindFileData.ToString());
- while (bState)
- {
- a_listFileName.Add(FindFileData.ToString());
- FindFile(a_strFolderName, FindFileData.ToString());
- }
- }
- }
- catch (Exception pe)
- {
- return false;
- }
- return true;
- }
- static String FindFile(String filename, String path)
- {
- if (Directory.Exists(path))
- {
- if (File.Exists(path + filename))
- return path + filename;
- String[] directorys = Directory.GetDirectories(path);
- foreach (String d in directorys)
- {
- String p = FindFile(filename, d);
- if (p != null)
- return p;
- }
- }
- return null;
- }
- //// change STD
- public bool ChangeSTDFromList(int a_nPos)
- {
-
- String a_strFolderName = m_DefaultParameters.GetPartSTDLibFolderName();
- if (a_strFolderName == "")
- {
- return false;
- }
- // file list
- List<String> listSTDFile = new List<string>();
- listSTDFile.Clear();
- const String STD_LIB_EXT = ".db";
- // get file list
- if (!GetFileNameList(a_strFolderName, STD_LIB_EXT, listSTDFile))
- {
- return false;
- }
- List<String> listSTDLibName = new List<string>();
- listSTDLibName.Clear();
- foreach (var file in listSTDFile)
- {
- //CString fileName = file.Left(file.GetLength() - 3);
- String fileName = file;
- listSTDLibName.Add(fileName);
- }
- if (a_nPos > (int)listSTDLibName.Count)
- {
- return false;
- }
- String STDName = listSTDLibName[a_nPos];
- // updata STD to working sample
- COTSSample pSample = GetWorkingSample();
-
- CMsrParams pParam = pSample.GetMsrParams();
-
- pParam.SetSTDName(STDName);
- pSample.SetMsrParams(pParam);
- return true;
- }
- // get measured sample list
- public bool GetMsredSampleList(List<COTSSample> a_listMsredSample)
- {
- a_listMsredSample.Clear();
- foreach (var pSample in m_listSamples)
- {
-
- if (pSample.GetMsrResults() == new CMsrResults())
- {
- continue;
- }
- else
- {
- a_listMsredSample.Add(pSample);//the reference count will increament automatically.
- }
- }
- return true;
- }
- // calculate measurement area
- public CDomain CalculateMsrArea(CHole a_pHole)
- {
- CDomain pMsrArea = new CDomain(a_pHole.GetShape(), a_pHole.GetDomainRect());
- // create measurement area
- // reset measurement area
- // measurement area should smaller than the sample hole
- Rectangle rectMsrArea = pMsrArea.GetDomainRect();
- int nWidth = rectMsrArea.Width;
- int nHeight = rectMsrArea.Height;
- int nDeflateX = CalculateDeflateValue(nWidth);
- int nDeflateY = CalculateDeflateValue(nHeight);
- rectMsrArea.Offset(nDeflateX, nDeflateY);
- pMsrArea.SetDomainRect(rectMsrArea);
- // return measurement area
- return pMsrArea;
- }
- // calculate deflate value
- public int CalculateDeflateValue(int a_nWitchOrHeight)
- {
- const long LENGTH_THRESHOLD = 150000;
- const long LENGTH_THRESHOLD_MIN = 10000;
- const int EDGE = 1000;
- const int EDGE_MIN = 500;
- // deflate 1000 if width or height is greater than 15000
- if (a_nWitchOrHeight >= LENGTH_THRESHOLD)
- {
- return EDGE;
- }
- // deflate 500 if width or height is greater than 15000
- else if (a_nWitchOrHeight >= LENGTH_THRESHOLD_MIN)
- {
- return EDGE_MIN;
- }
- // otherwise, no deflate
- return 0;
- }
- // remove background
- public bool RemoveBackGround(CBSEImg a_pImgIn, OTSDataType.COTSImageProcessParam a_pImgProcessParam, CBSEImg a_pImgOut)
- {
-
- /*COTSFieldMgr fldMgr;
- fldMgr.SetBSEImage(a_pImgIn);
- fldMgr.RemoveBSEImageBG(a_pImgProcessParam);
- a_pImgOut = fldMgr.GetBSEImage();*/
- // Binary
- int nWidth = a_pImgIn.GetWidth();
- int nHeight = a_pImgIn.GetHeight();
- int nImgSize = nWidth * nHeight;
- Byte[] pPixel = new Byte[nImgSize];
- Byte[] pSrcImg = a_pImgIn.GetImageDataPointer();
- Byte[] pTargetImg = new Byte[nImgSize];
- long nBGStart;
- long nBGEnd;
- if (a_pImgProcessParam.GetBGRemoveType() == OTS_BGREMOVE_TYPE.MANUAL)
- {
- nBGStart = a_pImgProcessParam.GetBGGray().GetStart();
- nBGEnd = a_pImgProcessParam.GetBGGray().GetEnd();
- // delete background
- for (uint i = 0; i < nImgSize; i++)
- {
- if (pSrcImg[i] >= nBGStart && pSrcImg[i] <= nBGEnd)
- {
- pPixel[i] = 0;
- }
- else
- {
- pPixel[i] = 255;
- }
- }
- }
- else
- {
- var range = a_pImgIn.CalBackground(a_pImgProcessParam.GetBGRemoveType());//in this function, the input perameter takes no effect right now,but may be useful in the future.
- nBGStart = range.GetStart();
-
- nBGEnd = range.GetEnd();
- switch (a_pImgProcessParam.GetAutoBGRemoveType())
- {
- case OTS_AUTOBGREMOVE_TYPE.DOWNWARD:
- for (uint i = 0; i < nImgSize; i++)
- {
- if (pSrcImg[i] <= nBGEnd)
- {
- pPixel[i] = 0;
- }
- else
- {
- pPixel[i] = 255;
- }
- }
- break;
- case OTS_AUTOBGREMOVE_TYPE.UPWARD:
- for (uint i = 0; i < nImgSize; i++)
- {
- if (pSrcImg[i] >= nBGStart)
- {
- pPixel[i] = 0;
- }
- else
- {
- pPixel[i] = 255;
- }
- }
- break;
- case OTS_AUTOBGREMOVE_TYPE.MIDDLE:
- for (uint i = 0; i < nImgSize; i++)
- {
- if (pSrcImg[i] >= nBGStart && pSrcImg[i] <= nBGEnd)
- {
- pPixel[i] = 0;
- }
- else
- {
- pPixel[i] = 255;
- }
- }
- break;
- default:
- break;
- }
- }
- long nPtStart = a_pImgProcessParam.GetParticleGray().GetStart();
- long nPtEnd = a_pImgProcessParam.GetParticleGray().GetEnd();
-
- // image process
- m_HardwareMgr.BErode3(pPixel.ToString(), pTargetImg.ToString(), 5, nHeight, nWidth);
- m_HardwareMgr.BDilate3(pTargetImg.ToString(), pPixel.ToString(), 5, nHeight, nWidth);
- // show the image
- for (uint i = 0; i < nImgSize; i++)
- {
- uint Pixel = BitConverter.ToUInt32(pPixel,0);
- uint SrcImg = BitConverter.ToUInt32(pSrcImg, 0);
- Pixel = 255 - (Pixel + i);
- if ((Pixel + i) == 0)
- {
- Pixel = SrcImg + i;
- }
- }
- a_pImgOut. SetImageRect(a_pImgIn.GetImageRect());
- a_pImgOut.SetImageData(pPixel);
-
- return true;
- }
-
- public COTSGeneralParameters GetDefaultParameters() { return m_DefaultParameters; }
- public void SetDefaultParameters(COTSGeneralParameters val) { m_DefaultParameters = val; }
- public void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
- {
- //xmls::xInt xProjMgrFileMark;
- //xmls::xString xProjMgrFileVersion;
- //xmls::xString xstrPathName;
- //xmls::Collection<CHoleBSEImg> xholeBSEImgs;
- //xmls::Collection<COTSSample> xsamples;
- //xmls::Slo slo;
- xInt xProjMgrFileMark = new xInt();
- xString xProjMgrFileVersion = new xString();
- xString xstrPathName = new xString();
- Collection<CHoleBSEImg> xholeBSEImgs = new Collection<CHoleBSEImg>();
- Collection<COTSSample> xsamples = new Collection<COTSSample>();
- Collection<CSEMStageData> m_pSEMStageData = new Collection<CSEMStageData>();
- Collection<CStage> m_pStage = new Collection<CStage>();
- Slo slo = new Slo();
- slo.Register("ProjMgrFileMark", xProjMgrFileMark);
- slo.Register("ProjMgrFileVersion", xProjMgrFileVersion);
- slo.Register("strPathName", xstrPathName);
- slo.Register("SEMStageData", m_pSEMStageData);
- slo.Register("Stage", m_pStage);
- slo.Register("HoleBSEImg", xholeBSEImgs);
- slo.Register("Samples", xsamples);
- if (isStoring)
- {
- xProjMgrFileMark.AssignValue(PROJ_MGR_FILE_MARK);
- xProjMgrFileVersion.AssignValue(PROJ_MGR_FILE_VERSION);
- xstrPathName.AssignValue(m_strPathName);
- xholeBSEImgs.Clear();
- foreach (var hole in m_listHoleBSEImg)
- {
- xholeBSEImgs.addItem(hole);
- }
- xsamples.Clear();
- foreach (var sample in m_listSamples)
- {
- xsamples.addItem(sample);
- }
- slo.Serialize(true, classDoc, rootNode);
- }
- else
- {
- slo.Serialize(false, classDoc, rootNode);
- m_strPathName = xstrPathName.value().ToString();
- m_listHoleBSEImg.Clear();
- for (uint i = 0; i < xholeBSEImgs.size(); i++)
- {
- m_listHoleBSEImg.Add(xholeBSEImgs.getItem((int)i));
- }
- m_listSamples.Clear();
- for (int i = 0; i < (int)xsamples.size(); i++)
- {
- m_listSamples.Add(xsamples.getItem(i));
- }
- }
- }
- //合并后新添加的需要的方法
- public bool SetImageScanParam(COTSGeneralParameters ImageScan) { return false; }
- public COTSImgScanPrm GetImageScanParam() { return null; }
- }
- }
|