Stage.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #include "stdafx.h"
  2. #include "Stage.h"
  3. namespace OTSDATA {
  4. // CStage
  5. //IMPLEMENT_SERIAL(CStage, CObject, 1)
  6. // constructor
  7. CStage::CStage()
  8. {
  9. // initialization
  10. Init();
  11. }
  12. // copy constructor
  13. CStage::CStage(const CStage& a_oSource)
  14. {
  15. // can't copy itself
  16. if (&a_oSource == this)
  17. {
  18. return;
  19. }
  20. // copy data over
  21. Duplicate(a_oSource);
  22. }
  23. // copy constructor
  24. CStage::CStage(CStage* a_poSource)
  25. {
  26. // can't copy itself
  27. if (a_poSource == this)
  28. {
  29. return;
  30. }
  31. // copy data over
  32. Duplicate(*a_poSource);
  33. }
  34. // =operator
  35. CStage& CStage::operator=(const CStage& a_oSource)
  36. {
  37. // cleanup
  38. Cleanup();
  39. // copy the class data over
  40. Duplicate(a_oSource);
  41. // return class
  42. return *this;
  43. }
  44. // ==operator
  45. BOOL CStage::operator==(const CStage& a_oSource)
  46. {
  47. // return FASLE, if the two holes list are in different size
  48. int nSize = (int)m_listHoles.size();
  49. if (nSize != (int)a_oSource.m_listHoles.size())
  50. {
  51. return FALSE;
  52. }
  53. // return FALSE if any of the pare holes are different
  54. for (int i = 0; i < nSize; ++i)
  55. {
  56. if (!(*(m_listHoles[i].get()) == *(a_oSource.m_listHoles[i].get())))
  57. {
  58. return FALSE;
  59. }
  60. }
  61. // members check
  62. return m_strName.Compare(a_oSource.m_strName) == 0 &&
  63. *(m_poBourary.get()) == *((a_oSource.m_poBourary).get()) &&
  64. *(m_poSTD.get()) == *((a_oSource.m_poSTD).get());
  65. }
  66. // destructor
  67. CStage::~CStage()
  68. {
  69. // cleanup
  70. Cleanup();
  71. }
  72. // CDomain functions
  73. // public
  74. //// serialization
  75. //void CStage::Serialize(CArchive& ar)
  76. //{
  77. // // store?
  78. // if (ar.IsStoring())
  79. // {
  80. // // store
  81. // ar << m_strName;
  82. // }
  83. // else
  84. // {
  85. // // load
  86. // ar >> m_strName;
  87. // }
  88. // // member classes serialization
  89. // m_poBourary->Serialize(ar);
  90. // m_poSTD->Serialize(ar);
  91. // // holes list serialization
  92. // if (ar.IsStoring())
  93. // {
  94. // // store
  95. // ar << (int)m_listHoles.size();
  96. // for (auto pHole : m_listHoles)
  97. // {
  98. // pHole->Serialize(ar);
  99. // }
  100. // }
  101. // else
  102. // {
  103. // // load
  104. // int nSize;
  105. // ar >> nSize;
  106. // for (int i = 0; i < nSize; ++i)
  107. // {
  108. // CHolePtr pHole = CHolePtr(new CHole());
  109. // pHole->Serialize(ar);
  110. // m_listHoles.push_back(pHole);
  111. // }
  112. // }
  113. // // base object serialization
  114. // CObject::Serialize(ar);
  115. //}
  116. // boundary
  117. void CStage::SetBoundary(CDomainPtr a_poBourary)
  118. {
  119. // input check
  120. ASSERT(a_poBourary);
  121. if (!a_poBourary)
  122. {
  123. return;
  124. }
  125. m_poBourary = CDomainPtr(new CDomain(a_poBourary.get()));
  126. }
  127. // std
  128. void CStage::SetSTD(CDomainPtr a_poSTD)
  129. {
  130. // input check
  131. ASSERT(a_poSTD);
  132. if (!a_poSTD)
  133. {
  134. return;
  135. }
  136. m_poSTD = CDomainPtr(new CDomain(a_poSTD.get()));
  137. }
  138. // holes list
  139. void CStage::SetHoleList(CHolesList& a_listHoles, BOOL a_bClear /* = TRUE*/)
  140. {
  141. // clear holes list if necessary
  142. if (a_bClear)
  143. {
  144. m_listHoles.clear();
  145. }
  146. // copy the list
  147. for (auto pHole : a_listHoles)
  148. {
  149. CHolePtr pHoleNew = CHolePtr(new CHole(*pHole.get()));
  150. m_listHoles.push_back(pHoleNew);
  151. }
  152. }
  153. // sample holes list
  154. CHolePtr CStage::GetHoleByIndex(int a_nIndex)
  155. {
  156. if (a_nIndex < 0 || a_nIndex >= (int)m_listHoles.size())
  157. {
  158. // invalid index
  159. return nullptr;
  160. }
  161. return m_listHoles[a_nIndex];
  162. }
  163. CHolePtr CStage::GetHoleByName(CString a_strHoleName)
  164. {
  165. a_strHoleName.Trim();
  166. if (a_strHoleName.IsEmpty())
  167. {
  168. // invalid hole name
  169. return nullptr;
  170. }
  171. auto itr = std::find_if(m_listHoles.begin(), m_listHoles.end(), [a_strHoleName](CHolePtr p) { return p->GetName().CompareNoCase(a_strHoleName) == 0; });
  172. if (itr == m_listHoles.end())
  173. {
  174. // didn't find the hole
  175. return nullptr;
  176. }
  177. // return the hole
  178. return *itr;
  179. }
  180. void CStage::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
  181. {
  182. xmls::xString xnstrName;
  183. xmls::Collection<CHole> xHolelist;
  184. xmls::Slo slo;
  185. slo.Register("strName", &xnstrName);
  186. slo.Register("boundary", m_poBourary.get());
  187. slo.Register("std", m_poSTD.get());
  188. slo.Register("Holes", &xHolelist);
  189. if (isStoring)
  190. {
  191. xnstrName = m_strName;
  192. xHolelist.Clear();
  193. for (unsigned int i = 0; i < m_listHoles.size(); i++)
  194. {
  195. xHolelist.addItem(m_listHoles[i].get());
  196. }
  197. slo.Serialize(true, classDoc, rootNode);
  198. }
  199. else
  200. {
  201. slo.Serialize(false, classDoc, rootNode);
  202. m_strName = xnstrName.value().c_str();
  203. m_listHoles.clear();
  204. for (unsigned int i = 0; i < xHolelist.size(); i++)
  205. {
  206. m_listHoles.push_back(CHolePtr(xHolelist.getItem(i)));
  207. }
  208. }
  209. }
  210. // protected
  211. // cleanup
  212. void CStage::Cleanup()
  213. {
  214. // need to do nothing at the moment
  215. }
  216. // initialization
  217. void CStage::Init()
  218. {
  219. // initialization
  220. m_strName = _T("");
  221. m_poBourary = CDomainPtr(new CDomain());
  222. m_poSTD = CDomainPtr(new CDomain());
  223. m_listHoles.clear();
  224. }
  225. // duplication
  226. void CStage::Duplicate(const CStage& a_oSource)
  227. {
  228. Init();
  229. // copy data over
  230. m_strName = a_oSource.m_strName;
  231. m_poBourary = CDomainPtr(new CDomain(*(a_oSource.m_poBourary.get())));
  232. m_poSTD = CDomainPtr(new CDomain(*(a_oSource.m_poSTD.get())));
  233. for (auto pHole : a_oSource.m_listHoles)
  234. {
  235. CHolePtr pHoleNew = CHolePtr(new CHole(pHole.get()));
  236. m_listHoles.push_back(pHoleNew);
  237. }
  238. //xnstrName = a_oSource.m_strName;
  239. }
  240. }