COTSMeasureParam.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  1. using OTSModelSharp;
  2. using OTSDataType;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.IO;
  8. using OTSModelSharp.ResourceManage;
  9. using static OTSModelSharp.ResourceManage.ResourceID;
  10. using static OTSModelSharp.ResourceManage.ResourceData;
  11. using static OTSDataType.otsdataconst;
  12. using System.Windows.Forms;
  13. using OTSMeasureApp._0_OTSModel.OTSDataType;
  14. namespace OTSMeasureApp
  15. {
  16. //设置线程状态
  17. public enum MSR_RUN_TYPE
  18. {
  19. RUNMEASURE = 1, //normal
  20. ShotSampleHoleImage = 2 //take photo of the measure area.
  21. };
  22. enum SAMPLE_FAULT_WARN_CODE
  23. {
  24. INVALID = -1,
  25. MIN = 0,
  26. SEM_DATA_ERROR = 0,
  27. AREA_OUTSIDE_HOLE = 1,
  28. RESOLUTION_LOW = 2,
  29. FINISHED = 3,
  30. NO_ERROR_WARNING = 4,
  31. FILE_NOT_SAVED = 5,
  32. MAX = 5
  33. };
  34. enum SAMPLE_CHECK_RESULT_TYPE
  35. {
  36. INVALID = -1,
  37. MIN = 0,
  38. SWITCH_ON = 0,
  39. FINISHED = 1,
  40. SETTING_ERROR = 2,
  41. SETTING_WARNING = 3,
  42. MEASURABLE = 4,
  43. NO_ERROR_WARNING = 5,
  44. MAX = 5
  45. };
  46. public class COTSMeasureParam
  47. {
  48. OTSIncAMeasureAppForm m_MeasureAppFrom = null;
  49. /// <summary></summary>
  50. /// <remarks>创建</remarks>
  51. private COTSMsrPrjResultData resultData;
  52. //参数文件
  53. private COTSDefaultParam defaultParam = null;
  54. //测量样品链表
  55. List<COTSSample> m_MeasureSampleList = new List<COTSSample>();
  56. NLog.Logger log ;
  57. public List<COTSSample> MeasureSampleList { get => m_MeasureSampleList; set => m_MeasureSampleList = value; }
  58. public COTSDefaultParam GetDefaultParam()
  59. {
  60. return defaultParam;
  61. }
  62. public void SetDefaultParam(COTSDefaultParam value)
  63. {
  64. defaultParam = value;
  65. }
  66. public COTSMsrPrjResultData GetResultData()
  67. {
  68. return resultData;
  69. }
  70. public void SetResultData(COTSMsrPrjResultData value)
  71. {
  72. resultData = value;
  73. }
  74. public COTSMeasureParam(OTSIncAMeasureAppForm MeasureApp)
  75. {
  76. log = NLog.LogManager.GetCurrentClassLogger();
  77. m_MeasureAppFrom = MeasureApp;
  78. SetResultData(new COTSMsrPrjResultData());
  79. }
  80. //检查参数文件是否存在
  81. public bool LoadParamFile()
  82. {
  83. //加载样品参数文件: \Config\SysData\OTSProgMgrParam.pmf
  84. SetDefaultParam(new COTSDefaultParam());
  85. return GetDefaultParam().LoadInfoFromProgMgrFile();
  86. }
  87. //获取系统文件是否存在和有效
  88. public bool InitResultData(bool bNewFileFlag = true)
  89. {
  90. //打开文件,则文件中保存有样品台信息,不需要使用系统样品名信息
  91. if (bNewFileFlag)
  92. {
  93. //设置样品台参数
  94. CSampleHolder Stage = GetDefaultParam().GetStageHolderParam().GetWorkingStage();
  95. if (null == Stage)
  96. {
  97. return false;
  98. }
  99. GetResultData().SetStage(Stage);
  100. // 设置 SEM stage data
  101. CSEMStageData SEMData = GetDefaultParam().GetStageDataParam();
  102. if (null == SEMData)
  103. {
  104. return false;
  105. }
  106. GetResultData().SetSEMStageData(SEMData);
  107. }
  108. //设置 general parameter
  109. COTSCommonParam GenParam = GetDefaultParam().GetCommonParam();
  110. if (null == GenParam)
  111. {
  112. return false;
  113. }
  114. GetResultData().SetGenParam(GenParam);
  115. if (GetResultData().GetPathName()=="")
  116. {
  117. GetResultData().SetPathName("Untitled");
  118. }
  119. GetResultData().SystemTypeId = GetDefaultParam().SystemTypeId;
  120. return true;
  121. }
  122. //新建样品工作文件 0:报错 1:正常 2:取消
  123. public int CreateNewFile()
  124. {
  125. if (GetResultData().IsModified()) // 文件被修改
  126. {
  127. int iRev = m_MeasureAppFrom.ShowSaveInfoMsgBox();
  128. if ((int)MessageBoxRev.DIALOG_YES == iRev)
  129. {
  130. if (!GetResultData().Save())
  131. {
  132. return 0;
  133. }
  134. }
  135. else if((int)MessageBoxRev.DIALOG_CANCEL == iRev)
  136. {
  137. return 2;
  138. }
  139. }
  140. //新建新的工作文件
  141. //重新生成一个工作文件对象
  142. COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();
  143. GetResultData().SetPathName("Untitled");
  144. SetResultData(ProjDataMgr);
  145. //this.LoadStageParamFile();
  146. if (!this.InitResultData())
  147. {
  148. return 0;
  149. }
  150. return 1;
  151. }
  152. public OTSSampleVisualPropertyInfo AddNewSampleMeasure(string a_strHoleName = "")
  153. {
  154. COTSSample NewSample = new COTSSample();
  155. SetSampleDefaultPara(ref NewSample, a_strHoleName);
  156. //NewSample.
  157. //添加样品
  158. GetResultData().AddSample(NewSample);
  159. // 获取样品的属性值
  160. OTSSampleVisualPropertyInfo MeasureInfo = new OTSSampleVisualPropertyInfo(NewSample, defaultParam.GetSysType());
  161. return MeasureInfo;
  162. }
  163. public void InitWorkingSampleData(int startfieldNo)
  164. {
  165. COTSSample Sample = GetWorkSample();
  166. if (Sample == null) return ;
  167. var sname= Sample.GetName();
  168. var pathname = resultData.GetFolderName(resultData.GetPathName());
  169. var sampleResultFolder = pathname + "\\" + sname;
  170. if (Directory.Exists(sampleResultFolder))
  171. {
  172. resultData.DeleteWorkingSampleFieldDataByFieldNo(startfieldNo);
  173. //Directory.Delete(sampleResultFolder, true);
  174. var flds = Sample.GetFieldsData();
  175. foreach (var f in flds)
  176. {
  177. if (f.GetMeasureSequence() >= startfieldNo)
  178. {
  179. f.ClearAllMeausredData();
  180. f.SetIsMeasureComplete(false);
  181. }
  182. }
  183. Sample.SetFieldsData(flds);
  184. }
  185. var sta = Sample.GetMsrStatus();
  186. sta.ClearCompletedFieldsInfo();
  187. sta.SetStatus(OTS_MSR_SAMPLE_STATUS.UNMEASURED);
  188. var rsts = Sample.GetMsrResults();
  189. var itms = rsts.GetResultItems();
  190. itms.Clear();
  191. rsts.SetResultItems(itms);
  192. rsts.SetMeasuredArea(0);
  193. rsts.SetRatio(0);
  194. }
  195. public OTSSampleVisualPropertyInfo GetWorkingSampleVisualPropertyInfo()
  196. {
  197. COTSSample Sample = GetWorkSample();
  198. if (Sample == null) return null;
  199. OTSSampleVisualPropertyInfo MeasureInfo = new OTSSampleVisualPropertyInfo(Sample, defaultParam.GetSysType());
  200. return MeasureInfo;
  201. }
  202. protected COTSSample SetSampleDefaultPara(ref COTSSample pSample, String a_strHoleName)
  203. {
  204. // get new sample name
  205. String strNewSampleName = GetNewSampleName();
  206. // make sure the new sample name is not an empty string
  207. strNewSampleName.Trim();
  208. // get a suitable sample hole for the new sample
  209. CHole pHole = SelectASmpleHole(a_strHoleName);
  210. // check the sample hole
  211. if (pHole == null)
  212. {
  213. // failed to get sample hole for the new sample
  214. return null;
  215. }
  216. // measurement area
  217. CDomain pMsrArea = CalculateDefaultArea(pHole);
  218. // measure data parameters containing particle analysis std, image scan parameter, image process parameter and x-ray parameter
  219. CSampleParam poMsrParams = new CSampleParam();
  220. poMsrParams.m_nPackId = GetDefaultParam().SystemTypeId;
  221. poMsrParams.m_runmode = GetDefaultParam().m_runmode;
  222. //MEMBRANE_TYPE a_nVal = (MEMBRANE_TYPE)m_pParam.GetMembraneType();
  223. poMsrParams.CopyImageScanParam(GetDefaultParam().GetImageScanParam ());
  224. poMsrParams.CopyImageProcessParam(GetDefaultParam().GetImageProcParam());
  225. poMsrParams.CopyXRayParam(GetDefaultParam().GetXRayParam());
  226. var m_pParam = GetDefaultParam().GetCommonParam();
  227. String sSTDName = m_pParam.GetSTDSelect();
  228. poMsrParams.SetSTDName(sSTDName);
  229. poMsrParams.SetSteelTechnology((STEEL_TECHNOLOGY)m_pParam.GetSteelTechnology());
  230. poMsrParams.GetImageProcessParam().SetSpecialGreyRangeParam(defaultParam.SpecialGrayRangeParam.Duplicate());
  231. // set sample parameters
  232. pSample.SetName(strNewSampleName);
  233. pSample.SetSampleHoleName(pHole.GetName());
  234. pSample.SetSwitch(m_pParam.GetMeasurementSwitch());
  235. poMsrParams.SetEngineType(m_pParam.GetEngineType());
  236. pSample.SetMsrDomain(pMsrArea);
  237. pSample.SetMsrParams(poMsrParams);
  238. CSEMFieldData semData = new CSEMFieldData();
  239. var m_pSEMStageData = GetDefaultParam().GetStageDataParam();
  240. var imageScanParam = GetDefaultParam().GetImageScanParam();
  241. string resol = imageScanParam.GetImageResulotion().ToString();
  242. double resWidth = Convert.ToDouble(resol.Split('_')[1]);
  243. double resHeight = Convert.ToDouble(resol.Split('_')[2]);
  244. double heightWidthRatio = resHeight / resWidth;
  245. semData.SetScanFieldSize100(m_pSEMStageData.GetScanFieldSize100());
  246. double fieldHeight = m_pSEMStageData.GetScanFieldSize100() * heightWidthRatio;
  247. semData.SetScanFieldHeight100((int)fieldHeight);
  248. pSample.SetSEMDataMsr(semData);
  249. return pSample;
  250. }
  251. public String GetNewSampleName()
  252. {
  253. // new sample name
  254. String strNewSmplName = "";
  255. // safety check
  256. var m_pParam = GetDefaultParam().GetCommonParam();
  257. if (m_pParam == null)
  258. {
  259. // shouldn't happen, invalid general parameter pointer.
  260. return strNewSmplName;
  261. }
  262. // new sample name base
  263. String strNewSmplNameBase = m_pParam.GetSampleName() + @"{0}";
  264. int nIndex = 1;
  265. do
  266. {
  267. // new sample name is new sample name base + number string
  268. strNewSmplName = string.Format(strNewSmplNameBase, nIndex);
  269. ++nIndex;
  270. }
  271. // make sure that the new sample name is not same with any sample in the samples list
  272. while (SameNameInList(strNewSmplName));
  273. // new sample name
  274. return strNewSmplName;
  275. }
  276. public bool SameNameInList(String a_strSampleName, int a_nExclude = -1)
  277. {
  278. // make sure the input sample name is not empty
  279. a_strSampleName.Trim();
  280. if (a_strSampleName == "")
  281. {
  282. // shouldn't happen, input name is an empty string
  283. return false;
  284. }
  285. // go through sample list
  286. int nIndex = 0;
  287. var m_listSamples = GetResultData().GetSampleList();
  288. foreach (var pSample in m_listSamples)
  289. {
  290. // return TRUE if this is not an exclude sample and its name is same with input
  291. String strSampleName = pSample.GetName();
  292. if (nIndex != a_nExclude && strSampleName.CompareTo(a_strSampleName) == 0)
  293. {
  294. // find a same name sample
  295. return true;
  296. }
  297. ++nIndex;
  298. }
  299. // no, same name sample in the same list, return FALSE
  300. return false;
  301. }
  302. // select a suitable sample hole for a new sample
  303. public CHole SelectASmpleHole(String a_strHoleName /*= _T("")*/)
  304. {
  305. // get holes list of the stage
  306. var m_pStage = GetDefaultParam(). GetStageHolderParam().GetWorkingStage();
  307. List<CHole> listHoles = m_pStage.GetHoleList();
  308. //返回样品孔对象
  309. CHole cReHole ;
  310. // make sure the holes list is not empty
  311. if (listHoles.Count == 0)
  312. {
  313. // shouldn't happen, stage have no hole.
  314. return null;
  315. }
  316. // check the input hole name
  317. a_strHoleName.Trim();
  318. if (a_strHoleName != "")
  319. {
  320. // try to find matched hole
  321. for (int i = 0; i < listHoles.Count; i++)
  322. {
  323. if (listHoles[i].GetName() == a_strHoleName)
  324. {
  325. cReHole = listHoles[i];
  326. return cReHole;
  327. }
  328. }
  329. }
  330. // can't find a matched hole, then pick the first empty hole
  331. // go through the holes list
  332. foreach (var pHole in listHoles)
  333. {
  334. // has this hole any sample in it?
  335. String strHoleName = pHole.GetName();
  336. bool IsChanged = false;
  337. var m_listSamples = GetResultData().GetSampleList();
  338. foreach (COTSSample sampleItem in m_listSamples)
  339. {
  340. if (strHoleName == sampleItem.GetSampleHoleName())
  341. {
  342. IsChanged = true;
  343. }
  344. }
  345. if (!IsChanged)
  346. {
  347. return pHole;
  348. }
  349. }
  350. // no empty hole, then the first hole will be the one
  351. return listHoles[0];
  352. }
  353. public CDomain CalculateDefaultArea(CHole a_pHole)
  354. {
  355. RectangleF rectHole = a_pHole.GetDomainRect();
  356. System.Drawing.PointF ptCenter = new System.Drawing.PointF((rectHole.Left + rectHole.Right) / 2, (rectHole.Top + rectHole.Bottom) / 2);
  357. var m_pParam = GetDefaultParam().GetCommonParam();
  358. DOMAIN_SHAPE nShape = m_pParam.GetShape();
  359. double dArea = m_pParam.GetArea() * 1000000;
  360. System.Drawing.PointF ptLeftTop = new System.Drawing.Point();
  361. System.Drawing.SizeF ptSize = new System.Drawing.Size();
  362. int nEdge = 0;
  363. int nRadius = 0;
  364. switch ((int)nShape)
  365. {
  366. case (int)DOMAIN_SHAPE.RECTANGLE:
  367. nEdge = (int)Math.Sqrt(dArea) / 2;
  368. ptLeftTop.X = ptCenter.X - nEdge;
  369. ptLeftTop.Y = ptCenter.Y - nEdge;
  370. ptSize.Width = ptCenter.X + nEdge - ptLeftTop.X;
  371. ptSize.Height = ptCenter.Y + nEdge - ptLeftTop.Y;
  372. break;
  373. case (int)DOMAIN_SHAPE.ROUND:
  374. nRadius = (int)Math.Sqrt(dArea / 3.1415926);
  375. ptLeftTop.X = ptCenter.X - nRadius;
  376. ptLeftTop.Y = ptCenter.Y - nRadius;
  377. ptSize.Width = ptCenter.X + nRadius - ptLeftTop.X;
  378. ptSize.Height = ptCenter.Y + nRadius - ptLeftTop.Y;
  379. break;
  380. }
  381. RectangleF MsrRect = new RectangleF(ptLeftTop, ptSize);
  382. CDomain pMsrArea = new CDomain(nShape, MsrRect);
  383. return pMsrArea;
  384. }
  385. //设置工作样品的属性值
  386. public bool SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS ItemId, OTS_ITEM_TYPES ValType, object objVal)
  387. {
  388. COTSSample WSample = GetResultData().GetWorkingSample();
  389. OTSSampleVisualPropertyInfo MeasureInfo = new OTSSampleVisualPropertyInfo(WSample, defaultParam.GetSysType());
  390. bool bSetFalg = false;
  391. bSetFalg = MeasureInfo.SetParamVal(ItemId, ValType, objVal);
  392. if (bSetFalg)
  393. {
  394. GetResultData().SetModify(true);
  395. }
  396. return bSetFalg;
  397. }
  398. //获取工作样品名称
  399. public string GetWorkSampleName()
  400. {
  401. COTSSample WSample = GetResultData().GetWorkingSample();
  402. if (null == WSample)
  403. {
  404. return "";
  405. }
  406. string sWorkSampleName = WSample.GetName();
  407. if ("" == sWorkSampleName)
  408. {
  409. return "";
  410. }
  411. return sWorkSampleName;
  412. }
  413. //设置工作样品
  414. //string sNewWorkSampleName: 新工作样品
  415. public bool SetWorkSample(string sNewWorkSampleName)
  416. {
  417. if ("" == sNewWorkSampleName)
  418. {
  419. return false;
  420. }
  421. if (!GetResultData().SetWorkingSampleByName(sNewWorkSampleName))
  422. {
  423. return false;
  424. }
  425. return true;
  426. }
  427. //获取工作样品
  428. // 返回工作样品对象
  429. public COTSSample GetWorkSample()
  430. {
  431. COTSSample WSample = GetResultData().GetWorkingSample();
  432. return WSample;
  433. }
  434. //删除工作样品
  435. //string sWorkSampleName : 删除工作样品名称
  436. public bool DeleteWorkSample(string sWorkSampleName)
  437. {
  438. return GetResultData().DeleteSampleByName(sWorkSampleName);
  439. }
  440. // 获取样品总数
  441. //返回样品总数
  442. public int GetSampleCount()
  443. {
  444. return GetResultData().GetSampleList().Count();
  445. }
  446. //改变工作样品名称
  447. //String sWSampleNewName
  448. public bool ChangeWorkSampleName(String sWSampleNewName)
  449. {
  450. if (!GetResultData().IsValidSampleName(sWSampleNewName))
  451. {
  452. return false;
  453. }
  454. COTSSample WorkSample = GetResultData().GetWorkingSample();
  455. if (null == WorkSample)
  456. {
  457. return false;
  458. }
  459. WorkSample.SetName(sWSampleNewName);
  460. GetResultData().SetModify(true);
  461. return true;
  462. }
  463. //设置测量区域的形状 (通过RIBBON 上的画圆,画矩形 设置)
  464. //int iShape: 测量区域形状 0: 圆形; 1 :矩形
  465. public void SetMeasureAreaShape(ShapeType iShape)
  466. {
  467. COTSSample WSample = GetResultData().GetWorkingSample();
  468. if (null == WSample)
  469. {
  470. return;
  471. }
  472. CDomain Domain = new CDomain();
  473. Domain.SetShape((otsdataconst.DOMAIN_SHAPE)iShape);
  474. }
  475. public bool CheckSampleParam(bool bCheckFlag)
  476. {
  477. m_MeasureSampleList.Clear();
  478. List<COTSSample> MSampleList = new List<COTSSample>();
  479. if (!CheckMeasureParam(GetResultData(), ref MSampleList, bCheckFlag))
  480. {
  481. return false;
  482. }
  483. if (MSampleList.Count > 0)
  484. {
  485. m_MeasureSampleList = MSampleList;
  486. return true;
  487. }
  488. return false;
  489. }
  490. public bool CheckMeasureParam(COTSMsrPrjResultData a_pProjMgrFile, ref List<COTSSample> a_listMeasuableSamples, bool a_bCheckSetting)
  491. {
  492. // go through the sample list to check setting parameters
  493. int nSwitchSmplNo = 0;
  494. int nCompletedSmplNo = 0;
  495. int nErrorSmplNo = 0;
  496. int nWarningSmplNo = 0;
  497. List<String> listSamplMessages = new List<string>();
  498. List<COTSSample> listSamples = a_pProjMgrFile.GetSampleList();
  499. List<COTSSample> listMeasurableSamples = new List<COTSSample>();
  500. List<COTSSample> listWithWarningMeasurableSamples = new List<COTSSample>();
  501. foreach (var pSample in listSamples)
  502. {
  503. // is the sample switch on
  504. if (pSample.GetSwitch())
  505. {
  506. ++nSwitchSmplNo;
  507. String strSmplMessage;
  508. strSmplMessage = pSample.GetName() + ":" + "\r\n";
  509. // is this a measurement completed sample
  510. if (IsMeasureCompletedSmpl(pSample))
  511. { // measurement completed sample
  512. ++nCompletedSmplNo;
  513. string str2 = GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE.FINISHED);
  514. strSmplMessage += str2;
  515. strSmplMessage += "\r\n";
  516. }
  517. else
  518. {
  519. // errors
  520. List<SAMPLE_FAULT_WARN_CODE> a_listErrorCodes = new List<SAMPLE_FAULT_WARN_CODE>();
  521. GetSampleErrorCodes(a_pProjMgrFile, pSample, ref a_listErrorCodes);
  522. if (a_listErrorCodes.Count != 0)
  523. {
  524. // has error, this is not a measurable sample
  525. ++nErrorSmplNo;
  526. foreach (var nErrorCode in a_listErrorCodes)
  527. {
  528. String str3 = GetSampleErrorWarnString(nErrorCode);
  529. strSmplMessage += str3;
  530. strSmplMessage += "\r\n";
  531. }
  532. }
  533. else
  534. {
  535. // no error, this is a measurable sample
  536. listMeasurableSamples.Add(pSample);
  537. }
  538. // warnings
  539. List<SAMPLE_FAULT_WARN_CODE> a_listWarningCodes = new List<SAMPLE_FAULT_WARN_CODE>();
  540. GetSampleWarningCodes(a_pProjMgrFile, pSample, ref a_listWarningCodes);
  541. if (a_listWarningCodes.Count != 0)
  542. {
  543. ++nWarningSmplNo;
  544. foreach (var nWarningCode in a_listWarningCodes)
  545. {
  546. String str3 = GetSampleErrorWarnString(nWarningCode);
  547. strSmplMessage += str3;
  548. strSmplMessage += "\r\n";
  549. }
  550. // has no error?
  551. if (a_listErrorCodes.Count == 0)
  552. {
  553. // this is a measurable sample but with setting warnings
  554. listWithWarningMeasurableSamples.Add(pSample);
  555. }
  556. }
  557. // no error and warning
  558. if (a_listErrorCodes.Count == 0 && a_listWarningCodes.Count == 0)
  559. {
  560. String str3 = GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE.NO_ERROR_WARNING);
  561. strSmplMessage += str3;
  562. strSmplMessage += "\r\n";
  563. }
  564. }
  565. // add
  566. listSamplMessages.Add(strSmplMessage);
  567. }
  568. }
  569. // dlg message string
  570. String strDlgMessage = "";
  571. String str;
  572. String str1;
  573. str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.SWITCH_ON);
  574. str1 = str1.Replace("%d", "{0}");
  575. str = string.Format(str1, nSwitchSmplNo);
  576. strDlgMessage += str;
  577. strDlgMessage += "\r\n";
  578. // add more string if there switch on sample
  579. if (nSwitchSmplNo > 0)
  580. {
  581. // completed sample number (optional)
  582. if (nCompletedSmplNo > 0)
  583. {
  584. str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.FINISHED);
  585. str1 = str1.Replace("%d", "{0}");
  586. str = string.Format(str1, nCompletedSmplNo);
  587. strDlgMessage += str;
  588. strDlgMessage += "\r\n";
  589. }
  590. // any unmeasured switch on samples?
  591. if (nSwitchSmplNo > nCompletedSmplNo)
  592. {
  593. // with setting error sample number
  594. str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.SETTING_ERROR);
  595. str1 = str1.Replace("%d", "{0}");
  596. str = string.Format(str1, nErrorSmplNo);
  597. strDlgMessage += str;
  598. strDlgMessage += "\r\n";
  599. // with setting warning sample number
  600. str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.SETTING_WARNING);
  601. str1 = str1.Replace("%d", "{0}");
  602. str = string.Format(str1, nWarningSmplNo);
  603. strDlgMessage += str;
  604. strDlgMessage += "\r\n";
  605. }
  606. }
  607. // add an empty line strDlgMessage
  608. strDlgMessage += "\r\n";
  609. // add sample messages
  610. foreach (var strSmplMessage in listSamplMessages)
  611. {
  612. strDlgMessage += strSmplMessage;
  613. strDlgMessage += "\r\n";
  614. }
  615. // do we need to show dialog box?
  616. if (nSwitchSmplNo == 0)
  617. {
  618. return false;
  619. }
  620. // measure button clicked?
  621. if (a_bCheckSetting)
  622. {
  623. // there are measurable samples but no setting warnings samples
  624. if (listMeasurableSamples.Count > 0 && listWithWarningMeasurableSamples.Count == 0)
  625. {
  626. // set output measurable samples list
  627. foreach (var pSample in listMeasurableSamples)
  628. {
  629. a_listMeasuableSamples.Add(pSample);
  630. }
  631. return true;
  632. }
  633. }
  634. //when there is sample setting error, and setting with no error and no warning samples, the dlg will not be show.??
  635. //show the result dlg
  636. DIALOG_CHECK_PARAM_RESULT dlg = new DIALOG_CHECK_PARAM_RESULT();
  637. int nTatolMeasuableSmplNo = listMeasurableSamples.Count;
  638. int nWithWarningMeasuableSmplNo = listWithWarningMeasurableSamples.Count;
  639. // set the dlg parameters
  640. dlg.SetCheckOnlyFlag(a_bCheckSetting);
  641. dlg.SetMessageBase(strDlgMessage);
  642. dlg.SetTatolMeasuableSmplNo(nTatolMeasuableSmplNo);
  643. dlg.SetWithWarningMeasuableSmplNo(nWithWarningMeasuableSmplNo);
  644. //no error not show dlg
  645. if (nTatolMeasuableSmplNo == nSwitchSmplNo - nCompletedSmplNo && listMeasurableSamples.Count != 0)
  646. {
  647. foreach (var pSample in listMeasurableSamples)
  648. {
  649. var itr = listWithWarningMeasurableSamples.Find(s => { return s.GetName() == pSample.GetName(); });
  650. if (itr == null)
  651. {
  652. a_listMeasuableSamples.Add(pSample);
  653. }
  654. }
  655. if (a_listMeasuableSamples.Count == listMeasurableSamples.Count)
  656. {
  657. return true;
  658. }
  659. }
  660. //show dlg
  661. DialogResult dResult = dlg.ShowDialog();
  662. if (!(dResult == System.Windows.Forms.DialogResult.OK))
  663. {
  664. // do something here
  665. return false;
  666. }
  667. else
  668. {
  669. //if warnDo, back the listMeasuableSample
  670. if (dlg.GetWarnDo())
  671. {
  672. foreach (var pSample in listMeasurableSamples)
  673. {
  674. a_listMeasuableSamples.Add(pSample);
  675. }
  676. }
  677. else // back with no warn sample
  678. {
  679. foreach (var pSample in listMeasurableSamples)
  680. {
  681. var itr = listWithWarningMeasurableSamples.Find(e => { return e.GetName() == pSample.GetName(); });
  682. if (itr == null)
  683. {
  684. a_listMeasuableSamples.Add(pSample);
  685. }
  686. }
  687. }
  688. }
  689. return true;
  690. }
  691. bool IsMeasureCompletedSmpl(COTSSample a_pSample)
  692. {
  693. if (a_pSample.GetMsrStatus().GetStatus() != OTSDataType.OTS_MSR_SAMPLE_STATUS.COMPLETED)
  694. {
  695. return false;
  696. }
  697. return true;
  698. }
  699. string GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE a_nSampleFaultWarn)
  700. {
  701. // check input
  702. if (a_nSampleFaultWarn < SAMPLE_FAULT_WARN_CODE.MIN && a_nSampleFaultWarn > SAMPLE_FAULT_WARN_CODE.MAX)
  703. {
  704. return "";
  705. }
  706. // error/waring string
  707. string strErrorWarn;
  708. strErrorWarn = GetResourceByKey(GrpOtherParam, IDS_ERROR_WARNING + (int)a_nSampleFaultWarn);
  709. return strErrorWarn;
  710. }
  711. // get error codes list of a sample
  712. void GetSampleErrorCodes(COTSMsrPrjResultData a_pProjMgrFile, COTSSample a_pSample, ref List<SAMPLE_FAULT_WARN_CODE> a_listErrorCodes)
  713. {
  714. const string UNTITLED_FILE_NAME = "Untitled";
  715. // file has not been saved
  716. String strPathName = a_pProjMgrFile.GetPathName();
  717. // is this a file no saved?
  718. strPathName.Trim();
  719. if (strPathName == UNTITLED_FILE_NAME || strPathName == "")
  720. {
  721. a_listErrorCodes.Add(SAMPLE_FAULT_WARN_CODE.FILE_NOT_SAVED);
  722. }
  723. }
  724. // get warning codes list of a sample
  725. void GetSampleWarningCodes(COTSMsrPrjResultData a_pProjMgrFile, COTSSample a_pSample, ref List<SAMPLE_FAULT_WARN_CODE> a_listWarningCodes)
  726. {
  727. // get the work stage
  728. CSampleHolder pStage = a_pProjMgrFile.GetStageHolder();
  729. //get hole
  730. String sHoleName = a_pSample.GetSampleHoleName();
  731. //look for the hole Domain
  732. CHole pSampleHole = pStage.GetHoleByName(sHoleName);
  733. if (pSampleHole == null)
  734. {
  735. return;
  736. }
  737. if (a_pSample.GetSEMDataMsr() != null)
  738. {
  739. // compute pixel size
  740. double dPixleSize = a_pSample.CalculatePixelSize();
  741. // get min size
  742. COTSImageProcParam pImageProcParam = a_pSample.GetMsrParams().GetImageProcessParam();
  743. double dMinSize = pImageProcParam.GetIncAreaRange().GetStart();
  744. // if pixel size is bigger than 1/2 of the min size,than can't see the object clearly on current magnification
  745. if (dPixleSize >= dMinSize * 0.5)
  746. {
  747. // resolution low
  748. a_listWarningCodes.Add(SAMPLE_FAULT_WARN_CODE.RESOLUTION_LOW);
  749. }
  750. }
  751. if(a_pSample.GetSEMDataMsr().GetTotalFields()==0
  752. && a_pSample.GetSEMDataMsr().GetScanFieldSize() == 0
  753. && a_pSample.GetSEMDataMsr().GetWorkingDistance() == 0)
  754. {
  755. // SEM_DATA_ERROR
  756. a_listWarningCodes.Add(SAMPLE_FAULT_WARN_CODE.SEM_DATA_ERROR);
  757. }
  758. }
  759. //打开工作样品的测量参数文件
  760. public bool LoadWorkMeasureFile()
  761. {
  762. CSampleParamMgr SMeasureParamData = new CSampleParamMgr();
  763. OpenFileDialog openFileDialog = new OpenFileDialog();
  764. openFileDialog.Filter = SMeasureParamData.MESUREMENT_PARAM_FILE_FILTER;
  765. if (openFileDialog.ShowDialog() != DialogResult.OK)
  766. {
  767. return false;
  768. }
  769. // get file pathname
  770. string strPathName = openFileDialog.FileName;
  771. if (!SMeasureParamData.Load(strPathName, true))
  772. {
  773. return false;
  774. }
  775. COTSSample WSample = GetResultData().GetWorkingSample();
  776. if (null == WSample)
  777. {
  778. return false;
  779. }
  780. WSample.SetMsrParams(SMeasureParamData.GetMsrParams());
  781. //更新样品GRID值测量文件名
  782. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(WSample,defaultParam.GetSysType());
  783. m_MeasureAppFrom.m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  784. return true;
  785. }
  786. //判断是否允许修改样品名
  787. public bool CheckSampleNameIsValid(string sNewName)
  788. {
  789. return GetResultData().IsValidSampleName(sNewName);
  790. }
  791. //设置电镜参数
  792. //int iScanFieldSize: Field扫描参数
  793. //int iWDistance: 电镜工作距离
  794. //double dMagni: 放大倍数
  795. public void SetWorkingSampleSEMData(double iWDistance, double dMagni,double bri,double contra,double kv)
  796. {
  797. var semdata = GetResultData().GetWorkingSample().GetSEMDataMsr();
  798. semdata.SetWorkingDistance(iWDistance);
  799. semdata.SetMagnification(dMagni);
  800. semdata.Brightness = bri;
  801. semdata.Contrast = contra;
  802. semdata.KV = kv;
  803. }
  804. public bool GetWorkingSampleSEMData(ref double iWDistance, ref double dMagni, ref double bri, ref double contra, ref double kv)
  805. {
  806. COTSSample WSample = GetResultData().GetWorkingSample();
  807. if (null == WSample)
  808. {
  809. return false;
  810. }
  811. var semdata = GetResultData().GetWorkingSample().GetSEMDataMsr();
  812. iWDistance = semdata.GetWorkingDistance();
  813. dMagni = semdata.GetMagnification();
  814. bri = semdata.Brightness;
  815. contra = semdata.Contrast;
  816. kv = semdata.KV;
  817. return true;
  818. }
  819. //检查Samplelist中的sample的checkbox状态
  820. //当Samplelist中的链表有sample 的checkbox状态是选中状态,则返回TRUE. 说明可以测量
  821. public bool GetSampleCheckBoxStatus()
  822. {
  823. COTSSample WSample = GetResultData().GetWorkingSample();
  824. if (null == WSample)
  825. {
  826. return false;
  827. }
  828. List<COTSSample> SampleList = new List<COTSSample>();
  829. SampleList = GetResultData().GetSampleList();
  830. int iCount = SampleList.Count();
  831. if (0 == iCount)
  832. {
  833. return false;
  834. }
  835. for (int i = 0; i < iCount; i++)
  836. {
  837. if (SampleList[i].GetSwitch())
  838. {
  839. return true;
  840. }
  841. }
  842. return false;
  843. }
  844. //获取BSE图像数据
  845. public bool GetBSEImageSize(ref int iHeight, ref int iWidth)
  846. {
  847. COTSSample WSample = GetResultData().GetWorkingSample();
  848. if (null == WSample)
  849. {
  850. return false;
  851. }
  852. if (!WSample.GetBSESize(out iHeight, out iWidth))
  853. {
  854. return false;
  855. }
  856. return true;
  857. }
  858. //获取图像尺寸
  859. public string GetBSEImageResolutionStr()
  860. {
  861. try
  862. {
  863. COTSSample WSample = GetResultData().GetWorkingSample();
  864. var res= WSample.GetMsrParams().GetImageScanParam().GetImageResolutionSize();
  865. return res.cx+"X"+res.cy;
  866. }
  867. catch (Exception)
  868. {
  869. return "";
  870. }
  871. }
  872. //获取测量Sample的开始时间
  873. public bool GetMsrSampleStartTime(ref DateTime MsrFieldStartTime)
  874. {
  875. COTSSample WSample = GetResultData().GetWorkingSample();
  876. if (null == WSample)
  877. {
  878. return false;
  879. }
  880. MsrFieldStartTime = (DateTime)WSample.GetMsrStatus().GetStartTime();
  881. return true;
  882. }
  883. //获取测量已用时间
  884. public bool GetMsrSampleUsedTime(ref TimeSpan TUsedTime)
  885. {
  886. COTSSample WSample = GetResultData().GetWorkingSample();
  887. if (null == WSample)
  888. {
  889. return false;
  890. }
  891. TUsedTime = (TimeSpan)WSample.GetMsrStatus().GetUsedTime();
  892. return true;
  893. }
  894. // 获取测量样品中之前已经测量完成Field帧图,(上一次未测量完成继续测试)
  895. public bool GetBeforeCompleteField(ref string MsrSampleName, ref List<PointF> FieldList)
  896. {
  897. COTSSample WSample = GetResultData().GetWorkingSample();
  898. if (null == WSample)
  899. {
  900. return false;
  901. }
  902. MsrSampleName = WSample.GetName();
  903. FieldList = WSample.GetMsrStatus().GetCompletedFieldsCenter();
  904. return true;
  905. }
  906. /// <summary>
  907. /// 获取已完成测量的结果文件路径
  908. /// </summary>
  909. /// <param name="mrFilePathList">返回测量结果文件路径</param>
  910. /// <returns></returns>
  911. public bool GetCompletedMeasureFileName(ref List<string> mrFilePathList)
  912. {
  913. //测量文件路径
  914. string proFilePath = GetResultData().GetPathName();
  915. //样品列表
  916. List<COTSSample> sampleList = GetResultData().GetSampleList();
  917. //获取样品数量
  918. int sampleCount = sampleList.Count;
  919. string mrSuffix = ".rst";
  920. int existsCount = 0;
  921. //获取测量文件路径
  922. if (proFilePath.Equals("Untitled"))
  923. {
  924. return false;
  925. }
  926. string mrFolderPath = string.Empty;
  927. try
  928. {
  929. mrFolderPath = proFilePath.Substring(0, proFilePath.LastIndexOf("\\"));
  930. }
  931. catch (Exception)
  932. {
  933. mrFolderPath = string.Empty;
  934. }
  935. for (int sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++)
  936. {
  937. int CompleteFieldsCount = sampleList[sampleIndex].GetMsrStatus().GetCompletedFields();
  938. //如果样品已测量成功后再加载至报告程序中
  939. if (CompleteFieldsCount > 0)
  940. {
  941. string sampleName = sampleList[sampleIndex].GetName();
  942. string mrFilePath = mrFolderPath + "\\" + sampleName + "\\" + sampleName + mrSuffix;
  943. //判断文件是否存在
  944. if (File.Exists(mrFilePath))
  945. {
  946. if (mrFilePathList != null)
  947. {
  948. mrFilePathList.Add(mrFilePath);
  949. }
  950. existsCount++;
  951. }
  952. }
  953. }
  954. if (existsCount > 0)
  955. {
  956. return true;
  957. }
  958. return false;
  959. }
  960. }
  961. }