COTSMeasureParam.cs 45 KB

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