CSmplMsrResult.cs 9.6 KB

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