COTSMsrPrjResultData.cs 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612
  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. 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.ListAnalysisParticles)
  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.ListAnalysisParticles)
  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.ListAnalysisParticles;
  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. Serialize(true, doc, root);
  1163. //string imgpath = filename.GetBuffer(0);
  1164. //const char* file = imgpath.c_str();
  1165. //tinyxml2::XMLDocument doc;
  1166. //if (doc.LoadFile(file) != 0)
  1167. //{
  1168. // return NULL;
  1169. //}
  1170. //tinyxml2::XMLElement* root = doc.RootElement();
  1171. //std::string sem = "Sample";
  1172. //tinyxml2::XMLElement* member = queryUserNodeByName(root, sem);
  1173. //tinyxml2::XMLElement* member1 = queryUserNodeByName(member, "MsrParams");
  1174. //member1->SetAttribute("STDName", stdFileName);
  1175. doc.Save(filename);
  1176. //get the steel technology parameter
  1177. STEEL_TECHNOLOGY steelTech = pMsrParam.GetSteelTechnology();
  1178. foreach (var fld in spl.GetFieldsData())
  1179. {
  1180. foreach (var part in fld.ListAnalysisParticles)
  1181. {
  1182. if (spl.IfUsingSysSTD())
  1183. {
  1184. if (stdFileName != "NoSTDDB")
  1185. {
  1186. var m_classifyEngine = new CClassifyEngine();
  1187. IClassifyEngine engine = m_classifyEngine.GetParticleEngine(stdFileName);
  1188. if (!engine.Classify(part))
  1189. {
  1190. return false;
  1191. }
  1192. }
  1193. if (part.GetType() == (int)OTS_PARTCLE_TYPE.NOT_IDENTIFIED)
  1194. {
  1195. var m_classifyEngine = new CClassifyEngine();
  1196. IClassifyEngine engine = m_classifyEngine.GetIncClassifyEngine();
  1197. if (!engine.ClassifyIncA(part, (int)steelTech))
  1198. {
  1199. return false;
  1200. }
  1201. }
  1202. }
  1203. else
  1204. {
  1205. if (stdFileName != "NoSTDDB")
  1206. {
  1207. var m_classifyEngine = new CClassifyEngine();
  1208. IClassifyEngine engine = m_classifyEngine.GetParticleEngine(stdFileName);
  1209. if (!engine.Classify(part))
  1210. {
  1211. return false;
  1212. }
  1213. }
  1214. }
  1215. }
  1216. string strFieldFileSubFolder = strFilePath + "\\" + spl.GetName() + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER;
  1217. string strIncAFilename = strFieldFileSubFolder + "\\" + SMPL_MSR_RESULT_INCLUSION_FILE;
  1218. CIncAFileMgr pIncAFileMgr = new CIncAFileMgr(strIncAFilename);
  1219. pIncAFileMgr.UpdateIncAList(fld.ListAnalysisParticles);
  1220. }
  1221. }
  1222. return true;
  1223. }
  1224. /// <summary>
  1225. /// 设置样品中对象属性 赋值
  1226. /// </summary>
  1227. /// <param name="pSample"></param>
  1228. /// <param name="poMsrParams"></param>
  1229. /// <returns></returns>
  1230. void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  1231. {
  1232. // copy data over
  1233. if (m_pSEMStageData == null)
  1234. {
  1235. m_pSEMStageData = new CSEMStageData();
  1236. }
  1237. if (m_pStage == null)
  1238. {
  1239. m_pStage = new CStage();
  1240. }
  1241. xInt xProjMgrFileMark = new xInt();
  1242. xString xProjMgrFileVersion = new xString();
  1243. xString xstrPathName = new xString();
  1244. xString xSystype = new xString();
  1245. Collection<CHoleBSEImg> xholeBSEImgs = new Collection<CHoleBSEImg>();
  1246. Collection<COTSSample> xsamples = new Collection<COTSSample>();
  1247. Slo slo = new Slo();
  1248. slo.Register("ProjMgrFileMark", xProjMgrFileMark);
  1249. slo.Register("ProjMgrFileVersion", xProjMgrFileVersion);
  1250. slo.Register("strPathName", xstrPathName);
  1251. slo.Register("SysType", xSystype);
  1252. slo.Register("SEMStageData", m_pSEMStageData);
  1253. slo.Register("Stage", m_pStage);
  1254. slo.Register("HoleBSEImg", xholeBSEImgs);
  1255. slo.Register("Samples", xsamples);
  1256. if (isStoring)
  1257. {
  1258. xProjMgrFileMark.AssignValue(0);
  1259. xProjMgrFileVersion.AssignValue("");
  1260. xSystype.AssignValue(m_nPackId.ToString());
  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. }