COTSMeasureParam.cs 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  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. RUNSampleHoleImage = 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.SetSpecialGrayRangeParam(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. //移动工作样品到其他样品孔,样品孔名称和测量区域都要改变,重新设置工作样品参数
  464. public void SetWorkSampleHoleAndMeasureArea(SampleMeasurePara SMeasurePara)
  465. {
  466. COTSSample WSample = GetResultData().GetWorkingSample();
  467. if (null == WSample)
  468. {
  469. return ;
  470. }
  471. CDomain Domain = new CDomain();
  472. Domain.SetShape((otsdataconst.DOMAIN_SHAPE)SMeasurePara.iShape);
  473. Domain.SetRectDomain(SMeasurePara.MeasureRect);
  474. if (SMeasurePara.DrawPolygonPointList != null)
  475. {
  476. List<Point> PolygonPoint = new List<Point>();
  477. foreach (var item in SMeasurePara.DrawPolygonPointList)
  478. {
  479. PolygonPoint.Add(new Point((int)item.X, (int)item.Y));
  480. }
  481. Domain.SetPolygonPoint(PolygonPoint);
  482. }
  483. WSample.SetSampleHoleName(SMeasurePara.sampleHoleName);
  484. WSample.SetMsrDomain(Domain);
  485. return ;
  486. }
  487. //设置测量区域的形状 (通过RIBBON 上的画圆,画矩形 设置)
  488. //int iShape: 测量区域形状 0: 圆形; 1 :矩形
  489. public void SetMeasureAreaShape(ShapeType iShape)
  490. {
  491. COTSSample WSample = GetResultData().GetWorkingSample();
  492. if (null == WSample)
  493. {
  494. return;
  495. }
  496. CDomain Domain = new CDomain();
  497. Domain.SetShape((otsdataconst.DOMAIN_SHAPE)iShape);
  498. }
  499. public bool CheckSampleParam(bool bCheckFlag)
  500. {
  501. m_MeasureSampleList.Clear();
  502. List<COTSSample> MSampleList = new List<COTSSample>();
  503. if (!CheckMeasureParam(GetResultData(), ref MSampleList, bCheckFlag))
  504. {
  505. return false;
  506. }
  507. if (MSampleList.Count > 0)
  508. {
  509. m_MeasureSampleList = MSampleList;
  510. return true;
  511. }
  512. return false;
  513. }
  514. public bool CheckMeasureParam(COTSMsrPrjResultData a_pProjMgrFile, ref List<COTSSample> a_listMeasuableSamples, bool a_bCheckSetting)
  515. {
  516. // go through the sample list to check setting parameters
  517. int nSwitchSmplNo = 0;
  518. int nCompletedSmplNo = 0;
  519. int nErrorSmplNo = 0;
  520. int nWarningSmplNo = 0;
  521. List<String> listSamplMessages = new List<string>();
  522. List<COTSSample> listSamples = a_pProjMgrFile.GetSampleList();
  523. List<COTSSample> listMeasurableSamples = new List<COTSSample>();
  524. List<COTSSample> listWithWarningMeasurableSamples = new List<COTSSample>();
  525. foreach (var pSample in listSamples)
  526. {
  527. // is the sample switch on
  528. if (pSample.GetSwitch())
  529. {
  530. ++nSwitchSmplNo;
  531. String strSmplMessage;
  532. strSmplMessage = pSample.GetName() + ":" + "\r\n";
  533. // is this a measurement completed sample
  534. if (IsMeasureCompletedSmpl(pSample))
  535. { // measurement completed sample
  536. ++nCompletedSmplNo;
  537. string str2 = GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE.FINISHED);
  538. strSmplMessage += str2;
  539. strSmplMessage += "\r\n";
  540. }
  541. else
  542. {
  543. // errors
  544. List<SAMPLE_FAULT_WARN_CODE> a_listErrorCodes = new List<SAMPLE_FAULT_WARN_CODE>();
  545. GetSampleErrorCodes(a_pProjMgrFile, pSample, ref a_listErrorCodes);
  546. if (a_listErrorCodes.Count != 0)
  547. {
  548. // has error, this is not a measurable sample
  549. ++nErrorSmplNo;
  550. foreach (var nErrorCode in a_listErrorCodes)
  551. {
  552. String str3 = GetSampleErrorWarnString(nErrorCode);
  553. strSmplMessage += str3;
  554. strSmplMessage += "\r\n";
  555. }
  556. }
  557. else
  558. {
  559. // no error, this is a measurable sample
  560. listMeasurableSamples.Add(pSample);
  561. }
  562. // warnings
  563. List<SAMPLE_FAULT_WARN_CODE> a_listWarningCodes = new List<SAMPLE_FAULT_WARN_CODE>();
  564. GetSampleWarningCodes(a_pProjMgrFile, pSample, ref a_listWarningCodes);
  565. if (a_listWarningCodes.Count != 0)
  566. {
  567. ++nWarningSmplNo;
  568. foreach (var nWarningCode in a_listWarningCodes)
  569. {
  570. String str3 = GetSampleErrorWarnString(nWarningCode);
  571. strSmplMessage += str3;
  572. strSmplMessage += "\r\n";
  573. }
  574. // has no error?
  575. if (a_listErrorCodes.Count == 0)
  576. {
  577. // this is a measurable sample but with setting warnings
  578. listWithWarningMeasurableSamples.Add(pSample);
  579. }
  580. }
  581. // no error and warning
  582. if (a_listErrorCodes.Count == 0 && a_listWarningCodes.Count == 0)
  583. {
  584. String str3 = GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE.NO_ERROR_WARNING);
  585. strSmplMessage += str3;
  586. strSmplMessage += "\r\n";
  587. }
  588. }
  589. // add
  590. listSamplMessages.Add(strSmplMessage);
  591. }
  592. }
  593. // dlg message string
  594. String strDlgMessage = "";
  595. String str;
  596. String str1;
  597. str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.SWITCH_ON);
  598. str1 = str1.Replace("%d", "{0}");
  599. str = string.Format(str1, nSwitchSmplNo);
  600. strDlgMessage += str;
  601. strDlgMessage += "\r\n";
  602. // add more string if there switch on sample
  603. if (nSwitchSmplNo > 0)
  604. {
  605. // completed sample number (optional)
  606. if (nCompletedSmplNo > 0)
  607. {
  608. str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.FINISHED);
  609. str1 = str1.Replace("%d", "{0}");
  610. str = string.Format(str1, nCompletedSmplNo);
  611. strDlgMessage += str;
  612. strDlgMessage += "\r\n";
  613. }
  614. // any unmeasured switch on samples?
  615. if (nSwitchSmplNo > nCompletedSmplNo)
  616. {
  617. // with setting error sample number
  618. str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.SETTING_ERROR);
  619. str1 = str1.Replace("%d", "{0}");
  620. str = string.Format(str1, nErrorSmplNo);
  621. strDlgMessage += str;
  622. strDlgMessage += "\r\n";
  623. // with setting warning sample number
  624. str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.SETTING_WARNING);
  625. str1 = str1.Replace("%d", "{0}");
  626. str = string.Format(str1, nWarningSmplNo);
  627. strDlgMessage += str;
  628. strDlgMessage += "\r\n";
  629. }
  630. }
  631. // add an empty line strDlgMessage
  632. strDlgMessage += "\r\n";
  633. // add sample messages
  634. foreach (var strSmplMessage in listSamplMessages)
  635. {
  636. strDlgMessage += strSmplMessage;
  637. strDlgMessage += "\r\n";
  638. }
  639. // do we need to show dialog box?
  640. if (nSwitchSmplNo == 0)
  641. {
  642. return false;
  643. }
  644. // measure button clicked?
  645. if (a_bCheckSetting)
  646. {
  647. // there are measurable samples but no setting warnings samples
  648. if (listMeasurableSamples.Count > 0 && listWithWarningMeasurableSamples.Count == 0)
  649. {
  650. // set output measurable samples list
  651. foreach (var pSample in listMeasurableSamples)
  652. {
  653. a_listMeasuableSamples.Add(pSample);
  654. }
  655. return true;
  656. }
  657. }
  658. //when there is sample setting error, and setting with no error and no warning samples, the dlg will not be show.??
  659. //show the result dlg
  660. DIALOG_CHECK_PARAM_RESULT dlg = new DIALOG_CHECK_PARAM_RESULT();
  661. int nTatolMeasuableSmplNo = listMeasurableSamples.Count;
  662. int nWithWarningMeasuableSmplNo = listWithWarningMeasurableSamples.Count;
  663. // set the dlg parameters
  664. dlg.SetCheckOnlyFlag(a_bCheckSetting);
  665. dlg.SetMessageBase(strDlgMessage);
  666. dlg.SetTatolMeasuableSmplNo(nTatolMeasuableSmplNo);
  667. dlg.SetWithWarningMeasuableSmplNo(nWithWarningMeasuableSmplNo);
  668. //no error not show dlg
  669. if (nTatolMeasuableSmplNo == nSwitchSmplNo - nCompletedSmplNo && listMeasurableSamples.Count != 0)
  670. {
  671. foreach (var pSample in listMeasurableSamples)
  672. {
  673. var itr = listWithWarningMeasurableSamples.Find(s => { return s.GetName() == pSample.GetName(); });
  674. if (itr == null)
  675. {
  676. a_listMeasuableSamples.Add(pSample);
  677. }
  678. }
  679. if (a_listMeasuableSamples.Count == listMeasurableSamples.Count)
  680. {
  681. return true;
  682. }
  683. }
  684. //show dlg
  685. DialogResult dResult = dlg.ShowDialog();
  686. if (!(dResult == System.Windows.Forms.DialogResult.OK))
  687. {
  688. // do something here
  689. return false;
  690. }
  691. else
  692. {
  693. //if warnDo, back the listMeasuableSample
  694. if (dlg.GetWarnDo())
  695. {
  696. foreach (var pSample in listMeasurableSamples)
  697. {
  698. a_listMeasuableSamples.Add(pSample);
  699. }
  700. }
  701. else // back with no warn sample
  702. {
  703. foreach (var pSample in listMeasurableSamples)
  704. {
  705. var itr = listWithWarningMeasurableSamples.Find(e => { return e.GetName() == pSample.GetName(); });
  706. if (itr == null)
  707. {
  708. a_listMeasuableSamples.Add(pSample);
  709. }
  710. }
  711. }
  712. }
  713. return true;
  714. }
  715. bool IsMeasureCompletedSmpl(COTSSample a_pSample)
  716. {
  717. // safety check
  718. if (a_pSample.GetMsrStatus().GetStatus() != OTSDataType.OTS_MSR_SAMPLE_STATUS.SUCCESSED)
  719. {
  720. return false;
  721. }
  722. return true;
  723. }
  724. string GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE a_nSampleFaultWarn)
  725. {
  726. // check input
  727. if (a_nSampleFaultWarn < SAMPLE_FAULT_WARN_CODE.MIN && a_nSampleFaultWarn > SAMPLE_FAULT_WARN_CODE.MAX)
  728. {
  729. return "";
  730. }
  731. // error/waring string
  732. string strErrorWarn;
  733. strErrorWarn = GetResourceByKey(GrpOtherParam, IDS_ERROR_WARNING + (int)a_nSampleFaultWarn);
  734. return strErrorWarn;
  735. }
  736. // get error codes list of a sample
  737. void GetSampleErrorCodes(COTSMsrPrjResultData a_pProjMgrFile, COTSSample a_pSample, ref List<SAMPLE_FAULT_WARN_CODE> a_listErrorCodes)
  738. {
  739. const string UNTITLED_FILE_NAME = "Untitled";
  740. // file has not been saved
  741. String strPathName = a_pProjMgrFile.GetPathName();
  742. // is this a file no saved?
  743. strPathName.Trim();
  744. if (strPathName == UNTITLED_FILE_NAME || strPathName == "")
  745. {
  746. a_listErrorCodes.Add(SAMPLE_FAULT_WARN_CODE.FILE_NOT_SAVED);
  747. }
  748. }
  749. // get warning codes list of a sample
  750. void GetSampleWarningCodes(COTSMsrPrjResultData a_pProjMgrFile, COTSSample a_pSample, ref List<SAMPLE_FAULT_WARN_CODE> a_listWarningCodes)
  751. {
  752. // get the work stage
  753. CSampleHolder pStage = a_pProjMgrFile.GetStageHolder();
  754. //get hole
  755. String sHoleName = a_pSample.GetSampleHoleName();
  756. //look for the hole Domain
  757. CHole pSampleHole = pStage.GetHoleByName(sHoleName);
  758. if (pSampleHole == null)
  759. {
  760. return;
  761. }
  762. if (a_pSample.GetSEMDataMsr() != null)
  763. {
  764. // compute pixel size
  765. double dPixleSize = a_pSample.CalculatePixelSize();
  766. // get min size
  767. COTSImageProcParam pImageProcParam = a_pSample.GetMsrParams().GetImageProcessParam();
  768. double dMinSize = pImageProcParam.GetIncAreaRange().GetStart();
  769. // if pixel size is bigger than 1/2 of the min size,than can't see the object clearly on current magnification
  770. if (dPixleSize >= dMinSize * 0.5)
  771. {
  772. // resolution low
  773. a_listWarningCodes.Add(SAMPLE_FAULT_WARN_CODE.RESOLUTION_LOW);
  774. }
  775. }
  776. if(a_pSample.GetSEMDataMsr().GetTotalFields()==0
  777. && a_pSample.GetSEMDataMsr().GetScanFieldSize() == 0
  778. && a_pSample.GetSEMDataMsr().GetWorkingDistance() == 0)
  779. {
  780. // SEM_DATA_ERROR
  781. a_listWarningCodes.Add(SAMPLE_FAULT_WARN_CODE.SEM_DATA_ERROR);
  782. }
  783. }
  784. //打开工作样品的测量参数文件
  785. public bool LoadWorkMeasureFile()
  786. {
  787. CSampleParamMgr SMeasureParamData = new CSampleParamMgr();
  788. OpenFileDialog openFileDialog = new OpenFileDialog();
  789. openFileDialog.Filter = SMeasureParamData.MESUREMENT_PARAM_FILE_FILTER;
  790. if (openFileDialog.ShowDialog() != DialogResult.OK)
  791. {
  792. return false;
  793. }
  794. // get file pathname
  795. string strPathName = openFileDialog.FileName;
  796. if (!SMeasureParamData.Load(strPathName, true))
  797. {
  798. return false;
  799. }
  800. COTSSample WSample = GetResultData().GetWorkingSample();
  801. if (null == WSample)
  802. {
  803. return false;
  804. }
  805. WSample.SetMsrParams(SMeasureParamData.GetMsrParams());
  806. //更新样品GRID值测量文件名
  807. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(WSample,defaultParam.GetSysType());
  808. m_MeasureAppFrom.m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  809. return true;
  810. }
  811. //判断是否允许修改样品名
  812. public bool CheckSampleNameIsValid(string sNewName)
  813. {
  814. return GetResultData().IsValidSampleName(sNewName);
  815. }
  816. //设置电镜参数
  817. //int iScanFieldSize: Field扫描参数
  818. //int iWDistance: 电镜工作距离
  819. //double dMagni: 放大倍数
  820. public void SetWorkingSampleSEMData(double iWDistance, double dMagni,double bri,double contra,double kv)
  821. {
  822. var semdata = GetResultData().GetWorkingSample().GetSEMDataMsr();
  823. semdata.SetWorkingDistance(iWDistance);
  824. semdata.SetMagnification(dMagni);
  825. semdata.Brightness = bri;
  826. semdata.Contrast = contra;
  827. semdata.KV = kv;
  828. }
  829. public bool GetWorkingSampleSEMData(ref double iWDistance, ref double dMagni, ref double bri, ref double contra, ref double kv)
  830. {
  831. COTSSample WSample = GetResultData().GetWorkingSample();
  832. if (null == WSample)
  833. {
  834. return false;
  835. }
  836. var semdata = GetResultData().GetWorkingSample().GetSEMDataMsr();
  837. iWDistance = semdata.GetWorkingDistance();
  838. dMagni = semdata.GetMagnification();
  839. bri = semdata.Brightness;
  840. contra = semdata.Contrast;
  841. kv = semdata.KV;
  842. return true;
  843. }
  844. //检查Samplelist中的sample的checkbox状态
  845. //当Samplelist中的链表有sample 的checkbox状态是选中状态,则返回TRUE. 说明可以测量
  846. public bool GetSampleCheckBoxStatus()
  847. {
  848. COTSSample WSample = GetResultData().GetWorkingSample();
  849. if (null == WSample)
  850. {
  851. return false;
  852. }
  853. List<COTSSample> SampleList = new List<COTSSample>();
  854. SampleList = GetResultData().GetSampleList();
  855. int iCount = SampleList.Count();
  856. if (0 == iCount)
  857. {
  858. return false;
  859. }
  860. for (int i = 0; i < iCount; i++)
  861. {
  862. if (SampleList[i].GetSwitch())
  863. {
  864. return true;
  865. }
  866. }
  867. return false;
  868. }
  869. //获取BSE图像数据
  870. public bool GetBSEImageSize(ref int iHeight, ref int iWidth)
  871. {
  872. COTSSample WSample = GetResultData().GetWorkingSample();
  873. if (null == WSample)
  874. {
  875. return false;
  876. }
  877. if (!WSample.GetBSESize(out iHeight, out iWidth))
  878. {
  879. return false;
  880. }
  881. return true;
  882. }
  883. //获取图像尺寸
  884. public string GetBSEImageResolutionStr()
  885. {
  886. try
  887. {
  888. COTSSample WSample = GetResultData().GetWorkingSample();
  889. var res= WSample.GetMsrParams().GetImageScanParam().GetImageResolutionSize();
  890. return res.cx+"X"+res.cy;
  891. }
  892. catch (Exception)
  893. {
  894. return "";
  895. }
  896. }
  897. //获取测量Sample的开始时间
  898. public bool GetMsrSampleStartTime(ref DateTime MsrFieldStartTime)
  899. {
  900. COTSSample WSample = GetResultData().GetWorkingSample();
  901. if (null == WSample)
  902. {
  903. return false;
  904. }
  905. MsrFieldStartTime = (DateTime)WSample.GetMsrStatus().GetStartTime();
  906. return true;
  907. }
  908. //获取测量已用时间
  909. public bool GetMsrSampleUsedTime(ref TimeSpan TUsedTime)
  910. {
  911. COTSSample WSample = GetResultData().GetWorkingSample();
  912. if (null == WSample)
  913. {
  914. return false;
  915. }
  916. TUsedTime = (TimeSpan)WSample.GetMsrStatus().GetUsedTime();
  917. return true;
  918. }
  919. // 获取测量样品中之前已经测量完成Field帧图,(上一次未测量完成继续测试)
  920. public bool GetBeforeCompleteField(ref string MsrSampleName, ref List<PointF> FieldList)
  921. {
  922. COTSSample WSample = GetResultData().GetWorkingSample();
  923. if (null == WSample)
  924. {
  925. return false;
  926. }
  927. MsrSampleName = WSample.GetName();
  928. FieldList = WSample.GetMsrStatus().GetCompletedFieldsCenter();
  929. return true;
  930. }
  931. /// <summary>
  932. /// 通过样品孔信息 返回默认测量区域大小
  933. /// </summary>
  934. /// <param name="cHoleClr"></param>
  935. /// <returns></returns>
  936. public RectangleF CalculateMsrArea(string cHoleName)
  937. {
  938. CHole cHoleClr = null;
  939. foreach (CHole item in GetResultData().GetStageHolder().GetHoleList())
  940. {
  941. if (item.GetName() == cHoleName)
  942. {
  943. cHoleClr = item;
  944. }
  945. }
  946. CDomain CDomain = GetResultData().CalculateMsrArea(cHoleClr);
  947. return CDomain.GetRectDomain();
  948. }
  949. /// <summary>
  950. /// 获取已完成测量的结果文件路径
  951. /// </summary>
  952. /// <param name="mrFilePathList">返回测量结果文件路径</param>
  953. /// <returns></returns>
  954. public bool GetCompletedMeasureFileName(ref List<string> mrFilePathList)
  955. {
  956. //测量文件路径
  957. string proFilePath = GetResultData().GetPathName();
  958. //样品列表
  959. List<COTSSample> sampleList = GetResultData().GetSampleList();
  960. //获取样品数量
  961. int sampleCount = sampleList.Count;
  962. string mrSuffix = ".rst";
  963. int existsCount = 0;
  964. //获取测量文件路径
  965. if (proFilePath.Equals("Untitled"))
  966. {
  967. return false;
  968. }
  969. string mrFolderPath = string.Empty;
  970. try
  971. {
  972. mrFolderPath = proFilePath.Substring(0, proFilePath.LastIndexOf("\\"));
  973. }
  974. catch (Exception)
  975. {
  976. mrFolderPath = string.Empty;
  977. }
  978. for (int sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++)
  979. {
  980. int CompleteFieldsCount = sampleList[sampleIndex].GetMsrStatus().GetCompletedFields();
  981. //如果样品已测量成功后再加载至报告程序中
  982. if (CompleteFieldsCount > 0)
  983. {
  984. string sampleName = sampleList[sampleIndex].GetName();
  985. string mrFilePath = mrFolderPath + "\\" + sampleName + "\\" + sampleName + mrSuffix;
  986. //判断文件是否存在
  987. if (File.Exists(mrFilePath))
  988. {
  989. if (mrFilePathList != null)
  990. {
  991. mrFilePathList.Add(mrFilePath);
  992. }
  993. existsCount++;
  994. }
  995. }
  996. }
  997. if (existsCount > 0)
  998. {
  999. return true;
  1000. }
  1001. return false;
  1002. }
  1003. /// <summary>
  1004. /// 获取工作样品的测量状态
  1005. /// </summary>
  1006. /// <param name="workingSampleName"></param>
  1007. /// <returns></returns>
  1008. public bool GetWorkSampleMeasureStatus()
  1009. {
  1010. bool reuslt = false;
  1011. COTSSample COTSSample = GetResultData().GetWorkingSample();
  1012. if (COTSSample == null) return false;
  1013. int sampleStatus = COTSSample.GetMsrStatus().GetCompletedFields();
  1014. if (sampleStatus > 0)
  1015. {
  1016. reuslt = true;
  1017. }
  1018. return reuslt;
  1019. }
  1020. }
  1021. }