| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- #pragma once
- #include "stdafx.h"
- #include "PartSizeItem.h"
- #include "DoubleRange.h"
- namespace OTSMODEL {
- using namespace OTSDATA;
- const double __declspec(dllexport) PART_LAST_NUMBER = (std::numeric_limits<int>::max)();
- // CPartSizeItem
- // constructor
- CPartSizeItem::CPartSizeItem()
- {
- // initialization
- Init();
- }
- // copy constructor
- CPartSizeItem::CPartSizeItem(const CPartSizeItem& a_oSource)
- {
- // can't copy itself
- if (&a_oSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(a_oSource);
- }
- // copy constructor
- CPartSizeItem::CPartSizeItem(CPartSizeItem* a_poSource)
- {
- // can't copy itself
- if (a_poSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(*a_poSource);
- }
- // =operator
- CPartSizeItem& CPartSizeItem::operator=(const CPartSizeItem& a_oSource)
- {
- // cleanup
- Cleanup();
- // copy the class data over
- Duplicate(a_oSource);
- // return class
- return *this;
- }
- // ==operator
- BOOL CPartSizeItem::operator==(const CPartSizeItem& a_oSource)
- {
- // members
- return m_strName.Compare(a_oSource.m_strName) == 0 &&
- *(m_poSizeLevel.get()) == *(a_oSource.m_poSizeLevel.get());
- }
- // destructor
- CPartSizeItem::~CPartSizeItem()
- {
- // cleanup
- Cleanup();
- }
- // CPartSizeItem member functions
- // public
- // serialization
-
- void CPartSizeItem::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
- {
- xmls::xString xstrName;
- xmls::Slo slo;
- slo.Register("Name", &xstrName);
- if (isStoring)
- {
- xstrName = m_strName;
- slo.Serialize(true, classDoc, rootNode);
- }
- else
- {
- slo.Serialize(false, classDoc, rootNode);
- m_strName = xstrName.value().c_str();
- }
- }
- /*// serialization
- void CPartSizeItem::Serialize(double start,double end)
- {
-
- if (end != PART_LAST_NUMBER)
- {
- m_strName = start + "-" + end;
- }
- else {
- m_strName = start + "-";
- }
-
- // member object
- m_poSizeLevel->Serialize(start, end);
- // base object serialization
- CObject::Serialize(ar);
- }
- */
- void CPartSizeItem::BuildList(double start, double end)
- {
- if (end != PART_LAST_NUMBER)
- {
- CString cstr_start = _T ("");
- CString cstr_end = _T("");
- if ((start - (int)start) == 0)
- {
- //小数位为零
- cstr_start.Format(_T("%.0f"), start);
- }
- else
- {
- cstr_start.Format(_T("%0.1lf"), start);
- }
- if ((end - (int)end) == 0)
- {
- //小数位为零
- cstr_end.Format(_T("%.0f"), end);
- }
- else
- {
- cstr_end.Format(_T("%0.1lf"), end);
- }
- m_strName = cstr_start + _T(" ~ ") + cstr_end;
-
- }
- else
- {
- if ((start - (int)start) == 0)
- {
- //小数位为零
- m_strName.Format(_T("%.0f ~ Max"), start);
- }
- else
- {
- m_strName.Format(_T("%0.1lf ~ Max"), start);
- }
- }
- CDoubleRangePtr poSizeLevel = CDoubleRangePtr(new CDoubleRange());
- poSizeLevel->SetEnd(end);
- poSizeLevel->SetStart(start);
- SetSizeLevel(poSizeLevel);
- // member object
- //m_poSizeLevel->Serialize(start, end);
- // base object serialization
- //CObject::Serialize(ar);
- }
- // element ranges list
- void CPartSizeItem::SetSizeLevel(CDoubleRangePtr a_poSizeLevel)
- {
- ASSERT(a_poSizeLevel);
- if (!a_poSizeLevel)
- {
- return;
- }
- m_poSizeLevel = CDoubleRangePtr(new CDoubleRange(*a_poSizeLevel.get()));
- }
- // protected
- // cleanup
- void CPartSizeItem::Cleanup()
- {
- // need to do nothing at the moment
- }
- // initialization
- void CPartSizeItem::Init()
- {
- // initialization
- m_strName = _T("");
- m_poSizeLevel = CDoubleRangePtr(new CDoubleRange());
- }
- // duplication
- void CPartSizeItem::Duplicate(const CPartSizeItem& a_oSource)
- {
- // initialization
- Init();
- // copy data over
- m_strName = a_oSource.m_strName;
- m_poSizeLevel = CDoubleRangePtr(new CDoubleRange(a_oSource.m_poSizeLevel.get()));
- }
- }
|