COTSMeasureParam.cs 45 KB

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