COTSMsrPrjResultData.cs 50 KB

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