PartSizeItem.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #pragma once
  2. #include "stdafx.h"
  3. #include "PartSizeItem.h"
  4. #include "DoubleRange.h"
  5. namespace OTSMODEL {
  6. using namespace OTSDATA;
  7. const double __declspec(dllexport) PART_LAST_NUMBER = (std::numeric_limits<int>::max)();
  8. // CPartSizeItem
  9. // constructor
  10. CPartSizeItem::CPartSizeItem()
  11. {
  12. // initialization
  13. Init();
  14. }
  15. // copy constructor
  16. CPartSizeItem::CPartSizeItem(const CPartSizeItem& a_oSource)
  17. {
  18. // can't copy itself
  19. if (&a_oSource == this)
  20. {
  21. return;
  22. }
  23. // copy data over
  24. Duplicate(a_oSource);
  25. }
  26. // copy constructor
  27. CPartSizeItem::CPartSizeItem(CPartSizeItem* a_poSource)
  28. {
  29. // can't copy itself
  30. if (a_poSource == this)
  31. {
  32. return;
  33. }
  34. // copy data over
  35. Duplicate(*a_poSource);
  36. }
  37. // =operator
  38. CPartSizeItem& CPartSizeItem::operator=(const CPartSizeItem& a_oSource)
  39. {
  40. // cleanup
  41. Cleanup();
  42. // copy the class data over
  43. Duplicate(a_oSource);
  44. // return class
  45. return *this;
  46. }
  47. // ==operator
  48. BOOL CPartSizeItem::operator==(const CPartSizeItem& a_oSource)
  49. {
  50. // members
  51. return m_strName.Compare(a_oSource.m_strName) == 0 &&
  52. *(m_poSizeLevel.get()) == *(a_oSource.m_poSizeLevel.get());
  53. }
  54. // destructor
  55. CPartSizeItem::~CPartSizeItem()
  56. {
  57. // cleanup
  58. Cleanup();
  59. }
  60. // CPartSizeItem member functions
  61. // public
  62. // serialization
  63. void CPartSizeItem::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
  64. {
  65. xmls::xString xstrName;
  66. xmls::Slo slo;
  67. slo.Register("Name", &xstrName);
  68. if (isStoring)
  69. {
  70. xstrName = m_strName;
  71. slo.Serialize(true, classDoc, rootNode);
  72. }
  73. else
  74. {
  75. slo.Serialize(false, classDoc, rootNode);
  76. m_strName = xstrName.value().c_str();
  77. }
  78. }
  79. /*// serialization
  80. void CPartSizeItem::Serialize(double start,double end)
  81. {
  82. if (end != PART_LAST_NUMBER)
  83. {
  84. m_strName = start + "-" + end;
  85. }
  86. else {
  87. m_strName = start + "-";
  88. }
  89. // member object
  90. m_poSizeLevel->Serialize(start, end);
  91. // base object serialization
  92. CObject::Serialize(ar);
  93. }
  94. */
  95. void CPartSizeItem::BuildList(double start, double end)
  96. {
  97. if (end != PART_LAST_NUMBER)
  98. {
  99. CString cstr_start = _T ("");
  100. CString cstr_end = _T("");
  101. if ((start - (int)start) == 0)
  102. {
  103. //小数位为零
  104. cstr_start.Format(_T("%.0f"), start);
  105. }
  106. else
  107. {
  108. cstr_start.Format(_T("%0.1lf"), start);
  109. }
  110. if ((end - (int)end) == 0)
  111. {
  112. //小数位为零
  113. cstr_end.Format(_T("%.0f"), end);
  114. }
  115. else
  116. {
  117. cstr_end.Format(_T("%0.1lf"), end);
  118. }
  119. m_strName = cstr_start + _T(" ~ ") + cstr_end;
  120. }
  121. else
  122. {
  123. if ((start - (int)start) == 0)
  124. {
  125. //小数位为零
  126. m_strName.Format(_T("%.0f ~ Max"), start);
  127. }
  128. else
  129. {
  130. m_strName.Format(_T("%0.1lf ~ Max"), start);
  131. }
  132. }
  133. CDoubleRangePtr poSizeLevel = CDoubleRangePtr(new CDoubleRange());
  134. poSizeLevel->SetEnd(end);
  135. poSizeLevel->SetStart(start);
  136. SetSizeLevel(poSizeLevel);
  137. // member object
  138. //m_poSizeLevel->Serialize(start, end);
  139. // base object serialization
  140. //CObject::Serialize(ar);
  141. }
  142. // element ranges list
  143. void CPartSizeItem::SetSizeLevel(CDoubleRangePtr a_poSizeLevel)
  144. {
  145. ASSERT(a_poSizeLevel);
  146. if (!a_poSizeLevel)
  147. {
  148. return;
  149. }
  150. m_poSizeLevel = CDoubleRangePtr(new CDoubleRange(*a_poSizeLevel.get()));
  151. }
  152. // protected
  153. // cleanup
  154. void CPartSizeItem::Cleanup()
  155. {
  156. // need to do nothing at the moment
  157. }
  158. // initialization
  159. void CPartSizeItem::Init()
  160. {
  161. // initialization
  162. m_strName = _T("");
  163. m_poSizeLevel = CDoubleRangePtr(new CDoubleRange());
  164. }
  165. // duplication
  166. void CPartSizeItem::Duplicate(const CPartSizeItem& a_oSource)
  167. {
  168. // initialization
  169. Init();
  170. // copy data over
  171. m_strName = a_oSource.m_strName;
  172. m_poSizeLevel = CDoubleRangePtr(new CDoubleRange(a_oSource.m_poSizeLevel.get()));
  173. }
  174. }