| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065 | using OTSCOMMONCLR;using OTSDataType;using OTSModelSharp.DTLBase;using OTSModelSharp.ServiceInterface;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.Forms;using System.Xml;namespace OTSModelSharp{    class CSmplMsrResult     {        //----------------定义----------------------        protected static NLog.Logger logger = null;        // working folder string        string m_strWorkingFolder;        string m_strSampleWorkingFolder;        string m_strFieldFileSubFolder;        private string m_strBSEImageFileFolder;        private string m_strDBFileFolder;        // pathname        string m_strRstFileName;        string m_strdbPathName;        CIncAFileMgr m_DBFileMgr ;       public   string SMPL_MSR_RESULT_FILE_EXT = ".rst";        // fields file sub-directory string       public  string SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER = "FIELD_FILES";       public  string DBFILE_NAME = "Inclusion.db";             public string SMPL_MSR_RESULT_FILE_FILTER = ("Sample Measure Result Files (*.rst)|*.rst||");        // BSE file name        public string SMPL_MSR_RESULT_FIELDS_BSE = ("Field");        // search x-ray file name        public string SMPL_MSR_RESULT_SEARCH_X_RAY_FILE = ("SearchXray.db");        //----------全局定义------------------        // sample measure result file mark        public int SMPL_MSR_RESULT_FILE_MARK = 'S' + 'M' + 'P' + 'L' + 'M' + 'S' + 'R' + 'R' + 'E' + 'S' + 'U' + 'L' + 'T';        // sample measure result file version        public string SMPL_MSR_RESULT_FILE_VERSION = ("2.0.0");        // sample measure result file extension        //----------定义----------------------        // file version string        string m_strFileVersion;        // SEM sample stage        CSEMStageData m_pSEMStageData;        // sample stage        CStage m_pStage;        //CSEMStageDataPtr m_pSEMData;        CSEMDataGnr m_pSEMData;        // sample setting        COTSSample m_pSample;        // switch        bool m_bSwitch;        List<Point> allfieldcenters;        public CIncAFileMgr DBFileMgr { get => m_DBFileMgr; set => m_DBFileMgr = value; }        //----------------public-----------------        public CSmplMsrResult()        {            Init();            m_pSample = new COTSSample();            allfieldcenters = new List<Point>();        }        protected void Duplicate(CSmplMsrResult a_oSource)        {            // initialization            Init();            m_pSample = new COTSSample();            // copy data over            // file version string            m_strFileVersion = a_oSource.m_strFileVersion;            // SEM sample stage            m_pSEMStageData = a_oSource.m_pSEMStageData;            // sample stage            m_pStage = a_oSource.m_pStage;            // SEM condition??            //CSEMStageDataPtr m_pSEMData;            m_pSEMData = a_oSource.m_pSEMData;            // sample setting            m_pSample = a_oSource.m_pSample;            // switch            m_bSwitch = a_oSource.m_bSwitch;            // fields            m_pSample.GetFieldsData().Clear();            foreach (COTSFieldData pFieldData in a_oSource.m_pSample.GetFieldsData())            {                COTSFieldData pFieldDataNew = pFieldData;                m_pSample.GetFieldsData().Add(pFieldDataNew);            }        }        public List<COTSFieldData> GetFieldData()        {            return m_pSample.GetFieldsData();            //m_pSample.GetFieldsData()        }        public CSmplMsrResult(string measureWorkingFolder,COTSSample a_pSample)        {            Init();            logger = NLog.LogManager.GetCurrentClassLogger();                       m_pSample = a_pSample;                        m_strWorkingFolder = measureWorkingFolder;            m_strSampleWorkingFolder = measureWorkingFolder + "\\" + a_pSample.GetName();            m_strFieldFileSubFolder = m_strSampleWorkingFolder + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER;            m_strBSEImageFileFolder = m_strFieldFileSubFolder;            m_strDBFileFolder = m_strFieldFileSubFolder;            m_strRstFileName = m_strSampleWorkingFolder + "\\" + a_pSample.GetName() + SMPL_MSR_RESULT_FILE_EXT;            m_strdbPathName = m_strFieldFileSubFolder + "\\" + DBFILE_NAME;                      m_DBFileMgr = new CIncAFileMgr(m_strdbPathName);        }        protected void Init()        {            // file version string            m_strFileVersion = ("");            // SEM sample stage            m_pSEMStageData = new CSEMStageData();            // sample stage            m_pStage = new CStage();            // SEM condition??            //CSEMStageDataPtr m_pSEMData;            m_pSEMData = new CSEMDataGnr();            // sample setting                       // switch            m_bSwitch = false;            // fields        }        protected void Cleanup()        {            m_pSample.GetFieldsData().Clear();        }        public string GetFileVersion()        {            return m_strFileVersion;        }        public void SetFileVersion(string a_strFileVersion)        {            m_strFileVersion = a_strFileVersion;        }        public COTSSample GetSample()        {            return m_pSample;        }        public void SetSample(COTSSample a_pSample)        {            if (a_pSample != null)            {                return;            }            m_pSample = a_pSample;        }        public CSEMStageData GetSEMStageData()        {            return m_pSEMStageData;        }        public void SetSEMStageData(CSEMStageData a_pSEMStageData)        {                     m_pSEMStageData = a_pSEMStageData;        }        // sample stage        public CStage GetStage()        {            return m_pStage;        }        public void SetStage(CStage a_pStage)        {            if (a_pStage != null)            {                return;            }            m_pStage = a_pStage;        }        // SEM condition        public CSEMDataGnr GetSEMStage()        {            return m_pSEMData;        }        public void SetSEMStage(CSEMDataGnr a_pSEMData)        {            if (a_pSEMData != null)            {                return;            }            m_pSEMData = a_pSEMData;        }        // sample setting        // switch        public bool GetSwitch()        {            return m_bSwitch;        }        public void SetSwitch(bool a_bSwitch)        {            m_bSwitch = a_bSwitch;        }        //fields        //----------protected----------------        // cleanup        // initialization        public void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)        {            xInt xnFileMark = new xInt();            xString xnVersion = new xString();            xBool xbSwitch = new xBool();            Collection<Slo> xfields = new Collection<Slo>();            Slo slo = new Slo();            slo.Register("FileMark", xnFileMark);            slo.Register("Version", xnVersion);            slo.Register("Switch", xbSwitch);            slo.Register("SEMStageData", m_pSEMStageData);            slo.Register("Stage", m_pStage);            slo.Register("SEMData", m_pSEMData);            slo.Register("Sample", m_pSample);            slo.Register("Fields", xfields);            if (isStoring)            {                xnFileMark.AssignValue(SMPL_MSR_RESULT_FILE_MARK);                xnVersion.AssignValue(SMPL_MSR_RESULT_FILE_VERSION);                xbSwitch.AssignValue(m_bSwitch);                for(int i=0;i<allfieldcenters.Count;i++)                {                    Slo flddata = new Slo();                    xInt id = new xInt();                    xInt fldx = new xInt();                    xInt fldy = new xInt();                    id.AssignValue( i);                    var p = allfieldcenters[i];                    fldx.AssignValue( p.X);                    fldy .AssignValue( p.Y);                    flddata.Register("ID", id);                    flddata.Register("FieldX", fldx);                    flddata.Register("FieldY", fldy);                    xfields.addItem(flddata);                }                slo.Serialize(true, classDoc, rootNode);            }            else            {                slo.Serialize(false, classDoc, rootNode);                m_bSwitch = xbSwitch.value();                m_strFileVersion = xnVersion.value();                // m_pSample.GetFieldsData();                //for (unsigned int i = 0; i < xfields.size(); i++)                //{                //    m_pSample.GetFieldsData().push_back(COTSFieldDataPtr(xfields.getItem(i)));                //}            }        }        private bool InitFolders()        {                       if (!Exists(m_strSampleWorkingFolder))            {                // the working directory is not exit, create it                if (!CreateFolder(m_strSampleWorkingFolder))                {                    return false;                }                           }                   // check if the field files directory exists            if (!Exists(m_strFieldFileSubFolder))            {                // field files directory exists not exists, creates it                if (!CreateFolder(m_strFieldFileSubFolder))                {                    // failed to create the field files directory                    return false;                }            }                       return true;        }               // creates a folder.        private bool CreateFolder(string a_strFolder)        {            // make sure the folder name string are not empty            string strFolder = a_strFolder;            strFolder.Trim();            if (strFolder=="")            {                return false;            }            // if the folder exist?            if (Exists(strFolder))            {                                   return true;                            }               Directory.CreateDirectory(strFolder);            bool bRet = true;            // return folder create result            return bRet;        }        // check if the file exists or not        private bool Exists(string a_sPath)        {           return Directory.Exists(a_sPath);                   }               // Load         public bool Load(String a_strPathname /*= _T("")*/)        {            a_strPathname.Trim();            if (a_strPathname == "")            {                  FolderBrowserDialog FileDialog = new FolderBrowserDialog();//创建一个文件对话框                if (FileDialog.ShowDialog() != DialogResult.OK)                {                    // user canceled loading                    logger.Info("Load: user canceled loading.");                    return false;                }                a_strPathname = FileDialog.SelectedPath;            }            // get path of the pathname            String strFilePath =a_strPathname;                     // field file sub folder string            m_strFieldFileSubFolder = strFilePath + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";                        // check if the field file sub folder exists            if (!Exists(m_strFieldFileSubFolder))            {                // field files folder doesn't exist                return false;            }            //m_strSampleWorkingFolder = strFilePath+;            // create sample measure result file            //CSmplMsrResult pSmplMsrResultFile = new CSmplMsrResult();            // file version            String strFileVersion = m_strFileVersion;            uint nFileVersion = GetVersionFromString(strFileVersion);            if (nFileVersion == 0)            {// invalid file                return false;            }            // sample measure result file            //m_pSmplMsrResult = pSmplMsrResultFile;            SetPathFileName(a_strPathname);            this.LoadFieldDataFromDB(a_strPathname);            // ok, return TRUE            return true;        }        // Get file versio        // File Version should be format <Major version>.<Minor version>.<Build version>, like 1.2.3        public uint GetVersionFromString(string a_sVersion)        {            int nMajorVersion = 0;            int nMinorVersion = 0;            int nBuildVersion = 0;            uint nVersion = 0;            if (GetMajorVersionFromString(a_sVersion, nMajorVersion) &&                GetMinorVersionFromString(a_sVersion, nMinorVersion) &&                GetBuildVersionFromString(a_sVersion, nBuildVersion))            {                nVersion = (uint)nMajorVersion * 10000 + (uint)nMinorVersion * 100 + (uint)nBuildVersion;            }            return nVersion;        }        public bool GetMinorVersionFromString(string a_sVersion, int a_nVersion)        {            // version string            String strVersion = a_sVersion;            // get major file version string position first            int nPosFirst = strVersion.IndexOf('.');            if (nPosFirst < 0)            {                // failed to find major file version string                return false;            }            // get minor file version string position                       int nPosSecond = strVersion.IndexOf('.', nPosFirst + 1);            int nStrLength = nPosSecond - nPosFirst - 1;            if (nStrLength <= 0)            {                // failed to find minor file version string                return false;            }            // get minor file version string            String strMinorVersion = strVersion.Remove(nPosFirst + 1, nStrLength);            // the minor file version string can't be empty            strMinorVersion.Trim();            if (strMinorVersion == "")            {                // failed to find minor file version string                return false;            }            // convert the minor version string to minor version number            if (!StringToInt(strMinorVersion, a_nVersion))            {                // failed to convert the major file version string to number                return false;            }            // ok, return TRUE            return true;        }        public bool GetMajorVersionFromString(string a_sVersion, int a_nVersion)        {            // version string            String strVersion = a_sVersion;            // get major file version string position            int nPosFirst = strVersion.IndexOf('.');            if (nPosFirst <= 0)            {                // failed to find major file version                return false;            }            // get major file version string            String strMajorVersion = strVersion.PadLeft(nPosFirst);            // the major file version string can't be empty            strMajorVersion.Trim();            if (strMajorVersion == "")            {                // failed to find major file version                return false;            }            // convert the major version string to major version number            if (!StringToInt(strMajorVersion, a_nVersion))            {                // failed to convert the major file version string to number                return false;            }            // ok, return TRUE            return true;        }        public bool GetBuildVersionFromString(string a_sVersion, int a_nBuild)        {            // version string            String strVersion = a_sVersion;            // get major file version string position first                      int nPosFirst = strVersion.IndexOf('.');            if (nPosFirst < 0)            {                // failed to find major file version string                return false;            }            // get minor file version string position                      int nPosSecond = strVersion.IndexOf('.', nPosFirst + 1);            if (nPosSecond < 0)            {                // failed to find minor file version string                return false;            }            // get build string position            int nStrLength = strVersion.Length - nPosSecond - 1;            if (nStrLength <= 0)            {                // failed to find build string                return false;            }            // get build string            String strBuild = strVersion.PadRight(nStrLength);            // build string can't be empty            strBuild.Trim();            if (strBuild == "")            {                // failed to convert the build string to number                return false;            }            // convert the build string to build number            if (!StringToInt(strBuild, a_nBuild))            {                // failed to convert the build string to number                return false;            }            // ok, return TRUE            return true;        }        // Strings to int.        public bool StringToInt(string a_sValue, int a_nValue)        {            if (!IsDigitString(a_sValue))            {                return false;            }            a_nValue = Convert.ToInt32(a_sValue);            return true;        }        // Determines whether is digit string.        public bool IsDigitString(string a_sValue)        {            String strInt = a_sValue;            strInt.Trim();            if (strInt == "")            {                return false;            }            int nStart = 0;            if (strInt[nStart] == '-')            {                ++nStart;            }            // cycle through string and check each character if it is a digit            for (; nStart < strInt.Length; ++nStart)            {                if (strInt[nStart] != '-')                {                    return false;                }            }            return true;        }        // gets the name of the folder        static String GetFolderName(String a_strPathName)        {               string str=   FileHelper.GetFolderName(a_strPathName);            return str.ToString();        }        private bool LoadFieldDataFromDB(string a_strPathname)        {            // check the pathname string            a_strPathname.Trim();            if (a_strPathname == null)            {                // open                FolderBrowserDialog FileDialog = new FolderBrowserDialog();//创建一个文件对话框                if (FileDialog.ShowDialog() != DialogResult.OK)                {                    // user canceled loading                    logger.Info("Load: user canceled loading.");                    return false;                }                a_strPathname = FileDialog.SelectedPath;            }            // get path of the pathname            // COTSHelper cOTSHelper = new COTSHelper();            string strFilePath = GetFolderName(a_strPathname);            if (strFilePath == null)            {                // file path string is an empty string                 logger.Info("Load: file path string is an empty string.");                return false;            }            // field file sub folder string                      string strFieldFileSubFolder = strFilePath + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";            // check if the field file sub folder exists            // COTSEDSBase cOTSFileSys = new COTSEDSBase();            if (!Exists(strFieldFileSubFolder))            {// field files folder doesn't exist                logger.Info("Load: field files folder doesn't exist (%s).");                return false;            }            string strIncAFilename = strFieldFileSubFolder + "\\" +DBFILE_NAME;            CIncAFileMgr pIncAFileMgr = new CIncAFileMgr(strIncAFilename);            List<COTSFieldData> allFlds;            allFlds = null;            CMsrSampleStatus poMsrStatus = m_pSample.GetMsrStatus();            CMsrDisplayResults poMsrResults = m_pSample.GetMsrResults();            double aFldArea = m_pSample.CalculateAFieldArea();            if (GetAllFieldsFromDB(allFlds, poMsrStatus, poMsrResults, aFldArea))            {                SetFieldData(allFlds);                              return true;            }            else            {                return false;            }        }        public bool GetAllFieldsFromDB(List<COTSFieldData> allFlds, CMsrSampleStatus status, CMsrDisplayResults rst, double aFieldArea)        {                        List<System.Drawing.Point> completedfld = new List<System.Drawing.Point>();                    m_DBFileMgr.GetIncADB().GetAllFieldsRecord(ref allFlds);            var SegmentDB = m_DBFileMgr.GetSegmentDB();            double msrFldsArea = 0;            // std::map<int, COTSParticleList> mapTypeParticles;//record typeId relevants particlelist;            Dictionary<int, List<COTSParticleClr>> mapTypeParticles = new Dictionary<int, List<COTSParticleClr>>();            // std::map<std::vector<int>, COTSSegmentsList> AllSegments;            Dictionary<List<int>, List<COTSSegmentClr>> AllSegments = new Dictionary<List<int>, List<COTSSegmentClr>>();            if (SegmentDB.GetAllSegmentsRecord(AllSegments))            {                int nCol;                foreach (var fld in allFlds)                {                    int fldId = fld.GetId();                    List<COTSParticleClr> parts = fld.ListAnalysisParticles;                    List<COTSSegmentClr> cOTSSegment = new List<COTSSegmentClr>();                    foreach (var part in parts)                    {                        List<int> fldvec = new List<int>();                        fldvec.Add(fldId);                        fldvec.Add(part.GetTagId());                        var itr = AllSegments.Values;                        if (itr != AllSegments.Values)                        {                            COTSFeatureClr f = new COTSFeatureClr();                            f.SetSegmentsList(cOTSSegment, true);                            part.SetFeature(f);                        }                        mapTypeParticles[part.GetClassifyId()].Add(part);                    }                    completedfld.Add(fld.GetPosition());                    msrFldsArea += aFieldArea;                }            }            // get MsrStatus info from DB.                       String strTimeStart = "";            String strTimeEnd = "";            String strRstStatus = "";            var m_GenInfoDB = m_DBFileMgr.GetGeneralInfoDB();            m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameTimeStart(), ref strTimeStart);            m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameTimeEnd(),ref strTimeEnd);            m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameResultStatus(),ref strRstStatus);            status.SetCompletedFieldsCenter(completedfld);            status.SetCompletedFields(completedfld.Count);            DateTime timeStart, timeEnd;                      timeStart = Convert.ToDateTime(strTimeStart);            timeEnd = Convert.ToDateTime(strTimeEnd);            status.SetStartTime(timeStart);            status.SetEndTime(timeEnd);            status.SetUsedTime(timeEnd - timeStart);            status.SetStatus((OTS_MSR_SAMPLE_STATUS)Convert.ToInt32(strRstStatus));            //get MsrResults data from map.            List<CMsrResultItem> rstItms = new List<CMsrResultItem>();            double allPartArea = 0;            foreach (var typeParticles in mapTypeParticles)            {                CMsrResultItem rstItm = new CMsrResultItem();                int typeNum = 0;                double typeArea = 0;                foreach (var p in mapTypeParticles)                {                    typeNum += 1;                    typeArea += Convert.ToInt32(p);                }                rstItm.SetTypeId(Convert.ToInt32(typeParticles));                rstItm.SetNumber((uint)typeNum);                rstItm.SetArea((uint)typeArea);                rstItms.Add(rstItm);                allPartArea += typeArea;            }            rst.SetResultItems(rstItms);            rst.SetMeasuredArea((uint)msrFldsArea * 1000000);            rst.SetRatio(allPartArea / (msrFldsArea * 1000000));            return true;        }        // Save         public bool CreateResultFiles(List<Point> listallfldcenter)        {            InitFolders();            XmlDocument xmlDoc = new XmlDocument();            XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);            xmlDoc.AppendChild(xmlDeclaration);            XmlElement rootNode = xmlDoc.CreateElement("XMLData");            xmlDoc.AppendChild(rootNode);            //xmlDoc.LoadXml(a_strPathname);            XmlNode root = xmlDoc.SelectSingleNode("XMLData");            allfieldcenters = listallfldcenter;            Serialize(true, xmlDoc, root);            xmlDoc.Save(m_strRstFileName);                                m_DBFileMgr.InitFile();            m_DBFileMgr.InitDataTable();            return true;        }              public string GetFieldFileSubFolderStr()        {                                   // return field file sub folder string            return m_strFieldFileSubFolder;        }        // sample measure result file          // save a BSE file for a field        public bool SaveBSEFileForAField(COTSFieldData a_pField)        {            if (a_pField == null)            {                logger.Info("SaveBSEFileForAField: invalid field data pointer.");                return false;            }                     string strBSEFilePathname = m_strSampleWorkingFolder + "\\" +SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";            // save BSE file for the field            CBSEImgClr pBSEImage = a_pField.GetBSEImage();            CBSEImageFileMgr pBSEImgFileMgr = new CBSEImageFileMgr();            pBSEImgFileMgr.SetBSEImg(pBSEImage);            pBSEImgFileMgr.SaveIntoBitmap(strBSEFilePathname);            // ok, return TRUE            return true;        }        // save a x-ray file for a field        public bool SaveXRayFileForAField(List<CPosXrayClr>  a_pFieldXray)        {                string strIncAFilename = m_strDBFileFolder + "\\" + DBFILE_NAME;            // save x-ray file for the field            CPosXrayDBMgr pPosXrayDBMgr = new CIncAFileMgr(strIncAFilename).GetPosXrayDBMgr();               List<CPosXrayClr> listAnalysisXray = a_pFieldXray;                       if (!pPosXrayDBMgr.SaveXray(listAnalysisXray,true))            {                logger.Info("SaveXRayFileForAField: save analysis x-ray failed.");                return false;            }            // ok, return TRUE            return true;        }        // fields        public COTSFieldData GetFieldById(int a_nID)        {            List<COTSFieldData> listFieldData = GetFieldData();            if (a_nID < 0 || a_nID > (int)listFieldData.Count)            {                return null;            }           COTSFieldData pFieldData = listFieldData[a_nID];            return pFieldData;        }        public void AddAField(COTSFieldData a_pFieldData)        {            m_pSample.AddFieldData(a_pFieldData);            return ;        }        public void SetFieldData(List<COTSFieldData> a_listFieldData)        {            m_pSample.SetFieldsData(a_listFieldData);        }               public bool DeleteAFieldById(int a_nID)        {            List<COTSFieldData> listFieldData = GetFieldData();            if (a_nID < 0 || a_nID > (int)listFieldData.Count)            {                return false;            }            //listFieldData.erase(listFieldData.begin() + a_nID);            for (int i = 0; i < a_nID; i++)            {                listFieldData.RemoveAt(0);            }            return true;        }        // pathname        public string GetPathFileName()        {            return m_strRstFileName;        }        public string GetDBPathName()        {            return m_strdbPathName;        }        public void SetPathFileName(string PathName)        {            m_strRstFileName = PathName;        }        // set sample             // set SEM general data        public void SetSEMGnr(CSEMDataGnr a_pSEMGnr)        {            //ASSERT(a_pSEMGnr);            if (a_pSEMGnr == null)            {                logger.Info("input a invalid SEM general data pointer.");                return;            }           m_pSEMData= a_pSEMGnr;        }        // get id for a new field         public int GetIdForANewField()        {            List<COTSFieldData> listFieldData = GetFieldData();            // new field id            int nNewFieldId= listFieldData.Count;                              bool bUnit = false;            do            {                bool iffound = false;                COTSFieldData cOTSFieldData;                for (int i = 0; i < listFieldData.Count; i++)                {                    cOTSFieldData = listFieldData[i];                    if (cOTSFieldData.GetId() == nNewFieldId)                    {                        iffound = true;                    }                }                if (iffound == true)                {                    ++nNewFieldId;                }                else                {                    break;                }            } while (true);                                 return nNewFieldId;        }        // set SEMStageData        // set SEMStage        public void SetSEMStage(CStage a_pStage)        {            //ASSERT(a_pStage);            if (a_pStage == null)            {                logger.Info("input a invalid stage pointer.");                return;            }                  m_pStage= a_pStage;        }        // according to a sample result file get a list of OTSFieldMgr        //public List<COTSFieldData> GetOTSFldMgrListAndAnalysisXrayList()        //{                     //    //Get FieldDataList        //    List<COTSFieldData> listFieldData =GetFieldData();        //    int nFieldNum = (int)listFieldData.Count;                  //    // get field number        //    foreach (COTSFieldData pFieldData in listFieldData)        //    {                      //        string strIncAFilename = m_strDBFileFolder + "\\" + DBFILE_NAME;        //        CIncAFileMgr DBFile = new CIncAFileMgr(strIncAFilename);        //        COTSFieldData pFieldMgr = new COTSFieldData();                       //        // get FieldData                      //        //pFieldMgr.SetOTSFieldData(pFieldData);        //        List<COTSParticleClr> listParticle = pFieldData.ListAnalysisParticles;        //        if (listParticle == null)        //        {        //            logger.Info("GetOTSFieldMgrList: there is no particle in this field.");        //            continue;        //        }        //        // get BSE        //        string strFieldFileFolder = m_strFieldFileSubFolder;        //        int nId = pFieldData.GetId();        //        string sFieldId;                      //        sFieldId = nId.ToString();        //        CBSEImageFileMgr cBSEImgFileMgr = new CBSEImageFileMgr();        //        string strBSEFilePathname = strFieldFileFolder + SMPL_MSR_RESULT_FIELDS_BSE + sFieldId + cBSEImgFileMgr.BMP_IMG_FILE_EXT;        //        CBSEImageFileMgr pBSEImgFile = new CBSEImageFileMgr();        //        if (!pBSEImgFile.LoadFromBitmap(strBSEFilePathname, true) == true)        //        {        //            logger.Error("GetOTSFieldMgrList: can't load BSE File.");                         //            AddAField(pFieldMgr);        //            continue;        //        }        //        CBSEImgClr pBSEImg = pBSEImgFile.GetBSEImg();        //        pFieldMgr.SetBSEImage(pBSEImg);        //        // get analysis X-ray list        //        CPosXrayDBMgr pPosAnalysisXrayFileMgr = DBFile.GetPosXrayDBMgr();        //        pPosAnalysisXrayFileMgr.SetHasElement(true);        //        if (!pPosAnalysisXrayFileMgr.Load(pFieldData.GetId(), true))        //        {        //           AddAField(pFieldMgr);        //            continue;        //        }        //        List<CPosXrayClr> listAnalysisXray = pPosAnalysisXrayFileMgr.GetPosXrayList();                     //        AddAField(pFieldMgr);        //    }        //    var flddata = GetFieldData();        //    return flddata;        //}                  //----------------protected-----------------        //protected bool GetID(COTSFieldData cOTSFieldData, int a_TypeId)        //{        //    if (cOTSFieldData.GetId() == a_TypeId)        //    {        //        return true;        //    }        //    else        //    {        //        return false;        //    }        //}          }}
 |