CSmplMsrResult.cs 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. using OTSCLRINTERFACE;
  2. using OTSDataType;
  3. using OTSModelSharp.DTLBase;
  4. using OTSModelSharp.ServiceInterface;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using System.Xml;
  14. namespace OTSModelSharp
  15. {
  16. class CSmplMsrResult
  17. {
  18. //----------------定义----------------------
  19. protected static NLog.Logger logger = null;
  20. // working folder string
  21. string m_strWorkingFolder;
  22. string m_strSampleWorkingFolder;
  23. string m_strFieldFileSubFolder;
  24. private string m_strBSEImageFileFolder;
  25. private string m_strDBFileFolder;
  26. // pathname
  27. string m_strRstFileName;
  28. string m_strdbPathName;
  29. CIncAFileMgr m_DBFileMgr ;
  30. public string SMPL_MSR_RESULT_FILE_EXT = ".rst";
  31. // fields file sub-directory string
  32. public string SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER = "FIELD_FILES";
  33. public string DBFILE_NAME = "Inclusion.db";
  34. public string SMPL_MSR_RESULT_FILE_FILTER = ("Sample Measure Result Files (*.rst)|*.rst||");
  35. // BSE file name
  36. public string SMPL_MSR_RESULT_FIELDS_BSE = ("Field");
  37. // search x-ray file name
  38. public string SMPL_MSR_RESULT_SEARCH_X_RAY_FILE = ("SearchXray.db");
  39. //----------全局定义------------------
  40. // sample measure result file mark
  41. public int SMPL_MSR_RESULT_FILE_MARK = 'S' + 'M' + 'P' + 'L' + 'M' + 'S' + 'R' + 'R' + 'E' + 'S' + 'U' + 'L' + 'T';
  42. // sample measure result file version
  43. public string SMPL_MSR_RESULT_FILE_VERSION = ("2.0.0");
  44. // sample measure result file extension
  45. //----------定义----------------------
  46. // file version string
  47. string m_strFileVersion;
  48. // SEM sample stage
  49. CSEMStageData m_pSEMStageData;
  50. // sample stage
  51. CStage m_pStage;
  52. //CSEMStageDataPtr m_pSEMData;
  53. CSEMDataGnr m_pSEMData;
  54. // sample setting
  55. COTSSample m_pSample;
  56. // switch
  57. bool m_bSwitch;
  58. public CIncAFileMgr DBFileMgr { get => m_DBFileMgr; set => m_DBFileMgr = value; }
  59. //----------------public-----------------
  60. public CSmplMsrResult()
  61. {
  62. Init();
  63. m_pSample = new COTSSample();
  64. }
  65. protected void Duplicate(CSmplMsrResult a_oSource)
  66. {
  67. // initialization
  68. Init();
  69. m_pSample = new COTSSample();
  70. // copy data over
  71. // file version string
  72. m_strFileVersion = a_oSource.m_strFileVersion;
  73. // SEM sample stage
  74. m_pSEMStageData = a_oSource.m_pSEMStageData;
  75. // sample stage
  76. m_pStage = a_oSource.m_pStage;
  77. // SEM condition??
  78. //CSEMStageDataPtr m_pSEMData;
  79. m_pSEMData = a_oSource.m_pSEMData;
  80. // sample setting
  81. m_pSample = a_oSource.m_pSample;
  82. // switch
  83. m_bSwitch = a_oSource.m_bSwitch;
  84. // fields
  85. m_pSample.GetFieldsData().Clear();
  86. foreach (COTSFieldData pFieldData in a_oSource.m_pSample.GetFieldsData())
  87. {
  88. COTSFieldData pFieldDataNew = pFieldData;
  89. m_pSample.GetFieldsData().Add(pFieldDataNew);
  90. }
  91. }
  92. public List<COTSFieldData> GetFieldData()
  93. {
  94. return m_pSample.GetFieldsData();
  95. //m_pSample.GetFieldsData()
  96. }
  97. public CSmplMsrResult(string measureWorkingFolder,COTSSample a_pSample)
  98. {
  99. Init();
  100. logger = NLog.LogManager.GetCurrentClassLogger();
  101. m_pSample = a_pSample;
  102. m_strWorkingFolder = measureWorkingFolder;
  103. m_strSampleWorkingFolder = measureWorkingFolder + "\\" + a_pSample.GetName();
  104. m_strFieldFileSubFolder = m_strSampleWorkingFolder + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER;
  105. m_strBSEImageFileFolder = m_strFieldFileSubFolder;
  106. m_strDBFileFolder = m_strFieldFileSubFolder;
  107. m_strRstFileName = m_strSampleWorkingFolder + "\\" + a_pSample.GetName() + SMPL_MSR_RESULT_FILE_EXT;
  108. m_strdbPathName = m_strFieldFileSubFolder + "\\" + DBFILE_NAME;
  109. m_DBFileMgr = new CIncAFileMgr(m_strdbPathName);
  110. }
  111. protected void Init()
  112. {
  113. m_strFileVersion = ("");
  114. m_pSEMStageData = new CSEMStageData();
  115. m_pStage = new CStage();
  116. m_pSEMData = new CSEMDataGnr();
  117. m_bSwitch = false;
  118. }
  119. protected void Cleanup()
  120. {
  121. m_pSample.GetFieldsData().Clear();
  122. }
  123. public string GetFileVersion()
  124. {
  125. return m_strFileVersion;
  126. }
  127. public void SetFileVersion(string a_strFileVersion)
  128. {
  129. m_strFileVersion = a_strFileVersion;
  130. }
  131. public COTSSample GetSample()
  132. {
  133. return m_pSample;
  134. }
  135. public void SetSample(COTSSample a_pSample)
  136. {
  137. if (a_pSample != null)
  138. {
  139. return;
  140. }
  141. m_pSample = a_pSample;
  142. }
  143. public CSEMStageData GetSEMStageData()
  144. {
  145. return m_pSEMStageData;
  146. }
  147. public void SetSEMStageData(CSEMStageData a_pSEMStageData)
  148. {
  149. m_pSEMStageData = a_pSEMStageData;
  150. }
  151. // sample stage
  152. public CStage GetStage()
  153. {
  154. return m_pStage;
  155. }
  156. public void SetStage(CStage a_pStage)
  157. {
  158. if (a_pStage != null)
  159. {
  160. return;
  161. }
  162. m_pStage = a_pStage;
  163. }
  164. // SEM condition
  165. public CSEMDataGnr GetSEMStage()
  166. {
  167. return m_pSEMData;
  168. }
  169. public void SetSEMStage(CSEMDataGnr a_pSEMData)
  170. {
  171. if (a_pSEMData != null)
  172. {
  173. return;
  174. }
  175. m_pSEMData = a_pSEMData;
  176. }
  177. public bool GetSwitch()
  178. {
  179. return m_bSwitch;
  180. }
  181. public void SetSwitch(bool a_bSwitch)
  182. {
  183. m_bSwitch = a_bSwitch;
  184. }
  185. public void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  186. {
  187. xInt xnFileMark = new xInt();
  188. xString xnVersion = new xString();
  189. xBool xbSwitch = new xBool();
  190. Collection<Slo> xfields = new Collection<Slo>();
  191. Slo slo = new Slo();
  192. slo.Register("FileMark", xnFileMark);
  193. slo.Register("Version", xnVersion);
  194. slo.Register("Switch", xbSwitch);
  195. slo.Register("SEMStageData", m_pSEMStageData);
  196. slo.Register("Stage", m_pStage);
  197. slo.Register("SEMData", m_pSEMData);
  198. slo.Register("Sample", m_pSample);
  199. slo.Register("Fields", xfields);
  200. if (isStoring)
  201. {
  202. xnFileMark.AssignValue(SMPL_MSR_RESULT_FILE_MARK);
  203. xnVersion.AssignValue(SMPL_MSR_RESULT_FILE_VERSION);
  204. xbSwitch.AssignValue(m_bSwitch);
  205. slo.Serialize(true, classDoc, rootNode);
  206. }
  207. else
  208. {
  209. slo.Serialize(false, classDoc, rootNode);
  210. m_bSwitch = xbSwitch.value();
  211. m_strFileVersion = xnVersion.value();
  212. }
  213. }
  214. private bool InitFolders()
  215. {
  216. if (!Exists(m_strSampleWorkingFolder))
  217. {
  218. // the working directory is not exit, create it
  219. if (!CreateFolder(m_strSampleWorkingFolder))
  220. {
  221. return false;
  222. }
  223. }
  224. // check if the field files directory exists
  225. if (!Exists(m_strFieldFileSubFolder))
  226. {
  227. // field files directory exists not exists, creates it
  228. if (!CreateFolder(m_strFieldFileSubFolder))
  229. {
  230. // failed to create the field files directory
  231. return false;
  232. }
  233. }
  234. return true;
  235. }
  236. // creates a folder.
  237. private bool CreateFolder(string a_strFolder)
  238. {
  239. // make sure the folder name string are not empty
  240. string strFolder = a_strFolder;
  241. strFolder.Trim();
  242. if (strFolder=="")
  243. {
  244. return false;
  245. }
  246. // if the folder exist?
  247. if (Exists(strFolder))
  248. {
  249. return true;
  250. }
  251. Directory.CreateDirectory(strFolder);
  252. bool bRet = true;
  253. // return folder create result
  254. return bRet;
  255. }
  256. // check if the file exists or not
  257. private bool Exists(string a_sPath)
  258. {
  259. return Directory.Exists(a_sPath);
  260. }
  261. // Load
  262. public bool Load(String a_strPathname /*= _T("")*/)
  263. {
  264. a_strPathname.Trim();
  265. if (a_strPathname == "")
  266. {
  267. FolderBrowserDialog FileDialog = new FolderBrowserDialog();//创建一个文件对话框
  268. if (FileDialog.ShowDialog() != DialogResult.OK)
  269. {
  270. // user canceled loading
  271. logger.Info("Load: user canceled loading.");
  272. return false;
  273. }
  274. a_strPathname = FileDialog.SelectedPath;
  275. }
  276. // get path of the pathname
  277. String strFilePath =a_strPathname;
  278. // field file sub folder string
  279. m_strFieldFileSubFolder = strFilePath + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
  280. // check if the field file sub folder exists
  281. if (!Exists(m_strFieldFileSubFolder))
  282. {
  283. // field files folder doesn't exist
  284. return false;
  285. }
  286. // file version
  287. String strFileVersion = m_strFileVersion;
  288. uint nFileVersion = GetVersionFromString(strFileVersion);
  289. if (nFileVersion == 0)
  290. {// invalid file
  291. return false;
  292. }
  293. // sample measure result file
  294. SetPathFileName(a_strPathname);
  295. this.LoadFieldDataFromDB(a_strPathname);
  296. // ok, return TRUE
  297. return true;
  298. }
  299. // Get file versio
  300. // File Version should be format <Major version>.<Minor version>.<Build version>, like 1.2.3
  301. public uint GetVersionFromString(string a_sVersion)
  302. {
  303. int nMajorVersion = 0;
  304. int nMinorVersion = 0;
  305. int nBuildVersion = 0;
  306. uint nVersion = 0;
  307. if (GetMajorVersionFromString(a_sVersion, nMajorVersion) &&
  308. GetMinorVersionFromString(a_sVersion, nMinorVersion) &&
  309. GetBuildVersionFromString(a_sVersion, nBuildVersion))
  310. {
  311. nVersion = (uint)nMajorVersion * 10000 + (uint)nMinorVersion * 100 + (uint)nBuildVersion;
  312. }
  313. return nVersion;
  314. }
  315. public bool GetMinorVersionFromString(string a_sVersion, int a_nVersion)
  316. {
  317. // version string
  318. String strVersion = a_sVersion;
  319. // get major file version string position first
  320. int nPosFirst = strVersion.IndexOf('.');
  321. if (nPosFirst < 0)
  322. {
  323. // failed to find major file version string
  324. return false;
  325. }
  326. // get minor file version string position
  327. int nPosSecond = strVersion.IndexOf('.', nPosFirst + 1);
  328. int nStrLength = nPosSecond - nPosFirst - 1;
  329. if (nStrLength <= 0)
  330. {
  331. // failed to find minor file version string
  332. return false;
  333. }
  334. // get minor file version string
  335. String strMinorVersion = strVersion.Remove(nPosFirst + 1, nStrLength);
  336. // the minor file version string can't be empty
  337. strMinorVersion.Trim();
  338. if (strMinorVersion == "")
  339. {
  340. // failed to find minor file version string
  341. return false;
  342. }
  343. // convert the minor version string to minor version number
  344. if (!StringToInt(strMinorVersion, a_nVersion))
  345. {
  346. // failed to convert the major file version string to number
  347. return false;
  348. }
  349. // ok, return TRUE
  350. return true;
  351. }
  352. public bool GetMajorVersionFromString(string a_sVersion, int a_nVersion)
  353. {
  354. // version string
  355. String strVersion = a_sVersion;
  356. // get major file version string position
  357. int nPosFirst = strVersion.IndexOf('.');
  358. if (nPosFirst <= 0)
  359. {
  360. // failed to find major file version
  361. return false;
  362. }
  363. // get major file version string
  364. String strMajorVersion = strVersion.PadLeft(nPosFirst);
  365. // the major file version string can't be empty
  366. strMajorVersion.Trim();
  367. if (strMajorVersion == "")
  368. {
  369. // failed to find major file version
  370. return false;
  371. }
  372. // convert the major version string to major version number
  373. if (!StringToInt(strMajorVersion, a_nVersion))
  374. {
  375. // failed to convert the major file version string to number
  376. return false;
  377. }
  378. // ok, return TRUE
  379. return true;
  380. }
  381. public bool GetBuildVersionFromString(string a_sVersion, int a_nBuild)
  382. {
  383. // version string
  384. String strVersion = a_sVersion;
  385. // get major file version string position first
  386. int nPosFirst = strVersion.IndexOf('.');
  387. if (nPosFirst < 0)
  388. {
  389. // failed to find major file version string
  390. return false;
  391. }
  392. // get minor file version string position
  393. int nPosSecond = strVersion.IndexOf('.', nPosFirst + 1);
  394. if (nPosSecond < 0)
  395. {
  396. // failed to find minor file version string
  397. return false;
  398. }
  399. // get build string position
  400. int nStrLength = strVersion.Length - nPosSecond - 1;
  401. if (nStrLength <= 0)
  402. {
  403. // failed to find build string
  404. return false;
  405. }
  406. // get build string
  407. String strBuild = strVersion.PadRight(nStrLength);
  408. // build string can't be empty
  409. strBuild.Trim();
  410. if (strBuild == "")
  411. {
  412. // failed to convert the build string to number
  413. return false;
  414. }
  415. // convert the build string to build number
  416. if (!StringToInt(strBuild, a_nBuild))
  417. {
  418. // failed to convert the build string to number
  419. return false;
  420. }
  421. // ok, return TRUE
  422. return true;
  423. }
  424. // Strings to int.
  425. public bool StringToInt(string a_sValue, int a_nValue)
  426. {
  427. if (!IsDigitString(a_sValue))
  428. {
  429. return false;
  430. }
  431. a_nValue = Convert.ToInt32(a_sValue);
  432. return true;
  433. }
  434. // Determines whether is digit string.
  435. public bool IsDigitString(string a_sValue)
  436. {
  437. String strInt = a_sValue;
  438. strInt.Trim();
  439. if (strInt == "")
  440. {
  441. return false;
  442. }
  443. int nStart = 0;
  444. if (strInt[nStart] == '-')
  445. {
  446. ++nStart;
  447. }
  448. // cycle through string and check each character if it is a digit
  449. for (; nStart < strInt.Length; ++nStart)
  450. {
  451. if (strInt[nStart] != '-')
  452. {
  453. return false;
  454. }
  455. }
  456. return true;
  457. }
  458. // gets the name of the folder
  459. static String GetFolderName(String a_strPathName)
  460. {
  461. string str= FileHelper.GetFolderName(a_strPathName);
  462. return str.ToString();
  463. }
  464. private bool LoadFieldDataFromDB(string a_strPathname)
  465. {
  466. // check the pathname string
  467. a_strPathname.Trim();
  468. if (a_strPathname == null)
  469. {
  470. // open
  471. FolderBrowserDialog FileDialog = new FolderBrowserDialog();//创建一个文件对话框
  472. if (FileDialog.ShowDialog() != DialogResult.OK)
  473. {
  474. // user canceled loading
  475. logger.Info("Load: user canceled loading.");
  476. return false;
  477. }
  478. a_strPathname = FileDialog.SelectedPath;
  479. }
  480. // get path of the pathname
  481. string strFilePath = GetFolderName(a_strPathname);
  482. if (strFilePath == null)
  483. {
  484. // file path string is an empty string
  485. logger.Info("Load: file path string is an empty string.");
  486. return false;
  487. }
  488. // field file sub folder string
  489. string strFieldFileSubFolder = strFilePath + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
  490. // check if the field file sub folder exists
  491. if (!Exists(strFieldFileSubFolder))
  492. {// field files folder doesn't exist
  493. logger.Info("Load: field files folder doesn't exist (%s).");
  494. return false;
  495. }
  496. string strIncAFilename = strFieldFileSubFolder + "\\" +DBFILE_NAME;
  497. CIncAFileMgr pIncAFileMgr = new CIncAFileMgr(strIncAFilename);
  498. List<COTSFieldData> allFlds;
  499. allFlds = null;
  500. CMsrSampleStatus poMsrStatus = m_pSample.GetMsrStatus();
  501. CMsrDisplayResults poMsrResults = m_pSample.GetMsrResults();
  502. double aFldArea = m_pSample.CalculateAFieldArea();
  503. if (GetAllFieldsFromDB(allFlds, poMsrStatus, poMsrResults, aFldArea))
  504. {
  505. SetFieldData(allFlds);
  506. return true;
  507. }
  508. else
  509. {
  510. return false;
  511. }
  512. }
  513. public bool GetAllFieldsFromDB(List<COTSFieldData> allFlds, CMsrSampleStatus status, CMsrDisplayResults rst, double aFieldArea)
  514. {
  515. List<System.Drawing.Point> completedfld = new List<System.Drawing.Point>();
  516. m_DBFileMgr.GetIncADB().GetAllFieldsRecord(ref allFlds);
  517. var SegmentDB = m_DBFileMgr.GetSegmentDB();
  518. double msrFldsArea = 0;
  519. Dictionary<int, List<COTSParticleClr>> mapTypeParticles = new Dictionary<int, List<COTSParticleClr>>();
  520. Dictionary<string, List<COTSSegmentClr>> AllSegments = new Dictionary<string, List<COTSSegmentClr>>();
  521. if (SegmentDB.GetAllSegmentsRecord(AllSegments))
  522. {
  523. int nCol;
  524. foreach (var fld in allFlds)
  525. {
  526. int fldId = fld.GetId();
  527. List<COTSParticleClr> parts = fld.GetListAnalysisParticles();
  528. List<COTSSegmentClr> cOTSSegment = new List<COTSSegmentClr>();
  529. foreach (var part in parts)
  530. {
  531. var itr = AllSegments.Values;
  532. if (itr != AllSegments.Values)
  533. {
  534. COTSFeatureClr f = new COTSFeatureClr();
  535. f.SetSegmentsList(cOTSSegment, true);
  536. part.SetFeature(f);
  537. }
  538. mapTypeParticles[part.GetClassifyId()].Add(part);
  539. }
  540. completedfld.Add(fld.GetOTSPosition());
  541. msrFldsArea += aFieldArea;
  542. }
  543. }
  544. // get MsrStatus info from DB.
  545. String strTimeStart = "";
  546. String strTimeEnd = "";
  547. String strRstStatus = "";
  548. var m_GenInfoDB = m_DBFileMgr.GetGeneralInfoDB();
  549. m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameTimeStart(), ref strTimeStart);
  550. m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameTimeEnd(),ref strTimeEnd);
  551. m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameResultStatus(),ref strRstStatus);
  552. status.SetCompletedFieldsCenter(completedfld);
  553. status.SetCompletedFields(completedfld.Count);
  554. DateTime timeStart, timeEnd;
  555. timeStart = Convert.ToDateTime(strTimeStart);
  556. timeEnd = Convert.ToDateTime(strTimeEnd);
  557. status.SetStartTime(timeStart);
  558. status.SetEndTime(timeEnd);
  559. status.SetUsedTime(timeEnd - timeStart);
  560. status.SetStatus((OTS_MSR_SAMPLE_STATUS)Convert.ToInt32(strRstStatus));
  561. //get MsrResults data from map.
  562. List<CMsrResultItem> rstItms = new List<CMsrResultItem>();
  563. double allPartArea = 0;
  564. foreach (var typeParticles in mapTypeParticles)
  565. {
  566. CMsrResultItem rstItm = new CMsrResultItem();
  567. int typeNum = 0;
  568. double typeArea = 0;
  569. foreach (var p in mapTypeParticles)
  570. {
  571. typeNum += 1;
  572. typeArea += Convert.ToInt32(p);
  573. }
  574. rstItm.SetTypeId(Convert.ToInt32(typeParticles));
  575. rstItm.SetNumber((uint)typeNum);
  576. rstItm.SetArea((uint)typeArea);
  577. rstItms.Add(rstItm);
  578. allPartArea += typeArea;
  579. }
  580. rst.SetResultItems(rstItms);
  581. rst.SetMeasuredArea((uint)msrFldsArea * 1000000);
  582. rst.SetRatio(allPartArea / (msrFldsArea * 1000000));
  583. return true;
  584. }
  585. // Save
  586. public bool CreateResultFiles()
  587. {
  588. InitFolders();
  589. XmlDocument xmlDoc = new XmlDocument();
  590. XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
  591. xmlDoc.AppendChild(xmlDeclaration);
  592. XmlElement rootNode = xmlDoc.CreateElement("XMLData");
  593. xmlDoc.AppendChild(rootNode);
  594. XmlNode root = xmlDoc.SelectSingleNode("XMLData");
  595. Serialize(true, xmlDoc, root);
  596. xmlDoc.Save(m_strRstFileName);
  597. m_DBFileMgr.InitFile();
  598. m_DBFileMgr.InitDataTable();
  599. return true;
  600. }
  601. public string GetFieldFileSubFolderStr()
  602. {
  603. // return field file sub folder string
  604. return m_strFieldFileSubFolder;
  605. }
  606. // sample measure result file
  607. // save a BSE file for a field
  608. public bool SaveBSEFileForAField(COTSFieldData a_pField)
  609. {
  610. if (a_pField == null)
  611. {
  612. logger.Info("SaveBSEFileForAField: invalid field data pointer.");
  613. return false;
  614. }
  615. string strBSEFilePathname = m_strSampleWorkingFolder + "\\" +SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
  616. // save BSE file for the field
  617. CBSEImgClr pBSEImage = a_pField.GetBSEImage();
  618. CBSEImageFileMgr pBSEImgFileMgr = new CBSEImageFileMgr();
  619. pBSEImgFileMgr.SetBSEImg(pBSEImage);
  620. pBSEImgFileMgr.SaveIntoBitmap(strBSEFilePathname);
  621. // ok, return TRUE
  622. return true;
  623. }
  624. // save a x-ray file for a field
  625. public bool SaveXRayFileForAField(List<CPosXrayClr> a_pFieldXray)
  626. {
  627. string strIncAFilename = m_strDBFileFolder + "\\" + DBFILE_NAME;
  628. // save x-ray file for the field
  629. CPosXrayDBMgr pPosXrayDBMgr = new CIncAFileMgr(strIncAFilename).GetPosXrayDBMgr();
  630. List<CPosXrayClr> listAnalysisXray = a_pFieldXray;
  631. if (!pPosXrayDBMgr.SaveXray(listAnalysisXray,true))
  632. {
  633. logger.Info("SaveXRayFileForAField: save analysis x-ray failed.");
  634. return false;
  635. }
  636. // ok, return TRUE
  637. return true;
  638. }
  639. // fields
  640. public COTSFieldData GetFieldById(int a_nID)
  641. {
  642. List<COTSFieldData> listFieldData = GetFieldData();
  643. if (a_nID < 0 || a_nID > (int)listFieldData.Count)
  644. {
  645. return null;
  646. }
  647. COTSFieldData pFieldData = listFieldData[a_nID];
  648. return pFieldData;
  649. }
  650. public void AddAField(COTSFieldData a_pFieldData)
  651. {
  652. m_pSample.AddFieldData(a_pFieldData);
  653. return ;
  654. }
  655. public void SetFieldData(List<COTSFieldData> a_listFieldData)
  656. {
  657. m_pSample.SetFieldsData(a_listFieldData);
  658. }
  659. public bool DeleteAFieldById(int a_nID)
  660. {
  661. List<COTSFieldData> listFieldData = GetFieldData();
  662. if (a_nID < 0 || a_nID > (int)listFieldData.Count)
  663. {
  664. return false;
  665. }
  666. //listFieldData.erase(listFieldData.begin() + a_nID);
  667. for (int i = 0; i < a_nID; i++)
  668. {
  669. listFieldData.RemoveAt(0);
  670. }
  671. return true;
  672. }
  673. // pathname
  674. public string GetPathFileName()
  675. {
  676. return m_strRstFileName;
  677. }
  678. public string GetDBPathName()
  679. {
  680. return m_strdbPathName;
  681. }
  682. public void SetPathFileName(string PathName)
  683. {
  684. m_strRstFileName = PathName;
  685. }
  686. // set sample
  687. // set SEM general data
  688. public void SetSEMGnr(CSEMDataGnr a_pSEMGnr)
  689. {
  690. //ASSERT(a_pSEMGnr);
  691. if (a_pSEMGnr == null)
  692. {
  693. logger.Info("input a invalid SEM general data pointer.");
  694. return;
  695. }
  696. m_pSEMData= a_pSEMGnr;
  697. }
  698. // get id for a new field
  699. public int GetIdForANewField()
  700. {
  701. List<COTSFieldData> listFieldData = GetFieldData();
  702. // new field id
  703. int nNewFieldId= listFieldData.Count;
  704. bool bUnit = false;
  705. do
  706. {
  707. bool iffound = false;
  708. COTSFieldData cOTSFieldData;
  709. for (int i = 0; i < listFieldData.Count; i++)
  710. {
  711. cOTSFieldData = listFieldData[i];
  712. if (cOTSFieldData.GetId() == nNewFieldId)
  713. {
  714. iffound = true;
  715. }
  716. }
  717. if (iffound == true)
  718. {
  719. ++nNewFieldId;
  720. }
  721. else
  722. {
  723. break;
  724. }
  725. } while (true);
  726. return nNewFieldId;
  727. }
  728. // set SEMStageData
  729. // set SEMStage
  730. public void SetSEMStage(CStage a_pStage)
  731. {
  732. //ASSERT(a_pStage);
  733. if (a_pStage == null)
  734. {
  735. logger.Info("input a invalid stage pointer.");
  736. return;
  737. }
  738. m_pStage= a_pStage;
  739. }
  740. // according to a sample result file get a list of OTSFieldMgr
  741. //public List<COTSFieldData> GetOTSFldMgrListAndAnalysisXrayList()
  742. //{
  743. // //Get FieldDataList
  744. // List<COTSFieldData> listFieldData =GetFieldData();
  745. // int nFieldNum = (int)listFieldData.Count;
  746. // // get field number
  747. // foreach (COTSFieldData pFieldData in listFieldData)
  748. // {
  749. // string strIncAFilename = m_strDBFileFolder + "\\" + DBFILE_NAME;
  750. // CIncAFileMgr DBFile = new CIncAFileMgr(strIncAFilename);
  751. // COTSFieldData pFieldMgr = new COTSFieldData();
  752. // // get FieldData
  753. // //pFieldMgr.SetOTSFieldData(pFieldData);
  754. // List<COTSParticleClr> listParticle = pFieldData.ListAnalysisParticles;
  755. // if (listParticle == null)
  756. // {
  757. // logger.Info("GetOTSFieldMgrList: there is no particle in this field.");
  758. // continue;
  759. // }
  760. // // get BSE
  761. // string strFieldFileFolder = m_strFieldFileSubFolder;
  762. // int nId = pFieldData.GetId();
  763. // string sFieldId;
  764. // sFieldId = nId.ToString();
  765. // CBSEImageFileMgr cBSEImgFileMgr = new CBSEImageFileMgr();
  766. // string strBSEFilePathname = strFieldFileFolder + SMPL_MSR_RESULT_FIELDS_BSE + sFieldId + cBSEImgFileMgr.BMP_IMG_FILE_EXT;
  767. // CBSEImageFileMgr pBSEImgFile = new CBSEImageFileMgr();
  768. // if (!pBSEImgFile.LoadFromBitmap(strBSEFilePathname, true) == true)
  769. // {
  770. // logger.Error("GetOTSFieldMgrList: can't load BSE File.");
  771. // AddAField(pFieldMgr);
  772. // continue;
  773. // }
  774. // CBSEImgClr pBSEImg = pBSEImgFile.GetBSEImg();
  775. // pFieldMgr.SetBSEImage(pBSEImg);
  776. // // get analysis X-ray list
  777. // CPosXrayDBMgr pPosAnalysisXrayFileMgr = DBFile.GetPosXrayDBMgr();
  778. // pPosAnalysisXrayFileMgr.SetHasElement(true);
  779. // if (!pPosAnalysisXrayFileMgr.Load(pFieldData.GetId(), true))
  780. // {
  781. // AddAField(pFieldMgr);
  782. // continue;
  783. // }
  784. // List<CPosXrayClr> listAnalysisXray = pPosAnalysisXrayFileMgr.GetPosXrayList();
  785. // AddAField(pFieldMgr);
  786. // }
  787. // var flddata = GetFieldData();
  788. // return flddata;
  789. //}
  790. //----------------protected-----------------
  791. //protected bool GetID(COTSFieldData cOTSFieldData, int a_TypeId)
  792. //{
  793. // if (cOTSFieldData.GetId() == a_TypeId)
  794. // {
  795. // return true;
  796. // }
  797. // else
  798. // {
  799. // return false;
  800. // }
  801. //}
  802. }
  803. }