123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- #include "stdafx.h"
- #include "OTSFieldData.h"
- namespace OTSDATA {
- // COTSParticle
- // constructor
- COTSFieldData::COTSFieldData() // constructor
- {
- Init();
- }
- COTSFieldData::COTSFieldData(const COTSFieldData& a_oSource) // copy constructor
- {
- // can't copy itself
- if (&a_oSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(a_oSource);
- }
- COTSFieldData::COTSFieldData(COTSFieldData* a_poSource) // copy constructor
- {
- // can't copy itself
- if (a_poSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(*a_poSource);
- }
- COTSFieldData& COTSFieldData::operator=(const COTSFieldData& a_oSource) // =operator
- {
- // cleanup
- Cleanup();
- // copy the class data over
- Duplicate(a_oSource);
- // return class
- return *this;
- }
- // ==operator
- BOOL COTSFieldData::operator==(const COTSFieldData& a_oSource)
- {
- int nSize = (int)m_listParticles.size();
- if (nSize != (int)a_oSource.m_listParticles.size())
- {
- return FALSE;
- }
- for (int i = 0; i < (int)nSize; ++i)
- {
- if (!(*(m_listParticles[i].get()) == *(a_oSource.m_listParticles[i].get())))
- {
- return FALSE;
- }
- }
- return m_nID == a_oSource.m_nID &&
- m_poiPos == a_oSource.m_poiPos &&
- m_strFieldFileFolder.CompareNoCase(a_oSource.m_strFieldFileFolder);
- }
- COTSFieldData::~COTSFieldData() // destructor
- {
- Cleanup();
- }
- void COTSFieldData::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
- {
- xmls::xInt xnID;
- xmls::xPoint xpoiPos;
- xmls::xString xstrFieldFileFolder;
- xmls::Collection<COTSParticle> parts;
- xmls::Slo slo;
- slo.Register("ID", &xnID);
- slo.Register("poiPos", &xpoiPos);
- slo.Register("FieldFileFolder", &xstrFieldFileFolder);
- slo.Register("Particles", &parts);
- if (isStoring)
- {
- xnID = m_nID;
- xpoiPos = m_poiPos;
- xstrFieldFileFolder = m_strFieldFileFolder;
- parts.Clear();
- for (auto pParticle : m_listParticles)
- {
- parts.addItem(pParticle.get());
- }
- slo.Serialize(true, classDoc, rootNode);
- }
- else
- {
- slo.Serialize(false, classDoc, rootNode);
- m_nID = xnID.value();
- m_poiPos = xpoiPos.value();
- m_strFieldFileFolder = xstrFieldFileFolder.value().c_str();
- m_listParticles.clear();
- for (unsigned int i=0; i < parts.size(); i++)
- {
- m_listParticles.push_back(COTSParticlePtr(parts.getItem(i)));
- }
- }
- }
- void COTSFieldData::SetParticleList(COTSParticleList& a_listParticles, BOOL a_bClear)
- {
- // clear holes list if necessary
- if (a_bClear)
- {
- m_listParticles.clear();
- }
- // copy the list
- for (auto pParticle : a_listParticles)
- {
-
- m_listParticles.push_back(pParticle);
- }
- }
- void COTSFieldData::SetBigParticleList(COTSParticleList& a_listParticles, BOOL a_bClear)
- {
- // clear holes list if necessary
- if (a_bClear)
- {
- m_listBigParticles.clear();
- }
- // copy the list
- for (auto pParticle : a_listParticles)
- {
-
- m_listBigParticles.push_back(pParticle);
- }
- }
- COTSParticleList COTSFieldData::GetTopBorderedBigParticles()
- {
- COTSParticleList parts;
- for (auto p : m_listBigParticles)
- {
- auto segs = p->GetFeature()->GetSegmentsList();
- for (auto seg : segs)
- {
- if (seg->GetHeight() == 0)
- {
- parts.push_back(p);
- break;
- }
- }
- }
- return parts;
- }
- COTSParticleList COTSFieldData::GetBottomBorderedBigParticles()
- {
- COTSParticleList parts;
- for (auto p : m_listBigParticles)
- {
- auto segs = p->GetFeature()->GetSegmentsList();
- for (auto seg : segs)
- {
- if (seg->GetHeight() == this->Height - 1)//the lowest height is 767(height-1),cause starting from 0.
- {
- parts.push_back(p);
- break;
- }
- }
- }
- return parts;
- }
- COTSParticleList COTSFieldData::GetLeftBorderedBigParticles()
- {
- COTSParticleList parts;
- for (auto p : m_listBigParticles)
- {
- auto segs = p->GetFeature()->GetSegmentsList();
- for (auto seg : segs)
- {
- if (seg->GetStart() == 0)
- {
- parts.push_back(p);
- break;
- }
- }
- }
- return parts;
- }
- COTSParticleList COTSFieldData::GetRightBorderedBigParticles()
- {
- COTSParticleList parts;
- for (auto p : m_listBigParticles)
- {
- auto segs = p->GetFeature()->GetSegmentsList();
- for (auto seg : segs)
- {
- if (seg->GetStart() + seg->GetLength() == this->Width)
- {
- parts.push_back(p);
- break;
- }
- }
- }
- return parts;
- }
- // cleanup
- void COTSFieldData::Cleanup()
- {
- m_listParticles.clear();
- }
- // initialization
- void COTSFieldData::Init()
- {
- // initialization
- m_nID = -1;
- m_poiPos = CPoint(0, 0);
- m_strFieldFileFolder = _T("");
- m_listParticles.clear();
- }
- // duplication
- void COTSFieldData::Duplicate(const COTSFieldData& a_oSource)
- {
- // initialization
- Init();
- m_nID = a_oSource.m_nID;
- m_poiPos = a_oSource.m_poiPos;
- m_strFieldFileFolder = a_oSource.m_strFieldFileFolder;
- // copy data over
- for (auto pParticle : a_oSource.m_listParticles)
- {
- COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get()));
- m_listParticles.push_back(pParticleNew);
- }
- }
-
- }
|