瀏覽代碼

修改各个升级类方法

sunyi 5 年之前
父節點
當前提交
47e205ee06

+ 2 - 2
OTS/OTSControl/OTSScanBase.h

@@ -181,8 +181,8 @@ namespace OTSController
 		}
 		// check if the file exists or not
 		BOOL Exists(LPCTSTR a_sPath)
-		{
-			return ::PathFileExists(a_sPath) == TRUE;
+		{		   
+			return true;
 		}
 	};
 

+ 1 - 1
OTS/OTSModel/Measure/SmplMsrResultFileMgr.cpp

@@ -62,7 +62,7 @@ namespace OTSMODEL
 			return FALSE;
 		}
 
-		// check if the working directory is there
+		// check if the working directory is ther
 		if (!OTSTools::COTSFileSys::Exists(m_strWorkingFolder))
 		{
 			// the working directory is not exit, create it

+ 2 - 2
OTS/OTSModelSharp/Measure/GetBSEPic/BSEImgFileMgr.cs

@@ -56,7 +56,7 @@ namespace OTSDataType
 
         public  const String BMP_IMG_FILE_EXT = ".bmp";
 
-        System.Windows.Rect rect = new System.Windows.Rect();
+        System.Drawing.Size rect = new System.Drawing.Size();
 
         public String BSE_IMG_FILE_FILTER = "BSE image Files (*.img)|*.img||";
 
@@ -228,7 +228,7 @@ namespace OTSDataType
             aFile.Read(pPixel, 0, (int)height * (int)LineBytes);
             aFile.Close();
 
-            System.Windows.Rect images = new System.Windows.Rect(0, 0, (int)width - 0, 0 - (int)height);
+            System.Drawing.Rectangle images = new System.Drawing.Rectangle(0, 0, (int)width - 0, 0 - (int)height);
             m_poBSE.SetImageRect(images);
             m_poBSE.InitImageData();
             Byte[] pImageData = m_poBSE.GetImageDataPointer();

+ 32 - 31
OTS/OTSModelSharp/Measure/GetBSEPic/MsrThread.cs

@@ -4,6 +4,7 @@ using System;
 using System.Drawing;
 using OTSIncAMeasureApp.OTSMeasureControl;
 using static OTSDataType.otsdataconst;
+using OTSIncAMeasureApp.OTSMesureControl;
 
 namespace OTSModelSharp
 {
@@ -103,10 +104,10 @@ namespace OTSModelSharp
     {
        // const CString UNTITLED_FILE_NAME = _T("Untitled");
         private const string UNTITLED_FILE_NAME = "Untitled";
-       public delegate void   ProgressEventHandler(ST_MSTMsg msg);
+        public delegate void   ProgressEventHandler(ST_MSTMsg msg);
         public event ProgressEventHandler ProgressEvent;
         COTSProjMgrFile m_pProjMgrFile;
-       List< COTSSample> m_listMeasurableSamples;
+        List< COTSSample> m_listMeasurableSamples;
         string m_strWorkingFolder;
         CMsrThreadStatus m_pThreadStatus;
         CSEMDataGnr m_pSEMDataGnr;
@@ -200,12 +201,12 @@ namespace OTSModelSharp
         }
         public bool IsMeasureStopped()
         {
-            return m_pThreadStatus.GetStatus() == OTS_MSR_THREAD_STATUS.STOPPED;
+            return m_pThreadStatus.GetStatus() == OTSIncAMeasureApp.OTSMesureControl.OTS_MSR_THREAD_STATUS.STOPPED;
         }
 
-        public bool  IsMeasureRunning() { return m_pThreadStatus.GetStatus() == OTS_MSR_THREAD_STATUS.INPROCESS; }
-        public bool  IsMeasureFailed() { return m_pThreadStatus.GetStatus() == OTS_MSR_THREAD_STATUS.FAILED; }
-        public bool  IsMeasureCompleted() { return m_pThreadStatus.GetStatus() == OTS_MSR_THREAD_STATUS.COMPLETED; }
+        public bool  IsMeasureRunning() { return m_pThreadStatus.GetStatus() == OTSIncAMeasureApp.OTSMesureControl.OTS_MSR_THREAD_STATUS.INPROCESS; }
+        public bool  IsMeasureFailed() { return m_pThreadStatus.GetStatus() == OTSIncAMeasureApp.OTSMesureControl.OTS_MSR_THREAD_STATUS.FAILED; }
+        public bool  IsMeasureCompleted() { return m_pThreadStatus.GetStatus() == OTSIncAMeasureApp.OTSMesureControl.OTS_MSR_THREAD_STATUS.COMPLETED; }
         void DoMeasure()
         {
             // start measurement, creat thread measure status class, let the main thread know that measurement started
@@ -219,7 +220,7 @@ namespace OTSModelSharp
             
             ST_MSTMsg MsgMsrStart=new ST_MSTMsg();
             MsgMsrStart.iMsgType  = ENUM_MSG_TYPE.MTHREADSTATUS;
-            MsgMsrStart.STMThreadStu.iMThreadStatus = (int)OTS_MSR_THREAD_STATUS.INPROCESS;
+            MsgMsrStart.STMThreadStu.iMThreadStatus = (int)OTSIncAMeasureApp.OTSMesureControl.OTS_MSR_THREAD_STATUS.INPROCESS;
             MsgMsrStart.STMThreadStu.cMsrStartTime = timeStart.ToShortDateString();
 
             ProgressEvent (MsgMsrStart);
@@ -228,9 +229,9 @@ namespace OTSModelSharp
             if(!m_HardwareMgr.ConnectHardware())
             {
                 loger .Error("DoMeasure: failed to connect hardware.");
-                m_pThreadStatus.SetStatus(OTS_MSR_THREAD_STATUS.FAILED);
+                m_pThreadStatus.SetStatus(OTSIncAMeasureApp.OTSMesureControl.OTS_MSR_THREAD_STATUS.FAILED);
                 //SetMsrLoopStatus(OTS_MSR_THREAD_STATUS::FAILED);
-                m_pThreadStatus.ComputeTime(OTS_THREAD_TIME_TYPE.STOPPED);
+                m_pThreadStatus.ComputeTime(OTSIncAMeasureApp.OTSMesureControl.OTS_THREAD_TIME_TYPE.STOPPED);
                 ThreadOver();
                 return;
             }
@@ -241,9 +242,9 @@ namespace OTSModelSharp
             {
                 // failed to call SetWorkingFolderStr method
                 //LogErrorTrace(__FILE__, __LINE__, _T("DoMeasure: failed to call SetWorkingFolderStr method."));
-                m_pThreadStatus.SetStatus(OTS_MSR_THREAD_STATUS.FAILED);
+                m_pThreadStatus.SetStatus(OTSIncAMeasureApp.OTSMesureControl.OTS_MSR_THREAD_STATUS.FAILED);
                 // record end time
-                m_pThreadStatus.ComputeTime(OTS_THREAD_TIME_TYPE.STOPPED);
+                m_pThreadStatus.ComputeTime(OTSIncAMeasureApp.OTSMesureControl.OTS_THREAD_TIME_TYPE.STOPPED);
                 ThreadOver();
                 return;
             }
@@ -252,9 +253,9 @@ namespace OTSModelSharp
             if (!m_HardwareMgr.GetSEMDataGnrFromHw(ref m_pSEMDataGnr))
             {
                 loger .Error("DoMeasure: failed to call GetSEMDataGnrFromHW method.");
-                m_pThreadStatus.SetStatus(OTS_MSR_THREAD_STATUS.FAILED);
+                m_pThreadStatus.SetStatus(OTSIncAMeasureApp.OTSMesureControl.OTS_MSR_THREAD_STATUS.FAILED);
                 // record end time
-                m_pThreadStatus.ComputeTime(OTS_THREAD_TIME_TYPE.STOPPED);
+                m_pThreadStatus.ComputeTime(OTSIncAMeasureApp.OTSMesureControl.OTS_THREAD_TIME_TYPE.STOPPED);
                 ThreadOver();
                 return;
             }
@@ -264,13 +265,13 @@ namespace OTSModelSharp
             // got through measure list
             foreach (var pSample in m_listMeasurableSamples)
             {// check and break if stop button is clicked 
-                if (m_pThreadStatus.GetStatus()== OTS_MSR_THREAD_STATUS.STOPPED )
+                if (m_pThreadStatus.GetStatus()== OTSIncAMeasureApp.OTSMesureControl.OTS_MSR_THREAD_STATUS.STOPPED )
                 {
                     // stop button clicked
                     loger .Info("DoMeasure: stop button is clicked.");
                     //SetMsrLoopStatus(OTS_MSR_THREAD_STATUS::STOPPED);
                     // record end time
-                    m_pThreadStatus.ComputeTime(OTS_THREAD_TIME_TYPE.STOPPED);
+                    m_pThreadStatus.ComputeTime(OTSIncAMeasureApp.OTSMesureControl.OTS_THREAD_TIME_TYPE.STOPPED);
                     ThreadOver();
                     return;
                 }
@@ -290,7 +291,7 @@ namespace OTSModelSharp
                 {
                     pSmplMeasure = mapSmplMsr[pSample.GetName()];
                     pSample.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.INPROCESS);
-                    m_pThreadStatus.SetStatus(OTS_MSR_THREAD_STATUS.INPROCESS);
+                    m_pThreadStatus.SetStatus(OTSIncAMeasureApp.OTSMesureControl.OTS_MSR_THREAD_STATUS.INPROCESS);
                 }
 
 
@@ -303,8 +304,8 @@ namespace OTSModelSharp
                 // check if measurement is successful
                 if (pSample.GetMsrStatus().GetStatus() == OTS_MSR_SAMPLE_STATUS.STOPPED)
                 {// record end time
-                    m_pThreadStatus.SetStatus(OTS_MSR_THREAD_STATUS.STOPPED);
-                    m_pThreadStatus.ComputeTime(OTS_THREAD_TIME_TYPE.STOPPED);
+                    m_pThreadStatus.SetStatus(OTSIncAMeasureApp.OTSMesureControl.OTS_MSR_THREAD_STATUS.STOPPED);
+                    m_pThreadStatus.ComputeTime(OTSIncAMeasureApp.OTSMesureControl.OTS_THREAD_TIME_TYPE.STOPPED);
 
                     // update thread measure status class, let the main thread know that this sample measurement stopped
                     ST_MSTMsg MsgSmpStop = new ST_MSTMsg(); 
@@ -320,9 +321,9 @@ namespace OTSModelSharp
 			    else if (pSample.GetMsrStatus().GetStatus() == OTS_MSR_SAMPLE_STATUS.FAILED)
 			    {
                     // measurement failed
-                    m_pThreadStatus.SetStatus(OTS_MSR_THREAD_STATUS.FAILED);
+                    m_pThreadStatus.SetStatus(OTSIncAMeasureApp.OTSMesureControl.OTS_MSR_THREAD_STATUS.FAILED);
                 // record end time
-                    m_pThreadStatus.ComputeTime(OTS_THREAD_TIME_TYPE.STOPPED);
+                    m_pThreadStatus.ComputeTime(OTSIncAMeasureApp.OTSMesureControl.OTS_THREAD_TIME_TYPE.STOPPED);
 
                 // update thread measure status class, let the main thread know that this sample measurement failed
                 ST_MSTMsg MsgSmpFailed=new ST_MSTMsg(); ;
@@ -337,27 +338,27 @@ namespace OTSModelSharp
 				        return;
 			    }
 
-    // record end time
-    m_pThreadStatus.ComputeTime(OTS_THREAD_TIME_TYPE.STOPPED);
+               // record end time
+               m_pThreadStatus.ComputeTime(OTSIncAMeasureApp.OTSMesureControl.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();
+              // update thread measure status class, let the main thread know that this sample measurement successes
+               ST_MSTMsg MsgSmpSuccess=new ST_MSTMsg();
               //  memset(&MsgSmpSuccess, 0, sizeof(ST_MSTMsg));
-    MsgSmpSuccess.iMsgType = ENUM_MSG_TYPE.MSAMPLESTATUS;
-	MsgSmpSuccess.STMSampleStu.iMeasureSampleStatus = (int) OTS_MSR_SAMPLE_STATUS.SUCCESSED;
+              MsgSmpSuccess.iMsgType = ENUM_MSG_TYPE.MSAMPLESTATUS;
+	          MsgSmpSuccess.STMSampleStu.iMeasureSampleStatus = (int) OTS_MSR_SAMPLE_STATUS.SUCCESSED;
                 // memcpy(MsgSmpSuccess.STMSampleStu.cSampleName, pSample->GetName(), sizeof(pSample->GetName()));
-         ProgressEvent(MsgSmpSuccess);
+              ProgressEvent(MsgSmpSuccess);
 
 			//SendMessageToMeasureApp(MsgSmpSuccess);
 
-    // continue to the next sample
-    listMeasuredSamples.Add (pSample.GetName());
+            // continue to the next sample
+              listMeasuredSamples.Add (pSample.GetName());
 		}
 
             // measurement completed
-            m_pThreadStatus.SetStatus(OTS_MSR_THREAD_STATUS.COMPLETED);
+            m_pThreadStatus.SetStatus(OTSIncAMeasureApp.OTSMesureControl.OTS_MSR_THREAD_STATUS.COMPLETED);
             // record end time
-            m_pThreadStatus.ComputeTime(OTS_THREAD_TIME_TYPE.STOPPED);
+            m_pThreadStatus.ComputeTime(OTSIncAMeasureApp.OTSMesureControl.OTS_THREAD_TIME_TYPE.STOPPED);
 
             ThreadOver();
 	}

+ 19 - 16
OTS/OTSModelSharp/Measure/GetBSEPic/OTSFieldMgr.cs

@@ -47,6 +47,8 @@ namespace OTSModelSharp
 
         const String BMP_IMG_FILE_EXT = ".bmp";
 
+        CPosXray PosXray = new CPosXray();
+
 
 
         //-------------public-----------------
@@ -543,29 +545,30 @@ namespace OTSModelSharp
             {
                 mapSmallParts[smallP.GetType()].Add(smallP);
             }
-            List<CSmallParticleInfoDB> smallparts = new List<CSmallParticleInfoDB>();
+            List<CSmallParticleInfo> smallparts = new List<CSmallParticleInfo>();
             
-            foreach (KeyValuePair<int, List<COTSParticle>> parts in mapSmallParts)
-            {
-                CSmallParticleInfoDB partInfo = new CSmallParticleInfoDB();
-                partInfo.FieldId = parts.second[0].GetFieldId();
-                partInfo.AveGray = parts.second[0].GetAveGray();
-                partInfo.Quantity = parts.second.Count() / m_smallParticlePercentage;
-                partInfo.TypeId = parts.first;
-                partInfo.TypeColor = parts.second[0].TypeColor();
-                partInfo.TypeName = parts.second[0].TypeName();
+            foreach (KeyValuePair<int, List<COTSParticle>> part in mapSmallParts)
+            {               
+                CSmallParticleInfo partInfo = new CSmallParticleInfo();
+                partInfo.FieldId = m_listSmallParticles[0].GetFieldId();
+                partInfo.AveGray = m_listSmallParticles[0].GetAveGray();
+                partInfo.Quantity = m_listSmallParticles.Count()/ Convert.ToInt32(m_smallParticlePercentage);
+                partInfo.TypeId = m_listSmallParticles.Count;//part.First;
+
+                partInfo.TypeColor = m_listSmallParticles[0].TypeColor();
+                partInfo.TypeName = m_listSmallParticles[0].TypeName();
                 double area = 0;
-                foreach (KeyValuePair<int, List<COTSParticle>> p in parts.second)
+                foreach(var p in m_listSmallParticles)
                 {
-                    area += p.GetArea();
+                    area += m_listSmallParticles[0].GetArea();//p.GetArea();
                 }
                 partInfo.Area = area / m_smallParticlePercentage;
                 smallparts.Add(partInfo);
             }
-            foreach (CSmallParticleInfo smallp in smallparts)
-            {
-                smallPartDB.SaveAKindOfSmallParticle(smallp, CPosXray(null),  Point(0,0));
-            }
+                 foreach(CSmallParticleInfo smallp in smallparts)
+                 {
+                  smallPartDB.SaveAKindOfSmallParticle(smallp, PosXray, new Point(0,0));
+                 }
             // ok, return TRUE
             return true;
         }

+ 646 - 49
OTS/OTSModelSharp/Measure/GetBSEPic/SmplMsrResultFileMgr.cs

@@ -1,6 +1,9 @@
 using OTSDataType;
+using OTSModelSharp.DTL;
 using System;
 using System.Collections.Generic;
+using System.Drawing;
+using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -29,51 +32,211 @@ namespace OTSModelSharp
 
         int _CRTDBG_REPORT_FLAG = -1;
 
-        //----------------public--------------------
+        const String SMPL_MSR_RESULT_FILE_EXT = ".rst";
+
+        // fields file sub-directory string
+        const String SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER = "FIELD_FILES";
+
+        public OTS_MSR_SAMPLE_STATUS m_nStatus;
+       
+        CIncAFileMgr m_IncAFileMgr = new CIncAFileMgr("");
+        CIncADataDB m_IncADataDB = new CIncADataDB("",null);
+
+        CSQLiteDB m_generalInfoTable;
+
+        private string conStr;
+        //----------------public-----------------
         public CSmplMsrResultFileMgr(string workingFolder)
         {
             m_strWorkingFolder = workingFolder;
             m_listAnalysisXray.Clear();
         }
-        public bool Init(COTSSample a_pSample)
+        //public bool Init(COTSSample a_pSample)
+        //{
+        //    if (a_pSample!=null )
+        //    {
+        //        // invalid sample pointer
+        //        logger.Info("Init: failed to create the working directory.");
+        //        return false;
+        //    }
+        //    // sample name
+        //    string strSmplName = a_pSample.GetName();
+        //    strSmplName.Trim();
+        //    if (strSmplName==null)
+        //    {
+        //        // the sample name string can't be an empty string
+        //        logger.Info(System.IO.Directory.GetCurrentDirectory(), "Init: the sample name string is an empty string.");
+        //        return false;
+        //    }
+        //    // the working directory string can't be an empty string
+        //    if (m_strWorkingFolder==null )
+        //    {
+        //        // the working directory is empty
+        //        logger.Info("Init: the woring folder directory string is an empty string.");
+        //        return false;
+        //    }
+        //    // check if the working directory is there
+        //    //COTSEDSBase.Exists(m_strWorkingFolder);
+        //    COTSEDSBase cOTSEDSBase = new COTSEDSBase();
+        //    if (!cOTSEDSBase.Exists(m_strWorkingFolder))
+        //    {
+        //        // field files directory exists not exists, creates it
+        //        COTSFileSys cOTSFileSys = new COTSFileSys();
+        //        if (!cOTSFileSys.CreateFolder(m_strWorkingFolder))
+        //        {
+        //            // failed to create the field files directory
+        //            return false;
+        //        }
+        //    }
+        //        // ok, return TRUE
+        //        SetSample(a_pSample);
+        //    return true;
+        //}
+
+       public bool Init(COTSSample a_pSample)
         {
-            if (a_pSample!=null )
-            {
-                // invalid sample pointer
-                logger.Info("Init: failed to create the working directory.");
-                return false;
-            }
             // sample name
-            string strSmplName = a_pSample.GetName();
+            String strSmplName = a_pSample.GetName();
             strSmplName.Trim();
-            if (strSmplName==null)
+            if (strSmplName=="")
             {
                 // the sample name string can't be an empty string
-                logger.Info(System.IO.Directory.GetCurrentDirectory(), "Init: the sample name string is an empty string.");
+
                 return false;
             }
+
             // the working directory string can't be an empty string
-            if (m_strWorkingFolder==null )
+            if (m_strWorkingFolder=="")
             {
                 // the working directory is empty
-                logger.Info("Init: the woring folder directory string is an empty string.");
+
                 return false;
             }
+
             // check if the working directory is there
-            //COTSEDSBase.Exists(m_strWorkingFolder);
-            COTSEDSBase cOTSEDSBase = new COTSEDSBase();
-            if (!cOTSEDSBase.Exists(m_strWorkingFolder))
+            if (!Exists(m_strWorkingFolder))
+            {
+                // the working directory is not exit, create it
+                if (!CreateFolder(m_strWorkingFolder))
+                {
+                    // failed to create the working directory
+
+                    return false;
+                }
+            }
+
+            // sample measure file pathname
+            String strPathname = m_strWorkingFolder + strSmplName + SMPL_MSR_RESULT_FILE_EXT;
+
+
+            // file not exists, creates it
+            if (!CreateFileMgr(strPathname))
+            {
+                // failed to create the file
+
+                return false;
+            }
+
+
+            // get field files directory string
+            String strFieldFileSubFolder = GetFieldFileSubFolderStr();
+
+            // check if the field files directory exists
+            if (!Exists(strFieldFileSubFolder))
             {
                 // field files directory exists not exists, creates it
-                COTSFileSys cOTSFileSys = new COTSFileSys();
-                if (!cOTSFileSys.CreateFolder(m_strWorkingFolder))
+                if (!CreateFolder(strFieldFileSubFolder))
                 {
                     // failed to create the field files directory
+
                     return false;
                 }
             }
-                // ok, return TRUE
-                SetSample(a_pSample);
+
+            // ok, return TRUE
+            SetSample(a_pSample);
+            return true;
+        }
+
+        // creates a folder.
+        public bool CreateFolder(string a_strFolder)
+        {
+            // make sure the folder name string are not empty
+            String strFolder = a_strFolder;
+            strFolder.Trim();
+            if (strFolder=="")
+            {
+
+                return false;
+            }
+
+            // if the folder exist?
+            if (Exists(strFolder))
+            {
+                // is a real folder?
+                if (IsFolder(strFolder))
+                {
+                    return true;
+                }
+            }
+
+            // create folder
+
+            // remove back slash if there
+            String strParentFolder = strFolder;
+            strParentFolder.Trim();
+
+            // find last back slash position
+            int nBackSlashPos = strParentFolder.LastIndexOf('\\');
+            if (nBackSlashPos > 0)
+            {
+                // get the folder name 
+                String strFolderName = strParentFolder.PadRight(strParentFolder.Length- nBackSlashPos - 1);
+
+                // separate the folder string
+                strParentFolder = strParentFolder.PadLeft(nBackSlashPos);
+                if (!IsValidFileName(strFolderName))
+                {
+
+                    return false;
+                }
+
+                // try to create folder from the base folder 
+                if (!CreateFolder(strParentFolder))
+                {
+
+                    return false;
+                }
+            }
+
+            // create the folder
+           
+            Directory.CreateDirectory(strFolder);
+
+            // return folder create result
+            return true;
+        }
+
+        // check if the given string is valid file name or not
+       public bool IsValidFileName(string a_sFileName)
+        {
+            String strFileName = a_sFileName;
+            const String INVALIDFILENAMECHAR="\\/:*?\"<>";
+
+            return strFileName.FindOneOf(INVALIDFILENAMECHAR) == -1;
+        }
+
+        // check if this is an existing folder
+        public  bool IsFolder(string a_strFolder)
+        {
+            
+            return Directory.Exists(a_strFolder);
+        }
+
+        // check if the file exists or not
+        public  bool Exists(string a_sPath)
+        {
+            Directory.Exists(a_sPath);
             return true;
         }
         // Load 
@@ -136,46 +299,119 @@ namespace OTSModelSharp
             return true;
 
         }
-        public bool Load(string a_strPathname)
+        //public bool Load(string a_strPathname)
+        //{
+
+        //    // get path of the pathname
+        //    COTSHelper cOTSHelper = new COTSHelper();
+        //    string strFilePath = cOTSHelper.GetFolderName(a_strPathname);
+        //    if (strFilePath==null)
+        //    {
+        //        // file path string is an empty string 
+        //        logger.Info("Load: file path string is an empty string.");
+        //        return false;
+        //    }
+        //    // field file sub folder string
+        //    CSmplMsrResultFile cSmplMsrResultFile = new CSmplMsrResultFile();
+        //    string strFieldFileSubFolder = strFilePath + "\\" + cSmplMsrResultFile.SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
+        //    // check if the field file sub folder exists
+        //    COTSEDSBase cOTSFileSys = new COTSEDSBase();
+        //    if (!cOTSFileSys.Exists(strFieldFileSubFolder))
+        //    {
+        //        // field files folder doesn't exist
+        //        logger.Info("Load: field files folder doesn't exist (%s).");
+        //        return false;
+        //    }
+        //    SetWorkingFolderStr(strFieldFileSubFolder);
+        //    // create sample measure result file
+        //    CSmplMsrResultFile pSmplMsrResultFile = new CSmplMsrResultFile();
+        //    XmlDocument xmlDoc = new XmlDocument();
+        //    xmlDoc.LoadXml(a_strPathname);
+        //    XmlNode root = xmlDoc.SelectSingleNode("XMLData");
+        //    pSmplMsrResultFile.Serialize(false, xmlDoc, root);
+
+        //    // file version
+        //    CSmplMsrResultFile cSmplMsrResult = new CSmplMsrResultFile();
+        //    string strFileVersion = cSmplMsrResult.GetFileVersion();
+        //    COTSHelper OTSHelper = new COTSHelper();
+        //    System.UInt32 nFileVersion = OTSHelper.GetVersionFromString(strFileVersion);
+        //    if (nFileVersion==0)
+        //    {
+        //        // invalid file
+        //        logger.Info("Load: invalid sample measure result file %s");
+        //        return false;
+        //    }
+        //    // sample measure result file
+        //    m_pSmplMsrResultFile = pSmplMsrResultFile;
+        //    SetPathName(a_strPathname);
+        //    this.LoadFieldDataFromDB(a_strPathname);
+        //    // ok, return TRUE
+        //    return true;
+        //}
+
+        // Load 
+      public  bool Load(String a_strPathname /*= _T("")*/)
         {
-            
+            int tmpFlag = _CRTDBG_REPORT_FLAG;
+            //tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
+           // _CrtSetDbgFlag(tmpFlag);
+
+            //_CrtSetBreakAlloc(7415416);
+            // AFX_MANAGE_STATE(AfxGetStaticModuleState());
+
+            // check the pathname string
+            a_strPathname.Trim();
+            if (a_strPathname=="")
+            {
+                // open
+                //CFileDialog dlg(TRUE, SMPL_MSR_RESULT_FILE_EXT, NULL, OFN_FILEMUSTEXIST, SMPL_MSR_RESULT_FILE_FILTER);
+                //if (dlg.DoModal() != IDOK)
+                //{
+                //    // user canceled loading
+
+                //    return false;
+                //}
+
+                FolderBrowserDialog FileDialog = new FolderBrowserDialog();//创建一个文件对话框
+                if (FileDialog.ShowDialog() != DialogResult.OK)
+                {
+                    // user canceled loading
+                    logger.Info("Load: user canceled loading.");
+                    return false;
+                }
+                a_strPathname = GetPathName();
+            }
+
             // get path of the pathname
-            COTSHelper cOTSHelper = new COTSHelper();
-            string strFilePath = cOTSHelper.GetFolderName(a_strPathname);
-            if (strFilePath==null)
+            String strFilePath = GetFolderName(a_strPathname);
+            if (strFilePath=="")
             {
                 // file path string is an empty string 
-                logger.Info("Load: file path string is an empty string.");
+
                 return false;
             }
+
             // field file sub folder string
-            CSmplMsrResultFile cSmplMsrResultFile = new CSmplMsrResultFile();
-            string strFieldFileSubFolder = strFilePath + "\\" + cSmplMsrResultFile.SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
+            String strFieldFileSubFolder = strFilePath + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
+
             // check if the field file sub folder exists
-            COTSEDSBase cOTSFileSys = new COTSEDSBase();
-            if (!cOTSFileSys.Exists(strFieldFileSubFolder))
+            if (!Exists(strFieldFileSubFolder))
             {
                 // field files folder doesn't exist
-                logger.Info("Load: field files folder doesn't exist (%s).");
+
                 return false;
             }
+
             SetWorkingFolderStr(strFieldFileSubFolder);
             // create sample measure result file
             CSmplMsrResultFile pSmplMsrResultFile = new CSmplMsrResultFile();
-            XmlDocument xmlDoc = new XmlDocument();
-            xmlDoc.LoadXml(a_strPathname);
-            XmlNode root = xmlDoc.SelectSingleNode("XMLData");
-            pSmplMsrResultFile.Serialize(false, xmlDoc, root);
 
             // file version
-            CSmplMsrResultFile cSmplMsrResult = new CSmplMsrResultFile();
-            string strFileVersion = cSmplMsrResult.GetFileVersion();
-            COTSHelper OTSHelper = new COTSHelper();
-            System.UInt32 nFileVersion = OTSHelper.GetVersionFromString(strFileVersion);
-            if (nFileVersion==0)
-            {
-                // invalid file
-                logger.Info("Load: invalid sample measure result file %s");
+            String strFileVersion = pSmplMsrResultFile.GetFileVersion();
+            uint nFileVersion = GetVersionFromString(strFileVersion);
+            if (nFileVersion == 0)
+            {// invalid file
+
                 return false;
             }
             // sample measure result file
@@ -185,6 +421,228 @@ namespace OTSModelSharp
             // ok, return TRUE
             return true;
         }
+
+        // Get file versio
+        // File Version should be format <Major version>.<Minor version>.<Build version>, like 1.2.3
+       public uint GetVersionFromString(string a_sVersion)
+        {
+            int nMajorVersion = 0;
+            int nMinorVersion = 0;
+            int nBuildVersion = 0;
+
+            uint nVersion = 0;
+            if (GetMajorVersionFromString(a_sVersion, nMajorVersion) &&
+                GetMinorVersionFromString(a_sVersion, nMinorVersion) &&
+                GetBuildVersionFromString(a_sVersion, nBuildVersion))
+            {
+                nVersion = (uint)nMajorVersion * 10000 + (uint)nMinorVersion * 100 + (uint)nBuildVersion;
+            }
+
+            return nVersion;
+        }
+
+       public bool GetMinorVersionFromString(string a_sVersion, int a_nVersion)
+        {
+            // version string
+            String strVersion=a_sVersion;
+
+            // get major file version string position first
+            int nPosFirst = strVersion.IndexOf('.');
+            if (nPosFirst < 0)
+            {
+                // failed to find major file version string
+
+                return false;
+            }
+
+            // get minor file version string position           
+            int nPosSecond = strVersion.IndexOf('.', nPosFirst + 1);
+            int nStrLength = nPosSecond - nPosFirst - 1;
+            if (nStrLength <= 0)
+            {
+                // failed to find minor file version string
+
+                return false;
+            }
+
+            // get minor file version string
+            String strMinorVersion = strVersion.Remove(nPosFirst + 1, nStrLength);
+              
+
+            // the minor file version string can't be empty
+            strMinorVersion.Trim();
+            if (strMinorVersion=="")
+            {
+                // failed to find minor file version string
+
+                return false;
+            }
+
+            // convert the minor version string to minor version number
+            if (!StringToInt(strMinorVersion, a_nVersion))
+            {
+                // failed to convert the major file version string to number
+
+                return false;
+            }
+
+            // ok, return TRUE
+            return true;
+        }
+
+        public  bool GetMajorVersionFromString(string a_sVersion, int a_nVersion)
+        {
+            // version string
+            String strVersion=a_sVersion;
+
+            // get major file version string position
+            int nPosFirst = strVersion.IndexOf('.');
+            if (nPosFirst <= 0)
+            {
+                // failed to find major file version
+
+                return false;
+            }
+
+            // get major file version string
+            String strMajorVersion = strVersion.PadLeft(nPosFirst);
+
+            // the major file version string can't be empty
+            strMajorVersion.Trim();
+            if (strMajorVersion=="")
+            {
+                // failed to find major file version
+
+                return false;
+            }
+
+            // convert the major version string to major version number
+            if (!StringToInt(strMajorVersion, a_nVersion))
+            {
+                // failed to convert the major file version string to number
+                
+                return false;
+            }
+
+            // ok, return TRUE
+            return true;
+        }
+
+       public bool GetBuildVersionFromString(string a_sVersion, int a_nBuild)
+        {
+            // version string
+            String strVersion=a_sVersion;
+
+            // get major file version string position first          
+            int nPosFirst = strVersion.IndexOf('.');
+            if (nPosFirst < 0)
+            {
+                // failed to find major file version string
+
+                return false;
+            }
+
+            // get minor file version string position          
+            int nPosSecond = strVersion.IndexOf('.', nPosFirst + 1);
+           
+            if (nPosSecond < 0)
+            {
+                // failed to find minor file version string
+
+                return false;
+            }
+
+            // get build string position
+            int nStrLength = strVersion.Length - nPosSecond - 1;
+            if (nStrLength <= 0)
+            {
+                // failed to find build string
+
+                return false;
+            }
+
+            // get build string
+            String strBuild = strVersion.PadRight(nStrLength);
+
+            // build string can't be empty
+            strBuild.Trim();
+            if (strBuild=="")
+            {
+                // failed to convert the build string to number
+
+                return false;
+            }
+
+            // convert the build string to build number
+            if (!StringToInt(strBuild, a_nBuild))
+            {
+                // failed to convert the build string to number
+
+                return false;
+            }
+
+            // ok, return TRUE
+            return true;
+        }
+
+        // Strings to int.
+        public bool StringToInt(string a_sValue, int a_nValue)
+        {
+            if (!IsDigitString(a_sValue))
+            {
+
+                return false;
+            }
+
+            a_nValue = Convert.ToInt32(a_sValue);
+
+            return true;
+        }
+
+        // Determines whether is digit string.
+       public bool IsDigitString(string a_sValue)
+        {
+            String strInt = a_sValue;
+            strInt.Trim();
+
+            if (strInt=="")
+            {
+
+                return false;
+            }
+
+            int nStart = 0;
+
+            if (strInt[nStart] == '-')
+            {
+                ++nStart;
+            }
+
+            // cycle through string and check each character if it is a digit
+            for (; nStart < strInt.Length; ++nStart)
+            {
+                if (strInt[nStart] !='-' )
+                {
+
+                    return false;
+                }
+            }
+
+            return true;
+        }
+
+
+
+        // gets the name of the folder
+        public String GetFolderName(String a_strPathName)
+        {           
+            string str = "";
+            char[] sPath = new char[COTSModelConst.MAX_PATH];
+            str.CopyTo(0, sPath, 0, Convert.ToInt32(a_strPathName));
+
+            return sPath.ToString();          
+        }
+
         public bool LoadFieldDataFromDB(string a_strPathname)
         {
             // check the pathname string
@@ -202,8 +660,8 @@ namespace OTSModelSharp
                 a_strPathname = FileDialog.SelectedPath;
             }
             // get path of the pathname
-            COTSHelper cOTSHelper = new COTSHelper();
-            string strFilePath = cOTSHelper.GetFolderName(a_strPathname);
+           // COTSHelper cOTSHelper = new COTSHelper();
+            string strFilePath = GetFolderName(a_strPathname);
             if (strFilePath==null)
             {
                 // file path string is an empty string 
@@ -214,8 +672,8 @@ namespace OTSModelSharp
             CSmplMsrResultFile cSmplMsrResultFile = new CSmplMsrResultFile();
             string strFieldFileSubFolder = strFilePath + "\\" + cSmplMsrResultFile.SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
             // check if the field file sub folder exists
-            COTSEDSBase cOTSFileSys = new COTSEDSBase();
-            if (!cOTSFileSys.Exists(strFieldFileSubFolder))
+           // COTSEDSBase cOTSFileSys = new COTSEDSBase();
+            if (!Exists(strFieldFileSubFolder))
             {// field files folder doesn't exist
                 logger.Info("Load: field files folder doesn't exist (%s).");
                 return false;
@@ -243,8 +701,147 @@ namespace OTSModelSharp
                 return false;
             }
         }
-        // Save 
-        public bool Save(string a_strPathname )
+
+       public bool GetAllFieldsFromDB(List<COTSFieldData>  allFlds, CMsrSampleStatus status, CMsrResults rst, double aFieldArea)
+        {
+            String sDatabaseName = GetPathName();
+
+            if (Exists(sDatabaseName))
+            {
+                if (!Open(m_strPathName,false))
+                {
+                    
+                    return false;
+                }
+            }
+            List<Point> completedfld = new List<Point>();
+            var IncADataDB = m_IncAFileMgr.GetIncADB();
+
+            m_IncADataDB.GetAllFieldsRecord(ref allFlds);
+            var SegmentDB = m_IncAFileMgr.GetSegmentDB();
+            double msrFldsArea = 0;
+
+            // std::map<int, COTSParticleList> mapTypeParticles;//record typeId relevants particlelist;
+            Dictionary<int, List<COTSParticle>> mapTypeParticles = new Dictionary<int, List<COTSParticle>>();
+            // std::map<std::vector<int>, COTSSegmentsList> AllSegments;
+            Dictionary<List<int>, List<COTSParticle>> AllSegments = new Dictionary<List<int>, List<COTSParticle>>();
+            if (SegmentDB.GetAllSegmentsRecord(AllSegments))
+            {
+                int nCol;
+                foreach(var fld in allFlds)
+    
+            {
+                    int fldId = fld.GetId();
+                    List<COTSParticle> parts = fld.GetParticleList();
+                    foreach(var part in parts)
+    
+                {
+                        List<int> fldvec = new List<int>();
+                        fldvec.Add(fldId);
+                        fldvec.Add(part.GetTagId());
+
+                        var itr = AllSegments.Values;
+                           
+                        if (itr != AllSegments.Last)
+                        {
+                            COTSFeature f = new COTSFeature();
+                            f.SetSegmentsList(itr.second);
+                            part.SetFeature(f);
+                        }
+                        mapTypeParticles[part.GetType()].Add(part);
+                    }
+                    completedfld.Add(fld.GetPosition());
+                    msrFldsArea += aFieldArea;
+                }
+            }
+            // get MsrStatus info from DB.
+            var GenDB = GetGeneralInfoDB();
+            String strTimeStart = "";
+            String strTimeEnd = "";
+            String strRstStatus = "";
+            GenDB.GetStringValue(GetTableItemNameTimeStart(), strTimeStart);
+            GenDB.GetStringValue(GetTableItemNameTimeEnd(), strTimeEnd);
+            GenDB.GetStringValue(GetTableItemNameResultStatus(), strRstStatus);
+            status.SetCompletedFieldsCenter(completedfld);
+            status.SetCompletedFields(completedfld.Count);
+            DateTime timeStart, timeEnd;
+            TimeSpan timeSpan;
+            timeStart = GetDateTimeFromString(strTimeStart);
+            timeEnd = GetDateTimeFromString(strTimeEnd);
+            status.SetStartTime(timeStart);
+            status.SetEndTime(timeEnd);
+            status.SetUsedTime(timeEnd - timeStart);
+            status.SetStatus(m_nStatus);           
+            //get MsrResults data from map.
+            List<CMsrResultItem> rstItms = new List<CMsrResultItem>();
+            double allPartArea = 0;
+            foreach (var typeParticles in mapTypeParticles)
+            {
+                CMsrResultItem rstItm = new CMsrResultItem();
+                int typeNum = 0;
+                double typeArea = 0;
+                foreach (var p in mapTypeParticles)
+                {
+                    typeNum += 1;
+                    typeArea += Convert.ToInt32(p);
+                }
+                rstItm.SetTypeId(Convert.ToInt32(typeParticles));
+                rstItm.SetNumber((uint)typeNum);
+                rstItm.SetArea((uint)typeArea);
+                rstItms.Add(rstItm);
+                allPartArea += typeArea;
+            }
+            rst.SetResultItems(rstItms);
+            rst.SetMeasuredArea((uint)msrFldsArea * 1000000);
+            rst.SetRadio(allPartArea / (msrFldsArea * 1000000));
+            return true;
+
+        }
+
+       public String GetTableItemNameTimeStart()
+        {
+            return COTSModelConst.g_sTableItemNameTimeStart;
+        }
+      public  String GetTableItemNameTimeEnd()
+        {
+            return COTSModelConst.g_sTableItemNameTimeEnd;
+        }
+       public String GetTableItemNameResultStatus()
+        {
+            return COTSModelConst.g_sTableItemNameResultStatus;
+        }
+
+        public CSQLiteDB GetGeneralInfoDB()
+        {
+            if (m_generalInfoTable != null)
+            {
+                var datastorePtr = GetDatastore();
+
+                if (datastorePtr != null)
+                {
+
+                    m_generalInfoTable.GetDatastore();
+                }
+            }
+
+            return m_generalInfoTable;
+
+        }
+
+        public string GetDatastore()
+        {
+            return conStr;
+        }
+
+        public  DateTime GetDateTimeFromString( String  a_DateTime)
+	{
+            DateTime ole_time = new DateTime();           
+            DateTime.Now.ToString();
+            return ole_time;
+	}
+
+    // Save 
+    public bool Save(string a_strPathname )
         {
             // safety check 
             if (m_pSmplMsrResultFile==null)

+ 1 - 1
OTS/OTSModelSharp/Measure/GetParam/COTSProjMgrFile.cs

@@ -14,7 +14,7 @@ using static OTSDataType.otsdataconst;
 
 namespace OTSModelSharp
 {
-    class COTSProjMgrFile
+   public  class COTSProjMgrFile
     {
 
         // SEM stage data

+ 1 - 1
OTS/OTSModelSharp/Measure/GetParticle/SmallParticles/SmallParticleInfoDB.cs

@@ -16,7 +16,7 @@ namespace OTSModelSharp.DTL
 		
         }
 
-       public bool SaveAKindOfSmallParticle( CSmallParticleInfoDB a_pParticleInfo,  CPosXray a_pXray, Point fldPos)
+       public bool SaveAKindOfSmallParticle( CSmallParticleInfo a_pParticleInfo,  CPosXray a_pXray, Point fldPos)
 	   {
 		
         var tableInfoPtr = GetTableInfo();

+ 1 - 0
OTS/OTSModelSharp/OTSModelSharp.csproj

@@ -77,6 +77,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="CSmallParticleInfo.cs" />
     <Compile Include="DataPublic.cs" />
     <Compile Include="DataPublicForModel.cs" />
     <Compile Include="DTLBase\CSQLiteDB.cs" />

+ 6 - 2
OTS/OTSModelSharp/Other/OTSModelConst.cs

@@ -92,8 +92,12 @@ namespace OTSModelSharp
 
         public const int IDS_MEASURE_IMAGE_MODE = 12548;
 
-       
+       public const String g_sTableItemNameTimeStart="TimeStart";
+       public const String g_sTableItemNameTimeEnd="TimeEnd";
+       public const String g_sTableItemNameResultStatus="ResultStatus";
+
+
+
 
-       
     }
 }