COTSMsrPrjResultData.cs 53 KB

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