COTSMsrPrjResultData.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599
  1. using OTSDataType;
  2. using OTSModelSharp.ServiceCenter;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Windows.Forms;
  8. using static OTSDataType.otsdataconst;
  9. using System.Xml;
  10. using OTSCLRINTERFACE;
  11. using System.Data;
  12. namespace OTSModelSharp
  13. {
  14. public class COTSMsrPrjResultData
  15. {
  16. // SEM stage data
  17. CSEMStageData m_pSEMStageData;
  18. //// stage
  19. CStage m_pStage;
  20. // general parameter
  21. COTSGeneralParam m_GenParam;
  22. // sample list
  23. List<COTSSample> m_listSamples = new List<COTSSample>();
  24. List<CHoleBSEImg> m_listHoleBSEImg = new List<CHoleBSEImg>();
  25. bool m_bModify;
  26. // path name
  27. String m_strPathName;
  28. // working sample index
  29. int m_nWorkingSampeIndex;
  30. const String UNTITLED_FILE_NAME = "Untitled";
  31. const String SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER = "FIELD_FILES";
  32. // Inclusion file name
  33. const String SMPL_MSR_RESULT_INCLUSION_FILE = "Inclusion.db";//put all the table in one db file so that report can make join query.
  34. private otsdataconst.OTS_SysType_ID systemTypeId;
  35. public OTS_SysType_ID SystemTypeId { get => systemTypeId; set => systemTypeId = value; }
  36. public COTSMsrPrjResultData()
  37. {
  38. Init();
  39. }
  40. // initialization
  41. public void Init()
  42. {
  43. m_listSamples.Clear();
  44. m_listHoleBSEImg.Clear();
  45. m_bModify = false;
  46. m_strPathName = "";
  47. m_nWorkingSampeIndex = -1;
  48. }
  49. // duplication
  50. public void Duplicate(COTSMsrPrjResultData a_oSource)
  51. {
  52. // initialization
  53. Init();
  54. // copy data over
  55. m_pSEMStageData = new CSEMStageData(a_oSource.m_pSEMStageData);
  56. m_pStage = new CStage(a_oSource.m_pStage);
  57. foreach (var pHoleBSEImg in a_oSource.m_listHoleBSEImg)
  58. {
  59. CHoleBSEImg pHoleBSEImgNew = (new CHoleBSEImg(pHoleBSEImg));
  60. m_listHoleBSEImg.Add(pHoleBSEImgNew);
  61. }
  62. foreach (var pSample in a_oSource.m_listSamples)
  63. {
  64. COTSSample pSampleNew = new COTSSample();
  65. m_listSamples.Add(pSampleNew);
  66. }
  67. m_bModify = a_oSource.m_bModify;
  68. m_strPathName = a_oSource.m_strPathName;
  69. m_nWorkingSampeIndex = a_oSource.m_nWorkingSampeIndex;
  70. }
  71. public void SetPathName(String a_strPathName) { m_strPathName = a_strPathName; }
  72. public bool Load(string strPathName)
  73. {
  74. Cleanup();
  75. // check if the file exist
  76. if (!FileExists(strPathName))
  77. {
  78. // shouldn't happen, file does not exist
  79. return false;
  80. }
  81. //获取测量项目文件
  82. XmlDocument doc = new XmlDocument();
  83. //载入xml文件
  84. doc.Load(strPathName);
  85. XmlNode root = doc.SelectSingleNode("XMLData");
  86. Serialize(false, doc, root);
  87. //设置测量项目文件路径
  88. m_strPathName = strPathName;
  89. //-------------
  90. foreach (var smpl in m_listSamples)
  91. {
  92. // get path of the pathname
  93. String strFilePath = GetFolderName(strPathName);
  94. if (strFilePath == "")
  95. {
  96. // file path string is an empty string
  97. return false;
  98. }
  99. // field file sub folder string
  100. String strFieldFileSubFolder = strFilePath + "\\" + smpl.GetName() + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
  101. // check if the field file sub folder exists
  102. if (!DirectoryExists(strFieldFileSubFolder))
  103. {// field files folder doesn't exist
  104. continue;
  105. }
  106. String strIncAFilename = strFieldFileSubFolder + "\\" + SMPL_MSR_RESULT_INCLUSION_FILE;
  107. //CIncAFileMgr pIncAFileMgr = new CIncAFileMgr(strIncAFilename);
  108. List<COTSField> allMeasuredFlds = new List<COTSField>();
  109. CMsrSampleStatus poMsrStatus = new CMsrSampleStatus();
  110. CMsrResultItems poMsrResults = smpl.GetMsrResults();
  111. double aFldArea = smpl.CalculateAFieldArea();
  112. SetPathName(strIncAFilename);
  113. int w, h;
  114. smpl.GetBSESize(out w, out h);
  115. double pixelsize = smpl.CalculatePixelSize();
  116. if (GetAllFieldsFromDB(ref allMeasuredFlds,ref poMsrStatus, poMsrResults, aFldArea,new Size(w,h),pixelsize))
  117. {
  118. var nodataFields = smpl.GetFieldsData();//there's only the field postion info in the xml file,so the initial filed has only postion info.
  119. List<COTSField> allflddata = new List<COTSField>() ;//contains all the field
  120. //------------complete the infomation that doesn't contained in database-----
  121. foreach (var f in allMeasuredFlds)
  122. {
  123. f.SetPixelSize(pixelsize);
  124. f.Width = w;
  125. f.Height = h;
  126. f.SetIsMeasureComplete(true);
  127. }
  128. //------------------------------
  129. foreach (var emptyfld in nodataFields)
  130. {
  131. bool isMeasured = false;
  132. foreach (var measuredField in allMeasuredFlds)
  133. {
  134. if (measuredField.PositionEquals(emptyfld))
  135. {
  136. allflddata.Add(measuredField);
  137. isMeasured = true;
  138. break;
  139. }
  140. }
  141. if (!isMeasured)
  142. {
  143. allflddata.Add(emptyfld);
  144. }
  145. }
  146. smpl.SetFieldsData(allflddata);
  147. // file validation
  148. smpl.SetMsrStatus(poMsrStatus);
  149. smpl.SetMsrResults(poMsrResults);
  150. // set pathname
  151. SetPathName(strPathName);
  152. // set working sample
  153. if (m_listSamples.Count > 0)
  154. {
  155. m_nWorkingSampeIndex = 0;
  156. }
  157. else
  158. {
  159. m_nWorkingSampeIndex = -1;
  160. }
  161. }
  162. else
  163. {
  164. return false;
  165. }
  166. }
  167. if (m_listSamples != null)
  168. {
  169. if (m_listSamples.Count > 0)
  170. {
  171. m_nWorkingSampeIndex = 0;
  172. }
  173. }
  174. //-----------------------------------------
  175. return true;
  176. }
  177. // gets the name of the folder
  178. public String GetFolderName(String a_strPathName)
  179. {
  180. string str = "";
  181. str = Path.GetDirectoryName(a_strPathName);
  182. return str.ToString();
  183. }
  184. public bool FileExists(string a_sPath)
  185. {
  186. bool b_IsExists = File.Exists(a_sPath);
  187. return b_IsExists;
  188. }
  189. public bool DirectoryExists(string a_sPath)
  190. {
  191. bool b_IsExists = Directory.Exists(a_sPath);
  192. return b_IsExists;
  193. }
  194. // cleanup
  195. public void Cleanup()
  196. {
  197. m_listHoleBSEImg.Clear();
  198. m_listSamples.Clear();
  199. m_bModify = false;
  200. m_strPathName = "";
  201. m_nWorkingSampeIndex = -1;
  202. }
  203. // set modify flag
  204. public void SetModify(bool a_bModify = true) { m_bModify = a_bModify; }
  205. // file pathname
  206. public String GetPathName() { return m_strPathName; }
  207. public bool GetAllFieldsFromDB(ref List<COTSField> allFlds, ref CMsrSampleStatus status, CMsrResultItems rst, double aFieldArea,Size picSize,double pixelSize)
  208. {
  209. String sDatabaseName = m_strPathName;
  210. if (!FileExists(sDatabaseName))
  211. {
  212. return false;
  213. }
  214. List<System.Drawing.PointF> completedFldPositions = new List<System.Drawing.PointF>();
  215. CIncAFileMgr incAFileMgr = new CIncAFileMgr(sDatabaseName);
  216. var m_IncADataDB = incAFileMgr.GetIncADB();
  217. List<COTSField> allFldsWithdata=new List<COTSField>();
  218. m_IncADataDB.GetAllFieldsRecord(new Size(picSize.Width,picSize.Height),pixelSize,ref allFldsWithdata);
  219. //foreach (var f in allFldsWithdata)
  220. //{
  221. // f.Width = picSize.Width;
  222. // f.Height = picSize.Height;
  223. // f.SetPixelSize(pixelSize);
  224. //}
  225. var eleChemistryDB = incAFileMgr.GetPosXrayDBMgr().GetElementChemistryDB();
  226. Dictionary<string, CPosXrayClr> mapXrayInfo=new Dictionary<string, CPosXrayClr>();
  227. eleChemistryDB.GetAllMapedXrayInfo(ref mapXrayInfo);
  228. foreach (var f in allFldsWithdata)
  229. {
  230. foreach (var p in f.GetListAnalysisParticles())
  231. {
  232. int curFldId = f.GetId();
  233. int xrayId = p.GetAnalysisId();
  234. string fldvec="";
  235. fldvec+=curFldId.ToString();
  236. fldvec+="_";
  237. fldvec += xrayId.ToString();
  238. if (mapXrayInfo.ContainsKey(fldvec))
  239. {
  240. var xray = mapXrayInfo[fldvec];
  241. p.SetXray(xray);
  242. }
  243. }
  244. }
  245. var xrayDataDBDB = incAFileMgr.GetPosXrayDBMgr().GetXrayDataDB();
  246. Dictionary<string, CPosXrayClr> mapXrayData=new Dictionary<string, CPosXrayClr>();// map structure:[(fieldId,xrayId),CPosXrayPtr],every element of this map represent one unique xraydata.
  247. xrayDataDBDB.GetAllMapedXrayData(ref mapXrayData);
  248. foreach (var f in allFldsWithdata)
  249. {
  250. foreach (var p in f.GetListAnalysisParticles())
  251. {
  252. int curFldId = f.GetId();
  253. int xrayId = p.GetAnalysisId();
  254. string fldvec="";
  255. fldvec+=curFldId.ToString();
  256. fldvec += "_";
  257. fldvec += xrayId.ToString();
  258. if (mapXrayData.ContainsKey(fldvec))
  259. {
  260. var xray = mapXrayData[fldvec];
  261. CPosXrayClr t2 = p.GetXray();
  262. if (t2 == null)
  263. {
  264. t2 =new CPosXrayClr();
  265. p.SetXray(t2);
  266. }
  267. t2.SetXrayData(xray.GetXrayData());
  268. }
  269. }
  270. }
  271. CSegmentDB SegmentDB = incAFileMgr.GetSegmentDB();
  272. double msrFldsArea = 0;
  273. Dictionary<int, List<COTSParticleClr>> mapTypeParticles = new Dictionary<int,List<COTSParticleClr>>();//record typeId relevants particlelist;
  274. List<COTSSegmentClr> AllSegments ;
  275. Dictionary<string, List<COTSSegmentClr>> mapSegments = new Dictionary<string, List<COTSSegmentClr>>();
  276. if (SegmentDB.GetAllSegmentsRecord(mapSegments))
  277. {
  278. foreach (var fld in allFldsWithdata)
  279. {
  280. int fldId = fld.GetId();
  281. List<COTSParticleClr> parts = fld.GetListAnalysisParticles();
  282. foreach (var part in parts)
  283. {
  284. string fldvec = "";
  285. fldvec+=fldId.ToString();
  286. fldvec += "_";
  287. fldvec+=part.GetParticleId().ToString();
  288. if (mapSegments.ContainsKey(fldvec))
  289. {
  290. COTSFeatureClr f = new COTSFeatureClr();
  291. AllSegments = mapSegments[fldvec];
  292. f.SetSegmentsList(AllSegments, true);
  293. part.SetFeature(f);
  294. if (mapTypeParticles.ContainsKey(part.GetType()))
  295. {
  296. mapTypeParticles[part.GetType()].Add(part);
  297. }
  298. else
  299. {
  300. List<COTSParticleClr> ps = new List<COTSParticleClr>();
  301. ps.Add(part);
  302. mapTypeParticles.Add(part.GetType(), ps);
  303. }
  304. }
  305. msrFldsArea += aFieldArea;
  306. }
  307. }
  308. }
  309. var fielddb = incAFileMgr.GetFieldDB();
  310. var fielddata = fielddb.GetTableQueryForDataTable();
  311. foreach (DataRow r in fielddata.Rows)
  312. {
  313. var p = new Point(Convert.ToInt32(r[(int)CFieldTable.ColumnID.N_FIELDPOS_X]), Convert.ToInt32(r[(int)CFieldTable.ColumnID.N_FIELDPOS_Y]));
  314. completedFldPositions.Add(p);
  315. }
  316. status.SetCompletedFieldsCenter(completedFldPositions);
  317. //add the empty field(there's no any particle in the bse image,so the field empty)
  318. foreach (var p in completedFldPositions)
  319. {
  320. bool haveData=false;
  321. var emptyFld = new COTSField(p,pixelSize);
  322. emptyFld.SetOTSPosition(p);
  323. foreach (var fld in allFldsWithdata)
  324. {
  325. if (fld.PositionEquals(emptyFld))
  326. {
  327. haveData = true;
  328. allFlds.Add(fld);
  329. break;
  330. }
  331. }
  332. if (!haveData)
  333. {
  334. allFlds.Add(emptyFld);
  335. }
  336. }
  337. // get MsrStatus info from DB.
  338. var m_GenInfoDB = incAFileMgr.GetGeneralInfoDB();//DBStoreFile类
  339. String strTimeStart = "";
  340. String strTimeEnd = "";
  341. String strRstStatus = "";
  342. m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameTimeStart(), ref strTimeStart);
  343. m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameTimeEnd(), ref strTimeEnd);
  344. m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameResultStatus(), ref strRstStatus);
  345. DateTime timeStart, timeEnd;
  346. try
  347. {
  348. timeStart = Convert.ToDateTime(ConvertFormatOfDateString(strTimeStart)); //此处为兼容之前得测量得结果可以打开,故在此进行数据格式变换
  349. timeEnd = Convert.ToDateTime(ConvertFormatOfDateString(strTimeEnd));
  350. }
  351. catch
  352. {
  353. timeStart = Convert.ToDateTime(strTimeStart); //此处为兼容之前得测量得结果可以打开,故在此进行数据格式变换
  354. timeEnd = Convert.ToDateTime(strTimeEnd);
  355. }
  356. status.SetStartTime(timeStart);
  357. status.SetEndTime(timeEnd);
  358. status.SetUsedTime(timeEnd - timeStart);
  359. status.SetStatus((OTS_MSR_SAMPLE_STATUS)Convert.ToInt32(strRstStatus));
  360. //get MsrResults data from map.
  361. List<CMsrResultItem> rstItms = new List<CMsrResultItem>();
  362. double allPartArea = 0;
  363. int typeNum = 0;
  364. double typeArea = 0;
  365. foreach (var typeParticles in mapTypeParticles)
  366. {
  367. CMsrResultItem rstItm = new CMsrResultItem();
  368. foreach (var p in typeParticles.Value)
  369. {
  370. typeNum += 1;
  371. typeArea +=p.GetActualArea();
  372. }
  373. rstItm.SetTypeId(typeParticles.Key);
  374. rstItm.SetNumber((uint)typeNum);
  375. rstItm.SetArea((uint)typeArea);
  376. rstItm.SetName(typeParticles.Value[0].GetTypeName());
  377. rstItms.Add(rstItm);
  378. allPartArea += typeArea;
  379. }
  380. rst.SetResultItems(rstItms);
  381. rst.SetMeasuredArea(Convert.ToUInt64(msrFldsArea * 1000000));
  382. rst.SetRatio(allPartArea / (msrFldsArea * 1000000));
  383. return true;
  384. //return false;
  385. }
  386. string ConvertFormatOfDateString(string Time)
  387. {
  388. string[] str1 = Time.Split(' ');
  389. string[] str2 = str1[0].Split('/');
  390. return str2[2] + "/" + str2[1] + "/" + str2[0] +" "+ str1[1];
  391. }
  392. public string GetSampleWorkingFolder(string sampleName)
  393. {
  394. var pathname = FileHelper.GetFolderName(GetPathName());
  395. var samplePathName = pathname + "\\" + sampleName + "\\";
  396. return samplePathName;
  397. }
  398. public bool Save()
  399. {
  400. // Save or Save As, if strPathName is not empty, it is exist in the computer, this is a save action
  401. String strPathName = GetPathName();
  402. if (strPathName.CompareTo(UNTITLED_FILE_NAME) == 0)
  403. {
  404. // this is a new file
  405. // return save as result
  406. return SaveAs();
  407. }
  408. // is this a new file?
  409. strPathName.Trim();
  410. //保存测量项目文件 .prj
  411. XmlDocument doc = new XmlDocument();
  412. doc.Load(strPathName);
  413. doc.RemoveAll();
  414. //添加xml文件头申明
  415. XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
  416. doc.AppendChild(xmldecl);
  417. XmlElement rootNode = doc.CreateElement("XMLData");
  418. doc.AppendChild(rootNode);
  419. Serialize(true, doc, rootNode);
  420. try
  421. {
  422. doc.Save(strPathName);
  423. }
  424. catch
  425. {
  426. return false;
  427. }
  428. // set file modify flag
  429. SetModify(false);
  430. // Ok, return TRUE
  431. return true;
  432. }
  433. public bool SaveAs()
  434. {
  435. // get file name
  436. String strPathName = "";
  437. // file open dialog
  438. SaveFileDialog saveFileDialog = new SaveFileDialog();
  439. saveFileDialog.FileName = m_strPathName.Split('\\')[m_strPathName.Split('\\').Length - 1];
  440. saveFileDialog.Filter = "Directory (*.*)|*.*";
  441. saveFileDialog.AddExtension=false;
  442. if (saveFileDialog.ShowDialog() != DialogResult.OK)
  443. {
  444. return false;
  445. }
  446. // get file pathname
  447. strPathName = saveFileDialog.FileName;
  448. string DirectoryName = Path.GetDirectoryName(strPathName);
  449. try
  450. {
  451. Directory.CreateDirectory(strPathName);
  452. }
  453. catch
  454. {
  455. MessageBox.Show("CreateDirectoryFailed!");
  456. return false;
  457. }
  458. strPathName += "\\"+Path.GetFileNameWithoutExtension(strPathName) + ".prj";
  459. //保存测量项目文件 .prj
  460. XmlDocument doc = new XmlDocument();
  461. //添加xml文件头申明
  462. XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
  463. doc.AppendChild(xmldecl);
  464. XmlElement rootNode = doc.CreateElement("XMLData");
  465. doc.AppendChild(rootNode);
  466. Serialize(true, doc, rootNode);
  467. try
  468. {
  469. doc.Save(strPathName);
  470. }
  471. catch
  472. {
  473. return false;
  474. }
  475. // set file modify flag
  476. m_bModify = false;
  477. // Set project Path
  478. SetPathName(strPathName);
  479. // Ok, return TRUE
  480. return true;
  481. }
  482. // SEM stage data
  483. public CSEMStageData GetSEMStageData() { return m_pSEMStageData; }
  484. // SEM stage data
  485. public void SetSEMStageData(CSEMStageData a_pCSEMStageData)
  486. {
  487. m_pSEMStageData = a_pCSEMStageData;
  488. }
  489. // stage
  490. public CStage GetStage() { return m_pStage; }
  491. public void SetStage(CStage a_pStage)
  492. {
  493. m_pStage = new CStage(a_pStage);
  494. }
  495. // samples list
  496. public List<COTSSample> GetSampleList() { return m_listSamples; }
  497. public COTSSample GetSampleByIndex(int a_nIndex)
  498. {
  499. // safe check
  500. if (a_nIndex < 0 || a_nIndex >= (int)m_listSamples.Count)
  501. {
  502. // invalid sample id
  503. return null;
  504. }
  505. // get the matching sample
  506. COTSSample pSample = m_listSamples[a_nIndex];
  507. // return the sample
  508. return pSample;
  509. }
  510. public COTSSample GetSampleByName(String a_strSampleName)
  511. {
  512. bool Isfind = false;
  513. COTSSample pOTSSample = null;
  514. for (int itr = 0; itr < m_listSamples.Count; itr++)
  515. {
  516. if (m_listSamples[itr].GetName() == a_strSampleName)
  517. {
  518. pOTSSample = m_listSamples[itr];
  519. //m_listSamples.RemoveAt(itr);
  520. Isfind = true;
  521. }
  522. }
  523. if (Isfind)
  524. {
  525. return pOTSSample;
  526. }
  527. return m_listSamples[0];
  528. }
  529. public void AddSample(COTSSample pSample)
  530. {
  531. // add the new sample into the samples list
  532. m_listSamples.Add(pSample);
  533. // set the project file modified.
  534. SetModify();
  535. // set the new as working sample
  536. m_nWorkingSampeIndex = (int)m_listSamples.Count - 1;
  537. // return the new sample
  538. }
  539. // get new sample name
  540. public bool DeleteSampleByIndex(int a_nIndex)
  541. {
  542. // check the index
  543. if (a_nIndex < 0 || a_nIndex >= (int)m_listSamples.Count)
  544. {
  545. // invalid input sample index
  546. return true;
  547. }
  548. // calculate new working sample index
  549. int nNewWorkingSampeIndex;
  550. if (a_nIndex < m_nWorkingSampeIndex)
  551. {
  552. nNewWorkingSampeIndex = m_nWorkingSampeIndex - 1;
  553. }
  554. else if (a_nIndex > m_nWorkingSampeIndex)
  555. {
  556. nNewWorkingSampeIndex = m_nWorkingSampeIndex;
  557. }
  558. else
  559. {
  560. // deleting working sample.
  561. if (a_nIndex == (int)m_listSamples.Count - 1)
  562. {
  563. // this is the last sample, select the above sample as working sample
  564. // if this is only sample in the list working sample index will be -1;
  565. nNewWorkingSampeIndex = m_nWorkingSampeIndex - 1;
  566. }
  567. else
  568. {
  569. // select next sample as working sample
  570. nNewWorkingSampeIndex = m_nWorkingSampeIndex;
  571. }
  572. }
  573. // delete the sample
  574. for (int i = m_listSamples.Count - 1; i >= 0; i--)
  575. {
  576. if (i == a_nIndex)
  577. {
  578. var sam = m_listSamples[i];
  579. sam.GetMsrStatus().ClearCompletedFieldsInfo();
  580. sam.GetMsrStatus().ClearCompletedFieldsInfo();
  581. sam.ClearFields();
  582. sam.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.UNMEASURED);
  583. m_listSamples.Remove(m_listSamples[i]);
  584. break;
  585. }
  586. }
  587. // the file is modified.
  588. SetModify();
  589. // reset working sample index
  590. m_nWorkingSampeIndex = nNewWorkingSampeIndex;
  591. // ok, return TRUE
  592. return true;
  593. }
  594. public bool ChangeParamFromList(int iNamePos)
  595. {
  596. throw new NotImplementedException();
  597. }
  598. public bool GetParamFileList(ref int iNamePos, ref List<string> mParamFileNameList)
  599. {
  600. throw new NotImplementedException();
  601. }
  602. public bool DeleteSampleByName(String a_strSampleName)
  603. {
  604. // check input sample name
  605. a_strSampleName.Trim();
  606. if (a_strSampleName == "")
  607. {
  608. // input sample name is empty
  609. return false;
  610. }
  611. // go through sample list
  612. int nIndex = 0;
  613. foreach (var pSample in m_listSamples)
  614. {
  615. // return TRUE if this is not an exclude sample and its name is same with input
  616. String strSampleName = pSample.GetName();
  617. if (strSampleName.CompareTo(a_strSampleName) == 0)
  618. {
  619. // find the sample, return deleting result
  620. return DeleteSampleByIndex(nIndex);
  621. }
  622. ++nIndex;
  623. }
  624. // can't find the sample in the samples list, return FALSE
  625. return false;
  626. }
  627. public bool ResetSamplesListOrder(List<String> a_listSampleNames)
  628. {
  629. // no sample in the samples list; shouldn't be here
  630. if (m_listSamples.Count == 0)
  631. {
  632. return false;
  633. }
  634. // make sure that input sample names list size is same with the samples list
  635. if (m_listSamples.Count != a_listSampleNames.Count)
  636. {
  637. return false;
  638. }
  639. // new sample list
  640. List<COTSSample> listSamples = new List<COTSSample>();
  641. // go through the sample names list
  642. foreach (var strSampleName in a_listSampleNames)
  643. {
  644. bool IsChanged = false;
  645. for (int itr = 0; itr < m_listSamples.Count; itr++)
  646. {
  647. if (m_listSamples[itr].GetName() == strSampleName)
  648. {
  649. COTSSample pElementChemistry = m_listSamples[itr];
  650. IsChanged = true;
  651. }
  652. }
  653. if (!IsChanged)
  654. {
  655. return false;
  656. }
  657. }
  658. // reset the samples list
  659. m_listSamples.Clear();
  660. foreach (var pSample in listSamples)
  661. {
  662. m_listSamples.Add(pSample);
  663. }
  664. // set modify flag
  665. SetModify();
  666. // Ok, return TRUE
  667. return true;
  668. }
  669. public bool InsrtSample(COTSSample a_pSample, int a_nIndex)
  670. {
  671. // input check
  672. if (a_pSample != null)
  673. {
  674. // invalid input sample pointer
  675. return false;
  676. }
  677. if (m_listSamples.Count == 0 || a_nIndex >= (int)m_listSamples.Count)
  678. {
  679. m_listSamples.Add(a_pSample);
  680. }
  681. else if (a_nIndex <= 0)
  682. {
  683. m_listSamples.Insert(Convert.ToInt32(m_listSamples[a_nIndex]), a_pSample);
  684. }
  685. else
  686. {
  687. m_listSamples.Insert(Convert.ToInt32(m_listSamples[a_nIndex]) + a_nIndex, a_pSample);
  688. }
  689. // Ok, return TRUE
  690. return true;
  691. }
  692. public bool ChangeSamplePosition(int a_nIndexFrom, int a_nIndexTo)
  693. {
  694. // make sure both index are valid
  695. if (a_nIndexFrom < 0 || a_nIndexFrom >= (int)m_listSamples.Count)
  696. {
  697. // invalid from index
  698. return false;
  699. }
  700. if (a_nIndexTo < 0 || a_nIndexTo >= (int)m_listSamples.Count)
  701. {
  702. // invalid to index
  703. return false;
  704. }
  705. // need to do nothing if the two indexes are the same
  706. if (a_nIndexFrom != a_nIndexTo)
  707. {
  708. // move to last?
  709. bool bLast = (a_nIndexTo == ((int)m_listSamples.Count - 1));
  710. // get the sample
  711. COTSSample pSample = m_listSamples[a_nIndexFrom];
  712. // remove it from the samples list
  713. m_listSamples.Remove(pSample);
  714. // put the sample back in
  715. if (bLast)
  716. {
  717. m_listSamples.Add(pSample);
  718. }
  719. else
  720. {
  721. m_listSamples.Insert(Convert.ToInt32(m_listSamples[a_nIndexTo]) + a_nIndexTo, pSample);
  722. }
  723. }
  724. // Ok, return TRUE
  725. return true;
  726. }
  727. public bool MoveSamplePosition(COTSSample a_pTargetSample, COTSSample a_RefpSample, bool a_bBefore /*= TRUE*/)
  728. {
  729. // check input
  730. if (a_pTargetSample != null)
  731. {
  732. // invalid input target sample pointer
  733. return false;
  734. }
  735. if (a_RefpSample != null)
  736. {
  737. // invalid input ref sample pointer
  738. return false;
  739. }
  740. bool IsChanged = false;
  741. for (int itr = 0; itr < m_listSamples.Count; itr++)
  742. {
  743. if (m_listSamples[itr].GetName() == a_pTargetSample.GetName())
  744. {
  745. COTSSample pElementChemistry = m_listSamples[itr];
  746. // m_listSamples.RemoveAt(itr);
  747. IsChanged = true;
  748. }
  749. }
  750. if (!IsChanged)
  751. {
  752. return false;
  753. }
  754. for (int itr = 0; itr < m_listSamples.Count; itr++)
  755. {
  756. if (m_listSamples[itr].GetName() == a_RefpSample.GetName())
  757. {
  758. COTSSample pElementChemistry = m_listSamples[itr];
  759. //m_listSamples.RemoveAt(itr);
  760. IsChanged = true;
  761. }
  762. }
  763. if (!IsChanged)
  764. {
  765. return false;
  766. }
  767. // remove the sample from the samples list
  768. for (int itr = 0; itr < m_listSamples.Count; itr++)
  769. {
  770. if (m_listSamples[itr].GetName() == a_RefpSample.GetName())
  771. {
  772. COTSSample pElementChemistry = m_listSamples[itr];
  773. //m_listSamples.RemoveAt(itr);
  774. IsChanged = true;
  775. }
  776. }
  777. if (!IsChanged)
  778. {
  779. return false;
  780. }
  781. // put the sample back in
  782. if (a_bBefore)
  783. {
  784. m_listSamples.Insert(0, a_pTargetSample);
  785. }
  786. else
  787. {
  788. m_listSamples.Insert(1, a_pTargetSample);
  789. }
  790. // Ok, return TRUE
  791. return true;
  792. }
  793. public bool MoveSamplePosition(String a_strTargetSampleName, String a_strRefSampleName, bool a_bBefore /*= TRUE*/)
  794. {
  795. // input check
  796. a_strTargetSampleName.Trim();
  797. if (a_strTargetSampleName == "")
  798. {
  799. // input target sample is an empty string
  800. return false;
  801. }
  802. a_strRefSampleName.Trim();
  803. if (a_strRefSampleName == "")
  804. {
  805. // input ref sample is an empty string
  806. return false;
  807. }
  808. bool IsChanged = false;
  809. for (int itr = 0; itr < m_listSamples.Count; itr++)
  810. {
  811. if (m_listSamples[itr].GetName() == a_strTargetSampleName)
  812. {
  813. COTSSample pElementChemistry = m_listSamples[itr];
  814. IsChanged = true;
  815. }
  816. }
  817. if (!IsChanged)
  818. {
  819. return false;
  820. }
  821. COTSSample pTargetSample = m_listSamples[0];
  822. for (int itr = 0; itr < m_listSamples.Count; itr++)
  823. {
  824. if (m_listSamples[itr].GetName() == a_strTargetSampleName)
  825. {
  826. COTSSample pElementChemistry = m_listSamples[itr];
  827. IsChanged = true;
  828. }
  829. }
  830. if (!IsChanged)
  831. {
  832. return false;
  833. }
  834. COTSSample pRefSample = pTargetSample;
  835. // need to do nothing if the two name are same
  836. if (a_strTargetSampleName.CompareTo(a_strRefSampleName) != 0)
  837. {
  838. return MoveSamplePosition(pTargetSample, pRefSample, a_bBefore);
  839. }
  840. // Ok, return TRUE
  841. return true;
  842. }
  843. public COTSSample GetWorkingSample()
  844. {
  845. return GetSampleByIndex(m_nWorkingSampeIndex);
  846. }
  847. public bool SetWorkingSampleByIndex(int a_nIndex)
  848. {
  849. // special treatment
  850. if (a_nIndex == -1 && m_listSamples.Count == 0)
  851. {
  852. m_nWorkingSampeIndex = -1;
  853. return true;
  854. }
  855. // check if the working sample index
  856. if (0 > a_nIndex || a_nIndex >= (int)m_listSamples.Count)
  857. {
  858. // invalid sample index
  859. return false;
  860. }
  861. m_nWorkingSampeIndex = a_nIndex;
  862. return true;
  863. }
  864. public bool SetWorkingSampleByName(String a_pSampleName)
  865. {
  866. // check input sample name
  867. a_pSampleName.Trim();
  868. if (a_pSampleName == "")
  869. {
  870. // input sample name is empty
  871. return false;
  872. }
  873. // go through sample list
  874. int nIndex = 0;
  875. foreach (var pSample in m_listSamples)
  876. {
  877. // return TRUE if this is not an exclude sample and its name is same with input
  878. String strSampleName = pSample.GetName();
  879. if (strSampleName.CompareTo(a_pSampleName) == 0)
  880. {
  881. // find the sample, return deleting result
  882. return SetWorkingSampleByIndex(nIndex);
  883. }
  884. ++nIndex;
  885. }
  886. // failed to find the named sample
  887. // failed to find the named sample return FALSE
  888. return false;
  889. }
  890. public bool DeleteWorkingSample()
  891. {
  892. // check if the working sample index
  893. if (m_nWorkingSampeIndex < 0 || m_nWorkingSampeIndex >= (int)m_listSamples.Count)
  894. {
  895. // invalid working sample index
  896. return false;
  897. }
  898. // return the result of DeleteSampleByIndex
  899. return DeleteSampleByIndex(m_nWorkingSampeIndex);
  900. }
  901. // Sample hole BSE image list
  902. public List<CHoleBSEImg> GetHoleBESImgList() { return m_listHoleBSEImg; }
  903. // hole BSE images list
  904. public void SetHoleBESImgList(List<CHoleBSEImg> a_listHoleBSEImg, bool a_bClear/* = TRUE*/)
  905. {
  906. // clear the hole BSE image list if necessary
  907. if (a_bClear)
  908. {
  909. m_listHoleBSEImg.Clear();
  910. }
  911. m_listHoleBSEImg = a_listHoleBSEImg;
  912. }
  913. // get modify flag
  914. public bool IsModified() { return m_bModify; }
  915. // file name
  916. public String GetFileName()
  917. {
  918. // make a copy of file path name
  919. String strPathName = m_strPathName;
  920. // is this a new file?
  921. if (strPathName.CompareTo(UNTITLED_FILE_NAME) == 0)
  922. {
  923. return strPathName;
  924. }
  925. // get file name
  926. String strFileName = GetFileNameWithoutExtension(strPathName);
  927. // return file name
  928. return strFileName;
  929. }
  930. // get file name without extension
  931. public String GetFileNameWithoutExtension(String a_strPathName)
  932. {
  933. string str = "";
  934. str = Path.GetFileNameWithoutExtension(a_strPathName);
  935. return str;
  936. }
  937. // if the new sample name can be used.
  938. public bool IsValidSampleName(String a_sName)
  939. {
  940. foreach (var pSample in m_listSamples)
  941. {
  942. String sSampleName = pSample.GetName();
  943. if (a_sName.Equals(sSampleName))
  944. {
  945. return false;
  946. }
  947. }
  948. return true;
  949. }
  950. static String FindFile(String filename, String path)
  951. {
  952. if (Directory.Exists(path))
  953. {
  954. if (File.Exists(path + filename))
  955. return path + filename;
  956. String[] directorys = Directory.GetDirectories(path);
  957. foreach (String d in directorys)
  958. {
  959. String p = FindFile(filename, d);
  960. if (p != null)
  961. return p;
  962. }
  963. }
  964. return null;
  965. }
  966. // get measured sample list
  967. public bool GetMsredSampleList(ref List<COTSSample> a_listMsredSample)
  968. {
  969. a_listMsredSample.Clear();
  970. foreach (var pSample in m_listSamples)
  971. {
  972. if (pSample.GetMsrResults() == new CMsrResultItems())
  973. {
  974. continue;
  975. }
  976. else
  977. {
  978. a_listMsredSample.Add(pSample);//the reference count will increament automatically.
  979. }
  980. }
  981. return true;
  982. }
  983. // calculate measurement area
  984. public CDomain CalculateMsrArea(CHole a_pHole)
  985. {
  986. CDomain pMsrArea = new CDomain(a_pHole.GetShape(), a_pHole.GetDomainRect());
  987. // create measurement area
  988. // reset measurement area
  989. // measurement area should smaller than the sample hole
  990. RectangleF rectMsrArea = pMsrArea.GetDomainRect();
  991. float nWidth = rectMsrArea.Width;
  992. float nHeight = rectMsrArea.Height;
  993. float nDeflateX = CalculateDeflateValue(nWidth);
  994. float nDeflateY = CalculateDeflateValue(nHeight);
  995. rectMsrArea.Offset(nDeflateX, nDeflateY);
  996. pMsrArea.SetDomainRect(rectMsrArea);
  997. // return measurement area
  998. return pMsrArea;
  999. }
  1000. // calculate deflate value
  1001. public float CalculateDeflateValue(float a_nWitchOrHeight)
  1002. {
  1003. const long LENGTH_THRESHOLD = 150000;
  1004. const long LENGTH_THRESHOLD_MIN = 10000;
  1005. const int EDGE = 1000;
  1006. const int EDGE_MIN = 500;
  1007. // deflate 1000 if width or height is greater than 15000
  1008. if (a_nWitchOrHeight >= LENGTH_THRESHOLD)
  1009. {
  1010. return EDGE;
  1011. }
  1012. // deflate 500 if width or height is greater than 15000
  1013. else if (a_nWitchOrHeight >= LENGTH_THRESHOLD_MIN)
  1014. {
  1015. return EDGE_MIN;
  1016. }
  1017. // otherwise, no deflate
  1018. return 0;
  1019. }
  1020. //合并后新添加的需要的方法
  1021. public void SetGenParam(COTSGeneralParam GenParam) { m_GenParam = GenParam; }
  1022. public COTSGeneralParam GetGenParam() { return m_GenParam; }
  1023. public bool Reclassify()
  1024. {
  1025. string strFilePath = FileHelper.GetFolderName(m_strPathName);
  1026. if(strFilePath==null)
  1027. {
  1028. return false;
  1029. }
  1030. foreach (var spl in m_listSamples)
  1031. {
  1032. //get the parameter MsrParam object
  1033. CSampleParam pMsrParam = spl.GetMsrParams();
  1034. string stdFileName = pMsrParam.GetSTDName();
  1035. if (!stdFileName.Contains(".db"))
  1036. {
  1037. stdFileName += ".db";
  1038. }
  1039. string filename = strFilePath + "\\" + spl.GetName() + "\\" + spl.GetName() + ".rst";
  1040. XmlDocument doc=new XmlDocument();
  1041. doc.Load(filename);
  1042. XmlNode root = doc.SelectSingleNode("XMLData");
  1043. var members = root.SelectNodes("Member");
  1044. foreach (XmlNode member1 in members)
  1045. {
  1046. if(member1.Attributes["RegName"].Value== "Sample")
  1047. {
  1048. var paramNode = member1.SelectNodes("Member");
  1049. foreach (XmlNode member2 in paramNode)
  1050. {
  1051. if(member2.Attributes["RegName"].Value == "MsrParams")
  1052. {
  1053. ((XmlElement)member2).SetAttribute("STDName", stdFileName);
  1054. }
  1055. }
  1056. }
  1057. }
  1058. doc.Save(filename);
  1059. foreach (var fld in spl.GetFieldsData())
  1060. {
  1061. foreach (var part in fld.GetListAnalysisParticles())
  1062. {
  1063. part.SetType((int)OTS_PARTICLE_TYPE.NOT_IDENTIFIED);
  1064. part.SetTypeName("Not Identified");
  1065. part.SetTypeColor("#000000");
  1066. }
  1067. }
  1068. var analysisparts = new List<COTSParticleClr>();
  1069. var m_classifyEngine = new CClassifyEngine();
  1070. if (SystemTypeId == OTS_SysType_ID.IncA)
  1071. {
  1072. //get the steel technology parameter
  1073. STEEL_TECHNOLOGY steelTech = pMsrParam.GetSteelTechnology();
  1074. if (spl.GetMsrParams().GetSysSTDSwitch())
  1075. {
  1076. if (stdFileName != "NoSTDDB.db")
  1077. {
  1078. foreach (var fld in spl.GetFieldsData())
  1079. {
  1080. foreach (var part in fld.GetListAnalysisParticles())
  1081. {
  1082. IClassifyEngine partEngine = m_classifyEngine.GetExpressionClassifyEngine(stdFileName);
  1083. if (IsLowCounts(part))
  1084. {
  1085. continue;
  1086. }
  1087. if (!partEngine.ClassifyByExpression(part))
  1088. {
  1089. NLog.LogManager.GetCurrentClassLogger().Error("1 failed to classify!" + "Particle Engine");
  1090. }
  1091. if (part.GetType() == (int)OTS_PARTICLE_TYPE.NOT_IDENTIFIED)
  1092. {
  1093. IClassifyEngine incAEngine = m_classifyEngine.GetIncClassifyEngine();
  1094. if (!incAEngine.ClassifyIncA(part, (int)steelTech))
  1095. {
  1096. NLog.LogManager.GetCurrentClassLogger().Error("2 failed to classify!" + "IncA Engine");
  1097. }
  1098. }
  1099. }
  1100. analysisparts.AddRange(fld.GetListAnalysisParticles());
  1101. }
  1102. }
  1103. else
  1104. {
  1105. foreach (var fld in spl.GetFieldsData())
  1106. {
  1107. foreach (var part in fld.GetListAnalysisParticles())
  1108. {
  1109. if (IsLowCounts(part))
  1110. {
  1111. continue;
  1112. }
  1113. IClassifyEngine incAEngine = m_classifyEngine.GetIncClassifyEngine();
  1114. if (!incAEngine.ClassifyIncA(part, (int)steelTech))
  1115. {
  1116. NLog.LogManager.GetCurrentClassLogger().Error("2 failed to classify!" + "IncA Engine");
  1117. }
  1118. }
  1119. analysisparts.AddRange(fld.GetListAnalysisParticles());
  1120. }
  1121. }
  1122. }
  1123. else
  1124. {
  1125. if (stdFileName != "NoSTDDB.db")
  1126. {
  1127. foreach (var fld in spl.GetFieldsData())
  1128. {
  1129. foreach (var part in fld.GetListAnalysisParticles())
  1130. {
  1131. if (IsLowCounts(part))
  1132. {
  1133. continue;
  1134. }
  1135. IClassifyEngine engine = m_classifyEngine.GetExpressionClassifyEngine(stdFileName);
  1136. if (!engine.ClassifyByExpression(part))
  1137. {
  1138. NLog.LogManager.GetCurrentClassLogger().Error("3 failed to classify!" + "Particle Engine");
  1139. }
  1140. }
  1141. analysisparts.AddRange(fld.GetListAnalysisParticles());
  1142. }
  1143. }
  1144. }
  1145. }
  1146. else if (SystemTypeId == OTS_SysType_ID.CleannessA)
  1147. {
  1148. if (stdFileName != "NoSTDDB.db")
  1149. {
  1150. foreach (var fld in spl.GetFieldsData())
  1151. {
  1152. foreach (var part in fld.GetListAnalysisParticles())
  1153. {
  1154. if (IsLowCounts(part))
  1155. {
  1156. continue;
  1157. }
  1158. IClassifyEngine engine = m_classifyEngine.GetExpressionClassifyEngine(stdFileName);
  1159. if (!engine.ClassifyByExpression(part))
  1160. {
  1161. NLog.LogManager.GetCurrentClassLogger().Error("3 failed to classify!" + "Particle Engine");
  1162. }
  1163. }
  1164. analysisparts.AddRange(fld.GetListAnalysisParticles());
  1165. }
  1166. }
  1167. }
  1168. string strFieldFileSubFolder = strFilePath + "\\" + spl.GetName() + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER;
  1169. string strIncAFilename = strFieldFileSubFolder + "\\" + SMPL_MSR_RESULT_INCLUSION_FILE;
  1170. CIncAFileMgr pIncAFileMgr = new CIncAFileMgr(strIncAFilename);
  1171. pIncAFileMgr.UpdateParticleList(analysisparts);
  1172. if (stdFileName.ToLower() != "nostddb.db")
  1173. {
  1174. try
  1175. {
  1176. string userdBpath = Application.StartupPath + "\\Config\\SysData\\" + stdFileName;
  1177. File.Copy(userdBpath, strFilePath + "\\" + spl.GetName() + "\\" + stdFileName, true);
  1178. }
  1179. catch (Exception ex)
  1180. {
  1181. MessageBox.Show(stdFileName+" copy failed:" + ex.ToString());
  1182. return false;
  1183. }
  1184. }
  1185. }
  1186. return true;
  1187. }
  1188. private bool IsLowCounts(COTSParticleClr particle)
  1189. {
  1190. COTSXRayParam pXRayParam = this.GetWorkingSample().GetMsrParams().GetXRayParam();
  1191. if (pXRayParam.GetUsingXray() == true)
  1192. {
  1193. var thecount = particle.GetXray().GetTotalCount();
  1194. var expect = pXRayParam.GetAnalyExpCount();
  1195. if (thecount < expect)
  1196. {
  1197. particle.SetType((int)OTS_PARTICLE_TYPE.LOW_COUNT);//4 represent "lowcount"
  1198. particle.SetTypeColor("#000000");
  1199. particle.SetTypeName("LowCounts");
  1200. return true;
  1201. }
  1202. }
  1203. return false;
  1204. }
  1205. /// <summary>
  1206. /// 设置样品中对象属性 赋值
  1207. /// </summary>
  1208. /// <param name="pSample"></param>
  1209. /// <param name="poMsrParams"></param>
  1210. /// <returns></returns>
  1211. void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  1212. {
  1213. // copy data over
  1214. if (m_pSEMStageData == null)
  1215. {
  1216. m_pSEMStageData = new CSEMStageData();
  1217. }
  1218. if (m_pStage == null)
  1219. {
  1220. m_pStage = new CStage();
  1221. }
  1222. xInt xProjMgrFileMark = new xInt();
  1223. xString xProjMgrFileVersion = new xString();
  1224. xString xstrPathName = new xString();
  1225. xString xSystype = new xString();
  1226. Collection<CHoleBSEImg> xholeBSEImgs = new Collection<CHoleBSEImg>();
  1227. Collection<COTSSample> xsamples = new Collection<COTSSample>();
  1228. Slo slo = new Slo();
  1229. slo.Register("ProjMgrFileMark", xProjMgrFileMark);
  1230. slo.Register("ProjMgrFileVersion", xProjMgrFileVersion);
  1231. slo.Register("strPathName", xstrPathName);
  1232. slo.Register("SysType", xSystype);
  1233. slo.Register("SEMStageData", m_pSEMStageData);
  1234. slo.Register("Stage", m_pStage);
  1235. slo.Register("HoleBSEImg", xholeBSEImgs);
  1236. slo.Register("Samples", xsamples);
  1237. if (isStoring)
  1238. {
  1239. xProjMgrFileMark.AssignValue(0);
  1240. xProjMgrFileVersion.AssignValue("");
  1241. xSystype.AssignValue(systemTypeId.ToString());
  1242. xstrPathName.AssignValue(m_strPathName);
  1243. xholeBSEImgs.Clear();
  1244. xsamples.Clear();
  1245. foreach (var sample in m_listSamples)
  1246. {
  1247. xsamples.addItem(sample);
  1248. }
  1249. slo.Serialize(true, classDoc, rootNode);
  1250. }
  1251. else
  1252. {
  1253. slo.Serialize(false, classDoc, rootNode);
  1254. m_strPathName = xstrPathName.value();
  1255. m_listHoleBSEImg.Clear();
  1256. m_listSamples.Clear();
  1257. for (int i = 0; i < (int)xsamples.size(); i++)
  1258. {
  1259. m_listSamples.Add(xsamples.getItem(i));
  1260. }
  1261. if(xSystype.value()== "IncA")
  1262. {
  1263. systemTypeId = otsdataconst.OTS_SysType_ID.IncA;
  1264. }
  1265. else
  1266. {
  1267. systemTypeId = otsdataconst.OTS_SysType_ID.CleannessA;
  1268. }
  1269. }
  1270. }
  1271. }
  1272. }