COTSMsrPrjResultData.cs 51 KB

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