#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 ps; xmls::SplitString(points, ps, ","); for (unsigned int i = 0; i < ps.size(); i++) { std::string strp = ps[i]; std::vector 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& 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); } } }