Prechádzať zdrojové kódy

Merge branch 'Release2.3' of http://36.129.163.148:10080/gaoshipeng/OTS2_0 into Release2.3

gsp 3 rokov pred
rodič
commit
64056621f9

+ 16 - 121
OTSIncAMeasureApp/0-OTSModel/Measure/1-OTSInclution/SmplMeasureInclution.cs

@@ -50,7 +50,7 @@ namespace OTSModelSharp
             // second step :filter the finded particles.
             log.Info("Begin to filter particles!");
             InitFieldParticles();
-
+            CalculateParticleAbsolutPos();
             COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
 
             if (pXRayParam.GetUsingXray() == true)
@@ -83,55 +83,11 @@ namespace OTSModelSharp
 
 
         // save field data
-        protected void SaveFieldMgrData()
-        {
-            while (bSaveThreadWorking)
-            {
-                while (fieldQueue.Count() > 0)
-                {
-                    COTSFieldData f = fieldQueue.Dequeue();
                    
 
-
-                    //save to disk first ,then pop . if the size is 0,then we know all the saving work is done.
-                    SaveFieldData(f,m_pSampleRstFile.GetFieldFileSubFolderStr());
-
-
-                }
-                if (fieldQueue.Count() == 0)
+        public void InitFieldParticles()
                 {
-                    bSaveThreadWorking = false; //must set this flag,so the main thread can know this thread has exited.
-                    log.Warn("finished batch saving");
-                    return;
-                }
-            }
-            return;
-        }
-
         
-        protected void StartSaveFileThread(COTSFieldData a_pFieldMgr)
-        {
-     
-            
-            fieldQueue.Enqueue(a_pFieldMgr);
-
-
-            if (fieldQueue.Count() > 0) //if there's data in the queue and the previous thread has finished then start a new thread.
-            {
-                if (bSaveThreadWorking == false)
-                {
-                    bSaveThreadWorking = true;
-
-                    m_thread_ptr = new System.Threading.Thread(this.SaveFieldMgrData);//m_thread_ptr = shared_ptr<thread>(new thread(&CSmplMeasureInc::SaveFieldMgrData, this));
-                    m_thread_ptr.IsBackground = true;
-                    m_thread_ptr.Start();
-                }
-            }
-        }
-
-        public void InitFieldParticles()
-        {
-            // remove over sized particles, too small particles and get a analysis particles list
             // get pixel size
             double dPixelSize = m_Sample.CalculatePixelSize();        
          
@@ -148,20 +104,20 @@ namespace OTSModelSharp
             return ;
         }
         //calculate the real sem position of the particle
-        public void CalculateParticlePos(List<COTSParticleClr> xrayParticles)
-        {
-            double dPixelSize = m_Sample.CalculatePixelSize();
-            CSEMStageData pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
-            foreach (var p in xrayParticles)
-            {
+        //public void CalculateParticlePos(List<COTSParticleClr> xrayParticles)
+        //{
+        //    double dPixelSize = m_Sample.CalculatePixelSize();
+        //    CSEMStageData pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
+        //    foreach (var p in xrayParticles)
+        //    {
                
-                Point fldOtsPos = new Point(curFldData.OTSPos.X, curFldData.OTSPos.Y);//take the field position as the particle's position instead
-                Point semPos = new Point();
-                pCSEMStageData.ConverOTSToSEMPoint(fldOtsPos, ref semPos);
-                p.SetAbsolutPos(semPos);
-            }
+        //        Point fldOtsPos = new Point(curFldData.OTSPos.X, curFldData.OTSPos.Y);//take the field position as the particle's position instead
+        //        Point semPos = new Point();
+        //        pCSEMStageData.ConverOTSToSEMPoint(fldOtsPos, ref semPos);
+        //        p.SetAbsolutPos(semPos);
+        //    }
 
-        }
+        //}
 
         public void CollectParticlesXrayData()
         {
@@ -176,7 +132,7 @@ namespace OTSModelSharp
          
             ////=============================================
             curFldData.CreateXrayList(listXrayAnalysisparts);
-            CalculateParticlePos(listXrayAnalysisparts);
+         
 
             var xraymode = m_Sample.GetMsrParams().GetXRayParam().GetScanMode();
 
@@ -287,7 +243,7 @@ namespace OTSModelSharp
             {
                 log.Info(" classify failed. " + e.Message);
             }
-         
+          
         }
         public override void ClassifyMergedParticles(List<COTSParticleClr> mergedParts)
         {
@@ -386,69 +342,8 @@ namespace OTSModelSharp
             }
             return ;
         }
-        public bool SaveFieldData(COTSFieldData fldData,string filedFileFoler)
-        {
-            //loger.Warn("begin bitmap saving...");
-            string strFieldFileFolder = filedFileFoler;
-
-            CBSEImageFileMgr pBSEImgFileMgr = new CBSEImageFileMgr();
-            pBSEImgFileMgr.SetBSEImg(fldData.GetBSEImage());
-            int nId = fldData.GetId();
-            string sFieldId;
-            sFieldId = nId.ToString();
-          
-
-            string strBSEFilePathname = strFieldFileFolder + "\\" + m_pSampleRstFile. SMPL_MSR_RESULT_FIELDS_BSE + sFieldId + pBSEImgFileMgr.BMP_IMG_FILE_EXT;
-            if (!pBSEImgFileMgr.SaveIntoBitmap(strBSEFilePathname))
-            {
-                log.Error("SaveFieldFiles: save BSE file failed.");
-                return false;
-            }
-
-            // IncA Data list
-
-            CIncAFileMgr pDBFileMgr = m_pSampleRstFile.DBFileMgr;
-
-
           
 
-            pDBFileMgr.SaveStatusDataToDB();
-            var fldDB = pDBFileMgr.GetFieldDB();
-        
-            log.Warn("Start saving particle data.");
-       
-            var fldcmd = fldDB.GetSavingAFieldcmdObj(fldData.GetId(), fldData.GetOTSPosition(), fldData.SemPos);
-
-            List<KeyValuePair<string, System.Data.SQLite.SQLiteParameter[]>> fldcmds = new List<KeyValuePair<string, System.Data.SQLite.SQLiteParameter[]>>();
-            fldcmds.Add(fldcmd);
-            pDBFileMgr.ExecuteNonQueryBatch(ref fldcmds);
-            //remomove the invalid particles
-            
-
 
-
-            var cmds = pDBFileMgr.GetSavingIncADataToDBCmds(curFldData.GetListAnalysisParticles(), fldData.GetOTSPosition());
-
-            pDBFileMgr.ExecuteNonQueryBatch(ref cmds);
-        
-          
-            CPosXrayDBMgr PosXrayDBMgr = pDBFileMgr.GetPosXrayDBMgr();
-            var listAnalysisPosXray = new List<CPosXrayClr>();
-            foreach (var p in curFldData.GetListXrayParticles())
-            {
-                listAnalysisPosXray.Add(p.GetXray());
             }
-
-         
-            var cmds1 = PosXrayDBMgr.GetSavingXrayCmds(listAnalysisPosXray, true);
-
-            pDBFileMgr.ExecuteNonQueryBatch(ref cmds1);
-    
-           
-
-            return true;
-        }
-
-
-    }
 }

+ 141 - 176
OTSIncAMeasureApp/0-OTSModel/Measure/2-OTSCleanliness/SmplMeasureCleanliness.cs

@@ -36,6 +36,13 @@ namespace OTSModelSharp
           
             curFldData.SetId(nNewFieldId);
             curFldData.SetOTSPosition(fldCenter);
+
+            Point semPos = new Point();
+            CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
+            a_pCSEMStageData.ConverOTSToSEMPoint(fldCenter, ref semPos);
+            curFldData.SemPos = semPos;
+
+
             GetOriginalParticles();
  
             // second step :filter the finded particles.
@@ -70,67 +77,54 @@ namespace OTSModelSharp
             return true;
 
         }
-        public void CalculateParticleAbsolutPos()
-        {
-            double dPixelSize = m_Sample.CalculatePixelSize();
-            CSEMStageData pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
-            foreach (var p in curFldData.GetListAnalysisParticles())
-            {
-
-                Point fldOtsPos = new Point(curFldData.OTSPos.X, curFldData.OTSPos.Y);
-                Point semPos = new Point();
-                pCSEMStageData.ConverOTSToSEMPoint(fldOtsPos, ref semPos);
-                p.SetAbsolutPos(semPos);
-            }
-
-        }
+      
 
 
         // save field data
-        protected void SaveFieldMgrData()
-        {
-            while (bSaveThreadWorking)
-            {
-                while (fieldQueue.Count() > 0)
-                {
-                    CFieldDataClean f = (CFieldDataClean) fieldQueue.Dequeue();
-                    double pixelSize = m_Sample.CalculatePixelSize();
+        //protected void SaveFieldMgrData()
+        //{
+        //    while (bSaveThreadWorking)
+        //    {
+        //        while (fieldQueue.Count() > 0)
+        //        {
+        //            CFieldDataClean f = (CFieldDataClean) fieldQueue.Dequeue();
+        //            //double pixelSize = m_Sample.CalculatePixelSize();
 
           
 
-                    //save to disk first ,then pop . if the size is 0,then we know all the saving work is done.
-                    SaveFieldFiles(f,m_pSampleRstFile.GetFieldFileSubFolderStr());
+        //            //save to disk first ,then pop . if the size is 0,then we know all the saving work is done.
+        //            SaveFieldData(f,m_pSampleRstFile.GetFieldFileSubFolderStr());
 
 
-                }
-                if (fieldQueue.Count() == 0)
-                {
-                    bSaveThreadWorking = false; //must set this flag,so the main thread can know this thread has exited.
-                    return;
-                }
-            }
-            return;
-        }
+        //        }
+        //        if (fieldQueue.Count() == 0)
+        //        {
+        //            bSaveThreadWorking = false; //must set this flag,so the main thread can know this thread has exited.
+        //            return;
+        //        }
+        //    }
+        //    return;
+        //}
 
 
-        protected void StartSaveFileThread(COTSFieldData a_pFieldMgr)
-        {
+        //protected void StartSaveFileThread(COTSFieldData a_pFieldMgr)
+        //{
       
 
-            fieldQueue.Enqueue(a_pFieldMgr);
+        //    fieldQueue.Enqueue(a_pFieldMgr);
 
 
-            if (fieldQueue.Count() > 0) //if there's data in the queue and the previous thread has finished then start a new thread.
-            {
-                if (bSaveThreadWorking == false)
-                {
-                    bSaveThreadWorking = true;
+        //    if (fieldQueue.Count() > 0) //if there's data in the queue and the previous thread has finished then start a new thread.
+        //    {
+        //        if (bSaveThreadWorking == false)
+        //        {
+        //            bSaveThreadWorking = true;
 
-                    m_thread_ptr = new System.Threading.Thread(this.SaveFieldMgrData);//m_thread_ptr = shared_ptr<thread>(new thread(&CSmplMeasureInc::SaveFieldMgrData, this));
-                    m_thread_ptr.Start();//m_thread_ptr->detach();
-                }
-            }
-        }
+        //            m_thread_ptr = new System.Threading.Thread(this.SaveFieldMgrData);//m_thread_ptr = shared_ptr<thread>(new thread(&CSmplMeasureInc::SaveFieldMgrData, this));
+        //            m_thread_ptr.Start();//m_thread_ptr->detach();
+        //        }
+        //    }
+        //}
 
         public void FilterParticles(CFieldDataClean fld)
         {
@@ -143,7 +137,7 @@ namespace OTSModelSharp
            
             CSampleParam pMsrParam = m_Sample.GetMsrParams();
             COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
-            var pXRayParam = pMsrParam.GetXRayParam();
+           
             curFldData.InitParticles(pImgProcessParam, dPixelSize);
             if (curFldData.NoAnalysisParticle())
             {
@@ -152,7 +146,7 @@ namespace OTSModelSharp
 
             var listXray = curFldData.GetListAnalysisParticles().OrderByDescending(x => x.GetActualArea()).ToList();
             var listXray1 = new List<COTSParticleClr>();
-
+            var pXRayParam = pMsrParam.GetXRayParam();
             if (listXray.Count > pXRayParam.GetXrayLimit())
             {
                 for (var i = 0; i < pXRayParam.GetXrayLimit(); i++)
@@ -213,16 +207,15 @@ namespace OTSModelSharp
 
 
             var pStatus = m_Sample.GetMsrStatus();
+            curFldData.CreateXrayList(bigparts); // big particle using the full xray strategy.
 
-            if (bigparts.Count > 0)
-            {
 
-                //// particle x-ray analysis
-                ////=============================================
-                curFldData.CreateXrayList(bigparts); // big particle using the full xray strategy.
+            curFldData.CreateXrayList(smallparts); //small particle using the fast xray strategy
 
+            if (bigparts.Count > 0)
+            {
 
-                curFldData.CreateXrayList(smallparts); //small particle using the fast xray strategy
+           
                 var workmode = pXRayParam.GetScanMode();
                 // get x-ray list (analysis) by particle features
                 if (workmode == OTS_X_RAY_SCAN_MODE.FeatureMode)
@@ -256,40 +249,7 @@ namespace OTSModelSharp
             return ;
         }
 
-        public void ParticleSpecialTreatment(CFieldDataClean fld)
-        {
-            //we adopt such a strategy here:if some particles satisfy the predefined condition then we go through the second collecting with max EDS time,so that we got a more acurate result.
-            Dictionary<COTSParticleClr, int> mapPartXray = new Dictionary<COTSParticleClr, int>();   //std.map<COTSParticlePtr, int> mapPartXray = new std.map<COTSParticlePtr, int>();
-            double edsTime = 0; //to store the EDSTime returned from the engine.
-            var bigparts = fld.ListBigParticles;
-          var  m_ClassifyEngine = new CClassifyEngine();
-            for (int i = 0; i < bigparts.Count(); i++)
-            {
-                var engine = m_ClassifyEngine.GetParticleEngine(m_Sample.GetMsrParams().GetSTDName());
-                var p = bigparts[i];
-               
-                // there will be very less particle satisfied the condition ,so we use only one MaxEDS time,though we set MaxEDSTime for every rule separately .Here we store the last one.
-                //if the particle satisfied the MaxEDS condition then we go through the second colleting.Here we record the particle and the EDSTime and the corresponding xray position.
-                edsTime = engine.IfNeedMaxEDS(p);
-                if (edsTime > 0)
-                {
-                    mapPartXray[p] = i;
-                }
-            }
-            List<COTSParticleClr> partsMax = new List<COTSParticleClr>();
-            if (mapPartXray.Count() > 0)
-            {
-                foreach (var p in mapPartXray)
-                {
-                    partsMax.Add(p.Key);
-                }
-                List<CPosXrayClr> maxEDSXrays = new List<CPosXrayClr>();
-                m_EDSHardwareMgr.GetXRayByFeatures(partsMax, edsTime, true);
-        
-
-
-            }
-        }
+       
 
         public override void ClassifyFieldParticles()
         {
@@ -340,10 +300,7 @@ namespace OTSModelSharp
         
 
         }
-        public void SaveFieldParticlesData()
-        {
-            StartSaveFileThread(curFldData);
-        }
+    
 
         public void GetOriginalParticles()
         {
@@ -410,105 +367,113 @@ namespace OTSModelSharp
             return true;
         }
 
-        public bool SaveFieldFiles(CFieldDataClean fldData, string filedFileFoler)
-        {
+        //public bool SaveFieldFiles(CFieldDataClean fldData, string filedFileFoler)
+        //{
 
-            string strFieldFileFolder = filedFileFoler;
+        //    string strFieldFileFolder = filedFileFoler;
 
-            CBSEImageFileMgr pBSEImgFileMgr = new CBSEImageFileMgr();
-            pBSEImgFileMgr.SetBSEImg(fldData.GetBSEImage());
-            int nId = fldData.GetId();
-            string sFieldId;
-            sFieldId = nId.ToString();
+        //    CBSEImageFileMgr pBSEImgFileMgr = new CBSEImageFileMgr();
+        //    pBSEImgFileMgr.SetBSEImg(fldData.GetBSEImage());
+        //    int nId = fldData.GetId();
+        //    string sFieldId;
+        //    sFieldId = nId.ToString();
      
 
-            string strBSEFilePathname = strFieldFileFolder + "\\" + m_pSampleRstFile.SMPL_MSR_RESULT_FIELDS_BSE + sFieldId + pBSEImgFileMgr.BMP_IMG_FILE_EXT;
-            if (!pBSEImgFileMgr.SaveIntoBitmap(strBSEFilePathname))
-            {
-                log.Info("SaveFieldFiles: save BSE file failed.");
-                return false;
-            }
-
-            // IncA Data list
+        //    string strBSEFilePathname = strFieldFileFolder + "\\" + m_pSampleRstFile.SMPL_MSR_RESULT_FIELDS_BSE + sFieldId + pBSEImgFileMgr.BMP_IMG_FILE_EXT;
+        //    if (!pBSEImgFileMgr.SaveIntoBitmap(strBSEFilePathname))
+        //    {
+        //        log.Info("SaveFieldFiles: save BSE file failed.");
+        //        return false;
+        //    }
 
-            CIncAFileMgr pDBFileMgr = m_pSampleRstFile.DBFileMgr;
+        //    // IncA Data list
 
+        //    CIncAFileMgr pDBFileMgr = m_pSampleRstFile.DBFileMgr;
 
 
-            //pDBFileMgr.BeginTransaction();
-            pDBFileMgr.SaveStatusDataToDB();
-            var fldDB = pDBFileMgr.GetFieldDB();
-            fldDB.SaveAField(fldData.GetId(), fldData.GetOTSPosition(),fldData.SemPos);
-            if (!pDBFileMgr.SaveIncADataToDB(fldData.GetListAnalysisParticles(), fldData.GetOTSPosition()))
-            {
-                log.Info("SaveFieldFiles: save inclusion file failed.");
-                return false;
-            }
-            //save the xray data and element data.
-            CPosXrayDBMgr PosXrayDBMgr = pDBFileMgr.GetPosXrayDBMgr();
-            var m_listAnalysisPosXray = new List<CPosXrayClr>();
-            foreach (var p in fldData.GetListAnalysisParticles())
-            {
-                m_listAnalysisPosXray.Add(p.GetXray());
-            }
-
-            if (!PosXrayDBMgr.SaveXray(m_listAnalysisPosXray, true))
-            {
-                log.Info("SaveFieldFiles: save analysis x-ray failed.");
-                return false;
-            }
-
 
+        
+        //    pDBFileMgr.SaveStatusDataToDB();
+        //    var fldDB = pDBFileMgr.GetFieldDB();
 
-            //save the small particle info 
-            CSmallParticleInfoDB smallPartDB = pDBFileMgr.GetSmallParticleInfoDB();
-            Dictionary<int, List<COTSParticleClr>> mapSmallParts = new Dictionary<int, List<COTSParticleClr>>();
-            foreach (COTSParticleClr smallP in fldData.ListSmallParticles)
-            {
-                if (mapSmallParts.ContainsKey((int)smallP.GetType()))
-                {
-                    mapSmallParts[(int)smallP.GetType()].Add(smallP);
-                }
-                else
-                {
-                    var plist = new List<COTSParticleClr>();
-                    plist.Add(smallP);
-                    mapSmallParts.Add((int)smallP.GetType(), plist);
+        //    fldDB.SaveAField(fldData.GetId(), fldData.GetOTSPosition(),fldData.SemPos);
 
-                }
 
-            }
-            List<CSmallParticleInfo> smallparts = new List<CSmallParticleInfo>();
 
-            foreach (KeyValuePair<int, List<COTSParticleClr>> particles in mapSmallParts)
-            {
-                CSmallParticleInfo partInfo = new CSmallParticleInfo();
-                partInfo.FieldId = particles.Value[0].GetFieldId();
-                partInfo.AveGray = particles.Value[0].GetAveGray();
-                partInfo.Quantity = (int)(particles.Value.Count / fldData.SmallParticlePercentage);
-                partInfo.TypeId = particles.Key;
-                partInfo.TypeColor = particles.Value[0].GetTypeColor();
-                partInfo.TypeName = particles.Value[0].GetTypeName();
-                double area = 0;
-                foreach (var p in particles.Value)
-                {
-                    area += p.GetActualArea();
-                }
-                //partInfo.Area = Convert.ToInt32(area / f.SmallParticlePercentage);
-                partInfo.Area =(int) area ;
-                smallparts.Add(partInfo);
-            }
-            List<KeyValuePair<string, SQLiteParameter[]>> cmds = new List<KeyValuePair<string, SQLiteParameter[]>>();
-            foreach (CSmallParticleInfo smallp in smallparts)
-            {
-              var cmd=  smallPartDB.SaveAKindOfSmallParticle(smallp, new CPosXrayClr(), new System.Drawing.Point(0, 0));
-                cmds.Add(cmd);
-            }
 
-            pDBFileMgr.ExecuteNonQueryBatch(ref cmds);
 
-            return true;
-        }
+        //    var analysisParts = fldData.GetListAnalysisParticles();
+        //    if (!pDBFileMgr.SaveIncADataToDB(analysisParts, fldData.GetOTSPosition()))
+        //    {
+        //        log.Info("SaveFieldFiles: save inclusion file failed.");
+        //        return false;
+        //    }
+        //    //save the xray data and element data.
+        //    CPosXrayDBMgr PosXrayDBMgr = pDBFileMgr.GetPosXrayDBMgr();
+        //    var m_listAnalysisPosXray = new List<CPosXrayClr>();
+           
+        //    foreach (var p in analysisParts)
+        //    {
+        //        m_listAnalysisPosXray.Add(p.GetXray());
+        //    }
+
+        //    if (!PosXrayDBMgr.SaveXray(m_listAnalysisPosXray, true))
+        //    {
+        //        log.Info("SaveFieldFiles: save analysis x-ray failed.");
+        //        return false;
+        //    }
+
+
+
+        //    //save the small particle info 
+        //    //CSmallParticleInfoDB smallPartDB = pDBFileMgr.GetSmallParticleInfoDB();
+        //    //Dictionary<int, List<COTSParticleClr>> mapSmallParts = new Dictionary<int, List<COTSParticleClr>>();
+        //    //foreach (COTSParticleClr smallP in fldData.ListSmallParticles)
+        //    //{
+        //    //    if (mapSmallParts.ContainsKey((int)smallP.GetType()))
+        //    //    {
+        //    //        mapSmallParts[(int)smallP.GetType()].Add(smallP);
+        //    //    }
+        //    //    else
+        //    //    {
+        //    //        var plist = new List<COTSParticleClr>();
+        //    //        plist.Add(smallP);
+        //    //        mapSmallParts.Add((int)smallP.GetType(), plist);
+
+        //    //    }
+
+        //    //}
+        //    //List<CSmallParticleInfo> smallparts = new List<CSmallParticleInfo>();
+
+        //    //foreach (KeyValuePair<int, List<COTSParticleClr>> particles in mapSmallParts)
+        //    //{
+        //    //    CSmallParticleInfo partInfo = new CSmallParticleInfo();
+        //    //    partInfo.FieldId = particles.Value[0].GetFieldId();
+        //    //    partInfo.AveGray = particles.Value[0].GetAveGray();
+        //    //    partInfo.Quantity = (int)(particles.Value.Count / fldData.SmallParticlePercentage);
+        //    //    partInfo.TypeId = particles.Key;
+        //    //    partInfo.TypeColor = particles.Value[0].GetTypeColor();
+        //    //    partInfo.TypeName = particles.Value[0].GetTypeName();
+        //    //    double area = 0;
+        //    //    foreach (var p in particles.Value)
+        //    //    {
+        //    //        area += p.GetActualArea();
+        //    //    }
+        //    //    //partInfo.Area = Convert.ToInt32(area / f.SmallParticlePercentage);
+        //    //    partInfo.Area =(int) area ;
+        //    //    smallparts.Add(partInfo);
+        //    //}
+        //    //List<KeyValuePair<string, SQLiteParameter[]>> cmds = new List<KeyValuePair<string, SQLiteParameter[]>>();
+        //    //foreach (CSmallParticleInfo smallp in smallparts)
+        //    //{
+        //    //  var cmd=  smallPartDB.SaveAKindOfSmallParticle(smallp, new CPosXrayClr(), new System.Drawing.Point(0, 0));
+        //    //    cmds.Add(cmd);
+        //    //}
+
+        //    //pDBFileMgr.ExecuteNonQueryBatch(ref cmds);
+
+        //    return true;
+        //}
 
 
     }

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

@@ -13,6 +13,7 @@ using System.Drawing;
 using System.Threading;
 using OTSModelSharp.DTLBase;
 using OTSCLRINTERFACE;
+using OTSModelSharp.ServiceCenter;
 
 namespace OTSModelSharp
 {
@@ -1070,7 +1071,161 @@ namespace OTSModelSharp
             xraydb.SaveElementChemistriesList(ches);
             return true;
         }
+        public bool SaveFieldData(COTSFieldData fldData, string filedFileFoler)
+        {
+            //loger.Warn("begin bitmap saving...");
+            string strFieldFileFolder = filedFileFoler;
+
+            CBSEImageFileMgr pBSEImgFileMgr = new CBSEImageFileMgr();
+            pBSEImgFileMgr.SetBSEImg(fldData.GetBSEImage());
+            int nId = fldData.GetId();
+            string sFieldId;
+            sFieldId = nId.ToString();
+
+
+            string strBSEFilePathname = strFieldFileFolder + "\\" + m_pSampleRstFile.SMPL_MSR_RESULT_FIELDS_BSE + sFieldId + pBSEImgFileMgr.BMP_IMG_FILE_EXT;
+            if (!pBSEImgFileMgr.SaveIntoBitmap(strBSEFilePathname))
+            {
+                log.Error("SaveFieldFiles: save BSE file failed.");
+                return false;
+            }
+
+            // IncA Data list
+
+            CIncAFileMgr pDBFileMgr = m_pSampleRstFile.DBFileMgr;
+
+
+
+
+            pDBFileMgr.SaveStatusDataToDB();
+            var fldDB = pDBFileMgr.GetFieldDB();
+
+            log.Warn("Start saving particle data.");
+
+            var fldcmd = fldDB.GetSavingAFieldcmdObj(fldData.GetId(), fldData.GetOTSPosition(), fldData.SemPos);
+
+            List<KeyValuePair<string, System.Data.SQLite.SQLiteParameter[]>> fldcmds = new List<KeyValuePair<string, System.Data.SQLite.SQLiteParameter[]>>();
+            fldcmds.Add(fldcmd);
+            pDBFileMgr.ExecuteNonQueryBatch(ref fldcmds);
+            //remomove the invalid particles
+
+
+
+
+            var cmds = pDBFileMgr.GetSavingIncADataToDBCmds(curFldData.GetListAnalysisParticles(), fldData.GetOTSPosition());
+
+            pDBFileMgr.ExecuteNonQueryBatch(ref cmds);
+
+
+            CPosXrayDBMgr PosXrayDBMgr = pDBFileMgr.GetPosXrayDBMgr();
+            var listAnalysisPosXray = new List<CPosXrayClr>();
+            foreach (var p in curFldData.GetListXrayParticles())
+            {
+                listAnalysisPosXray.Add(p.GetXray());
+            }
+
+
+            var cmds1 = PosXrayDBMgr.GetSavingXrayCmds(listAnalysisPosXray, true);
+
+            pDBFileMgr.ExecuteNonQueryBatch(ref cmds1);
+
+
+
+            return true;
+        }
+        protected void SaveFieldMgrData()
+        {
+            while (bSaveThreadWorking)
+            {
+                while (fieldQueue.Count() > 0)
+                {
+                    COTSFieldData f = fieldQueue.Dequeue();
+
+
+
+                    //save to disk first ,then pop . if the size is 0,then we know all the saving work is done.
+                    SaveFieldData(f, m_pSampleRstFile.GetFieldFileSubFolderStr());
+
 
+                }
+                if (fieldQueue.Count() == 0)
+                {
+                    bSaveThreadWorking = false; //must set this flag,so the main thread can know this thread has exited.
+                    log.Warn("finished batch saving");
+                    return;
+                }
+            }
+            return;
+        }
+
+
+        protected void StartSaveFileThread(COTSFieldData a_pFieldMgr)
+        {
+
+
+            fieldQueue.Enqueue(a_pFieldMgr);
+
+
+            if (fieldQueue.Count() > 0) //if there's data in the queue and the previous thread has finished then start a new thread.
+            {
+                if (bSaveThreadWorking == false)
+                {
+                    bSaveThreadWorking = true;
+
+                    m_thread_ptr = new System.Threading.Thread(this.SaveFieldMgrData);//m_thread_ptr = shared_ptr<thread>(new thread(&CSmplMeasureInc::SaveFieldMgrData, this));
+                    m_thread_ptr.IsBackground = true;
+                    m_thread_ptr.Start();
+                }
+            }
+        }
+        public void ParticleSpecialTreatment(COTSFieldData fld)
+        {
+            //we adopt such a strategy here:if some particles satisfy the predefined condition then we go through the second collecting with max EDS time,so that we got a more acurate result.
+            Dictionary<COTSParticleClr, int> mapPartXray = new Dictionary<COTSParticleClr, int>();   //std.map<COTSParticlePtr, int> mapPartXray = new std.map<COTSParticlePtr, int>();
+            double edsTime = 0; //to store the EDSTime returned from the engine.
+            var bigparts = fld.GetListXrayParticles();
+            var m_ClassifyEngine = new CClassifyEngine();
+            for (int i = 0; i < bigparts.Count(); i++)
+            {
+                var engine = m_ClassifyEngine.GetParticleEngine(m_Sample.GetMsrParams().GetSTDName());
+                var p = bigparts[i];
+
+                // there will be very less particle satisfied the condition ,so we use only one MaxEDS time,though we set MaxEDSTime for every rule separately .Here we store the last one.
+                //if the particle satisfied the MaxEDS condition then we go through the second colleting.Here we record the particle and the EDSTime and the corresponding xray position.
+                edsTime = engine.IfNeedMaxEDS(p);
+                if (edsTime > 0)
+                {
+                    mapPartXray[p] = i;
+                }
+            }
+            List<COTSParticleClr> partsMax = new List<COTSParticleClr>();
+            if (mapPartXray.Count() > 0)
+            {
+                foreach (var p in mapPartXray)
+                {
+                    partsMax.Add(p.Key);
+                }
+                List<CPosXrayClr> maxEDSXrays = new List<CPosXrayClr>();
+                m_EDSHardwareMgr.GetXRayByFeatures(partsMax, edsTime, true);
+
+
+
+            }
+        }
+        public void CalculateParticleAbsolutPos()
+        {
+            double dPixelSize = m_Sample.CalculatePixelSize();
+            CSEMStageData pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
+            foreach (var p in curFldData.GetListAnalysisParticles())
+            {
+
+                Point fldOtsPos = new Point(curFldData.OTSPos.X, curFldData.OTSPos.Y);
+                Point semPos = new Point();
+                pCSEMStageData.ConverOTSToSEMPoint(fldOtsPos, ref semPos);
+                p.SetAbsolutPos(semPos);
+            }
+
+        }
 
     }
 }

+ 4 - 4
OTSIncAMeasureApp/0-OTSModel/Measure/BSEPicData/COTSFieldData.cs

@@ -166,15 +166,15 @@ namespace OTSModelSharp
             CDoubleRange oAreaRange = a_pImageProcessParam.GetIncAreaRange();
             double rMin = oAreaRange.GetStart() / 2.0;
             double rMax = oAreaRange.GetEnd() / 2.0;
-            double dAreaLow = rMin * rMin * 3.14159;
-            double dAreaHigh = rMax * rMax * 3.14159;
+            //double dAreaLow = rMin * rMin * 3.14159;
+            //double dAreaHigh = rMax * rMax * 3.14159;
 
 
             int nTagId = 0;
             //int nAnalysisPartId = 0;
-            int tooSmallnum = 0;
+            //int tooSmallnum = 0;
          
-            int overSizenum = 0;
+            //int overSizenum = 0;
             log.Info("Total Particles: " + m_listAllParticles.Count);
             foreach (COTSParticleClr pParticle in m_listAllParticles)//m_listAllParticles memorize all the particles .
             {