MsrSampleStatus.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. // MsrSampleStatus.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "OTSData.h"
  5. #include "MsrSampleStatus.h"
  6. namespace OTSMODEL {
  7. // CMsrSampleStatus
  8. // constructor
  9. CMsrSampleStatus::CMsrSampleStatus()
  10. {
  11. // initialization
  12. Init();
  13. }
  14. // copy constructor
  15. CMsrSampleStatus::CMsrSampleStatus(const CMsrSampleStatus& a_oSource)
  16. {
  17. // can't copy itself
  18. if (&a_oSource == this)
  19. {
  20. return;
  21. }
  22. // copy data over
  23. Duplicate(a_oSource);
  24. }
  25. // copy constructor
  26. CMsrSampleStatus::CMsrSampleStatus(CMsrSampleStatus* a_poSource)
  27. {
  28. // input check
  29. ASSERT(a_poSource);
  30. if (!a_poSource)
  31. {
  32. return;
  33. }
  34. // can't copy itself
  35. if (a_poSource == this)
  36. {
  37. return;
  38. }
  39. // copy data over
  40. Duplicate(*a_poSource);
  41. }
  42. // =operator
  43. CMsrSampleStatus& CMsrSampleStatus::operator=(const CMsrSampleStatus& a_oSource)
  44. {
  45. // cleanup
  46. Cleanup();
  47. // copy the class data over
  48. Duplicate(a_oSource);
  49. // return class
  50. return *this;
  51. }
  52. // destructor
  53. CMsrSampleStatus::~CMsrSampleStatus()
  54. {
  55. // cleanup
  56. Cleanup();
  57. }
  58. // ==operator
  59. BOOL CMsrSampleStatus::operator==(const CMsrSampleStatus& a_oSource)
  60. {
  61. // return FASLE, if the two center list are in different size
  62. int nSize = (int)m_listCpltedCenter.size();
  63. if (nSize != (int)a_oSource.m_listCpltedCenter.size())
  64. {
  65. return FALSE;
  66. }
  67. // return FALSE if any of the center are different
  68. for (int i = 0; i < nSize; ++i)
  69. {
  70. if ((m_listCpltedCenter[i].x != a_oSource.m_listCpltedCenter[i].x)
  71. ||(m_listCpltedCenter[i].y != a_oSource.m_listCpltedCenter[i].y))
  72. {
  73. return FALSE;
  74. }
  75. }
  76. return m_nStatus == a_oSource.m_nStatus &&
  77. m_timeStart == a_oSource.m_timeStart &&
  78. m_timeUsed == a_oSource.m_timeUsed &&
  79. m_timeStart == a_oSource.m_timeStart &&
  80. m_nCompletedFields == a_oSource.m_nCompletedFields;
  81. }
  82. // CMsrSampleStatus member functions
  83. // public
  84. // serialization
  85. void CMsrSampleStatus::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
  86. {
  87. xmls::xInt xStatus;
  88. xmls::xOleDateTime xtimeStart;
  89. xmls::xOleDateTimeSpan xtimeUsed;
  90. xmls::xOleDateTime xtimeEnd;
  91. xmls::xInt xnCompletedFields;
  92. xmls::xString xPoints;
  93. xmls::Slo slo;
  94. slo.Register("Status", &xStatus);
  95. slo.Register("TimeStart", &xtimeStart);
  96. slo.Register("TimeUsed", &xtimeUsed);
  97. slo.Register("TimeEnd", &xtimeEnd);
  98. slo.Register("CompletedFields", &xnCompletedFields);
  99. slo.Register("CompletedCenters", &xPoints);
  100. if (isStoring)
  101. {
  102. xStatus = (int)m_nStatus;
  103. xtimeStart = m_timeStart;
  104. xtimeEnd = m_timeEnd;
  105. xtimeUsed = m_timeUsed;
  106. xnCompletedFields = m_nCompletedFields;
  107. std::string strPoints="";
  108. for (auto pCenter : m_listCpltedCenter)
  109. {
  110. std::string point;
  111. point = std::to_string(pCenter.x) + ":" + std::to_string(pCenter.y);
  112. if (strPoints == "")
  113. {
  114. strPoints = point;
  115. }
  116. else
  117. {
  118. strPoints = strPoints + "," + point;
  119. }
  120. }
  121. xPoints = strPoints;
  122. slo.Serialize(true, classDoc, rootNode);
  123. }
  124. else
  125. {
  126. slo.Serialize(false, classDoc, rootNode);
  127. m_nStatus= (OTS_MSR_SAMPLE_STATUS)xStatus.value ();
  128. m_timeStart= xtimeStart.value ();
  129. m_timeEnd=xtimeEnd.value ();
  130. m_timeUsed= xtimeUsed.value ();
  131. std::string points = xPoints.value();
  132. m_nCompletedFields = xnCompletedFields.value();
  133. m_listCpltedCenter.clear();
  134. std::vector <std::string> ps;
  135. xmls::SplitString(points, ps, ",");
  136. for (unsigned int i = 0; i < ps.size(); i++)
  137. {
  138. std::string strp = ps[i];
  139. std::vector<std::string> s;
  140. xmls::SplitString(strp, s, ":");
  141. CPoint p = CPoint(std::stoi(s[0]), std::stoi(s[1]));
  142. m_listCpltedCenter.push_back(p);
  143. }
  144. }
  145. }
  146. BOOL CMsrSampleStatus::ComputeTime(OTS_MSR_TIME_TYPE a_nType)
  147. {
  148. if (a_nType == OTS_MSR_TIME_TYPE::START)
  149. {
  150. if (m_timeStart == COleDateTime())
  151. {
  152. m_timeStart = COleDateTime::GetCurrentTime();
  153. m_timeStartCur = m_timeStart;
  154. m_timeUsedLast = COleDateTimeSpan();
  155. }
  156. else
  157. {
  158. m_timeStartCur = COleDateTime::GetCurrentTime();
  159. m_timeUsedLast = m_timeUsed;
  160. }
  161. m_timeEnd = COleDateTime::GetCurrentTime();
  162. if (m_timeStartCur == m_timeStart)
  163. {
  164. // first compute time
  165. m_timeUsed = m_timeEnd - m_timeStart;
  166. }
  167. else
  168. {
  169. // not the first compute time
  170. m_timeUsed = m_timeUsed + m_timeEnd - m_timeStartCur;
  171. }
  172. }
  173. else if (a_nType == OTS_MSR_TIME_TYPE::STOPPED)
  174. {
  175. // set current time as end time
  176. m_timeEnd = COleDateTime::GetCurrentTime();
  177. // compute used time
  178. COleDateTimeSpan timeUsed = COleDateTimeSpan();
  179. if (m_timeStartCur == m_timeStart)
  180. {
  181. // first compute time
  182. timeUsed = m_timeEnd - m_timeStart;
  183. }
  184. else
  185. {
  186. // not the first compute time
  187. timeUsed = m_timeEnd - m_timeStartCur + m_timeUsedLast;
  188. }
  189. m_timeUsed = timeUsed;
  190. }
  191. else
  192. {
  193. return FALSE;
  194. }
  195. return TRUE;
  196. }
  197. // protected
  198. // cleanup
  199. void CMsrSampleStatus::Cleanup()
  200. {
  201. // need to do nothing at the moment
  202. m_listCpltedCenter.clear();
  203. }
  204. void CMsrSampleStatus::SetCompletedFieldsCenter(std::vector<CPoint>& a_listCpltedCenter)
  205. {
  206. m_listCpltedCenter.clear();
  207. for (auto pt: a_listCpltedCenter)
  208. {
  209. m_listCpltedCenter.push_back(pt);
  210. }
  211. }
  212. // initialization
  213. void CMsrSampleStatus::Init()
  214. {
  215. m_nStatus = DEFAULT_MSR_SAMPLE_STATUS;
  216. m_timeStart = COleDateTime();
  217. m_timeUsed = COleDateTimeSpan();
  218. m_timeEnd = COleDateTime();
  219. m_nCompletedFields = 0;
  220. m_listCpltedCenter.clear();
  221. }
  222. // duplication
  223. void CMsrSampleStatus::Duplicate(const CMsrSampleStatus& a_oSource)
  224. {
  225. // initialization
  226. Init();
  227. // copy data over
  228. m_nStatus = a_oSource.m_nStatus;
  229. m_timeStart = a_oSource.m_timeStart;
  230. m_timeUsed = a_oSource.m_timeUsed;
  231. m_timeEnd = a_oSource.m_timeEnd;
  232. m_nCompletedFields = a_oSource.m_nCompletedFields;
  233. for (auto pCpltedCenter : a_oSource.m_listCpltedCenter)
  234. {
  235. m_listCpltedCenter.push_back(pCpltedCenter);
  236. }
  237. }
  238. }