CMsrSampleStatus.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Drawing;
  8. namespace OTSDataType
  9. {
  10. public enum OTS_MSR_SAMPLE_STATUS
  11. {
  12. INVALID = -1,
  13. MIN = 0,
  14. UNMEASURED = 0,
  15. INPROCESS = 1,
  16. PAUSED=2,
  17. STOPPED = 3,
  18. FAILED = 4,
  19. SUCCESSED = 5,
  20. MAX = 5
  21. }
  22. public enum OTS_MSR_TIME_TYPE
  23. {
  24. MIN = 0,
  25. START = 1,
  26. STOPPED = 2,
  27. COMPLT = 3,
  28. MAX = 3
  29. }
  30. public class CMsrSampleStatus
  31. {
  32. //using namespace OTSDATA;
  33. const OTS_MSR_SAMPLE_STATUS DEFAULT_MSR_SAMPLE_STATUS = OTS_MSR_SAMPLE_STATUS.UNMEASURED;
  34. private OTS_MSR_SAMPLE_STATUS m_nStatus;
  35. DateTime m_timeStart = new DateTime();
  36. DateTime m_timeEnd = new DateTime();
  37. DateTime m_timeStartCur = new DateTime();
  38. TimeSpan m_timeUsed = new TimeSpan();
  39. TimeSpan m_timeUsedLast = new TimeSpan();
  40. List<System.Drawing.PointF> m_listCpltedCenter = new List<System.Drawing.PointF>();
  41. //int m_nCompletedFields;
  42. public CMsrSampleStatus()
  43. {
  44. Init();
  45. }
  46. void Init()
  47. {
  48. m_nStatus = DEFAULT_MSR_SAMPLE_STATUS;
  49. m_timeStart = new DateTime();
  50. m_timeUsed = new TimeSpan();
  51. m_timeEnd = new DateTime();
  52. //m_nCompletedFields = 0;
  53. m_listCpltedCenter.Clear();
  54. }
  55. // constructor
  56. public void CCMsrSampleStatus(CMsrSampleStatus a_oSource)
  57. {
  58. // can't copy itself
  59. if (a_oSource == this)
  60. {
  61. return;
  62. }
  63. Duplicate(a_oSource);
  64. }
  65. public CMsrSampleStatus(CMsrSampleStatus a_poSource)
  66. {
  67. // can't copy itself
  68. if (a_poSource == this)
  69. {
  70. return;
  71. }
  72. Duplicate(a_poSource);
  73. }
  74. public bool Equals(CMsrSampleStatus a_oSource) // CBSEImg& operator=(const CBSEImg&); // =operator
  75. {
  76. // return FASLE, if the two center list are in different size
  77. int nSize = m_listCpltedCenter.Count;
  78. if (nSize != a_oSource.m_listCpltedCenter.Count)
  79. {
  80. return false;
  81. }
  82. // return FALSE if any of the center are different
  83. for (int i = 0; i < nSize; ++i)
  84. {
  85. if (m_listCpltedCenter[i].Equals(a_oSource.m_listCpltedCenter[i]))
  86. {
  87. return false;
  88. }
  89. }
  90. return m_nStatus == a_oSource.m_nStatus &&
  91. m_timeStart == a_oSource.m_timeStart &&
  92. m_timeUsed == a_oSource.m_timeUsed &&
  93. m_timeStart == a_oSource.m_timeStart;
  94. }
  95. // status
  96. public OTS_MSR_SAMPLE_STATUS GetStatus()
  97. {
  98. return m_nStatus;
  99. }
  100. public void SetStatus(OTS_MSR_SAMPLE_STATUS a_nStatus)
  101. {
  102. m_nStatus = a_nStatus;
  103. }
  104. // start time
  105. public DateTime GetStartTime()
  106. {
  107. return m_timeStart;
  108. }
  109. public void SetStartTime(DateTime a_timeStart)
  110. {
  111. m_timeStart = a_timeStart;
  112. }
  113. // used time
  114. public TimeSpan GetUsedTime()
  115. {
  116. return m_timeUsed;
  117. }
  118. public void SetUsedTime(TimeSpan a_timeUsed)
  119. {
  120. m_timeUsed = a_timeUsed;
  121. }
  122. // end time
  123. public DateTime GetEndTime()
  124. {
  125. return m_timeEnd;
  126. }
  127. public void SetEndTime(DateTime a_timeEnd)
  128. {
  129. m_timeEnd = a_timeEnd;
  130. }
  131. // completed fields
  132. public int GetCompletedFields()
  133. {
  134. return m_listCpltedCenter.Count;
  135. }
  136. public void ClearCompletedFieldsInfo()
  137. {
  138. m_listCpltedCenter.Clear();
  139. }
  140. // completed fieldCenter
  141. public List<System.Drawing.PointF> GetCompletedFieldsCenter()
  142. {
  143. return m_listCpltedCenter;
  144. }
  145. public void AddCompletedFieldCenter(PointF p)
  146. {
  147. m_listCpltedCenter.Add(p);
  148. }
  149. public void SetCompletedFieldsCenter(List<System.Drawing.PointF> a_listCpltedCenter)
  150. {
  151. // m_listCpltedCenter = a_listCpltedCenter;
  152. m_listCpltedCenter.Clear();
  153. foreach (var pt in a_listCpltedCenter)
  154. {
  155. m_listCpltedCenter.Add(pt);
  156. }
  157. }
  158. // current start time
  159. public DateTime GetStartTimeCur()
  160. {
  161. return m_timeStartCur;
  162. }
  163. public void SetStartTimeCur(DateTime a_timeStartCur)
  164. {
  165. a_timeStartCur = m_timeStartCur;
  166. }
  167. // compute time
  168. public bool ComputeTime(OTS_MSR_TIME_TYPE a_nType)
  169. {
  170. //DateTime time = new DateTime();
  171. if (a_nType == OTS_MSR_TIME_TYPE.START)
  172. {
  173. if (m_timeStart == new DateTime())
  174. {
  175. m_timeStart = DateTime.Now; //OleDateTime.GetCurrentTime();
  176. m_timeStartCur = m_timeStart;
  177. m_timeUsedLast = m_timeUsed;
  178. }
  179. else
  180. {
  181. m_timeStartCur = DateTime.Now;
  182. m_timeUsedLast = m_timeUsed;
  183. }
  184. }
  185. else if (a_nType == OTS_MSR_TIME_TYPE.STOPPED)
  186. {
  187. // set current time as end time
  188. m_timeEnd =DateTime.Now;
  189. if (m_timeStartCur == m_timeStart)
  190. {
  191. // first compute time
  192. m_timeUsed = m_timeEnd - m_timeStart;
  193. }
  194. else
  195. {
  196. // not the first compute time
  197. m_timeUsed = m_timeEnd - m_timeStartCur + m_timeUsedLast;
  198. }
  199. }
  200. else if(a_nType == OTS_MSR_TIME_TYPE.COMPLT)
  201. {
  202. m_timeEnd = DateTime.Now;
  203. if (m_timeStartCur == m_timeStart)
  204. {
  205. // first compute time
  206. m_timeUsed = m_timeEnd - m_timeStart;
  207. }
  208. else
  209. {
  210. // not the first compute time
  211. m_timeUsed = m_timeEnd - m_timeStartCur + m_timeUsedLast;
  212. }
  213. }
  214. return true;
  215. }
  216. // duplication
  217. void Duplicate(CMsrSampleStatus a_oSource)
  218. {
  219. // copy data over
  220. m_nStatus = a_oSource.m_nStatus;
  221. m_timeStart = a_oSource.m_timeStart;
  222. m_timeUsed = a_oSource.m_timeUsed;
  223. m_timeEnd = a_oSource.m_timeEnd;
  224. //m_nCompletedFields = a_oSource.m_nCompletedFields;
  225. foreach (var pCpltedCenter in a_oSource.m_listCpltedCenter)
  226. {
  227. m_listCpltedCenter.Add(pCpltedCenter);
  228. }
  229. }
  230. }
  231. }