123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Drawing;
- namespace OTSDataType
- {
- public enum OTS_MSR_SAMPLE_STATUS
- {
- INVALID = -1,
- MIN = 0,
- UNMEASURED = 0,
- INPROCESS = 1,
- PAUSED=2,
- STOPPED = 3,
- FAILED = 4,
- SUCCESSED = 5,
- MAX = 5
- }
- public enum OTS_MSR_TIME_TYPE
- {
- MIN = 0,
- START = 1,
- STOPPED = 2,
- COMPLT = 3,
- MAX = 3
- }
- public class CMsrSampleStatus
- {
- //using namespace OTSDATA;
- const OTS_MSR_SAMPLE_STATUS DEFAULT_MSR_SAMPLE_STATUS = OTS_MSR_SAMPLE_STATUS.UNMEASURED;
- private OTS_MSR_SAMPLE_STATUS m_nStatus;
- DateTime m_timeStart = new DateTime();
- DateTime m_timeEnd = new DateTime();
- DateTime m_timeStartCur = new DateTime();
- TimeSpan m_timeUsed = new TimeSpan();
- TimeSpan m_timeUsedLast = new TimeSpan();
- List<System.Drawing.PointF> m_listCpltedCenter = new List<System.Drawing.PointF>();
- //int m_nCompletedFields;
- public CMsrSampleStatus()
- {
- Init();
- }
- void Init()
- {
- m_nStatus = DEFAULT_MSR_SAMPLE_STATUS;
- m_timeStart = new DateTime();
- m_timeUsed = new TimeSpan();
- m_timeEnd = new DateTime();
- //m_nCompletedFields = 0;
- m_listCpltedCenter.Clear();
- }
- // constructor
- public void CCMsrSampleStatus(CMsrSampleStatus a_oSource)
- {
- // can't copy itself
- if (a_oSource == this)
- {
- return;
- }
- Duplicate(a_oSource);
- }
- public CMsrSampleStatus(CMsrSampleStatus a_poSource)
- {
- // can't copy itself
- if (a_poSource == this)
- {
- return;
- }
- Duplicate(a_poSource);
- }
- public bool Equals(CMsrSampleStatus a_oSource) // CBSEImg& operator=(const CBSEImg&); // =operator
- {
- // return FASLE, if the two center list are in different size
- int nSize = m_listCpltedCenter.Count;
- if (nSize != a_oSource.m_listCpltedCenter.Count)
- {
- return false;
- }
- // return FALSE if any of the center are different
- for (int i = 0; i < nSize; ++i)
- {
- if (m_listCpltedCenter[i].Equals(a_oSource.m_listCpltedCenter[i]))
- {
- return false;
- }
- }
- return m_nStatus == a_oSource.m_nStatus &&
- m_timeStart == a_oSource.m_timeStart &&
- m_timeUsed == a_oSource.m_timeUsed &&
- m_timeStart == a_oSource.m_timeStart;
-
- }
- // status
- public OTS_MSR_SAMPLE_STATUS GetStatus()
- {
- return m_nStatus;
- }
- public void SetStatus(OTS_MSR_SAMPLE_STATUS a_nStatus)
- {
- m_nStatus = a_nStatus;
- }
- // start time
- public DateTime GetStartTime()
- {
- return m_timeStart;
- }
- public void SetStartTime(DateTime a_timeStart)
- {
- m_timeStart = a_timeStart;
- }
- // used time
- public TimeSpan GetUsedTime()
- {
- return m_timeUsed;
- }
- public void SetUsedTime(TimeSpan a_timeUsed)
- {
- m_timeUsed = a_timeUsed;
- }
- // end time
- public DateTime GetEndTime()
- {
- return m_timeEnd;
- }
- public void SetEndTime(DateTime a_timeEnd)
- {
- m_timeEnd = a_timeEnd;
- }
- // completed fields
- public int GetCompletedFields()
- {
- return m_listCpltedCenter.Count;
- }
- public void ClearCompletedFieldsInfo()
- {
- m_listCpltedCenter.Clear();
- m_timeStart = new DateTime();
- }
- // completed fieldCenter
- public List<System.Drawing.PointF> GetCompletedFieldsCenter()
- {
- return m_listCpltedCenter;
- }
- public void AddCompletedFieldCenter(PointF p)
- {
- m_listCpltedCenter.Add(p);
- }
- public void SetCompletedFieldsCenter(List<System.Drawing.PointF> a_listCpltedCenter)
- {
-
- m_listCpltedCenter.Clear();
- foreach (var pt in a_listCpltedCenter)
- {
- m_listCpltedCenter.Add(pt);
- }
- }
-
- // compute time
- public bool ComputeTime(OTS_MSR_TIME_TYPE a_nType)
- {
- //DateTime time = new DateTime();
- if (a_nType == OTS_MSR_TIME_TYPE.START)
- {
- if (m_timeStart == new DateTime())
- {
- m_timeStart = DateTime.Now; //OleDateTime.GetCurrentTime();
- m_timeStartCur = m_timeStart;
- m_timeUsedLast = m_timeUsed;
- }
- else
- {
- m_timeStartCur = DateTime.Now;
- m_timeUsedLast = m_timeUsed;
- }
- }
- else if (a_nType == OTS_MSR_TIME_TYPE.STOPPED)
- {
- // set current time as end time
- m_timeEnd =DateTime.Now;
-
- if (m_timeStartCur == m_timeStart)
- {
- // first compute time
- m_timeUsed = m_timeEnd - m_timeStart;
- }
- else
- {
- // not the first compute time
- m_timeUsed = m_timeEnd - m_timeStartCur + m_timeUsedLast;
- }
-
- }
- else if(a_nType == OTS_MSR_TIME_TYPE.COMPLT)
- {
- m_timeEnd = DateTime.Now;
- if (m_timeStartCur == m_timeStart)
- {
- // first compute time
- m_timeUsed = m_timeEnd - m_timeStart;
- }
- else
- {
- // not the first compute time
- m_timeUsed = m_timeEnd - m_timeStartCur + m_timeUsedLast;
- }
-
- }
- return true;
- }
- // duplication
- void Duplicate(CMsrSampleStatus a_oSource)
- {
- // copy data over
- m_nStatus = a_oSource.m_nStatus;
- m_timeStart = a_oSource.m_timeStart;
- m_timeUsed = a_oSource.m_timeUsed;
- m_timeEnd = a_oSource.m_timeEnd;
- //m_nCompletedFields = a_oSource.m_nCompletedFields;
- foreach (var pCpltedCenter in a_oSource.m_listCpltedCenter)
- {
- m_listCpltedCenter.Add(pCpltedCenter);
- }
- }
-
- }
- }
|