Browse Source

add missing files

gsp 4 years ago
parent
commit
ee1b8b0066

+ 450 - 0
OTSIncAMeasureApp/1-OTSMeasure/CMeasureThreadWrapper.cs

@@ -0,0 +1,450 @@
+using System;
+using System.ComponentModel;
+using OTSModelSharp;
+using OTSDataType;
+using System.Collections.Generic;
+using static OTSDataType.otsdataconst;
+using System.Drawing;
+
+namespace OTSMeasureApp
+{
+    public class CMeasureThreadWrapper 
+    {
+        #region 变量生成汇总
+        //后台线程
+        public static System.ComponentModel.BackgroundWorker m_bgWorker;
+  
+        OTSIncAMeasureAppForm m_MeasureApp = null;
+        OTSMeasureDisplayResult m_OTSMeasureResult = null;
+        //测量线程类
+        CMsrThread m_MsrThread = null;
+
+        //线程执行类型 1:测量 2:获取样品孔图片
+        public static int DoRunType = 1;
+        public static int m_HoleID;
+        public static CDomain c_DomainMessure;
+        NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
+        #endregion
+        COTSMsrPrjResultData m_ProjData;
+        #region 构造方法
+        public CMeasureThreadWrapper(OTSIncAMeasureAppForm MeasureApp)
+        {
+            m_ProjData = MeasureApp.m_ProjData;
+            m_MeasureApp = MeasureApp;
+            m_bgWorker = new BackgroundWorker();
+            //设置报告更新是否可用
+            m_bgWorker.WorkerReportsProgress = true;
+            //设置支持取消操作是否可用
+            m_bgWorker.WorkerSupportsCancellation = true;
+            m_bgWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
+
+            m_bgWorker.WorkerSupportsCancellation = true;
+           
+            m_OTSMeasureResult = new OTSMeasureDisplayResult(m_MeasureApp,m_bgWorker);
+
+            m_MsrThread = new CMsrThread();
+            m_MsrThread.ProgressEvent += M_MsrThread_ProgressEvent;
+         
+
+        }
+        #endregion
+        #region 设置线程类型
+        /// <summary>
+        /// 设置线程类型
+        /// </summary>
+        /// <param name="doRunType">线程执行类型 1:测量类型 2:获取样品孔图片类型</param>
+        public void SetDoRunType(int doRunType)
+        {
+            DoRunType = doRunType;
+        }
+        #endregion
+        #region 设置获取样品孔中照片所需的参数
+        /// <summary>
+        /// 设置获取样品孔中照片所需的参数
+        /// </summary>
+        /// <param name="HoleID">样品孔编号的序号</param>
+        /// <param name="DomainMessure">测量区域属性对象</param>
+        public void SetHoleImagePreview(int HoleID, CDomain DomainMessure)
+        {
+            //样品孔编号的序号
+            m_HoleID = HoleID;
+            //测量区域属性对象
+            c_DomainMessure = DomainMessure;
+        }
+        #endregion
+        #region 启动测量线程
+        public void StartBGWorkThread()
+        {
+            m_bgWorker.RunWorkerAsync();
+        }
+        #endregion
+
+        #region 线程是否在运行
+        /// <summary>
+        ///  True:  线程正在运行
+        /// </summary>
+        /// <returns></returns>
+        public bool BGWorkThreadIsRunning()
+        {
+
+            if (m_bgWorker.IsBusy)
+            {
+                return true;
+            }
+            return false;
+        }
+        #endregion
+
+        #region 判断线程挂起状态
+        /// <summary>
+        /// True:  线程挂起状态
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        bool WorkThreadIsPending()
+        {
+            return m_bgWorker.CancellationPending;
+        }
+        #endregion
+
+        #region 线程挂起
+        /// <summary>
+        /// 线程挂起
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        public void SetWorkThreadPending()
+        {
+            m_bgWorker.CancelAsync();
+            m_bgWorker = null;
+        }
+    
+        #endregion
+
+
+        #region 后台进程开始工作_DoWork
+        /// <summary>
+        /// 后台进程开始工作        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
+        {
+            if (DoRunType == (int)MSR_THREAD_RunSTATUS.RUNMEASURE)
+            {
+                InitMeasureThread(m_MeasureApp.m_ProjData);
+
+                m_MsrThread.SetMsrLoopStatus(otsdataconst.OTS_MSR_THREAD_STATUS.INPROCESS);
+                m_MsrThread.DoMeasure();
+              
+            }
+            else if (DoRunType == (int)MSR_THREAD_RunSTATUS.RUNSampleHoleImage)
+            {
+                InitMeasureThread(m_MeasureApp.m_ProjData);
+
+                SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.INPROCESS);
+                DoHolePreview(m_HoleID, c_DomainMessure);
+            }
+        }
+
+   
+        public void InitMeasureThread(COTSMsrPrjResultData a_ProjData)
+        {
+          
+                m_ProjData = a_ProjData;
+                m_MsrThread.Init(m_ProjData);
+              
+          
+
+        }
+
+        private void M_MsrThread_ProgressEvent(OTSModelSharp.ST_MSTMsg msg)
+        {
+           AddMeasureMsg(msg);
+        }
+        private void AddMeasureMsg(OTSModelSharp.ST_MSTMsg MSTMsg)
+        {
+          
+            ShowCurrentFieldPointMessage(MSTMsg.STMSampleRetData.SMsrField.FieldPos);
+          
+            switch (MSTMsg.iMsgType)
+            {
+                case OTSModelSharp.ENUM_MSG_TYPE.MTHREADSTATUS:
+                    if (MSTMsg.STMThreadStu.iMsrStatu == otsdataconst.OTS_MSR_THREAD_STATUS.INPROCESS)
+                    {
+
+                        StartMeasure(MSTMsg);
+                    }
+                    else if (MSTMsg.STMThreadStu.iMsrStatu == otsdataconst.OTS_MSR_THREAD_STATUS.STOPPED)
+                    {
+                        string csETime = MSTMsg.STMThreadStu.csMsrEndTime;
+                        StopMeasure(MSTMsg);
+
+                    }
+                    else if (MSTMsg.STMThreadStu.iMsrStatu == otsdataconst.OTS_MSR_THREAD_STATUS.FAILED)
+                    {
+
+                        StopMeasure(MSTMsg);
+                        log.Error("(OTSGetMreRetThread)  MSTMsg.STMThreadStu.iMThreadStatus = RET_MEASURE_THREAD_STATUS.FAILED");
+
+
+                    }
+                    else if (MSTMsg.STMThreadStu.iMsrStatu == otsdataconst.OTS_MSR_THREAD_STATUS.COMPLETED)
+                    {
+
+                        StopMeasure(MSTMsg);
+
+                    }
+                    else
+                    {
+                        log.Error("(OTSGetMreRetThread) MSTMsg.STMThreadStu.iMThreadStatus =" + MSTMsg.STMThreadStu.iMsrStatu.ToString() + "Failed");
+                    }
+                    break;
+
+                case OTSModelSharp.ENUM_MSG_TYPE.MSAMPLESTATUS:
+                    if (MSTMsg.STMSampleStu.iMsrSampleStatu == OTSDataType.OTS_MSR_SAMPLE_STATUS.INPROCESS)   // 开始测量样品
+                    {
+                        string csName = MSTMsg.STMSampleStu.cSampleName;
+                        m_MeasureApp.SwitchMeasureSample(csName);
+
+                        StartMsrSample(MSTMsg);
+
+                    }
+                    else if (MSTMsg.STMSampleStu.iMsrSampleStatu == OTSDataType.OTS_MSR_SAMPLE_STATUS.STOPPED)
+                    {
+
+                    }
+                    else if (MSTMsg.STMSampleStu.iMsrSampleStatu == OTSDataType.OTS_MSR_SAMPLE_STATUS.FAILED)
+                    {
+                        log.Error("(OTSGetMreRetThread) MSTMsg.STMSampleStu.iMeasureSampleStatus = RET_MEASURE_SAMPLE_STATUS.FAILED Failed");
+
+                    }
+                    else if (MSTMsg.STMSampleStu.iMsrSampleStatu == OTSDataType.OTS_MSR_SAMPLE_STATUS.SUCCESSED)
+                    {
+
+                    }
+                    else
+                    {
+                        log.Error("(OTSGetMreRetThread) MSTMsg.STMSampleStu.iMeasureSampleStatus =" + MSTMsg.STMSampleStu.iMsrSampleStatu.ToString() + "Failed");
+                    }
+                    break;
+                case OTSModelSharp.ENUM_MSG_TYPE.MSAMPLERESULT:
+                    if (MSTMsg.STMSampleRetData.iRetDataType == OTSModelSharp.MSAMPLE_RET.BSE_DATA)
+                    {
+                        int iHeight = MSTMsg.STMSampleRetData.BSEData.iBSEDataHeight;
+                        int iWidth = MSTMsg.STMSampleRetData.BSEData.iBSEDataWidth;
+
+                        if (iHeight > 0 && iWidth > 0)
+                        {
+
+                            GetBSEData(MSTMsg);
+
+                        }
+                        else
+                        {
+                            log.Error("(OTSGetMreRetThread) BSEDataHeight = " + iHeight.ToString() + "BSEDataWidth = " + iWidth.ToString() + " Failed");
+                        }
+                    }
+                    else if (MSTMsg.STMSampleRetData.iRetDataType == OTSModelSharp.MSAMPLE_RET.FIELD_DATA)
+                    {
+                        GetFiledData(MSTMsg);
+                    }
+
+                    else if (MSTMsg.STMSampleRetData.iRetDataType == OTSModelSharp.MSAMPLE_RET.START_MSR_FIELD)
+                    {
+                        GetStartMsrField(MSTMsg);
+                    }
+                    else
+                    {
+                        log.Error("(OTSGetMreRetThread) MSTMsg.STMSampleRetData.iRetDataType =" + MSTMsg.STMSampleRetData.iRetDataType.ToString() + "Failed");
+                    }
+                    break;
+
+            }
+        }
+        #region privte part
+        private void StartMeasure(ST_MSTMsg SMsrData)
+        {
+            m_MeasureApp.SetStartMeasureRibbonStatus();
+
+           GetMsrRetData(ref SMsrData.STMThreadStu.SMsrCompleteData);
+
+            m_OTSMeasureResult.RunMeasureState(SMsrData);
+
+        }
+
+
+        private void ShowCurrentFieldPointMessage(Point currPoint)
+        {
+            //当前测量帧图视场坐标---------------------------------------------------------------------------------------
+
+            Point lsp = currPoint;
+            if (lsp.X != 0 || lsp.Y != 0)
+            {
+                string STSemCoordinate = "当前帧坐标 X:" + lsp.X.ToString() + " Y:" + lsp.Y.ToString();
+
+                //显示当前视场 XY轴
+                m_MeasureApp.ShowSemCoordvAL(STSemCoordinate);
+            }
+            //------------------------------------------------------------------------------------------------------------
+        }
+
+        //处理测量线程停止消息
+        private void StopMeasure(ST_MSTMsg SMsrData)
+        {
+            m_MeasureApp.SetStopMeasureRibbonStatus();
+
+            GetMsrRetData(ref SMsrData.STMThreadStu.SMsrCompleteData);
+
+            m_OTSMeasureResult.RunMeasureState(SMsrData);
+        }
+
+        private void GetBSEData(ST_MSTMsg SMsrData)
+        {
+
+
+            m_OTSMeasureResult.RunMeasureState(SMsrData);
+        }
+
+        private void GetFiledData(ST_MSTMsg SMsrData)
+        {
+
+            this.GetSMsrUsedTime(ref SMsrData.STMSampleRetData.SFieldData.TUsedTime);
+
+            m_OTSMeasureResult.RunMeasureState(SMsrData);
+        }
+
+        private void GetStartMsrField(ST_MSTMsg SMsrData)
+        {
+
+
+            m_OTSMeasureResult.RunMeasureState(SMsrData);
+        }
+
+        private void StartMsrSample(ST_MSTMsg SMsrData)
+        {
+            DateTime SampleMsrStartTime = new DateTime();
+
+            m_MeasureApp.m_ProjParam.GetMsrSampleStartTime(ref SampleMsrStartTime);
+            SMsrData.STMSampleStu.csSampleMsrStartTime = SampleMsrStartTime.ToString("yyyy-MM-dd HH:mm:ss");
+            string csSName = "";
+            List<Point> FieldList = new List<Point>();
+            m_MeasureApp.m_ProjParam.GetBeforeCompleteField(ref csSName, ref FieldList);
+            string csSampleName = SMsrData.STMSampleStu.cSampleName;
+            if (csSName == csSampleName)
+            {
+                SMsrData.STMSampleStu.BCompleteFieldList = FieldList;
+            }
+
+            m_OTSMeasureResult.RunMeasureState(SMsrData);
+
+        }
+
+        private void GetSMsrUsedTime(ref TimeSpan MsrUsedTime)
+        {
+            TimeSpan UsedTime = new TimeSpan();
+            if (!m_MeasureApp.m_ProjParam.GetMsrSampleUsedTime(ref UsedTime))
+            {
+                return;
+            }
+
+            MsrUsedTime = UsedTime;
+        }
+        #endregion
+        public void InitMeasureSample()
+        {
+
+            m_MsrThread.Init(m_ProjData);
+          
+
+          
+            return ;
+        }
+        public void InitHolePreview()
+        {
+            m_MsrThread.Init(m_ProjData);
+          
+            m_MsrThread.ProgressEvent += M_MsrThread_ProgressEvent;
+           
+            return ;
+        }
+        public void DoHolePreview(int m_HoleID, CDomain c_DomainMessure)
+        {
+            m_MsrThread.DoHolePreview(m_HoleID, c_DomainMessure);
+        }
+        // 开始样品测量
+       
+        //停止测量
+        public void SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS ThreadStatus)
+        {
+            //设置测量线程状态
+            m_MsrThread.SetMsrLoopStatus(ThreadStatus);
+        }
+
+
+        #endregion
+
+        public bool GetMsrRetData(ref SMSR_COMPLETE_DATA MsrCompleteData)
+        {
+            try
+            {
+            
+
+                List<COTSSample> MeasureCompleteSampleList = new List<COTSSample>();
+                if (!m_ProjData.GetMsredSampleList(ref MeasureCompleteSampleList))
+                {
+                    return false;
+                }
+
+
+                DateTime DTime = new DateTime();
+                if (m_MsrThread.GetMsrThreadStatus() == null)
+                {
+                    return false;
+                }
+                if (m_MsrThread.GetMsrThreadStatus().GetStartTime() == null)
+                {
+                    return false;
+                }
+                DTime = (DateTime)m_MsrThread.GetMsrThreadStatus().GetStartTime();
+                MsrCompleteData.csMsrStartTime = DTime.ToString("yyyy-MM-dd HH:mm:ss");
+
+                MsrCompleteData.MsrUsedTime = (TimeSpan)m_MsrThread.GetMsrThreadStatus().GetUsedTime();
+
+                DTime = (DateTime)m_MsrThread.GetMsrThreadStatus().GetEndTime();
+                MsrCompleteData.csMsrEndTime = DTime.ToString("yyyy-MM-dd HH:mm:ss");
+
+                MsrCompleteData.iMsrCompleteSampleCount = MeasureCompleteSampleList.Count;
+
+                MsrCompleteData.iMsrCompleteFieldCount = 0;
+                MsrCompleteData.iParticleCount = 0;
+                for (int i = 0; i < MsrCompleteData.iMsrCompleteSampleCount; i++)
+                {
+                    MsrCompleteData.iMsrCompleteFieldCount += MeasureCompleteSampleList[i].GetMsrStatus().GetCompletedFields();
+                    List<CMsrResultItem> MsrRetClr = MeasureCompleteSampleList[i].GetMsrResults().GetResultItems();
+                    for (int k = 0; k < MsrRetClr.Count; k++)
+                    {
+                        MsrCompleteData.iParticleCount += (int)MsrRetClr[k].GetNumber();
+                    }
+                }
+
+                return true;
+            }
+            catch (Exception ex)
+            {
+             
+                return false;
+            }
+        }
+
+        internal void freeHw()
+        {
+            var sem = m_MsrThread.GetSEMController();
+            var hw = sem.GetHardwareInterface();
+           
+          
+           
+            hw.FreeHardware();
+            
+        }
+    }
+}

+ 1659 - 0
OTSIncAMeasureApp/2-OTSMeasureParamManage/COTSMeasureParam.cs

@@ -0,0 +1,1659 @@
+using OTSModelSharp;
+using OTSDataType;
+using NSOTSController;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.IO;
+
+using OTSModelSharp.ResourceManage;
+using static OTSModelSharp.ResourceManage.ResourceID;
+using static OTSModelSharp.ResourceManage.ResourceData;
+using static OTSDataType.otsdataconst;
+using System.Windows.Forms;
+
+namespace OTSMeasureApp
+{
+
+    public enum OTS_SOFT_PACKAGE_ID
+    {
+        OTSIncA = 0,             //夹杂物分析
+        OTSPartA = 1,            //颗粒度分析
+    };
+
+    //文件保存返回的结果,DataMgr返回
+    public enum OTS_SAVE_FILE_REV
+    {
+        SaveFile_Success = 0,
+        SaveFile_Cancel = 1,
+        SaveFile_Failed = 2,
+        SaveFile_NoNedd = 3      //文件不需要保存
+    }
+
+ 
+
+    //设置线程状态
+    public enum MSR_THREAD_RunSTATUS
+    {
+        RUNMEASURE = 1,         //开始测量
+        RUNSampleHoleImage = 2  //运行获取样品孔照片
+    };
+    enum SAMPLE_FAULT_WARN_CODE
+    {
+        INVALID = -1,
+        MIN = 0,
+        SEM_DATA_ERROR = 0,
+        AREA_OUTSIDE_HOLE = 1,
+        RESOLUTION_LOW = 2,
+        FINISHED = 3,
+        NO_ERROR_WARNING = 4,
+        FILE_NOT_SAVED = 5,
+        MAX = 5
+    };
+    enum SAMPLE_CHECK_RESULT_TYPE
+    {
+        INVALID = -1,
+        MIN = 0,
+        SWITCH_ON = 0,
+        FINISHED = 1,
+        SETTING_ERROR = 2,
+        SETTING_WARNING = 3,
+        MEASURABLE = 4,
+        NO_ERROR_WARNING = 5,
+        MAX = 5
+    };
+    public class COTSMeasureParam 
+    {
+        OTSIncAMeasureAppForm m_MeasureAppFrom = null;
+
+
+        /// <summary></summary>
+        /// <remarks>创建</remarks>
+        public COTSMsrPrjResultData m_ResultData;
+
+
+
+        //参数文件
+        public COTSDefaultParam m_DefaultParam = null;
+        //样品台文件(读取样品台数据等)                            
+        public CStageParam m_StageParam = null;
+  
+        //测量样品链表
+        List<COTSSample> m_MeasureSampleList = new List<COTSSample>();
+
+        NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
+
+        public COTSMeasureParam(OTSIncAMeasureAppForm MeasureApp)
+        {
+            m_MeasureAppFrom = MeasureApp;
+           
+            m_ResultData = new COTSMsrPrjResultData();
+
+
+        }
+
+      
+
+
+
+        //检查参数文件是否存在
+        public bool LoadParamFile()
+        {
+            //加载样品参数文件:   \Config\SysData\OTSProgMgrParam.pmf
+            m_DefaultParam = new COTSDefaultParam();
+            m_DefaultParam.LoadInfoFromProgMgrFile();
+            if (null == m_DefaultParam)
+            {
+                return false;
+            }
+
+
+            return true;
+        }
+
+        //检查参数样品台文件是否存在
+        public bool LoadStageParamFile()
+        {
+            m_StageParam = new CStageParam();
+            // 加载样品台文件;  \Config\SysData\OTSStage.stg
+            if (!m_StageParam.Load(true, false))
+            {
+                return false;
+            }
+
+            return true;
+        }
+
+
+
+        //获取系统文件是否存在和有效
+      
+        public bool InitResultData(bool bNewFileFlag = true)
+        {
+            //打开文件,则文件中保存有样品台信息,不需要使用系统样品名信息
+            if (bNewFileFlag)
+            {
+
+                //设置样品台参数
+                CStage Stage = m_StageParam.GetWorkingStage();
+                if (null == Stage)
+                {
+                    return false;
+                }
+                m_ResultData.SetStage(Stage);
+                
+
+                // 设置 SEM stage data
+                CSEMStageData SEMData = m_DefaultParam.GetStageDataParam();
+                if (null == SEMData)
+                {
+                    return false;
+                }
+                m_ResultData.SetSEMStageData(SEMData);
+            }
+
+            //设置 general parameter
+            COTSGeneralParam GenParam = m_DefaultParam.GetGenParam();
+            if (null == GenParam)
+            {
+                return false;
+            }
+            m_ResultData.SetGenParam(GenParam);
+
+
+
+            if (bNewFileFlag)
+            {
+                m_ResultData.SetPathName("Untitled");
+             
+            }
+
+            m_ResultData.m_nPackId = m_DefaultParam.m_nPackId;
+
+
+            return true;
+        }
+
+       
+
+        //新建样品工作文件 0:报错 1:正常 2:取消
+        public int CreateNewFile()
+        {
+            if (m_ResultData.IsModified())    // 文件被修改
+            {
+                int iRev = m_MeasureAppFrom.ShowSaveInfoMsgBox();
+                if ((int)MessageBoxRev.DIALOG_YES == iRev)
+                {
+                    if (!m_ResultData.Save())
+                    {
+
+                        return 0;
+                    }
+                }
+                else if((int)MessageBoxRev.DIALOG_CANCEL == iRev)
+                {
+                    return 2;
+                }
+            }
+
+            //新建新的工作文件
+            //重新生成一个工作文件对象
+            COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();
+            m_ResultData.SetPathName("Untitled");
+          
+
+            m_ResultData = ProjDataMgr;
+            this.LoadStageParamFile();
+           
+            if (!this.InitResultData())
+            {
+                return 0;
+            }
+
+            return 1;
+        }
+
+
+
+
+ 
+
+        //将样品台坐标转换为Sem 坐标
+        public Point ChangeOTSToSemCoord(Point POTSCoord)
+        {
+            System.Drawing.Point VSemCoord = new System.Drawing.Point();
+            m_DefaultParam.GetStageDataParam().ConverOTSToSEMPoint(POTSCoord, ref VSemCoord);
+            return (Point)VSemCoord;
+        }
+
+        //将Sem 坐标转换为样品台坐标
+        public Point ConverSEMToOTSPoint(Point PSEMCoord)
+        {
+            System.Drawing.Point VOTSCoord = new System.Drawing.Point();
+            m_DefaultParam.GetStageDataParam().ConverSEMToOTSPoint(PSEMCoord, ref VOTSCoord);
+            return (Point)VOTSCoord;
+        }
+
+        //添加样品
+        //string sSHoleName:  样品孔名,当在样品孔上点击右键添加样品时,sSHoleName=样品孔名。当MEASUREAPP和TREEVIEW添加样品时,sSHoleName=""
+        //返回新的工作样品名称
+        public OTSSamplePropertyInfo AddNewSampleMeasure(string a_strHoleName = "")
+        {
+
+            COTSSample NewSample = new COTSSample();
+            SetSampleDefaultPara(ref NewSample, a_strHoleName);
+            //NewSample.
+            //添加样品
+            m_ResultData.AddSample(NewSample);
+
+          
+            // 获取样品的属性值
+            OTSSamplePropertyInfo MeasureInfo = new OTSSamplePropertyInfo();
+            if (!GetWorkSamplePerameter(NewSample, ref MeasureInfo))
+            {
+                return null;
+            }      
+
+            return MeasureInfo;
+        }
+        protected COTSSample SetSampleDefaultPara(ref COTSSample pSample, String a_strHoleName)
+        {
+            // get new sample name
+            String strNewSampleName = GetNewSampleName();
+
+            // make sure the new sample name is not an empty string
+            strNewSampleName.Trim();
+
+
+            // get a suitable sample hole for the new sample
+            CHole pHole = SelectASmpleHole(a_strHoleName);
+
+            // check the sample hole
+            if (pHole == null)
+            {
+                // failed to get sample hole for the new sample
+
+                return null;
+            }
+            // measurement area 	
+            CDomain pMsrArea = CalculateDefaultArea(pHole);
+            // measure data parameters containing particle analysis std, image scan parameter, image process parameter and x-ray parameter 
+            CSampleParam poMsrParams = new CSampleParam();
+            poMsrParams.m_nPackId = m_DefaultParam.m_nPackId;
+            poMsrParams.m_runmode = m_DefaultParam.m_runmode;
+            var m_pParam = m_DefaultParam.GetGenParam();
+            MEMBRANE_TYPE a_nVal = (MEMBRANE_TYPE)m_pParam.GetMembraneType();
+            poMsrParams.SetImageScanParam(m_DefaultParam.GetImageScanParam ());
+            poMsrParams.SetImageProcessParam(m_DefaultParam.GetImageProcParam()); 
+            poMsrParams.SetXRayParam(m_DefaultParam.GetXRayParam());
+            String sSTDName = m_pParam.GetSTDSelect();
+            poMsrParams.SetSTDName(sSTDName);
+            poMsrParams.SetSteelTechnology((STEEL_TECHNOLOGY)m_pParam.GetSteelTechnology());
+            // set sample parameters
+            pSample.SetName(strNewSampleName);
+            pSample.SetSampleHoleName(pHole.GetName());
+            pSample.SetSwitch(m_pParam.GetMeasurementSwitch());
+            pSample.SetSysSTDSwitch(m_pParam.GetSysSTD());
+            pSample.SetMsrArea(pMsrArea);
+            pSample.SetMembraneType(a_nVal);
+            pSample.SetMsrParams(poMsrParams);
+            CSEMDataMsr semData = new CSEMDataMsr();
+            var m_pSEMStageData = m_DefaultParam.GetStageDataParam();
+            semData.SetScanFieldSize100(m_pSEMStageData.GetScanFieldSize100());
+            pSample.SetSEMDataMsr(semData);
+
+            return pSample;
+        }
+        public String GetNewSampleName()
+        {
+            // new sample name
+            String strNewSmplName = "";
+
+            // safety check
+            var m_pParam = m_DefaultParam.GetGenParam();
+            if (m_pParam == null)
+            {
+                // shouldn't happen, invalid general parameter pointer.
+
+                return strNewSmplName;
+            }
+
+            // new sample name base
+            String strNewSmplNameBase = m_pParam.GetSampleName() + @"{0}";
+            int nIndex = 1;
+
+            do
+            {
+                // new sample name is new sample name base + number string
+                strNewSmplName = string.Format(strNewSmplNameBase, nIndex);
+                ++nIndex;
+            }
+            // make sure that the new sample name is not same with any sample in the samples list
+            while (SameNameInList(strNewSmplName));
+
+            // new sample name
+            return strNewSmplName;
+        }
+        public bool SameNameInList(String a_strSampleName, int a_nExclude = -1)
+        {
+            // make sure the input sample name is not empty
+            a_strSampleName.Trim();
+            if (a_strSampleName == "")
+            {
+                // shouldn't happen, input name is an empty string
+
+                return false;
+            }
+
+            // go through sample list
+            int nIndex = 0;
+            var m_listSamples = m_ResultData.GetSampleList();
+            foreach (var pSample in m_listSamples)
+            {
+                // return TRUE if this is not an exclude sample and its name is same with input
+                String strSampleName = pSample.GetName();
+                if (nIndex != a_nExclude && strSampleName.CompareTo(a_strSampleName) == 0)
+                {
+                    // find a same name sample
+                    return true;
+                }
+
+                ++nIndex;
+            }
+
+            // no, same name sample in the same list, return FALSE
+            return false;
+        }
+        // select a suitable sample hole for a new sample
+        public CHole SelectASmpleHole(String a_strHoleName /*= _T("")*/)
+        {
+
+            // get holes list of the stage
+            var m_pStage = m_StageParam.GetWorkingStage();
+            List<CHole> listHoles = m_pStage.GetHoleList();
+            //返回样品孔对象
+            CHole cReHole = new CHole();
+            // make sure the holes list is not empty
+            if (listHoles.Count == 0)
+            {
+                // shouldn't happen, stage have no hole.
+
+                return null;
+            }
+
+            // check the input hole name
+            a_strHoleName.Trim();
+            if (a_strHoleName != "")
+            {
+                // try to find matched hole
+                bool IsChanged = false;
+                int holeIndex = -1;
+                for (int itr = 0; itr < listHoles.Count; itr++)
+                {
+                    if (listHoles[itr].GetName() == a_strHoleName)
+                    {
+                        cReHole = listHoles[itr];
+                        //listHoles.RemoveAt(itr);
+                        IsChanged = true;
+                        holeIndex = itr;
+                        break;
+                    }
+                }
+
+                if (IsChanged)
+                {
+                    return cReHole;
+                }
+            }
+
+            // can't find a matched hole, then pick the first empty hole
+            //没有按照孔进行添加,则与样品列表进行判断
+            // go through the holes list
+            foreach (var pHole in listHoles)
+            {
+                // has this hole any sample in it?
+                String strHoleName = pHole.GetName();
+                bool IsChanged = false;
+                var m_listSamples = m_ResultData.GetSampleList();
+                foreach (COTSSample sampleItem in m_listSamples)
+                {
+                    if (strHoleName == sampleItem.GetSampleHoleName())
+                    {
+                        //listHoles.RemoveAt(itr);
+                        IsChanged = true;
+                    }
+                }
+                if (!IsChanged)
+                {
+                    return pHole;
+                }
+            }
+
+            // no empty hole, then the first hole will be the one
+            return listHoles[0];
+        }
+        public CDomain CalculateDefaultArea(CHole a_pHole)
+        {
+            Rectangle rectHole = a_pHole.GetDomainRect();
+            System.Drawing.Point ptCenter = new System.Drawing.Point((rectHole.Left + rectHole.Right) / 2, (rectHole.Top + rectHole.Bottom) / 2);
+            var m_pParam = m_DefaultParam.GetGenParam();
+            DOMAIN_SHAPE nShape = m_pParam.GetShape();
+
+            double dArea = m_pParam.GetArea() * 1000000;
+
+            System.Drawing.Point ptLeftTop = new System.Drawing.Point();
+            System.Drawing.Size ptSize = new System.Drawing.Size();
+
+            int nEdge = 0;
+            int nRadius = 0;
+
+            switch ((int)nShape)
+            {
+                case (int)DOMAIN_SHAPE.RECTANGLE:
+                    nEdge = (int)Math.Sqrt(dArea) / 2;
+                    ptLeftTop.X = ptCenter.X - nEdge;
+                    ptLeftTop.Y = ptCenter.Y - nEdge;
+                    ptSize.Width = ptCenter.X + nEdge - ptLeftTop.X;
+                    ptSize.Height = ptCenter.Y + nEdge - ptLeftTop.Y;
+                    break;
+                case (int)DOMAIN_SHAPE.ROUND:
+                    nRadius = (int)Math.Sqrt(dArea / 3.1415926);
+                    ptLeftTop.X = ptCenter.X - nRadius;
+                    ptLeftTop.Y = ptCenter.Y - nRadius;
+                    ptSize.Width = ptCenter.X + nRadius - ptLeftTop.X;
+                    ptSize.Height = ptCenter.Y + nRadius - ptLeftTop.Y;
+                    break;
+            }
+
+            Rectangle MsrRect = new Rectangle(ptLeftTop, ptSize);
+            CDomain pMsrArea = new CDomain(nShape, MsrRect);
+
+            // return measurement area
+            return pMsrArea;
+        }
+        //设置工作样品的属性值
+        public bool SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS ItemId, OTS_ITEM_TYPES ValType, object objVal)
+        {
+
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+
+            bool bSetFalg = false;
+            //判断样品名是否有效
+            if (ItemId == OTS_SAMPLE_PROP_GRID_ITEMS.SAMPLE_NAME)
+            {
+                if (!m_ResultData.IsValidSampleName((string)objVal))
+                {
+                    bSetFalg = false;
+                    return false;
+                }
+            }
+            bSetFalg = WSample.SetParamVal(ItemId, ValType, objVal);
+
+            if (bSetFalg)
+            {
+                m_ResultData.SetModify(true);
+            }
+            return bSetFalg;
+        }
+
+        //获取工作样品名称
+        public string GetWorkSampleName()
+        {
+
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+                return "";
+            }
+            string sWorkSampleName = WSample.GetName();
+            if ("" == sWorkSampleName)
+            {
+                return "";
+            }
+
+            return sWorkSampleName;
+        }
+
+        //设置工作样品
+        //string sNewWorkSampleName:  新工作样品
+        public bool SetWorkSample(string sNewWorkSampleName)
+        {
+            if ("" == sNewWorkSampleName)
+            {
+                return false;
+            }
+
+            if (!m_ResultData.SetWorkingSampleByName(sNewWorkSampleName))
+            {
+                return false;
+            }
+            return true;
+        }
+
+        //获取工作样品
+        // 返回工作样品对象
+        public COTSSample GetWorkSample()
+        {
+
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+
+            }
+            return WSample;
+
+        }
+
+        //删除工作样品
+        //string sWorkSampleName : 删除工作样品名称
+        public bool DeleteWorkSample(string sWorkSampleName)
+        {
+            return m_ResultData.DeleteSampleByName(sWorkSampleName);
+        }
+
+        // 获取样品总数
+        //返回样品总数
+        public int GetSampleCount()
+        {
+            return m_ResultData.GetSampleList().Count();
+        }
+
+        //改变工作样品名称
+        //String sWSampleNewName
+        public bool ChangeWorkSampleName(String sWSampleNewName)
+        {
+            if (!m_ResultData.IsValidSampleName(sWSampleNewName))
+            {
+                return false;
+            }
+            COTSSample WorkSample = m_ResultData.GetWorkingSample();
+            if (null == WorkSample)
+            {
+                return false;
+            }
+
+            WorkSample.SetName(sWSampleNewName);
+            m_ResultData.SetModify(true);
+            return true;
+
+        }
+
+        //移动工作样品到其他样品孔,样品孔名称和测量区域都要改变,重新设置工作样品参数
+        //SampleMeasurePara SMeasurePara:
+        public SampleMeasurePara SetWorkSampleHoleNameAndMeasureArea(SampleMeasurePara SMeasurePara)
+        {
+            SampleMeasurePara SMPara = new SampleMeasurePara();
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+                return SMPara;
+            }
+
+            CDomain Domain = new CDomain();
+            Domain.SetShape((otsdataconst.DOMAIN_SHAPE)SMeasurePara.iShape);
+            Domain.SetRectDomain(SMeasurePara.MeasureRect);
+            if (SMeasurePara.DrawPolygonPointRegionF != null)
+            {
+                List<Point> PolygonPoint = new List<Point>();
+                foreach (var item in SMeasurePara.DrawPolygonPointRegionF)
+                {
+                    PolygonPoint.Add(new Point((int)item.X, (int)item.Y));
+                }
+                Domain.SetPolygonPoint(PolygonPoint);
+            }
+            WSample.SetSampleHoleName(SMeasurePara.sHoleName);
+            WSample.SetMsrArea(Domain);
+
+            //获取样品的测量区域信息 
+            SMPara.sSampleName = WSample.GetName();    //获取样品名称
+            SMPara.iShape = (int)WSample.GetMsrArea().GetShape();  // 获取测量区域形状
+            SMPara.sHoleName = WSample.GetSampleHoleName(); //获取样品孔名称
+            SMPara.MeasureRect = (Rectangle)WSample.GetMsrArea().GetRectDomain();  //样品测量区域
+
+            //改变测量区域后重新设置样品修改状态
+            //m_ResultData.SetModify(true);
+            //string pathName = m_ProjDataMgr.GetPathName();
+            //if (pathName != "" && pathName != "Untitled")
+            //{
+            //    m_ProjDataMgr.Save();
+            //}
+            return SMPara;
+
+        }
+
+
+
+
+        //设置测量区域的形状 (通过RIBBON 上的画圆,画矩形 设置)
+        //int iShape:  测量区域形状 0: 圆形; 1 :矩形
+        public void SetMeasureAreaShape(int iShape)
+        {
+            //  SampleMeasurePara SMPara = new SampleMeasurePara();
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+                return;
+            }
+
+            CDomain Domain = new CDomain();
+            Domain.SetShape((otsdataconst.DOMAIN_SHAPE)iShape);
+        }
+
+
+        //修改了ITEMID后,重新更新GROUPID和ITEMID
+        public void UpdateGroupValAndItemVal(OTS_SAMPLE_PROP_GRID_ITEMS ItemID)
+        {
+            OTS_SAMPLE_PROP_GRID_ITEM_GROUPS GroupID = OTS_SAMPLE_PROP_GRID_ITEM_GROUPS.INVALID;
+            OTS_SAMPLE_PROP_GRID_ITEMS iItemID = OTS_SAMPLE_PROP_GRID_ITEMS.INVALID;
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+                return;
+            }
+            if (!WSample.GetRelatedPropItemGrp((OTS_SAMPLE_PROP_GRID_ITEMS)ItemID, ref GroupID))
+            {
+                bool bFlag = WSample.GetRelatedPropItem(ItemID, ref iItemID);
+            }
+
+        }
+
+  
+
+        //设置样品参数锁
+        //bool ParaLockFlag : 样品参数锁
+        public bool SetWorkSampleParamLock(bool ParaLockFlag)
+        {
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+                return false;
+            }
+            WSample.SetParamLock(ParaLockFlag);
+            m_ResultData.SetModify(true);
+            return true;
+        }
+
+        //获取工作样品锁
+        //ref bool ParamLockFlag : 获取的工作样品参数锁
+        public bool GetWSampleParaLock(ref bool ParamLockFlag)
+        {
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+                return false;
+            }
+            ParamLockFlag = WSample.GetParamLock();
+            return true;
+        }
+
+        //获取工作样品测量锁
+        public bool GetWSampleParaLock(ref OTSSamplePropertyInfo SMInfo)
+        {
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+                return false;
+            }
+
+            if (!GetWorkSamplePerameter(WSample, ref SMInfo))
+            {
+
+                return false;
+            }
+            return true;
+        }
+
+        //重新设置样品在样品列表中的位置(当拖动TREEVIEW的样品顺序后执行 )
+        public bool SortSamplePosition(List<string> SNameList)
+        {
+            if (!m_ResultData.ResetSamplesListOrder(SNameList))
+            {
+                return false;
+            }
+
+            List<COTSSample> SampleList = new List<COTSSample>();
+            SampleList = m_ResultData.GetSampleList();
+
+            return true;
+        }
+
+      
+        public bool CheckSampleParam(bool bCheckFlag)
+        {
+            m_MeasureSampleList.Clear();
+            List<COTSSample> MSampleList = new List<COTSSample>();
+
+            if (!CheckMeasureParam(m_ResultData, ref MSampleList, bCheckFlag))
+            {
+                return false;
+            }
+            if (MSampleList.Count > 0)
+            {
+                m_MeasureSampleList = MSampleList;
+                return true;
+            }
+            return false;
+        }
+        public bool CheckMeasureParam(COTSMsrPrjResultData a_pProjMgrFile, ref List<COTSSample> a_listMeasuableSamples, bool a_bCheckSetting)
+        {
+
+
+            // go through the sample list to check setting parameters 
+            int nSwitchSmplNo = 0;
+            int nCompletedSmplNo = 0;
+            int nErrorSmplNo = 0;
+            int nWarningSmplNo = 0;
+            List<String> listSamplMessages = new List<string>();
+            List<COTSSample> listSamples = a_pProjMgrFile.GetSampleList();
+            List<COTSSample> listMeasurableSamples = new List<COTSSample>();
+            List<COTSSample> listWithWarningMeasurableSamples = new List<COTSSample>();
+            foreach (var pSample in listSamples)
+            {
+                // is the sample switch on
+                if (pSample.GetSwitch())
+                {
+                    ++nSwitchSmplNo;
+                    String strSmplMessage;
+                    strSmplMessage = pSample.GetName() + ":" + "\r\n";
+
+                    // is this a measurement completed sample
+                    if (IsMeasureCompletedSmpl(pSample))
+                    {   // measurement completed sample
+                        ++nCompletedSmplNo;
+                        string str2 = GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE.FINISHED);
+                        strSmplMessage += str2;
+                        strSmplMessage += "\r\n";
+                    }
+                    else
+                    {
+                        // errors
+                        List<SAMPLE_FAULT_WARN_CODE> a_listErrorCodes = new List<SAMPLE_FAULT_WARN_CODE>();
+                        GetSampleErrorCodes(a_pProjMgrFile, pSample, ref a_listErrorCodes);
+                        if (a_listErrorCodes.Count != 0)
+                        {
+                            // has error, this is not a measurable sample
+                            ++nErrorSmplNo;
+                            foreach (var nErrorCode in a_listErrorCodes)
+                            {
+                                String str3 = GetSampleErrorWarnString(nErrorCode);
+                                strSmplMessage += str3;
+                                strSmplMessage += "\r\n";
+                            }
+                        }
+                        else
+                        {
+                            // no error, this is a measurable sample
+                            listMeasurableSamples.Add(pSample);
+                        }
+
+                        // warnings
+                        List<SAMPLE_FAULT_WARN_CODE> a_listWarningCodes = new List<SAMPLE_FAULT_WARN_CODE>();
+                        GetSampleWarningCodes(a_pProjMgrFile, pSample, ref a_listWarningCodes);
+                        if (a_listWarningCodes.Count != 0)
+                        {
+                            ++nWarningSmplNo;
+                            foreach (var nWarningCode in a_listWarningCodes)
+                            {
+                                String str3 = GetSampleErrorWarnString(nWarningCode);
+                                strSmplMessage += str3;
+                                strSmplMessage += "\r\n";
+                            }
+
+                            // has no error?
+                            if (a_listErrorCodes.Count == 0)
+                            {
+                                // this is a measurable sample but with setting warnings
+                                listWithWarningMeasurableSamples.Add(pSample);
+                            }
+                        }
+
+                        // no error and warning
+                        if (a_listErrorCodes.Count == 0 && a_listWarningCodes.Count == 0)
+                        {
+                            String str3 = GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE.NO_ERROR_WARNING);
+                            strSmplMessage += str3;
+                            strSmplMessage += "\r\n";
+                        }
+                    }
+
+                    // add 
+                    listSamplMessages.Add(strSmplMessage);
+                }
+            }
+
+            // dlg message string
+            String strDlgMessage = "";
+            String str;
+            String str1;
+            str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.SWITCH_ON);
+            str1 = str1.Replace("%d", "{0}");
+            str = string.Format(str1, nSwitchSmplNo);
+            strDlgMessage += str;
+            strDlgMessage += "\r\n";
+
+            // add more string if there switch on sample
+            if (nSwitchSmplNo > 0)
+            {
+                // completed sample number (optional)
+                if (nCompletedSmplNo > 0)
+                {
+                    str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.FINISHED);
+                    str1 = str1.Replace("%d", "{0}");
+                    str = string.Format(str1, nCompletedSmplNo);
+                    strDlgMessage += str;
+                    strDlgMessage += "\r\n";
+                }
+
+                // any unmeasured switch on samples?
+                if (nSwitchSmplNo > nCompletedSmplNo)
+                {
+                    // with setting error sample number
+                    str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.SETTING_ERROR);
+                    str1 = str1.Replace("%d", "{0}");
+                    str = string.Format(str1, nErrorSmplNo);
+                    strDlgMessage += str;
+                    strDlgMessage += "\r\n";
+
+                    // with setting warning sample number
+                    str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.SETTING_WARNING);
+                    str1 = str1.Replace("%d", "{0}");
+                    str = string.Format(str1, nWarningSmplNo);
+                    strDlgMessage += str;
+                    strDlgMessage += "\r\n";
+
+                }
+            }
+
+            // add an empty line strDlgMessage
+            strDlgMessage += "\r\n";
+
+            // add sample messages
+            foreach (var strSmplMessage in listSamplMessages)
+            {
+                strDlgMessage += strSmplMessage;
+                strDlgMessage += "\r\n";
+            }
+
+            // do we need to show dialog box?
+            if (nSwitchSmplNo == 0)
+            {
+                return false;
+            }
+
+            // measure button clicked?
+            if (a_bCheckSetting)
+            {
+                // there are measurable samples but no setting warnings samples
+                if (listMeasurableSamples.Count > 0 && listWithWarningMeasurableSamples.Count == 0)
+                {
+                    // set output measurable samples list
+                    foreach (var pSample in listMeasurableSamples)
+                    {
+                        a_listMeasuableSamples.Add(pSample);
+                    }
+                    return true;
+                }
+
+            }
+            //when there is sample setting error, and setting with no error and no warning samples, the dlg will not be show.??
+
+            //show the result dlg
+            DIALOG_CHECK_PARAM_RESULT dlg = new DIALOG_CHECK_PARAM_RESULT();
+            int nTatolMeasuableSmplNo = listMeasurableSamples.Count;
+            int nWithWarningMeasuableSmplNo = listWithWarningMeasurableSamples.Count;
+
+            // set the dlg parameters
+            dlg.SetCheckOnlyFlag(a_bCheckSetting);
+            dlg.SetMessageBase(strDlgMessage);
+            dlg.SetTatolMeasuableSmplNo(nTatolMeasuableSmplNo);
+            dlg.SetWithWarningMeasuableSmplNo(nWithWarningMeasuableSmplNo);
+
+            //no error not show dlg
+            if (nTatolMeasuableSmplNo == nSwitchSmplNo - nCompletedSmplNo && listMeasurableSamples.Count != 0)
+            {
+                foreach (var pSample in listMeasurableSamples)
+                {
+                    var itr = listWithWarningMeasurableSamples.Find(s => { return s.GetName() == pSample.GetName(); });
+
+
+                    if (itr == null)
+                    {
+                        a_listMeasuableSamples.Add(pSample);
+                    }
+                }
+
+                if (a_listMeasuableSamples.Count == listMeasurableSamples.Count)
+                {
+                    return true;
+                }
+
+            }
+
+
+            //show dlg
+            DialogResult dResult = dlg.ShowDialog();
+            if (!(dResult == System.Windows.Forms.DialogResult.OK))
+            {
+                // do something here
+                return false;
+            }
+            else
+            {
+                //if warnDo, back the listMeasuableSample
+                if (dlg.GetWarnDo())
+                {
+                    foreach (var pSample in listMeasurableSamples)
+                    {
+                        a_listMeasuableSamples.Add(pSample);
+                    }
+                }
+                else // back with no warn sample
+                {
+                    foreach (var pSample in listMeasurableSamples)
+                    {
+                        var itr = listWithWarningMeasurableSamples.Find(e => { return e.GetName() == pSample.GetName(); });
+                        if (itr == null)
+                        {
+                            a_listMeasuableSamples.Add(pSample);
+                        }
+                    }
+                }
+            }
+
+
+
+            return true;
+        }
+        bool IsMeasureCompletedSmpl(COTSSample a_pSample)
+        {
+            // safety check
+
+            if (a_pSample.GetMsrStatus().GetStatus() != OTSDataType.OTS_MSR_SAMPLE_STATUS.SUCCESSED)
+            {
+
+                return false;
+            }
+            return true;
+        }
+        string GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE a_nSampleFaultWarn)
+        {
+
+            // check input
+            if (a_nSampleFaultWarn < SAMPLE_FAULT_WARN_CODE.MIN && a_nSampleFaultWarn > SAMPLE_FAULT_WARN_CODE.MAX)
+            {
+                return "";
+            }
+            // error/waring string
+            string strErrorWarn;
+            strErrorWarn = GetResourceByKey(GrpOtherParam, IDS_ERROR_WARNING + (int)a_nSampleFaultWarn);
+            return strErrorWarn;
+        }
+        // get error codes list of a sample
+        void GetSampleErrorCodes(COTSMsrPrjResultData a_pProjMgrFile, COTSSample a_pSample, ref List<SAMPLE_FAULT_WARN_CODE> a_listErrorCodes)
+        {
+
+            const string UNTITLED_FILE_NAME = "Untitled";
+
+            // file has not been saved
+            String strPathName = a_pProjMgrFile.GetPathName();
+
+            // is this a file no saved?
+            strPathName.Trim();
+            if (strPathName == UNTITLED_FILE_NAME || strPathName == "")
+            {
+           
+                a_listErrorCodes.Add(SAMPLE_FAULT_WARN_CODE.FILE_NOT_SAVED);
+            }
+
+
+        }
+
+        // get warning codes list of a sample
+        void GetSampleWarningCodes(COTSMsrPrjResultData a_pProjMgrFile, COTSSample a_pSample, ref List<SAMPLE_FAULT_WARN_CODE> a_listWarningCodes)
+        {
+
+            // get the work stage
+            CStage pStage = a_pProjMgrFile.GetStage();
+
+            //get hole
+            String sHoleName = a_pSample.GetSampleHoleName();
+
+            //look for the hole Domain
+            CHole pSampleHole = pStage.GetHoleByName(sHoleName);
+            if (pSampleHole == null)
+            {
+
+                return;
+            }
+            if (a_pSample.GetSEMDataMsr() != null)
+            {
+                // compute pixel size
+                double dPixleSize = a_pSample.CalculatePixelSize();
+
+                // get min size
+                COTSImageProcParam pImageProcParam = a_pSample.GetMsrParams().GetImageProcessParam();
+                double dMinSize = pImageProcParam.GetIncAreaRange().GetStart();
+
+                // if pixel size bigger than 1/2 of the min size, current magnification can't see clear of the object
+                if (dPixleSize >= dMinSize * 0.5)
+                {
+                    // resolution low
+                    a_listWarningCodes.Add(SAMPLE_FAULT_WARN_CODE.RESOLUTION_LOW);
+                }
+            }
+            if(a_pSample.GetSEMDataMsr().GetTotalFields()==0
+               && a_pSample.GetSEMDataMsr().GetScanFieldSize() == 0
+               && a_pSample.GetSEMDataMsr().GetWorkingDistance() == 0)
+            {
+                // SEM_DATA_ERROR 
+                a_listWarningCodes.Add(SAMPLE_FAULT_WARN_CODE.SEM_DATA_ERROR);
+            }
+        }
+
+        //获取测量参数文件名称
+        //int iNamePos:  文件名在链表中的位置
+        //List<string> MParamFileNameList:  测量参数文件链表
+        public bool GetMeasureParamFileName(ref int iNamePos, ref List<string> MParamFileNameList)
+        {
+            if (!m_ResultData.GetParamFileList(ref iNamePos, ref MParamFileNameList))
+            {
+                return false;
+            }
+            return true;
+        }
+        //设置测量文件名称
+        //int iNamePos:  文件名在链表中的位置
+        public bool SetMeasrueParamFileName(int iNamePos)
+        {
+            if (!m_ResultData.ChangeParamFromList(iNamePos))
+            {
+                return false;
+            }
+            return true;
+        }
+
+        //获取STD 标准库文件名称
+        //int iNamePos:  文件名在链表中的位置
+        //List<string> STDFileNameList:  STD文件链表
+        public bool GetSTDFileName(ref int iNamePos, ref List<string> STDFileNameList)
+        {
+            if (!m_ResultData.GetSTDFileList(ref iNamePos, ref STDFileNameList))
+            {
+                return false;
+            }
+            return true;
+        }
+        //设置STD 标准库文件名称
+        public bool SetSTDFileName(int iNamePos)
+        {
+            if (!m_ResultData.ChangeSTDFromList(iNamePos))
+            {
+                return false;
+            }
+            return true;
+        }
+
+        ///保存工作样品的测量参数文件     
+        public bool SaveWorkMeasureFile()
+        {
+            CSampleParamMgr SMeasureParamData = new CSampleParamMgr();
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+                return false;
+            }
+            if (!SMeasureParamData.SetMsrParamFile(WSample.GetMsrParams()))
+            {
+                return false;
+            }
+            // file open dialog
+            CSampleParamMgr cSampleParamMgr = new CSampleParamMgr();
+            SaveFileDialog saveFileDialog = new SaveFileDialog();
+            saveFileDialog.FileName = WSample.GetName() +"_Config"+ cSampleParamMgr.MESUREMENT_PARAM_FILE_EXT;
+            saveFileDialog.Filter = cSampleParamMgr.MESUREMENT_PARAM_FILE_FILTER;
+            if (saveFileDialog.ShowDialog() != DialogResult.OK)
+            {
+                return false;
+
+            }
+            // get file pathname
+            string strPathName = saveFileDialog.FileName;
+            SMeasureParamData.Save(strPathName);
+            return true;
+        }
+
+
+
+
+        //打开工作样品的测量参数文件     
+        public bool LoadWorkMeasureFile()
+        {
+            CSampleParamMgr SMeasureParamData = new CSampleParamMgr();
+            OpenFileDialog openFileDialog = new OpenFileDialog();
+            openFileDialog.Filter = SMeasureParamData.MESUREMENT_PARAM_FILE_FILTER;
+            if (openFileDialog.ShowDialog() != DialogResult.OK)
+            {
+                return false;
+
+            }
+            // get file pathname
+            string strPathName = openFileDialog.FileName;
+            if (!SMeasureParamData.Load(strPathName, true))
+            {
+                return false;
+            }
+
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+                return false;
+            }
+
+            WSample.SetMsrParams(SMeasureParamData.GetMsrParams());
+
+            //更新样品GRID值测量文件名
+            OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
+            if (!this.GetWorkSamplePerameter(WSample, ref SMInfo))
+            {
+                return false;
+            }
+            m_MeasureAppFrom.m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
+            return true;
+        }
+
+
+
+        //判断是否允许修改样品名
+        public bool CheckSampleNameIsValid(string sNewName)
+        {
+            return m_ResultData.IsValidSampleName(sNewName);
+        }
+
+        //设置电镜参数
+        //int iScanFieldSize: Field扫描参数
+        //int iWDistance: 电镜工作距离
+        //double dMagni: 放大倍数
+        public void SetWorkingSampleSEMData(double iWDistance, double dMagni)
+        {
+            try
+            {
+                m_ResultData.GetWorkingSample().GetSEMDataMsr().SetWorkingDistance(iWDistance);
+                m_ResultData.GetWorkingSample().GetSEMDataMsr().SetMagnification(dMagni);
+            }
+            catch (Exception)
+            {
+            }
+        }
+
+        //获取电镜参数
+        //int iScanFieldSize: Field扫描参数
+        //int iWDistance: 电镜工作距离
+        //double dMagni: 放大倍数
+        public void GetWorkingSampleSEMData(ref double iWDistance, ref double dMagni)
+        {
+            iWDistance = m_ResultData.GetWorkingSample().GetSEMDataMsr().GetWorkingDistance();
+            dMagni = m_ResultData.GetWorkingSample().GetSEMDataMsr().GetMagnification();
+        }
+
+        //获取工作样品的测量区域
+        //int iShape :测量区域形状
+        //Rectangle Srect: 测量区域大小
+        public bool GetWSampleMrsArea(ref int iShape, ref Rectangle Srect)
+        {
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+                return false;
+            }
+
+            CDomain pMsrArea = new CDomain();
+            pMsrArea = WSample.GetMsrArea();
+            if (null == pMsrArea)
+            {
+                return false;
+            }
+
+            iShape = (int)pMsrArea.GetShape();
+
+            ValueType ValType = new Rectangle();
+            ValType = pMsrArea.GetRectDomain();
+            Srect = (Rectangle)ValType;
+            return true;
+        }
+
+
+
+
+        //检查Samplelist中的sample的checkbox状态
+        //当Samplelist中的链表有sample 的checkbox状态是选中状态,则返回TRUE. 说明可以测量
+        public bool GetSampleCheckBoxStatus()
+        {
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+                return false;
+            }
+            List<COTSSample> SampleList = new List<COTSSample>();
+            SampleList = m_ResultData.GetSampleList();
+            int iCount = SampleList.Count();
+            if (0 == iCount)
+            {
+                return false;
+            }
+
+            for (int i = 0; i < iCount; i++)
+            {
+                if (SampleList[i].GetSwitch())
+                {
+                    return true;
+                }
+            }
+
+            return false;
+        }
+
+        //获取BSE图像数据
+        public bool GetBSEImageSize(ref int iHeight, ref int iWidth)
+        {
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+                return false;
+            }
+
+            if (!WSample.GetBSESize(out iHeight, out iWidth))
+            {
+                return false;
+            }
+            return true;
+        }
+
+
+
+       
+
+        //获取图像尺寸
+        public string GetBSEImageSize()
+        {
+            try
+            {
+                COTSSample WSample = m_ResultData.GetWorkingSample();
+                if (null == WSample)
+                {
+                    return "";
+                }
+
+                OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
+                if (!GetWorkSamplePerameter(WSample, ref SMInfo))
+                {
+                    return "";
+                }
+                int iCount = SMInfo.SampleDataList.Count();
+                for (int i = 0; i < iCount; i++)
+                {
+                    if (OTS_SAMPLE_PROP_GRID_ITEMS.IMAGE_RESOLUTION == SMInfo.SampleDataList[i].iSampleId)
+                    {
+
+                        String val = (String)SMInfo.SampleDataList[i].SampleVal;
+
+                        return val;
+                    }
+                }
+                return "";
+            }
+            catch (Exception)
+            {
+                return "";
+            }
+        }
+
+        //获取放大倍数和工作距离
+        public bool GetMagAndDistance(ref double SemMag, ref double dDistance)
+        {
+          
+                COTSSample WSample = m_ResultData.GetWorkingSample();
+                if (null == WSample)
+                {
+                    return false;
+                }
+            //GetWorkingSampleSEMData(ref SemMag, ref dDistance);
+            GetWorkingSampleSEMData(ref dDistance, ref SemMag);
+            return true;
+           
+        }
+
+        public bool GetWorkSamplePerameter(COTSSample Sample, ref OTSSamplePropertyInfo SMeasureInfo)
+        {
+            //设置工作样品属性项
+            if (Sample.GetMsrParams().m_nPackId == OTS_SysType_ID.CleanlinessA)
+            {
+                Sample.SetPropItemGrpsForCleanlinessSys();
+            }
+            else
+            {
+                Sample.SetPropItemGrpsForIncA();
+            }
+          
+            bool MeasurementStatus = false;
+            if (null == Sample)
+            {
+                return false;
+            }
+
+            //样品的标题名 (Treeview的根节点名)           
+            SMeasureInfo.sSampleSoluName = m_ResultData.GetFileName();
+
+            // Treeview 的样品信息  
+            SMeasureInfo.TSampleParam.sSampleTitleName = m_ResultData.GetFileName();
+
+            //获得 样品属性值
+
+           
+
+            SMeasureInfo.bSwitch = Sample.GetSwitch();// (bool)jo.GetValue("bSwitch");
+            SMeasureInfo.TSampleParam.bParamLock = Sample.GetParamLock();// (bool)jo.GetValue("ParamLock");
+
+            //获取样品的测量区域信息 
+            //获取样品名称
+          
+            SMeasureInfo.SMeasurePara.sSampleName = Sample.GetName();// (String)SMeasurePara.GetValue("sNewSampleName");
+            // 获取测量区域形状
+            SMeasureInfo.SMeasurePara.iShape = (int)Sample.GetMsrArea().GetShape();// (int)SMeasurePara.GetValue("iShape");
+            //获取样品孔名称
+            SMeasureInfo.SMeasurePara.sHoleName = Sample.GetSampleHoleName();// (String)SMeasurePara.GetValue("sHoleName");
+                                                                             //样品测量区域
+                                                                             // JObject rec = (JObject)SMeasurePara.GetValue("MeasureRect");
+            Rectangle rec = Sample.GetMsrArea().GetDomainRect();
+            SMeasureInfo.SMeasurePara.MeasureRect = new Rectangle((int)rec.X, (int)rec.Y, (int)rec.Width, (int)rec.Height);
+
+         
+            SMeasureInfo.TSampleParam.sWorkSampleName = Sample.GetName();// (String)TSampleParam.GetValue("sWorkSampleName");
+            SMeasureInfo.TSampleParam.bSwitch = Sample.GetSwitch();// (bool)TSampleParam.GetValue("bSwitch");
+
+            List<CPropItemGrp> ja = Sample.GetPropItemGrps();// (JArray)jo.GetValue("ItemGrp");
+
+            for (int i = 0; i < ja.Count; i++)
+            {
+                //获取GROUP ID和Grid的显示组的标题名
+                var grp = ja[i];
+                int grpId = (int)grp.GetGroupId();
+                String sTitle = (String)grp.GetName();
+
+                //获取样品属性ID和值
+
+                var SDataArr = grp.GetItemsList();
+                if (SDataArr.Count == 0)
+                    continue;
+
+                SampleDataGroup smlgrp = new SampleDataGroup();
+                smlgrp.GroupId = (OTS_SAMPLE_PROP_GRID_ITEM_GROUPS)grpId;
+                smlgrp.sTitle = sTitle;
+                for (int j = 0; j < SDataArr.Count; j++)
+                {
+                    var SDataObj = SDataArr[j];
+                    SampleData SData = new SampleData();
+                    int smplid = (int)SDataObj.GetSmplItemId();
+                    SData.iSampleId = (OTS_SAMPLE_PROP_GRID_ITEMS)smplid;
+                    if (SData.iSampleId == OTS_SAMPLE_PROP_GRID_ITEMS.WORKING_DISTANCE)
+                    {
+                        bool b = (bool)SDataObj.IsReadOnly();
+                    }
+                    SData.sSCaptionName = (String)SDataObj.GetName();
+                    //------------------------------修改--------------------------
+
+                    if ((String)SDataObj.GetName() == "样品名")
+                    {
+                        for (int a = 0; a < ja.Count; a++)
+                        {
+                            var grpa = ja[a];
+                            var SDataArra = grpa.GetItemsList();
+                            for (int b = 0; b < SDataArra.Count; b++)
+                            {
+                                var SDataObb = SDataArra[b];
+                                if ((String)SDataObb.GetName() == "测量状态")
+                                {
+                                    if ((String)Sample.GetItemValueStr((OTS_SAMPLE_PROP_GRID_ITEMS)SDataObb.GetSmplItemId()) == "未测量")
+                                    {
+                                        MeasurementStatus = false;
+                                    }
+                                    else
+                                    {
+                                        MeasurementStatus = true;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    else
+                    {
+                        MeasurementStatus = false;
+                    }
+                    if (MeasurementStatus)
+                    {
+                        SData.bReadOnly = MeasurementStatus;
+                    }
+                    else
+                    {
+                        SData.bReadOnly = (bool)SDataObj.IsReadOnly();// OTS_ITEM_TYPES
+                    }
+
+                    //---------------------------------------------------------------
+
+                    int type = (int)SDataObj.GetTypeId();
+                    SData.iSampleValType = (OTS_ITEM_TYPES)type;
+                    SData.sDescriptionInfo = (String)SDataObj.GetDescription();
+                
+                    OTS_SAMPLE_PROP_GRID_ITEMS ItemId = SDataObj.GetSmplItemId();
+                    SData.SampleVal = (String)Sample.GetItemValueStr(ItemId);
+                    List<string> downStrList = new List<string>();
+                    if (type == (int)OTS_ITEM_TYPES.COMBO)
+                    {
+                        Sample.GetPropComboStrings(SDataObj.GetSmplItemId(), downStrList);
+                    }
+                    else if (type == (int)OTS_ITEM_TYPES.FILE_LIST)
+                    {
+                        //the sample object dosen't know anything about the fileList infomation so it has to delay this duty here.
+                        int iPos = -1;
+                        List<string> sFileNameList = new List<string>();
+                        if (OTS_SAMPLE_PROP_GRID_ITEMS.MEASURE_PARAM_FILE_NAME == (OTS_SAMPLE_PROP_GRID_ITEMS)smplid)
+                        {
+                            if (!this.GetMeasureParamFileName(ref iPos, ref sFileNameList))
+                            {
+                                return false;
+                            }
+                            foreach (var f in sFileNameList)
+                            {
+                                downStrList.Add(f);
+                            }
+
+                        }
+
+                        if (OTS_SAMPLE_PROP_GRID_ITEMS.STD_FILE_NAME == (OTS_SAMPLE_PROP_GRID_ITEMS)smplid)
+                        {
+                            if (!this.GetSTDFileName(ref iPos, ref sFileNameList))
+                            {
+                                return false;
+                            }
+                            foreach (var f in sFileNameList)
+                            {
+                                downStrList.Add(f);
+                            }
+
+                        }
+
+                    }
+
+                    if (downStrList.Count > 0)
+                    {
+                        for (int k = 0; k < downStrList.Count; k++)
+                        {
+                            SData.comboDownList.Add((String)downStrList[k]);
+                        }
+                    }
+                    smlgrp.SampleDataList.Add(SData);
+
+                }
+                SMeasureInfo.AddASampleDataGrp(smlgrp);
+            }
+
+            return true;
+        }
+
+
+
+
+        //保存测量样品的
+        public bool SaveMeasureSampleInfo()
+        {
+
+            if (!m_ResultData.Save())
+            {
+                return false;
+            }
+            return true;
+        }
+
+        //获取测量Sample的开始时间
+        public bool GetMsrSampleStartTime(ref DateTime MsrFieldStartTime)
+        {
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+                return false;
+            }
+            MsrFieldStartTime = (DateTime)WSample.GetMsrStatus().GetStartTime();
+            return true;
+        }
+
+        //获取测量已用时间
+        public bool GetMsrSampleUsedTime(ref TimeSpan TUsedTime)
+        {
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+                return false;
+            }
+            TUsedTime = (TimeSpan)WSample.GetMsrStatus().GetUsedTime();
+            return true;
+        }
+
+
+
+        // 获取测量样品中之前已经测量完成Field帧图,(上一次未测量完成继续测试)
+        public bool GetBeforeCompleteField(ref string MsrSampleName, ref List<Point> FieldList)
+        {
+            COTSSample WSample = m_ResultData.GetWorkingSample();
+            if (null == WSample)
+            {
+                return false;
+            }
+
+            MsrSampleName = WSample.GetName();
+            FieldList = WSample.GetMsrStatus().GetCompletedFieldsCenter();
+            return true;
+        }
+
+
+ 
+
+        /// <summary>
+        /// 通过样品孔信息 返回默认测量区域大小
+        /// </summary>
+        /// <param name="cHoleClr"></param>
+        /// <returns></returns>
+        public Rectangle CalculateMsrArea(string cHoleName)
+        {
+            CHole cHoleClr = null;
+            foreach (CHole item in m_ResultData.GetStage().GetHoleList())
+            {
+                if (item.GetName() == cHoleName)
+                {
+                    cHoleClr = item;
+                }
+            }
+            CDomain CDomain = m_ResultData.CalculateMsrArea(cHoleClr);
+            return (Rectangle)CDomain.GetRectDomain();
+        }
+
+        /// <summary>
+        /// 获取已完成测量的结果文件路径
+        /// </summary>
+        /// <param name="mrFilePathList">返回测量结果文件路径</param>
+        /// <returns></returns>
+        public bool GetCompletedMeasureFileName(ref List<string> mrFilePathList)
+        {
+            //测量文件路径
+            string proFilePath = m_ResultData.GetPathName();
+            //样品列表
+            List<COTSSample> sampleList = m_ResultData.GetSampleList();
+            //获取样品数量
+            int sampleCount = sampleList.Count;
+            string mrSuffix = ".rst";
+            int existsCount = 0;
+            //获取测量文件路径
+            if (proFilePath.Equals("Untitled"))
+            {
+                return false;
+            }
+            string mrFolderPath = string.Empty;
+            try
+            {
+                mrFolderPath = proFilePath.Substring(0, proFilePath.LastIndexOf("\\"));
+            }
+            catch (Exception)
+            {
+                mrFolderPath = string.Empty;
+            }
+            for (int sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++)
+            {
+                int CompleteFieldsCount = sampleList[sampleIndex].GetMsrStatus().GetCompletedFields();
+                //如果样品已测量成功后再加载至报告程序中
+                if (CompleteFieldsCount > 0)
+                {
+                    string sampleName = sampleList[sampleIndex].GetName();
+                    string mrFilePath = mrFolderPath + "\\" + sampleName + "\\" + sampleName + mrSuffix;
+                    //判断文件是否存在
+                    if (File.Exists(mrFilePath))
+                    {
+                        if (mrFilePathList != null)
+                        {
+                            mrFilePathList.Add(mrFilePath);
+                        }
+                        existsCount++;
+                    }
+                }
+            }
+            if (existsCount > 0)
+            {
+                return true;
+            }
+            return false;
+        }
+
+
+        /// <summary>
+        /// 获取工作样品的测量状态
+        /// </summary>
+        /// <param name="workingSampleName"></param>
+        /// <returns></returns>
+        public bool GetWorkSampleMeasureStatus()
+        {
+            bool reuslt = false;
+            COTSSample COTSSample = m_ResultData.GetWorkingSample();
+            int sampleStatus = COTSSample.GetMsrStatus().GetCompletedFields();
+            if (sampleStatus > 0)
+            {
+                reuslt = true;
+            }
+            return reuslt;
+
+        }
+      
+    }
+
+   
+
+
+
+}