COTSMsrPrjResultData.cs 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658
  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. CMsrResultItems 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, CMsrResultItems 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 string GetSampleWorkingFolder(string sampleName)
  394. {
  395. var pathname = FileHelper.GetFolderName(GetPathName());
  396. var samplePathName = pathname + "\\" + sampleName + "\\";
  397. return samplePathName;
  398. }
  399. public bool Save()
  400. {
  401. // Save or Save As, if strPathName is not empty, it is exist in the computer, this is a save action
  402. String strPathName = GetPathName();
  403. if (strPathName.CompareTo(UNTITLED_FILE_NAME) == 0)
  404. {
  405. // this is a new file
  406. // return save as result
  407. return SaveAs();
  408. }
  409. // is this a new file?
  410. strPathName.Trim();
  411. //保存测量项目文件 .prj
  412. XmlDocument doc = new XmlDocument();
  413. doc.Load(strPathName);
  414. doc.RemoveAll();
  415. //添加xml文件头申明
  416. XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
  417. doc.AppendChild(xmldecl);
  418. XmlElement rootNode = doc.CreateElement("XMLData");
  419. doc.AppendChild(rootNode);
  420. Serialize(true, doc, rootNode);
  421. try
  422. {
  423. doc.Save(strPathName);
  424. }
  425. catch
  426. {
  427. return false;
  428. }
  429. // set file modify flag
  430. SetModify(false);
  431. // Ok, return TRUE
  432. return true;
  433. }
  434. public bool SaveAs()
  435. {
  436. // get file name
  437. String strPathName = "";
  438. // file open dialog
  439. SaveFileDialog saveFileDialog = new SaveFileDialog();
  440. saveFileDialog.FileName = m_strPathName.Split('\\')[m_strPathName.Split('\\').Length - 1];
  441. saveFileDialog.Filter = "Probject Files (*.prj)|*.prj|All files (*.*)|*.*";
  442. if (saveFileDialog.ShowDialog() != DialogResult.OK)
  443. {
  444. return false;
  445. }
  446. // get file pathname
  447. strPathName = saveFileDialog.FileName;
  448. string DirectoryName = Path.GetDirectoryName(strPathName);
  449. DirectoryInfo Folder = new DirectoryInfo(DirectoryName);
  450. List<string> FolderNames = new List<string>();
  451. if (Folder.GetDirectories().Length != 0)
  452. {
  453. MessageBox.Show("Save failed, a folder exists in the current location, delete or create a new one!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  454. return false;
  455. }
  456. //保存测量项目文件 .prj
  457. XmlDocument doc = new XmlDocument();
  458. //添加xml文件头申明
  459. XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
  460. doc.AppendChild(xmldecl);
  461. XmlElement rootNode = doc.CreateElement("XMLData");
  462. doc.AppendChild(rootNode);
  463. Serialize(true, doc, rootNode);
  464. try
  465. {
  466. doc.Save(strPathName);
  467. }
  468. catch
  469. {
  470. return false;
  471. }
  472. // set file modify flag
  473. m_bModify = false;
  474. // Set project Path
  475. SetPathName(strPathName);
  476. // Ok, return TRUE
  477. return true;
  478. }
  479. // SEM stage data
  480. public CSEMStageData GetSEMStageData() { return m_pSEMStageData; }
  481. // SEM stage data
  482. public void SetSEMStageData(CSEMStageData a_pCSEMStageData)
  483. {
  484. m_pSEMStageData = a_pCSEMStageData;
  485. }
  486. // stage
  487. public CStage GetStage() { return m_pStage; }
  488. public void SetStage(CStage a_pStage)
  489. {
  490. m_pStage = new CStage(a_pStage);
  491. }
  492. // samples list
  493. public List<COTSSample> GetSampleList() { return m_listSamples; }
  494. public COTSSample GetSampleByIndex(int a_nIndex)
  495. {
  496. // safe check
  497. if (a_nIndex < 0 || a_nIndex >= (int)m_listSamples.Count)
  498. {
  499. // invalid sample id
  500. return null;
  501. }
  502. // get the matching sample
  503. COTSSample pSample = m_listSamples[a_nIndex];
  504. // return the sample
  505. return pSample;
  506. }
  507. public COTSSample GetSampleByName(String a_strSampleName)
  508. {
  509. bool Isfind = false;
  510. COTSSample pOTSSample = null;
  511. for (int itr = 0; itr < m_listSamples.Count; itr++)
  512. {
  513. if (m_listSamples[itr].GetName() == a_strSampleName)
  514. {
  515. pOTSSample = m_listSamples[itr];
  516. //m_listSamples.RemoveAt(itr);
  517. Isfind = true;
  518. }
  519. }
  520. if (Isfind)
  521. {
  522. return pOTSSample;
  523. }
  524. return m_listSamples[0];
  525. }
  526. public void AddSample(COTSSample pSample)
  527. {
  528. // add the new sample into the samples list
  529. m_listSamples.Add(pSample);
  530. // set the project file modified.
  531. SetModify();
  532. // set the new as working sample
  533. m_nWorkingSampeIndex = (int)m_listSamples.Count - 1;
  534. // return the new sample
  535. }
  536. // get new sample name
  537. public bool DeleteSampleByIndex(int a_nIndex)
  538. {
  539. // check the index
  540. if (a_nIndex < 0 || a_nIndex >= (int)m_listSamples.Count)
  541. {
  542. // invalid input sample index
  543. return true;
  544. }
  545. // calculate new working sample index
  546. int nNewWorkingSampeIndex;
  547. if (a_nIndex < m_nWorkingSampeIndex)
  548. {
  549. nNewWorkingSampeIndex = m_nWorkingSampeIndex - 1;
  550. }
  551. else if (a_nIndex > m_nWorkingSampeIndex)
  552. {
  553. nNewWorkingSampeIndex = m_nWorkingSampeIndex;
  554. }
  555. else
  556. {
  557. // deleting working sample.
  558. if (a_nIndex == (int)m_listSamples.Count - 1)
  559. {
  560. // this is the last sample, select the above sample as working sample
  561. // if this is only sample in the list working sample index will be -1;
  562. nNewWorkingSampeIndex = m_nWorkingSampeIndex - 1;
  563. }
  564. else
  565. {
  566. // select next sample as working sample
  567. nNewWorkingSampeIndex = m_nWorkingSampeIndex;
  568. }
  569. }
  570. // delete the sample
  571. for (int i = m_listSamples.Count - 1; i >= 0; i--)
  572. {
  573. if (i == a_nIndex)
  574. {
  575. var sam = m_listSamples[i];
  576. sam.GetMsrStatus().ClearCompletedFieldsInfo();
  577. sam.GetMsrStatus().ClearCompletedFieldsInfo();
  578. sam.ClearFields();
  579. sam.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.UNMEASURED);
  580. m_listSamples.Remove(m_listSamples[i]);
  581. break;
  582. }
  583. }
  584. // the file is modified.
  585. SetModify();
  586. // reset working sample index
  587. m_nWorkingSampeIndex = nNewWorkingSampeIndex;
  588. // ok, return TRUE
  589. return true;
  590. }
  591. public bool ChangeParamFromList(int iNamePos)
  592. {
  593. throw new NotImplementedException();
  594. }
  595. public bool GetParamFileList(ref int iNamePos, ref List<string> mParamFileNameList)
  596. {
  597. throw new NotImplementedException();
  598. }
  599. public bool DeleteSampleByName(String a_strSampleName)
  600. {
  601. // check input sample name
  602. a_strSampleName.Trim();
  603. if (a_strSampleName == "")
  604. {
  605. // input sample name is empty
  606. return false;
  607. }
  608. // go through sample list
  609. int nIndex = 0;
  610. foreach (var pSample in m_listSamples)
  611. {
  612. // return TRUE if this is not an exclude sample and its name is same with input
  613. String strSampleName = pSample.GetName();
  614. if (strSampleName.CompareTo(a_strSampleName) == 0)
  615. {
  616. // find the sample, return deleting result
  617. return DeleteSampleByIndex(nIndex);
  618. }
  619. ++nIndex;
  620. }
  621. // can't find the sample in the samples list, return FALSE
  622. return false;
  623. }
  624. public bool ResetSamplesListOrder(List<String> a_listSampleNames)
  625. {
  626. // no sample in the samples list; shouldn't be here
  627. if (m_listSamples.Count == 0)
  628. {
  629. return false;
  630. }
  631. // make sure that input sample names list size is same with the samples list
  632. if (m_listSamples.Count != a_listSampleNames.Count)
  633. {
  634. return false;
  635. }
  636. // new sample list
  637. List<COTSSample> listSamples = new List<COTSSample>();
  638. // go through the sample names list
  639. foreach (var strSampleName in a_listSampleNames)
  640. {
  641. bool IsChanged = false;
  642. for (int itr = 0; itr < m_listSamples.Count; itr++)
  643. {
  644. if (m_listSamples[itr].GetName() == strSampleName)
  645. {
  646. COTSSample pElementChemistry = m_listSamples[itr];
  647. IsChanged = true;
  648. }
  649. }
  650. if (!IsChanged)
  651. {
  652. return false;
  653. }
  654. }
  655. // reset the samples list
  656. m_listSamples.Clear();
  657. foreach (var pSample in listSamples)
  658. {
  659. m_listSamples.Add(pSample);
  660. }
  661. // set modify flag
  662. SetModify();
  663. // Ok, return TRUE
  664. return true;
  665. }
  666. public bool InsrtSample(COTSSample a_pSample, int a_nIndex)
  667. {
  668. // input check
  669. if (a_pSample != null)
  670. {
  671. // invalid input sample pointer
  672. return false;
  673. }
  674. if (m_listSamples.Count == 0 || a_nIndex >= (int)m_listSamples.Count)
  675. {
  676. m_listSamples.Add(a_pSample);
  677. }
  678. else if (a_nIndex <= 0)
  679. {
  680. m_listSamples.Insert(Convert.ToInt32(m_listSamples[a_nIndex]), a_pSample);
  681. }
  682. else
  683. {
  684. m_listSamples.Insert(Convert.ToInt32(m_listSamples[a_nIndex]) + a_nIndex, a_pSample);
  685. }
  686. // Ok, return TRUE
  687. return true;
  688. }
  689. public bool ChangeSamplePosition(int a_nIndexFrom, int a_nIndexTo)
  690. {
  691. // make sure both index are valid
  692. if (a_nIndexFrom < 0 || a_nIndexFrom >= (int)m_listSamples.Count)
  693. {
  694. // invalid from index
  695. return false;
  696. }
  697. if (a_nIndexTo < 0 || a_nIndexTo >= (int)m_listSamples.Count)
  698. {
  699. // invalid to index
  700. return false;
  701. }
  702. // need to do nothing if the two indexes are the same
  703. if (a_nIndexFrom != a_nIndexTo)
  704. {
  705. // move to last?
  706. bool bLast = (a_nIndexTo == ((int)m_listSamples.Count - 1));
  707. // get the sample
  708. COTSSample pSample = m_listSamples[a_nIndexFrom];
  709. // remove it from the samples list
  710. m_listSamples.Remove(pSample);
  711. // put the sample back in
  712. if (bLast)
  713. {
  714. m_listSamples.Add(pSample);
  715. }
  716. else
  717. {
  718. m_listSamples.Insert(Convert.ToInt32(m_listSamples[a_nIndexTo]) + a_nIndexTo, pSample);
  719. }
  720. }
  721. // Ok, return TRUE
  722. return true;
  723. }
  724. public bool MoveSamplePosition(COTSSample a_pTargetSample, COTSSample a_RefpSample, bool a_bBefore /*= TRUE*/)
  725. {
  726. // check input
  727. if (a_pTargetSample != null)
  728. {
  729. // invalid input target sample pointer
  730. return false;
  731. }
  732. if (a_RefpSample != null)
  733. {
  734. // invalid input ref sample pointer
  735. return false;
  736. }
  737. bool IsChanged = false;
  738. for (int itr = 0; itr < m_listSamples.Count; itr++)
  739. {
  740. if (m_listSamples[itr].GetName() == a_pTargetSample.GetName())
  741. {
  742. COTSSample pElementChemistry = m_listSamples[itr];
  743. // m_listSamples.RemoveAt(itr);
  744. IsChanged = true;
  745. }
  746. }
  747. if (!IsChanged)
  748. {
  749. return false;
  750. }
  751. for (int itr = 0; itr < m_listSamples.Count; itr++)
  752. {
  753. if (m_listSamples[itr].GetName() == a_RefpSample.GetName())
  754. {
  755. COTSSample pElementChemistry = m_listSamples[itr];
  756. //m_listSamples.RemoveAt(itr);
  757. IsChanged = true;
  758. }
  759. }
  760. if (!IsChanged)
  761. {
  762. return false;
  763. }
  764. // remove the sample from the samples list
  765. for (int itr = 0; itr < m_listSamples.Count; itr++)
  766. {
  767. if (m_listSamples[itr].GetName() == a_RefpSample.GetName())
  768. {
  769. COTSSample pElementChemistry = m_listSamples[itr];
  770. //m_listSamples.RemoveAt(itr);
  771. IsChanged = true;
  772. }
  773. }
  774. if (!IsChanged)
  775. {
  776. return false;
  777. }
  778. // put the sample back in
  779. if (a_bBefore)
  780. {
  781. m_listSamples.Insert(0, a_pTargetSample);
  782. }
  783. else
  784. {
  785. m_listSamples.Insert(1, a_pTargetSample);
  786. }
  787. // Ok, return TRUE
  788. return true;
  789. }
  790. public bool MoveSamplePosition(String a_strTargetSampleName, String a_strRefSampleName, bool a_bBefore /*= TRUE*/)
  791. {
  792. // input check
  793. a_strTargetSampleName.Trim();
  794. if (a_strTargetSampleName == "")
  795. {
  796. // input target sample is an empty string
  797. return false;
  798. }
  799. a_strRefSampleName.Trim();
  800. if (a_strRefSampleName == "")
  801. {
  802. // input ref sample is an empty string
  803. return false;
  804. }
  805. bool IsChanged = false;
  806. for (int itr = 0; itr < m_listSamples.Count; itr++)
  807. {
  808. if (m_listSamples[itr].GetName() == a_strTargetSampleName)
  809. {
  810. COTSSample pElementChemistry = m_listSamples[itr];
  811. IsChanged = true;
  812. }
  813. }
  814. if (!IsChanged)
  815. {
  816. return false;
  817. }
  818. COTSSample pTargetSample = m_listSamples[0];
  819. for (int itr = 0; itr < m_listSamples.Count; itr++)
  820. {
  821. if (m_listSamples[itr].GetName() == a_strTargetSampleName)
  822. {
  823. COTSSample pElementChemistry = m_listSamples[itr];
  824. IsChanged = true;
  825. }
  826. }
  827. if (!IsChanged)
  828. {
  829. return false;
  830. }
  831. COTSSample pRefSample = pTargetSample;
  832. // need to do nothing if the two name are same
  833. if (a_strTargetSampleName.CompareTo(a_strRefSampleName) != 0)
  834. {
  835. return MoveSamplePosition(pTargetSample, pRefSample, a_bBefore);
  836. }
  837. // Ok, return TRUE
  838. return true;
  839. }
  840. public COTSSample GetWorkingSample()
  841. {
  842. return GetSampleByIndex(m_nWorkingSampeIndex);
  843. }
  844. public bool SetWorkingSampleByIndex(int a_nIndex)
  845. {
  846. // special treatment
  847. if (a_nIndex == -1 && m_listSamples.Count == 0)
  848. {
  849. m_nWorkingSampeIndex = -1;
  850. return true;
  851. }
  852. // check if the working sample index
  853. if (0 > a_nIndex || a_nIndex >= (int)m_listSamples.Count)
  854. {
  855. // invalid sample index
  856. return false;
  857. }
  858. m_nWorkingSampeIndex = a_nIndex;
  859. return true;
  860. }
  861. public bool SetWorkingSampleByName(String a_pSampleName)
  862. {
  863. // check input sample name
  864. a_pSampleName.Trim();
  865. if (a_pSampleName == "")
  866. {
  867. // input sample name is empty
  868. return false;
  869. }
  870. // go through sample list
  871. int nIndex = 0;
  872. foreach (var pSample in m_listSamples)
  873. {
  874. // return TRUE if this is not an exclude sample and its name is same with input
  875. String strSampleName = pSample.GetName();
  876. if (strSampleName.CompareTo(a_pSampleName) == 0)
  877. {
  878. // find the sample, return deleting result
  879. return SetWorkingSampleByIndex(nIndex);
  880. }
  881. ++nIndex;
  882. }
  883. // failed to find the named sample
  884. // failed to find the named sample return FALSE
  885. return false;
  886. }
  887. public bool DeleteWorkingSample()
  888. {
  889. // check if the working sample index
  890. if (m_nWorkingSampeIndex < 0 || m_nWorkingSampeIndex >= (int)m_listSamples.Count)
  891. {
  892. // invalid working sample index
  893. return false;
  894. }
  895. // return the result of DeleteSampleByIndex
  896. return DeleteSampleByIndex(m_nWorkingSampeIndex);
  897. }
  898. // Sample hole BSE image list
  899. public List<CHoleBSEImg> GetHoleBESImgList() { return m_listHoleBSEImg; }
  900. // hole BSE images list
  901. public void SetHoleBESImgList(List<CHoleBSEImg> a_listHoleBSEImg, bool a_bClear/* = TRUE*/)
  902. {
  903. // clear the hole BSE image list if necessary
  904. if (a_bClear)
  905. {
  906. m_listHoleBSEImg.Clear();
  907. }
  908. m_listHoleBSEImg = a_listHoleBSEImg;
  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. // CMeasureParam 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. // CMeasureParam 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 CMsrResultItems())
  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. }