CMsrSampleStatus.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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.Point> m_listCpltedCenter = new List<System.Drawing.Point>();
  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. // completed fieldCenter
  137. public List<System.Drawing.Point> GetCompletedFieldsCenter()
  138. {
  139. return m_listCpltedCenter;
  140. }
  141. public void AddCompletedFieldCenter(Point p)
  142. {
  143. m_listCpltedCenter.Add(p);
  144. }
  145. public void SetCompletedFieldsCenter(List<System.Drawing.Point> a_listCpltedCenter)
  146. {
  147. // m_listCpltedCenter = a_listCpltedCenter;
  148. m_listCpltedCenter.Clear();
  149. foreach (var pt in a_listCpltedCenter)
  150. {
  151. m_listCpltedCenter.Add(pt);
  152. }
  153. }
  154. // current start time
  155. public DateTime GetStartTimeCur()
  156. {
  157. return m_timeStartCur;
  158. }
  159. public void SetStartTimeCur(DateTime a_timeStartCur)
  160. {
  161. a_timeStartCur = m_timeStartCur;
  162. }
  163. // compute time
  164. public bool ComputeTime(OTS_MSR_TIME_TYPE a_nType)
  165. {
  166. DateTime time = new DateTime();
  167. if (a_nType == OTS_MSR_TIME_TYPE.START)
  168. {
  169. if (m_timeStart == new DateTime())
  170. {
  171. m_timeStart = DateTime.Now; //OleDateTime.GetCurrentTime();
  172. m_timeStartCur = m_timeStart;
  173. m_timeUsedLast = m_timeUsed;
  174. }
  175. else
  176. {
  177. m_timeStartCur = DateTime.Now;
  178. m_timeUsedLast = m_timeUsed;
  179. }
  180. }
  181. else if (a_nType == OTS_MSR_TIME_TYPE.STOPPED)
  182. {
  183. // set current time as end time
  184. m_timeEnd =DateTime.Now;
  185. if (m_timeStartCur == m_timeStart)
  186. {
  187. // first compute time
  188. m_timeUsed = m_timeEnd - m_timeStart;
  189. }
  190. else
  191. {
  192. // not the first compute time
  193. m_timeUsed = m_timeEnd - m_timeStartCur + m_timeUsedLast;
  194. }
  195. }
  196. else if(a_nType == OTS_MSR_TIME_TYPE.COMPLT)
  197. {
  198. m_timeEnd = DateTime.Now;
  199. if (m_timeStartCur == m_timeStart)
  200. {
  201. // first compute time
  202. m_timeUsed = m_timeEnd - m_timeStart;
  203. }
  204. else
  205. {
  206. // not the first compute time
  207. m_timeUsed = m_timeEnd - m_timeStartCur + m_timeUsedLast;
  208. }
  209. }
  210. return true;
  211. }
  212. // duplication
  213. void Duplicate(CMsrSampleStatus a_oSource)
  214. {
  215. // copy data over
  216. m_nStatus = a_oSource.m_nStatus;
  217. m_timeStart = a_oSource.m_timeStart;
  218. m_timeUsed = a_oSource.m_timeUsed;
  219. m_timeEnd = a_oSource.m_timeEnd;
  220. //m_nCompletedFields = a_oSource.m_nCompletedFields;
  221. foreach (var pCpltedCenter in a_oSource.m_listCpltedCenter)
  222. {
  223. m_listCpltedCenter.Add(pCpltedCenter);
  224. }
  225. }
  226. }
  227. }