COTSMsrPrjResultData.cs 54 KB

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