COTSMsrPrjResultData.cs 52 KB

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