| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923 |
- #pragma once
- #include "stdafx.h"
- #include "OTSProjMgrFile.h"
- #include "OTSProgMgr.h"
- #include "StageFile.h"
- #include "STDXMLFileMnr.h"
- #include "MsrParamFileMgr.h"
- #include "OTSImageProcess.h"
- #include "OTSFileSys.h"
- #include "OTSHelper.h"
- #include "resource.h"
- #include "SmplMsrResultFile.h"
- #include "IncAFileMgr.h"
- #include <io.h>
- #include <stdio.h>
- #include <stdlib.h>
- namespace OTSMODEL {
- using namespace OTSIMGPROC;
- // project file mark
- const int PROJ_MGR_FILE_MARK = 'P' + 'R' + 'O' + 'J' + 'E' + 'T' + 'M' + 'A' + 'N' + 'A' + 'G' + 'E' + 'R';
- // project file version string
- const CString PROJ_MGR_FILE_VERSION = _T("1.1.1");
- // project file extension
- const CString PROJ_EXTION = _T("prj");
- // project file filter
- const CString PROJECT_FILE_FILTER = _T("Project Files (*.prj)|*.prj|All Files (*.*)|*.*||");
- // EDGE threshold if length > 15000 edge is 1000, if length > 10000 edge is 500, otherwise no edge, unit is um
- const long LENGTH_THRESHOLD = 150000;
- const long LENGTH_THRESHOLD_MIN = 10000;
- const long EDGE = 1000;
- const long EDGE_MIN = 500;
- // COTSProjMgrFile
- // constructor
- COTSProjMgrFile::COTSProjMgrFile()
- {
- Init();
- }
- // copy constructor
- COTSProjMgrFile::COTSProjMgrFile(const COTSProjMgrFile& a_oSource)
- {
- // can't copy itself
- if (&a_oSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(a_oSource);
- }
- COTSProjMgrFile::COTSProjMgrFile(COTSProjMgrFile* a_poSource)
- {
- // input check
- ASSERT(a_poSource);
- if (!a_poSource)
- {
- return;
- }
- // can't copy itself
- if (a_poSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(*a_poSource);
- }
- // =operator
- COTSProjMgrFile& COTSProjMgrFile::operator=(const COTSProjMgrFile& a_oSource)
- {
- // cleanup
- Cleanup();
- // copy the class data over
- Duplicate(a_oSource);
- // return class
- return *this;
- }
- // destructor
- COTSProjMgrFile::~COTSProjMgrFile()
- {
- // cleanup
- Cleanup();
-
- }
- // serialization
-
- void COTSProjMgrFile::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
- {
-
- xmls::xInt xProjMgrFileMark;
- xmls::xString xProjMgrFileVersion;
- xmls::xString xstrPathName;
- xmls::Collection< CHoleBSEImg> xholeBSEImgs;
- xmls::Collection<COTSSample> xsamples;
- xmls::Slo slo;
- slo.Register("ProjMgrFileMark", &xProjMgrFileMark);
- slo.Register("ProjMgrFileVersion", &xProjMgrFileVersion);
- slo.Register("strPathName", &xstrPathName);
- slo.Register("SEMStageData", m_pSEMStageData.get());
- slo.Register("Stage", m_pStage.get());
- slo.Register("HoleBSEImg", &xholeBSEImgs);
- slo.Register("Samples", &xsamples);
- if (isStoring)
- {
- xProjMgrFileMark = PROJ_MGR_FILE_MARK;
- xProjMgrFileVersion = PROJ_MGR_FILE_VERSION;
- xstrPathName = m_strPathName;
- xholeBSEImgs.Clear();
- for (auto hole : m_listHoleBSEImg)
- {
- xholeBSEImgs.addItem(hole.get());
- }
- xsamples.Clear();
- for (auto sample : m_listSamples)
- {
- xsamples.addItem(sample.get());
- }
- slo.Serialize(true, classDoc, rootNode);
-
- }
- else
- {
- slo.Serialize(false, classDoc, rootNode);
- m_strPathName = xstrPathName.value().c_str();
- m_listHoleBSEImg.clear();
- for (unsigned int i = 0; i < xholeBSEImgs.size(); i++)
- {
- m_listHoleBSEImg.push_back(CHoleBSEImgPtr(xholeBSEImgs.getItem(i)));
- }
- m_listSamples.clear();
- for (int i = 0; i < (int)xsamples.size(); i++)
- {
- m_listSamples.push_back(COTSSamplePtr(xsamples.getItem(i)));
- }
-
- }
-
- }
- // class member functions
- // public
- // file
- BOOL COTSProjMgrFile::NewFile()
- {
- // file invalidation
- if (!IsValid())
- {
- // shouldn't happen, file is invalid
- LogErrorTrace(__FILE__, __LINE__, _T("Load: file is invalid."));
- return FALSE;
- }
- // set file name
- SetPathName(UNTITLED_FILE_NAME);
- // Ok, return TRUE
- return TRUE;
- }
- BOOL COTSProjMgrFile::Load()
- {
- // use dll resource
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // open file dialog,
- CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, PROJECT_FILE_FILTER);
- if (dlg.DoModal() != IDOK)
- {
- // user didn't click OK button, return FALSE
- LogTrace(__FILE__, __LINE__, _T("Load: user canceled on file open dialog."));
- return FALSE;
- }
- //Init data
- Cleanup();
-
- // get file name
- CString strPathName = dlg.GetPathName();
- // check if the file exist
- if (!COTSFileSys::Exists(strPathName))
- {
- // shouldn't happen, file does not exist
- LogErrorTrace(__FILE__, __LINE__, _T("Load: file (%s) does not exist."), strPathName);
- return FALSE;
- }
- tinyxml2::XMLDocument doc;
- doc.LoadFile(strPathName);//载入xml文件
- tinyxml2::XMLElement *rootNode;
- rootNode = doc.FirstChildElement(RootClassName);
- Serialize(false, &doc, rootNode);
- m_strPathName = strPathName;
- // get path of the pathname
- CString strFilePath = COTSHelper::GetFolderName(strPathName);
- if (strFilePath.IsEmpty())
- {
- // file path string is an empty string
- LogErrorTrace(__FILE__, __LINE__, _T("Load: file path string is an empty string."));
- return FALSE;
- }
- //-------------
- for(auto smpl:m_listSamples)
- {
-
- // field file sub folder string
- CString strFieldFileSubFolder = strFilePath + _T("\\")+smpl->GetName()+_T("\\") + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + _T("\\");
- // check if the field file sub folder exists
- if (!COTSFileSys::Exists(strFieldFileSubFolder))
- {// field files folder doesn't exist
- //LogErrorTrace(__FILE__, __LINE__, _T("Load: field files folder doesn't exist (%s)."), strFieldFileSubFolder);
- continue;
- }
- CString strIncAFilename = strFieldFileSubFolder + _T("\\") + SMPL_MSR_RESULT_INCLUSION_FILE;
- CIncAFileMgrPtr pIncAFileMgr = CIncAFileMgrPtr(new CIncAFileMgr(strIncAFilename));
- COTSFieldDataList allFlds;
- CMsrSampleStatusPtr poMsrStatus = smpl->GetMsrStatus();
- CMsrResultsPtr poMsrResults = smpl->GetMsrResults();
- double aFldArea = smpl->CalculateAFieldArea();
- if (pIncAFileMgr->GetAllFieldsFromDB(allFlds, poMsrStatus, poMsrResults, aFldArea))
- {
- smpl->SetFieldsData(allFlds);
- // file validation
- if (!m_pSEMStageData || *(m_pSEMStageData.get()) == CSEMStageData())
- {
- // invalid SME stage data
- LogErrorTrace(__FILE__, __LINE__, _T("Load: invalid SME stage data."));
- return FALSE;
- }
- if (!m_pStage || *(m_pStage.get()) == CStage())
- {
- // invalid stage
- LogErrorTrace(__FILE__, __LINE__, _T("Load: empty SEM stage data."));
- return FALSE;
- }
- // set modify flag
- SetModify(FALSE);
- // set pathname
- SetPathName(strPathName);
- // set working sample
- if (m_listSamples.size() > 0)
- {
- m_nWorkingSampeIndex = 0;
- }
- else
- {
- m_nWorkingSampeIndex = -1;
- }
-
-
- }
- else
- {
- return FALSE;
- }
- }
- if (!m_listSamples.empty())
- {
- m_nWorkingSampeIndex = 0;
- }
- //-----------------------------------------
- return TRUE;
-
- }
- BOOL COTSProjMgrFile::Save()
- {
- // Save or Save As, if strPathName is not empty, it is exist in the computer, this is a save action
- CString strPathName = GetPathName();
- // is this a new file?
- strPathName.Trim();
- if (strPathName.CompareNoCase(UNTITLED_FILE_NAME) == 0)
- {
- if (!SaveAs())
- {
- return FALSE;
- }
- // this is a new file
- for (auto pSample : m_listSamples)
- {
- DeleteSampleFiles(pSample->GetName());
- }
- //DeleteSampleFiles
- // return save as result
- }
- tinyxml2::XMLDocument doc;
- if (COTSFileSys::Exists(strPathName))
- {
- doc.LoadFile(strPathName);//载入xml文件
- }
- doc.Clear();
- tinyxml2::XMLDeclaration* declaration = doc.NewDeclaration();//添加xml文件头申明
- doc.InsertFirstChild(declaration);
- tinyxml2::XMLElement *rootNode;
- rootNode = doc.NewElement(RootClassName);
- Serialize(true, &doc, rootNode);
- doc.InsertEndChild(rootNode);
-
- int result = doc.SaveFile(strPathName);
-
- // set file modify flag
- SetModify(FALSE);
- // Ok, return TRUE
- return TRUE;
- }
- BOOL COTSProjMgrFile::SaveAs()
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // save file dialog
- CString strFileName = _T("");
- if (!m_strPathName.IsEmpty())
- {
- strFileName = COTSHelper::GetFileName(m_strPathName);
- }
- CFileDialog dlg(FALSE, PROJ_EXTION, strFileName, OFN_OVERWRITEPROMPT, PROJECT_FILE_FILTER);
- if (dlg.DoModal() != IDOK)
- {
- // user didn't click OK button, return FALSE
- LogTrace(__FILE__, __LINE__, _T("SaveAs: user canceled on file open dialog."));
- return FALSE;
- }
- // get file pathname
- CString strPathName = dlg.GetPathName();
-
- //--------xml serialize-------
- tinyxml2::XMLDocument doc;
- if (COTSFileSys::Exists(strPathName))
- {
- doc.LoadFile(strPathName);//载入xml文件
- }
-
- doc.Clear();
- tinyxml2::XMLDeclaration* declaration = doc.NewDeclaration();//添加xml文件头申明
- doc.InsertFirstChild(declaration);
- tinyxml2::XMLElement *rootNode;
- rootNode = doc.NewElement(RootClassName);
- doc.InsertEndChild(rootNode);
- Serialize(true, &doc, rootNode);
- int result = doc.SaveFile(strPathName);
-
- //-----------------------------
- // set file modify flag
- m_bModify = FALSE;
- // Set project Path
- SetPathName(strPathName);
- // Ok, return TRUE
- return TRUE;
- }
- BOOL COTSProjMgrFile::IsValid()
- {
- if (!m_pSEMStageData || m_pSEMStageData.get() == nullptr)
- {
- return FALSE;
- }
- else if (!m_pStage || m_pStage.get() == nullptr)
- {
- return FALSE;
- }
- else if (!m_pGenParam || !m_pImageProcParam || !m_pImageScanParam || !m_pXRayParam)
- {
- return FALSE;
- }
- // Ok, return TRUE
- return TRUE;
- }
- // SEM stage data
- void COTSProjMgrFile::SetSEMStageData(CSEMStageDataPtr a_pCSEMStageData)
- {
- // safety check
- ASSERT(a_pCSEMStageData);
- if (!a_pCSEMStageData)
- {
- // invalid stage data pointer
- LogErrorTrace(__FILE__, __LINE__, _T("SetStageData: invalid input stage data pointer."));
- return;
- }
- m_pSEMStageData = CSEMStageDataPtr(new CSEMStageData(a_pCSEMStageData.get()));
- }
- // stage (working stage)
- void COTSProjMgrFile::SetStage(CStagePtr a_pStage)
- {
- // safety check
- ASSERT(a_pStage);
- if (!a_pStage)
- {
- // invalid input
- LogErrorTrace(__FILE__, __LINE__, _T("SetStage: invalid input stage pointer."));
- return;
- }
- m_pStage = CStagePtr(new CStage(a_pStage.get()));
- }
- // general parameters
- void COTSProjMgrFile::SetGenParam(COTSGeneralParametersPtr a_pGenParam)
- {
- ASSERT(a_pGenParam);
- if (!a_pGenParam)
- {
- // invalid input
- LogErrorTrace(__FILE__, __LINE__, _T("SetGenParam: invalid input general parameter pointer."));
- return;
- }
- m_pGenParam = COTSGeneralParametersPtr(new COTSGeneralParameters(a_pGenParam.get()));
- }
- // image scan parameters
- void COTSProjMgrFile::SetImageScanParam(COTSImageScanParamPtr a_pImageScanParam)
- {
- ASSERT(a_pImageScanParam);
- if (!a_pImageScanParam)
- {
- // invalid input
- LogErrorTrace(__FILE__, __LINE__, _T("SetImageScanParam: invalid input image scan parameter pointer."));
- return;
- }
- m_pImageScanParam = COTSImageScanParamPtr(new COTSImageScanParam(a_pImageScanParam.get()));
- }
- // image process parameters
- void COTSProjMgrFile::SetImageProcParam(COTSImageProcessParamPtr a_pImageProcParam)
- {
- ASSERT(a_pImageProcParam);
- if (!a_pImageProcParam)
- {
- // invalid input
- LogErrorTrace(__FILE__, __LINE__, _T("SetImageProcParam: invalid input image process parameter pointer."));
- return;
- }
- m_pImageProcParam = COTSImageProcessParamPtr(new COTSImageProcessParam(a_pImageProcParam.get()));
- }
- // x ray parameters
- void COTSProjMgrFile::SetXRayParam(COTSXRayParamPtr a_pXRayParam)
- {
- ASSERT(a_pXRayParam);
- if (!a_pXRayParam)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("SetXRayParam: invalid X-Ray parameter pointer."));
- return;
- }
- m_pXRayParam = COTSXRayParamPtr(new COTSXRayParam(a_pXRayParam.get()));
- }
- // samples list
- bool COTSProjMgrFile::SetSampleList(COTSSamplesList& 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
- for (auto pSample : a_listSample)
- {
- // add the new sample into sample list
- m_listSamples.push_back(pSample);
- }
- return true;
- }
- COTSSamplePtr COTSProjMgrFile::GetSampleByIndex(int a_nIndex)
- {
- // safe check
- if (a_nIndex < 0 || a_nIndex >= (int)m_listSamples.size())
- {
- // invalid sample id
- LogErrorTrace(__FILE__, __LINE__, _T("GetSample: invalid sample id."));
- return nullptr;
- }
- // get the matching sample
- COTSSamplePtr pSample = m_listSamples[a_nIndex];
- // return the sample
- return pSample;
- }
- COTSSamplePtr COTSProjMgrFile::GetSampleByName(CString a_strSampleName)
- {
- // find the name matching sample
- auto itr = std::find_if(m_listSamples.begin(), m_listSamples.end(), [a_strSampleName](COTSSamplePtr p) { return p->GetName().CompareNoCase(a_strSampleName) == 0; });
- // get the matching sample if found
- COTSSamplePtr pSample = nullptr;
- if (itr != m_listSamples.end())
- {
- pSample = *itr;
- }
- // return the sample
- return pSample;
- }
- COTSSamplePtr COTSProjMgrFile::AddSample(CString 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
- LogErrorTrace(__FILE__, __LINE__, _T("AddSample: invalid file."));
- return nullptr;
- }
- // get new sample name
- CString strNewSampleName = GetNewSampleName();
- // make sure the new sample name is not an empty string
- strNewSampleName.Trim();
- //判断当前文件夹下是否有新的文件 有就删除
- DeleteSampleFiles(strNewSampleName);
-
- // get a suitable sample hole for the new sample
- CHolePtr pHole = SelectASmpleHole(a_strHoleName);
- // check the sample hole
- if (!pHole)
- {
- // failed to get sample hole for the new sample
- LogErrorTrace(__FILE__, __LINE__, _T("AddSample: failed to get sample hole for the new sample."));
- return nullptr;
- }
- // particle analysis STD lib
- CPartSTDDataPtr pPartSTDDataPtr = m_pGenParam->GetPartSTDLib();
- // measure data parameters containing particle analysis std, image scan parameter, image process parameter and x-ray parameter
- CMsrParamsPtr poMsrParams = CMsrParamsPtr(new CMsrParams());
- STEEL_TECHNOLOGY a_nVal = (STEEL_TECHNOLOGY)m_pGenParam->GetSteelTechnology();
- poMsrParams->SetSteelTechnology(a_nVal);
- poMsrParams->SetPartSTDData(pPartSTDDataPtr);
- poMsrParams->SetImageScanParam(m_pImageScanParam);
- poMsrParams->SetImageProcessParam(m_pImageProcParam);
- poMsrParams->SetXRayParam(m_pXRayParam);
- // measurement area
- //CDomainPtr pMsrArea = CalculateMsrArea(pHole);
- CDomainPtr pMsrArea = CalculateDefaultArea(pHole);
- // create a sample
- COTSSamplePtr pSample = COTSSamplePtr(new COTSSample());
- // set sample parameters
- pSample->SetName(strNewSampleName);
- pSample->SetSampleHoleName(pHole->GetName());
- pSample->SetSwitch(m_pGenParam->GetMeasurementSwitch());
- pSample->SetMsrParams(poMsrParams);
- pSample->SetMsrArea(pMsrArea);
- // add the new sample into the samples list
- m_listSamples.push_back(pSample);
- // set the project file modified.
- SetModify();
- // set the new as working sample
- m_nWorkingSampeIndex = (int)m_listSamples.size() - 1;
- // return the new sample
- return pSample;
- }
- //2020-7-30 张佳鑫
- BOOL COTSProjMgrFile::DeleteSampleFiles(CString a_nString)
- {
- CString strSamplePath = COTSHelper::GetFolderName(m_strPathName); //m_strPathName + _T("\\") + m_listSamples[a_nIndex]->GetName();
- // this sample has been measured, need to delete all the measure result files.
- if (COTSFileSys::IsFolder(strSamplePath))
- {
- strSamplePath = strSamplePath + _T("\\") + a_nString;
- CString strSampleFieldPath = strSamplePath + _T("\\") + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER;
- if (!COTSFileSys::DeleteAllFiles(strSampleFieldPath))
- {
- return FALSE;
- }
- SetFileAttributes(strSampleFieldPath, FILE_ATTRIBUTE_NORMAL); //设置文件夹的属性
- RemoveDirectory(strSampleFieldPath); //删除文件夹
- if (!COTSFileSys::DeleteAllFiles(strSamplePath))
- {
- return FALSE;
- }
- SetFileAttributes(strSamplePath, FILE_ATTRIBUTE_NORMAL); //设置文件夹的属性
- RemoveDirectory(strSamplePath); //删除文件夹
-
- }
- }
- BOOL COTSProjMgrFile::DeleteSampleByIndex(int a_nIndex)
- {
- // find the sample's result file
- CString strSamplePath = COTSHelper::GetFolderName(m_strPathName); //m_strPathName + _T("\\") + m_listSamples[a_nIndex]->GetName();
- // this sample has been measured, need to delete all the measure result files.
- if(COTSFileSys::IsFolder(strSamplePath))
- {
- strSamplePath = strSamplePath + _T("\\") + m_listSamples[a_nIndex]->GetName();
- CString strSampleFieldPath = strSamplePath + _T("\\") + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER;
- if (!COTSFileSys::DeleteAllFiles(strSampleFieldPath))
- {
- return FALSE;
- }
- SetFileAttributes(strSampleFieldPath, FILE_ATTRIBUTE_NORMAL); //设置文件夹的属性
- RemoveDirectory(strSampleFieldPath); //删除文件夹
- if (!COTSFileSys::DeleteAllFiles(strSamplePath))
- {
- return FALSE;
- }
- SetFileAttributes(strSamplePath, FILE_ATTRIBUTE_NORMAL); //设置文件夹的属性
- RemoveDirectory(strSamplePath); //删除文件夹
- }
- // check the index
- if (a_nIndex < 0 || a_nIndex >= (int)m_listSamples.size())
- {
- // invalid input sample index
- LogErrorTrace(__FILE__, __LINE__, _T("DeleteSampleByIndex::input sample index"));
- return FALSE;
- }
- // 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.size() - 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
- m_listSamples.erase(m_listSamples.begin() + a_nIndex);
- // the file is modified.
- SetModify();
- // reset working sample index
- m_nWorkingSampeIndex = nNewWorkingSampeIndex;
- // ok, return TRUE
- return TRUE;
- }
- BOOL COTSProjMgrFile::DeleteSampleByName(CString a_strSampleName)
- {
- // check input sample name
- a_strSampleName.Trim();
- if (a_strSampleName.IsEmpty())
- {
- // input sample name is empty
- LogErrorTrace(__FILE__, __LINE__, _T("DeleteSampleByName: input sample name is an empty string."));
- return FALSE;
- }
- // go through sample list
- int nIndex = 0;
- for (auto pSample : m_listSamples)
- {
- // return TRUE if this is not an exclude sample and its name is same with input
- CString strSampleName = pSample->GetName();
- if (strSampleName.CompareNoCase(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;
- }
- BOOL COTSProjMgrFile::SameNameInList(CString a_strSampleName, int a_nExclude /*= -1*/)
- {
- // make sure the input sample name is not empty
- a_strSampleName.Trim();
- if (a_strSampleName.IsEmpty())
- {
- // shouldn't happen, input name is an empty string
- LogErrorTrace(__FILE__, __LINE__, _T("SameNameInList: input name is an empty string."));
- return FALSE;
- }
- // go through sample list
- int nIndex = 0;
- for (auto pSample : m_listSamples)
- {
- // return TRUE if this is not an exclude sample and its name is same with input
- CString strSampleName = pSample->GetName();
- if (nIndex != a_nExclude && strSampleName.CompareNoCase(a_strSampleName) == 0)
- {
- // find a same name sample
- return TRUE;
- }
- ++nIndex;
- }
- // no, same name sample in the same list, return FALSE
- return FALSE;
- }
- BOOL COTSProjMgrFile::ResetSamplesListOrder(std::vector<CString> a_listSampleNames)
- {
- // no sample in the samples list; shouldn't be here
- if (m_listSamples.size() == 0)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ResetSamplesListOrder: no sample in samples list."));
- return FALSE;
- }
- // make sure that input sample names list size is same with the samples list
- if (m_listSamples.size() != a_listSampleNames.size())
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ResetSamplesListOrder: sample names list has different size with the samples list."));
- return FALSE;
- }
- // new sample list
- COTSSamplesList listSamples;
- // go through the sample names list
- for (auto strSampleName : a_listSampleNames)
- {
- // find the sample
- auto 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
- LogErrorTrace(__FILE__, __LINE__, _T("ResetSamplesListOrder: failed to find the sample (%s)."), strSampleName);
- return FALSE;
- }
- // add the sample into the new list
- listSamples.push_back(*itr);
- }
- // reset the samples list
- m_listSamples.clear();
- for (auto pSample : listSamples)
- {
- m_listSamples.push_back(pSample);
- }
- // set modify flag
- SetModify();
- // Ok, return TRUE
- return TRUE;
- }
- BOOL COTSProjMgrFile::InsrtSample(COTSSamplePtr a_pSample, int a_nIndex)
- {
- // input check
- ASSERT(a_pSample);
- if (!a_pSample)
- {
- // invalid input sample pointer
- LogErrorTrace(__FILE__, __LINE__, _T("InsrtSample: invalid input sample pointer."));
- return FALSE;
- }
- if (m_listSamples.size() == 0 || a_nIndex >= (int)m_listSamples.size())
- {
- m_listSamples.push_back(a_pSample);
- }
- else if (a_nIndex <= 0)
- {
- m_listSamples.insert(m_listSamples.begin(), a_pSample);
- }
- else
- {
- m_listSamples.insert(m_listSamples.begin() + a_nIndex, a_pSample);
- }
- // Ok, return TRUE
- return TRUE;
- }
- BOOL COTSProjMgrFile::ChangeSamplePosition(int a_nIndexFrom, int a_nIndexTo)
- {
- // make sure both index are valid
- if (a_nIndexFrom < 0 || a_nIndexFrom >= (int)m_listSamples.size())
- {
- // invalid from index
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSamplePosition: invalid from index."));
- return FALSE;
- }
- if (a_nIndexTo < 0 || a_nIndexTo >= (int)m_listSamples.size())
- {
- // invalid to index
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSamplePosition: 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.size() - 1));
- // get the sample
- COTSSamplePtr pSample = m_listSamples.at(a_nIndexFrom);
- // remove it from the samples list
- m_listSamples.erase(m_listSamples.begin() + a_nIndexFrom);
- // put the sample back in
- if (bLast)
- {
- m_listSamples.push_back(pSample);
- }
- else
- {
- m_listSamples.insert(m_listSamples.begin() + a_nIndexTo, pSample);
- }
- }
- // Ok, return TRUE
- return TRUE;
- }
- BOOL COTSProjMgrFile::MoveSamplePosition(COTSSamplePtr a_pTargetSample, COTSSamplePtr a_RefpSample, BOOL a_bBefore /*= TRUE*/)
- {
- // check input
- ASSERT(a_pTargetSample);
- if (!a_pTargetSample)
- {
- // invalid input target sample pointer
- LogErrorTrace(__FILE__, __LINE__, _T("MoveSamplePosition: invalid input target sample pointer."));
- return FALSE;
- }
- ASSERT(a_RefpSample);
- if (!a_RefpSample)
- {
- // invalid input ref sample pointer
- LogErrorTrace(__FILE__, __LINE__, _T("MoveSamplePosition: invalid input ref sample pointer."));
- return FALSE;
- }
- auto itrTarget = std::find(m_listSamples.begin(), m_listSamples.end(), a_pTargetSample);
- if (itrTarget == m_listSamples.end())
- {
- // target sample in not in the samples list
- LogErrorTrace(__FILE__, __LINE__, _T("MoveSamplePosition: target sample in not in the samples list."));
- return FALSE;
- }
- auto itrRef = std::find(m_listSamples.begin(), m_listSamples.end(), a_RefpSample);
- if (itrRef == m_listSamples.end())
- {
- // ref sample in not in the samples list
- LogErrorTrace(__FILE__, __LINE__, _T("MoveSamplePosition: ref sample in not in the samples list."));
- return FALSE;
- }
- // need to do nothing if the two sample are same
- if (itrTarget != itrRef)
- {
- // remove the sample from the samples list
- m_listSamples.erase(itrTarget);
- // find ref sample position again
- itrRef = std::find(m_listSamples.begin(), m_listSamples.end(), a_RefpSample);
- if (itrRef == m_listSamples.end())
- {
- // shouldn't happen, ref sample in not in the samples list
- LogErrorTrace(__FILE__, __LINE__, _T("MoveSamplePosition: ref sample in not in the samples list."));
- return FALSE;
- }
- // put the sample back in
- if (a_bBefore)
- {
- m_listSamples.insert(itrRef, a_pTargetSample);
- }
- else
- {
- m_listSamples.insert(itrRef + 1, a_pTargetSample);
- }
- }
- // Ok, return TRUE
- return TRUE;
- }
- BOOL COTSProjMgrFile::MoveSamplePosition(CString a_strTargetSampleName, CString a_strRefSampleName, BOOL a_bBefore /*= TRUE*/)
- {
- // input check
- a_strTargetSampleName.Trim();
- if (a_strTargetSampleName.IsEmpty())
- {
- // input target sample is an empty string
- LogErrorTrace(__FILE__, __LINE__, _T("MoveSamplePosition: input target sample is an empty string."));
- return FALSE;
- }
- a_strRefSampleName.Trim();
- if (a_strRefSampleName.IsEmpty())
- {
- // input ref sample is an empty string
- LogErrorTrace(__FILE__, __LINE__, _T("MoveSamplePosition: input ref sample is an empty string."));
- return FALSE;
- }
- auto 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
- LogErrorTrace(__FILE__, __LINE__, _T("MoveSamplePosition: target sample is not the name of any sample in the samples list."));
- return FALSE;
- }
- COTSSamplePtr pTargetSample = *itr;
- 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
- LogErrorTrace(__FILE__, __LINE__, _T("MoveSamplePosition: ref sample is not the name of any sample in the samples list."));
- return FALSE;
- }
- COTSSamplePtr pRefSample = *itr;
- // need to do nothing if the two name are same
- if (a_strTargetSampleName.CompareNoCase(a_strRefSampleName) != 0)
- {
- return MoveSamplePosition(pTargetSample, pRefSample, a_bBefore);
- }
- // Ok, return TRUE
- return TRUE;
- }
- // working sample
- COTSSamplePtr COTSProjMgrFile::GetWorkingSample()
- {
- // check if the working sample index
- if ( m_nWorkingSampeIndex < 0 || m_nWorkingSampeIndex >= (int)m_listSamples.size())
- {
- // invalid working sample index
- return nullptr;
- }
- return GetSampleByIndex(m_nWorkingSampeIndex);
- }
- BOOL COTSProjMgrFile::SetWorkingSampleByIndex(int a_nIndex)
- {
- // special treatment
- if (a_nIndex == -1 && m_listSamples.size() == 0)
- {
- m_nWorkingSampeIndex = -1;
- return TRUE;
- }
- // check if the working sample index
- if (0 > a_nIndex || a_nIndex >= (int)m_listSamples.size())
- {
- // invalid sample index
- return FALSE;
- }
- m_nWorkingSampeIndex = a_nIndex;
- return TRUE;
- }
- BOOL COTSProjMgrFile::SetWorkingSampleByName(CString a_pSampleName)
- {
- // check input sample name
- a_pSampleName.Trim();
- if (a_pSampleName.IsEmpty())
- {
- // input sample name is empty
- LogErrorTrace(__FILE__, __LINE__, _T("SetWorkingSampleByName: input sample name is an empty string."));
- return FALSE;
- }
- // go through sample list
- int nIndex = 0;
- for (auto pSample : m_listSamples)
- {
- // return TRUE if this is not an exclude sample and its name is same with input
- CString strSampleName = pSample->GetName();
- if (strSampleName.CompareNoCase(a_pSampleName) == 0)
- {
- // find the sample, return deleting result
- return SetWorkingSampleByIndex(nIndex);
- }
- ++nIndex;
- }
- // failed to find the named sample
- LogErrorTrace(__FILE__, __LINE__, _T("SetWorkingSampleByName: failed to find the named sample."));
- // failed to find the named sample return FALSE
- return FALSE;
- }
- BOOL COTSProjMgrFile::DeleteWorkingSample()
- {
- // check if the working sample index
- if (m_nWorkingSampeIndex < 0 || m_nWorkingSampeIndex >= (int)m_listSamples.size())
- {
- // invalid working sample index
- return FALSE;
- }
- // return the result of DeleteSampleByIndex
- return DeleteSampleByIndex(m_nWorkingSampeIndex);
- }
- // hole BSE images list
- void COTSProjMgrFile::SetHoleBESImgList(CHoleBSEImgsList& a_listHoleBSEImg, BOOL a_bClear/* = TRUE*/)
- {
- // clear the hole BSE image list if necessary
- if (a_bClear)
- {
- m_listHoleBSEImg.clear();
- }
- // go through the input list
- for (auto pHoleBSEImg : a_listHoleBSEImg)
- {
- // create a hole BSE image copy
- CHoleBSEImgPtr pHoleBSEImgNew(new CHoleBSEImg(pHoleBSEImg.get()));
- // add the new hole BSE image into HoleBSEImage list
- m_listHoleBSEImg.push_back(pHoleBSEImgNew);
- }
- if (m_nWorkingSampeIndex != -1)
- {
- COTSSamplePtr pSample = GetWorkingSample();
- pSample->SetPropItemGrps();
- }
- }
- // samples list
- bool COTSProjMgrFile::SetSysSTDItem(CSTDItemsList& a_listSysSTDItem, BOOL a_bClear/* = TRUE*/)
- {
- // clear samples list if necessary
- if (a_bClear)
- {
- m_listSysSTDItem.clear();
- }
- // go through the sample list of the source
- for (auto pItem : a_listSysSTDItem)
- {
- // create a sample copy
- //CSTDItemPtr pItemNew(new CSTDItem(*pItem.get()));
- // add the new sample into sample list
- m_listSysSTDItem.push_back(pItem);
- }
-
- return true;
- }
- // file name
- CString COTSProjMgrFile::GetFileName()
- {
- // make a copy of file path name
- CString strPathName = m_strPathName;
- // is this a new file?
- strPathName.Trim();
- if (strPathName.CompareNoCase(UNTITLED_FILE_NAME) == 0)
- {
- return strPathName;
- }
- // get file name
- CString strFileName = COTSHelper::GetFileNameWithoutExtension(strPathName);
- strFileName = COTSHelper::GetFileName(strFileName);
- // return file name
- return strFileName;
- }
- // if the new sample name can be used.
- BOOL COTSProjMgrFile::IsValidSampleName(CString a_sName)
- {
- int nindex = -1;
- for (auto pSample : m_listSamples)
- {
- nindex++;
- CString sSampleName = pSample->GetName();
- if (!a_sName.CompareNoCase(sSampleName))
- {
- if (nindex != m_nWorkingSampeIndex)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("This name has been used."));
- 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.
- BOOL COTSProjMgrFile::GetParamFileList(int& a_nPos, std::vector<CString>& a_listParamFileName)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // get folder name from general GetParamFileListparameter.
- ASSERT(m_pGenParam);
- if (!m_pGenParam)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("GetSTDFileList: Can't find the folder."));
- return false;
- }
- CString a_strFolderName = m_pGenParam->GetMsrParamFileFolderName();
- if (a_strFolderName == _T(""))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("GetSTDFileList: empty folder name."));
- return false;
- }
- // lib name list
- a_listParamFileName.clear();
- // file list
- std::vector<CString> listParamFile;
- listParamFile.clear();
- // get file list
- if (!COTSHelper::GetFileNameList(a_strFolderName, MESUREMENT_PARAM_FILE_EXT, listParamFile))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("GetSTDFileList::There is no %s file in the folder %s"), STD_FILE_EXT, a_strFolderName);
- return FALSE;
- }
- a_nPos = -1;
- // the first postion is default value
- CString sDefault;
- sDefault= MultiLang::GetInstance().GetCStringByKey(IDS_DEFAULT);
- a_listParamFileName.push_back(sDefault);
- // get the param
- CMsrParamFileMgrPtr pParamMrg = CMsrParamFileMgrPtr(new CMsrParamFileMrg());
- // get current param
- CMsrParamsPtr pCurrentParam = CMsrParamsPtr(new CMsrParams());
- COTSSamplePtr pSample = GetWorkingSample();
- if (pSample == nullptr)
- {
- LogTrace(__FILE__, __LINE__, _T("GetParamFileList: failed to get working sample."));
- }
- else
- {
- pCurrentParam = pSample->GetMsrParams();
- if (pCurrentParam == nullptr)
- {
- LogTrace(__FILE__, __LINE__, _T("GetParamFileList: failed to get working sample's param."));
- }
- else
- {
-
- if ((*(pCurrentParam->GetPartSTDData().get()) == *(m_pGenParam->GetPartSTDLib().get()))
- && (*(pCurrentParam->GetImageProcessParam().get()) == *(m_pImageProcParam.get()))
- && (*(pCurrentParam->GetImageScanParam().get()) == *(m_pImageScanParam.get()))
- && (*(pCurrentParam->GetXRayParam().get()) == *(m_pXRayParam.get())))
- {
- a_nPos = 0;
- }
- }
- }
- int index = -1;
- for (auto sPathName : listParamFile)
- {
- // get file name
- CString strFileName = COTSHelper::GetFileNameWithoutExtension(sPathName);
- strFileName = COTSHelper::GetFileName(strFileName);
-
- index++;
- //compare which param is used in the list
- CString sParamFileName = listParamFile[index];
- if (sParamFileName.IsEmpty())
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList::wrong param file name."));
- return FALSE;
- }
- //load STD
- CString sPathName = a_strFolderName + sParamFileName;
- if (!pParamMrg->Load(sPathName))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList::can't load param."));
- return FALSE;
- }
- CMsrParamsPtr pNewParam = pParamMrg->GetMsrParams();
- if (*pNewParam.get() == *pCurrentParam.get())
- {
- a_nPos = (index+1);
- }
- a_listParamFileName.push_back(strFileName);
- }
- return TRUE;
- }
- // change param from file
- BOOL COTSProjMgrFile::ChangeParamFromList(int a_nPos)
- {
- // get folder name from general parameter.
- ASSERT(m_pGenParam);
- if (!m_pGenParam)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("GetSTDFileList: Can't find the folder."));
- return false;
- }
- CString a_strFolderName = m_pGenParam->GetMsrParamFileFolderName();
- if (a_strFolderName == _T(""))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("GetSTDFileList: empty folder name."));
- return false;
- }
- // file list
- std::vector<CString> listParamFile;
- listParamFile.clear();
- // get file list
- if (!COTSHelper::GetFileNameList(a_strFolderName, MESUREMENT_PARAM_FILE_EXT, listParamFile))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("GetSTDFileList::There is no %s file in the folder %s"), STD_FILE_EXT, a_strFolderName);
- return FALSE;
- }
- // check the pos if is valid
- CMsrParamsPtr pNewParam = CMsrParamsPtr(new CMsrParams());
- int nSize = (int)listParamFile.size();
- if(a_nPos == 0)
- {
- //set param to default value
- CPartSTDDataPtr pPartSTD = m_pGenParam->GetPartSTDLib();
- pNewParam->SetPartSTDData(pPartSTD);
- pNewParam->SetImageScanParam(m_pImageScanParam);
- pNewParam->SetImageProcessParam(m_pImageProcParam);
- pNewParam->SetXRayParam(m_pXRayParam);
- }
- else if (a_nPos < 0 || a_nPos >(nSize+1))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList::choose wrong position."));
- return FALSE;
- }
- else
- {
- // get the param
- CMsrParamFileMgrPtr pParamMrg = CMsrParamFileMgrPtr(new CMsrParamFileMrg());
- CString sParamFileName = listParamFile[a_nPos-1];
- if (sParamFileName.IsEmpty())
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList::wrong param file name."));
- return FALSE;
- }
- //load STD
- CString sPathName = a_strFolderName + sParamFileName;
- if (!pParamMrg->Load(sPathName))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList::can't load param."));
- return FALSE;
- }
- pNewParam = pParamMrg->GetMsrParams();
- ASSERT(pNewParam);
- if (!pNewParam)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList::load an empty param."));
- return FALSE;
- }
- }
- // updata STD to working sample
- COTSSamplePtr pSample = GetWorkingSample();
- ASSERT(pSample);
- if (!pSample)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList: failed to get working sample."));
- return FALSE;
- }
- pSample->SetMsrParams(pNewParam);
-
- return TRUE;
- }
- // get std file list, a_nPos = -1, current do not use any STD lib, a_nPos = 0, current use STD lib.
- BOOL COTSProjMgrFile::GetSTDFileList(int& a_nPos, std::vector<CString>& a_listSTDLibName)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // get folder name from general parameter.
- ASSERT(m_pGenParam);
- if (!m_pGenParam)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("GetSTDFileList: Can't find the folder."));
- return false;
- }
- CString a_strFolderName = m_pGenParam->GetPartSTDLibFolderName();
- if (a_strFolderName == _T(""))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("GetSTDFileList: empty folder name."));
- return false;
- }
-
- // lib name list
- a_listSTDLibName.clear();
- // file list
- std::vector<CString> listSTDFile;
- listSTDFile.clear();
- // get file list
- if (!COTSHelper::GetFileNameList(a_strFolderName, STD_FILE_EXT, listSTDFile))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("GetSTDFileList::There is no %s file in the folder %s"), STD_FILE_EXT, a_strFolderName);
- return FALSE;
- }
- //before the use choose one STD, always should be null.
- a_nPos = -1;
-
- // get folder's STD name.
- CPartSTDFileMnrPtr pPartSTDFileMnr = CPartSTDFileMnrPtr(new CSTDXMLFileMnr());
- // get current std
- CPartSTDDataPtr pCurrentSTD ;
- CMsrParamsPtr pCurrentParam ;
- COTSSamplePtr pSample = GetWorkingSample();
- if (pSample == nullptr)
- {
- LogTrace(__FILE__, __LINE__, _T("GetSTDFileList: failed to get working sample."));
- }
- else
- {
- pCurrentParam = pSample->GetMsrParams();
- if (pCurrentParam == nullptr)
- {
- LogTrace(__FILE__, __LINE__, _T("GetSTDFileList: failed to get working param."));
- }
- pCurrentSTD = pCurrentParam->GetPartSTDData();
- CString sDefault = pCurrentSTD->GetName();
- a_nPos = 0;
- a_listSTDLibName.push_back(sDefault);
- }
- // read file name
- int index = -1;
- for (auto sFileName : listSTDFile)
- {
- index++;
- // read the file
- CString sPathName = a_strFolderName + sFileName;
- if (!pPartSTDFileMnr->Load(sPathName))
- {
- LogTrace(__FILE__, __LINE__, _T("GetSTDFileList::There is no %s in the folder %s"), sFileName, a_strFolderName);
- return FALSE;
- }
- // get STDData from file
- CPartSTDDataPtr pPartSTDData = pPartSTDFileMnr->GetPartSTDData();
- ASSERT(pPartSTDData);
- if (!pPartSTDData)
- {
- LogTrace(__FILE__, __LINE__, _T("There is no %s in the folder %s"), sFileName, a_strFolderName);
- return FALSE;
- }
- if (*pCurrentSTD.get() == *pPartSTDData.get())
- {
- a_nPos = (index+1);
- }
- // get lib name
- CString sLibName = pPartSTDData->GetName();
-
- a_listSTDLibName.push_back(sLibName);
- }
-
- return TRUE;
- }
- // change STD
- BOOL COTSProjMgrFile::ChangeSTDFromList(int a_nPos)
- {
- // get folder name from general parameter.
- ASSERT(m_pGenParam);
- if (!m_pGenParam)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList: Can't find the folder."));
- return false;
- }
- CString a_strFolderName = m_pGenParam->GetPartSTDLibFolderName();
- if (a_strFolderName == _T(""))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList: empty folder name."));
- return false;
- }
-
- // file list
- std::vector<CString> listSTDFile;
- listSTDFile.clear();
- // get file list
- if (!COTSHelper::GetFileNameList(a_strFolderName, STD_FILE_EXT, listSTDFile))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList::There is no %s file in the folder %s"), STD_FILE_EXT, a_strFolderName);
- return FALSE;
- }
- // check the pos if is valid
- CPartSTDDataPtr pNewSTD = CPartSTDDataPtr(new CPartSTDData());
- int nSize = (int)listSTDFile.size();
- if (a_nPos == 0)
- {
- pNewSTD = m_pGenParam->GetPartSTDLib();
- }
- else if (a_nPos < 0 || a_nPos > nSize)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList::choose wrong position."));
- return FALSE;
- }
- else
- {
- // get the STD
- CPartSTDFileMnrPtr pSTDMnr = CPartSTDFileMnrPtr(new CSTDXMLFileMnr());
- CString sSTDFileName = listSTDFile[a_nPos-1];
- if (sSTDFileName.IsEmpty())
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList::wrong STD file name."));
- return FALSE;
- }
- //load STD
- CString sPathName = a_strFolderName + sSTDFileName;
- if (!pSTDMnr->Load(sPathName))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList::can't load STD."));
- return FALSE;
- }
- pNewSTD = pSTDMnr->GetPartSTDData();
- pNewSTD->SetName(sSTDFileName);
- ASSERT(pNewSTD);
- if (!pNewSTD)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList::load an empty STD."));
- return FALSE;
- }
- }
- // updata STD to working sample
- COTSSamplePtr pSample = GetWorkingSample();
- ASSERT(pSample);
- if (!pSample)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList: failed to get working sample."));
- return FALSE;
- }
- CMsrParamsPtr pParam = pSample->GetMsrParams();
- ASSERT(pParam);
- if (!pParam)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeSTDFromList: working sample's param is empty."));
- return FALSE;
- }
- pParam->SetPartSTDData(pNewSTD);
- pSample->SetMsrParams(pParam);
- return TRUE;
- }
- // get measured sample list
- BOOL COTSProjMgrFile::GetMsredSampleList(COTSSamplesList& a_listMsredSample)
- {
- a_listMsredSample.clear();
- for (auto pSample : m_listSamples)
- {
- if (*(pSample->GetMsrResults().get()) == CMsrResults())
- {
-
- continue;
- }
- else
- {
-
- a_listMsredSample.push_back(pSample);//the reference count will increament automatically.
- }
- }
- return TRUE;
- }
- // remove background
- BOOL COTSProjMgrFile::RemoveBackGround(CBSEImgPtr a_pImgIn, COTSImageProcessParamPtr a_pImgProcessParam, CBSEImgPtr a_pImgOut)
- {
- //safety check
- ASSERT(a_pImgIn);
- if (!a_pImgIn)
- {
- LogTrace(__FILE__, __LINE__, _T("RemoveBackGround: invalid input BSE."));
- return FALSE;
- }
- ASSERT(a_pImgProcessParam);
- if (!a_pImgProcessParam)
- {
- LogTrace(__FILE__, __LINE__, _T("RemoveBackGround: invalid image process param."));
- return FALSE;
- }
- ASSERT(a_pImgOut);
- if (!a_pImgOut)
- {
- LogTrace(__FILE__, __LINE__, _T("RemoveBackGround: invalid output BSE."));
- return FALSE;
- }
- // 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 = a_pImgProcessParam->GetBGGray().GetStart();
- long nBGEnd = a_pImgProcessParam->GetBGGray().GetEnd();
- long nPtStart = a_pImgProcessParam->GetParticleGray().GetStart();
- long nPtEnd = a_pImgProcessParam->GetParticleGray().GetEnd();
-
- // delete background
- for (int i = 0; i < nImgSize; i++)
- {
- if (pSrcImg[i] >= nBGStart && pSrcImg[i] <= nBGEnd)
- {
- pPixel[i] = 0;
- }
- else
- {
- pPixel[i] = 255;
- }
- }
-
- // image process
- COTSImageProcess::BErode3(pPixel, pTargetImg, 5, nHeight, nWidth);
- COTSImageProcess::BDilate3(pTargetImg, pPixel, 5, nHeight, nWidth);
- // show the image
- for (int i = 0; i < nImgSize; i++)
- {
- *(pPixel + i) = 255 - *(pPixel + i);
- if (*(pPixel + i) == 0)
- {
- *(pPixel + i) = *(pSrcImg + i);
- }
- }
- a_pImgOut->SetImageRect(a_pImgIn->GetImageRect());
- a_pImgOut->SetImageData(pPixel);
- // memory release
- delete[]pPixel;
- delete[]pTargetImg;
-
- return TRUE;
- }
-
- BOOL COTSProjMgrFile::GetSystemSTDLib(OTS_SOFT_PACKAGE_ID a_nPacketId)
- {
- CSTDFileMgrPtr pSTDFileMgr = CSTDFileMgrPtr(new CSTDFileMgr());
- // get software pack measure preference file pathname
- //CString SysSTDLibFilePath = COTSFileSys::GetOTSPackSysSTDLibFilePathName(a_nPacketId);
- //if (SysSTDLibFilePath.IsEmpty())
- //{
- // // shouldn't happen, software pack measure preference file pathname is empty, return nullptr
- // LogErrorTrace(__FILE__, __LINE__, _T("GetSystemSTDLib: failed to find program manager param file pathname."));
- // return FALSE;
- //}
- // program manager param file exists?
- /*if (!COTSFileSys::Exists(SysSTDLibFilePath))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("GetSystemSTDLib: there is no STD lib file."));
- return FALSE;
- }*/
- CSTDItemsList listSTDItem = pSTDFileMgr->GetSTDItemList();
- if (listSTDItem.empty())
- {
- if (!pSTDFileMgr->Load( TRUE))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("GetSystemSTDLib: can't load system STD lib data."));
- return FALSE;
- }
- }
- SetSysSTDItem(listSTDItem, TRUE);
- return TRUE;
- }
- // protected
-
- // cleanup
- void COTSProjMgrFile::Cleanup()
- {
- m_listHoleBSEImg.clear();
- m_listSamples.clear();
- m_listSysSTDItem.clear();
- m_bModify = FALSE;
- m_strPathName = _T("");
- m_nWorkingSampeIndex = -1;
- }
- // initialization
- void COTSProjMgrFile::Init()
- {
- m_pSEMStageData = CSEMStageDataPtr(new CSEMStageData());
- m_pStage = CStagePtr(new CStage());
- m_pGenParam = COTSGeneralParametersPtr(new COTSGeneralParameters());
- m_pImageScanParam = COTSImageScanParamPtr(new COTSImageScanParam());
- m_pImageProcParam = COTSImageProcessParamPtr(new COTSImageProcessParam());
- m_pXRayParam = COTSXRayParamPtr(new COTSXRayParam());
-
- m_listSamples.clear();
- m_listHoleBSEImg.clear();
- m_listSysSTDItem.clear();
- m_bModify = FALSE;
- m_strPathName = _T("");
- m_nWorkingSampeIndex = -1;
- }
- // duplication
- void COTSProjMgrFile::Duplicate(const COTSProjMgrFile& a_oSource)
- {
- // initialization
- Init();
- // copy data over
- m_pSEMStageData = CSEMStageDataPtr(new CSEMStageData( a_oSource.m_pSEMStageData.get()));
- m_pStage = CStagePtr(new CStage(a_oSource.m_pStage.get()));
- m_pGenParam = COTSGeneralParametersPtr(new COTSGeneralParameters( a_oSource.m_pGenParam.get()));
- m_pImageScanParam = COTSImageScanParamPtr(new COTSImageScanParam( a_oSource.m_pImageScanParam.get()));
- m_pImageProcParam = COTSImageProcessParamPtr(new COTSImageProcessParam(a_oSource.m_pImageProcParam.get()));
- m_pXRayParam = COTSXRayParamPtr(new COTSXRayParam(a_oSource.m_pXRayParam.get()));
- for (auto pHoleBSEImg : a_oSource.m_listHoleBSEImg)
- {
- CHoleBSEImgPtr pHoleBSEImgNew(new CHoleBSEImg(pHoleBSEImg.get()));
- m_listHoleBSEImg.push_back(pHoleBSEImgNew);
- }
- for (auto pSample : a_oSource.m_listSamples)
- {
- COTSSamplePtr pSampleNew(new COTSSample(pSample.get()));
- m_listSamples.push_back(pSampleNew);
- }
- for (auto pItem : a_oSource.m_listSysSTDItem)
- {
- CSTDItemPtr pItemNew = CSTDItemPtr(new CSTDItem(*pItem.get()));
- m_listSysSTDItem.push_back(pItemNew);
- }
- m_bModify = a_oSource.m_bModify;
- m_strPathName = a_oSource.m_strPathName;
- m_nWorkingSampeIndex = a_oSource.m_nWorkingSampeIndex;
- }
- // get new sample name
- CString COTSProjMgrFile::GetNewSampleName()
- {
- // new sample name
- CString strNewSmplName = _T("");
- // safety check
- ASSERT(m_pGenParam);
- if (!m_pGenParam)
- {
- // shouldn't happen, invalid general parameter pointer.
- LogErrorTrace(__FILE__, __LINE__, _T("GetNewSampleName: invalid general parameter pointer."));
- return strNewSmplName;
- }
- // new sample name base
- CString strNewSmplNameBase = m_pGenParam->GetSampleName() + _T("%d");
- int nIndex = 1;
- do
- {
- // new sample name is new sample name base + number string
- strNewSmplName.Format(strNewSmplNameBase, nIndex);
- ++nIndex;
- }
- // make sure that the new sample name is not same with any sample in the samples list
- while (SameNameInList(strNewSmplName));
- // new sample name
- return strNewSmplName;
- }
- // select a suitable sample hole for a new sample
- CHolePtr COTSProjMgrFile::SelectASmpleHole(CString a_strHoleName /*= _T("")*/)
- {
- // safety check
- ASSERT(m_pStage);
- if (!m_pStage)
- {
- // shouldn't happen, invalid stage pointer.
- LogErrorTrace(__FILE__, __LINE__, _T("COTSProjMgrFile: invalid stage pointer."));
- return nullptr;
- }
- // get holes list of the stage
- CHolesList& listHoles = m_pStage->GetHoleList();
- // make sure the holes list is not empty
- if (listHoles.size() == 0)
- {
- // shouldn't happen, stage have no hole.
- LogErrorTrace(__FILE__, __LINE__, _T("COTSProjMgrFile: stage have no hole."));
- return nullptr;
- }
- // check the input hole name
- a_strHoleName.Trim();
- if (!a_strHoleName.IsEmpty())
- {
- // try to find matched hole
- auto itr = std::find_if(listHoles.begin(), listHoles.end(), [a_strHoleName](CHolePtr p) { return p->GetName().CompareNoCase(a_strHoleName) == 0; });
- if (itr != listHoles.end())
- {
- // found the matched hole, return its pointer
- CHolePtr pHole = *itr;
- return pHole;
- }
- }
- // can't find a matched hole, then pick the first empty hole
- // go through the holes list
- for (auto pHole : listHoles)
- {
- // has this hole any sample in it?
- CString strHoleName = pHole->GetName();
- auto itr = find_if(m_listSamples.begin(), m_listSamples.end(), [strHoleName](COTSSamplePtr p) { return p->GetSampleHoleName().CompareNoCase(strHoleName) == 0; });
- if (itr == m_listSamples.end())
- {
- // this hole has no sample in it
- return pHole;
- }
- }
- // no empty hole, then the first hole will be the one
- return listHoles[0];
- }
- // calculate measurement area
- CDomainPtr COTSProjMgrFile::CalculateMsrArea(CHolePtr a_pHole)
- {
- // safety check
- ASSERT(a_pHole);
- if (!a_pHole)
- {
- // input hole invalid.
- LogErrorTrace(__FILE__, __LINE__, _T("CalculateMsrArea: input hole invalid."));
- return nullptr;
- }
- CDomainPtr pMsrArea = CDomainPtr(new CDomain(a_pHole->GetShape(), a_pHole->GetDomainRect()));
- // create measurement area
- // reset measurement area
- // measurement area should smaller than the sample hole
- CRect rectMsrArea = pMsrArea->GetDomainRect();
- int nWidth = rectMsrArea.Width();
- int nHeight = rectMsrArea.Height();
- int nDeflateX = CalculateDeflateValue(nWidth);
- int nDeflateY = CalculateDeflateValue(nHeight);
- rectMsrArea.DeflateRect(nDeflateX, nDeflateY);
- pMsrArea->SetDomainRect(rectMsrArea);
- // return measurement area
- return pMsrArea;
- }
- CDomainPtr COTSProjMgrFile::CalculateDefaultArea(CHolePtr a_pHole)
- {
- // safety check
- ASSERT(m_pGenParam);
- if (!m_pGenParam)
- {
- // input hole invalid.
- LogErrorTrace(__FILE__, __LINE__, _T("CalculateDefaultArea: input invalid."));
- return nullptr;
- }
- ASSERT(a_pHole);
- if (!a_pHole)
- {
- // input hole invalid.
- LogErrorTrace(__FILE__, __LINE__, _T("CalculateDefaultArea: input hole invalid."));
- return nullptr;
- }
- CRect rectHole = a_pHole->GetDomainRect();
- CPoint ptCenter = rectHole.CenterPoint();
- DOMAIN_SHAPE nShape = m_pGenParam->GetShape();
- double dArea = m_pGenParam->GetArea() * 1000000;
- CPoint ptLeftTop;
- CPoint ptRightBottom;
- int nEdge = 0;
- int nRadius = 0;
- switch ((int)nShape)
- {
- case (int)DOMAIN_SHAPE::RECTANGLE:
- nEdge = (int)sqrt(dArea) / 2;
- ptLeftTop.x = ptCenter.x - nEdge;
- ptLeftTop.y = ptCenter.y - nEdge;
- ptRightBottom.x = ptCenter.x + nEdge;
- ptRightBottom.y = ptCenter.y + nEdge;
- break;
- case (int)DOMAIN_SHAPE::ROUND:
- nRadius = (int)sqrt(dArea / 3.1415926);
- ptLeftTop.x = ptCenter.x - nRadius;
- ptLeftTop.y = ptCenter.y - nRadius;
- ptRightBottom.x = ptCenter.x + nRadius;
- ptRightBottom.y = ptCenter.y + nRadius;
- break;
- }
- CRect MsrRect = CRect(ptLeftTop, ptRightBottom);
- CDomainPtr pMsrArea = CDomainPtr(new CDomain(nShape, MsrRect));
- // return measurement area
- return pMsrArea;
- }
- // calculate deflate value
- int COTSProjMgrFile::CalculateDeflateValue(int a_nWitchOrHeight)
- {
- // 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;
- }
- }
|