CSmplMsrResult.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. 
  2. using OTSDataType;
  3. using System.IO;
  4. using System.Xml;
  5. namespace OTSModelSharp
  6. {
  7. public class CSmplMsrResult
  8. {
  9. //----------------定义----------------------
  10. protected static NLog.Logger logger = null;
  11. string m_strSampleWorkingFolder;
  12. string m_strFieldFileSubFolder;
  13. string m_strParticleImageFolder;
  14. // pathname
  15. string m_strRstFileName;
  16. string m_strdbPathName;
  17. CIncAFileMgr m_DBFileMgr ;
  18. public string SMPL_MSR_RESULT_FILE_EXT = ".rst";
  19. // fields file sub-directory string
  20. public string SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER = "FIELD_FILES";
  21. public string DBFILE_NAME = "Inclusion.db";
  22. public string PARTICLE_IMGFOLDER = "PARTICLE_IMAGE";
  23. // BSE file name
  24. public string SMPL_MSR_RESULT_FIELDS_BSE = ("Field");
  25. public string SMPL_MSR_RESULT_FILE_FILTER = ("Sample Measure Result Files (*.rst)|*.rst||");
  26. //----------全局定义------------------
  27. // sample measure result file mark
  28. public int SMPL_MSR_RESULT_FILE_MARK = 'S' + 'M' + 'P' + 'L' + 'M' + 'S' + 'R' + 'R' + 'E' + 'S' + 'U' + 'L' + 'T';
  29. // sample measure result file version
  30. public string SMPL_MSR_RESULT_FILE_VERSION = ("3.2.0");
  31. // sample measure result file extension
  32. //----------定义----------------------
  33. // file version string
  34. string m_strFileVersion;
  35. // SEM sample stage
  36. //CSEMStageData m_pSEMStageData;
  37. //// sample stage
  38. //CStage m_pStage;
  39. //CSEMDataGnr m_pSEMData;
  40. // sample setting
  41. COTSSample m_pSample;
  42. // switch
  43. bool m_bSwitch;
  44. public CIncAFileMgr DBFileMgr { get => m_DBFileMgr; set => m_DBFileMgr = value; }
  45. public CSmplMsrResult(string measureWorkingFolder,COTSSample a_pSample)
  46. {
  47. Init();
  48. logger = NLog.LogManager.GetCurrentClassLogger();
  49. m_pSample = a_pSample;
  50. m_strSampleWorkingFolder = measureWorkingFolder + "\\" + a_pSample.GetName();
  51. m_strFieldFileSubFolder = m_strSampleWorkingFolder + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER;
  52. m_strRstFileName = m_strSampleWorkingFolder + "\\" + a_pSample.GetName() + SMPL_MSR_RESULT_FILE_EXT;
  53. m_strdbPathName = m_strFieldFileSubFolder + "\\" + DBFILE_NAME;
  54. m_strParticleImageFolder= m_strFieldFileSubFolder + "\\" + PARTICLE_IMGFOLDER;
  55. m_DBFileMgr = new CIncAFileMgr(m_strdbPathName);
  56. }
  57. protected void Init()
  58. {
  59. m_strFileVersion = ("");
  60. //m_pSEMStageData = new CSEMStageData();
  61. //m_pStage = new CStage();
  62. //m_pSEMData = new CSEMDataGnr();
  63. m_bSwitch = false;
  64. }
  65. protected void Cleanup()
  66. {
  67. m_pSample.GetFieldsData().Clear();
  68. }
  69. public string GetFileVersion()
  70. {
  71. return m_strFileVersion;
  72. }
  73. public void SetFileVersion(string a_strFileVersion)
  74. {
  75. m_strFileVersion = a_strFileVersion;
  76. }
  77. public COTSSample GetSample()
  78. {
  79. return m_pSample;
  80. }
  81. public void SetSample(COTSSample a_pSample)
  82. {
  83. if (a_pSample != null)
  84. {
  85. return;
  86. }
  87. m_pSample = a_pSample;
  88. }
  89. //public CSEMStageData GetSEMStageData()
  90. //{
  91. // return m_pSEMStageData;
  92. //}
  93. //public void SetSEMStageData(CSEMStageData a_pSEMStageData)
  94. //{
  95. // m_pSEMStageData = a_pSEMStageData;
  96. //}
  97. //// sample stage
  98. //public CStage GetStage()
  99. //{
  100. // return m_pStage;
  101. //}
  102. //public void SetStage(CStage a_pStage)
  103. //{
  104. // if (a_pStage != null)
  105. // {
  106. // return;
  107. // }
  108. // m_pStage = a_pStage;
  109. //}
  110. //// SEM condition
  111. //public CSEMDataGnr GetSEMStage()
  112. //{
  113. // return m_pSEMData;
  114. //}
  115. //public void SetSEMStage(CSEMDataGnr a_pSEMData)
  116. //{
  117. // if (a_pSEMData != null)
  118. // {
  119. // return;
  120. // }
  121. // m_pSEMData = a_pSEMData;
  122. //}
  123. public void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  124. {
  125. xInt xnFileMark = new xInt();
  126. xString xnVersion = new xString();
  127. xBool xbSwitch = new xBool();
  128. Collection<Slo> xfields = new Collection<Slo>();
  129. Slo slo = new Slo();
  130. slo.Register("FileMark", xnFileMark);
  131. slo.Register("Version", xnVersion);
  132. slo.Register("Switch", xbSwitch);
  133. //slo.Register("SEMStageData", m_pSEMStageData);
  134. //slo.Register("Stage", m_pStage);
  135. //slo.Register("SEMData", m_pSEMData);
  136. slo.Register("Sample", m_pSample);
  137. //slo.Register("Fields", xfields);
  138. if (isStoring)
  139. {
  140. xnFileMark.AssignValue(SMPL_MSR_RESULT_FILE_MARK);
  141. xnVersion.AssignValue(SMPL_MSR_RESULT_FILE_VERSION);
  142. xbSwitch.AssignValue(m_bSwitch);
  143. slo.Serialize(true, classDoc, rootNode);
  144. }
  145. else
  146. {
  147. slo.Serialize(false, classDoc, rootNode);
  148. m_bSwitch = xbSwitch.value();
  149. m_strFileVersion = xnVersion.value();
  150. }
  151. }
  152. private bool InitFolders()
  153. {
  154. if (!Exists(m_strSampleWorkingFolder))
  155. {
  156. // the working directory is not exit, create it
  157. if (!CreateFolder(m_strSampleWorkingFolder))
  158. {
  159. return false;
  160. }
  161. }
  162. // check if the field files directory exists
  163. if (!Exists(m_strFieldFileSubFolder))
  164. {
  165. // field files directory exists not exists, creates it
  166. if (!CreateFolder(m_strFieldFileSubFolder))
  167. {
  168. // failed to create the field files directory
  169. return false;
  170. }
  171. CreateFolder(m_strParticleImageFolder);
  172. }
  173. return true;
  174. }
  175. // creates a folder.
  176. private bool CreateFolder(string a_strFolder)
  177. {
  178. // make sure the folder name string are not empty
  179. string strFolder = a_strFolder;
  180. strFolder.Trim();
  181. if (strFolder=="")
  182. {
  183. return false;
  184. }
  185. // if the folder exist?
  186. if (Exists(strFolder))
  187. {
  188. return true;
  189. }
  190. Directory.CreateDirectory(strFolder);
  191. bool bRet = true;
  192. // return folder create result
  193. return bRet;
  194. }
  195. // check if the file exists or not
  196. private bool Exists(string a_sPath)
  197. {
  198. return Directory.Exists(a_sPath);
  199. }
  200. // Save
  201. public bool CreateResultFiles()
  202. {
  203. InitFolders();
  204. XmlDocument xmlDoc = new XmlDocument();
  205. XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
  206. xmlDoc.AppendChild(xmlDeclaration);
  207. XmlElement rootNode = xmlDoc.CreateElement("XMLData");
  208. xmlDoc.AppendChild(rootNode);
  209. XmlNode root = xmlDoc.SelectSingleNode("XMLData");
  210. Serialize(true, xmlDoc, root);
  211. xmlDoc.Save(m_strRstFileName);
  212. m_DBFileMgr.InitFile();
  213. m_DBFileMgr.InitDataTable();
  214. return true;
  215. }
  216. public string GetFieldFileSubFolderStr()
  217. {
  218. // return field file sub folder string
  219. return m_strFieldFileSubFolder;
  220. }
  221. public string GetParticleImageFolder()
  222. {
  223. return m_strParticleImageFolder;
  224. }
  225. //public void SetSEMGnr(CSEMDataGnr a_pSEMGnr)
  226. //{
  227. // if (a_pSEMGnr == null)
  228. // {
  229. // logger.Info("input a invalid SEM general data pointer.");
  230. // return;
  231. // }
  232. // m_pSEMData= a_pSEMGnr;
  233. //}
  234. //public void SetSEMStage(CStage a_pStage)
  235. //{
  236. // //ASSERT(a_pStage);
  237. // if (a_pStage == null)
  238. // {
  239. // logger.Info("input a invalid stage pointer.");
  240. // return;
  241. // }
  242. // m_pStage= a_pStage;
  243. //}
  244. }
  245. }