CSmplMsrResult.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  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. public 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. public 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.PointF> completedfld = new List<System.Drawing.PointF>();
  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. DateTime timeStart, timeEnd;
  554. timeStart = Convert.ToDateTime(strTimeStart);
  555. timeEnd = Convert.ToDateTime(strTimeEnd);
  556. status.SetStartTime(timeStart);
  557. status.SetEndTime(timeEnd);
  558. status.SetUsedTime(timeEnd - timeStart);
  559. status.SetStatus((OTS_MSR_SAMPLE_STATUS)Convert.ToInt32(strRstStatus));
  560. //get MsrResults data from map.
  561. List<CMsrResultItem> rstItms = new List<CMsrResultItem>();
  562. double allPartArea = 0;
  563. foreach (var typeParticles in mapTypeParticles)
  564. {
  565. CMsrResultItem rstItm = new CMsrResultItem();
  566. int typeNum = 0;
  567. double typeArea = 0;
  568. foreach (var p in mapTypeParticles)
  569. {
  570. typeNum += 1;
  571. typeArea += Convert.ToInt32(p);
  572. }
  573. rstItm.SetTypeId(Convert.ToInt32(typeParticles));
  574. rstItm.SetNumber((uint)typeNum);
  575. rstItm.SetArea((uint)typeArea);
  576. rstItms.Add(rstItm);
  577. allPartArea += typeArea;
  578. }
  579. rst.SetResultItems(rstItms);
  580. rst.SetMeasuredArea((uint)msrFldsArea * 1000000);
  581. rst.SetRatio(allPartArea / (msrFldsArea * 1000000));
  582. return true;
  583. }
  584. // Save
  585. public bool CreateResultFiles()
  586. {
  587. InitFolders();
  588. XmlDocument xmlDoc = new XmlDocument();
  589. XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
  590. xmlDoc.AppendChild(xmlDeclaration);
  591. XmlElement rootNode = xmlDoc.CreateElement("XMLData");
  592. xmlDoc.AppendChild(rootNode);
  593. XmlNode root = xmlDoc.SelectSingleNode("XMLData");
  594. Serialize(true, xmlDoc, root);
  595. if (!File.Exists(m_strRstFileName))
  596. {
  597. xmlDoc.Save(m_strRstFileName);
  598. }
  599. m_DBFileMgr.InitFile();
  600. m_DBFileMgr.InitDataTable();
  601. return true;
  602. }
  603. public string GetFieldFileSubFolderStr()
  604. {
  605. // return field file sub folder string
  606. return m_strFieldFileSubFolder;
  607. }
  608. // sample measure result file
  609. // save a BSE file for a field
  610. public bool SaveBSEFileForAField(COTSFieldData a_pField)
  611. {
  612. if (a_pField == null)
  613. {
  614. logger.Info("SaveBSEFileForAField: invalid field data pointer.");
  615. return false;
  616. }
  617. string strBSEFilePathname = m_strSampleWorkingFolder + "\\" +SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
  618. // save BSE file for the field
  619. CBSEImgClr pBSEImage = a_pField.GetBSEImage();
  620. CBSEImageFileMgr pBSEImgFileMgr = new CBSEImageFileMgr();
  621. pBSEImgFileMgr.SetBSEImg(pBSEImage);
  622. pBSEImgFileMgr.SaveIntoBitmap(strBSEFilePathname);
  623. // ok, return TRUE
  624. return true;
  625. }
  626. // save a x-ray file for a field
  627. public bool SaveXRayFileForAField(List<CPosXrayClr> a_pFieldXray)
  628. {
  629. string strIncAFilename = m_strDBFileFolder + "\\" + DBFILE_NAME;
  630. // save x-ray file for the field
  631. CPosXrayDBMgr pPosXrayDBMgr = new CIncAFileMgr(strIncAFilename).GetPosXrayDBMgr();
  632. List<CPosXrayClr> listAnalysisXray = a_pFieldXray;
  633. if (!pPosXrayDBMgr.SaveXray(listAnalysisXray,true))
  634. {
  635. logger.Info("SaveXRayFileForAField: save analysis x-ray failed.");
  636. return false;
  637. }
  638. // ok, return TRUE
  639. return true;
  640. }
  641. // fields
  642. //public COTSFieldData GetFieldById(int a_nID)
  643. //{
  644. // List<COTSFieldData> listFieldData = m_pSample.GetFieldsData();
  645. // if (a_nID < 0 || a_nID > (int)listFieldData.Count)
  646. // {
  647. // return null;
  648. // }
  649. // COTSFieldData pFieldData = listFieldData[a_nID];
  650. // return pFieldData;
  651. //}
  652. //public void AddAField(COTSFieldData a_pFieldData)
  653. //{
  654. // m_pSample.AddFieldData(a_pFieldData);
  655. // return ;
  656. //}
  657. public void SetFieldData(List<COTSFieldData> a_listFieldData)
  658. {
  659. m_pSample.SetFieldsData(a_listFieldData);
  660. }
  661. //public bool DeleteAFieldById(int a_nID)
  662. //{
  663. // List<COTSFieldData> listFieldData = GetFieldData();
  664. // if (a_nID < 0 || a_nID > (int)listFieldData.Count)
  665. // {
  666. // return false;
  667. // }
  668. // //listFieldData.erase(listFieldData.begin() + a_nID);
  669. // for (int i = 0; i < a_nID; i++)
  670. // {
  671. // listFieldData.RemoveAt(0);
  672. // }
  673. // return true;
  674. //}
  675. // pathname
  676. public string GetPathFileName()
  677. {
  678. return m_strRstFileName;
  679. }
  680. public string GetDBPathName()
  681. {
  682. return m_strdbPathName;
  683. }
  684. public void SetPathFileName(string PathName)
  685. {
  686. m_strRstFileName = PathName;
  687. }
  688. // set sample
  689. // set SEM general data
  690. public void SetSEMGnr(CSEMDataGnr a_pSEMGnr)
  691. {
  692. //ASSERT(a_pSEMGnr);
  693. if (a_pSEMGnr == null)
  694. {
  695. logger.Info("input a invalid SEM general data pointer.");
  696. return;
  697. }
  698. m_pSEMData= a_pSEMGnr;
  699. }
  700. // get id for a new field
  701. // set SEMStageData
  702. // set SEMStage
  703. public void SetSEMStage(CStage a_pStage)
  704. {
  705. //ASSERT(a_pStage);
  706. if (a_pStage == null)
  707. {
  708. logger.Info("input a invalid stage pointer.");
  709. return;
  710. }
  711. m_pStage= a_pStage;
  712. }
  713. // according to a sample result file get a list of OTSFieldMgr
  714. //public List<COTSFieldData> GetOTSFldMgrListAndAnalysisXrayList()
  715. //{
  716. // //Get FieldDataList
  717. // List<COTSFieldData> listFieldData =GetFieldData();
  718. // int nFieldNum = (int)listFieldData.Count;
  719. // // get field number
  720. // foreach (COTSFieldData pFieldData in listFieldData)
  721. // {
  722. // string strIncAFilename = m_strDBFileFolder + "\\" + DBFILE_NAME;
  723. // CIncAFileMgr DBFile = new CIncAFileMgr(strIncAFilename);
  724. // COTSFieldData pFieldMgr = new COTSFieldData();
  725. // // get FieldData
  726. // //pFieldMgr.SetOTSFieldData(pFieldData);
  727. // List<COTSParticleClr> listParticle = pFieldData.ListAnalysisParticles;
  728. // if (listParticle == null)
  729. // {
  730. // logger.Info("GetOTSFieldMgrList: there is no particle in this field.");
  731. // continue;
  732. // }
  733. // // get BSE
  734. // string strFieldFileFolder = m_strFieldFileSubFolder;
  735. // int nId = pFieldData.GetId();
  736. // string sFieldId;
  737. // sFieldId = nId.ToString();
  738. // CBSEImageFileMgr cBSEImgFileMgr = new CBSEImageFileMgr();
  739. // string strBSEFilePathname = strFieldFileFolder + SMPL_MSR_RESULT_FIELDS_BSE + sFieldId + cBSEImgFileMgr.BMP_IMG_FILE_EXT;
  740. // CBSEImageFileMgr pBSEImgFile = new CBSEImageFileMgr();
  741. // if (!pBSEImgFile.LoadFromBitmap(strBSEFilePathname, true) == true)
  742. // {
  743. // logger.Error("GetOTSFieldMgrList: can't load BSE File.");
  744. // AddAField(pFieldMgr);
  745. // continue;
  746. // }
  747. // CBSEImgClr pBSEImg = pBSEImgFile.GetBSEImg();
  748. // pFieldMgr.SetBSEImage(pBSEImg);
  749. // // get analysis X-ray list
  750. // CPosXrayDBMgr pPosAnalysisXrayFileMgr = DBFile.GetPosXrayDBMgr();
  751. // pPosAnalysisXrayFileMgr.SetHasElement(true);
  752. // if (!pPosAnalysisXrayFileMgr.Load(pFieldData.GetId(), true))
  753. // {
  754. // AddAField(pFieldMgr);
  755. // continue;
  756. // }
  757. // List<CPosXrayClr> listAnalysisXray = pPosAnalysisXrayFileMgr.GetPosXrayList();
  758. // AddAField(pFieldMgr);
  759. // }
  760. // var flddata = GetFieldData();
  761. // return flddata;
  762. //}
  763. //----------------protected-----------------
  764. //protected bool GetID(COTSFieldData cOTSFieldData, int a_TypeId)
  765. //{
  766. // if (cOTSFieldData.GetId() == a_TypeId)
  767. // {
  768. // return true;
  769. // }
  770. // else
  771. // {
  772. // return false;
  773. // }
  774. //}
  775. }
  776. }