Browse Source

optimize the pausing function

gsp 2 years ago
parent
commit
3864393162

+ 33 - 17
OTSIncAMeasureApp/0-OTSModel/Measure/3-MeasureFlow/CMeasure.cs

@@ -6,6 +6,7 @@ using static OTSDataType.otsdataconst;
 
 using OTSModelSharp.ImageProcess;
 using OTSModelSharp.ServiceInterface;
+using System.Threading;
 
 namespace OTSModelSharp
 {
@@ -231,11 +232,6 @@ namespace OTSModelSharp
         public   void DoMeasure()
         {
             // start measurement, creat thread measure status class, let the main thread know that measurement started
-
-
-           
-
-           
             m_ThreadStatus.SetStartTime(System.DateTime.Now);
             DateTime timeStart = m_ThreadStatus.GetStartTime(); 
             
@@ -278,11 +274,30 @@ namespace OTSModelSharp
                     ThreadOver();
                     return;
                 }
+                if (m_ThreadStatus.GetStatus() == OTS_MSR_THREAD_STATUS.PAUSED)
+                {
+                    // stop button clicked
+                    loger.Info("DoMeasure: stop button is clicked.");
+                    // record end time
+                    m_ThreadStatus.ComputeTime(OTS_THREAD_TIME_TYPE.STOPPED);
+                    while (m_ThreadStatus.GetStatus() == OTS_MSR_THREAD_STATUS.PAUSED)
+                    {
+                        Thread.Sleep(300);
+
+                    }
+                    //return;
+                }
 
                 if (!pSample.GetSwitch())
                 {
                     continue;
                 }
+                var sta = pSample.GetMsrStatus().GetStatus();
+                if (sta == OTS_MSR_SAMPLE_STATUS.SUCCESSED || sta == OTS_MSR_SAMPLE_STATUS.STOPPED)
+                {
+                    continue;
+                
+                }
              
                 CSmplMeasure pSmplMeasure;
                 if (!mapSmplMsr.ContainsKey(pSample.GetName()))
@@ -322,6 +337,8 @@ namespace OTSModelSharp
                 pSmplMeasure.DoMeasureForOneSample();
 
 
+           
+
                 // check if measurement is successful
                 if (pSample.GetMsrStatus().GetStatus() == OTS_MSR_SAMPLE_STATUS.PAUSED)
                 {// record end time
@@ -356,7 +373,7 @@ namespace OTSModelSharp
 
 
                     ThreadOver();
-                    return;
+                    break;
                 }
 			    else if (pSample.GetMsrStatus().GetStatus() == OTS_MSR_SAMPLE_STATUS.FAILED)
 			    {
@@ -377,19 +394,18 @@ namespace OTSModelSharp
 				  return;
 			    }
 
-               // record end time
-               m_ThreadStatus.ComputeTime(OTS_THREAD_TIME_TYPE.STOPPED);
+              
+                // update thread measure status class, let the main thread know that this sample measurement successes
+                ST_MSTMsg MsgSmpSuccess = new ST_MSTMsg();
+                MsgSmpSuccess.iMsgType = ENUM_MSG_TYPE.MSAMPLESTATUS;
+                MsgSmpSuccess.STMSampleStu.iMsrSampleStatu = OTS_MSR_SAMPLE_STATUS.SUCCESSED;
+                ProgressEvent(MsgSmpSuccess);
 
-              // update thread measure status class, let the main thread know that this sample measurement successes
-               ST_MSTMsg MsgSmpSuccess=new ST_MSTMsg();           
-              MsgSmpSuccess.iMsgType = ENUM_MSG_TYPE.MSAMPLESTATUS;
-	          MsgSmpSuccess.STMSampleStu.iMsrSampleStatu = OTS_MSR_SAMPLE_STATUS.SUCCESSED;         
-              ProgressEvent(MsgSmpSuccess);
-                		
 
-            // continue to the next sample
-              listMeasuredSamples.Add (pSample.GetName());
-		}
+                // continue to the next sample
+                listMeasuredSamples.Add(pSample.GetName());
+
+            }
 
             // measurement completed
             m_ThreadStatus.SetStatus(OTS_MSR_THREAD_STATUS.COMPLETED);

+ 17 - 2
OTSIncAMeasureApp/0-OTSModel/Measure/3-MeasureFlow/CSmplMeasure.cs

@@ -345,7 +345,7 @@ namespace OTSModelSharp
         }
         protected bool IsAborted()
         {
-            //Debug.Assert(m_pMsrThread == null);
+           
             return m_pMsrThread.IsMeasureStopped();
         }
         protected bool IsPaused()
@@ -693,7 +693,22 @@ namespace OTSModelSharp
                         {
                             Thread.Sleep(100);
                         }
-                        return;
+
+                        SetSEMExteralOff();
+                        // update thread measure status class, let the main thread know that this sample measurement stopped
+                        ST_MSTMsg MsgSmpStop = new ST_MSTMsg();
+                        MsgSmpStop.iMsgType = ENUM_MSG_TYPE.MSAMPLESTATUS;
+                        MsgSmpStop.STMThreadStu.iMsrStatu = OTS_MSR_THREAD_STATUS.PAUSED;
+                        MsgSmpStop.STMSampleStu.iMsrSampleStatu = OTS_MSR_SAMPLE_STATUS.PAUSED;
+                        MsgSmpStop.STMThreadStu.csMsrEndTime = DateTime.Now.ToShortDateString();
+                        MsgSmpStop.STMThreadStu.iMsrStatu = OTS_MSR_THREAD_STATUS.PAUSED;
+                        m_pMsrThread.SendMessageToMeasureApp(MsgSmpStop);
+                        while (IsPaused())
+                        {
+                            Thread.Sleep(300);
+                        
+                        }
+                       
                     }
                     if (IsAborted())
                     {// measure stopped			

+ 6 - 19
OTSIncAMeasureApp/0-OTSModel/Measure/ParamData/COTSMsrPrjResultData.cs

@@ -545,25 +545,7 @@ namespace OTSModelSharp
         // samples list
         public List<COTSSample> GetSampleList() { return m_listSamples; }
 
-        // samples list
-        //public bool SetSampleList(List<COTSSample> a_listSample, bool a_bClear/* = TRUE*/)
-        //{
-        //    // clear samples list if necessary 
-        //    if (a_bClear)
-        //    {
-        //        m_listSamples.Clear();
-        //    }
-
-        //    // go through the sample list of the source
-        //    foreach (var pSample in a_listSample)
-        //    {
-
-        //        // add the new sample into sample list
-        //        m_listSamples.Add(pSample);
-        //    }
-
-        //    return true;
-        //}
+ 
 
         public COTSSample GetSampleByIndex(int a_nIndex)
         {
@@ -674,6 +656,11 @@ namespace OTSModelSharp
             {
                 if (i == a_nIndex)
                 {
+                    var sam = m_listSamples[i];
+                    sam.GetMsrStatus().ClearCompletedFieldsInfo();
+                    sam.GetMsrStatus().ClearCompletedFieldsInfo();
+                    sam.ClearFields();
+                    sam.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.UNMEASURED);
                     m_listSamples.Remove(m_listSamples[i]);
                     break;
                 }

+ 5 - 1
OTSIncAMeasureApp/0-OTSModel/OTSDataType/CMsrSampleStatus.cs

@@ -162,7 +162,11 @@ namespace OTSDataType
             return m_listCpltedCenter.Count;
         }
 
- 
+        public void ClearCompletedFieldsInfo()
+        {
+            m_listCpltedCenter.Clear();
+        
+        }
         // completed fieldCenter
 
         public List<System.Drawing.Point> GetCompletedFieldsCenter()

+ 10 - 1
OTSIncAMeasureApp/1-OTSMeasure/CMeasureThreadWrapper.cs

@@ -100,13 +100,21 @@ namespace OTSMeasureApp
         /// <returns></returns>
         public bool BGWorkThreadIsRunning()
         {
-
+        
             if (m_bgWorker.IsBusy)
             {
                 return true;
             }
             return false;
         }
+        public bool BgWorkIsPaused()
+        {
+            if (m_MsrThread.GetMsrThreadStatus().GetStatus() == OTS_MSR_THREAD_STATUS.PAUSED)
+            {
+                return true;
+            }
+            return false;
+        }
         #endregion
 
         #region 判断线程挂起状态
@@ -245,6 +253,7 @@ namespace OTSMeasureApp
                     }
                     else if(MSTMsg.STMSampleStu.iMsrSampleStatu == OTSDataType.OTS_MSR_SAMPLE_STATUS.PAUSED)
                     {
+                        PauseMeasure(MSTMsg);
                         log.Warn("This sample measure is paused!");
                     }
                     break;

+ 0 - 4
OTSIncAMeasureApp/1-OTSMeasure/OTSMeasureDisplayResult.cs

@@ -339,10 +339,6 @@ namespace OTSMeasureApp
         #region 更改已完成测量的帧图状态
         public void ChangeDoneMeasureState(Point CurrentFIELDOTSPoint, Color changeColor)
         {
-
-
-            //获取帧图对象集合
-            //m_SingleGDIObjects = OTSSamplespaceWindow.m_SingleGDIObjects;
             //根据完成的测量帧图 更改帧图的完成状态
             if (OTSSamplespaceWindow.m_SingleGDIObjects != null)
             {

+ 9 - 3
OTSIncAMeasureApp/3-OTSDisplaySourceGridData/OTSPropertyWindow.cs

@@ -90,15 +90,21 @@ namespace OTSMeasureApp
    
         public void SampleGridInfoChange(OTS_SAMPLE_PROP_GRID_ITEMS SampleId, OTS_ITEM_TYPES ValType, object ObjVal)
         {
-            var PropertyMeasureThreadRunFlag = m_MeasureAppForm.MeasureThreadRunFlag;
+            var PropertyMeasureThreadRunFlag = m_MeasureAppForm.m_MsrThreadWrapper.BGWorkThreadIsRunning();
+            var measureTreadIsPaused= m_MeasureAppForm.m_MsrThreadWrapper.BgWorkIsPaused();
+
             var m_SolutionWindows = m_MeasureAppForm.m_SolutionWindows;
             //设置样品属性参数成功
             OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
             var m_DataMgr = m_MeasureAppForm.m_ProjParam;
             //当前正在测量
-            if (PropertyMeasureThreadRunFlag)
+            if (PropertyMeasureThreadRunFlag)//measureThread is running
             {
-                goto HERE;
+                if (measureTreadIsPaused == false)//and is not paused
+                {
+                    goto HERE;
+                }
+               
             }
             string sWSampleName = m_DataMgr.GetWorkSampleName();
             if ("" == sWSampleName)

+ 24 - 0
OTSIncAMeasureApp/5-OTSMeasureStatuImageFun/OTSMeasureStatusWindow.cs

@@ -129,6 +129,7 @@ namespace OTSMeasureApp
                 m_ImageData = new OTSImageData(this, m_MeasureAppForm);
             }
             m_ElementPointGDIObjects = new List<ARectangleGDIObject>();
+        
             //进入时首先对XRayTable进行隐藏
             panelXray.Visible = false;
             //国际化
@@ -1907,6 +1908,18 @@ namespace OTSMeasureApp
 
         private void ViewStripMenuItem_Click(object sender, EventArgs e)
         {
+            if (m_iWidth == 0 || m_iHeight == 0)
+            {
+                string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolution();// 举例:1024X768 
+                string[] sArray = str.Split('X');
+                if (sArray[0] != "" && sArray[1] != "")
+                {
+                    m_iWidth = Convert.ToInt32(sArray[0]);
+                    m_iHeight = Convert.ToInt32(sArray[1]);
+                }
+
+            }
+          
             ToolWindow toolWindow = new ToolWindow(m_MeasureAppForm, this);
             int grayStart = 0;
             int grayEnd = 0;
@@ -1946,6 +1959,17 @@ namespace OTSMeasureApp
 
         private void toolStripMenuItem1_Click(object sender, EventArgs e)
         {
+            if (m_iWidth == 0 || m_iHeight == 0)
+            {
+                string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolution();// 举例:1024X768 
+                string[] sArray = str.Split('X');
+                if (sArray[0] != "" && sArray[1] != "")
+                {
+                    m_iWidth = Convert.ToInt32(sArray[0]);
+                    m_iHeight = Convert.ToInt32(sArray[1]);
+                }
+
+            }
             SpecialParticleForm specialParticleForm = new SpecialParticleForm(CSpecialGrayRangeParam.GetParamFileFullName(), m_MeasureAppForm,  bBseData, m_iWidth, m_iHeight,this);
             DialogResult dialogResult = specialParticleForm.ShowDialog();
 

+ 3 - 72
OTSIncAMeasureApp/6-OTSDisplayTreeViewData/OTSDisplayTreeBase.cs

@@ -12,9 +12,7 @@ namespace OTSMeasureApp
     public class OTSDisplayTreeBase
     {
         OTSSolutionWindow m_SolutionWindow = null;
-        //  TreeNode m_Menunode = new TreeNode();     //树的跟节点
-        //     String m_csSolutionName = "未加载样品名";
-        //    String m_csSampleName = "";
+
         NLog.Logger log;
         public OTSDisplayTreeBase(OTSSolutionWindow SolutionWindow)
         {
@@ -393,27 +391,7 @@ namespace OTSMeasureApp
                 GetAfterSortTreeNode(m_SolutionWindow.treeView1.Nodes[iTNodeCount],ref  SampleNameList);
             }
 
-            //log.Error(" *********************************** **************************************************");
-            //log.Error("                                                                                      ");
-            //log.Error("                                  Begin   SortTreeNodeList()                                                 ");
-
-            //for (int i = 0; i < SampleNameList.Count; i++)
-            //{
-            //    m_SolutionWindow.m_MeasureAppForm.m_LogFunExport.TraceLog(" Sort SampleName = " + SampleNameList[i]);
-            //}
-
-
-            //if (!m_SolutionWindow.m_MeasureAppForm.m_DataMgrFun.SortSamplePosition(SampleNameList))
-            //{
-            //    log.Error("(OTSDisplayTreeBase.SortTreeNodeList) m_SolutionWindow.m_MeasureAppForm.m_DataMgrFun.SortSamplePosition(SampleNameList) = false Failed ");
-            //    for (int i = 0; i < SampleNameList.Count; i++)
-            //    {
-            //        log.Error("Sort SampleName = " + SampleNameList[i]);
-            //    }
-            //}
-            //log.Error("                                   End    SortTreeNodeList()                                                   ");
-            //log.Error("                                                                                      ");
-            //log.Error(" *************************************************************************************");
+        
             
         }
 
@@ -584,54 +562,7 @@ namespace OTSMeasureApp
             }
         }
 
-        //在Treeview里查找是否有重名的样品名
-        //public bool FindNodeNameInTreeview(String sNodeName)
-        //{
-        //    for (int i = 0; i < m_SolutionWindow.m_TreeSampleInfoList.Count; i++)
-        //    {
-        //        if (sNodeName == m_SolutionWindow.m_TreeSampleInfoList[i].st_SNodeMeaInfo.sSampleName)
-        //        {
-        //            return true;
-        //        }
-
-        //    }
-        //    return false;
-
-
-            /*       foreach (String sName in m_SolutionWindow.m_csTreeNodeList)
-                   {
-                       if(sNodeName == sName)
-                       {
-                           return true;
-                       }
-                   }
-                   return false; 
-
-            */
-        //}
-
-        //修改m_csTreeNodeList里指定的样品名为新的样品名
-        //public void ModifyNodeName(String sNewName, String sOldName)
-        //{
-
-        //    //
-        //    for (int i = 0; i < m_SolutionWindow.m_TreeSampleInfoList.Count; i++)
-        //    {
-        //        if (m_SolutionWindow.m_TreeSampleInfoList[i].st_SNodeMeaInfo.sSampleName == sOldName)
-        //        {
-        //            m_SolutionWindow.m_TreeSampleInfoList[i].st_SNodeMeaInfo.sSampleName = sNewName;
-        //            break;
-        //        }
-        //    }
-        //    /*     for (int i = 0; i < m_SolutionWindow.m_csTreeNodeList.Count; i++)
-        //         {
-        //             if(m_SolutionWindow.m_csTreeNodeList[i] == sOldName)
-        //             {
-        //                 m_SolutionWindow.m_csTreeNodeList[i] = sNewName;
-        //                 break;
-        //             }
-        //         }  */
-        //}
+       
         //设置样品参数锁的状态
         public void SetSampleParaLockStatu()
         {

+ 7 - 24
OTSIncAMeasureApp/6-OTSDisplayTreeViewData/OTSSolutionWindow.cs

@@ -453,13 +453,11 @@ namespace OTSMeasureApp
                     string smPathName = mPathName.Substring(0, mPathName.LastIndexOf("\\"))+"\\" + m_WorkSampleNode.Text;
                     if (DeleteFile(smPathName))
                     {
-                        //2.删除样品节点信息
-                        if (m_MeasureAppForm.DeleteSample(m_WorkSampleNode.Text))
-                        {
-                            //选择节点
-                            m_WorkSampleName = m_MeasureAppForm.m_ProjParam.GetWorkSampleName();
-                            m_TreeViewBase.GetTreeWorkSampleNode(m_WorkSampleName);
-                        }
+                      var sam=  m_MeasureAppForm.m_ProjParam.GetResultData().GetSampleByName(m_WorkSampleNode.Text);
+                        sam.GetMsrStatus().ClearCompletedFieldsInfo();
+                        sam.ClearFields();
+                        sam.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.UNMEASURED);
+                   
                         //保存测量文件
                         m_MeasureAppForm.m_ProjParam.GetResultData().Save();
                         //重新打开文件
@@ -467,6 +465,7 @@ namespace OTSMeasureApp
                     }
                 }
             }
+            MessageBox.Show("The sample data has been cleared!");
             ClearMeasureData.Visible = false;
         }
 
@@ -476,23 +475,7 @@ namespace OTSMeasureApp
         /// <param name="path"></param>
         public bool DeleteFile(string path)
         {
-            //try
-            //{
-            //    FileAttributes attr = File.GetAttributes(path);
-            //    if (attr == FileAttributes.Directory)
-            //    {
-            //        Directory.Delete(path, true);
-            //    }
-            //    else
-            //    {
-            //        File.Delete(path);
-            //    }
-            //    return true;
-            //}
-            //catch (Exception ex)
-            //{
-            //    return false;
-            //}
+           
 
             try
             {

+ 1 - 0
OTSIncAMeasureApp/OTSIncAMeasureAppForm.Designer.cs

@@ -668,6 +668,7 @@
             this.rbPause.ToolTip = null;
             this.rbPause.ToolTipImage = null;
             this.rbPause.ToolTipTitle = null;
+          
             this.rbPause.Click += new System.EventHandler(this.rbPause_Click);
             // 
             // rbStop

+ 5 - 0
OTSIncAMeasureApp/OTSIncAMeasureAppForm.cs

@@ -976,6 +976,11 @@ namespace OTSMeasureApp
                 m_MsrThreadWrapper.StartBGWorkThread();
                 m_RibbonFun.SetMeasureRibbonButnStatu();
             }
+            else //thread is in pausing state
+            {
+                m_MsrThreadWrapper.SetMeasureThreadStatus(OTS_MSR_THREAD_STATUS.INPROCESS);
+                m_RibbonFun.SetMeasureRibbonButnStatu();
+            }
         }
 
         public void SetStartMeasureRibbonStatus()

+ 2 - 0
OTSIncAMeasureApp/ServiceCenter/CImageHandler.cs

@@ -27,6 +27,8 @@ namespace OTSModelSharp.ServiceInterface
         /// <returns>位图</returns>    
         public static Bitmap ToGrayBitmap(byte[] data, int width, int height)
         {
+            if (width == 0 || height == 0) 
+                return null;
             //// 申请目标位图的变量,并将其内存区域锁定    
             Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
             //// BitmapData这部分内容  需要 using System.Drawing.Imaging;