COTSMsrPrjResultData.cs 51 KB

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