浏览代码

optimize the measure flow.(do not recalculate the field center position of one sample). restore the semstate of sem after the doholepreview operation.

gsp 3 年之前
父节点
当前提交
d563717a6c

+ 1 - 96
OTSCPP/OTSClrInterface/ImageProClr/FieldMgrClr.cpp

@@ -266,102 +266,7 @@ namespace OTSCLRINTERFACE {
 		return Pts;
 	}
 
-	// unmeasured field centre points list
-	/*bool CFieldMgrClr::CFieldMgrClr::UnmeasuredGetNextField(System::Drawing::Rectangle^ a_rctField)
-	{
-
-		ASSERT(a_rctField);
-		if (!a_rctField)
-		{
-			LogErrorTrace(__FILE__, __LINE__, _T("UnmeasuredGetNextField:invalid rectangle pointer."));
-			return false;
-		}
-
-		CRect oRect;
-		oRect.left = a_rctField->Left;
-		oRect.top = a_rctField->Top;
-		oRect.right = a_rctField->Right;
-		oRect.bottom = a_rctField->Bottom;
-
-
-		CFieldMgrPtr pFieldMgr = GetCFiledMgrPtr();
-
-		ASSERT(pFieldMgr);
-		if (!pFieldMgr)
-		{
-			LogErrorTrace(__FILE__, __LINE__, _T("UnmeasuredGetNextField: invalid pointer."));
-			return false;
-		}
-
-		bool bRet = pFieldMgr->UnmeasuredGetNextField(oRect);
-
-		return bRet;
-
-	}*/
-
-	/*bool CFieldMgrClr::CFieldMgrClr::GetUnmeasuredRandemField(System::Drawing::Rectangle^ a_rctField)
-	{
-
-		ASSERT(a_rctField);
-		if (!a_rctField)
-		{
-			LogErrorTrace(__FILE__, __LINE__, _T("GetUnmeasuredRandemField:invalid rectangle pointer."));
-			return false;
-		}
-
-		CRect oRect;
-		oRect.left = a_rctField->Left;
-		oRect.top = a_rctField->Top;
-		oRect.right = a_rctField->Right;
-		oRect.bottom = a_rctField->Bottom;
-
-
-		CFieldMgrPtr pFieldMgr = GetCFiledMgrPtr();
-
-		ASSERT(pFieldMgr);
-		if (!pFieldMgr)
-		{
-			LogErrorTrace(__FILE__, __LINE__, _T("GetUnmeasuredRandemField: invalid pointer."));
-			return false;
-		}
-
-		bool bRet = pFieldMgr->GetUnmeasuredRandemField(oRect);
-
-		return bRet;
-	}*/
-
-	//List<Point>^ CFieldMgrClr::GetMeasuredFieldCentrePoints()
-	//{
-	//	List<Point>^ Pts = gcnew List<Point>();
-	//	if (m_LpFieldMgr != nullptr)
-	//	{
-	//		std::vector<CPoint> ps = m_LpFieldMgr->get()->GetMeasuredFieldCentrePoints();
-	//		for each(auto p in ps)
-	//		{
-	//			Pts->Add(Point(p.x, p.y));
-	//		}
-
-	//	}
-
-	//	return Pts;
-	//}
-
-	//void CFieldMgrClr::SetMeasuredFieldCentrePoints(List<Point>^ a_listMeasuredFieldCentrePoints)
-	//{
-	//	List<Point>^ Pts = a_listMeasuredFieldCentrePoints;
-	//	std::vector<CPoint> ps;
-	//	if (m_LpFieldMgr != nullptr)
-	//	{
-	//		
-	//		for each(auto p in Pts)
-	//		{
-	//			ps.push_back (CPoint(p.X, p.Y));
-	//		}
-
-	//	}
-	//	 m_LpFieldMgr->get()->SetMeasuredFieldCentrePoints(ps);
-	//	
-	//}
+	
 
 	CDomainClr ^ CFieldMgrClr::GetMeasureArea()
 	{

+ 1 - 6
OTSCPP/OTSClrInterface/ImageProClr/FieldMgrClr.h

@@ -45,12 +45,7 @@ namespace OTSCLRINTERFACE {
 
 		// unmeasured field centre points list
 		List<Point>^ GetUnmeasuredFieldCentrePoints(List<Point>^ a_listMeasuredFieldCentrePoints);
-		//bool UnmeasuredGetNextField(System::Drawing::Rectangle^ a_rectField);
-		//bool GetUnmeasuredRandemField(System::Drawing::Rectangle^ a_rectField);
-
-		//// measured field centre points list
-		//List<Point>^ GetMeasuredFieldCentrePoints();
-		//void SetMeasuredFieldCentrePoints(List<Point>^ a_listMeasuredFieldCentrePoints);
+	
 
 		// measure area
 		CDomainClr^ GetMeasureArea();

+ 3 - 118
OTSCPP/OTSImagePro/FieldMgr.cpp

@@ -386,117 +386,7 @@ namespace OTSIMGPROC {
 		// the measure domain centre 
 		CPoint poiDomainCentre = rectMeasureDomain.CenterPoint();
 
-		// field centres need to be aligned with measured field centres
-		//if (0 < (int)a_listHaveMeasuredFieldCentrePoints.size())
-		//{	// get the first measured centre
-		//	CPoint poiMeasuredFieldCentre = a_listHaveMeasuredFieldCentrePoints[0];
-		//	// distance between the measure domain centre and the first measured field
-		//	int nDistanceX = abs(poiDomainCentre.x - poiMeasuredFieldCentre.x);
-		//	int nDistanceY = abs(poiDomainCentre.y - poiMeasuredFieldCentre.y);
-		//	// minimum shift
-		//	int nMinShiftX = 0;
-		//	int nMinShiftY = 0;
-
-		//	// x direction shift
-		//	if (nDistanceX != 0)
-		//	{// calculate shift distance
-		//		int nShiftX = nDistanceX % (int)(dScanFiledSizeX);
-		//		// need to move?
-		//		if (nShiftX != 0)
-		//		{
-		//		// need to shift on x direction
-		//		// calculate the minimum shift  , there must be something wrong, one is number, one is mm
-		//			nMinShiftX = min(nShiftX, ((int)(dScanFiledSizeX)-nShiftX));
-		//			// check if domain centre on left side of the first measured centre
-		//			if (poiDomainCentre.x > poiMeasuredFieldCentre.x)
-		//			{
-		//				// shift domain centre left nShiftX should make the two aligned 
-		//				// shift to left or right
-		//				if (nMinShiftX == nShiftX)
-		//				{
-		//					// left
-		//					poiDomainCentre.x -= nMinShiftX;
-		//				}
-		//				else
-		//				{
-		//					// right
-		//					poiDomainCentre.x += nMinShiftX;
-		//				}
-		//			}
-		//			else
-		//			{
-		//				// shift domain centre right nShiftX should make the two aligned 
-		//				// shift to left or right
-		//				if (nMinShiftX != nShiftX)
-		//				{
-		//					// left
-		//					poiDomainCentre.x -= nMinShiftX;
-		//				}
-		//				else
-		//				{
-		//					// right
-		//					poiDomainCentre.x += nMinShiftX;
-		//				}
-		//			}
-		//		}
-		//	}
-
-			// y direction shift	
-			//if (nDistanceY != 0)
-			//{
-			//	// calculate shift distance
-			//	int nShiftY = nDistanceY % (int)(dScanFiledSizeY);
-
-			//	// need to move?
-			//	if (nShiftY != 0)
-			//	{
-			//		// need to shift on x direction
-			//		// calculate the minimum shift  
-			//		nMinShiftY = min(nShiftY, ((int)(dScanFiledSizeY)-nShiftY));
-
-			//		// check if domain centre on top of the first measured centre
-			//		if (poiDomainCentre.y > poiMeasuredFieldCentre.y)
-			//		{
-			//			// shift domain centre down nShiftY should make the two aligned 
-			//			// move down or up?
-			//			if (nMinShiftY == nShiftY)
-			//			{
-			//				// move down
-			//				poiDomainCentre.y -= nMinShiftY;
-			//			}
-			//			else
-			//			{
-			//				// move up
-			//				poiDomainCentre.y += nMinShiftY;
-			//			}
-			//		}
-			//		else
-			//		{
-			//			// shift domain centre up nShiftY should make the two aligned 
-			//			// move down or up?
-			//			if (nMinShiftY == nShiftY)
-			//			{
-			//				// move up
-			//				poiDomainCentre.y += nMinShiftY;
-			//			}
-			//			else
-			//			{
-			//				// move down
-			//				poiDomainCentre.y -= nMinShiftY;
-			//			}
-			//		}
-			//	}
-			//}
-
-			// reset the measure domain rectangle 
-
-			// domain size
-		/*	CSize sizeMeasureDomain = rectMeasureDomain.Size();
-			sizeMeasureDomain.cx += 2 * nMinShiftX;
-			sizeMeasureDomain.cy += 2 * nMinShiftY;
-
-			rectMeasureDomain = CRect(poiDomainCentre, sizeMeasureDomain);
-		}*/
+		
 		// start mode
 		OTS_GET_IMAGE_MODE nStartMode = (OTS_GET_IMAGE_MODE)m_fieldStartMode;
 			
@@ -559,8 +449,7 @@ namespace OTSIMGPROC {
 					for (auto itr : mapCenterPoint)
 					{
 						CPoint itrPoint = itr.second;
-						if (IsInPolygonMeasureArea(itrPoint, sizeImage, ptPolygon))
-						//if (PtInPolygon(itrPoint, ptPolygon))
+						if (IsInPolygonMeasureArea(itrPoint, sizeImage, ptPolygon))					
 						{
 							m_listFieldCentrePoints.push_back(itr.second);
 							
@@ -574,11 +463,7 @@ namespace OTSIMGPROC {
 						if (IsInMeasureArea(itr.second, sizeImage))
 						{
 							m_listFieldCentrePoints.push_back(itr.second);
-							//if (!IsInMeasuredFieldList(itr.second ))
-							//{
-							//	// add the field centre into the unmeasured field centre points list
-							//	m_listUnmeasuredFieldCentrePoints.push_back(itr.second);
-							//}
+					
 						}
 					}
 				}

+ 2 - 1
OTSIncAMeasureApp/0-OTSModel/Measure/1-OTSInclution/CFieldDataIncA.cs

@@ -2,6 +2,7 @@
 using OTSDataType;
 using System;
 using System.Collections.Generic;
+using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -10,7 +11,7 @@ namespace OTSModelSharp.Measure.OTSInclution
 {
     class CFieldDataIncA: COTSFieldData
     {
-      public  CFieldDataIncA(CBSEImgClr a_pBSEImg, double a_dPixelSize) : base(a_pBSEImg, a_dPixelSize)
+      public  CFieldDataIncA(Point center, double a_dPixelSize) : base(center, a_dPixelSize)
         { 
         
         }

+ 2 - 1
OTSIncAMeasureApp/0-OTSModel/Measure/2-OTSCleanliness/CFieldDataClean.cs

@@ -2,6 +2,7 @@
 using OTSDataType;
 using System;
 using System.Collections.Generic;
+using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -10,7 +11,7 @@ namespace OTSModelSharp.Measure.OTSCleanliness
 {
     class CFieldDataClean : COTSFieldData
     {
-       public    CFieldDataClean(CBSEImgClr a_pBSEImg, double a_dPixelSize) : base(a_pBSEImg, a_dPixelSize)
+       public    CFieldDataClean(Point center, double a_dPixelSize) : base(center, a_dPixelSize)
         {
 
         }

+ 1 - 7
OTSIncAMeasureApp/0-OTSModel/Measure/3-MeasureFlow/CFieldPositionMgr.cs

@@ -15,13 +15,7 @@ namespace OTSModelSharp
 {
     public   class CFieldPositionMgr
     {
-        public enum SORTING_DIRECTION
-        {
-            LEFT = 1,
-            DOWN = 2,
-            RIGHT = 3,
-            UP = 4
-        };
+
        
         // measure area
         CDomain m_pMeasureArea;

+ 94 - 60
OTSIncAMeasureApp/0-OTSModel/Measure/3-MeasureFlow/CSmplMeasure.cs

@@ -349,7 +349,7 @@ namespace OTSModelSharp
             return m_pMsrThread.IsMeasureStopped();
         }
 
-        bool IsSampleOver(COTSImgScanPrm  a_pScanParam, int a_nTotalFields)
+        bool IsSampleOver(COTSImgScanPrm  a_pScanParam)
         {
           
 
@@ -393,7 +393,7 @@ namespace OTSModelSharp
                 {
                     case (int)OTS_MEASURE_STOP_MODE.CoverMode:
                         // completed fields number
-                        if (nCompeltedField == a_nTotalFields)
+                        if (nCompeltedField == m_Sample.GetFieldsData().Count)
                         {
 
                             bRet = true;
@@ -511,11 +511,7 @@ namespace OTSModelSharp
             return pBSEImage;
         }
 
-        //public virtual bool FieldImageProcess(Point fldCenter, CBSEImgClr imageData)
-        //{
-        //    return true;
-
-        //}
+    
         public virtual void ClassifyFieldParticles()
         {
             return;
@@ -524,18 +520,38 @@ namespace OTSModelSharp
         {
             return;
         }
+        private class SEMStateObject
+        {
+            private Point pos;
+            private double workingDistance;
+            private CSEMDataGnr semdata;
+            private double magnification;
+            public Point Pos { get => pos; set => pos = value; }
+            public double WorkingDistance { get => workingDistance; set => workingDistance = value; }
+            public CSEMDataGnr Semdata { get => semdata; set => semdata = value; }
+            public double Magnification { get => magnification; set => magnification = value; }
+        }
         private class AutoResetSEMControl:IDisposable
         {
             CSmplMeasure sm;
+            private SEMStateObject semState=null;
             public AutoResetSEMControl(CSmplMeasure s)
             {
                 sm = s;
             }
 
-         
+            public SEMStateObject SemState { get => semState; set => semState = value; }
 
             public void Dispose()
             {
+                if (semState == null)
+                {
+                    sm.MoveSEMToPoint(semState.Pos);
+                    sm.m_SemHardwareMgr.SetMagnification(semState.Magnification);
+                    sm.m_SemHardwareMgr.SetWorkingDistance(semState.WorkingDistance);
+
+
+                }
                 sm.SetSEMExteralOff();
             }
         }
@@ -605,17 +621,17 @@ namespace OTSModelSharp
                 m_pSampleRstFile.SetSEMStage(pStage);
          
                 // calculate field centers
-                List<System.Drawing.Point> umMeasuredlistFieldCenter;
-                List<System.Drawing.Point> alllistFieldCenter;
-
-                if (!CalculateUnMeasuredFieldsCenters(out alllistFieldCenter,out umMeasuredlistFieldCenter))
-                {// failed to calculate field centers
-                    log.Error("DoMeasure: failed to calculate field centers.");
-                    pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
-                    // record end time
-                    pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
-                    return;
-                }
+                //List<System.Drawing.Point> umMeasuredlistFieldCenter;
+                //List<System.Drawing.Point> alllistFieldCenter;
+
+                //if (!CalculateUnMeasuredFieldsCenters(out alllistFieldCenter,out umMeasuredlistFieldCenter))
+                //{// failed to calculate field centers
+                //    log.Error("DoMeasure: failed to calculate field centers.");
+                //    pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.FAILED);
+                //    // record end time
+                //    pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
+                //    return;
+                //}
                 //-----save the static measure result file data into xml file and the dynamic data of every field will be saved into sqlite database
                 log.Info("Create result file!");
                 if (!m_pSampleRstFile.CreateResultFiles())
@@ -629,12 +645,19 @@ namespace OTSModelSharp
                 //------
 
 
-                int nNewFieldId = 0;
-                int numOfAllFields = pStatus.GetCompletedFields() + umMeasuredlistFieldCenter.Count;//
-                int completedFields = pStatus.GetCompletedFields();
-                log.Info("Unmeasured fields:" + umMeasuredlistFieldCenter.Count);
-                for (int i = 0; i < (int)umMeasuredlistFieldCenter.Count; ++i)
+                //int nNewFieldId = 0;
+                //int numOfAllFields = pStatus.GetCompletedFields() + umMeasuredlistFieldCenter.Count;//
+                //int completedFields = pStatus.GetCompletedFields();
+                //log.Info("Unmeasured fields:" + umMeasuredlistFieldCenter.Count);
+                var FldDatas = m_Sample.GetFieldsData();
+                for (int i = 0; i < FldDatas.Count; ++i)
                 {// check and break if stop button is clicked
+                   
+                    var curFld = FldDatas[i];
+                    if (curFld.GetIsMeasureComplete())
+                    {
+                        continue;
+                    }
                     if (IsAborted())
                     {// measure stopped			
                         pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.STOPPED);
@@ -650,18 +673,18 @@ namespace OTSModelSharp
 
                     // check if sample measurement completes
                     COTSImgScanPrm pScanParam = m_Sample.GetMsrParams().GetImageScanParam();
-                    int nTotalFieldSize = (int)umMeasuredlistFieldCenter.Count;
+                    //int nTotalFieldSize = (int)umMeasuredlistFieldCenter.Count;
 
 
 
-                    if (IsSampleOver(pScanParam, numOfAllFields))
+                    if (IsSampleOver(pScanParam))
                     {
                         pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
                         break;
                     }
 
                     // get a field center 
-                    System.Drawing.Point poiFieldCentre = umMeasuredlistFieldCenter[i];
+                    System.Drawing.Point poiFieldCentre = curFld.GetOTSPosition();
 
                     // update thread measure status class, let the main thread know that starts a new field
                   
@@ -671,7 +694,7 @@ namespace OTSModelSharp
                     MsgFieldStart.STMSampleRetData.iRetDataType = MSAMPLE_RET.START_MSR_FIELD;
                     MsgFieldStart.STMSampleRetData.SMsrField.FieldPos = poiFieldCentre;
                     m_pMsrThread.SendMessageToMeasureApp(MsgFieldStart);
-                    int fldNo = completedFields + i + 1;
+                    int fldNo = curFld.GetId();
                     log.Warn("Current field:" + fldNo.ToString());
                     
 
@@ -720,13 +743,13 @@ namespace OTSModelSharp
 
                     // image process
 
-                 var rst = FieldImageProcess(poiFieldCentre, pBSEImg);
+                 var rst = FieldImageProcess(curFld, pBSEImg);
                     if (rst == true)
                     {
-              
-                            // add the field into the field
-                            m_pSampleRstFile.AddAField(curFldData);
 
+                        // add the field into the field
+                        //m_pSampleRstFile.AddAField(curFldData);
+                        curFld.SetIsMeasureComplete(true);
                        
                     }
 
@@ -734,13 +757,14 @@ namespace OTSModelSharp
                  
 
 
-                    ++nNewFieldId;
+                    //++nNewFieldId;
 
                     double measuredArea = 0; // this area should be the field area
                     var a_pBSEImg = curFldData.GetBSEImage();
-                    
-                    double dPixelSize = m_Sample.CalculatePixelSize();
-                   
+
+                    double dPixelSize = curFldData.GetPixelSize();
+
+
                         measuredArea = a_pBSEImg.GetHeight() * a_pBSEImg.GetWidth()* dPixelSize * dPixelSize + 0.5; //Get measured area
                     if (!CumulateFieldData(curFldData.GetListAnalysisParticles(), measuredArea))
                     { // failed to call SaveFieldFile method
@@ -749,13 +773,8 @@ namespace OTSModelSharp
                         return;
                     }
                     log.Info("Send field data to screen!");
-                    // completed fields
-                    pStatus.SetCompletedFields(pStatus.GetCompletedFields() + 1);
-
-                    // completed fieldCenter
-                    List<System.Drawing.Point> listCpltedCenter = pStatus.GetCompletedFieldsCenter();
-                    listCpltedCenter.Add(poiFieldCentre);
-
+               
+                    pStatus.AddCompletedFieldCenter(poiFieldCentre);
                     //Field Data
                     // record end time
                     pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
@@ -763,7 +782,7 @@ namespace OTSModelSharp
                     MsgFieldEnd.iMsgType = ENUM_MSG_TYPE.MSAMPLERESULT;
                     MsgFieldEnd.STMSampleRetData.iRetDataType = MSAMPLE_RET.FIELD_DATA;
                     MsgFieldEnd.STMSampleRetData.SFieldData.iCompleteFieldCount = pStatus.GetCompletedFields();
-                    MsgFieldEnd.STMSampleRetData.SFieldData.iMeasureFieldCount = numOfAllFields;
+                    MsgFieldEnd.STMSampleRetData.SFieldData.iMeasureFieldCount = m_Sample.GetFieldsData().Count;
                     MsgFieldEnd.STMSampleRetData.SFieldData.iSParticleCount = (int)curFldData.GetListAnalysisParticles().Count;
                     MsgFieldEnd.STMSampleRetData.SFieldData.FieldPos.X = Convert.ToInt32(poiFieldCentre.X);
                     MsgFieldEnd.STMSampleRetData.SFieldData.FieldPos.Y = Convert.ToInt32(poiFieldCentre.Y);
@@ -823,19 +842,17 @@ namespace OTSModelSharp
             }
           
         }
-        public  bool FieldImageProcess(Point fldCenter, CBSEImgClr a_pBSEImg)
+        public  bool FieldImageProcess(COTSFieldData curFldData, CBSEImgClr a_pBSEImg)
         {
-            int nNewFieldId;
-            nNewFieldId = m_pSampleRstFile.GetIdForANewField();
 
-            // create a field
-            curFldData = new COTSFieldData(a_pBSEImg, m_Sample.CalculatePixelSize());
-            curFldData.SetId(nNewFieldId);
-            curFldData.SetOTSPosition(fldCenter);
+            Point fldCenter = curFldData.OTSPos;
+           
+            curFldData.SetBSEImage(a_pBSEImg);
             CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
             Point semPos = new Point();
             a_pCSEMStageData.ConverOTSToSEMPoint(fldCenter, ref semPos);
-            curFldData.SemPos = semPos;
+
+            curFldData.SetSemPos(semPos);
 
             //first step:remove background of the bse image and compound all the finded particles.
 
@@ -1060,9 +1077,26 @@ namespace OTSModelSharp
         {
             using (AutoResetSEMControl autoReset = new AutoResetSEMControl(this))
             {
+                //----------memorize the state of sem
+                var semstate = new SEMStateObject();
+             
+                 double dMagnification = m_Sample.GetSEMDataMsr().GetMagnification();
+               double wd = m_Sample.GetSEMDataMsr().GetWorkingDistance();
+                SemController sem = m_SemHardwareMgr;
+                double posX=0, posY=0,posR=0;
+                sem.GetSemPositionXY(ref posX, ref posY, ref posR);           
+
+                Point pos = new Point((int)posX, (int)posY);
+                semstate.Pos = pos;
+                semstate.Magnification = dMagnification;
+                semstate.WorkingDistance = wd;
+
+                autoReset.SemState = semstate;
+                //-------------------------------------
+
 
-                    // let the main thread to know that this sample measurement starts
-                    CMsrSampleStatus pStatus = m_Sample.GetMsrStatus();
+                // let the main thread to know that this sample measurement starts
+                CMsrSampleStatus pStatus = m_Sample.GetMsrStatus();
                 pStatus.SetStatus(OTS_MSR_SAMPLE_STATUS.INPROCESS);
 
                 // set current time to current time
@@ -1143,12 +1177,12 @@ namespace OTSModelSharp
                
  
 
-                    if (IsSampleOver(pScanParam, nTotalFieldSize))
-                    {
-                        pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
+                    //if (IsSampleOver(pScanParam))
+                    //{
+                    //    pStatus.ComputeTime(OTS_MSR_TIME_TYPE.STOPPED);
 
-                        break;
-                    }
+                    //    break;
+                    //}
 
                     // get a field center 
                     System.Drawing.Point poiFieldCentre = listFieldCenter[i];
@@ -1358,7 +1392,7 @@ namespace OTSModelSharp
 
             log.Warn("Start saving particle data.");
 
-            var fldcmd = fldDB.GetSavingAFieldcmdObj(fldData.GetId(), fldData.GetOTSPosition(), fldData.SemPos);
+            var fldcmd = fldDB.GetSavingAFieldcmdObj(fldData.GetId(), fldData.GetOTSPosition(), fldData.GetSemPos());
 
             List<KeyValuePair<string, System.Data.SQLite.SQLiteParameter[]>> fldcmds = new List<KeyValuePair<string, System.Data.SQLite.SQLiteParameter[]>>();
             fldcmds.Add(fldcmd);

+ 7 - 43
OTSIncAMeasureApp/0-OTSModel/Measure/3-MeasureFlow/CSmplMsrResult.cs

@@ -700,7 +700,7 @@ namespace OTSModelSharp
             m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameTimeEnd(),ref strTimeEnd);
             m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameResultStatus(),ref strRstStatus);
             status.SetCompletedFieldsCenter(completedfld);
-            status.SetCompletedFields(completedfld.Count);
+            //status.SetCompletedFields(completedfld.Count);
             DateTime timeStart, timeEnd;
           
             timeStart = Convert.ToDateTime(strTimeStart);
@@ -830,11 +830,11 @@ namespace OTSModelSharp
            COTSFieldData pFieldData = listFieldData[a_nID];
             return pFieldData;
         }
-        public void AddAField(COTSFieldData a_pFieldData)
-        {
-            m_pSample.AddFieldData(a_pFieldData);
-            return ;
-        }
+        //public void AddAField(COTSFieldData a_pFieldData)
+        //{
+        //    m_pSample.AddFieldData(a_pFieldData);
+        //    return ;
+        //}
 
         public void SetFieldData(List<COTSFieldData> a_listFieldData)
         {
@@ -886,43 +886,7 @@ namespace OTSModelSharp
            m_pSEMData= a_pSEMGnr;
         }
         // get id for a new field 
-        public int GetIdForANewField()
-        {
-            List<COTSFieldData> listFieldData = GetFieldData();
-            // new field id
-            int nNewFieldId= listFieldData.Count;
-
-        
-          
-            bool bUnit = false;
-            do
-            {
-                bool iffound = false;
-                COTSFieldData cOTSFieldData;
-                for (int i = 0; i < listFieldData.Count; i++)
-                {
-                    cOTSFieldData = listFieldData[i];
-                    if (cOTSFieldData.GetId() == nNewFieldId)
-                    {
-                        iffound = true;
-                    }
-                }
-
-                if (iffound == true)
-                {
-                    ++nNewFieldId;
-                }
-                else
-                {
-                    break;
-                }
-
-            } while (true);
-           
-
-          
-            return nNewFieldId;
-        }
+       
         // set SEMStageData
 
         // set SEMStage

+ 2 - 1
OTSIncAMeasureApp/0-OTSModel/Measure/4-ReMeasure/SmplMeasureReMeasure.cs

@@ -27,7 +27,8 @@ namespace OTSMeasureApp._0_OTSModel.Measure._4_ReMeasure
         {
             OTSIncAMeasureAppForm aMeasureAppForm = (OTSIncAMeasureAppForm)Application.OpenForms["OTSIncAMeasureAppForm"];
             COTSSample sampleClr = aMeasureAppForm.m_ProjData.GetSampleByName(sampleName);
-            curFldData = new COTSFieldData(a_pBSEImg, sampleClr.CalculatePixelSize());
+            Point center = new Point(0, 0);
+            curFldData = new COTSFieldData(center, sampleClr.CalculatePixelSize());
             curFldData.SetId(0);
             curFldData.SetBSEImage(a_pBSEImg);
             SetSample(sampleClr);

+ 38 - 18
OTSIncAMeasureApp/0-OTSModel/Measure/BSEPicData/COTSFieldData.cs

@@ -48,7 +48,28 @@ namespace OTSModelSharp
         public int Height { get => height; set => height = value; }
         public int Width { get => width; set => width = value; }
         public System.Drawing.Point OTSPos { get => m_otsPos; set => m_otsPos = value; }
-        public Point SemPos { get => m_semPos; set => m_semPos = value; }
+
+        public bool GetIsMeasureComplete()
+        {
+            return isMeasureComplete;
+        }
+
+        public void SetIsMeasureComplete(bool value)
+        {
+            isMeasureComplete = value;
+        }
+
+        private bool isMeasureComplete;
+
+        public Point GetSemPos()
+        {
+            return m_semPos;
+        }
+
+        public void SetSemPos(Point value)
+        {
+            m_semPos = value;
+        }
 
         private Point m_semPos;
         public List<COTSParticleClr> GetAllParticles()
@@ -80,15 +101,19 @@ namespace OTSModelSharp
 
       
 
-        public COTSFieldData(CBSEImgClr a_pBSEImg, double a_dPixelSize)
+        public COTSFieldData(Point centerPoint, double a_dPixelSize)
         {
             log = NLog.LogManager.GetCurrentClassLogger();
             Init();
-            m_pBSEImg = a_pBSEImg;
+            //m_pBSEImg = a_pBSEImg;
+            m_otsPos = centerPoint;
             m_pixelSize = a_dPixelSize;
-            width = a_pBSEImg.GetWidth();
-            height = a_pBSEImg.GetHeight();
+           
            
+        }
+        public double GetPixelSize()
+        {
+            return m_pixelSize;
         }
         public COTSFieldData()
         {
@@ -138,10 +163,14 @@ namespace OTSModelSharp
                 return;
             }
             m_pBSEImg = a_pBSEImg;
+            width = a_pBSEImg.GetWidth();
+            height = a_pBSEImg.GetHeight();
         }
 
         public void RemoveImgBGAndGetParticles(COTSImageProcParam a_pImageProcessParam,double a_pixelSize,bool ifXray)
         {
+            if (m_pBSEImg == null)
+                return;
             CImageHandler imghandler = new CImageHandler();
             List<COTSParticleClr> xrayParts = new List<COTSParticleClr>();
             imghandler.RemoveBGAndGetParts(m_pBSEImg, a_pImageProcessParam,a_pixelSize, ref xrayParts);
@@ -156,6 +185,8 @@ namespace OTSModelSharp
         }
         public void GetPartsBySpecialGray(CIntRangeClr grayRange, CDoubleRangeClr diameterRange,double pixelSize, bool ifXray)
         {
+            if (m_pBSEImg == null)
+                return;
             CImageHandler imghandler = new CImageHandler();
             List<COTSParticleClr> specialParts = new List<COTSParticleClr>();
             imghandler.GetParticlesBySpecialGray(m_pBSEImg, grayRange,diameterRange,pixelSize, ref specialParts);
@@ -210,24 +241,13 @@ namespace OTSModelSharp
               
                 pParticle.SetAnalysisId(nTagId); // the same as the tagId no use now.  
                 nTagId++;
-                //m_listAnalysisParticles.Add(pParticle);
+               
                
             }
             log.Info("Total Particles: (>" + oAreaRange.GetStart().ToString("f2") + "): "+ "<" + oAreaRange.GetEnd().ToString("f2") + "): " + m_listAllParticles.Count);
            
 
-            //List<COTSParticleClr> xrayParts = new List<COTSParticleClr>();
-            //foreach (var p in m_listXrayParticles)//m_listXrayParticles memorize all the particles which needs xray analysis.
-            //{
-            //    if (p.GetTagId() > -1)//it has been initialized and it's a valid particle.
-            //    {
-            //        xrayParts.Add(p);
-
-
-            //    }
-            
-            //}
-            //m_listXrayParticles = xrayParts;
+     
 
         }
        

+ 2 - 7
OTSIncAMeasureApp/0-OTSModel/Measure/ParamData/COTSMsrPrjResultData.cs

@@ -385,7 +385,7 @@ namespace OTSModelSharp
                 m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameResultStatus(), ref strRstStatus);
 
                 status.SetCompletedFieldsCenter(completedflds);
-                status.SetCompletedFields(completedflds.Count);
+                //status.SetCompletedFields(completedflds.Count);
 
                 DateTime timeStart, timeEnd;
                 try
@@ -993,12 +993,7 @@ namespace OTSModelSharp
 
         public COTSSample GetWorkingSample()
         {
-            // check if the working sample index
-            if (m_nWorkingSampeIndex < 0 || m_nWorkingSampeIndex >= (int)m_listSamples.Count)
-            {
-                // invalid working sample index
-                return null;
-            }
+         
 
             return GetSampleByIndex(m_nWorkingSampeIndex);
         }

+ 14 - 10
OTSIncAMeasureApp/0-OTSModel/OTSDataType/CMsrSampleStatus.cs

@@ -44,7 +44,7 @@ namespace OTSDataType
         List<System.Drawing.Point> m_listCpltedCenter = new List<System.Drawing.Point>();
 
 
-        int m_nCompletedFields;
+        //int m_nCompletedFields;
         public CMsrSampleStatus()
         {
 
@@ -57,7 +57,7 @@ namespace OTSDataType
             m_timeStart = new DateTime();
             m_timeUsed = new TimeSpan();
             m_timeEnd = new DateTime();
-            m_nCompletedFields = 0;
+            //m_nCompletedFields = 0;
             m_listCpltedCenter.Clear();
         }
         // constructor
@@ -108,8 +108,8 @@ namespace OTSDataType
             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 &&
-                m_nCompletedFields == a_oSource.m_nCompletedFields;
+                m_timeStart == a_oSource.m_timeStart;
+                //m_nCompletedFields == a_oSource.m_nCompletedFields;
         }
 
         // status
@@ -158,13 +158,13 @@ namespace OTSDataType
         // completed fields
         public int GetCompletedFields()
         {
-            return m_nCompletedFields;
+            return m_listCpltedCenter.Count;
         }
 
-        public void SetCompletedFields(int a_nCompletedFields)
-        {
-            m_nCompletedFields = a_nCompletedFields;
-        }
+        //public void SetCompletedFields(int a_nCompletedFields)
+        //{
+        //    m_nCompletedFields = a_nCompletedFields;
+        //}
 
         // completed fieldCenter
 
@@ -172,6 +172,10 @@ namespace OTSDataType
         {
             return m_listCpltedCenter;
         }
+        public void AddCompletedFieldCenter(Point p)
+        {
+            m_listCpltedCenter.Add(p);
+        }
 
         public void SetCompletedFieldsCenter(List<System.Drawing.Point> a_listCpltedCenter)
         {
@@ -271,7 +275,7 @@ namespace OTSDataType
             m_timeStart = a_oSource.m_timeStart;
             m_timeUsed = a_oSource.m_timeUsed;
             m_timeEnd = a_oSource.m_timeEnd;
-            m_nCompletedFields = a_oSource.m_nCompletedFields;
+            //m_nCompletedFields = a_oSource.m_nCompletedFields;
             foreach (var pCpltedCenter in a_oSource.m_listCpltedCenter)
             {
                 m_listCpltedCenter.Add(pCpltedCenter);

+ 52 - 5
OTSIncAMeasureApp/0-OTSModel/OTSDataType/COTSSample.cs

@@ -40,10 +40,9 @@ namespace OTSDataType
         private string m_strName;
         private string m_strHoleName;
         private bool m_bParamLock;
-        // Measuren Switch
+     
         private bool m_bSwitch;
-        // system STD Switch
-        //private bool m_bSysSTDSwitch;
+    
         private CSampleParam m_poMsrParams;
         private CDomain m_poMsrArea;
         private CSEMDataMsr m_poSEMDataMsr;
@@ -432,10 +431,58 @@ namespace OTSDataType
         {
             m_listFieldData = a_listFieldData;
         }
-        public void AddFieldData(COTSFieldData f)
+  
+        public void AddFieldData(Point centerPoint )
+
+        {
+            var pixelsize = CalculatePixelSize();
+            var newfld = new COTSFieldData(centerPoint, pixelsize);
+
+            int nNewFieldId;
+            nNewFieldId =GetIdForANewField();
+            newfld.SetId(nNewFieldId);
+            
+
+           
+            m_listFieldData.Add(newfld);
+
+        }
+        public int GetIdForANewField()
         {
-            m_listFieldData.Add(f);
+            List<COTSFieldData> listFieldData = GetFieldsData();
+            // new field id
+            int nNewFieldId = listFieldData.Count;
+
+
+
+            bool bUnit = false;
+            do
+            {
+                bool iffound = false;
+                COTSFieldData cOTSFieldData;
+                for (int i = 0; i < listFieldData.Count; i++)
+                {
+                    cOTSFieldData = listFieldData[i];
+                    if (cOTSFieldData.GetId() == nNewFieldId)
+                    {
+                        iffound = true;
+                    }
+                }
+
+                if (iffound == true)
+                {
+                    ++nNewFieldId;
+                }
+                else
+                {
+                    break;
+                }
+
+            } while (true);
+
+
 
+            return nNewFieldId;
         }
         // measure results
         public CMsrDisplayResults GetMsrResults() { return m_poMsrResults; }

+ 1 - 11
OTSIncAMeasureApp/4-OTSSamplespaceGraphicsPanel/CStageManage.cs

@@ -696,17 +696,7 @@ namespace OTSMeasureApp
 
         public static void SetShowCMStrip(int IsSelectType, ContextMenuStrip cmStrip, bool IsTrue)
         {
-            /*不知道哪里用这个,若无影响日后可删
-            ////国际化
-            //OTSCommon.Language lan = new OTSCommon.Language();
-            //Hashtable table;
-            //table = lan.GetNameTable("CStageManage");
-            //string str1 = "拍摄样品孔BSE照片";
-            //str1 = table["shootbsepicture1"].ToString();
-            //string str2 = "拍摄测量区域BSE照片";
-            //str2 = table["shootbsepicture2"].ToString();
-            //cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Text = str1;
-            */
+
             //鼠标右键选择的类型 0:样品台 1:样品 2:测量区域
             cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = (int)MessageState.ShotBSEPicture;
             switch (IsSelectType)

+ 5 - 73
OTSIncAMeasureApp/4-OTSSamplespaceGraphicsPanel/OTSSamplespaceGraphicsPanelFun.cs

@@ -501,45 +501,7 @@ namespace OTSMeasureApp
                 return new CreateRectangle(new Rectangle(), 0, "");
             }
         }
-        public static Rectangle GetPixRects(int width, Point xPoint, Point yPoint, string sampleName, string sampleHoleName, int IsWidth, int Width, int Height)
-        {
-            try
-            {
-                //将微米信息 转换为 像素
-                Point xPoints = new Point();
-                Point yPoints = new Point();
-                xPoints.X = (int)MillimetersToPixelsWidth(width, xPoint.X, IsWidth, Width, Height);
-                xPoints.Y = (int)MillimetersToPixelsWidth(width, xPoint.Y, IsWidth, Width, Height);
-                yPoints.X = (int)MillimetersToPixelsWidth(width, yPoint.X, IsWidth, Width, Height);
-                yPoints.Y = (int)MillimetersToPixelsWidth(width, yPoint.Y, IsWidth, Width, Height);
-                //计算位置
-                xPoints = CalculateLocation(xPoints, Width, Height);
-                //yPoints = CalculateLocation(yPoints, Width, Height);
-
-                //获取图形四个点
-                int realStartX = Math.Min(xPoints.X, yPoints.X);
-                int realStartY = Math.Min(xPoints.Y, yPoints.Y);
-                int realEndX = Math.Max(xPoints.X, yPoints.X);
-                int realEndY = Math.Max(xPoints.Y, yPoints.Y);
-
-                //float startX = realStartX < 0 ? 0 : realStartX;
-                //float startY = realStartY < 0 ? 0 : realStartY;
-                //float endX = realEndX - Math.Abs(realStartX);
-                //float endY = endX / 4*3;
-
-                //xPoint.X = startX;
-                //xPoint.Y = startY;
-                //yPoint.X = endX;
-                //yPoint.Y = endY;
-                //创建矩形 并返回类型对象
-                return new Rectangle(xPoints.X, xPoints.Y, yPoints.X, yPoints.Y);
-                //return new RectangleF(realStartX < 0 ? 0 : realStartX, realStartY < 0 ? 0 : realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY));
-            }
-            catch (Exception)
-            {
-                return new Rectangle();
-            }
-        }
+        
         public static RectangleF GetPixRectF(int width, Point xPoint, Point yPoint, string sampleName, string sampleHoleName, int IsWidth, int Width, int Height)
         {
             try
@@ -563,35 +525,7 @@ namespace OTSMeasureApp
                 return new RectangleF();
             }
         }
-        public static CreateRectangle GetChangeSizePixRects(int width, Point xPoint, Point yPoint, int type, string sampleName, string sampleHoleName, int IsWidth, int Width, int Height)
-        {
-            try
-            {
-                //将微米信息 转换为 像素
-                Point xPoints = new Point();
-                Point yPoints = new Point();
-                xPoints.X = (int)MillimetersToPixelsWidth(width, xPoint.X, IsWidth, Width, Height);
-                xPoints.Y = (int)MillimetersToPixelsWidth(width, xPoint.Y, IsWidth, Width, Height);
-                yPoints.X = (int)MillimetersToPixelsWidth(width, yPoint.X, IsWidth, Width, Height);
-                yPoints.Y = (int)MillimetersToPixelsWidth(width, yPoint.Y, IsWidth, Width, Height);
-                //计算位置
-                //xPoints = CalculateLocation(xPoints, Width, Height);
-                //yPoints = CalculateLocation(yPoints, Width, Height);
-
-                //获取图形四个点
-                int realStartX = Math.Min(xPoints.X, yPoints.X);
-                int realStartY = Math.Min(xPoints.Y, yPoints.Y);
-                int realEndX = Math.Max(xPoints.X, yPoints.X);
-                int realEndY = Math.Max(xPoints.Y, yPoints.Y);
-
-                //创建矩形 并返回类型对象
-                return new CreateRectangle(realStartX < 0 ? 0 : realStartX, realStartY < 0 ? 0 : realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY), type, "", "");
-            }
-            catch (Exception)
-            {
-                return new CreateRectangle(new Rectangle(), 0, "");
-            }
-        }
+     
         public static double MillimetersToPixelsWidth(int width, double PointVal, int IsWidth, int Width, int Height)
         {
             return PointVal / ((double)width / (IsWidth == 0 ? (double)Width : (double)Height));
@@ -960,9 +894,7 @@ namespace OTSMeasureApp
                 float CenterX = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.X, wDomain, w);
                 float CenterY = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.Y, wDomain, w);
                 Rectangle sampleMeasureRect = new Rectangle();
-                //根据屏幕中心点获取移动后样品台中心点的偏移位置
-                //sampleMeasureRect.X = -(WorkAreaCenterPointX - sampleMeasureParas.MeasureRect.X);
-                //sampleMeasureRect.Y = WorkAreaCenterPointY - sampleMeasureParas.MeasureRect.Bottom;
+               
                 //根据样品台中心点获取开始点位置
                 sampleMeasureRect.X = -((int)CenterX - sampleMeasureParas.MeasureRect.X);
                 sampleMeasureRect.Y = (int)CenterY - sampleMeasureParas.MeasureRect.Bottom;
@@ -1012,10 +944,10 @@ namespace OTSMeasureApp
         public static bool SetWorkSamplHoleAndMeasureArea(ARectangleGDIObject MeasureItem, OTSIncAMeasureAppForm m_MeasureAppForm, StageDrawingData oTSSampleStageData, ARectangleGDIObject m_RectangleGDIObjects, int IsWidth, int Width, int Height, int wDomain)
         {
             //获取工作样品中的测量区域
-            SampleMeasurePara sampleMeasurePara = new SampleMeasurePara();
+           
             //设置测量区域位置
             //获取修改后的测量区域的位置与尺寸
-            sampleMeasurePara = GetSampleMeasureRect(MeasureItem, m_MeasureAppForm, oTSSampleStageData, m_RectangleGDIObjects, IsWidth, Width, Height, wDomain);
+          var  sampleMeasurePara = GetSampleMeasureRect(MeasureItem, m_MeasureAppForm, oTSSampleStageData, m_RectangleGDIObjects, IsWidth, Width, Height, wDomain);
             sampleMeasurePara.sHoleName = MeasureItem.Name;
             sampleMeasurePara.sSampleName = MeasureItem.SampleName;
             //设置测量区域信息(位置与大小)

+ 15 - 8
OTSIncAMeasureApp/4-OTSSamplespaceGraphicsPanel/OTSSamplespaceWindow.cs

@@ -3738,10 +3738,10 @@ namespace OTSMeasureApp
         #region 获取Filed帧图
         public List<Rectangle> GetFieldRects()
         {
-            List<Point> listCenterPoint = new List<Point>();
-            Size rectSize = new Size();
+            List<Point> listCenterPoint ;
+            Size rectSize ;
             //获取所有帧图的中心点信息 与矩形尺寸信息
-            bool flag = GetField(ref listCenterPoint, ref rectSize);
+            bool flag = GetFieldData(out listCenterPoint, out rectSize);
             //将所有中心点 转换为矩形
             List<Rectangle> returnRectList = new List<Rectangle>();
             foreach (Point item in listCenterPoint)
@@ -3750,8 +3750,10 @@ namespace OTSMeasureApp
             }
             return returnRectList;
         }
-        public bool GetField(ref List<Point> pFields, ref Size iSzie)
+        public bool GetFieldData(out List<Point> pFields, out Size iSzie)
         {
+             pFields = new List<Point>();
+            iSzie = new Size();
             var m_ResultData = m_MeasureAppForm.m_ProjParam.GetResultData();
             
             COTSSample WSample = m_ResultData.GetWorkingSample();
@@ -3844,8 +3846,13 @@ namespace OTSMeasureApp
                 return false;
             }
             iSzie = oValue.Size;
-            //将幁图数赋值给工作样品后
+           
            WSample.GetSEMDataMsr().SetTotalFields(iFieldCount);
+            foreach (Point fldcenter in pFields)
+            {
+                WSample.AddFieldData(fldcenter);
+            }
+            
             return true;
         }
         #endregion
@@ -4176,7 +4183,7 @@ namespace OTSMeasureApp
                 {
                      bret = m_SEMDATAFieldManage.SetSEMCurrentLocation(m_MouseDownLocation, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth, Width, Height);
 
-                //m_SEMDATAFieldManage.CloseSEM();
+               
                 }
            
                 return bret;
@@ -4202,7 +4209,7 @@ namespace OTSMeasureApp
                     bret = (m_SEMDATAFieldManage.DriveSEMToLocation(m_MouseDownLocation, m_RectangleGDIObjects, m_SingleGDIObjects, m_OTSSampleStageData, IsWidth, Width, Height));
 
 
-                    //m_SEMDATAFieldManage.CloseSEM();
+                 
 
 
                 }
@@ -4233,7 +4240,7 @@ namespace OTSMeasureApp
                 {
                      bret = m_SEMDATAFieldManage.GetSemLocation(ref SemLocation);
 
-                //m_SEMDATAFieldManage.CloseSEM();
+             
 
                 }
             return bret;

+ 2 - 7
OTSIncAMeasureApp/4-OTSSamplespaceGraphicsPanel/SEMDATAFieldManage.cs

@@ -28,7 +28,7 @@ namespace OTSMeasureApp
         EDSController cEDSfun = null;
         //主窗体对象
         COTSMeasureParam m_ProjData;
-        CFieldPositionMgr cFieldMgrClr;
+        //CFieldPositionMgr cFieldMgrClr;
 
         NLog.Logger log ;
         #endregion
@@ -65,12 +65,7 @@ namespace OTSMeasureApp
                 {
                     cEDSfun = EDSController.GetEDSController();
                 }
-                //获取帧图操作类对象
-                if (cFieldMgrClr == null)
-                {
-                    cFieldMgrClr = new CFieldPositionMgr();
-                }
-                //连接电镜
+           
                 return cSemfun.Connect();
             }
             catch (Exception ex)