Kaynağa Gözat

处理类没有包含在项目中问题

sunyi 5 yıl önce
ebeveyn
işleme
f4cdc38955

+ 23 - 0
OTS/OTSModelSharp/DTLBase/SQLiteFactory.cs

@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OTSModelSharp.DTL
+{
+    class SQLiteFactory
+    {
+        
+                    /// <param name="conStr">数据库地址</param>
+                    /// <param name="_table">表结构</param>
+                  
+         static public IDBBase CreateNewSQLiteTable(string _conStr, TableModel _table)
+        {
+            dbHelper = new SqlHelper("data source='" + _conStr + "'");
+            table = _table;
+            conStr = _conStr;
+        }
+
+    }
+}

+ 1804 - 0
OTS/OTSModelSharp/Measure/GetParam/COTSProjMgrFile.cs

@@ -0,0 +1,1804 @@
+using OTSDataType;
+using OTSIncAMeasureApp.OTSMeasureControl;
+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;
+using System.Windows;
+using System.Windows.Forms;
+using static OTSDataType.otsdataconst;
+
+namespace OTSModelSharp
+{
+   public  class COTSProjMgrFile
+    {
+
+        // SEM stage data
+        CSEMStageData m_pSEMStageData;
+        // stage
+        CStage m_pStage;
+
+        COTSGeneralParameters m_DefaultParameters;
+
+        // sample list
+        List<COTSSample> m_listSamples;
+
+        List<CHoleBSEImg> m_listHoleBSEImg;
+
+        bool m_bModify;
+
+        // path name
+        String m_strPathName;
+
+        // working sample index
+        int m_nWorkingSampeIndex;
+
+        const String UNTITLED_FILE_NAME = "Untitled";
+
+        //以下这两个原来在SmplMsrResultFile中
+        // fields file sub-directory string
+        const String SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER = "FIELD_FILES";
+
+        // Inclusion file name
+        const String SMPL_MSR_RESULT_INCLUSION_FILE = "Inclusion.db";//put all the table in one db file so that report can make join query.
+
+       // CDBStoreBase m_datastorePtr;
+        CSQLiteDBFile m_datastore;
+
+        IMeasureHardware m_HardwareMgr;
+
+        public OTS_MSR_SAMPLE_STATUS m_nStatus;
+
+        CIncAFileMgr m_IncAFileMgr = new CIncAFileMgr("");
+        
+        CIncADataDB m_IncADataDB ;
+
+        CSegmentDB m_Segment ;
+
+        CSQLiteDB m_generalInfoTable;
+
+
+        public COTSProjMgrFile()
+	{
+		    Init();
+            m_HardwareMgr = new MeasureHardware();
+        }
+
+        // initialization
+      public  void Init()
+        {
+            m_pSEMStageData = new CSEMStageData();
+            m_pStage = new CStage();
+           
+            m_DefaultParameters = new COTSGeneralParameters();
+            m_listSamples.Clear();
+            m_listHoleBSEImg.Clear();
+            //m_listSysSTDItem.clear();
+
+            m_bModify = false;
+            m_strPathName = "";
+            m_nWorkingSampeIndex = -1;
+
+        }
+
+        public void OTSProjMgrFile(COTSProjMgrFile a_oSource)
+        {
+            // can't copy itself
+            if (a_oSource == this)
+            {
+                return;
+            }
+
+            // copy data over
+            Duplicate(a_oSource);
+        }
+
+        // duplication
+      public   void Duplicate( COTSProjMgrFile a_oSource)
+	{
+		// initialization
+		Init();
+
+        // copy data over
+        m_pSEMStageData = new CSEMStageData(a_oSource.m_pSEMStageData);
+		m_pStage = new CStage(a_oSource.m_pStage);		
+		m_DefaultParameters = new COTSGeneralParameters(a_oSource.m_DefaultParameters);
+		
+		foreach (var pHoleBSEImg in a_oSource.m_listHoleBSEImg)
+		{
+			CHoleBSEImg pHoleBSEImgNew =(new CHoleBSEImg(pHoleBSEImg));
+			m_listHoleBSEImg.Add(pHoleBSEImgNew);
+		}
+		foreach (var pSample in a_oSource.m_listSamples)
+		{
+			COTSSample pSampleNew =new COTSSample();
+			m_listSamples.Add(pSampleNew);
+		}
+
+        m_bModify = a_oSource.m_bModify;
+		m_strPathName = a_oSource.m_strPathName;
+		m_nWorkingSampeIndex = a_oSource.m_nWorkingSampeIndex;
+	}
+
+        // file
+      public  bool NewFile()
+        {
+            // file invalidation
+            if (!IsValid())
+            {
+                // shouldn't happen, file is invalid
+
+                return false;
+            }
+
+            // set file name 
+            SetPathName(UNTITLED_FILE_NAME);
+            // Ok, return TRUE
+            return true;
+        }
+
+      public   bool IsValid()
+        {
+            if (m_pSEMStageData!=null || m_pSEMStageData == null)
+            {
+                return false;
+            }
+            else if (m_pStage!=null || m_pStage == null)
+            {
+                return false;
+            }
+            else if (m_DefaultParameters!=null)
+            {
+                return false;
+            }
+
+            // Ok, return TRUE
+            return true;
+        }
+
+       public  void SetPathName(String a_strPathName) { m_strPathName = a_strPathName; }
+
+      public  bool Load()
+        {
+            // use dll resource
+            // AFX_MANAGE_STATE(AfxGetStaticModuleState());
+
+            // get file name
+            String strPathName = "";
+            // check file pathname
+            strPathName.Trim();
+            if (strPathName == "")
+            {
+                // file open dialog
+                OpenFileDialog openFileDialog = new OpenFileDialog();
+                if (openFileDialog.ShowDialog() != DialogResult.OK)
+                {
+                    return false;
+
+                }
+
+                // get file pathname
+
+                strPathName = openFileDialog.FileName;
+            }
+
+            //Init data
+            Cleanup();
+
+            // check if the file exist 
+            if (!Exists(strPathName))
+            {
+                // shouldn't happen, file does not exist
+
+                return false;
+            }
+
+                    
+            //-------------
+            foreach (var smpl  in m_listSamples)
+            {
+                // get path of the pathname
+                String strFilePath = GetFolderName(strPathName);
+                if (strFilePath=="")
+                {
+                    // file path string is an empty string 
+
+                    return false;
+                }
+
+                // field file sub folder string
+                String strFieldFileSubFolder = strFilePath + "\\" + smpl.GetName() + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
+
+                // check if the field file sub folder exists
+                if (!Exists(strFieldFileSubFolder))
+                {// field files folder doesn't exist
+
+                    return false;
+                }
+
+                String strIncAFilename = strFieldFileSubFolder + "\\" + SMPL_MSR_RESULT_INCLUSION_FILE;
+                CIncAFileMgr pIncAFileMgr = new CIncAFileMgr(strIncAFilename);
+                List<COTSFieldData> allFlds = new List<COTSFieldData>();
+                CMsrSampleStatus poMsrStatus = new CMsrSampleStatus();
+                poMsrStatus.GetStatus();
+                CMsrResults poMsrResults = smpl.GetMsrResults();
+                double aFldArea = smpl.CalculateAFieldArea();
+                if (GetAllFieldsFromDB(ref allFlds, poMsrStatus, poMsrResults, aFldArea))
+                {
+                    smpl.SetFieldsData(allFlds);
+                    // file validation
+                    if (m_pSEMStageData!= new CSEMStageData() || (m_pSEMStageData) == new CSEMStageData())
+                    {
+                        // invalid SME stage data
+
+                        return false;
+                    }
+                    if (m_pStage!= new CStage() || (m_pStage) == new CStage())
+                    {
+                        // invalid stage 
+
+                        return false;
+                    }
+
+                    // set modify flag
+                    SetModify(false);
+
+                    // set pathname
+                    SetPathName(strPathName);
+
+                    // set working sample
+                    if (m_listSamples.Count > 0)
+                    {
+                        m_nWorkingSampeIndex = 0;
+                    }
+                    else
+                    {
+                        m_nWorkingSampeIndex = -1;
+                    }
+
+
+                }
+                else
+                {
+                    return false;
+                }
+            }
+            //-----------------------------------------
+            return true;
+
+        }
+
+        // gets the name of the folder
+       public String GetFolderName(String a_strPathName)
+        {
+            string str = "";
+            char[] sPath=new char[otsdataconst.MAX_PATH];
+            str.CopyTo(0,sPath, 0, Convert.ToInt32(a_strPathName));
+                       
+            return sPath.ToString();
+        }
+
+        // check if the file exists or not
+      public  bool Exists(string a_sPath)
+        {
+            return  true;
+        }
+
+        // cleanup 
+      public  void Cleanup()
+        {
+            m_listHoleBSEImg.Clear();
+            m_listSamples.Clear();
+            
+            m_bModify = false;
+            m_strPathName = "";
+            m_nWorkingSampeIndex = -1;
+        }
+
+        // set modify flag
+       public void SetModify(bool a_bModify = true) { m_bModify = a_bModify; }
+
+        // file pathname
+       public String GetPathName() { return m_strPathName; }
+
+        public  bool GetAllFieldsFromDB(ref List<COTSFieldData > allFlds, CMsrSampleStatus status, CMsrResults rst, double aFieldArea)
+        {
+            String sDatabaseName = GetPathName();
+
+            if (Exists(sDatabaseName))
+            {
+                if (!Open(m_strPathName, false))
+                {
+                   
+                    return false;
+                }
+            }
+            List<System.Windows.Point> completedflds = new List<System.Windows.Point>();
+
+            CIncAFileMgr IncADataDBs = m_IncAFileMgr.GetIncADB();
+            m_IncADataDB.GetAllFieldsRecord(ref allFlds);
+            CSegmentDB SegmentDB = m_IncAFileMgr.GetSegmentDB();
+            double msrFldsArea = 0;
+            List<COTSParticle> mapTypeParticles=new List<COTSParticle>();//record typeId relevants particlelist;
+            // std::map<std::vector<int>, COTSSegmentsList> AllSegments;
+            List<COTSSegment> AllSegments = new List<COTSSegment>();
+            Dictionary<List<int>, List<COTSSegment>> mapSegments = new Dictionary<List<int>, List<COTSSegment>>();
+            if (SegmentDB.GetAllSegmentsRecord(mapSegments))
+            {
+                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.Find( 
+                    delegate(COTSSegment segment) 
+                    { 
+                    return segment.Equals(sDatabaseName); 
+                    });
+                        if (itr != AllSegments.Last())
+                        {
+                            COTSFeature f = new COTSFeature();
+                            f.SetSegmentsList(AllSegments, true);
+                            part.SetFeature(f);
+                        }
+                        mapTypeParticles[part.GetType()].GetDMax();
+                }
+                    completedflds.Add(fld.GetPosition());
+                    msrFldsArea += aFieldArea;
+                }
+
+              
+            }
+            // get MsrStatus info from DB.
+            var GenDB = GetGeneralInfoDB();//DBStoreFile类
+            String strTimeStart = "";
+            String strTimeEnd = "";
+            String strRstStatus = "";
+            GenDB.GetDatastore();
+            GenDB.GetTableQuery(strTimeStart);
+            GenDB.GetTableQuery(strTimeEnd);
+            GenDB.GetTableQuery(strRstStatus);          
+            status.SetCompletedFieldsCenter(completedflds);
+            status.SetCompletedFields(completedflds.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 += p.GetArea();
+                }
+                rstItm.SetTypeId(typeParticles.GetType());
+                rstItm.SetNumber((uint)typeNum);
+                rstItm.SetArea((uint)typeArea);
+                rstItms.Add(rstItm);
+                allPartArea += typeArea;
+            }
+            rst.SetResultItems(rstItms);
+            rst.SetMeasuredArea(Convert.ToUInt32(msrFldsArea * 1000000));
+            rst.SetRadio(allPartArea / (msrFldsArea * 1000000));
+            return true;
+
+        }
+
+        public   CSQLiteDB GetGeneralInfoDB()
+        {
+            if (m_generalInfoTable!=null)
+            {
+                var datastorePtr = GetDatastore();
+
+                if (datastorePtr!=null)
+                {
+
+                    m_generalInfoTable.GetDatastore();
+                }
+            }
+         
+            return m_generalInfoTable;
+
+        }
+
+        //public CGenInfoDB GetGeneralInfoDB()
+        // {
+        //     if (m_generalInfoTable!=null)
+        //     {
+        //         var datastorePtr = GetDatastore();
+
+        //         if (datastorePtr)
+        //         {
+        //             m_generalInfoTable.reset(new CGenInfoDB(datastorePtr));
+        //         }
+        //     }
+
+        //     return m_generalInfoTable;
+
+        // }
+
+        public DateTime GetDateTimeFromString( String  a_DateTime)
+	    {
+            DateTime ole_time = new DateTime();
+            ole_time.ToLocalTime();                
+		    return ole_time;
+	    }
+
+    //此方法为OTSSQLiteDLl中的DBStoreFile类
+    public  bool Open(string a_sFileName, bool a_bForce /*= TRUE*/)
+	{
+        
+        var datastorePtr = GetDatastore();
+
+		return datastorePtr.Open(a_sFileName, a_bForce);
+    }
+
+       public CSQLiteDBFile GetDatastore()
+        {
+            if (m_datastore!=null)
+            {
+                m_datastore = CreateNewSQLiteStore();
+            }
+
+            return m_datastore;
+        }
+
+       public CSQLiteDBFile CreateNewSQLiteStore()
+        {
+            CSQLiteDBFile SQLiteDBFile = new CSQLiteDBFile();
+
+            return SQLiteDBFile;
+
+        }
+
+       public  bool Save()
+        {
+            // Save or Save As, if strPathName is not empty, it is exist in the computer, this is a save action
+            String strPathName = GetPathName();
+
+            // is this a new file?
+            strPathName.Trim();
+            if (strPathName.CompareTo(UNTITLED_FILE_NAME) == 0)
+            {
+                // this is a new file 
+
+                // return save as result
+                return SaveAs();
+            }
+   
+            // set file modify flag
+            SetModify(false);
+
+            // Ok, return TRUE
+            return true;
+        }
+
+       public bool SaveAs()
+        {
+           // AFX_MANAGE_STATE(AfxGetStaticModuleState());
+
+            // save file dialog
+            String strFileName = "";
+            if (m_strPathName!="")
+            {
+                strFileName = GetFileName(m_strPathName);
+            }
+            // get file name
+            String strPathName = "";
+            // check file pathname
+            strPathName.Trim();
+            if (strPathName == "")
+            {
+                // file open dialog
+                OpenFileDialog openFileDialog = new OpenFileDialog();
+                if (openFileDialog.ShowDialog() != DialogResult.OK)
+                {
+                    return false;
+
+                }
+
+                // get file pathname
+
+                strPathName = openFileDialog.FileName;
+            }
+
+            // set file modify flag
+            m_bModify = false;
+
+            // Set project Path
+            SetPathName(strPathName);
+
+            // Ok, return TRUE
+            return true;
+        }
+
+        // Gets the name of the file.
+       public  String GetFileName(string a_strPathName)
+        {
+            return a_strPathName;
+
+        }
+
+        // SEM stage data
+       public CSEMStageData GetSEMStageData() { return m_pSEMStageData; }
+
+        // SEM stage data
+       public void SetSEMStageData(CSEMStageData a_pCSEMStageData)
+        {
+            // safety check
+           
+            if (a_pCSEMStageData!=null)
+            {
+                // invalid stage data pointer
+               
+                return;
+            }
+
+            m_pSEMStageData = new CSEMStageData(a_pCSEMStageData);
+        }
+
+        // stage
+       public CStage GetStage() { return m_pStage; }
+        void SetStage(CStage a_pStage)
+        {
+            // safety check
+            
+            if (a_pStage!=null)
+            {
+                // invalid input             
+                return;
+            }
+
+            m_pStage = new CStage(a_pStage);
+        }
+
+        // samples list
+      public List< COTSSample> GetSampleList() { return m_listSamples; }
+
+        // samples list
+      public  bool SetSampleList(List<COTSSample> a_listSample, bool a_bClear/* = TRUE*/)
+        {
+            // clear samples list if necessary 
+            if (a_bClear)
+            {
+                m_listSamples.Clear();
+            }
+
+            // go through the sample list of the source
+            foreach (var pSample in a_listSample)
+            {
+
+                // add the new sample into sample list
+                m_listSamples.Add(pSample);
+            }
+
+            return true;
+        }
+
+       public COTSSample GetSampleByIndex(int a_nIndex)
+        {
+            // safe check
+            if (a_nIndex < 0 || a_nIndex >= (int)m_listSamples.Count)
+            {
+                // invalid sample id
+
+                return null;
+            }
+            // get the matching sample
+            COTSSample pSample = m_listSamples[a_nIndex];
+
+            // return the sample
+            return pSample;
+        }
+
+      public  COTSSample GetSampleByName(String a_strSampleName)
+        {
+           
+            bool IsChanged = false;
+            for (int itr = 0; itr < m_listSamples.Count; itr++)
+            {
+                if (m_listSamples[itr].GetName() == a_strSampleName)
+                {
+                    COTSSample pOTSSample = m_listSamples[itr];                  
+                    m_listSamples.RemoveAt(itr);
+                    IsChanged = true;
+                }
+            }
+
+            if (!IsChanged)
+            {
+                return m_listSamples[0];
+            }
+
+            return m_listSamples[0];
+
+        }
+
+        public  COTSSample AddSample(String a_strHoleName)
+        {
+
+            // this file is valid, pass the test will make sure all the parameters are ok. 
+            if (!IsValid())
+            {
+                // shouldn't be here, invalid file 
+
+                return null;
+            }
+
+            // get new sample name
+            String strNewSampleName = GetNewSampleName();
+
+            // make sure the new sample name is not an empty string
+            strNewSampleName.Trim();
+
+
+            // get a suitable sample hole for the new sample
+            CHole pHole = SelectASmpleHole(a_strHoleName);
+
+            // check the sample hole
+            if (pHole!=null)
+            {
+                // failed to get sample hole for the new sample
+
+                return null;
+            }
+
+
+            // measure data parameters containing particle analysis std, image scan parameter, image process parameter and x-ray parameter 
+            CMsrParams poMsrParams = new CMsrParams();
+
+            MEMBRANE_TYPE a_nVal = (MEMBRANE_TYPE)m_DefaultParameters.GetMembraneType();
+
+            poMsrParams.SetImageScanParam(m_DefaultParameters.GetMsrParam().GetImageScanParam());
+            poMsrParams.SetImageProcessParam(m_DefaultParameters.GetMsrParam().GetImageProcessParam());
+            poMsrParams.SetXRayParam(m_DefaultParameters.GetMsrParam().GetXRayParam());
+
+            String sSTDName = m_DefaultParameters.GetPartSTDLibFileName();
+            poMsrParams.SetSTDName(sSTDName);
+
+            // measurement area 	
+            //CDomainPtr pMsrArea = CalculateMsrArea(pHole);
+            CDomain pMsrArea = CalculateDefaultArea(pHole);
+            // create a sample 
+            COTSSample pSample = new COTSSample();
+
+            // set sample parameters
+            pSample.SetName(strNewSampleName);
+            pSample.SetSampleHoleName(pHole.GetName());
+            pSample.SetSwitch(m_DefaultParameters.GetMeasurementSwitch());
+            pSample.SetMsrParams(poMsrParams);
+            pSample.SetMsrArea(pMsrArea);
+            pSample.SetMembraneType(a_nVal);
+            // add the new sample into the samples list
+            m_listSamples.Add(pSample);
+
+            // set the project file modified.
+            SetModify();
+
+            // set the new as working sample
+            m_nWorkingSampeIndex = (int)m_listSamples.Count - 1;
+
+            // return the new sample
+            return pSample;
+        }
+
+        // select a suitable sample hole for a new sample
+        public   CHole SelectASmpleHole(String a_strHoleName /*= _T("")*/)
+        {
+            
+            // get holes list of the stage
+           List< CHole > listHoles = m_pStage.GetHoleList();
+
+            // make sure the holes list is not empty
+            if (listHoles.Count == 0)
+            {
+                // shouldn't happen, stage have no hole.
+
+                return null;
+            }
+
+            // check the input hole name
+            a_strHoleName.Trim();
+            if (a_strHoleName!="")
+            {
+                // try to find matched hole
+               
+                bool IsChanged = false;
+                for (int itr = 0; itr < listHoles.Count; itr++)
+                {
+                    if (listHoles[itr].GetName() == a_strHoleName)
+                    {
+                        CHole pElementChemistry = listHoles[itr];                        
+                        listHoles.RemoveAt(itr);
+                        IsChanged = true;
+                    }
+                }
+
+                if (!IsChanged)
+                {
+                    return listHoles[0];
+                }
+            }
+
+            // can't find a matched hole, then pick the first empty hole
+
+            // go through the holes list
+            foreach (var pHole in listHoles)
+            {
+                // has this hole any sample in it?
+                String strHoleName = pHole.GetName();
+                bool IsChanged = false;
+                for (int itr = 0; itr < listHoles.Count; itr++)
+                {
+                    if (listHoles[itr].GetName() == a_strHoleName)
+                    {
+                        CHole pElementChemistry = listHoles[itr];
+                        listHoles.RemoveAt(itr);
+                        IsChanged = true;
+                    }
+                }
+
+                if (!IsChanged)
+                {
+                    return listHoles[0];
+                }
+            }
+
+		// no empty hole, then the first hole will be the one
+		return listHoles[0];
+	}
+
+    public  CDomain CalculateDefaultArea(CHole a_pHole)
+        {
+            
+
+            Rectangle rectHole = a_pHole.GetDomainRect();
+            System.Drawing.Point ptCenter = rectHole.Location;
+
+            DOMAIN_SHAPE nShape = m_DefaultParameters.GetShape();
+
+            double dArea = m_DefaultParameters.GetArea() * 1000000;
+
+            System.Drawing.Point ptLeftTop = new System.Drawing.Point();
+            System.Drawing.Size ptRightBottom = new System.Drawing.Size();
+
+            int nEdge = 0;
+            int nRadius = 0;
+
+            switch ((int)nShape)
+            {
+                case (int)DOMAIN_SHAPE.RECTANGLE:
+                    nEdge = (int)Math.Sqrt(dArea) / 2;
+                    ptLeftTop.X = ptCenter.X - nEdge;
+                    ptLeftTop.Y = ptCenter.Y - nEdge;
+                    ptRightBottom.Width = ptCenter.X + nEdge;
+                    ptRightBottom.Height = ptCenter.Y + nEdge;
+                    break;
+                case (int)DOMAIN_SHAPE.ROUND:
+                    nRadius = (int)Math.Sqrt(dArea / 3.1415926);
+                    ptLeftTop.X = ptCenter.X - nRadius;
+                    ptLeftTop.Y = ptCenter.Y - nRadius;
+                    ptRightBottom.Width = ptCenter.X + nRadius;
+                    ptRightBottom.Height = ptCenter.Y + nRadius;
+                    break;
+            }
+
+            Rectangle MsrRect = new Rectangle(ptLeftTop, ptRightBottom);
+            CDomain pMsrArea = new CDomain(nShape, MsrRect);
+
+            // return measurement area
+            return pMsrArea;
+        }
+
+        // get new sample name
+        public  String GetNewSampleName()
+        {
+            // new sample name
+            String strNewSmplName = "";
+
+            // safety check
+            
+            if (m_DefaultParameters!=null)
+            {
+                // shouldn't happen, invalid general parameter pointer.
+               
+                return strNewSmplName;
+            }
+
+            // new sample name base
+            String strNewSmplNameBase = m_DefaultParameters.GetSampleName() + "%d";
+            int nIndex = 1;
+
+            do
+            {
+                // new sample name is new sample name base + number string
+                string.Format(strNewSmplNameBase, nIndex);
+                ++nIndex;
+            }
+            // make sure that the new sample name is not same with any sample in the samples list
+            while (SameNameInList(strNewSmplName,0));
+
+            // new sample name
+            return strNewSmplName;
+        }
+
+      public  bool SameNameInList(String a_strSampleName, int a_nExclude /*= -1*/)
+        {
+            // make sure the input sample name is not empty
+            a_strSampleName.Trim();
+            if (a_strSampleName=="")
+            {
+                // shouldn't happen, input name is an empty string
+
+                return false;
+            }
+
+            // go through sample list
+            int nIndex = 0;
+            foreach (var pSample in m_listSamples)
+            {
+                // return TRUE if this is not an exclude sample and its name is same with input
+                String strSampleName = pSample.GetName();
+                if (nIndex != a_nExclude && strSampleName.CompareTo(a_strSampleName) == 0)
+                {
+                    // find a same name sample
+                    return true;
+                }
+
+                ++nIndex;
+            }
+
+            // no, same name sample in the same list, return FALSE
+            return false;
+        }
+
+      public  bool DeleteSampleByIndex(int a_nIndex)
+        {
+            // check the index
+            if (a_nIndex < 0 || a_nIndex >= (int)m_listSamples.Count)
+            {
+                // invalid input sample index
+                
+                return true;
+            }
+
+            // calculate new working sample index
+            int nNewWorkingSampeIndex;
+            if (a_nIndex < m_nWorkingSampeIndex)
+            {
+                nNewWorkingSampeIndex = m_nWorkingSampeIndex - 1;
+            }
+            else if (a_nIndex > m_nWorkingSampeIndex)
+            {
+                nNewWorkingSampeIndex = m_nWorkingSampeIndex;
+            }
+            else
+            {
+                // deleting working sample.
+                if (a_nIndex == (int)m_listSamples.Count - 1)
+                {
+                    // this is the last sample, select the above sample as working sample 
+                    // if this is only sample in the list working sample index will be -1;
+                    nNewWorkingSampeIndex = m_nWorkingSampeIndex - 1;
+                }
+                else
+                {
+                    // select next sample as working sample
+                    nNewWorkingSampeIndex = m_nWorkingSampeIndex;
+                }
+            }
+
+            // delete the sample 
+            
+            for (int i = 0; i < m_listSamples.Count; i++)
+            {
+                m_listSamples.Remove(m_listSamples[i]);
+
+               
+            }
+           
+            // the file is modified.
+            SetModify();
+
+            // reset working sample index
+            m_nWorkingSampeIndex = nNewWorkingSampeIndex;
+
+            // ok, return TRUE
+            return true;
+        }
+
+      public  bool DeleteSampleByName(String a_strSampleName)
+        {
+            // check input sample name
+            a_strSampleName.Trim();
+            if (a_strSampleName=="")
+            {
+                // input sample name is empty
+
+                return false;
+            }
+
+            // go through sample list
+            int nIndex = 0;
+            foreach (var pSample in m_listSamples)
+            {
+                // return TRUE if this is not an exclude sample and its name is same with input
+                String strSampleName = pSample.GetName();
+                if (strSampleName.CompareTo(a_strSampleName) == 0)
+                {
+                    // find the sample, return deleting result
+                    return DeleteSampleByIndex(nIndex);
+                }
+
+                ++nIndex;
+            }
+
+            // can't find the sample in the samples list, return FALSE
+            return false;
+        }
+
+      public  bool ResetSamplesListOrder(List<String> a_listSampleNames)
+        {
+            // no sample in the samples list; shouldn't be here
+            if (m_listSamples.Count == 0)
+            {
+
+                return false;
+            }
+
+            // make sure that input sample names list size is same with the samples list
+            if (m_listSamples.Count != a_listSampleNames.Count)
+            {
+
+                return false;
+            }
+
+            // new sample list
+            List<COTSSample> listSamples = new List<COTSSample>();
+
+            // go through the sample names list
+            foreach (var strSampleName in a_listSampleNames)
+            {
+                // find the sample
+                //  var itr = find_if(m_listSamples.begin(), m_listSamples.end(), [strSampleName](COTSSamplePtr p) { return p->GetName().CompareNoCase(strSampleName) == 0; });
+                //if (itr == m_listSamples.end())
+                //{
+                //        // failed to find the sample
+
+                //        return false;
+                //}
+
+                //// add the sample into the new list
+                //listSamples.Add(itr);
+                bool IsChanged = false;
+                for (int itr = 0; itr < m_listSamples.Count; itr++)
+                {
+                    if (m_listSamples[itr].GetName() == strSampleName)
+                    {
+                        COTSSample pElementChemistry = m_listSamples[itr];                       
+                        m_listSamples.RemoveAt(itr);
+                        IsChanged = true;
+                    }
+                }
+
+                if (!IsChanged)
+                {
+                    return false;
+                }
+
+            }
+
+            // reset the samples list
+            m_listSamples.Clear();
+		foreach (var pSample in listSamples)
+		{
+			m_listSamples.Add(pSample);
+		}
+
+         // set modify flag
+         SetModify();
+
+            // Ok, return TRUE
+            return true;
+	}
+
+      public  bool InsrtSample(COTSSample a_pSample, int a_nIndex)
+        {
+            // input check
+           
+            if (a_pSample!=null)
+            {
+                // invalid input sample pointer 
+
+                return false;
+            }
+            if (m_listSamples.Count == 0 || a_nIndex >= (int)m_listSamples.Count)
+            {
+                m_listSamples.Add(a_pSample);
+            }
+            else if (a_nIndex <= 0)
+            {
+                m_listSamples.Insert(Convert.ToInt32(m_listSamples[a_nIndex]), a_pSample);
+            }
+            else
+            {
+                m_listSamples.Insert(Convert.ToInt32(m_listSamples[a_nIndex]) + a_nIndex, a_pSample);
+            }
+
+            // Ok, return TRUE
+            return true;
+        }
+
+       public  bool ChangeSamplePosition(int a_nIndexFrom, int a_nIndexTo)
+        {
+            // make sure both index are valid
+            if (a_nIndexFrom < 0 || a_nIndexFrom >= (int)m_listSamples.Count)
+            {
+                // invalid from index                
+                return false;
+            }
+            if (a_nIndexTo < 0 || a_nIndexTo >= (int)m_listSamples.Count)
+            {
+                // invalid to index             
+                return false;
+            }
+
+            // need to do nothing if the two indexes are the same
+            if (a_nIndexFrom != a_nIndexTo)
+            {
+                // move to last?
+                bool bLast = (a_nIndexTo == ((int)m_listSamples.Count - 1));
+
+                // get the sample 
+                COTSSample pSample = m_listSamples[a_nIndexFrom];
+                   
+                // remove it from the samples list
+                m_listSamples.Remove(pSample);
+
+                // put the sample back in 
+                if (bLast)
+                {
+                    m_listSamples.Add(pSample);
+                }
+                else
+                {
+                    m_listSamples.Insert(Convert.ToInt32(m_listSamples[a_nIndexTo]) + a_nIndexTo, pSample);
+                }
+            }
+
+            // Ok, return TRUE
+            return true;
+        }
+
+       public bool MoveSamplePosition(COTSSample a_pTargetSample, COTSSample a_RefpSample, bool a_bBefore /*= TRUE*/)
+        {
+            // check input
+           
+            if (a_pTargetSample!=null)
+            {
+                // invalid input target sample pointer 
+
+                return false;
+            }
+           
+            if (a_RefpSample!=null)
+            {
+                // invalid input ref sample pointer 
+
+                return false;
+            }
+            
+            bool IsChanged = false;
+            for (int itr = 0; itr < m_listSamples.Count; itr++)
+            {
+                if (m_listSamples[itr].GetName() == a_pTargetSample.GetName())
+                {
+                    COTSSample pElementChemistry = m_listSamples[itr];
+                   
+                    m_listSamples.RemoveAt(itr);
+                    IsChanged = true;
+                }
+            }
+
+            if (!IsChanged)
+            {
+                return false;
+            }
+           
+            for (int itr = 0; itr < m_listSamples.Count; itr++)
+            {
+                if (m_listSamples[itr].GetName() == a_RefpSample.GetName())
+                {
+                    COTSSample pElementChemistry = m_listSamples[itr];
+
+                    m_listSamples.RemoveAt(itr);
+                    IsChanged = true;
+                }
+            }
+
+            if (!IsChanged)
+            {
+                return false;
+            }
+
+            // need to do nothing if the two sample are same
+           
+                // remove the sample from the samples list
+                      
+            for (int itr = 0; itr < m_listSamples.Count; itr++)
+            {
+                if (m_listSamples[itr].GetName() == a_RefpSample.GetName())
+                {
+                    COTSSample pElementChemistry = m_listSamples[itr];
+
+                    m_listSamples.RemoveAt(itr);
+                    IsChanged = true;
+                }
+            }
+
+            if (!IsChanged)
+            {
+                return false;
+            }
+            // put the sample back in 
+            if (a_bBefore)
+                {
+                    m_listSamples.Insert(0, a_pTargetSample);
+                }
+                else
+                {
+                    m_listSamples.Insert(1, a_pTargetSample);
+                }
+            
+            // Ok, return TRUE
+            return true;
+        }
+
+       public bool MoveSamplePosition(String a_strTargetSampleName, String a_strRefSampleName, bool a_bBefore /*= TRUE*/)
+        {
+            // input check
+            a_strTargetSampleName.Trim();
+            if (a_strTargetSampleName=="")
+            {
+                // input target sample is an empty string 
+
+                return false;
+            }
+            a_strRefSampleName.Trim();
+            if (a_strRefSampleName=="")
+            {
+                // input ref sample is an empty string 
+
+                return false;
+            }
+            // var itr = std::find_if(m_listSamples.begin(), m_listSamples.end(), [a_strTargetSampleName](COTSSamplePtr p) { return p->GetName().CompareNoCase(a_strTargetSampleName) == 0; });
+            //if (itr == m_listSamples.end())
+            //{
+            //    // target sample name is not the name of any sample in the samples list
+
+            //    return false;
+            //}
+            bool IsChanged = false;
+            for (int itr = 0; itr < m_listSamples.Count; itr++)
+            {
+                if (m_listSamples[itr].GetName() == a_strTargetSampleName)
+                {
+                    COTSSample pElementChemistry = m_listSamples[itr];
+
+                    m_listSamples.RemoveAt(itr);
+                    IsChanged = true;
+                }
+            }
+
+            if (!IsChanged)
+            {
+                return false;
+            }
+            COTSSample pTargetSample = m_listSamples[0];
+            //  itr = std::find_if(m_listSamples.begin(), m_listSamples.end(), [a_strRefSampleName](COTSSamplePtr p) { return p->GetName().CompareNoCase(a_strRefSampleName) == 0; });
+            //if (itr == m_listSamples.end())
+            //{
+            //    // ref sample name is not the name of any sample in the samples list
+
+            //    return false;
+            //}
+           
+            for (int itr = 0; itr < m_listSamples.Count; itr++)
+            {
+                if (m_listSamples[itr].GetName() == a_strTargetSampleName)
+                {
+                    COTSSample pElementChemistry = m_listSamples[itr];
+
+                    m_listSamples.RemoveAt(itr);
+                    IsChanged = true;
+                }
+            }
+
+            if (!IsChanged)
+            {
+                return false;
+            }
+            COTSSample pRefSample = pTargetSample;
+
+            // need to do nothing if the two name are same
+            if (a_strTargetSampleName.CompareTo(a_strRefSampleName) != 0)
+            {
+                return MoveSamplePosition(pTargetSample, pRefSample, a_bBefore);
+            }
+
+            // Ok, return TRUE
+            return true;
+        }
+
+       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);
+        }
+
+        int GetWorkingSampleIndex() { return m_nWorkingSampeIndex; }
+
+        void SetWorkingSampleIndex(int a_nWorkingSampleIndex) { m_nWorkingSampeIndex = a_nWorkingSampleIndex; }
+
+       public bool SetWorkingSampleByIndex(int a_nIndex)
+        {
+            // special treatment
+            if (a_nIndex == -1 && m_listSamples.Count == 0)
+            {
+                m_nWorkingSampeIndex = -1;
+                return true;
+            }
+
+            // check if the working sample index
+            if (0 > a_nIndex || a_nIndex >= (int)m_listSamples.Count)
+            {
+                // invalid sample index
+                return false;
+            }
+
+            m_nWorkingSampeIndex = a_nIndex;
+            return true;
+        }
+
+      public  bool SetWorkingSampleByName(String a_pSampleName)
+        {
+            // check input sample name
+            a_pSampleName.Trim();
+            if (a_pSampleName=="")
+            {
+                // input sample name is empty
+
+                return false;
+            }
+
+            // go through sample list
+            int nIndex = 0;
+            foreach (var pSample in m_listSamples)
+            {
+                // return TRUE if this is not an exclude sample and its name is same with input
+                String strSampleName = pSample.GetName();
+                if (strSampleName.CompareTo(a_pSampleName) == 0)
+                {
+                    // find the sample, return deleting result
+                    return SetWorkingSampleByIndex(nIndex);
+                }
+
+                ++nIndex;
+            }
+
+            // failed to find the named sample
+
+            // failed to find the named sample return FALSE
+            return false;
+        }
+
+       public bool DeleteWorkingSample()
+        {
+            // check if the working sample index
+            if (m_nWorkingSampeIndex < 0 || m_nWorkingSampeIndex >= (int)m_listSamples.Count)
+            {
+                // invalid working sample index
+                return false;
+            }
+
+            // return the result of DeleteSampleByIndex
+            return DeleteSampleByIndex(m_nWorkingSampeIndex);
+        }
+
+        // Sample hole BSE image list
+       public List< CHoleBSEImg> GetHoleBESImgList() { return m_listHoleBSEImg; }
+
+        // hole BSE images list
+      public  void SetHoleBESImgList(List<CHoleBSEImg> a_listHoleBSEImg, bool a_bClear/* = TRUE*/)
+        {
+            // clear the hole BSE image list if necessary 
+            if (a_bClear)
+            {
+                m_listHoleBSEImg.Clear();
+            }
+
+            // go through the input list
+            foreach (var pHoleBSEImg in a_listHoleBSEImg)
+            {
+                // create a hole BSE image copy
+                CHoleBSEImg pHoleBSEImgNew=(new CHoleBSEImg(pHoleBSEImg));
+
+            // add the new hole BSE image into HoleBSEImage list
+            m_listHoleBSEImg.Add(pHoleBSEImgNew);
+        }
+
+		if (m_nWorkingSampeIndex != -1)
+		{
+			COTSSample pSample = GetWorkingSample();
+      
+       }
+       }
+
+        // get modify flag
+        bool IsModified() { return m_bModify; }
+
+        // file name
+       public  String GetFileName()
+        {
+            // make a copy of file path name
+            String strPathName = m_strPathName;
+
+            // is this a new file?
+            strPathName.Trim();
+            if (strPathName.CompareTo(UNTITLED_FILE_NAME) == 0)
+            {
+                return strPathName;
+            }
+
+            // get file name
+            String strFileName = GetFileNameWithoutExtension(strPathName);
+            strFileName = GetFileName(strFileName);
+
+            // return file name
+            return strFileName;
+        }
+
+        // get file name without extension
+       public String GetFileNameWithoutExtension(String a_strPathName)
+        {
+            string str = "";
+            Char[] sPath=new Char[otsdataconst.MAX_PATH + 4];
+            str.CopyTo(0,sPath, 0, Convert.ToInt32(a_strPathName));
+
+            return a_strPathName;
+        }
+
+        // if the new sample name can be used.
+      public  bool IsValidSampleName(String a_sName)
+        {
+            int nindex = -1;
+            foreach (var pSample in m_listSamples)
+            {
+                nindex++;
+
+                String sSampleName = pSample.GetName();
+                if (a_sName.CompareTo(sSampleName)!=0)
+                {
+                    if (nindex != m_nWorkingSampeIndex)
+                    {
+
+                        return false;
+                    }
+                }
+            }
+
+            return true;
+        }
+
+        // get std file list, a_nPos = -1, current do not use any STD lib, a_nPos = 0, current use STD lib.
+      public  bool GetSTDFileList(int a_nPos, List<String> a_listSTDLibName)
+        {
+            
+
+            String a_strFolderName = m_DefaultParameters.GetPartSTDLibFolderName();
+            if (a_strFolderName == "")
+            {
+               
+                return false;
+            }
+
+            // lib name list
+            a_listSTDLibName.Clear();
+
+            // file list
+            List<String> listSTDFile = new List<string>();
+            listSTDFile.Clear();
+            const String STD_LIB_EXT = ".db";
+            // get file list
+            if (!GetFileNameList(a_strFolderName, STD_LIB_EXT, listSTDFile))
+            {
+
+                return false;
+            }
+
+            foreach (var file in listSTDFile)
+            {
+                //CString fileName = file.Left(file.GetLength() - 3);
+                String fileName = file;
+                a_listSTDLibName.Add(fileName);
+            }
+
+            //before the use choose one STD, always should be null.
+            a_nPos = -1;
+
+            String sCurrentSTD;
+            CMsrParams pCurrentParam;
+            COTSSample pSample = GetWorkingSample();
+            if (pSample == null)
+            {
+                
+            }
+            else
+            {
+                pCurrentParam = pSample.GetMsrParams();
+                if (pCurrentParam == null)
+                {
+                   
+                }
+
+                //将当前使用的数据库的名字与下拉菜单的名字对应起来
+                sCurrentSTD = pCurrentParam.GetSTDName();
+                for (int i = 0; i < (int)a_listSTDLibName.Count; i++)
+                {
+                    a_nPos++;
+                    if (a_listSTDLibName[i].CompareTo(sCurrentSTD) == 0)
+                        break;
+                }
+
+            }
+
+            return true;
+        }
+
+        // get file name list in a folder
+      public  bool GetFileNameList(String a_strFolderName, String a_strFileType, List<String> a_listFileName)
+        {
+            // get file name
+            a_strFolderName += "*";
+            a_strFolderName += a_strFileType;
+
+            try
+            {
+                //find first file
+                int FindFileData = 0;
+                // int file = FindFirstFile(a_strFolderName, FindFileData);
+
+                string path = a_strFolderName;
+
+                string filename = a_strFileType;
+
+                List<string> lineStringList = new List<string>();//存储所有读取到的文件
+
+                DirectoryInfo[] dateDirArr = new DirectoryInfo(path).GetDirectories(); //取指定路径下的所有目录
+
+                foreach (DirectoryInfo directoryInfo in dateDirArr)
+
+                {
+                    string fullName =  directoryInfo.Name + "\\" + filename;
+                    if (!File.Exists(fullName))
+                    {
+                        continue;//目录下不存在此文件,返回。
+                    }
+                    FileInfo file = new FileInfo(fullName);
+                    StreamReader reader = new StreamReader(file.FullName);
+                    while (!reader.EndOfStream)//判断是否读取完成
+                    {
+                        lineStringList.Add(reader.ReadLine());
+                    }
+                    reader.Close();
+                    
+                }
+
+                int INVALID_HANDLE_VALUE = 0;
+                //find other file
+                if (FindFileData!= INVALID_HANDLE_VALUE)
+                {
+                    a_listFileName.Add(FindFileData.ToString());
+                    bool bState = false;
+                                                       
+                    FindFile(a_strFolderName, FindFileData.ToString());                      
+                    while (bState)
+                    {
+                    a_listFileName.Add(FindFileData.ToString());                       
+                    FindFile(a_strFolderName, FindFileData.ToString());
+                    }
+                }
+            }
+            catch (Exception pe)
+            {               
+                return false;
+            }
+
+            return true;
+
+        }
+
+        static String FindFile(String filename, String path)
+        {
+            if (Directory.Exists(path))
+            {
+                if (File.Exists(path + filename))
+                    return path + filename;
+                String[] directorys = Directory.GetDirectories(path);
+                foreach (String d in directorys)
+                {
+                    String p = FindFile(filename, d);
+                    if (p != null)
+                        return p;
+                }
+            }
+            return null;
+        }
+
+        //// change STD
+        public  bool ChangeSTDFromList(int a_nPos)
+        {
+
+           
+            String a_strFolderName = m_DefaultParameters.GetPartSTDLibFolderName();
+            if (a_strFolderName == "")
+            {                
+                return false;
+            }
+
+            // file list
+            List<String> listSTDFile = new List<string>();
+            listSTDFile.Clear();
+            const String STD_LIB_EXT = ".db";
+            // get file list
+            if (!GetFileNameList(a_strFolderName, STD_LIB_EXT, listSTDFile))
+            {
+
+                return false;
+            }
+
+            List<String> listSTDLibName = new List<string>();
+            listSTDLibName.Clear();
+
+            foreach (var file in listSTDFile)
+            {
+                //CString fileName = file.Left(file.GetLength() - 3);
+                String fileName = file;
+                listSTDLibName.Add(fileName);
+            }
+
+            if (a_nPos > (int)listSTDLibName.Count)
+            {
+                return false;
+            }
+            String STDName = listSTDLibName[a_nPos];
+
+            // updata STD to working sample
+            COTSSample pSample = GetWorkingSample();
+           
+
+            CMsrParams pParam = pSample.GetMsrParams();
+            
+            pParam.SetSTDName(STDName);
+            pSample.SetMsrParams(pParam);
+
+            return true;
+
+        }
+
+        // get measured sample list
+       public bool GetMsredSampleList(List<COTSSample> a_listMsredSample)
+        {
+            a_listMsredSample.Clear();
+
+            foreach (var pSample in m_listSamples)
+            {
+               
+                if (pSample.GetMsrResults() == new CMsrResults())
+                {
+
+                    continue;
+                }
+                else
+                {
+
+                    a_listMsredSample.Add(pSample);//the reference count will increament automatically.
+                }
+            }
+
+            return true;
+        }
+
+        // calculate measurement area
+        public  CDomain CalculateMsrArea(CHole a_pHole)
+        {            
+            CDomain pMsrArea = new CDomain(a_pHole.GetShape(), a_pHole.GetDomainRect());
+            // create measurement area
+            // reset measurement area 
+            // measurement area should smaller than the sample hole
+            Rectangle rectMsrArea = pMsrArea.GetDomainRect();
+            int nWidth = rectMsrArea.Width;
+            int nHeight = rectMsrArea.Height;
+            int nDeflateX = CalculateDeflateValue(nWidth);
+            int nDeflateY = CalculateDeflateValue(nHeight);
+            rectMsrArea.Offset(nDeflateX, nDeflateY);
+            pMsrArea.SetDomainRect(rectMsrArea);
+
+            // return measurement area
+            return pMsrArea;
+        }
+
+        // calculate deflate value
+      public  int CalculateDeflateValue(int a_nWitchOrHeight)
+        {
+            const long LENGTH_THRESHOLD = 150000;
+            const long LENGTH_THRESHOLD_MIN = 10000;
+            const int EDGE = 1000;
+            const int EDGE_MIN = 500;
+            // deflate 1000 if width or height is greater than 15000
+            if (a_nWitchOrHeight >= LENGTH_THRESHOLD)
+            {
+                return EDGE;
+            }
+            // deflate 500 if width or height is greater than 15000
+            else if (a_nWitchOrHeight >= LENGTH_THRESHOLD_MIN)
+            {
+                return EDGE_MIN;
+            }
+
+            // otherwise, no deflate
+            return 0;
+        }
+
+        // remove background
+      public  bool RemoveBackGround(CBSEImg a_pImgIn, COTSImageProcessParam a_pImgProcessParam, CBSEImg a_pImgOut)
+        {
+           
+            /*COTSFieldMgr fldMgr;
+            fldMgr.SetBSEImage(a_pImgIn);
+            fldMgr.RemoveBSEImageBG(a_pImgProcessParam);
+            a_pImgOut = fldMgr.GetBSEImage();*/
+            // Binary
+            int nWidth = a_pImgIn.GetWidth();
+            int nHeight = a_pImgIn.GetHeight();
+            int nImgSize = nWidth * nHeight;
+
+            Byte[] pPixel = new Byte[nImgSize];
+            Byte[] pSrcImg = a_pImgIn.GetImageDataPointer();
+            Byte[] pTargetImg = new Byte[nImgSize];
+            long nBGStart;
+            long nBGEnd;
+            if (a_pImgProcessParam.GetBGRemoveType() == OTS_BGREMOVE_TYPE.MANUAL)
+            {
+                nBGStart = a_pImgProcessParam.GetBGGray().GetStart();
+                nBGEnd = a_pImgProcessParam.GetBGGray().GetEnd();
+
+                // delete background 
+                for (uint i = 0; i < nImgSize; i++)
+                {
+                    if (pSrcImg[i] >= nBGStart && pSrcImg[i] <= nBGEnd)
+                    {
+                        pPixel[i] = 0;
+                    }
+                    else
+                    {
+                        pPixel[i] = 255;
+                    }
+                }
+            }
+            else
+            {
+                var range = a_pImgIn.CalBackground(a_pImgProcessParam.GetBGRemoveType());//in this function, the input perameter takes no effect right now,but may be useful in the future.
+                nBGStart = range.GetStart();
+                
+                nBGEnd = range.GetEnd();
+                switch (a_pImgProcessParam.GetAutoBGRemoveType())
+                {
+                    case OTS_AUTOBGREMOVE_TYPE.DOWNWARD:
+                        for (uint i = 0; i < nImgSize; i++)
+                        {
+                            if (pSrcImg[i] <= nBGEnd)
+                            {
+                                pPixel[i] = 0;
+                            }
+                            else
+                            {
+                                pPixel[i] = 255;
+                            }
+                        }
+                        break;
+                    case OTS_AUTOBGREMOVE_TYPE.UPWARD:
+                        for (uint i = 0; i < nImgSize; i++)
+                        {
+                            if (pSrcImg[i] >= nBGStart)
+                            {
+                                pPixel[i] = 0;
+                            }
+                            else
+                            {
+                                pPixel[i] = 255;
+                            }
+                        }
+                        break;
+                    case OTS_AUTOBGREMOVE_TYPE.MIDDLE:
+                        for (uint i = 0; i < nImgSize; i++)
+                        {
+                            if (pSrcImg[i] >= nBGStart && pSrcImg[i] <= nBGEnd)
+                            {
+                                pPixel[i] = 0;
+                            }
+                            else
+                            {
+                                pPixel[i] = 255;
+                            }
+                        }
+                        break;
+                    default:
+                        break;
+                }
+
+            }
+
+            long nPtStart = a_pImgProcessParam.GetParticleGray().GetStart();
+            long nPtEnd = a_pImgProcessParam.GetParticleGray().GetEnd();
+
+            
+            // image process 
+            m_HardwareMgr.BErode3(pPixel.ToString(), pTargetImg.ToString(), 5, nHeight, nWidth);
+            m_HardwareMgr.BDilate3(pTargetImg.ToString(), pPixel.ToString(), 5, nHeight, nWidth);
+
+            // show the image
+            for (uint i = 0; i < nImgSize; i++)
+            {
+                uint Pixel = BitConverter.ToUInt32(pPixel,0);
+                uint SrcImg = BitConverter.ToUInt32(pSrcImg, 0);
+                Pixel = 255 - (Pixel + i);
+                if ((Pixel + i) == 0)
+                {
+                    Pixel = SrcImg + i;
+                }
+            }
+
+            a_pImgOut. SetImageRect(a_pImgIn.GetImageRect());
+            a_pImgOut.SetImageData(pPixel);
+         
+            return true;
+        }
+
+      
+
+        public  COTSGeneralParameters GetDefaultParameters() { return m_DefaultParameters; }
+
+        public  void SetDefaultParameters(COTSGeneralParameters val) { m_DefaultParameters = val; }
+
+      
+    }
+}

+ 151 - 0
OTS/OTSModelSharp/Measure/GetParam/DIALOG_CHECK_PARAM_RESULT.cs

@@ -0,0 +1,151 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using OTSDataType;
+
+namespace OTSModelSharp
+{
+    public partial class DIALOG_CHECK_PARAM_RESULT : Form
+    {
+        // check setting only flag
+        private bool m_bCheckOnly;
+        // message base string
+        private string m_strMessageBase;
+        // total measurable samples No
+        private int m_nTatolMeasuableSmplNo;
+        // with warning measurable samples No
+        private int m_nWithWarningMeasuableSmplNo;
+        bool m_bCheckWarnDo;  // if it is true, even if there is warn, it will also be measured
+
+        String m_strlEditResult;
+
+
+        public DIALOG_CHECK_PARAM_RESULT()
+        {
+            InitializeComponent();
+            IDC_EDIT_RESULT.Text = "";           //m_strlEditResult(_T(""))
+            IDC_CHECK_WARN_DO.Checked = false;           //m_bCheckWarnDo(FALSE)
+            m_strMessageBase = "";                 //m_strMessageBase(_T(""))
+            m_nTatolMeasuableSmplNo = 0;                    //m_nTatolMeasuableSmplNo(0)
+            m_nWithWarningMeasuableSmplNo = 0;               //m_nWithWarningMeasuableSmplNo(0)
+        }
+
+
+        // controls
+        void SetControlState()
+        {
+            // hiding the check box if necessary
+
+            // check only flag is true or no 
+            if (m_bCheckOnly || m_nWithWarningMeasuableSmplNo == 0)
+            {
+                IDC_CHECK_WARN_DO.Visible = false;                //m_ctrlCheckWarnDo.ShowWindow(SW_HIDE);
+            }
+            // change button text if necessary
+        }
+
+        private void IDD_DIALOG_CHECK_PARAM_RESULT_Load(object sender, EventArgs e)
+        {
+            //CDialog::OnInitDialog();
+
+            // controls
+            SetControlState();
+
+            // control data
+            SetControlData();
+
+            //CWnd* pWnd = GetDlgItem(IDOK);
+            //if (pWnd)
+            //{
+            //    /*CWnd* pWnd = GetDlgItem(IDD_DIALOG_CHECK_PARAM_RESULT)*/
+            //    pWnd->SetWindowText(MultiLang::GetInstance().GetCStringByKey(GrpOtherParam, DlgCheckParam_OKBtn));
+            //}
+            IDOK.Text = MultiLang.GetInstance().GetStringByKey(OTSModelresource.GrpOtherParam, OTSModelresource.DlgCheckParam_OKBtn);
+
+            //pWnd = GetDlgItem(IDCANCEL);
+            //if (pWnd)
+            //{
+            //    /*CWnd* pWnd = GetDlgItem(IDD_DIALOG_CHECK_PARAM_RESULT)*/
+            //    pWnd->SetWindowText(MultiLang::GetInstance().GetCStringByKey(GrpOtherParam, DlgCheckParam_CancelBtn));
+            //}
+            IDCANCEL.Text = MultiLang.GetInstance().GetStringByKey(OTSModelresource.GrpOtherParam, OTSModelresource.DlgCheckParam_CancelBtn);
+
+            //pWnd = GetDlgItem(IDC_CHECK_WARN_DO);
+            //if (pWnd)
+            //{
+            //    /*CWnd* pWnd = GetDlgItem(IDD_DIALOG_CHECK_PARAM_RESULT)*/
+            //    pWnd->SetWindowText(MultiLang::GetInstance().GetCStringByKey(GrpOtherParam, DlgCheckParam_WarningStr));
+            //}
+            //SetWindowText(MultiLang::GetInstance().GetCStringByKey(GrpOtherParam, DlgCheckParam_Title));
+            IDC_CHECK_WARN_DO.Text = MultiLang.GetInstance().GetStringByKey(OTSModelresource.GrpOtherParam, OTSModelresource.DlgCheckParam_Title);
+            //return TRUE;  // return TRUE unless you set the focus to a control
+        }
+
+        private void IDOK_Click(object sender, EventArgs e)
+        {
+            UpdateData();
+            this.Close();
+        }
+
+        private void IDCANCEL_Click(object sender, EventArgs e)
+        {
+            this.Close();
+        }
+
+        void SetControlData()
+        {
+            // format the message
+            int nMeasurableSampleNo = m_nTatolMeasuableSmplNo;
+            if (!IDC_CHECK_WARN_DO.Checked)
+            {
+                nMeasurableSampleNo -= m_nWithWarningMeasuableSmplNo;
+            }
+            IDC_EDIT_RESULT.Text = string.Format(m_strMessageBase, nMeasurableSampleNo); //m_strlEditResult.Format(m_strMessageBase, nMeasurableSampleNo);
+            // set data to controls
+            //UpdateData(FALSE);
+        }
+
+        private void IDC_CHECK_WARN_DO_CheckedChanged(object sender, EventArgs e)
+        {
+            // get data from controls
+            UpdateData();        // this.Refresh();      // UpdateData();
+            // set contras data
+            SetControlData();
+        }
+
+        void UpdateData()
+        {
+            IDC_EDIT_RESULT.Text = m_strlEditResult;
+            IDC_CHECK_WARN_DO.Checked = m_bCheckWarnDo;
+        }
+
+        // check setting only flag
+        public void SetCheckOnlyFlag(bool a_bCheckOnly) { m_bCheckOnly = a_bCheckOnly; }
+
+        // message base string
+        public void SetMessageBase(string a_strMessageBase) { m_strMessageBase = a_strMessageBase; }
+
+        // total measurable samples No
+        public void SetTatolMeasuableSmplNo(int a_nTatolMeasuableSmplNo) { m_nTatolMeasuableSmplNo = a_nTatolMeasuableSmplNo; }
+
+        // with warning measurable samples No
+        public void SetWithWarningMeasuableSmplNo(int a_nWithWarningMeasuableSmplNo) { m_nWithWarningMeasuableSmplNo = a_nWithWarningMeasuableSmplNo; }
+
+        public bool GetWarnDo() { return m_bCheckWarnDo; }
+
+        public void UpDataIDC_EDIT_RESULTText(string strRESULT)
+        {
+            IDC_EDIT_RESULT.Text = strRESULT;
+        }
+        public void UpDataIDC_CHECK_WARN_DOStatus(bool Status)
+        {
+            IDC_CHECK_WARN_DO.Checked = Status;
+        }
+    }
+}

+ 107 - 0
OTS/OTSModelSharp/OTSDataType/CDoubleRange.cs

@@ -0,0 +1,107 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml;
+
+namespace OTSDataType
+{
+   public class CDoubleRange:ISlo
+    {
+        private double m_dStart;
+        private double m_dEnd;
+
+    public    CDoubleRange()
+        {
+
+            m_dStart = 0;
+            m_dEnd = 0;
+        }
+    public CDoubleRange(double a_dStart, double a_dEnd)
+	{
+	
+
+        m_dStart = Math.Min(a_dStart, a_dEnd);
+        m_dEnd = Math.Max(a_dStart, a_dEnd);
+    }
+    public CDoubleRange(CDoubleRange a_poSource)
+	    {
+
+		    // can't copy itself
+		    if (a_poSource == this)
+		    {
+			    return;
+		    }
+
+		    // copy data over
+		    Duplicate(a_poSource);
+        }
+        public void Duplicate( CDoubleRange a_oSource)
+	    {        // copy data over
+            m_dStart = a_oSource.m_dStart;
+		    m_dEnd = a_oSource.m_dEnd;
+	    }
+        public void Normalise()
+        {
+           
+            m_dEnd = Math.Max(m_dStart, m_dEnd);
+            m_dStart = Math.Min(m_dStart, m_dEnd);
+
+        }
+        public bool DataInRange(double a_dData)
+        {
+            return a_dData >= m_dStart && a_dData <= m_dEnd;
+        }
+
+        // start
+        public void SetStart(double a_dStart)
+        {
+            m_dStart = a_dStart;
+            Normalise();
+        }
+        public double GetStart()
+        {
+            return m_dStart;
+        }
+        // end
+        public void SetEnd(double a_dEnd)
+        {
+            m_dEnd = a_dEnd;
+            Normalise();
+        }
+        public double GetEnd()
+        {
+            return m_dEnd;
+        }
+        public bool equals(CDoubleRange a_oSource)
+        {
+
+            return m_dStart == a_oSource.m_dStart && m_dEnd == a_oSource.m_dEnd;
+        }
+
+        public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
+        {
+            xDouble xStart=new xDouble();
+            xDouble xEnd=new xDouble();
+            Slo slo=new Slo();
+            slo.Register("start", xStart);
+            slo.Register("end", xEnd);
+            if (isStoring)
+            {
+                xStart.AssignValue( m_dStart);
+                xEnd .AssignValue(m_dEnd);
+
+                slo.Serialize(true, classDoc, rootNode);
+            }
+            else
+            {
+                slo.Serialize(false, classDoc, rootNode);
+
+                m_dStart = xStart.value();
+                m_dEnd = xEnd.value();
+
+            }
+        }
+    }
+}

+ 118 - 0
OTS/OTSModelSharp/OTSDataType/CHoleBSEImg.cs

@@ -0,0 +1,118 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Drawing;
+
+
+namespace OTSDataType
+{
+  public  class CHoleBSEImg : CBSEImg
+    {
+        //DECLARE_SERIAL(CHoleBSEImg);
+
+        //hole name
+        protected int m_nHoleID;
+        //image position
+        protected System.Windows.Point m_poiPosition = new System.Windows.Point();
+
+        public CHoleBSEImg()
+        {
+            Init();
+        }
+
+        public CHoleBSEImg(Rectangle a_rectImage, int a_nHoleID, System.Windows.Point a_poiPosition)										// constructor
+	   {
+		   Init();
+           // set image rectangle and create memory for image data
+           SetImageRect(a_rectImage);
+           m_nHoleID = a_nHoleID;
+		   m_poiPosition = a_poiPosition;
+	    }
+        public CHoleBSEImg(CHoleBSEImg a_oSource)
+        {
+            if (a_oSource == null)
+            {
+                return;
+            }
+            // can't copy itself
+            if (a_oSource == this)
+            {
+                return;
+            }
+            // copy data over
+            Duplicate(a_oSource);
+        }
+
+        public bool Equals(CHoleBSEImg a_oSource)
+        {
+            if(m_nHoleID!= a_oSource.m_nHoleID)
+            {
+                return false;
+            }
+            if(m_poiPosition!= a_oSource.m_poiPosition)
+            {
+                return false;
+            }
+            return true;
+        }
+        //CHoleBSEImg(const CHoleBSEImg&);							// copy constructor
+        //CHoleBSEImg& operator=(const CHoleBSEImg&);				// =operator
+        // sterilizations
+        //void Serialize(CArchive& ar);
+        //void Serialize(bool isStoring, tinyxml2::XMLDocument* classDoc, tinyxml2::XMLElement* rootNode);
+        //~CHoleBSEImg();
+
+        // HoleID
+        public int GetHoleID()
+        {
+            return m_nHoleID;
+        }
+        public void SetHoleID(int a_nHoleID)
+        {
+            m_nHoleID = a_nHoleID;
+        }
+
+        // position
+        public System.Windows.Point GetPosition()
+        {
+            return m_poiPosition;
+        }
+        public void SetPosition(System.Windows.Point a_poiPosition)
+        {
+            m_poiPosition = a_poiPosition;
+        }
+
+        // cleanup
+        //protected new void Cleanup()
+        //{
+
+        //}
+
+        // Initialization
+        protected new void Init()
+        {
+            // base class initialization
+            base.Init();
+            // initialization
+            m_nHoleID = 0;
+            m_poiPosition = new System.Windows.Point(0, 0);
+        }
+
+        // duplication 
+        protected void Duplicate(CHoleBSEImg a_oSource)
+        {
+            // initialization
+            //Init();
+
+            // base class duplication
+            base.Duplicate(a_oSource);
+
+            // copy data over
+            m_nHoleID = a_oSource.m_nHoleID;
+            m_poiPosition = a_oSource.m_poiPosition;
+        }
+    }
+}

+ 245 - 0
OTS/OTSModelSharp/OTSDataType/LanguageID.cs

@@ -0,0 +1,245 @@
+namespace OTSDataType
+{
+    public  class LanguageID
+    {
+        public const int GrpNormalParam = 0;
+        public const int GrpImageScanParam = 1;
+        public const int GrpImageProcessParam = 2;
+        public const int GrpXrayParam = 3;
+        public const int GrpFieldProcessParam = 4;
+        public const int GrpSEMWorkingParam = 5;
+        public const int GrpMeasureStateParam = 6;
+        public const int GrpMeasureResultParam = 7;
+        public const int GrpReportParam = 8;
+
+
+        public const int IDS_SAMPLE_TITLE_FIRST = 20000;
+        public const int IDS_SAMPLE_DES_FIRST = 20070;
+        public const int IDS_SAMPLE_ITEM_GROUP_NAME_FIRST = 20140;
+        public const int IDS_MEASURE_STATUS_FIRST = 20150;
+        public const int IDS_IMAGE_MODE_FIRST = 20160;
+        public const int IDS_MEASURE_STOP_MODE_FIRST = 20170;
+        public const int IDS_THREE_TIES_OPTIONS_FIRST = 20180;
+        public const int IDS_X_RAY_STEP_FIRST = 20185;
+        public const int IDS_X_RAY_SCAN_MODE_FIRST = 20185; //there's a problem here ,these two items shouldn't equal to one ID number.
+
+        public const int IDS_STRING20189 = 20189;
+        public const int IDS_DATA_SOUCE_TYPE_FIRST = 20230;
+        public const int IDS_IMAGE_DISPLAY_TYPE_FIRST = 20235;
+        public const int IDS_IMAGE_TYPE_FIRST = 20240;
+        public const int IDS_MEASURE_DATA_TYPE_FIRST = 20245;
+        public const int IDS_CALCULATE_TABLE_TYPE_FIRST = 20255;
+        public const int IDS_CALCULATE_CHART_TYPE_FIRST = 20265;
+        public const int IDS_PARTICLE_TYPE_FIRST = 20275;
+        public const int IDS_STD_ID_DEFUALT_FIRST = 20285;
+        public const int IDS_SIZE_CLASS_DEFUALT_FIRST = 20295;
+        public const int IDS_SIZE_CAL_METHOD_TYPE_FIRST = 20305;
+        public const int IDS_STRING20314 = 20314;
+        public const int IDS_SIZE_GRID_CAL_METHOD_TYPE_FIRST = 20315;
+        public const int IDS_STRING20316 = 20316;
+        public const int IDS_TRIANTEMPLATE_TYPE_FIRST = 20325;
+        public const int IDS_SYSTEMSTD_NAME_FIRST = 20335;
+        public const int IDS_STRING20350 = 20350;
+        public const int IDS_STRING20351 = 20351;
+        public const int IDS_STEEL_TECHNOLOGY = 20353;
+
+        public const int IDS_REPORT_TITLE_FIRST = 20370;
+        public const int IDS_REPORT_DES_FIRST = 20390;
+        public const int IDS_DISPLAY_TYPE_FIRST = 20410;
+        public const int IDS_SORT_IMAGE_TYPE_FIRST = 20415;
+        public const int IDS_DISPLAY_IMAGE_TYPE_FIRST = 20425;
+        public const int IDS_MINERAL_GROUP_FIRST = 20430;
+        public const int IDS_PRIMITIVE_MINERAL_GROUP_FIRST = 20440;
+        public const int IDS_MINERAL_CLASSIFY_GROUP_FIRST = 20450;
+        public const int IDS_BRITTLENESS_CHARACTERISTIC_GROUP_FIRST = 20460;
+        public const int IDS_USER_CUSTOM_MINERAL_GROUP_FIRST = 20470;
+        public const int IDS_SIZE_CALCULATE_METHOD_FIRST = 20480;
+        public const int IDS_DATA_TYPE_FIRST = 20490;
+        public const int IDS_DATA_TABLE_TYPE_FIRST = 20495;
+        public const int IDS_DATA_CHART_TYPE_FIRST = 20505;
+        public const int IDS_COMPARE_DATA_TYPE_FIRST = 20515;
+
+        public const int IDD_LICENSE_INFO = 12000;
+        public const int IDC_BUTTON_LOAD = 12002;
+        public const int IDC_EDIT_NICKNAME = 12003;
+        public const int IDC_COMBO_PACKID = 12004;
+        public const int IDC_COMBO_LICESETYPE = 12005;
+        public const int IDC_DATETIME_EXPIREDATE = 12006;
+        public const int IDC_EDIT_KEY = 12007;
+        public const int IDC_EDIT_MACHEINEID = 12008;
+
+        public const int IDD_STAGE_MGR = 12006;
+        public const int IDD_SAMPLE_PLANE_MGR_INFO = 12006;
+        public const int IDD_PROG_MGR_INFO = 12004;
+        public const int IDD_DLG_RENAME = 12008;
+        public const int IDC_COMBO_YDIRECT = 12009;
+        public const int IDC_COMBO_XDIREC = 12010;
+        public const int IDD_DIALOG_CHECK_PARAM_RESULT = 12010;
+        public const int IDC_EDIT_XEND = 12011;
+        public const int IDC_EDIT_SAMPLEPLANENAME = 12012;
+        public const int IDC_COMBO_STAGE = 12012;
+        public const int IDC_EDIT3 = 12013;
+        public const int IDC_EDIT_YEND = 12013;
+        public const int IDC_EDIT_YSTART = 12014;
+        public const int IDC_BUTTON_MEASPRAMPATHSET = 12016;
+        public const int IDC_BUTTON_SMAPLEPLANESET = 12017;
+        public const int IDC_BUTTON_STAGE = 12017;
+        public const int IDC_LIST_STAGE = 12017;
+        public const int IDC_BUTTON_PARTSTDLIBPATHSET = 12018;
+        public const int IDC_PIC_STAGE = 12018;
+        public const int IDC_CHECK1 = 12019;
+        public const int IDC_MEAS_SWITCH = 12019;
+        public const int IDC_CHECK_WARN_DO = 12019;
+        public const int IDC_BTN_DEL = 12020;
+        public const int IDC_COMBO_MEASURESPEED = 12021;
+        public const int IDC_BTN_RENAME = 12021;
+        public const int IDC_EDIT_MAGFACTOR = 12022;
+        public const int IDC_BTN_APLY = 12022;
+        public const int IDC_EDIT_FIEDNUM = 12023;
+        public const int IDC_BTN_IMPORT = 12023;
+        public const int IDC_EDIT_WORKDISTNS = 12024;
+        public const int IDC_BTN_EXPORT = 12024;
+        public const int IDC_EDIT_SAMPLENAME = 12025;
+        public const int IDC_SCROLLBAR1 = 12025;
+        public const int IDC_COMBO_EXCUTESWITCH = 12026;
+        public const int IDC_EDIT1 = 12026;
+        public const int IDC_EDIT_NAME = 12026;
+        public const int IDC_EDIT_RESULT = 12026;
+        public const int IDC_COMBO_PARAMSWITCH = 12027;
+        public const int IDC_BUTTON1 = 12027;
+        public const int IDC_EDIT_STDLIBNAME = 12028;
+        public const int IDC_COMBO_ANALYXRAYSPEED = 12029;
+        public const int IDC_COMBO_XRAYSCANMODE = 12030;
+        public const int IDC_COMBO_SEARCHXRAYSPEED = 12031;
+        public const int IDC_COMBO_STOPMODE = 12032;
+        public const int IDC_COMBO_FETCHIMGMODE = 12033;
+        public const int IDC_EDIT_STOPPARAM = 12034;
+        public const int IDC_EDIT_STOP_TIME = 12034;
+        public const int IDC_COMBO_IMGSCANSPEED = 12035;
+        public const int IDC_COMBO_IMGSIZE = 12036;
+        public const int IDC_EDIT_SCREENWIDTH = 12037;
+        public const int IDC_EDIT_PARTAREAMIN = 12038;
+        public const int IDC_EDIT_BACKMAX = 12039;
+        public const int IDC_EDIT_PARTMAX = 12040;
+        public const int IDC_EDIT_STDLIBNAME2 = 12041;
+        public const int IDC_EDIT_STOP_FIELD_NUM = 12041;
+        public const int IDC_EDIT_STOPPARAM2 = 12042;
+        public const int IDC_EDIT_STOP_INCA_NUM = 12042;
+        public const int IDC_EDIT_STOPPARAM3 = 12043;
+        public const int IDC_EDIT_STDLIBNAME3 = 12043;
+        public const int IDC_EDIT_MESA_PARAM_FILE = 12043;
+        public const int IDC_EDIT_SEARCHXRAYCOUNTLIMIT = 12044;
+        public const int IDC_EDIT_ANALYXRAYAIMVALUE = 12047;
+        public const int IDC_EDIT_PARTAREAMAX = 12048;
+        public const int IDC_EDIT_BACKMIN = 12049;
+        public const int IDC_EDIT_PARTMIN = 12050;
+        public const int IDC_EDIT_XSTART = 12051;
+        public const int IDC_EDIT_MEASUREPARAMPATH = 12052;
+        public const int IDC_EDIT_ANALYSESTDLIBPATH = 12053;
+        public const int IDS_SOFTWARETYPEID_FIRST = 12200;
+        public const int IDS_LICENSETYPEID_FIRST = 12205;
+        public const int IDS_LICENSE_INFO_TITLE_FIRST = 12210;
+        public const int IDS_BUTTON_EMAIL = 12220;
+        public const int IDS_STAGE_FILE_TITLE_FIRST = 12221;
+        public const int IDS_STRING12229 = 12229;
+        public const int IDS_PART_SIZE_FILE_TITLE_FIRST = 12231;
+        public const int IDS_STRING12236 = 12236;
+        public const int IDS_USER_DEFINE = 12238;
+        public const int IDS_UNDEFINED_PARTICLE = 12239;
+        public const int IDS_XAXISDIRECTION = 12240;
+        public const int IDS_STRING12228 = 12242;
+        public const int IDS_STRING12245 = 12245;
+        public const int IDS_YAXISDIRECTION = 12246;
+        public const int IDS_SCANSTOPMODE = 12252;
+        public const int IDS_FETCHIMAGEMODE = 12261;
+        public const int IDS_SCANSPEED = 12270;
+        public const int IDS_SCANSIZE = 12278;
+        public const int IDS_XRAYSCANMODE = 12288;
+        public const int IDS_SEARCHSPEED = 12295;
+        public const int IDS_STRING12300 = 12300;
+        public const int IDS_ANALYSPEED = 12303;
+        public const int IDS_SAMPLE_CHECK_RESULT = 12311;
+        public const int IDS_STRING12321 = 12321;
+        public const int IDS_ERROR_WARNING = 12322;
+        public const int IDS_STRING12328 = 12328;
+        public const int IDS_STRING12329 = 12329;
+        public const int IDS_DEFAULT = 12330;
+        public const int IDS_PARTICLE_GEN_INFO_START = 12331;
+        public const int IDS_PARTICLE_COMPONENT_START = 12341;
+        public const int IDS_STRING12350 = 12350;
+        public const int IDS_SORT_CLASS_START = 12351;
+        public const int IDS_SIC = 12356;
+        public const int IDS_FEO = 12357;
+        public const int IDS_SORT_KIND_START = 12361;
+        public const int IDS_SORT_SIZE_START = 12371;
+        //public const int IDS_SIZE_CLASS_DEFUALT_FIRST    12381
+        public const int IDS_AVE_ELEMENT_START = 12391;
+        public const int IDS_PARTICL_UNDEFINED = 12401;
+        public const int IDS_PARTICL_ANALYSIS = 12402;
+        public const int IDS_INCLUSION_INDEX = 12403;
+        public const int IDS_OPEN_TAGE_FILE = 12404;
+        public const int IDS_OPEN_STAGE_FILE = 12404;
+        public const int IDS_ELEMENT_COMPONENT_START = 12411;
+        public const int IDS_RESULT_INFOR_NAME_FIRST = 12419;
+        public const int IDS_STRING12435 = 12435;
+        public const int IDS_COMMON_FIVE_START = 12436;
+        public const int IDS_STRING12437 = 12437;
+        public const int IDS_NUM = 12446;
+        public const int IDS_PERCENT = 12447;
+        public const int IDS_PERCENT_SUM = 12448;
+        public const int GBStr1 = 12449;
+        public const int GBStr2 = 12450;
+        public const int GBStr3 = 12451;
+        public const int GBStr4 = 12452;
+        public const int GBStr5 = 12453;
+        public const int GBStr6 = 12454;
+        public const int GBStr7 = 12455;
+        public const int GBStr8 = 12456;
+        public const int GBStr9 = 12457;
+        public const int DlgCheckParam_Title = 12458;
+        public const int DlgCheckParam_OKBtn = 12459;
+        public const int DlgCheckParam_CancelBtn = 12460;
+        public const int DlgCheckParam_WarningStr = 12461;
+        public const int DlgStageMgr_StageList = 12462;
+        public const int DlgStageMgr_Apply = 12463;
+        public const int DlgStageMgr_Delete = 12464;
+        public const int DlgStageMgr_Rename = 12465;
+        public const int DlgStageMgr_Import = 12466;
+        public const int DlgStageMgr_Export = 12467;
+        public const int DlgStageMgr_Title = 12468;
+        public const int DlgStageRename_Ok = 12469;
+        public const int DlgStageRename_Cancel = 12470;
+        public const int DlgStageRename_Title = 12471;
+        public const int IDS_MINERAL_BRPL = 12480;
+        public const int IDS_MINERAL_KINDS = 12490;
+        public const int IDS_ORETYPE_PROP = 12500;
+        public const int IDS_MINERAL_PROP = 12510;
+        public const int IDS_ELEMENT_PROP = 12530;
+        public const int IDS_MEASURE_SHAPE = 12540;
+        public const int IDS_ROCK_TYPE = 12550;
+        public const int IDS_XRAY_STEP = 12560;
+
+        //license information
+        public const int IDS_DLG_LICNESE_INFO = 12600;
+        public const int IDS_COMPUTE_NAME = 12601;
+        public const int IDS_HARDWARE_ID = 12602;
+        public const int IDS_SOFTWARE_ID = 12603;
+        public const int IDS_PASSPORT_ID = 12604;
+        public const int IDS_VALIDITY = 12605;
+        public const int IDS_PASSPORT = 12606;
+        public const int IDS_BUT_LOAD = 12607;
+        public const int IDS_BUT_OK = 12608;
+        public const int IDS_BUT_CANCLE = 12609;
+
+        // Next default values for new objects
+        // 
+       #if APSTUDIO_INVOKED
+           #if APSTUDIO_READONLY_SYMBOLS
+                 public const int _APS_NEXT_RESOURCE_VALUE = 2001;
+                 public const int _APS_NEXT_COMMAND_VALUE = 32771;
+                 public const int _APS_NEXT_CONTROL_VALUE = 2000;
+                 public const int _APS_NEXT_SYMED_VALUE = 2000;
+           #endif
+       #endif
+    }
+}

+ 121 - 0
OTS/OTSModelSharp/OTSDataType/OTSPeak.cs

@@ -0,0 +1,121 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing.Printing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OTSDataType
+{
+   public  class COTSPeak
+    {
+        // peak position
+        long m_nPosition;
+
+        // peak height
+        long m_nHeight;
+
+        // peak range
+        CIntRange m_oRange;
+
+        // tag id
+        int m_nTagId;
+
+        // constructor
+        public void  COTSParticle()													// constructor
+	     {
+		Init();
+        
+	    }
+
+        // initialization
+        void Init()
+        {
+            m_nPosition = 0;
+            m_nHeight = 0;
+           m_oRange =new CIntRange();
+        }
+
+        public COTSPeak()
+        {
+            // initialization
+            Init();
+        }
+
+        public void COTSPeakn(COTSPeak a_oSource)
+        {
+            // can't copy itself
+            if (a_oSource == this)
+            {
+                return;
+            }
+            Duplicate(a_oSource);
+        }
+
+        public COTSPeak(COTSPeak a_poSource)
+        {
+
+            // can't copy itself
+            if (a_poSource == this)
+            {
+                return;
+            }
+            Duplicate(a_poSource);
+        }
+
+        public bool Equals(COTSPeak a_oSource)          // CBSEImg& operator=(const CBSEImg&);        // =operator
+        {       
+            // return test result
+            return m_nPosition == a_oSource.m_nPosition &&
+            m_nHeight == a_oSource.m_nHeight &&
+            m_oRange == a_oSource.m_oRange;
+        }
+
+        // peak position
+        public long GetPosition()
+        {
+            return m_nPosition;
+        }
+
+       public void SetPosition(long a_nPosition)
+        {
+            m_nPosition = a_nPosition;
+        }
+
+        // peak height
+        public long GetHeight()
+        {
+            return m_nHeight;
+        }
+
+       public  void SetHeight(long a_nHeight)
+        {
+            m_nHeight = a_nHeight;
+        }
+
+        // peak range
+        public CIntRange GetRange()
+        {
+            return m_oRange;
+        }
+
+        public void SetRange(CIntRange a_oRange)
+        {
+            m_oRange = a_oRange;
+        }
+        
+
+
+        // duplication
+        void Duplicate( COTSPeak a_oSource)
+    	{
+		// initialization
+		Init();
+
+        // copy data over
+        m_nPosition = a_oSource.m_nPosition;
+		m_nHeight = a_oSource.m_nHeight;
+		m_oRange = a_oSource.m_oRange;
+	    }
+}
+}

+ 197 - 0
OTS/OTSModelSharp/OTSModelSharp.csproj

@@ -0,0 +1,197 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="..\packages\EntityFramework.6.3.0\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.props')" />
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{63A944EC-AF52-4BD4-BEFF-B09F5DDDA9B1}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>OTSModelSharp</RootNamespace>
+    <AssemblyName>OTSModelSharp</AssemblyName>
+    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <Deterministic>true</Deterministic>
+    <NuGetPackageImportStamp>
+    </NuGetPackageImportStamp>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <HintPath>..\packages\EntityFramework.6.3.0\lib\net45\EntityFramework.dll</HintPath>
+    </Reference>
+    <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <HintPath>..\packages\EntityFramework.6.3.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Office.Interop.PowerPoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
+      <EmbedInteropTypes>True</EmbedInteropTypes>
+    </Reference>
+    <Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
+      <HintPath>..\packages\NLog.4.7.4\lib\net45\NLog.dll</HintPath>
+    </Reference>
+    <Reference Include="NPOI.OpenXmlFormats">
+      <HintPath>..\OpenDll\WordApiDll\NPOI.OpenXmlFormats.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Activities.Core.Presentation" />
+    <Reference Include="System.Activities.Presentation" />
+    <Reference Include="System.ComponentModel.DataAnnotations" />
+    <Reference Include="System.Configuration" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Data.SQLite, Version=1.0.113.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Data.SQLite.Core.1.0.113.1\lib\net46\System.Data.SQLite.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Data.SQLite.EF6, Version=1.0.113.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Data.SQLite.EF6.1.0.113.0\lib\net46\System.Data.SQLite.EF6.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Data.SQLite.Linq, Version=1.0.113.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Data.SQLite.Linq.1.0.113.0\lib\net46\System.Data.SQLite.Linq.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Diagnostics.Tracing" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.IO.Compression" />
+    <Reference Include="System.Runtime.Serialization" />
+    <Reference Include="System.ServiceModel" />
+    <Reference Include="System.Transactions" />
+    <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Windows.Presentation" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+    <Reference Include="WindowsBase" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="CSmallParticleInfo.cs" />
+    <Compile Include="CStdioFile.cs" />
+    <Compile Include="DataPublic.cs" />
+    <Compile Include="DTLBase\CSQLiteDB.cs" />
+    <Compile Include="DTLBase\CSQLiteDBFile.cs" />
+    <Compile Include="DTLBase\CSQLiteTable.cs" />
+    <Compile Include="DTLBase\IDBBase.cs" />
+    <Compile Include="DTLBase\IDBFileBase.cs" />
+    <Compile Include="DTLBase\IDBTableBase.cs" />
+    <Compile Include="DTLBase\SQLiteFactory.cs" />
+    <Compile Include="DTLBase\TableModel.cs" />
+    <Compile Include="DTL\DBConst.cs" />
+    <Compile Include="GenInfoDB.cs" />
+    <Compile Include="InfomationTable.cs" />
+    <Compile Include="InformationDB.cs" />
+    <Compile Include="MeasureControl\IClassifyEngine.cs" />
+    <Compile Include="MeasureControl\IImageProcess.cs" />
+    <Compile Include="Measure\GetBSEPic\BSEImgFileMgr.cs" />
+    <Compile Include="Measure\GetBSEPic\FieldMgr.cs" />
+    <Compile Include="Measure\GetBSEPic\MsrThread.cs" />
+    <Compile Include="Measure\GetBSEPic\MsrThreadStatus.cs" />
+    <Compile Include="Measure\GetBSEPic\OTSFieldMgr.cs" />
+    <Compile Include="Measure\GetBSEPic\SmplMeasure.cs" />
+    <Compile Include="Measure\GetBSEPic\SmplMeasureInc.cs" />
+    <Compile Include="Measure\GetBSEPic\SmplMsrResultFile.cs" />
+    <Compile Include="Measure\GetBSEPic\SmplMsrResultFileMgr.cs" />
+    <Compile Include="Measure\GetParam\COTSProjMgrFile.cs" />
+    <Compile Include="Measure\GetParam\DIALOG_CHECK_PARAM_RESULT.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Measure\GetParam\DIALOG_CHECK_PARAM_RESULT.designer.cs">
+      <DependentUpon>DIALOG_CHECK_PARAM_RESULT.cs</DependentUpon>
+    </Compile>
+    <Compile Include="Measure\GetParam\MsrParamFileMgr.cs" />
+    <Compile Include="Measure\GetParam\OTSGeneralParameters.cs" />
+    <Compile Include="Measure\GetParam\OTSProgMgr.cs" />
+    <Compile Include="Measure\GetParam\OTSProgMgrParamFile.cs" />
+    <Compile Include="Measure\GetParticle\ElementChemistryDB.cs" />
+    <Compile Include="Measure\GetParticle\ElementChemistryTable.cs" />
+    <Compile Include="Measure\GetParticle\IncADataDB.cs" />
+    <Compile Include="Measure\GetParticle\IncADataTable.cs" />
+    <Compile Include="Measure\GetParticle\IncAFileMgr.cs" />
+    <Compile Include="Measure\GetParticle\MergedParticles\MergeParticleDB.cs" />
+    <Compile Include="Measure\GetParticle\MergedParticles\MergParticleTable.cs" />
+    <Compile Include="Measure\GetParticle\PosXrayInfoDB.cs" />
+    <Compile Include="Measure\GetParticle\PosXrayInfoTable.cs" />
+    <Compile Include="Measure\GetParticle\SegmentDB.cs" />
+    <Compile Include="Measure\GetParticle\SegmentTable.cs" />
+    <Compile Include="Measure\GetParticle\SmallParticles\SmallParticleInfoDB.cs" />
+    <Compile Include="Measure\GetParticle\SmallParticles\SmallParticleInfoTable.cs" />
+    <Compile Include="Measure\GetParticle\XRayDataDB.cs" />
+    <Compile Include="Measure\GetParticle\XRayDataTable.cs" />
+    <Compile Include="Measure\GetStageInfo\DlgStageMgr.cs" />
+    <Compile Include="Measure\GetStageInfo\DlgStageRename.cs" />
+    <Compile Include="Measure\GetStageInfo\StageFile.cs" />
+    <Compile Include="Measure\GetXrayInfo\PosXrayFileMgr.cs" />
+    <Compile Include="OTSControl\EBrukerErrorCode.cs" />
+    <Compile Include="OTSDataType\CBSEImg.cs" />
+    <Compile Include="OTSDataType\CDomain.cs" />
+    <Compile Include="OTSDataType\CDoubleRange.cs" />
+    <Compile Include="OTSDataType\CElement.cs" />
+    <Compile Include="OTSDataType\CElementRange.cs" />
+    <Compile Include="OTSDataType\CHole.cs" />
+    <Compile Include="OTSDataType\CHoleBSEImg.cs" />
+    <Compile Include="OTSDataType\CIntRange.cs" />
+    <Compile Include="OTSDataType\CMsrParams.cs" />
+    <Compile Include="OTSDataType\CMsrSampleStatus.cs" />
+    <Compile Include="OTSDataType\COTSFieldData.cs" />
+    <Compile Include="OTSDataType\COTSImageProcessParam.cs" />
+    <Compile Include="OTSDataType\COTSImageScanParam.cs" />
+    <Compile Include="OTSDataType\COTSLicenseInfo.cs" />
+    <Compile Include="OTSDataType\COTSSample.cs" />
+    <Compile Include="OTSDataType\COTSSegment.cs" />
+    <Compile Include="OTSDataType\COTSXRayParam.cs" />
+    <Compile Include="OTSDataType\CSEMDataGnr.cs" />
+    <Compile Include="OTSDataType\CSEMDataMsr.cs" />
+    <Compile Include="OTSDataType\CSize.cs" />
+    <Compile Include="OTSDataType\LanguageID.cs" />
+    <Compile Include="OTSDataType\MsrResults.cs" />
+    <Compile Include="OTSDataType\MultiLang.cs" />
+    <Compile Include="OTSDataType\otsdataconst.cs" />
+    <Compile Include="OTSDataType\OTSDATAResource.cs" />
+    <Compile Include="OTSDataType\OTSFeature.cs" />
+    <Compile Include="OTSDataType\OTSParticle.cs" />
+    <Compile Include="OTSDataType\OTSPeak.cs" />
+    <Compile Include="OTSDataType\PosXraycs.cs" />
+    <Compile Include="OTSDataType\PosXrayInfo.cs" />
+    <Compile Include="OTSDataType\SEMStageData.cs" />
+    <Compile Include="OTSDataType\stage.cs" />
+    <Compile Include="OTSDataType\XMLSerialization.cs" />
+    <Compile Include="OTSModelresource.cs" />
+    <Compile Include="DTLBase\SqlHelper.cs" />
+    <Compile Include="MeasureControl\FileHelper.cs" />
+    <Compile Include="MeasureControl\IMeasureHardware.cs" />
+    <Compile Include="MeasureControl\MeasureHardware.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="Measure\GetParam\DIALOG_CHECK_PARAM_RESULT.resx">
+      <DependentUpon>DIALOG_CHECK_PARAM_RESULT.cs</DependentUpon>
+    </EmbeddedResource>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+    <PropertyGroup>
+      <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
+    </PropertyGroup>
+    <Error Condition="!Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.3.0\build\EntityFramework.props'))" />
+    <Error Condition="!Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.3.0\build\EntityFramework.targets'))" />
+    <Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.113.1\build\net46\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.113.1\build\net46\System.Data.SQLite.Core.targets'))" />
+  </Target>
+  <Import Project="..\packages\EntityFramework.6.3.0\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.targets')" />
+  <Import Project="..\packages\System.Data.SQLite.Core.1.0.113.1\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.113.1\build\net46\System.Data.SQLite.Core.targets')" />
+</Project>