COTSMeasureParam.cs 58 KB

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