MsrSampleStatus.cpp 5.8 KB

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