COTSMsrPrjResultData.cs 52 KB

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