COTSMeasureParam.cs 56 KB

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