COTSMsrPrjResultData.cs 52 KB

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