123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- #include "stdafx.h"
- #include "OTSData.h"
- #include "MsrSampleStatus.h"
- namespace OTSMODEL {
- // CMsrSampleStatus
- // constructor
- CMsrSampleStatus::CMsrSampleStatus()
- {
- // initialization
- Init();
- }
- // copy constructor
- CMsrSampleStatus::CMsrSampleStatus(const CMsrSampleStatus& a_oSource)
- {
- // can't copy itself
- if (&a_oSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(a_oSource);
- }
- // copy constructor
- CMsrSampleStatus::CMsrSampleStatus(CMsrSampleStatus* a_poSource)
- {
- // input check
- ASSERT(a_poSource);
- if (!a_poSource)
- {
- return;
- }
- // can't copy itself
- if (a_poSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(*a_poSource);
- }
- // =operator
- CMsrSampleStatus& CMsrSampleStatus::operator=(const CMsrSampleStatus& a_oSource)
- {
- // cleanup
- Cleanup();
- // copy the class data over
- Duplicate(a_oSource);
- // return class
- return *this;
- }
- // destructor
- CMsrSampleStatus::~CMsrSampleStatus()
- {
- // cleanup
- Cleanup();
- }
- // ==operator
- BOOL CMsrSampleStatus::operator==(const CMsrSampleStatus& a_oSource)
- {
- // return FASLE, if the two center list are in different size
- int nSize = (int)m_listCpltedCenter.size();
- if (nSize != (int)a_oSource.m_listCpltedCenter.size())
- {
- return FALSE;
- }
- // return FALSE if any of the center are different
- for (int i = 0; i < nSize; ++i)
- {
- if ((m_listCpltedCenter[i].x != a_oSource.m_listCpltedCenter[i].x)
- ||(m_listCpltedCenter[i].y != a_oSource.m_listCpltedCenter[i].y))
- {
- return FALSE;
- }
- }
- return m_nStatus == a_oSource.m_nStatus &&
- m_timeStart == a_oSource.m_timeStart &&
- m_timeUsed == a_oSource.m_timeUsed &&
- m_timeStart == a_oSource.m_timeStart &&
- m_nCompletedFields == a_oSource.m_nCompletedFields;
- }
- // CMsrSampleStatus member functions
- // public
- // serialization
-
- void CMsrSampleStatus::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
- {
- xmls::xInt xStatus;
- xmls::xOleDateTime xtimeStart;
- xmls::xOleDateTimeSpan xtimeUsed;
- xmls::xOleDateTime xtimeEnd;
- xmls::xInt xnCompletedFields;
- xmls::xString xPoints;
- xmls::Slo slo;
- slo.Register("Status", &xStatus);
- slo.Register("TimeStart", &xtimeStart);
- slo.Register("TimeUsed", &xtimeUsed);
- slo.Register("TimeEnd", &xtimeEnd);
-
- slo.Register("CompletedFields", &xnCompletedFields);
- slo.Register("CompletedCenters", &xPoints);
- if (isStoring)
- {
- xStatus = (int)m_nStatus;
- xtimeStart = m_timeStart;
- xtimeEnd = m_timeEnd;
- xtimeUsed = m_timeUsed;
- xnCompletedFields = m_nCompletedFields;
- std::string strPoints="";
- for (auto pCenter : m_listCpltedCenter)
- {
- std::string point;
- point = std::to_string(pCenter.x) + ":" + std::to_string(pCenter.y);
- if (strPoints == "")
- {
- strPoints = point;
- }
- else
- {
- strPoints = strPoints + "," + point;
- }
- }
- xPoints = strPoints;
- slo.Serialize(true, classDoc, rootNode);
- }
- else
- {
- slo.Serialize(false, classDoc, rootNode);
- m_nStatus= (OTS_MSR_SAMPLE_STATUS)xStatus.value ();
- m_timeStart= xtimeStart.value ();
- m_timeEnd=xtimeEnd.value ();
- m_timeUsed= xtimeUsed.value ();
- std::string points = xPoints.value();
- m_nCompletedFields = xnCompletedFields.value();
- m_listCpltedCenter.clear();
- std::vector <std::string> ps;
- xmls::SplitString(points, ps, ",");
- for (unsigned int i = 0; i < ps.size(); i++)
- {
- std::string strp = ps[i];
- std::vector<std::string> s;
- xmls::SplitString(strp, s, ":");
- CPoint p = CPoint(std::stoi(s[0]), std::stoi(s[1]));
- m_listCpltedCenter.push_back(p);
- }
- }
- }
- BOOL CMsrSampleStatus::ComputeTime(OTS_MSR_TIME_TYPE a_nType)
- {
- if (a_nType == OTS_MSR_TIME_TYPE::START)
- {
- if (m_timeStart == COleDateTime())
- {
- m_timeStart = COleDateTime::GetCurrentTime();
- m_timeStartCur = m_timeStart;
- m_timeUsedLast = COleDateTimeSpan();
- }
- else
- {
- m_timeStartCur = COleDateTime::GetCurrentTime();
- m_timeUsedLast = m_timeUsed;
- }
- m_timeEnd = COleDateTime::GetCurrentTime();
- if (m_timeStartCur == m_timeStart)
- {
- // first compute time
- m_timeUsed = m_timeEnd - m_timeStart;
- }
- else
- {
- // not the first compute time
- m_timeUsed = m_timeUsed + m_timeEnd - m_timeStartCur;
- }
-
- }
- else if (a_nType == OTS_MSR_TIME_TYPE::STOPPED)
- {
- // set current time as end time
- m_timeEnd = COleDateTime::GetCurrentTime();
- // compute used time
- COleDateTimeSpan timeUsed = COleDateTimeSpan();
- if (m_timeStartCur == m_timeStart)
- {
- // first compute time
- timeUsed = m_timeEnd - m_timeStart;
- }
- else
- {
- // not the first compute time
- timeUsed = m_timeEnd - m_timeStartCur + m_timeUsedLast;
- }
- m_timeUsed = timeUsed;
- }
- else
- {
- return FALSE;
- }
- return TRUE;
- }
- // protected
- // cleanup
- void CMsrSampleStatus::Cleanup()
- {
- // need to do nothing at the moment
- m_listCpltedCenter.clear();
- }
- void CMsrSampleStatus::SetCompletedFieldsCenter(std::vector<CPoint>& a_listCpltedCenter)
- {
- m_listCpltedCenter.clear();
-
- for (auto pt: a_listCpltedCenter)
- {
- m_listCpltedCenter.push_back(pt);
- }
- }
- // initialization
- void CMsrSampleStatus::Init()
- {
- m_nStatus = DEFAULT_MSR_SAMPLE_STATUS;
- m_timeStart = COleDateTime();
- m_timeUsed = COleDateTimeSpan();
- m_timeEnd = COleDateTime();
- m_nCompletedFields = 0;
- m_listCpltedCenter.clear();
- }
- // duplication
- void CMsrSampleStatus::Duplicate(const CMsrSampleStatus& a_oSource)
- {
- // initialization
- Init();
- // copy data over
- m_nStatus = a_oSource.m_nStatus;
- m_timeStart = a_oSource.m_timeStart;
- m_timeUsed = a_oSource.m_timeUsed;
- m_timeEnd = a_oSource.m_timeEnd;
- m_nCompletedFields = a_oSource.m_nCompletedFields;
- for (auto pCpltedCenter : a_oSource.m_listCpltedCenter)
- {
- m_listCpltedCenter.push_back(pCpltedCenter);
- }
- }
- }
|