OTSFieldData.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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(pParticleNew);
  111. }
  112. }
  113. // cleanup
  114. void COTSFieldData::Cleanup()
  115. {
  116. m_listParticles.clear();
  117. }
  118. // initialization
  119. void COTSFieldData::Init()
  120. {
  121. // initialization
  122. m_nID = -1;
  123. m_poiPos = CPoint(0, 0);
  124. m_strFieldFileFolder = _T("");
  125. m_listParticles.clear();
  126. }
  127. // duplication
  128. void COTSFieldData::Duplicate(const COTSFieldData& a_oSource)
  129. {
  130. // initialization
  131. Init();
  132. m_nID = a_oSource.m_nID;
  133. m_poiPos = a_oSource.m_poiPos;
  134. m_strFieldFileFolder = a_oSource.m_strFieldFileFolder;
  135. // copy data over
  136. for (auto pParticle : a_oSource.m_listParticles)
  137. {
  138. COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get()));
  139. m_listParticles.push_back(pParticleNew);
  140. }
  141. }
  142. }