OTSFieldData.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #include "stdafx.h"
  2. #include "OTSFieldData.h"
  3. namespace OTSDATA {
  4. // COTSParticle
  5. // constructor
  6. COTSFieldData::COTSFieldData() // constructor
  7. {
  8. Init();
  9. }
  10. COTSFieldData::COTSFieldData(const COTSFieldData& a_oSource) // copy constructor
  11. {
  12. // can't copy itself
  13. if (&a_oSource == this)
  14. {
  15. return;
  16. }
  17. // copy data over
  18. Duplicate(a_oSource);
  19. }
  20. COTSFieldData::COTSFieldData(COTSFieldData* a_poSource) // copy constructor
  21. {
  22. // can't copy itself
  23. if (a_poSource == this)
  24. {
  25. return;
  26. }
  27. // copy data over
  28. Duplicate(*a_poSource);
  29. }
  30. COTSFieldData& COTSFieldData::operator=(const COTSFieldData& a_oSource) // =operator
  31. {
  32. // cleanup
  33. Cleanup();
  34. // copy the class data over
  35. Duplicate(a_oSource);
  36. // return class
  37. return *this;
  38. }
  39. // ==operator
  40. BOOL COTSFieldData::operator==(const COTSFieldData& a_oSource)
  41. {
  42. int nSize = (int)m_listParticles.size();
  43. if (nSize != (int)a_oSource.m_listParticles.size())
  44. {
  45. return FALSE;
  46. }
  47. for (int i = 0; i < (int)nSize; ++i)
  48. {
  49. if (!(*(m_listParticles[i].get()) == *(a_oSource.m_listParticles[i].get())))
  50. {
  51. return FALSE;
  52. }
  53. }
  54. return m_nID == a_oSource.m_nID &&
  55. m_poiPos == a_oSource.m_poiPos &&
  56. m_strFieldFileFolder.CompareNoCase(a_oSource.m_strFieldFileFolder);
  57. }
  58. COTSFieldData::~COTSFieldData() // destructor
  59. {
  60. Cleanup();
  61. }
  62. void COTSFieldData::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
  63. {
  64. xmls::xInt xnID;
  65. xmls::xPoint xpoiPos;
  66. xmls::xString xstrFieldFileFolder;
  67. xmls::Collection<COTSParticle> parts;
  68. xmls::Slo slo;
  69. slo.Register("ID", &xnID);
  70. slo.Register("poiPos", &xpoiPos);
  71. slo.Register("FieldFileFolder", &xstrFieldFileFolder);
  72. slo.Register("Particles", &parts);
  73. if (isStoring)
  74. {
  75. xnID = m_nID;
  76. xpoiPos = m_poiPos;
  77. xstrFieldFileFolder = m_strFieldFileFolder;
  78. parts.Clear();
  79. for (auto pParticle : m_listParticles)
  80. {
  81. parts.addItem(pParticle.get());
  82. }
  83. slo.Serialize(true, classDoc, rootNode);
  84. }
  85. else
  86. {
  87. slo.Serialize(false, classDoc, rootNode);
  88. m_nID = xnID.value();
  89. m_poiPos = xpoiPos.value();
  90. m_strFieldFileFolder = xstrFieldFileFolder.value().c_str();
  91. m_listParticles.clear();
  92. for (unsigned int i=0; i < parts.size(); i++)
  93. {
  94. m_listParticles.push_back(COTSParticlePtr(parts.getItem(i)));
  95. }
  96. }
  97. }
  98. void COTSFieldData::SetParticleList(COTSParticleList& a_listParticles, BOOL a_bClear)
  99. {
  100. // clear holes list if necessary
  101. if (a_bClear)
  102. {
  103. m_listParticles.clear();
  104. }
  105. // copy the list
  106. for (auto pParticle : a_listParticles)
  107. {
  108. //COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get()));
  109. //COTSParticlePtr pParticleNew = COTSParticlePtr(pParticle.get());
  110. m_listParticles.push_back(pParticle);
  111. }
  112. }
  113. void COTSFieldData::SetBigParticleList(COTSParticleList& a_listParticles, BOOL a_bClear)
  114. {
  115. // clear holes list if necessary
  116. if (a_bClear)
  117. {
  118. m_listBigParticles.clear();
  119. }
  120. // copy the list
  121. for (auto pParticle : a_listParticles)
  122. {
  123. //COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get()));
  124. //COTSParticlePtr pParticleNew = COTSParticlePtr(pParticle.get());
  125. m_listBigParticles.push_back(pParticle);
  126. }
  127. }
  128. COTSParticleList COTSFieldData::GetTopBorderedBigParticles()
  129. {
  130. COTSParticleList parts;
  131. for (auto p : m_listBigParticles)
  132. {
  133. auto segs = p->GetFeature()->GetSegmentsList();
  134. for (auto seg : segs)
  135. {
  136. if (seg->GetHeight() == 0)
  137. {
  138. parts.push_back(p);
  139. break;
  140. }
  141. }
  142. }
  143. return parts;
  144. }
  145. COTSParticleList COTSFieldData::GetBottomBorderedBigParticles()
  146. {
  147. COTSParticleList parts;
  148. for (auto p : m_listBigParticles)
  149. {
  150. auto segs = p->GetFeature()->GetSegmentsList();
  151. for (auto seg : segs)
  152. {
  153. if (seg->GetHeight() == this->Height - 1)//the lowest height is 767(height-1),cause starting from 0.
  154. {
  155. parts.push_back(p);
  156. break;
  157. }
  158. }
  159. }
  160. return parts;
  161. }
  162. COTSParticleList COTSFieldData::GetLeftBorderedBigParticles()
  163. {
  164. COTSParticleList parts;
  165. for (auto p : m_listBigParticles)
  166. {
  167. auto segs = p->GetFeature()->GetSegmentsList();
  168. for (auto seg : segs)
  169. {
  170. if (seg->GetStart() == 0)
  171. {
  172. parts.push_back(p);
  173. break;
  174. }
  175. }
  176. }
  177. return parts;
  178. }
  179. COTSParticleList COTSFieldData::GetRightBorderedBigParticles()
  180. {
  181. COTSParticleList parts;
  182. for (auto p : m_listBigParticles)
  183. {
  184. auto segs = p->GetFeature()->GetSegmentsList();
  185. for (auto seg : segs)
  186. {
  187. if (seg->GetStart() + seg->GetLength() == this->Width)
  188. {
  189. parts.push_back(p);
  190. break;
  191. }
  192. }
  193. }
  194. return parts;
  195. }
  196. // cleanup
  197. void COTSFieldData::Cleanup()
  198. {
  199. m_listParticles.clear();
  200. }
  201. // initialization
  202. void COTSFieldData::Init()
  203. {
  204. // initialization
  205. m_nID = -1;
  206. m_poiPos = CPoint(0, 0);
  207. m_strFieldFileFolder = _T("");
  208. m_listParticles.clear();
  209. }
  210. // duplication
  211. void COTSFieldData::Duplicate(const COTSFieldData& a_oSource)
  212. {
  213. // initialization
  214. Init();
  215. m_nID = a_oSource.m_nID;
  216. m_poiPos = a_oSource.m_poiPos;
  217. m_strFieldFileFolder = a_oSource.m_strFieldFileFolder;
  218. // copy data over
  219. for (auto pParticle : a_oSource.m_listParticles)
  220. {
  221. COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get()));
  222. m_listParticles.push_back(pParticleNew);
  223. }
  224. }
  225. }