COTSMeasureParam.cs 48 KB

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