COTSMeasureParam.cs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  1. using OTSModelSharp;
  2. using OTSDataType;
  3. using OTSCLRINTERFACE;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.IO;
  9. using OTSModelSharp.ResourceManage;
  10. using static OTSModelSharp.ResourceManage.ResourceID;
  11. using static OTSModelSharp.ResourceManage.ResourceData;
  12. using static OTSDataType.otsdataconst;
  13. using System.Windows.Forms;
  14. using OTSMeasureApp._0_OTSModel.Measure.ParamData;
  15. namespace OTSMeasureApp
  16. {
  17. public enum OTS_SOFT_PACKAGE_ID
  18. {
  19. OTSIncA = 0, //夹杂物分析
  20. OTSPartA = 1, //颗粒度分析
  21. };
  22. //文件保存返回的结果,DataMgr返回
  23. public enum OTS_SAVE_FILE_REV
  24. {
  25. SaveFile_Success = 0,
  26. SaveFile_Cancel = 1,
  27. SaveFile_Failed = 2,
  28. SaveFile_NoNedd = 3 //文件不需要保存
  29. }
  30. //设置线程状态
  31. public enum MSR_THREAD_RunSTATUS
  32. {
  33. RUNMEASURE = 1, //开始测量
  34. RUNSampleHoleImage = 2 //运行获取样品孔照片
  35. };
  36. enum SAMPLE_FAULT_WARN_CODE
  37. {
  38. INVALID = -1,
  39. MIN = 0,
  40. SEM_DATA_ERROR = 0,
  41. AREA_OUTSIDE_HOLE = 1,
  42. RESOLUTION_LOW = 2,
  43. FINISHED = 3,
  44. NO_ERROR_WARNING = 4,
  45. FILE_NOT_SAVED = 5,
  46. MAX = 5
  47. };
  48. enum SAMPLE_CHECK_RESULT_TYPE
  49. {
  50. INVALID = -1,
  51. MIN = 0,
  52. SWITCH_ON = 0,
  53. FINISHED = 1,
  54. SETTING_ERROR = 2,
  55. SETTING_WARNING = 3,
  56. MEASURABLE = 4,
  57. NO_ERROR_WARNING = 5,
  58. MAX = 5
  59. };
  60. public class COTSMeasureParam
  61. {
  62. OTSIncAMeasureAppForm m_MeasureAppFrom = null;
  63. /// <summary></summary>
  64. /// <remarks>创建</remarks>
  65. private COTSMsrPrjResultData resultData;
  66. //参数文件
  67. private COTSDefaultParam defaultParam = null;
  68. //样品台文件(读取样品台数据等)
  69. private CStageParam stageParam = null;
  70. private CSpecialGrayRangeParam specialRanges = null;
  71. //测量样品链表
  72. List<COTSSample> m_MeasureSampleList = new List<COTSSample>();
  73. NLog.Logger log ;
  74. public CSpecialGrayRangeParam SpecialRanges { get => specialRanges; set => specialRanges = value; }
  75. public CStageParam GetStageParam()
  76. {
  77. return stageParam;
  78. }
  79. public void SetStageParam(CStageParam value)
  80. {
  81. stageParam = value;
  82. }
  83. public COTSDefaultParam GetDefaultParam()
  84. {
  85. return defaultParam;
  86. }
  87. public void SetDefaultParam(COTSDefaultParam value)
  88. {
  89. defaultParam = value;
  90. }
  91. public COTSMsrPrjResultData GetResultData()
  92. {
  93. return resultData;
  94. }
  95. public void SetResultData(COTSMsrPrjResultData value)
  96. {
  97. resultData = value;
  98. }
  99. public COTSMeasureParam(OTSIncAMeasureAppForm MeasureApp)
  100. {
  101. log = NLog.LogManager.GetCurrentClassLogger();
  102. m_MeasureAppFrom = MeasureApp;
  103. SetResultData(new COTSMsrPrjResultData());
  104. }
  105. //检查参数文件是否存在
  106. public bool LoadParamFile()
  107. {
  108. //加载样品参数文件: \Config\SysData\OTSProgMgrParam.pmf
  109. SetDefaultParam(new COTSDefaultParam());
  110. GetDefaultParam().LoadInfoFromProgMgrFile();
  111. if (null == GetDefaultParam())
  112. {
  113. return false;
  114. }
  115. return true;
  116. }
  117. //检查参数样品台文件是否存在
  118. public bool LoadStageParamFile()
  119. {
  120. SetStageParam(new CStageParam());
  121. // 加载样品台文件; \Config\SysData\OTSStage.stg
  122. if (!GetStageParam().Load(true, false))
  123. {
  124. return false;
  125. }
  126. return true;
  127. }
  128. public bool LoadSpecialGrayRangeParamFile()
  129. {
  130. SpecialRanges = new CSpecialGrayRangeParam();
  131. if (!SpecialRanges.LoadParam())
  132. {
  133. return false;
  134. }
  135. return true;
  136. }
  137. //获取系统文件是否存在和有效
  138. public bool InitResultData(bool bNewFileFlag = true)
  139. {
  140. //打开文件,则文件中保存有样品台信息,不需要使用系统样品名信息
  141. if (bNewFileFlag)
  142. {
  143. //设置样品台参数
  144. CStage Stage = GetStageParam().GetWorkingStage();
  145. if (null == Stage)
  146. {
  147. return false;
  148. }
  149. GetResultData().SetStage(Stage);
  150. // 设置 SEM stage data
  151. CSEMStageData SEMData = GetDefaultParam().GetStageDataParam();
  152. if (null == SEMData)
  153. {
  154. return false;
  155. }
  156. GetResultData().SetSEMStageData(SEMData);
  157. }
  158. //设置 general parameter
  159. COTSGeneralParam GenParam = GetDefaultParam().GetGenParam();
  160. if (null == GenParam)
  161. {
  162. return false;
  163. }
  164. GetResultData().SetGenParam(GenParam);
  165. if (GetResultData().GetPathName()=="")
  166. {
  167. GetResultData().SetPathName("Untitled");
  168. }
  169. GetResultData().m_nPackId = GetDefaultParam().m_nPackId;
  170. return true;
  171. }
  172. //新建样品工作文件 0:报错 1:正常 2:取消
  173. public int CreateNewFile()
  174. {
  175. if (GetResultData().IsModified()) // 文件被修改
  176. {
  177. int iRev = m_MeasureAppFrom.ShowSaveInfoMsgBox();
  178. if ((int)MessageBoxRev.DIALOG_YES == iRev)
  179. {
  180. if (!GetResultData().Save())
  181. {
  182. return 0;
  183. }
  184. }
  185. else if((int)MessageBoxRev.DIALOG_CANCEL == iRev)
  186. {
  187. return 2;
  188. }
  189. }
  190. //新建新的工作文件
  191. //重新生成一个工作文件对象
  192. COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();
  193. GetResultData().SetPathName("Untitled");
  194. SetResultData(ProjDataMgr);
  195. this.LoadStageParamFile();
  196. if (!this.InitResultData())
  197. {
  198. return 0;
  199. }
  200. return 1;
  201. }
  202. //将样品台坐标转换为Sem 坐标
  203. public PointF ConvertOTSToSemCoord(PointF POTSCoord)
  204. {
  205. System.Drawing.PointF VSemCoord = new System.Drawing.PointF();
  206. GetDefaultParam().GetStageDataParam().ConvertOTSToSEMCoord(POTSCoord, ref VSemCoord);
  207. return VSemCoord;
  208. }
  209. //将Sem 坐标转换为样品台坐标
  210. public PointF ConverSEMToOTSCoord(PointF PSEMCoord)
  211. {
  212. System.Drawing.PointF VOTSCoord = new System.Drawing.PointF();
  213. GetDefaultParam().GetStageDataParam().ConvertSEMToOTSCoord(PSEMCoord, ref VOTSCoord);
  214. return VOTSCoord;
  215. }
  216. //添加样品
  217. //string sSHoleName: 样品孔名,当在样品孔上点击右键添加样品时,sSHoleName=样品孔名。当MEASUREAPP和TREEVIEW添加样品时,sSHoleName=""
  218. //返回新的工作样品名称
  219. public OTSSamplePropertyInfo AddNewSampleMeasure(string a_strHoleName = "")
  220. {
  221. COTSSample NewSample = new COTSSample();
  222. SetSampleDefaultPara(ref NewSample, a_strHoleName);
  223. //NewSample.
  224. //添加样品
  225. GetResultData().AddSample(NewSample);
  226. // 获取样品的属性值
  227. OTSSamplePropertyInfo MeasureInfo = new OTSSamplePropertyInfo();
  228. if (!GetWorkSamplePerameter(NewSample, ref MeasureInfo))
  229. {
  230. return null;
  231. }
  232. return MeasureInfo;
  233. }
  234. protected COTSSample SetSampleDefaultPara(ref COTSSample pSample, String a_strHoleName)
  235. {
  236. // get new sample name
  237. String strNewSampleName = GetNewSampleName();
  238. // make sure the new sample name is not an empty string
  239. strNewSampleName.Trim();
  240. // get a suitable sample hole for the new sample
  241. CHole pHole = SelectASmpleHole(a_strHoleName);
  242. // check the sample hole
  243. if (pHole == null)
  244. {
  245. // failed to get sample hole for the new sample
  246. return null;
  247. }
  248. // measurement area
  249. CDomain pMsrArea = CalculateDefaultArea(pHole);
  250. // measure data parameters containing particle analysis std, image scan parameter, image process parameter and x-ray parameter
  251. CSampleParam poMsrParams = new CSampleParam();
  252. poMsrParams.m_nPackId = GetDefaultParam().m_nPackId;
  253. poMsrParams.m_runmode = GetDefaultParam().m_runmode;
  254. var m_pParam = GetDefaultParam().GetGenParam();
  255. MEMBRANE_TYPE a_nVal = (MEMBRANE_TYPE)m_pParam.GetMembraneType();
  256. poMsrParams.SetImageScanParam(GetDefaultParam().GetImageScanParam ());
  257. poMsrParams.SetImageProcessParam(GetDefaultParam().GetImageProcParam());
  258. poMsrParams.SetXRayParam(GetDefaultParam().GetXRayParam());
  259. String sSTDName = m_pParam.GetSTDSelect();
  260. poMsrParams.SetSTDName(sSTDName);
  261. poMsrParams.SetSteelTechnology((STEEL_TECHNOLOGY)m_pParam.GetSteelTechnology());
  262. poMsrParams.SetSpecialGrayRangeParam(SpecialRanges);
  263. // set sample parameters
  264. pSample.SetName(strNewSampleName);
  265. pSample.SetSampleHoleName(pHole.GetName());
  266. pSample.SetSwitch(m_pParam.GetMeasurementSwitch());
  267. pSample.GetMsrParams().SetSysSTDSwitch(m_pParam.GetSysSTD());
  268. pSample.SetMsrArea(pMsrArea);
  269. pSample.SetMembraneType(a_nVal);
  270. pSample.SetMsrParams(poMsrParams);
  271. CSEMDataMsr semData = new CSEMDataMsr();
  272. var m_pSEMStageData = GetDefaultParam().GetStageDataParam();
  273. var imageScanParam = GetDefaultParam().GetImageScanParam();
  274. string resol = imageScanParam.GetImageResulotion().ToString();
  275. double resWidth = Convert.ToDouble(resol.Split('_')[1]);
  276. double resHeight = Convert.ToDouble(resol.Split('_')[2]);
  277. double heightWidthRatio = resHeight / resWidth;
  278. semData.SetScanFieldSize100(m_pSEMStageData.GetScanFieldSize100());
  279. double fieldHeight = m_pSEMStageData.GetScanFieldSize100() * heightWidthRatio;
  280. semData.SetScanFieldHeight100((int)fieldHeight);
  281. pSample.SetSEMDataMsr(semData);
  282. return pSample;
  283. }
  284. public String GetNewSampleName()
  285. {
  286. // new sample name
  287. String strNewSmplName = "";
  288. // safety check
  289. var m_pParam = GetDefaultParam().GetGenParam();
  290. if (m_pParam == null)
  291. {
  292. // shouldn't happen, invalid general parameter pointer.
  293. return strNewSmplName;
  294. }
  295. // new sample name base
  296. String strNewSmplNameBase = m_pParam.GetSampleName() + @"{0}";
  297. int nIndex = 1;
  298. do
  299. {
  300. // new sample name is new sample name base + number string
  301. strNewSmplName = string.Format(strNewSmplNameBase, nIndex);
  302. ++nIndex;
  303. }
  304. // make sure that the new sample name is not same with any sample in the samples list
  305. while (SameNameInList(strNewSmplName));
  306. // new sample name
  307. return strNewSmplName;
  308. }
  309. public bool SameNameInList(String a_strSampleName, int a_nExclude = -1)
  310. {
  311. // make sure the input sample name is not empty
  312. a_strSampleName.Trim();
  313. if (a_strSampleName == "")
  314. {
  315. // shouldn't happen, input name is an empty string
  316. return false;
  317. }
  318. // go through sample list
  319. int nIndex = 0;
  320. var m_listSamples = GetResultData().GetSampleList();
  321. foreach (var pSample in m_listSamples)
  322. {
  323. // return TRUE if this is not an exclude sample and its name is same with input
  324. String strSampleName = pSample.GetName();
  325. if (nIndex != a_nExclude && strSampleName.CompareTo(a_strSampleName) == 0)
  326. {
  327. // find a same name sample
  328. return true;
  329. }
  330. ++nIndex;
  331. }
  332. // no, same name sample in the same list, return FALSE
  333. return false;
  334. }
  335. // select a suitable sample hole for a new sample
  336. public CHole SelectASmpleHole(String a_strHoleName /*= _T("")*/)
  337. {
  338. // get holes list of the stage
  339. var m_pStage = GetStageParam().GetWorkingStage();
  340. List<CHole> listHoles = m_pStage.GetHoleList();
  341. //返回样品孔对象
  342. CHole cReHole = new CHole();
  343. // make sure the holes list is not empty
  344. if (listHoles.Count == 0)
  345. {
  346. // shouldn't happen, stage have no hole.
  347. return null;
  348. }
  349. // check the input hole name
  350. a_strHoleName.Trim();
  351. if (a_strHoleName != "")
  352. {
  353. // try to find matched hole
  354. bool IsChanged = false;
  355. int holeIndex = -1;
  356. for (int itr = 0; itr < listHoles.Count; itr++)
  357. {
  358. if (listHoles[itr].GetName() == a_strHoleName)
  359. {
  360. cReHole = listHoles[itr];
  361. //listHoles.RemoveAt(itr);
  362. IsChanged = true;
  363. holeIndex = itr;
  364. break;
  365. }
  366. }
  367. if (IsChanged)
  368. {
  369. return cReHole;
  370. }
  371. }
  372. // can't find a matched hole, then pick the first empty hole
  373. //没有按照孔进行添加,则与样品列表进行判断
  374. // go through the holes list
  375. foreach (var pHole in listHoles)
  376. {
  377. // has this hole any sample in it?
  378. String strHoleName = pHole.GetName();
  379. bool IsChanged = false;
  380. var m_listSamples = GetResultData().GetSampleList();
  381. foreach (COTSSample sampleItem in m_listSamples)
  382. {
  383. if (strHoleName == sampleItem.GetSampleHoleName())
  384. {
  385. //listHoles.RemoveAt(itr);
  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. bool bSetFalg = false;
  434. //判断样品名是否有效
  435. if (ItemId == OTS_SAMPLE_PROP_GRID_ITEMS.SAMPLE_NAME)
  436. {
  437. if (!GetResultData().IsValidSampleName((string)objVal))
  438. {
  439. bSetFalg = false;
  440. return false;
  441. }
  442. }
  443. bSetFalg = WSample.SetParamVal(ItemId, ValType, objVal);
  444. if (bSetFalg)
  445. {
  446. GetResultData().SetModify(true);
  447. }
  448. return bSetFalg;
  449. }
  450. //获取工作样品名称
  451. public string GetWorkSampleName()
  452. {
  453. COTSSample WSample = GetResultData().GetWorkingSample();
  454. if (null == WSample)
  455. {
  456. return "";
  457. }
  458. string sWorkSampleName = WSample.GetName();
  459. if ("" == sWorkSampleName)
  460. {
  461. return "";
  462. }
  463. return sWorkSampleName;
  464. }
  465. //设置工作样品
  466. //string sNewWorkSampleName: 新工作样品
  467. public bool SetWorkSample(string sNewWorkSampleName)
  468. {
  469. if ("" == sNewWorkSampleName)
  470. {
  471. return false;
  472. }
  473. if (!GetResultData().SetWorkingSampleByName(sNewWorkSampleName))
  474. {
  475. return false;
  476. }
  477. return true;
  478. }
  479. //获取工作样品
  480. // 返回工作样品对象
  481. public COTSSample GetWorkSample()
  482. {
  483. COTSSample WSample = GetResultData().GetWorkingSample();
  484. if (null == WSample)
  485. {
  486. }
  487. return WSample;
  488. }
  489. //删除工作样品
  490. //string sWorkSampleName : 删除工作样品名称
  491. public bool DeleteWorkSample(string sWorkSampleName)
  492. {
  493. return GetResultData().DeleteSampleByName(sWorkSampleName);
  494. }
  495. // 获取样品总数
  496. //返回样品总数
  497. public int GetSampleCount()
  498. {
  499. return GetResultData().GetSampleList().Count();
  500. }
  501. //改变工作样品名称
  502. //String sWSampleNewName
  503. public bool ChangeWorkSampleName(String sWSampleNewName)
  504. {
  505. if (!GetResultData().IsValidSampleName(sWSampleNewName))
  506. {
  507. return false;
  508. }
  509. COTSSample WorkSample = GetResultData().GetWorkingSample();
  510. if (null == WorkSample)
  511. {
  512. return false;
  513. }
  514. WorkSample.SetName(sWSampleNewName);
  515. GetResultData().SetModify(true);
  516. return true;
  517. }
  518. //移动工作样品到其他样品孔,样品孔名称和测量区域都要改变,重新设置工作样品参数
  519. public void SetWorkSampleHoleAndMeasureArea(SampleMeasurePara SMeasurePara)
  520. {
  521. COTSSample WSample = GetResultData().GetWorkingSample();
  522. if (null == WSample)
  523. {
  524. return ;
  525. }
  526. CDomain Domain = new CDomain();
  527. Domain.SetShape((otsdataconst.DOMAIN_SHAPE)SMeasurePara.iShape);
  528. Domain.SetRectDomain(SMeasurePara.MeasureRect);
  529. if (SMeasurePara.DrawPolygonPointList != null)
  530. {
  531. List<Point> PolygonPoint = new List<Point>();
  532. foreach (var item in SMeasurePara.DrawPolygonPointList)
  533. {
  534. PolygonPoint.Add(new Point((int)item.X, (int)item.Y));
  535. }
  536. Domain.SetPolygonPoint(PolygonPoint);
  537. }
  538. WSample.SetSampleHoleName(SMeasurePara.sampleHoleName);
  539. WSample.SetMsrArea(Domain);
  540. return ;
  541. }
  542. //设置测量区域的形状 (通过RIBBON 上的画圆,画矩形 设置)
  543. //int iShape: 测量区域形状 0: 圆形; 1 :矩形
  544. public void SetMeasureAreaShape(ShapeType iShape)
  545. {
  546. COTSSample WSample = GetResultData().GetWorkingSample();
  547. if (null == WSample)
  548. {
  549. return;
  550. }
  551. CDomain Domain = new CDomain();
  552. Domain.SetShape((otsdataconst.DOMAIN_SHAPE)iShape);
  553. }
  554. //修改了ITEMID后,重新更新GROUPID和ITEMID
  555. public void UpdateGroupValAndItemVal(OTS_SAMPLE_PROP_GRID_ITEMS ItemID)
  556. {
  557. OTS_SAMPLE_PROP_GRID_ITEM_GROUPS GroupID = OTS_SAMPLE_PROP_GRID_ITEM_GROUPS.INVALID;
  558. OTS_SAMPLE_PROP_GRID_ITEMS iItemID = OTS_SAMPLE_PROP_GRID_ITEMS.INVALID;
  559. COTSSample WSample = GetResultData().GetWorkingSample();
  560. if (null == WSample)
  561. {
  562. return;
  563. }
  564. if (!WSample.GetRelatedPropItemGrp((OTS_SAMPLE_PROP_GRID_ITEMS)ItemID, ref GroupID))
  565. {
  566. bool bFlag = WSample.GetRelatedPropItem(ItemID, ref iItemID);
  567. }
  568. }
  569. //设置样品参数锁
  570. //bool ParaLockFlag : 样品参数锁
  571. public bool SetWorkSampleParamLock(bool ParaLockFlag)
  572. {
  573. COTSSample WSample = GetResultData().GetWorkingSample();
  574. if (null == WSample)
  575. {
  576. return false;
  577. }
  578. WSample.SetParamLock(ParaLockFlag);
  579. GetResultData().SetModify(true);
  580. return true;
  581. }
  582. //获取工作样品锁
  583. public bool GetWSampleParaLock(ref bool ParamLockFlag)
  584. {
  585. COTSSample WSample = GetResultData().GetWorkingSample();
  586. if (null == WSample)
  587. {
  588. return false;
  589. }
  590. ParamLockFlag = WSample.GetParamLock();
  591. return true;
  592. }
  593. //获取工作样品测量锁
  594. public bool GetWSampleParaLock(ref OTSSamplePropertyInfo SMInfo)
  595. {
  596. COTSSample WSample = GetResultData().GetWorkingSample();
  597. if (null == WSample)
  598. {
  599. return false;
  600. }
  601. if (!GetWorkSamplePerameter(WSample, ref SMInfo))
  602. {
  603. return false;
  604. }
  605. return true;
  606. }
  607. //重新设置样品在样品列表中的位置(当拖动TREEVIEW的样品顺序后执行 )
  608. public bool SortSamplePosition(List<string> SNameList)
  609. {
  610. if (!GetResultData().ResetSamplesListOrder(SNameList))
  611. {
  612. return false;
  613. }
  614. List<COTSSample> SampleList = new List<COTSSample>();
  615. SampleList = GetResultData().GetSampleList();
  616. return true;
  617. }
  618. public bool CheckSampleParam(bool bCheckFlag)
  619. {
  620. m_MeasureSampleList.Clear();
  621. List<COTSSample> MSampleList = new List<COTSSample>();
  622. if (!CheckMeasureParam(GetResultData(), ref MSampleList, bCheckFlag))
  623. {
  624. return false;
  625. }
  626. if (MSampleList.Count > 0)
  627. {
  628. m_MeasureSampleList = MSampleList;
  629. return true;
  630. }
  631. return false;
  632. }
  633. public bool CheckMeasureParam(COTSMsrPrjResultData a_pProjMgrFile, ref List<COTSSample> a_listMeasuableSamples, bool a_bCheckSetting)
  634. {
  635. // go through the sample list to check setting parameters
  636. int nSwitchSmplNo = 0;
  637. int nCompletedSmplNo = 0;
  638. int nErrorSmplNo = 0;
  639. int nWarningSmplNo = 0;
  640. List<String> listSamplMessages = new List<string>();
  641. List<COTSSample> listSamples = a_pProjMgrFile.GetSampleList();
  642. List<COTSSample> listMeasurableSamples = new List<COTSSample>();
  643. List<COTSSample> listWithWarningMeasurableSamples = new List<COTSSample>();
  644. foreach (var pSample in listSamples)
  645. {
  646. // is the sample switch on
  647. if (pSample.GetSwitch())
  648. {
  649. ++nSwitchSmplNo;
  650. String strSmplMessage;
  651. strSmplMessage = pSample.GetName() + ":" + "\r\n";
  652. // is this a measurement completed sample
  653. if (IsMeasureCompletedSmpl(pSample))
  654. { // measurement completed sample
  655. ++nCompletedSmplNo;
  656. string str2 = GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE.FINISHED);
  657. strSmplMessage += str2;
  658. strSmplMessage += "\r\n";
  659. }
  660. else
  661. {
  662. // errors
  663. List<SAMPLE_FAULT_WARN_CODE> a_listErrorCodes = new List<SAMPLE_FAULT_WARN_CODE>();
  664. GetSampleErrorCodes(a_pProjMgrFile, pSample, ref a_listErrorCodes);
  665. if (a_listErrorCodes.Count != 0)
  666. {
  667. // has error, this is not a measurable sample
  668. ++nErrorSmplNo;
  669. foreach (var nErrorCode in a_listErrorCodes)
  670. {
  671. String str3 = GetSampleErrorWarnString(nErrorCode);
  672. strSmplMessage += str3;
  673. strSmplMessage += "\r\n";
  674. }
  675. }
  676. else
  677. {
  678. // no error, this is a measurable sample
  679. listMeasurableSamples.Add(pSample);
  680. }
  681. // warnings
  682. List<SAMPLE_FAULT_WARN_CODE> a_listWarningCodes = new List<SAMPLE_FAULT_WARN_CODE>();
  683. GetSampleWarningCodes(a_pProjMgrFile, pSample, ref a_listWarningCodes);
  684. if (a_listWarningCodes.Count != 0)
  685. {
  686. ++nWarningSmplNo;
  687. foreach (var nWarningCode in a_listWarningCodes)
  688. {
  689. String str3 = GetSampleErrorWarnString(nWarningCode);
  690. strSmplMessage += str3;
  691. strSmplMessage += "\r\n";
  692. }
  693. // has no error?
  694. if (a_listErrorCodes.Count == 0)
  695. {
  696. // this is a measurable sample but with setting warnings
  697. listWithWarningMeasurableSamples.Add(pSample);
  698. }
  699. }
  700. // no error and warning
  701. if (a_listErrorCodes.Count == 0 && a_listWarningCodes.Count == 0)
  702. {
  703. String str3 = GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE.NO_ERROR_WARNING);
  704. strSmplMessage += str3;
  705. strSmplMessage += "\r\n";
  706. }
  707. }
  708. // add
  709. listSamplMessages.Add(strSmplMessage);
  710. }
  711. }
  712. // dlg message string
  713. String strDlgMessage = "";
  714. String str;
  715. String str1;
  716. str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.SWITCH_ON);
  717. str1 = str1.Replace("%d", "{0}");
  718. str = string.Format(str1, nSwitchSmplNo);
  719. strDlgMessage += str;
  720. strDlgMessage += "\r\n";
  721. // add more string if there switch on sample
  722. if (nSwitchSmplNo > 0)
  723. {
  724. // completed sample number (optional)
  725. if (nCompletedSmplNo > 0)
  726. {
  727. str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.FINISHED);
  728. str1 = str1.Replace("%d", "{0}");
  729. str = string.Format(str1, nCompletedSmplNo);
  730. strDlgMessage += str;
  731. strDlgMessage += "\r\n";
  732. }
  733. // any unmeasured switch on samples?
  734. if (nSwitchSmplNo > nCompletedSmplNo)
  735. {
  736. // with setting error sample number
  737. str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.SETTING_ERROR);
  738. str1 = str1.Replace("%d", "{0}");
  739. str = string.Format(str1, nErrorSmplNo);
  740. strDlgMessage += str;
  741. strDlgMessage += "\r\n";
  742. // with setting warning sample number
  743. str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.SETTING_WARNING);
  744. str1 = str1.Replace("%d", "{0}");
  745. str = string.Format(str1, nWarningSmplNo);
  746. strDlgMessage += str;
  747. strDlgMessage += "\r\n";
  748. }
  749. }
  750. // add an empty line strDlgMessage
  751. strDlgMessage += "\r\n";
  752. // add sample messages
  753. foreach (var strSmplMessage in listSamplMessages)
  754. {
  755. strDlgMessage += strSmplMessage;
  756. strDlgMessage += "\r\n";
  757. }
  758. // do we need to show dialog box?
  759. if (nSwitchSmplNo == 0)
  760. {
  761. return false;
  762. }
  763. // measure button clicked?
  764. if (a_bCheckSetting)
  765. {
  766. // there are measurable samples but no setting warnings samples
  767. if (listMeasurableSamples.Count > 0 && listWithWarningMeasurableSamples.Count == 0)
  768. {
  769. // set output measurable samples list
  770. foreach (var pSample in listMeasurableSamples)
  771. {
  772. a_listMeasuableSamples.Add(pSample);
  773. }
  774. return true;
  775. }
  776. }
  777. //when there is sample setting error, and setting with no error and no warning samples, the dlg will not be show.??
  778. //show the result dlg
  779. DIALOG_CHECK_PARAM_RESULT dlg = new DIALOG_CHECK_PARAM_RESULT();
  780. int nTatolMeasuableSmplNo = listMeasurableSamples.Count;
  781. int nWithWarningMeasuableSmplNo = listWithWarningMeasurableSamples.Count;
  782. // set the dlg parameters
  783. dlg.SetCheckOnlyFlag(a_bCheckSetting);
  784. dlg.SetMessageBase(strDlgMessage);
  785. dlg.SetTatolMeasuableSmplNo(nTatolMeasuableSmplNo);
  786. dlg.SetWithWarningMeasuableSmplNo(nWithWarningMeasuableSmplNo);
  787. //no error not show dlg
  788. if (nTatolMeasuableSmplNo == nSwitchSmplNo - nCompletedSmplNo && listMeasurableSamples.Count != 0)
  789. {
  790. foreach (var pSample in listMeasurableSamples)
  791. {
  792. var itr = listWithWarningMeasurableSamples.Find(s => { return s.GetName() == pSample.GetName(); });
  793. if (itr == null)
  794. {
  795. a_listMeasuableSamples.Add(pSample);
  796. }
  797. }
  798. if (a_listMeasuableSamples.Count == listMeasurableSamples.Count)
  799. {
  800. return true;
  801. }
  802. }
  803. //show dlg
  804. DialogResult dResult = dlg.ShowDialog();
  805. if (!(dResult == System.Windows.Forms.DialogResult.OK))
  806. {
  807. // do something here
  808. return false;
  809. }
  810. else
  811. {
  812. //if warnDo, back the listMeasuableSample
  813. if (dlg.GetWarnDo())
  814. {
  815. foreach (var pSample in listMeasurableSamples)
  816. {
  817. a_listMeasuableSamples.Add(pSample);
  818. }
  819. }
  820. else // back with no warn sample
  821. {
  822. foreach (var pSample in listMeasurableSamples)
  823. {
  824. var itr = listWithWarningMeasurableSamples.Find(e => { return e.GetName() == pSample.GetName(); });
  825. if (itr == null)
  826. {
  827. a_listMeasuableSamples.Add(pSample);
  828. }
  829. }
  830. }
  831. }
  832. return true;
  833. }
  834. bool IsMeasureCompletedSmpl(COTSSample a_pSample)
  835. {
  836. // safety check
  837. if (a_pSample.GetMsrStatus().GetStatus() != OTSDataType.OTS_MSR_SAMPLE_STATUS.SUCCESSED)
  838. {
  839. return false;
  840. }
  841. return true;
  842. }
  843. string GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE a_nSampleFaultWarn)
  844. {
  845. // check input
  846. if (a_nSampleFaultWarn < SAMPLE_FAULT_WARN_CODE.MIN && a_nSampleFaultWarn > SAMPLE_FAULT_WARN_CODE.MAX)
  847. {
  848. return "";
  849. }
  850. // error/waring string
  851. string strErrorWarn;
  852. strErrorWarn = GetResourceByKey(GrpOtherParam, IDS_ERROR_WARNING + (int)a_nSampleFaultWarn);
  853. return strErrorWarn;
  854. }
  855. // get error codes list of a sample
  856. void GetSampleErrorCodes(COTSMsrPrjResultData a_pProjMgrFile, COTSSample a_pSample, ref List<SAMPLE_FAULT_WARN_CODE> a_listErrorCodes)
  857. {
  858. const string UNTITLED_FILE_NAME = "Untitled";
  859. // file has not been saved
  860. String strPathName = a_pProjMgrFile.GetPathName();
  861. // is this a file no saved?
  862. strPathName.Trim();
  863. if (strPathName == UNTITLED_FILE_NAME || strPathName == "")
  864. {
  865. a_listErrorCodes.Add(SAMPLE_FAULT_WARN_CODE.FILE_NOT_SAVED);
  866. }
  867. }
  868. // get warning codes list of a sample
  869. void GetSampleWarningCodes(COTSMsrPrjResultData a_pProjMgrFile, COTSSample a_pSample, ref List<SAMPLE_FAULT_WARN_CODE> a_listWarningCodes)
  870. {
  871. // get the work stage
  872. CStage pStage = a_pProjMgrFile.GetStage();
  873. //get hole
  874. String sHoleName = a_pSample.GetSampleHoleName();
  875. //look for the hole Domain
  876. CHole pSampleHole = pStage.GetHoleByName(sHoleName);
  877. if (pSampleHole == null)
  878. {
  879. return;
  880. }
  881. if (a_pSample.GetSEMDataMsr() != null)
  882. {
  883. // compute pixel size
  884. double dPixleSize = a_pSample.CalculatePixelSize();
  885. // get min size
  886. COTSImageProcParam pImageProcParam = a_pSample.GetMsrParams().GetImageProcessParam();
  887. double dMinSize = pImageProcParam.GetIncAreaRange().GetStart();
  888. // if pixel size bigger than 1/2 of the min size, current magnification can't see clear of the object
  889. if (dPixleSize >= dMinSize * 0.5)
  890. {
  891. // resolution low
  892. a_listWarningCodes.Add(SAMPLE_FAULT_WARN_CODE.RESOLUTION_LOW);
  893. }
  894. }
  895. if(a_pSample.GetSEMDataMsr().GetTotalFields()==0
  896. && a_pSample.GetSEMDataMsr().GetScanFieldSize() == 0
  897. && a_pSample.GetSEMDataMsr().GetWorkingDistance() == 0)
  898. {
  899. // SEM_DATA_ERROR
  900. a_listWarningCodes.Add(SAMPLE_FAULT_WARN_CODE.SEM_DATA_ERROR);
  901. }
  902. }
  903. //获取测量参数文件名称
  904. //int iNamePos: 文件名在链表中的位置
  905. //List<string> MParamFileNameList: 测量参数文件链表
  906. public bool GetMeasureParamFileName(ref int iNamePos, ref List<string> MParamFileNameList)
  907. {
  908. if (!GetResultData().GetParamFileList(ref iNamePos, ref MParamFileNameList))
  909. {
  910. return false;
  911. }
  912. return true;
  913. }
  914. //设置测量文件名称
  915. //int iNamePos: 文件名在链表中的位置
  916. public bool SetMeasrueParamFileName(int iNamePos)
  917. {
  918. if (!GetResultData().ChangeParamFromList(iNamePos))
  919. {
  920. return false;
  921. }
  922. return true;
  923. }
  924. //获取STD 标准库文件名称
  925. //int iNamePos: 文件名在链表中的位置
  926. //List<string> STDFileNameList: STD文件链表
  927. public bool GetSTDFileName(ref int iNamePos, ref List<string> STDFileNameList)
  928. {
  929. if (!GetResultData().GetSTDFileList(ref iNamePos, ref STDFileNameList))
  930. {
  931. return false;
  932. }
  933. return true;
  934. }
  935. //设置STD 标准库文件名称
  936. public bool SetSTDFileName(int iNamePos)
  937. {
  938. if (!GetResultData().ChangeSTDFromList(iNamePos))
  939. {
  940. return false;
  941. }
  942. return true;
  943. }
  944. ///保存工作样品的测量参数文件
  945. public bool SaveWorkMeasureFile()
  946. {
  947. CSampleParamMgr SMeasureParamData = new CSampleParamMgr();
  948. COTSSample WSample = GetResultData().GetWorkingSample();
  949. if (null == WSample)
  950. {
  951. return false;
  952. }
  953. if (!SMeasureParamData.SetMsrParamFile(WSample.GetMsrParams()))
  954. {
  955. return false;
  956. }
  957. // file open dialog
  958. CSampleParamMgr cSampleParamMgr = new CSampleParamMgr();
  959. SaveFileDialog saveFileDialog = new SaveFileDialog();
  960. saveFileDialog.FileName = WSample.GetName() +"_Config"+ cSampleParamMgr.MESUREMENT_PARAM_FILE_EXT;
  961. saveFileDialog.Filter = cSampleParamMgr.MESUREMENT_PARAM_FILE_FILTER;
  962. if (saveFileDialog.ShowDialog() != DialogResult.OK)
  963. {
  964. return false;
  965. }
  966. // get file pathname
  967. string strPathName = saveFileDialog.FileName;
  968. SMeasureParamData.Save(strPathName);
  969. return true;
  970. }
  971. //打开工作样品的测量参数文件
  972. public bool LoadWorkMeasureFile()
  973. {
  974. CSampleParamMgr SMeasureParamData = new CSampleParamMgr();
  975. OpenFileDialog openFileDialog = new OpenFileDialog();
  976. openFileDialog.Filter = SMeasureParamData.MESUREMENT_PARAM_FILE_FILTER;
  977. if (openFileDialog.ShowDialog() != DialogResult.OK)
  978. {
  979. return false;
  980. }
  981. // get file pathname
  982. string strPathName = openFileDialog.FileName;
  983. if (!SMeasureParamData.Load(strPathName, true))
  984. {
  985. return false;
  986. }
  987. COTSSample WSample = GetResultData().GetWorkingSample();
  988. if (null == WSample)
  989. {
  990. return false;
  991. }
  992. WSample.SetMsrParams(SMeasureParamData.GetMsrParams());
  993. //更新样品GRID值测量文件名
  994. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  995. if (!this.GetWorkSamplePerameter(WSample, ref SMInfo))
  996. {
  997. return false;
  998. }
  999. m_MeasureAppFrom.m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  1000. return true;
  1001. }
  1002. //判断是否允许修改样品名
  1003. public bool CheckSampleNameIsValid(string sNewName)
  1004. {
  1005. return GetResultData().IsValidSampleName(sNewName);
  1006. }
  1007. //设置电镜参数
  1008. //int iScanFieldSize: Field扫描参数
  1009. //int iWDistance: 电镜工作距离
  1010. //double dMagni: 放大倍数
  1011. public void SetWorkingSampleSEMData(double iWDistance, double dMagni)
  1012. {
  1013. try
  1014. {
  1015. GetResultData().GetWorkingSample().GetSEMDataMsr().SetWorkingDistance(iWDistance);
  1016. GetResultData().GetWorkingSample().GetSEMDataMsr().SetMagnification(dMagni);
  1017. }
  1018. catch (Exception)
  1019. {
  1020. }
  1021. }
  1022. public void SetFliedsCount(int FliedsCount)
  1023. {
  1024. GetResultData().GetWorkingSample().GetSEMDataMsr().SetTotalFields(FliedsCount);
  1025. }
  1026. //获取电镜参数
  1027. //int iScanFieldSize: Field扫描参数
  1028. //int iWDistance: 电镜工作距离
  1029. //double dMagni: 放大倍数
  1030. public void GetWorkingSampleSEMData(ref double iWDistance, ref double dMagni)
  1031. {
  1032. iWDistance = GetResultData().GetWorkingSample().GetSEMDataMsr().GetWorkingDistance();
  1033. dMagni = GetResultData().GetWorkingSample().GetSEMDataMsr().GetMagnification();
  1034. }
  1035. public int GetTotalFieldsCount()
  1036. {
  1037. int icount = GetResultData().GetWorkingSample().GetSEMDataMsr().GetTotalFields();
  1038. return icount;
  1039. }
  1040. //获取工作样品的测量区域
  1041. //int iShape :测量区域形状
  1042. //Rectangle Srect: 测量区域大小
  1043. public bool GetWorkSampleMrsArea(ref int iShape, ref RectangleF Srect)
  1044. {
  1045. COTSSample WSample = GetResultData().GetWorkingSample();
  1046. if (null == WSample)
  1047. {
  1048. return false;
  1049. }
  1050. CDomain pMsrArea = new CDomain();
  1051. pMsrArea = WSample.GetMsrArea();
  1052. if (null == pMsrArea)
  1053. {
  1054. return false;
  1055. }
  1056. iShape = (int)pMsrArea.GetShape();
  1057. Srect = pMsrArea.GetRectDomain();
  1058. return true;
  1059. }
  1060. //检查Samplelist中的sample的checkbox状态
  1061. //当Samplelist中的链表有sample 的checkbox状态是选中状态,则返回TRUE. 说明可以测量
  1062. public bool GetSampleCheckBoxStatus()
  1063. {
  1064. COTSSample WSample = GetResultData().GetWorkingSample();
  1065. if (null == WSample)
  1066. {
  1067. return false;
  1068. }
  1069. List<COTSSample> SampleList = new List<COTSSample>();
  1070. SampleList = GetResultData().GetSampleList();
  1071. int iCount = SampleList.Count();
  1072. if (0 == iCount)
  1073. {
  1074. return false;
  1075. }
  1076. for (int i = 0; i < iCount; i++)
  1077. {
  1078. if (SampleList[i].GetSwitch())
  1079. {
  1080. return true;
  1081. }
  1082. }
  1083. return false;
  1084. }
  1085. //获取BSE图像数据
  1086. public bool GetBSEImageSize(ref int iHeight, ref int iWidth)
  1087. {
  1088. COTSSample WSample = GetResultData().GetWorkingSample();
  1089. if (null == WSample)
  1090. {
  1091. return false;
  1092. }
  1093. if (!WSample.GetBSESize(out iHeight, out iWidth))
  1094. {
  1095. return false;
  1096. }
  1097. return true;
  1098. }
  1099. //获取图像尺寸
  1100. public string GetBSEImageResolution()
  1101. {
  1102. try
  1103. {
  1104. COTSSample WSample = GetResultData().GetWorkingSample();
  1105. if (null == WSample)
  1106. {
  1107. return "";
  1108. }
  1109. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  1110. if (!GetWorkSamplePerameter(WSample, ref SMInfo))
  1111. {
  1112. return "";
  1113. }
  1114. int iCount = SMInfo.SampleDataList.Count();
  1115. for (int i = 0; i < iCount; i++)
  1116. {
  1117. if (OTS_SAMPLE_PROP_GRID_ITEMS.IMAGE_RESOLUTION == SMInfo.SampleDataList[i].iSampleId)
  1118. {
  1119. String val = (String)SMInfo.SampleDataList[i].SampleVal;
  1120. return val;
  1121. }
  1122. }
  1123. return "";
  1124. }
  1125. catch (Exception)
  1126. {
  1127. return "";
  1128. }
  1129. }
  1130. //获取放大倍数和工作距离
  1131. public bool GetMagAndDistance(ref double SemMag, ref double dDistance)
  1132. {
  1133. COTSSample WSample = GetResultData().GetWorkingSample();
  1134. if (null == WSample)
  1135. {
  1136. return false;
  1137. }
  1138. //GetWorkingSampleSEMData(ref SemMag, ref dDistance);
  1139. GetWorkingSampleSEMData(ref dDistance, ref SemMag);
  1140. return true;
  1141. }
  1142. public bool GetWorkSamplePerameter(COTSSample Sample, ref OTSSamplePropertyInfo SMeasureInfo)
  1143. {
  1144. //设置工作样品属性项
  1145. if (Sample.GetMsrParams().m_nPackId == OTS_SysType_ID.CleannessA)
  1146. {
  1147. Sample.SetPropItemGrpsForCleanlinessSys();
  1148. }
  1149. else
  1150. {
  1151. Sample.SetPropItemGrpsForIncA();
  1152. }
  1153. bool MeasurementStatus = false;
  1154. //样品的标题名 (Treeview的根节点名)
  1155. SMeasureInfo.sSampleSoluName = GetResultData().GetFileName();
  1156. // Treeview 的样品信息
  1157. SMeasureInfo.TSampleParam.sSampleTitleName = GetResultData().GetFileName();
  1158. //获得 样品属性值
  1159. SMeasureInfo.bSwitch = Sample.GetSwitch();// (bool)jo.GetValue("bSwitch");
  1160. SMeasureInfo.TSampleParam.bParamLock = Sample.GetParamLock();// (bool)jo.GetValue("ParamLock");
  1161. //获取样品的测量区域信息
  1162. //获取样品名称
  1163. SMeasureInfo.SMeasurePara.sSampleName = Sample.GetName();// (String)SMeasurePara.GetValue("sNewSampleName");
  1164. // 获取测量区域形状
  1165. SMeasureInfo.SMeasurePara.iShape = (ShapeType)Sample.GetMsrArea().GetShape();// (int)SMeasurePara.GetValue("iShape");
  1166. //获取样品孔名称
  1167. SMeasureInfo.SMeasurePara.sampleHoleName = Sample.GetSampleHoleName();// (String)SMeasurePara.GetValue("sHoleName");
  1168. //样品测量区域
  1169. // JObject rec = (JObject)SMeasurePara.GetValue("MeasureRect");
  1170. RectangleF rec = Sample.GetMsrArea().GetDomainRect();
  1171. SMeasureInfo.SMeasurePara.MeasureRect = new Rectangle((int)rec.X, (int)rec.Y, (int)rec.Width, (int)rec.Height);
  1172. SMeasureInfo.TSampleParam.sWorkSampleName = Sample.GetName();// (String)TSampleParam.GetValue("sWorkSampleName");
  1173. SMeasureInfo.TSampleParam.bSwitch = Sample.GetSwitch();// (bool)TSampleParam.GetValue("bSwitch");
  1174. List<CPropItemGrp> ja = Sample.GetPropItemGrps();// (JArray)jo.GetValue("ItemGrp");
  1175. for (int i = 0; i < ja.Count; i++)
  1176. {
  1177. //获取GROUP ID和Grid的显示组的标题名
  1178. var grp = ja[i];
  1179. int grpId = (int)grp.GetGroupId();
  1180. String sTitle = (String)grp.GetName();
  1181. //获取样品属性ID和值
  1182. var SDataArr = grp.GetItemsList();
  1183. if (SDataArr.Count == 0)
  1184. continue;
  1185. SamplePropertyDataGroup smlgrp = new SamplePropertyDataGroup();
  1186. smlgrp.GroupId = (OTS_SAMPLE_PROP_GRID_ITEM_GROUPS)grpId;
  1187. smlgrp.sTitle = sTitle;
  1188. for (int j = 0; j < SDataArr.Count; j++)
  1189. {
  1190. var SDataObj = SDataArr[j];
  1191. SamplePropertyData SData = new SamplePropertyData();
  1192. int smplid = (int)SDataObj.GetSmplItemId();
  1193. SData.iSampleId = (OTS_SAMPLE_PROP_GRID_ITEMS)smplid;
  1194. if (SData.iSampleId == OTS_SAMPLE_PROP_GRID_ITEMS.WORKING_DISTANCE)
  1195. {
  1196. bool b = (bool)SDataObj.IsReadOnly();
  1197. }
  1198. SData.sSCaptionName = (String)SDataObj.GetName();
  1199. //------------------------------修改--------------------------
  1200. if ((String)SDataObj.GetName() == "样品名")
  1201. {
  1202. for (int a = 0; a < ja.Count; a++)
  1203. {
  1204. var grpa = ja[a];
  1205. var SDataArra = grpa.GetItemsList();
  1206. for (int b = 0; b < SDataArra.Count; b++)
  1207. {
  1208. var SDataObb = SDataArra[b];
  1209. if ((String)SDataObb.GetName() == "测量状态")
  1210. {
  1211. if ((String)Sample.GetItemValueStr((OTS_SAMPLE_PROP_GRID_ITEMS)SDataObb.GetSmplItemId()) == "未测量")
  1212. {
  1213. MeasurementStatus = false;
  1214. }
  1215. else
  1216. {
  1217. MeasurementStatus = true;
  1218. }
  1219. }
  1220. }
  1221. }
  1222. }
  1223. else
  1224. {
  1225. MeasurementStatus = false;
  1226. }
  1227. if (MeasurementStatus)
  1228. {
  1229. SData.bReadOnly = MeasurementStatus;
  1230. }
  1231. else
  1232. {
  1233. SData.bReadOnly = (bool)SDataObj.IsReadOnly();// OTS_ITEM_TYPES
  1234. }
  1235. //---------------------------------------------------------------
  1236. int type = (int)SDataObj.GetTypeId();
  1237. SData.iSampleValType = (OTS_ITEM_TYPES)type;
  1238. SData.sDescriptionInfo = (String)SDataObj.GetDescription();
  1239. OTS_SAMPLE_PROP_GRID_ITEMS ItemId = SDataObj.GetSmplItemId();
  1240. SData.SampleVal = (String)Sample.GetItemValueStr(ItemId);
  1241. List<string> downStrList = new List<string>();
  1242. if (type == (int)OTS_ITEM_TYPES.COMBO)
  1243. {
  1244. Sample.GetPropComboStrings(SDataObj.GetSmplItemId(), downStrList);
  1245. }
  1246. else if (type == (int)OTS_ITEM_TYPES.FILE_LIST)
  1247. {
  1248. //the sample object dosen't know anything about the fileList infomation so it has to delay this duty here.
  1249. int iPos = -1;
  1250. List<string> sFileNameList = new List<string>();
  1251. if (OTS_SAMPLE_PROP_GRID_ITEMS.MEASURE_PARAM_FILE_NAME == (OTS_SAMPLE_PROP_GRID_ITEMS)smplid)
  1252. {
  1253. if (!this.GetMeasureParamFileName(ref iPos, ref sFileNameList))
  1254. {
  1255. return false;
  1256. }
  1257. foreach (var f in sFileNameList)
  1258. {
  1259. downStrList.Add(f);
  1260. }
  1261. }
  1262. if (OTS_SAMPLE_PROP_GRID_ITEMS.STD_FILE_NAME == (OTS_SAMPLE_PROP_GRID_ITEMS)smplid)
  1263. {
  1264. if (!this.GetSTDFileName(ref iPos, ref sFileNameList))
  1265. {
  1266. return false;
  1267. }
  1268. foreach (var f in sFileNameList)
  1269. {
  1270. downStrList.Add(f);
  1271. }
  1272. }
  1273. }
  1274. if (downStrList.Count > 0)
  1275. {
  1276. for (int k = 0; k < downStrList.Count; k++)
  1277. {
  1278. SData.comboDownList.Add((String)downStrList[k]);
  1279. }
  1280. }
  1281. smlgrp.SampleDataList.Add(SData);
  1282. }
  1283. SMeasureInfo.AddASampleDataGrp(smlgrp);
  1284. }
  1285. return true;
  1286. }
  1287. //保存测量样品的
  1288. public bool SaveMeasureSampleInfo()
  1289. {
  1290. if (!GetResultData().Save())
  1291. {
  1292. return false;
  1293. }
  1294. return true;
  1295. }
  1296. //获取测量Sample的开始时间
  1297. public bool GetMsrSampleStartTime(ref DateTime MsrFieldStartTime)
  1298. {
  1299. COTSSample WSample = GetResultData().GetWorkingSample();
  1300. if (null == WSample)
  1301. {
  1302. return false;
  1303. }
  1304. MsrFieldStartTime = (DateTime)WSample.GetMsrStatus().GetStartTime();
  1305. return true;
  1306. }
  1307. //获取测量已用时间
  1308. public bool GetMsrSampleUsedTime(ref TimeSpan TUsedTime)
  1309. {
  1310. COTSSample WSample = GetResultData().GetWorkingSample();
  1311. if (null == WSample)
  1312. {
  1313. return false;
  1314. }
  1315. TUsedTime = (TimeSpan)WSample.GetMsrStatus().GetUsedTime();
  1316. return true;
  1317. }
  1318. // 获取测量样品中之前已经测量完成Field帧图,(上一次未测量完成继续测试)
  1319. public bool GetBeforeCompleteField(ref string MsrSampleName, ref List<Point> FieldList)
  1320. {
  1321. COTSSample WSample = GetResultData().GetWorkingSample();
  1322. if (null == WSample)
  1323. {
  1324. return false;
  1325. }
  1326. MsrSampleName = WSample.GetName();
  1327. FieldList = WSample.GetMsrStatus().GetCompletedFieldsCenter();
  1328. return true;
  1329. }
  1330. /// <summary>
  1331. /// 通过样品孔信息 返回默认测量区域大小
  1332. /// </summary>
  1333. /// <param name="cHoleClr"></param>
  1334. /// <returns></returns>
  1335. public RectangleF CalculateMsrArea(string cHoleName)
  1336. {
  1337. CHole cHoleClr = null;
  1338. foreach (CHole item in GetResultData().GetStage().GetHoleList())
  1339. {
  1340. if (item.GetName() == cHoleName)
  1341. {
  1342. cHoleClr = item;
  1343. }
  1344. }
  1345. CDomain CDomain = GetResultData().CalculateMsrArea(cHoleClr);
  1346. return CDomain.GetRectDomain();
  1347. }
  1348. /// <summary>
  1349. /// 获取已完成测量的结果文件路径
  1350. /// </summary>
  1351. /// <param name="mrFilePathList">返回测量结果文件路径</param>
  1352. /// <returns></returns>
  1353. public bool GetCompletedMeasureFileName(ref List<string> mrFilePathList)
  1354. {
  1355. //测量文件路径
  1356. string proFilePath = GetResultData().GetPathName();
  1357. //样品列表
  1358. List<COTSSample> sampleList = GetResultData().GetSampleList();
  1359. //获取样品数量
  1360. int sampleCount = sampleList.Count;
  1361. string mrSuffix = ".rst";
  1362. int existsCount = 0;
  1363. //获取测量文件路径
  1364. if (proFilePath.Equals("Untitled"))
  1365. {
  1366. return false;
  1367. }
  1368. string mrFolderPath = string.Empty;
  1369. try
  1370. {
  1371. mrFolderPath = proFilePath.Substring(0, proFilePath.LastIndexOf("\\"));
  1372. }
  1373. catch (Exception)
  1374. {
  1375. mrFolderPath = string.Empty;
  1376. }
  1377. for (int sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++)
  1378. {
  1379. int CompleteFieldsCount = sampleList[sampleIndex].GetMsrStatus().GetCompletedFields();
  1380. //如果样品已测量成功后再加载至报告程序中
  1381. if (CompleteFieldsCount > 0)
  1382. {
  1383. string sampleName = sampleList[sampleIndex].GetName();
  1384. string mrFilePath = mrFolderPath + "\\" + sampleName + "\\" + sampleName + mrSuffix;
  1385. //判断文件是否存在
  1386. if (File.Exists(mrFilePath))
  1387. {
  1388. if (mrFilePathList != null)
  1389. {
  1390. mrFilePathList.Add(mrFilePath);
  1391. }
  1392. existsCount++;
  1393. }
  1394. }
  1395. }
  1396. if (existsCount > 0)
  1397. {
  1398. return true;
  1399. }
  1400. return false;
  1401. }
  1402. /// <summary>
  1403. /// 获取工作样品的测量状态
  1404. /// </summary>
  1405. /// <param name="workingSampleName"></param>
  1406. /// <returns></returns>
  1407. public bool GetWorkSampleMeasureStatus()
  1408. {
  1409. bool reuslt = false;
  1410. COTSSample COTSSample = GetResultData().GetWorkingSample();
  1411. if (COTSSample == null) return false;
  1412. int sampleStatus = COTSSample.GetMsrStatus().GetCompletedFields();
  1413. if (sampleStatus > 0)
  1414. {
  1415. reuslt = true;
  1416. }
  1417. return reuslt;
  1418. }
  1419. }
  1420. }