COTSMsrPrjResultData.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620
  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. if(xSystype.value()== "IncA")
  1289. {
  1290. m_nPackId = otsdataconst.OTS_SysType_ID.IncA;
  1291. }
  1292. else
  1293. {
  1294. m_nPackId = otsdataconst.OTS_SysType_ID.CleanlinessA;
  1295. }
  1296. }
  1297. }
  1298. }
  1299. }