SmplMsrResultFile.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml;
  7. using OTSDataType;
  8. using static OTSDataType.otsdataconst;
  9. namespace OTSModelSharp
  10. {
  11. class CSmplMsrResultFile
  12. {
  13. //----------全局定义------------------
  14. // sample measure result file mark
  15. public int SMPL_MSR_RESULT_FILE_MARK = 'S' + 'M' + 'P' + 'L' + 'M' + 'S' + 'R' + 'R' + 'E' + 'S' + 'U' + 'L' + 'T';
  16. // sample measure result file version
  17. public string SMPL_MSR_RESULT_FILE_VERSION = ("1.1.1");
  18. // sample measure result file extension
  19. public string SMPL_MSR_RESULT_FILE_EXT = (".rst");
  20. public string SMPL_MSR_RESULT_FILE_FILTER = ("Sample Measure Result Files (*.rst)|*.rst||");
  21. // fields file sub-directory string
  22. public string SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER = ("FIELD_FILES");
  23. // BSE file name
  24. public string SMPL_MSR_RESULT_FIELDS_BSE = ("Field");
  25. // search x-ray file name
  26. public string SMPL_MSR_RESULT_SEARCH_X_RAY_FILE = ("SearchXray.db");
  27. // analysis x-ray file name
  28. public string SMPL_MSR_RESULT_ANALYSIS_X_RAY_FILE = ("Inclusion.db");
  29. // Inclusion file name
  30. public string SMPL_MSR_RESULT_INCLUSION_FILE = ("Inclusion.db");//put all the table in one db file so that report can make join query.
  31. //----------定义----------------------
  32. // file version string
  33. string m_strFileVersion;
  34. // SEM sample stage
  35. CSEMStageData m_pSEMStageData;
  36. // sample stage
  37. CStage m_pStage;
  38. //CSEMStageDataPtr m_pSEMData;
  39. CSEMDataGnr m_pSEMData;
  40. // sample setting
  41. COTSSample m_pSample;
  42. // switch
  43. bool m_bSwitch;
  44. // fields
  45. List<COTSFieldData> m_listFieldData;
  46. //----------public-------------------
  47. public CSmplMsrResultFile()
  48. {
  49. Init();
  50. }
  51. public CSmplMsrResultFile(CSmplMsrResultFile a_oSource)
  52. {
  53. // can't copy itself
  54. if (a_oSource == this)
  55. {
  56. return;
  57. }
  58. // copy data over
  59. Duplicate(a_oSource);
  60. }
  61. public virtual void Dispose()
  62. {
  63. Cleanup();
  64. }
  65. public bool Equals(CSmplMsrResultFile a_oSource)
  66. {
  67. Duplicate(a_oSource);
  68. return false;
  69. }
  70. // cleanup
  71. public void Cleanup()
  72. {
  73. m_listFieldData.Clear();
  74. }
  75. // file version string
  76. public string GetFileVersion()
  77. {
  78. return m_strFileVersion;
  79. }
  80. public void SetFileVersion(string a_strFileVersion)
  81. {
  82. m_strFileVersion = a_strFileVersion;
  83. }
  84. // SEM sample stage
  85. public CSEMStageData GetSEMStageData()
  86. {
  87. return m_pSEMStageData;
  88. }
  89. public void SetSEMStageData(CSEMStageData a_pSEMStageData )
  90. {
  91. if (a_pSEMStageData!=null)
  92. {
  93. return;
  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. // sample setting
  124. public COTSSample GetSample()
  125. {
  126. return m_pSample;
  127. }
  128. public void SetSample (COTSSample a_pSample)
  129. {
  130. if (a_pSample!=null)
  131. {
  132. return;
  133. }
  134. m_pSample = a_pSample;
  135. SetFieldData(a_pSample.GetFieldsData());
  136. }
  137. // switch
  138. public bool GetSwitch()
  139. {
  140. return m_bSwitch;
  141. }
  142. public void SetSwitch(bool a_bSwitch)
  143. {
  144. m_bSwitch = a_bSwitch;
  145. }
  146. //fields
  147. public List<COTSFieldData> GetFieldData()
  148. {
  149. return m_listFieldData;
  150. }
  151. public void SetFieldData(List<COTSFieldData> a_listFieldData)
  152. {
  153. m_listFieldData.Clear();
  154. foreach(COTSFieldData pFieldData in a_listFieldData)
  155. {
  156. m_listFieldData.Add(pFieldData);
  157. }
  158. }
  159. public List<COTSParticle> GetAllParticles()
  160. {
  161. List<COTSParticle> listParticle = new List<COTSParticle>();
  162. List< COTSFieldData> listFieldData = GetFieldData();
  163. foreach (var pFieldData in listFieldData)
  164. {
  165. List< COTSParticle> listParticlenew = pFieldData.GetParticleList();
  166. foreach (var pParticle in listParticlenew)
  167. {
  168. listParticle.Add(pParticle);
  169. }
  170. }
  171. return listParticle;
  172. }
  173. //----------protected----------------
  174. // initialization
  175. protected void Init()
  176. {
  177. // file version string
  178. m_strFileVersion = ("");
  179. // SEM sample stage
  180. m_pSEMStageData = new CSEMStageData();
  181. // sample stage
  182. m_pStage = new CStage();
  183. // SEM condition??
  184. //CSEMStageDataPtr m_pSEMData;
  185. m_pSEMData = new CSEMDataGnr();
  186. // sample setting
  187. m_pSample =new COTSSample();
  188. // switch
  189. m_bSwitch = false;
  190. // fields
  191. m_listFieldData.Clear();
  192. }
  193. protected void Duplicate(CSmplMsrResultFile a_oSource)
  194. {
  195. // initialization
  196. Init();
  197. // copy data over
  198. // file version string
  199. m_strFileVersion = a_oSource.m_strFileVersion;
  200. // SEM sample stage
  201. m_pSEMStageData = a_oSource.m_pSEMStageData;
  202. // sample stage
  203. m_pStage = a_oSource.m_pStage;
  204. // SEM condition??
  205. //CSEMStageDataPtr m_pSEMData;
  206. m_pSEMData = a_oSource.m_pSEMData;
  207. // sample setting
  208. m_pSample = a_oSource.m_pSample;
  209. // switch
  210. m_bSwitch = a_oSource.m_bSwitch;
  211. // fields
  212. m_listFieldData.Clear();
  213. foreach (COTSFieldData pFieldData in a_oSource.m_listFieldData)
  214. {
  215. COTSFieldData pFieldDataNew = pFieldData;
  216. m_listFieldData.Add(pFieldDataNew);
  217. }
  218. }
  219. public void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  220. {
  221. xInt xnFileMark = new xInt();
  222. xString xnVersion = new xString();
  223. xBool xbSwitch = new xBool();
  224. Collection<COTSFieldData> xfields = new Collection<COTSFieldData>();
  225. Collection<CSEMStageData> m_pSEMStageData = new Collection<CSEMStageData>();
  226. Collection<CStage> m_pStage = new Collection<CStage>();
  227. Collection<CSEMDataGnr> m_pSEMData = new Collection<CSEMDataGnr>();
  228. Collection<COTSSample> m_pSample = new Collection<COTSSample>();
  229. Slo slo = new Slo();
  230. slo.Register("xnFileMark", xnFileMark);
  231. slo.Register("xnVersion", xnVersion);
  232. slo.Register("xbSwitch", xbSwitch);
  233. slo.Register("SEMStageData", m_pSEMStageData);
  234. slo.Register("Stage", m_pStage);
  235. slo.Register("SEMData", m_pSEMData);
  236. slo.Register("Sample", m_pSample);
  237. slo.Register("Fields", xfields);
  238. if (isStoring)
  239. {
  240. xnFileMark.AssignValue(SMPL_MSR_RESULT_FILE_MARK);
  241. xnVersion.AssignValue(SMPL_MSR_RESULT_FILE_VERSION);
  242. xbSwitch.AssignValue(m_bSwitch);
  243. xfields.Clear();
  244. /*for (auto pFildData : m_listFieldData)
  245. {
  246. xfields.addItem(pFildData.get());
  247. }*/
  248. slo.Serialize(true, classDoc, rootNode);
  249. }
  250. else
  251. {
  252. slo.Serialize(false, classDoc, rootNode);
  253. m_bSwitch = xbSwitch.value();
  254. m_strFileVersion = xnVersion.value().ToString();
  255. m_listFieldData.Clear();
  256. /*for (unsigned int i = 0;i < xfields.size(); i++)
  257. {
  258. m_listFieldData.push_back(COTSFieldDataPtr(xfields.getItem(i)));
  259. }*/
  260. }
  261. }
  262. public bool GetSTDMapedParticleList(Dictionary<string, List<COTSParticle>> mapSameSTDPartList)
  263. {
  264. //把颗粒根据类型分组,类型 ID做key,颗粒列表做value
  265. Dictionary < string, List<COTSParticle>> partListIter;
  266. var listParticle = GetAllParticles();
  267. //get the same type particle together
  268. foreach (var pParticle in listParticle)
  269. {
  270. string sType = pParticle.TypeName();
  271. int nType = pParticle.GetType();
  272. //只有"NOT_IDENTIFIED"以上的颗粒类型需要考虑
  273. if (nType >= (int)OTS_PARTCLE_TYPE.NOT_IDENTIFIED_SIC)
  274. {
  275. partListIter = mapSameSTDPartList;
  276. if (partListIter == mapSameSTDPartList)
  277. {
  278. List<COTSParticle> listParticles = new List<COTSParticle>();
  279. listParticles.Add(pParticle);
  280. mapSameSTDPartList.Insert(new KeyValuePair<string, List<COTSParticle>>(sType, listParticles));
  281. }
  282. else
  283. {
  284. partListIter.second.Add(pParticle);
  285. }
  286. }
  287. }
  288. return true;
  289. }
  290. }
  291. }