OTSMeasureParam.cs 56 KB

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