CMsrSampleStatus.cs 6.9 KB

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