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 m_listCpltedCenter = new List(); //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 GetCompletedFieldsCenter() { return m_listCpltedCenter; } public void AddCompletedFieldCenter(PointF p) { m_listCpltedCenter.Add(p); } public void SetCompletedFieldsCenter(List 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); } } } }