| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- #include "stdafx.h"
- #include "TriTempFile.h"
- namespace OTSMODEL {
- // CPartSizeFile
-
- // constructor
- CTriTempFile::CTriTempFile()
- {
- // initialization
- Init();
- }
- // copy constructor
- CTriTempFile::CTriTempFile(const CTriTempFile& a_oSource)
- {
- // can't copy itself
- if (&a_oSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(a_oSource);
- }
- // copy constructor
- CTriTempFile::CTriTempFile(CTriTempFile* a_poSource)
- {
- // can't copy itself
- if (a_poSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(*a_poSource);
- }
- // =operator
- CTriTempFile& CTriTempFile::operator=(const CTriTempFile& a_oSource)
- {
- // cleanup
- Cleanup();
- // copy the class data over
- Duplicate(a_oSource);
- // return class
- return *this;
- }
- // ==operator
- BOOL CTriTempFile::operator==(const CTriTempFile& a_oSource)
- {
- // return FASLE, if the two list are in different size
- int nSize = (int)m_listTriTempItem.size();
- if (nSize != (int)a_oSource.m_listTriTempItem.size())
- {
- return FALSE;
- }
- // return FALSE if any of the pare holes are different
- for (int i = 0; i < nSize; ++i)
- {
- if (!(*(m_listTriTempItem[i].get()) == *(a_oSource.m_listTriTempItem[i].get())))
- {
- return FALSE;
- }
- }
- return m_strName.Compare(a_oSource.m_strName) == 0 &&
- m_strVersion == a_oSource.m_strVersion;
- }
- // destructor
- CTriTempFile::~CTriTempFile()
- {
- // cleanup
- Cleanup();
- }
- // CPartSizeItem member functions
- // public
- // serialization
-
- void CTriTempFile::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
- {
- xmls::xString xstrName;
- xmls::xString xstrVersion;
- xmls::Collection<CTriTempItem> xTriTempItem;
- xmls::Slo slo;
- slo.Register("Name", &xstrName);
- slo.Register("Version", &xstrVersion);
- slo.Register("TemplateItem", &xTriTempItem);
- if (isStoring)
- {
- xstrName = TRIA_TEMP_NAME;
- xstrVersion = TRIA_TEMP_FILE_VERSION;
- for (int i = 0; i < m_listTriTempItem.size(); i++)
- {
- xTriTempItem.addItem(m_listTriTempItem[i].get());
- }
- slo.Serialize(true, classDoc, rootNode);
- }
- else
- {
- slo.Serialize(false, classDoc, rootNode);
- m_strName = xstrName.value().c_str();
- m_strVersion = xstrVersion.value().c_str();
- for (int i = 0; i < xTriTempItem.size(); i++)
- {
- m_listTriTempItem.push_back(CTriTempItemPtr(xTriTempItem.getItem(i)));
- }
- }
- //// Filemark
- //xmls::xInt xnTriaTempFileMark;
- //// Fileversion
- //xmls::xString xnTriaTempFileVersion;
- //// Name
- //xmls::xString xstrName;
- //xmls::Collection<CTriTempItem> xTriTemps;
- //xmls::Slo slo;
- //slo.Register("Name", &xstrName);
- //slo.Register("FileMark", &xnTriaTempFileMark);
- //slo.Register("FileVersion", &xnTriaTempFileVersion);
- //slo.Register("TriTemps", &xTriTemps);
- //if (isStoring)
- //{
- // xnTriaTempFileMark = TRIA_TEMP_FILE_MARK;
- // xnTriaTempFileVersion = TRIA_TEMP_FILE_VERSION;
- // xstrName = m_strName;
- // xTriTemps.Clear();
- // for (int i = 0; i < m_listTriTemp.size(); i++)
- // {
- // xTriTemps.addItem(m_listTriTemp[i].get());
- // }
- // slo.Serialize(true, classDoc, rootNode);
- //}
- //else
- //{
- // slo.Serialize(false, classDoc, rootNode);
- // m_strVersion = xnTriaTempFileVersion.value().c_str();
- // m_strName = xstrName.value().c_str();
- // m_listTriTemp.clear();
- // for (int i=0;i<xTriTemps.size ();i++)
- // {
- // m_listTriTemp.push_back(CTriTempItemPtr(xTriTemps.getItem(i)));
- // }
- //}
- }
- void CTriTempFile::SetTriTempItemList(CTriTempItemList& a_listTriTemp, BOOL a_bClear/* = TRUE*/)
- {
- // clear list if necessary
- if (a_bClear)
- {
- m_listTriTempItem.clear();
- }
- // copy the list
- for (auto pTriTemp : a_listTriTemp)
- {
- CTriTempItemPtr pTriTempItemNew = CTriTempItemPtr(new CTriTempItem(*pTriTemp.get()));
- m_listTriTempItem.push_back(pTriTempItemNew);
- }
- }
- CTriTempItemPtr CTriTempFile::GetTriTempByIndex(int a_nIndex)
- {
- if (a_nIndex < 0 || a_nIndex >= (int)m_listTriTempItem.size())
- {
- // invalid index
- return nullptr;
- }
- return m_listTriTempItem[a_nIndex];
- }
- CTriTempItemPtr CTriTempFile::GetTriTempByName(CString a_strPartSizeName)
- {
- a_strPartSizeName.Trim();
- if (a_strPartSizeName.IsEmpty())
- {
- // invalid hole name
- return nullptr;
- }
- auto itr = std::find_if(m_listTriTempItem.begin(), m_listTriTempItem.end(), [a_strPartSizeName](CTriTempItemPtr p) { return p->GetTemplateName().CompareNoCase(a_strPartSizeName) == 0; });
- if (itr == m_listTriTempItem.end())
- {
- // didn't find the hole
- return nullptr;
- }
- // return the hole
- return *itr;
- }
- // protected
- // cleanup
- void CTriTempFile::Cleanup()
- {
- m_listTriTempItem.clear();
- }
- // initialization
- void CTriTempFile::Init()
- {
- m_strVersion = _T("");
- m_strName = _T("");
- // initialization
- m_listTriTempItem.clear();
- }
- // duplication
- void CTriTempFile::Duplicate(const CTriTempFile& a_oSource)
- {
- // initialization
- Init();
- // copy data over
- m_strVersion = a_oSource.m_strVersion;
- m_strName = a_oSource.m_strName;
- for (auto pTriTempItem : a_oSource.m_listTriTempItem)
- {
- CTriTempItemPtr pTriTempNew = CTriTempItemPtr(new CTriTempItem(pTriTempItem.get()));
- m_listTriTempItem.push_back(pTriTempNew);
- }
- }
- }
|