123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
-
- using OTSDataType;
- using System.IO;
- using System.Xml;
- namespace OTSModelSharp
- {
- public class CSmplMsrResult
- {
- //----------------定义----------------------
- protected static NLog.Logger logger = null;
-
- string m_strSampleWorkingFolder;
- string m_strFieldFileSubFolder;
- string m_strParticleImageFolder;
-
- // 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 PARTICLE_IMGFOLDER = "PARTICLE_IMAGE";
- // BSE file name
- public string SMPL_MSR_RESULT_FIELDS_BSE = ("Field");
- public string SMPL_MSR_RESULT_FILE_FILTER = ("Sample Measure Result Files (*.rst)|*.rst||");
-
- //----------全局定义------------------
- // 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 = ("3.2.0");
- // sample measure result file extension
- //----------定义----------------------
- // file version string
- string m_strFileVersion;
- // SEM sample stage
- //CSEMStageData m_pSEMStageData;
- //// sample stage
- //CStage m_pStage;
-
- //CSEMDataGnr m_pSEMData;
- // sample setting
- COTSSample m_pSample;
- // switch
- bool m_bSwitch;
-
- public CIncAFileMgr DBFileMgr { get => m_DBFileMgr; set => m_DBFileMgr = value; }
-
- public CSmplMsrResult(string measureWorkingFolder,COTSSample a_pSample)
- {
- Init();
- logger = NLog.LogManager.GetCurrentClassLogger();
-
- m_pSample = a_pSample;
-
-
- m_strSampleWorkingFolder = measureWorkingFolder + "\\" + a_pSample.GetName();
- m_strFieldFileSubFolder = m_strSampleWorkingFolder + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER;
-
- m_strRstFileName = m_strSampleWorkingFolder + "\\" + a_pSample.GetName() + SMPL_MSR_RESULT_FILE_EXT;
- m_strdbPathName = m_strFieldFileSubFolder + "\\" + DBFILE_NAME;
- m_strParticleImageFolder= m_strFieldFileSubFolder + "\\" + PARTICLE_IMGFOLDER;
- m_DBFileMgr = new CIncAFileMgr(m_strdbPathName);
- }
- protected void Init()
- {
-
- m_strFileVersion = ("");
-
- //m_pSEMStageData = new CSEMStageData();
-
- //m_pStage = new CStage();
-
- //m_pSEMData = new CSEMDataGnr();
-
- m_bSwitch = false;
-
- }
- 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;
- //}
-
- 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);
- slo.Serialize(true, classDoc, rootNode);
- }
- else
- {
- slo.Serialize(false, classDoc, rootNode);
- m_bSwitch = xbSwitch.value();
- m_strFileVersion = xnVersion.value();
-
- }
- }
- 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;
- }
- CreateFolder(m_strParticleImageFolder);
- }
-
- 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);
-
- }
-
-
- // Save
- public bool CreateResultFiles()
- {
- 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);
-
- XmlNode root = xmlDoc.SelectSingleNode("XMLData");
-
- 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;
- }
- public string GetParticleImageFolder()
- {
- return m_strParticleImageFolder;
- }
-
-
- //public void SetSEMGnr(CSEMDataGnr a_pSEMGnr)
- //{
-
- // if (a_pSEMGnr == null)
- // {
- // logger.Info("input a invalid SEM general data pointer.");
- // return;
- // }
- // m_pSEMData= a_pSEMGnr;
- //}
- //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;
- //}
-
-
- }
- }
|