CMsrSampleStatus.cs 7.0 KB

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