COTSMeasureParam.cs 57 KB

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