CSmplMsrResult.cs 33 KB

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