COTSMeasureParam.cs 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  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. // safety check
  694. if (a_pSample.GetMsrStatus().GetStatus() != OTSDataType.OTS_MSR_SAMPLE_STATUS.SUCCESSED)
  695. {
  696. return false;
  697. }
  698. return true;
  699. }
  700. string GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE a_nSampleFaultWarn)
  701. {
  702. // check input
  703. if (a_nSampleFaultWarn < SAMPLE_FAULT_WARN_CODE.MIN && a_nSampleFaultWarn > SAMPLE_FAULT_WARN_CODE.MAX)
  704. {
  705. return "";
  706. }
  707. // error/waring string
  708. string strErrorWarn;
  709. strErrorWarn = GetResourceByKey(GrpOtherParam, IDS_ERROR_WARNING + (int)a_nSampleFaultWarn);
  710. return strErrorWarn;
  711. }
  712. // get error codes list of a sample
  713. void GetSampleErrorCodes(COTSMsrPrjResultData a_pProjMgrFile, COTSSample a_pSample, ref List<SAMPLE_FAULT_WARN_CODE> a_listErrorCodes)
  714. {
  715. const string UNTITLED_FILE_NAME = "Untitled";
  716. // file has not been saved
  717. String strPathName = a_pProjMgrFile.GetPathName();
  718. // is this a file no saved?
  719. strPathName.Trim();
  720. if (strPathName == UNTITLED_FILE_NAME || strPathName == "")
  721. {
  722. a_listErrorCodes.Add(SAMPLE_FAULT_WARN_CODE.FILE_NOT_SAVED);
  723. }
  724. }
  725. // get warning codes list of a sample
  726. void GetSampleWarningCodes(COTSMsrPrjResultData a_pProjMgrFile, COTSSample a_pSample, ref List<SAMPLE_FAULT_WARN_CODE> a_listWarningCodes)
  727. {
  728. // get the work stage
  729. CSampleHolder pStage = a_pProjMgrFile.GetStageHolder();
  730. //get hole
  731. String sHoleName = a_pSample.GetSampleHoleName();
  732. //look for the hole Domain
  733. CHole pSampleHole = pStage.GetHoleByName(sHoleName);
  734. if (pSampleHole == null)
  735. {
  736. return;
  737. }
  738. if (a_pSample.GetSEMDataMsr() != null)
  739. {
  740. // compute pixel size
  741. double dPixleSize = a_pSample.CalculatePixelSize();
  742. // get min size
  743. COTSImageProcParam pImageProcParam = a_pSample.GetMsrParams().GetImageProcessParam();
  744. double dMinSize = pImageProcParam.GetIncAreaRange().GetStart();
  745. // if pixel size is bigger than 1/2 of the min size,than can't see the object clearly on current magnification
  746. if (dPixleSize >= dMinSize * 0.5)
  747. {
  748. // resolution low
  749. a_listWarningCodes.Add(SAMPLE_FAULT_WARN_CODE.RESOLUTION_LOW);
  750. }
  751. }
  752. if(a_pSample.GetSEMDataMsr().GetTotalFields()==0
  753. && a_pSample.GetSEMDataMsr().GetScanFieldSize() == 0
  754. && a_pSample.GetSEMDataMsr().GetWorkingDistance() == 0)
  755. {
  756. // SEM_DATA_ERROR
  757. a_listWarningCodes.Add(SAMPLE_FAULT_WARN_CODE.SEM_DATA_ERROR);
  758. }
  759. }
  760. //打开工作样品的测量参数文件
  761. public bool LoadWorkMeasureFile()
  762. {
  763. CSampleParamMgr SMeasureParamData = new CSampleParamMgr();
  764. OpenFileDialog openFileDialog = new OpenFileDialog();
  765. openFileDialog.Filter = SMeasureParamData.MESUREMENT_PARAM_FILE_FILTER;
  766. if (openFileDialog.ShowDialog() != DialogResult.OK)
  767. {
  768. return false;
  769. }
  770. // get file pathname
  771. string strPathName = openFileDialog.FileName;
  772. if (!SMeasureParamData.Load(strPathName, true))
  773. {
  774. return false;
  775. }
  776. COTSSample WSample = GetResultData().GetWorkingSample();
  777. if (null == WSample)
  778. {
  779. return false;
  780. }
  781. WSample.SetMsrParams(SMeasureParamData.GetMsrParams());
  782. //更新样品GRID值测量文件名
  783. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(WSample,defaultParam.GetSysType());
  784. m_MeasureAppFrom.m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  785. return true;
  786. }
  787. //判断是否允许修改样品名
  788. public bool CheckSampleNameIsValid(string sNewName)
  789. {
  790. return GetResultData().IsValidSampleName(sNewName);
  791. }
  792. //设置电镜参数
  793. //int iScanFieldSize: Field扫描参数
  794. //int iWDistance: 电镜工作距离
  795. //double dMagni: 放大倍数
  796. public void SetWorkingSampleSEMData(double iWDistance, double dMagni,double bri,double contra,double kv)
  797. {
  798. var semdata = GetResultData().GetWorkingSample().GetSEMDataMsr();
  799. semdata.SetWorkingDistance(iWDistance);
  800. semdata.SetMagnification(dMagni);
  801. semdata.Brightness = bri;
  802. semdata.Contrast = contra;
  803. semdata.KV = kv;
  804. }
  805. public bool GetWorkingSampleSEMData(ref double iWDistance, ref double dMagni, ref double bri, ref double contra, ref double kv)
  806. {
  807. COTSSample WSample = GetResultData().GetWorkingSample();
  808. if (null == WSample)
  809. {
  810. return false;
  811. }
  812. var semdata = GetResultData().GetWorkingSample().GetSEMDataMsr();
  813. iWDistance = semdata.GetWorkingDistance();
  814. dMagni = semdata.GetMagnification();
  815. bri = semdata.Brightness;
  816. contra = semdata.Contrast;
  817. kv = semdata.KV;
  818. return true;
  819. }
  820. //检查Samplelist中的sample的checkbox状态
  821. //当Samplelist中的链表有sample 的checkbox状态是选中状态,则返回TRUE. 说明可以测量
  822. public bool GetSampleCheckBoxStatus()
  823. {
  824. COTSSample WSample = GetResultData().GetWorkingSample();
  825. if (null == WSample)
  826. {
  827. return false;
  828. }
  829. List<COTSSample> SampleList = new List<COTSSample>();
  830. SampleList = GetResultData().GetSampleList();
  831. int iCount = SampleList.Count();
  832. if (0 == iCount)
  833. {
  834. return false;
  835. }
  836. for (int i = 0; i < iCount; i++)
  837. {
  838. if (SampleList[i].GetSwitch())
  839. {
  840. return true;
  841. }
  842. }
  843. return false;
  844. }
  845. //获取BSE图像数据
  846. public bool GetBSEImageSize(ref int iHeight, ref int iWidth)
  847. {
  848. COTSSample WSample = GetResultData().GetWorkingSample();
  849. if (null == WSample)
  850. {
  851. return false;
  852. }
  853. if (!WSample.GetBSESize(out iHeight, out iWidth))
  854. {
  855. return false;
  856. }
  857. return true;
  858. }
  859. //获取图像尺寸
  860. public string GetBSEImageResolutionStr()
  861. {
  862. try
  863. {
  864. COTSSample WSample = GetResultData().GetWorkingSample();
  865. var res= WSample.GetMsrParams().GetImageScanParam().GetImageResolutionSize();
  866. return res.cx+"X"+res.cy;
  867. }
  868. catch (Exception)
  869. {
  870. return "";
  871. }
  872. }
  873. //获取测量Sample的开始时间
  874. public bool GetMsrSampleStartTime(ref DateTime MsrFieldStartTime)
  875. {
  876. COTSSample WSample = GetResultData().GetWorkingSample();
  877. if (null == WSample)
  878. {
  879. return false;
  880. }
  881. MsrFieldStartTime = (DateTime)WSample.GetMsrStatus().GetStartTime();
  882. return true;
  883. }
  884. //获取测量已用时间
  885. public bool GetMsrSampleUsedTime(ref TimeSpan TUsedTime)
  886. {
  887. COTSSample WSample = GetResultData().GetWorkingSample();
  888. if (null == WSample)
  889. {
  890. return false;
  891. }
  892. TUsedTime = (TimeSpan)WSample.GetMsrStatus().GetUsedTime();
  893. return true;
  894. }
  895. // 获取测量样品中之前已经测量完成Field帧图,(上一次未测量完成继续测试)
  896. public bool GetBeforeCompleteField(ref string MsrSampleName, ref List<PointF> FieldList)
  897. {
  898. COTSSample WSample = GetResultData().GetWorkingSample();
  899. if (null == WSample)
  900. {
  901. return false;
  902. }
  903. MsrSampleName = WSample.GetName();
  904. FieldList = WSample.GetMsrStatus().GetCompletedFieldsCenter();
  905. return true;
  906. }
  907. /// <summary>
  908. /// 获取已完成测量的结果文件路径
  909. /// </summary>
  910. /// <param name="mrFilePathList">返回测量结果文件路径</param>
  911. /// <returns></returns>
  912. public bool GetCompletedMeasureFileName(ref List<string> mrFilePathList)
  913. {
  914. //测量文件路径
  915. string proFilePath = GetResultData().GetPathName();
  916. //样品列表
  917. List<COTSSample> sampleList = GetResultData().GetSampleList();
  918. //获取样品数量
  919. int sampleCount = sampleList.Count;
  920. string mrSuffix = ".rst";
  921. int existsCount = 0;
  922. //获取测量文件路径
  923. if (proFilePath.Equals("Untitled"))
  924. {
  925. return false;
  926. }
  927. string mrFolderPath = string.Empty;
  928. try
  929. {
  930. mrFolderPath = proFilePath.Substring(0, proFilePath.LastIndexOf("\\"));
  931. }
  932. catch (Exception)
  933. {
  934. mrFolderPath = string.Empty;
  935. }
  936. for (int sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++)
  937. {
  938. int CompleteFieldsCount = sampleList[sampleIndex].GetMsrStatus().GetCompletedFields();
  939. //如果样品已测量成功后再加载至报告程序中
  940. if (CompleteFieldsCount > 0)
  941. {
  942. string sampleName = sampleList[sampleIndex].GetName();
  943. string mrFilePath = mrFolderPath + "\\" + sampleName + "\\" + sampleName + mrSuffix;
  944. //判断文件是否存在
  945. if (File.Exists(mrFilePath))
  946. {
  947. if (mrFilePathList != null)
  948. {
  949. mrFilePathList.Add(mrFilePath);
  950. }
  951. existsCount++;
  952. }
  953. }
  954. }
  955. if (existsCount > 0)
  956. {
  957. return true;
  958. }
  959. return false;
  960. }
  961. }
  962. }