| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794 |
- #include "stdafx.h"
- #include "PartSizeFileMgr.h"
- #include "OTSFileSys.h"
- #include "OTSHelper.h"
- namespace OTSMODEL {
- using namespace OTSDATA;
- // CPartSTDFileMnr
- // constructor
- CPartSizeFileMgr::CPartSizeFileMgr()
- {
- // initialization
- Init();
- }
- // copy constructor
- CPartSizeFileMgr::CPartSizeFileMgr(const CPartSizeFileMgr& a_oSource)
- {
- // can't copy itself
- if (&a_oSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(a_oSource);
- }
- // copy constructor
- CPartSizeFileMgr::CPartSizeFileMgr(CPartSizeFileMgr* a_poSource)
- {
- // can't copy itself
- if (a_poSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(*a_poSource);
- }
- // =operator
- CPartSizeFileMgr& CPartSizeFileMgr::operator=(const CPartSizeFileMgr& a_oSource)
- {
- // cleanup
- Cleanup();
- // copy the class data over
- Duplicate(a_oSource);
- // return class
- return *this;
- }
- // ==operator
- BOOL CPartSizeFileMgr::operator==(const CPartSizeFileMgr& a_oSource)
- {
- // members
- return *(m_poPartSizeFile.get()) == *(a_oSource.m_poPartSizeFile.get());
- }
- // destructor
- CPartSizeFileMgr::~CPartSizeFileMgr()
- {
- // cleanup
- Cleanup();
- }
- // public
- //LoadAll/SaveAll
- BOOL CPartSizeFileMgr::LoadAll(CString a_strPathName /*= _T("")*/, BOOL a_bClear /*= TRUE*/)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // clear all data if necessary
- if (a_bClear)
- {
- Init();
- }
- // check file pathname
- a_strPathName.Trim();
- if (a_strPathName.IsEmpty())
- {
- // file open dialog
- CFileDialog dlg(TRUE, PART_SIZE_FILE_EXT, NULL, OFN_FILEMUSTEXIST, TEXTAPTF_FILE_FILTER);
- if (dlg.DoModal() != IDOK)
- {
- return FALSE;
- }
- // get file pathname
- a_strPathName = dlg.GetPathName();
- }
- int nLength = a_strPathName.GetLength();
- int nSeatt = a_strPathName.Find(TEXTFILE_FILE_EXT);
- int nSeatp = a_strPathName.Find(PART_SIZE_FILE_EXT);
- if (nSeatt > 0 && ((nLength - nSeatt) == FILE_SUFFIX_NUMBER))
- {
- LoadPartSizeFromTextFile(a_strPathName);
- }
- if (nSeatp > 0 && ((nLength - nSeatp) == FILE_SUFFIX_NUMBER))
- {
- Load(a_strPathName, a_bClear);
- }
- return true;
- }
- BOOL CPartSizeFileMgr::SaveAll(CString a_strPathName /*= _T("")*/, CString a_SizeName)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // check file pathname
- a_strPathName.Trim();
- if (a_strPathName.IsEmpty())
- {
- // file open dialog
- CFileDialog dlg(FALSE, PART_SIZE_FILE_EXT, NULL, OFN_OVERWRITEPROMPT, TEXTAPTF_FILE_FILTER);
- //CFileDialog dlg(TRUE, PART_SIZE_FILE_EXT, NULL, OFN_FILEMUSTEXIST, TEXTAPTF_FILE_FILTER);
- TCHAR _szPath[MAX_PATH + 1] = {0};
- GetModuleFileName(NULL,_szPath,MAX_PATH);
- (_tcsrchr(_szPath, _T('\\')))[1] = 0;//删除文件名,只获得路径字串
- CString strPath;
- for (int n = 0; _szPath[n];n++) {
- if (_szPath[n] != _T('\\')) {
- strPath += _szPath[n];
- }
- else {
- strPath += _T("\\");
- }
- }
- CString Suffix = "Config\\ProData";
- CString FinalPath = strPath + Suffix;
- dlg.m_ofn.lpstrInitialDir = FinalPath;
-
- TCHAR szBuffer[MAX_PATH] = { 0 };
- CString dd = a_SizeName; //"Sample1";
- _tcscpy(szBuffer, dd);
- dlg.m_ofn.lpstrFile = szBuffer;
- dlg.m_ofn.nMaxFile = sizeof(szBuffer) / sizeof(*szBuffer);
- if (dlg.DoModal() != IDOK)
- {
- return FALSE;
- }
- // get file pathname
- a_strPathName = dlg.GetPathName();
- }
- else {
- if (a_strPathName==".\\Config\\") {
- // file open dialog
- CFileDialog dlg(FALSE, PART_SIZE_FILE_EXT, NULL, OFN_OVERWRITEPROMPT, TEXTAPTF_FILE_FILTER);
- TCHAR _szPath[MAX_PATH + 1] = { 0 };
- GetModuleFileName(NULL, _szPath, MAX_PATH);
- (_tcsrchr(_szPath, _T('\\')))[1] = 0;//删除文件名,只获得路径字串
- CString strPath;
- for (int n = 0; _szPath[n]; n++) {
- if (_szPath[n] != _T('\\')) {
- strPath += _szPath[n];
- }
- else {
- strPath += _T("\\");
- }
- }
- CString Suffix = "Config\\ProData";
- CString FinalPath = strPath + Suffix;
- dlg.m_ofn.lpstrInitialDir = FinalPath;
- if (dlg.DoModal() != IDOK)
- {
- return FALSE;
- }
- // get file pathname
- a_strPathName = dlg.GetPathName();
- }
- else {
- CFileDialog dlg(FALSE, PART_SIZE_FILE_EXT, NULL, OFN_OVERWRITEPROMPT, TEXTAPTF_FILE_FILTER);
- dlg.m_ofn.lpstrInitialDir = a_strPathName;
- TCHAR szBuffer[MAX_PATH] = { 0 };
- CString dd = a_SizeName; //"Sample1";
- _tcscpy(szBuffer, dd);
- dlg.m_ofn.lpstrFile = szBuffer;
- dlg.m_ofn.nMaxFile = sizeof(szBuffer) / sizeof(*szBuffer);
-
- if (dlg.DoModal() != IDOK)
- {
- return FALSE;
- }
- // get file pathname
- a_strPathName = dlg.GetPathName();
- }
- }
-
- int nLength = a_strPathName.GetLength();
- int nSeatt = a_strPathName.Find(TEXTFILE_FILE_EXT);
- int nSeatp = a_strPathName.Find(PART_SIZE_FILE_EXT);
- if (nSeatt > 0 && ((nLength - nSeatt) == FILE_SUFFIX_NUMBER))
- {
- if (SavePartSizeTextFile(a_strPathName))
- {
- SetPathName(a_strPathName);
- }
- }
- else if (nSeatp > 0 && ((nLength - nSeatp) == FILE_SUFFIX_NUMBER))
- {
- if (Save(a_strPathName))
- {
- SetPathName(a_strPathName);
- }
- }
- return true;
- }
-
- // Load/Save
- BOOL CPartSizeFileMgr::Load(CString a_strPathName /*= _T("")*/, BOOL a_bClear /*= TRUE*/)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // clear all data if necessary
- if (a_bClear)
- {
- Init();
- }
- // check file pathname
- a_strPathName.Trim();
- if (a_strPathName.IsEmpty())
- {
- // file open dialog
- CFileDialog dlg(TRUE, PART_SIZE_FILE_EXT, NULL, OFN_FILEMUSTEXIST, PART_SIZE_FILE_FILTER);
- if (dlg.DoModal() != IDOK)
- {
- return FALSE;
- }
- // get file pathname
- a_strPathName = dlg.GetPathName();
- }
- // open the particle analysis standard file
- //CFile hFile;
- //CFileException ex;
- //if (!hFile.Open(a_strPathName, CFile::modeRead, &ex))
- //{
- // // failed to open the file
- // TCHAR szCause[255];
- // ex.GetErrorMessage(szCause, 255);
- // LogErrorTrace(__FILE__, __LINE__, _T("Load: can't open file %s. error: %s"), a_strPathName, szCause);
- // return FALSE;
- //}
- // create a new part size file point
- CPartSizeFilePtr poPartSizeFile = CPartSizeFilePtr(new CPartSizeFile());
- //// create a loading archive
- //CArchive ar(&hFile, CArchive::load);
- //poPartSizeFile->Serialize(ar);
- //// close the file
- //ar.Close();
- tinyxml2::XMLDocument doc;
- doc.LoadFile(a_strPathName);//载入xml文件
- tinyxml2::XMLElement *rootNode;
- rootNode = doc.FirstChildElement(RootClassName);
- poPartSizeFile->Serialize(false, &doc, rootNode);
- // file version
- CString strFileVersion = poPartSizeFile->GetVersion();
- DWORD nFileVersion = COTSHelper::GetVersionFromString(strFileVersion);
- if (nFileVersion == 0)
- {// invalid file
- LogErrorTrace(__FILE__, __LINE__, _T("Load: invalid particle size level file %s"), a_strPathName);
- return FALSE;
- }
- m_poPartSizeFile = poPartSizeFile;
- // file pathname
- m_strPathName = a_strPathName;
- // set file modify flag to FALSE
- m_bModify = FALSE;
- // ok, return TRUE
- return TRUE;
- }
- BOOL CPartSizeFileMgr::Save(CString a_strPathName /*= _T("")*/)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // check file pathname
- a_strPathName.Trim();
- if (a_strPathName.IsEmpty())
- {
- // file save as dialog
- CFileDialog dlg(FALSE, PART_SIZE_FILE_EXT, NULL, OFN_OVERWRITEPROMPT, PART_SIZE_FILE_FILTER);
- if (dlg.DoModal() != IDOK)
- {
- return FALSE;
- }
- // get file pathname
- a_strPathName = dlg.GetPathName();
- }
- // create the file
- //CFile hFile;
- //CFileException ex;
- //if (!hFile.Open(a_strPathName, CFile::modeCreate | CFile::modeWrite, &ex))
- //{
- // // failed to open file
- // TCHAR szCause[255];
- // ex.GetErrorMessage(szCause, 255);
- // LogErrorTrace(__FILE__, __LINE__, _T("Save: failed to create file. %s. error: %s"), a_strPathName, szCause);
- // return FALSE;
- //}
- // create a store archive
- //CArchive ar(&hFile, CArchive::store);
- // file serialization (store)
- //m_poPartSizeFile->Serialize(ar);
- //// close the file
- //ar.Close();
- //--------xml serialize-------
- tinyxml2::XMLDocument doc;
- doc.LoadFile(a_strPathName);//载入xml文件
- doc.Clear();
- tinyxml2::XMLDeclaration* declaration = doc.NewDeclaration();//添加xml文件头申明
- doc.InsertFirstChild(declaration);
- tinyxml2::XMLElement *rootNode;
- rootNode = doc.NewElement(RootClassName);
- doc.InsertEndChild(rootNode);
- m_poPartSizeFile->Serialize(true, &doc, rootNode);
- int result = doc.SaveFile(a_strPathName);
- //-----------------------------
- // file pathname
- m_strPathName = a_strPathName;
- // set file modify flag to FALSE
- m_bModify = FALSE;
- // ok, return TRUE
- return TRUE;
- }
- // load/save a part size from a text file
- BOOL CPartSizeFileMgr::LoadPartSizeFromTextFile(CString a_strFilePathName/* = _T("")*/)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // check file pathname
- a_strFilePathName.Trim();
- if (a_strFilePathName.IsEmpty())
- {
- // open file dialog
- CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, TEXTFILE_FILTER);
- if (dlg.DoModal() != IDOK)
- {
- // user didn't click OK button, return FALSE
- LogTrace(__FILE__, __LINE__, _T("LoadStageFromTextFile: user canceled on file open dialog."));
- return FALSE;
- }
- else
- {
- a_strFilePathName = dlg.GetPathName();
- }
- }
- // load string lines from the file
- std::vector<CString > listLineStr = COTSHelper::LoadTextFileToCStingList(a_strFilePathName);
- CString strName = _T("");
- CString strVersion = PART_SIZE_FILE_VERSION;
- CString strLine = listLineStr[0];
-
- // split the string line with ":"
- std::vector<CString > listStr = COTSHelper::SplitString(strLine, FILE_TITLE_SPLIT);
- // jump over the string if it is invalid
- // it should have a title string and value string
- if ((int)listStr.size() != TEXTFILE_ITEM_COLUMN_NUMBER)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("LoadPartSizeFromTextFile: There is no name."));
- return FALSE;
- }
- CString strTitle = listStr[0];
- CString strValue = listStr[1];
- // get part size component
- for (int i = (int)PART_SIZE_ITEMS::MIN; i <= (int)PART_SIZE_ITEMS::MAX; ++i)
- {
- // match title?
- CString strFileItemTitle;
- strFileItemTitle.LoadString(IDS_PART_SIZE_FILE_TITLE_FIRST + i);
- if (strTitle.CompareNoCase(strFileItemTitle) == 0)
- {
- // jump over if name is set
- if (!strTitle.IsEmpty())
- {
- // jump over if value string is empty
- strValue.Trim();
- if (!strValue.IsEmpty())
- {
- strName = strValue;
- }
- }
- }
- }
-
- CPartSizeList listSizes;
- listSizes.clear();
- int nSize = (int)listLineStr.size();
- if (nSize < 2)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("LoadPartSizeFromTextFile: There is no particle size."));
- return FALSE;
- }
- for (int i = 1; i< nSize; i++)
- {
- CString strLine = listLineStr[i];
- double size = atof(strLine);
- listSizes.push_back(size);
- }
- m_poPartSizeFile->SetSizes(listSizes);
- m_poPartSizeFile->ChangDoubleToItem();
- // set stage components
- m_poPartSizeFile->SetName(strName);
- m_poPartSizeFile->SetVersion(strVersion);
-
- // ok, return TRUE
- return TRUE;
- }
-
- BOOL CPartSizeFileMgr::SavePartSizeTextFile(CString a_strFilePathName/* = _T("")*/)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // check file pathname
- a_strFilePathName.Trim();
- if (a_strFilePathName.IsEmpty())
- {
- // file pathname is empty
- // open a file save as dialog
- CFileDialog dlg(FALSE, TEXTFILE_FILE_EXT, NULL, OFN_OVERWRITEPROMPT, TEXTFILE_FILTER);
- if (dlg.DoModal() != IDOK)
- {
- // user didn't click OK button, return FALSE
- LogTrace(__FILE__, __LINE__, _T("SaveStageIntoTextFile: user canceled on file open dialog."));
- return FALSE;
- }
- // get file pathname
- a_strFilePathName = dlg.GetPathName();
- }
- else
- {
- // get path name string
- CString strFilePath = COTSHelper::GetFolderName(a_strFilePathName);
- // check the path name string
- strFilePath.Trim();
- if (!strFilePath.IsEmpty())
- {
- // check if file folder exists
- if (!COTSFileSys::Exists(strFilePath))
- {
- // create the file folder
- if (!COTSFileSys::CreateFolder(strFilePath))
- {
- // failed to create the file folder
- LogErrorTrace(__FILE__, __LINE__, _T("SavePartSizeTextFile: failed to create file folder. %s"), strFilePath);
- return FALSE;
- }
- }
- }
- }
- // create the file
- CStdioFile file;
- CFileException ex;
- if (!file.Open(a_strFilePathName, CFile::modeCreate | CFile::modeWrite, &ex))
- {
- // failed to open file
- LogErrorTrace(__FILE__, __LINE__, _T("SaveStageIntoTextFile: failed to create file. %s"), a_strFilePathName);
- return FALSE;
- }
- // get part size text body
- CString strStageTextBody = GetPartSizeTextBody(m_poPartSizeFile);
- file.WriteString(strStageTextBody);
- file.Close();
- // ok, return TRUE
- return TRUE;
- }
-
- // part size items list
- void CPartSizeFileMgr::SetPartSizeItemList(std::vector<double>& a_listPartSizeItems, BOOL a_bClear/* = TRUE*/)
- {
- ASSERT(m_poPartSizeFile);
- if (!m_poPartSizeFile)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("SetPartSizeItemList: empty part size file."));
- return;
- }
- m_poPartSizeFile->SetSizes(a_listPartSizeItems, a_bClear);
- }
- CPartSizeItemPtr CPartSizeFileMgr::GetPartSizeItemByIndex(int a_nIndex)
- {
- CPartSizeItemList listPartSize = m_poPartSizeFile->GetPartSizeList();
-
- if (a_nIndex < 0 || a_nIndex >(int)listPartSize.size())
- {
- LogErrorTrace(__FILE__, __LINE__, _T("GetPartSizeItemList: invalid index."));
- return nullptr;
- }
- CPartSizeItemPtr pPartSizeItem = CPartSizeItemPtr(new CPartSizeItem(*(listPartSize[a_nIndex].get())));
- return pPartSizeItem;
- }
- CPartSizeItemPtr CPartSizeFileMgr::GetPartSizeItemByName(CString a_strName)
- {
- CPartSizeItemList listPartSize = m_poPartSizeFile->GetPartSizeList();
- // make sure there is no a same name item in the list
- auto itr = std::find_if(listPartSize.begin(), listPartSize.end(), [a_strName](CPartSizeItemPtr& poPartSizeItem) { return poPartSizeItem->GetName().CompareNoCase(a_strName) == 0; });
- if (itr != listPartSize.end())
- {
- // same name std item already in the list
- LogErrorTrace(__FILE__, __LINE__, _T("GetPartSizeItemByName: can't find the same name in the list. name is %s"), a_strName);
- return FALSE;
- }
- CPartSizeItemPtr pPartSizeItem = *itr;
- return CPartSizeItemPtr(new CPartSizeItem(*(pPartSizeItem.get())));;
- }
- //delete as index
- BOOL CPartSizeFileMgr::DeletePartSizeItemByIndex(int a_nIndex)
- {
- CPartSizeList listPartSize = m_poPartSizeFile->GetSizes();
- if (a_nIndex >= 0 && a_nIndex <(int)listPartSize.size())
- {
- listPartSize.erase(listPartSize.begin() + a_nIndex);
- }
- SetPartSizeItemList(listPartSize);
- m_poPartSizeFile->ChangDoubleToItem();
- return TRUE;
- }
- BOOL CPartSizeFileMgr::DeletePartSizeItemByPart(double d_Part)
- {
- CPartSizeList listPartSize = m_poPartSizeFile->GetSizes();
- // find the name matching sample
- auto itr = std::find_if(listPartSize.begin(), listPartSize.end(), [d_Part](double p) { return p == d_Part; });
- if (itr != listPartSize.end())
- {
- listPartSize.erase(itr);
- }
- SetPartSizeItemList(listPartSize);
- m_poPartSizeFile->ChangDoubleToItem();
- return TRUE;
- }
-
- BOOL CPartSizeFileMgr::AddPartSizeItem(double a_poPartSizeItem)
- {
- ASSERT(m_poPartSizeFile);
- if (!m_poPartSizeFile)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("AddPartSizeItem: empty part size file."));
- return FALSE;
- }
- CPartSizeList listPartSize = m_poPartSizeFile->GetSizes();
- //check if in the list already
- auto itr = std::find_if(listPartSize.begin(), listPartSize.end(), [a_poPartSizeItem](double poPartSize) { return (poPartSize == a_poPartSizeItem); });
- if (itr != listPartSize.end())
- {
- // same name std item already in the list
- LogErrorTrace(__FILE__, __LINE__, _T("AddPartSizeItem: the double %f value has already in the list. "), a_poPartSizeItem);
- return TRUE;
- }
- listPartSize.push_back(a_poPartSizeItem);
- sort(listPartSize.begin(), listPartSize.end());
- SetPartSizeItemList(listPartSize);
- m_poPartSizeFile->ChangDoubleToItem();
- return TRUE;
- }
-
-
- BOOL CPartSizeFileMgr::EditPartSizeItem(int a_nIndex, CPartSizeItemPtr a_poPartSizeItem)
- {
- // input check
- ASSERT(a_poPartSizeItem);
- if (!a_poPartSizeItem)
- {
- // invalid std item pointer
- LogErrorTrace(__FILE__, __LINE__, _T("EdiPartSizeItem: invalid input std item pointer."));
- return FALSE;
- }
- // get part size items list
- CPartSizeItemList& listPartSizeItems = m_poPartSizeFile->GetPartSizeList();
- // check index value
- if (a_nIndex < 0 || a_nIndex >(int)listPartSizeItems.size())
- {
- // invalid index
- LogErrorTrace(__FILE__, __LINE__, _T("EdiPartSizeItem: invalid index."));
- return FALSE;
- }
- // replace the part size item
- *(listPartSizeItems[a_nIndex].get()) = *(a_poPartSizeItem.get());
- // ok, return TRUE
- return TRUE;
- }
-
- void CPartSizeFileMgr::SetPartSizeFile(CPartSizeFilePtr a_pPartSizeFile)
- {
- ASSERT(a_pPartSizeFile);
- if (!a_pPartSizeFile)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("SetPartSizeFile: empty part size file pointer."));
- return;
- }
- m_poPartSizeFile = CPartSizeFilePtr(new CPartSizeFile(*a_pPartSizeFile.get()));
- }
- // protected
- // cleanup
- void CPartSizeFileMgr::Cleanup()
- {
- // need to do nothing at the moment
- }
- // initialization
- void CPartSizeFileMgr::Init()
- {
- // initialization
- m_strPathName = _T("");
- m_bModify = FALSE;
- m_poPartSizeFile = CPartSizeFilePtr(new CPartSizeFile());
- }
- // duplication
- void CPartSizeFileMgr::Duplicate(const CPartSizeFileMgr& a_oSource)
- {
- // initialization
- Init();
- // copy data over
- m_strPathName = a_oSource.m_strPathName;
- m_bModify = a_oSource.m_bModify;
- m_poPartSizeFile = CPartSizeFilePtr(new CPartSizeFile(a_oSource.m_poPartSizeFile.get()));
- }
- // get part size
- CPartSizeItemPtr CPartSizeFileMgr::GetLevel(CString a_strValue)
- {
- // part size item
- CPartSizeItemPtr pPartSize = nullptr;
- // check value string
- a_strValue.Trim();
- if (a_strValue.IsEmpty())
- {
- return pPartSize;
- }
- // split the value string
- std::vector<CString > listStr = COTSHelper::SplitString(a_strValue, FILE_VALUE_SPLIT);
- // check vector size
- if (listStr.size() != PART_SIZE_ITEM_NUMBER)
- {
- return pPartSize;
- }
- // get name
- CString strName = listStr[0];
- // remove the name from the list
- listStr.erase(listStr.begin());
- CDoubleRangePtr poSizeLevel = CDoubleRangePtr(new CDoubleRange());
- // Max
- int nMax;
- CString strValue = listStr[0];
- if (!COTSHelper::StringToInt(strValue, nMax))
- {
- return pPartSize;
- }
- poSizeLevel->SetEnd(nMax);
- // Min
- int nMin;
- strValue = listStr[1];
- if (!COTSHelper::StringToInt(strValue, nMin))
- {
- return pPartSize;
- }
- poSizeLevel->SetStart(nMin);
- // check the level
- if (!poSizeLevel)
- {
- // failed to get domain
- return pPartSize;
- }
- pPartSize = CPartSizeItemPtr(new CPartSizeItem());
- // create part size
- pPartSize->SetName(strName);
- pPartSize->SetSizeLevel(poSizeLevel);
- // return the hole pointer
- return pPartSize;
- }
- // get part size level
- CString CPartSizeFileMgr::GetPartSizeTextBody(CPartSizeFilePtr a_pPartSizeFile)
- {
- // part size text body
- CString strPartSizeTextBody = _T("");
- // check input
- ASSERT(a_pPartSizeFile);
- if (!a_pPartSizeFile)
- {
- // invalid input
- LogErrorTrace(__FILE__, __LINE__, _T("GetPartSizeTextBody: invalid input stage pointer."));
- return strPartSizeTextBody;
- }
- // name
- CString strTitle;
- strTitle.LoadString(IDS_PART_SIZE_FILE_TITLE_FIRST);
- strPartSizeTextBody += strTitle + FILE_TITLE_SPLIT + _T(" ") + a_pPartSizeFile->GetName() + LINE_END;
- CPartSizeList listSizes = a_pPartSizeFile->GetSizes();
-
- for (size_t i=0;i<listSizes.size();i++)
- {
- CString strValue;
- strValue.Format(_T("%f"), listSizes[i]);
- strPartSizeTextBody += strValue + LINE_END;
- }
- // return part size text body
- return strPartSizeTextBody;
- }
- }
|