COTSMeasureParam.cs 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737
  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_RUN_TYPE
  32. {
  33. RUNMEASURE = 1, //normal
  34. RUNSampleHoleImage = 2 //take photo of the measure area.
  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_systemTypeId = GetDefaultParam().m_systemTypeId;
  170. return true;
  171. }
  172. //新建样品工作文件 0:报错 1:正常 2:取消
  173. public int CreateNewFile()
  174. {
  175. if (GetResultData().IsModified()) // 文件被修改
  176. {
  177. int iRev = m_MeasureAppFrom.ShowSaveInfoMsgBox();
  178. if ((int)MessageBoxRev.DIALOG_YES == iRev)
  179. {
  180. if (!GetResultData().Save())
  181. {
  182. return 0;
  183. }
  184. }
  185. else if((int)MessageBoxRev.DIALOG_CANCEL == iRev)
  186. {
  187. return 2;
  188. }
  189. }
  190. //新建新的工作文件
  191. //重新生成一个工作文件对象
  192. COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();
  193. GetResultData().SetPathName("Untitled");
  194. SetResultData(ProjDataMgr);
  195. this.LoadStageParamFile();
  196. if (!this.InitResultData())
  197. {
  198. return 0;
  199. }
  200. return 1;
  201. }
  202. //将样品台坐标转换为Sem 坐标
  203. public PointF ConvertOTSToSemCoord(PointF POTSCoord)
  204. {
  205. System.Drawing.PointF VSemCoord = new System.Drawing.PointF();
  206. GetDefaultParam().GetStageDataParam().ConvertOTSToSEMCoord(POTSCoord, ref VSemCoord);
  207. return VSemCoord;
  208. }
  209. //将Sem 坐标转换为样品台坐标
  210. public PointF ConverSEMToOTSCoord(PointF PSEMCoord)
  211. {
  212. System.Drawing.PointF VOTSCoord = new System.Drawing.PointF();
  213. GetDefaultParam().GetStageDataParam().ConvertSEMToOTSCoord(PSEMCoord, ref VOTSCoord);
  214. return VOTSCoord;
  215. }
  216. //添加样品
  217. //string sSHoleName: 样品孔名,当在样品孔上点击右键添加样品时,sSHoleName=样品孔名。当MEASUREAPP和TREEVIEW添加样品时,sSHoleName=""
  218. //返回新的工作样品名称
  219. public OTSSamplePropertyInfo AddNewSampleMeasure(string a_strHoleName = "")
  220. {
  221. COTSSample NewSample = new COTSSample();
  222. SetSampleDefaultPara(ref NewSample, a_strHoleName);
  223. //NewSample.
  224. //添加样品
  225. GetResultData().AddSample(NewSample);
  226. // 获取样品的属性值
  227. OTSSamplePropertyInfo MeasureInfo = new OTSSamplePropertyInfo();
  228. if (!GetWorkSamplePerameter(NewSample, ref MeasureInfo))
  229. {
  230. return null;
  231. }
  232. return MeasureInfo;
  233. }
  234. public OTSSamplePropertyInfo DeleteCurrentSampleData()
  235. {
  236. COTSSample Sample = GetWorkSample();
  237. if (Sample == null) return null;
  238. var sname= Sample.GetName();
  239. var pathname = resultData.GetFolderName(resultData.GetPathName());
  240. var sampleResultFolder = pathname + "\\" + sname;
  241. if (Directory.Exists(sampleResultFolder))
  242. {
  243. Directory.Delete(sampleResultFolder, true);
  244. var flds = Sample.GetFieldsData();
  245. foreach (var f in flds)
  246. {
  247. f.SetIsMeasureComplete(false);
  248. }
  249. }
  250. var sta = Sample.GetMsrStatus();
  251. sta.ClearCompletedFieldsInfo();
  252. sta.SetStatus(OTS_MSR_SAMPLE_STATUS.UNMEASURED);
  253. var rsts = Sample.GetMsrResults();
  254. var itms = rsts.GetResultItems();
  255. itms.Clear();
  256. rsts.SetResultItems(itms);
  257. rsts.SetMeasuredArea(0);
  258. rsts.SetRatio(0);
  259. // 获取样品的属性值
  260. OTSSamplePropertyInfo MeasureInfo = new OTSSamplePropertyInfo();
  261. if (!GetWorkSamplePerameter(Sample, ref MeasureInfo))
  262. {
  263. return null;
  264. }
  265. return MeasureInfo;
  266. }
  267. protected COTSSample SetSampleDefaultPara(ref COTSSample pSample, String a_strHoleName)
  268. {
  269. // get new sample name
  270. String strNewSampleName = GetNewSampleName();
  271. // make sure the new sample name is not an empty string
  272. strNewSampleName.Trim();
  273. // get a suitable sample hole for the new sample
  274. CHole pHole = SelectASmpleHole(a_strHoleName);
  275. // check the sample hole
  276. if (pHole == null)
  277. {
  278. // failed to get sample hole for the new sample
  279. return null;
  280. }
  281. // measurement area
  282. CDomain pMsrArea = CalculateDefaultArea(pHole);
  283. // measure data parameters containing particle analysis std, image scan parameter, image process parameter and x-ray parameter
  284. CSampleParam poMsrParams = new CSampleParam();
  285. poMsrParams.m_nPackId = GetDefaultParam().m_systemTypeId;
  286. poMsrParams.m_runmode = GetDefaultParam().m_runmode;
  287. var m_pParam = GetDefaultParam().GetGenParam();
  288. MEMBRANE_TYPE a_nVal = (MEMBRANE_TYPE)m_pParam.GetMembraneType();
  289. poMsrParams.SetImageScanParam(GetDefaultParam().GetImageScanParam ());
  290. poMsrParams.SetImageProcessParam(GetDefaultParam().GetImageProcParam());
  291. poMsrParams.SetXRayParam(GetDefaultParam().GetXRayParam());
  292. String sSTDName = m_pParam.GetSTDSelect();
  293. poMsrParams.SetSTDName(sSTDName);
  294. poMsrParams.SetSteelTechnology((STEEL_TECHNOLOGY)m_pParam.GetSteelTechnology());
  295. poMsrParams.SetSpecialGrayRangeParam(SpecialRanges);
  296. // set sample parameters
  297. pSample.SetName(strNewSampleName);
  298. pSample.SetSampleHoleName(pHole.GetName());
  299. pSample.SetSwitch(m_pParam.GetMeasurementSwitch());
  300. poMsrParams.SetSysSTDSwitch(m_pParam.GetSysSTD());
  301. pSample.SetMsrDomain(pMsrArea);
  302. pSample.SetMembraneType(a_nVal);
  303. pSample.SetMsrParams(poMsrParams);
  304. CSEMDataMsr semData = new CSEMDataMsr();
  305. var m_pSEMStageData = GetDefaultParam().GetStageDataParam();
  306. var imageScanParam = GetDefaultParam().GetImageScanParam();
  307. string resol = imageScanParam.GetImageResulotion().ToString();
  308. double resWidth = Convert.ToDouble(resol.Split('_')[1]);
  309. double resHeight = Convert.ToDouble(resol.Split('_')[2]);
  310. double heightWidthRatio = resHeight / resWidth;
  311. semData.SetScanFieldSize100(m_pSEMStageData.GetScanFieldSize100());
  312. double fieldHeight = m_pSEMStageData.GetScanFieldSize100() * heightWidthRatio;
  313. semData.SetScanFieldHeight100((int)fieldHeight);
  314. pSample.SetSEMDataMsr(semData);
  315. return pSample;
  316. }
  317. public String GetNewSampleName()
  318. {
  319. // new sample name
  320. String strNewSmplName = "";
  321. // safety check
  322. var m_pParam = GetDefaultParam().GetGenParam();
  323. if (m_pParam == null)
  324. {
  325. // shouldn't happen, invalid general parameter pointer.
  326. return strNewSmplName;
  327. }
  328. // new sample name base
  329. String strNewSmplNameBase = m_pParam.GetSampleName() + @"{0}";
  330. int nIndex = 1;
  331. do
  332. {
  333. // new sample name is new sample name base + number string
  334. strNewSmplName = string.Format(strNewSmplNameBase, nIndex);
  335. ++nIndex;
  336. }
  337. // make sure that the new sample name is not same with any sample in the samples list
  338. while (SameNameInList(strNewSmplName));
  339. // new sample name
  340. return strNewSmplName;
  341. }
  342. public bool SameNameInList(String a_strSampleName, int a_nExclude = -1)
  343. {
  344. // make sure the input sample name is not empty
  345. a_strSampleName.Trim();
  346. if (a_strSampleName == "")
  347. {
  348. // shouldn't happen, input name is an empty string
  349. return false;
  350. }
  351. // go through sample list
  352. int nIndex = 0;
  353. var m_listSamples = GetResultData().GetSampleList();
  354. foreach (var pSample in m_listSamples)
  355. {
  356. // return TRUE if this is not an exclude sample and its name is same with input
  357. String strSampleName = pSample.GetName();
  358. if (nIndex != a_nExclude && strSampleName.CompareTo(a_strSampleName) == 0)
  359. {
  360. // find a same name sample
  361. return true;
  362. }
  363. ++nIndex;
  364. }
  365. // no, same name sample in the same list, return FALSE
  366. return false;
  367. }
  368. // select a suitable sample hole for a new sample
  369. public CHole SelectASmpleHole(String a_strHoleName /*= _T("")*/)
  370. {
  371. // get holes list of the stage
  372. var m_pStage = GetStageParam().GetWorkingStage();
  373. List<CHole> listHoles = m_pStage.GetHoleList();
  374. //返回样品孔对象
  375. CHole cReHole ;
  376. // make sure the holes list is not empty
  377. if (listHoles.Count == 0)
  378. {
  379. // shouldn't happen, stage have no hole.
  380. return null;
  381. }
  382. // check the input hole name
  383. a_strHoleName.Trim();
  384. if (a_strHoleName != "")
  385. {
  386. // try to find matched hole
  387. for (int i = 0; i < listHoles.Count; i++)
  388. {
  389. if (listHoles[i].GetName() == a_strHoleName)
  390. {
  391. cReHole = listHoles[i];
  392. return cReHole;
  393. }
  394. }
  395. }
  396. // can't find a matched hole, then pick the first empty hole
  397. // go through the holes list
  398. foreach (var pHole in listHoles)
  399. {
  400. // has this hole any sample in it?
  401. String strHoleName = pHole.GetName();
  402. bool IsChanged = false;
  403. var m_listSamples = GetResultData().GetSampleList();
  404. foreach (COTSSample sampleItem in m_listSamples)
  405. {
  406. if (strHoleName == sampleItem.GetSampleHoleName())
  407. {
  408. IsChanged = true;
  409. }
  410. }
  411. if (!IsChanged)
  412. {
  413. return pHole;
  414. }
  415. }
  416. // no empty hole, then the first hole will be the one
  417. return listHoles[0];
  418. }
  419. public CDomain CalculateDefaultArea(CHole a_pHole)
  420. {
  421. RectangleF rectHole = a_pHole.GetDomainRect();
  422. System.Drawing.PointF ptCenter = new System.Drawing.PointF((rectHole.Left + rectHole.Right) / 2, (rectHole.Top + rectHole.Bottom) / 2);
  423. var m_pParam = GetDefaultParam().GetGenParam();
  424. DOMAIN_SHAPE nShape = m_pParam.GetShape();
  425. double dArea = m_pParam.GetArea() * 1000000;
  426. System.Drawing.PointF ptLeftTop = new System.Drawing.Point();
  427. System.Drawing.SizeF ptSize = new System.Drawing.Size();
  428. int nEdge = 0;
  429. int nRadius = 0;
  430. switch ((int)nShape)
  431. {
  432. case (int)DOMAIN_SHAPE.RECTANGLE:
  433. nEdge = (int)Math.Sqrt(dArea) / 2;
  434. ptLeftTop.X = ptCenter.X - nEdge;
  435. ptLeftTop.Y = ptCenter.Y - nEdge;
  436. ptSize.Width = ptCenter.X + nEdge - ptLeftTop.X;
  437. ptSize.Height = ptCenter.Y + nEdge - ptLeftTop.Y;
  438. break;
  439. case (int)DOMAIN_SHAPE.ROUND:
  440. nRadius = (int)Math.Sqrt(dArea / 3.1415926);
  441. ptLeftTop.X = ptCenter.X - nRadius;
  442. ptLeftTop.Y = ptCenter.Y - nRadius;
  443. ptSize.Width = ptCenter.X + nRadius - ptLeftTop.X;
  444. ptSize.Height = ptCenter.Y + nRadius - ptLeftTop.Y;
  445. break;
  446. }
  447. RectangleF MsrRect = new RectangleF(ptLeftTop, ptSize);
  448. CDomain pMsrArea = new CDomain(nShape, MsrRect);
  449. return pMsrArea;
  450. }
  451. //设置工作样品的属性值
  452. public bool SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS ItemId, OTS_ITEM_TYPES ValType, object objVal)
  453. {
  454. COTSSample WSample = GetResultData().GetWorkingSample();
  455. bool bSetFalg = false;
  456. bSetFalg = WSample.SetParamVal(ItemId, ValType, objVal);
  457. if (bSetFalg)
  458. {
  459. GetResultData().SetModify(true);
  460. }
  461. return bSetFalg;
  462. }
  463. //获取工作样品名称
  464. public string GetWorkSampleName()
  465. {
  466. COTSSample WSample = GetResultData().GetWorkingSample();
  467. if (null == WSample)
  468. {
  469. return "";
  470. }
  471. string sWorkSampleName = WSample.GetName();
  472. if ("" == sWorkSampleName)
  473. {
  474. return "";
  475. }
  476. return sWorkSampleName;
  477. }
  478. //设置工作样品
  479. //string sNewWorkSampleName: 新工作样品
  480. public bool SetWorkSample(string sNewWorkSampleName)
  481. {
  482. if ("" == sNewWorkSampleName)
  483. {
  484. return false;
  485. }
  486. if (!GetResultData().SetWorkingSampleByName(sNewWorkSampleName))
  487. {
  488. return false;
  489. }
  490. return true;
  491. }
  492. //获取工作样品
  493. // 返回工作样品对象
  494. public COTSSample GetWorkSample()
  495. {
  496. COTSSample WSample = GetResultData().GetWorkingSample();
  497. return WSample;
  498. }
  499. //删除工作样品
  500. //string sWorkSampleName : 删除工作样品名称
  501. public bool DeleteWorkSample(string sWorkSampleName)
  502. {
  503. return GetResultData().DeleteSampleByName(sWorkSampleName);
  504. }
  505. // 获取样品总数
  506. //返回样品总数
  507. public int GetSampleCount()
  508. {
  509. return GetResultData().GetSampleList().Count();
  510. }
  511. //改变工作样品名称
  512. //String sWSampleNewName
  513. public bool ChangeWorkSampleName(String sWSampleNewName)
  514. {
  515. if (!GetResultData().IsValidSampleName(sWSampleNewName))
  516. {
  517. return false;
  518. }
  519. COTSSample WorkSample = GetResultData().GetWorkingSample();
  520. if (null == WorkSample)
  521. {
  522. return false;
  523. }
  524. WorkSample.SetName(sWSampleNewName);
  525. GetResultData().SetModify(true);
  526. return true;
  527. }
  528. //移动工作样品到其他样品孔,样品孔名称和测量区域都要改变,重新设置工作样品参数
  529. public void SetWorkSampleHoleAndMeasureArea(SampleMeasurePara SMeasurePara)
  530. {
  531. COTSSample WSample = GetResultData().GetWorkingSample();
  532. if (null == WSample)
  533. {
  534. return ;
  535. }
  536. CDomain Domain = new CDomain();
  537. Domain.SetShape((otsdataconst.DOMAIN_SHAPE)SMeasurePara.iShape);
  538. Domain.SetRectDomain(SMeasurePara.MeasureRect);
  539. if (SMeasurePara.DrawPolygonPointList != null)
  540. {
  541. List<Point> PolygonPoint = new List<Point>();
  542. foreach (var item in SMeasurePara.DrawPolygonPointList)
  543. {
  544. PolygonPoint.Add(new Point((int)item.X, (int)item.Y));
  545. }
  546. Domain.SetPolygonPoint(PolygonPoint);
  547. }
  548. WSample.SetSampleHoleName(SMeasurePara.sampleHoleName);
  549. WSample.SetMsrDomain(Domain);
  550. return ;
  551. }
  552. //设置测量区域的形状 (通过RIBBON 上的画圆,画矩形 设置)
  553. //int iShape: 测量区域形状 0: 圆形; 1 :矩形
  554. public void SetMeasureAreaShape(ShapeType iShape)
  555. {
  556. COTSSample WSample = GetResultData().GetWorkingSample();
  557. if (null == WSample)
  558. {
  559. return;
  560. }
  561. CDomain Domain = new CDomain();
  562. Domain.SetShape((otsdataconst.DOMAIN_SHAPE)iShape);
  563. }
  564. //修改了ITEMID后,重新更新GROUPID和ITEMID
  565. public void UpdateGroupValAndItemVal(OTS_SAMPLE_PROP_GRID_ITEMS ItemID)
  566. {
  567. OTS_SAMPLE_PROP_GRID_ITEM_GROUPS GroupID = OTS_SAMPLE_PROP_GRID_ITEM_GROUPS.INVALID;
  568. OTS_SAMPLE_PROP_GRID_ITEMS iItemID = OTS_SAMPLE_PROP_GRID_ITEMS.INVALID;
  569. COTSSample WSample = GetResultData().GetWorkingSample();
  570. if (null == WSample)
  571. {
  572. return;
  573. }
  574. if (!WSample.GetRelatedPropItemGrp((OTS_SAMPLE_PROP_GRID_ITEMS)ItemID, ref GroupID))
  575. {
  576. bool bFlag = WSample.GetRelatedPropItem(ItemID, ref iItemID);
  577. }
  578. }
  579. //设置样品参数锁
  580. //bool ParaLockFlag : 样品参数锁
  581. public bool SetWorkSampleParamLock(bool ParaLockFlag)
  582. {
  583. COTSSample WSample = GetResultData().GetWorkingSample();
  584. if (null == WSample)
  585. {
  586. return false;
  587. }
  588. WSample.SetParamLock(ParaLockFlag);
  589. GetResultData().SetModify(true);
  590. return true;
  591. }
  592. //获取工作样品锁
  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. GetResultData().GetWorkingSample().GetSEMDataMsr().SetWorkingDistance(iWDistance);
  1024. GetResultData().GetWorkingSample().GetSEMDataMsr().SetMagnification(dMagni);
  1025. }
  1026. public void SetFliedsCount(int FliedsCount)
  1027. {
  1028. GetResultData().GetWorkingSample().GetSEMDataMsr().SetTotalFields(FliedsCount);
  1029. }
  1030. public void GetWorkingSampleSEMData(ref double iWDistance, ref double dMagni)
  1031. {
  1032. iWDistance = GetResultData().GetWorkingSample().GetSEMDataMsr().GetWorkingDistance();
  1033. dMagni = GetResultData().GetWorkingSample().GetSEMDataMsr().GetMagnification();
  1034. }
  1035. public int GetTotalFieldsCount()
  1036. {
  1037. int icount = GetResultData().GetWorkingSample().GetSEMDataMsr().GetTotalFields();
  1038. return icount;
  1039. }
  1040. //获取工作样品的测量区域
  1041. //int iShape :测量区域形状
  1042. //Rectangle Srect: 测量区域大小
  1043. public bool GetWorkSampleMrsArea(ref int iShape, ref RectangleF Srect)
  1044. {
  1045. COTSSample WSample = GetResultData().GetWorkingSample();
  1046. if (null == WSample)
  1047. {
  1048. return false;
  1049. }
  1050. CDomain pMsrArea = new CDomain();
  1051. pMsrArea = WSample.GetMsrDomain();
  1052. if (null == pMsrArea)
  1053. {
  1054. return false;
  1055. }
  1056. iShape = (int)pMsrArea.GetShape();
  1057. Srect = pMsrArea.GetRectDomain();
  1058. return true;
  1059. }
  1060. //检查Samplelist中的sample的checkbox状态
  1061. //当Samplelist中的链表有sample 的checkbox状态是选中状态,则返回TRUE. 说明可以测量
  1062. public bool GetSampleCheckBoxStatus()
  1063. {
  1064. COTSSample WSample = GetResultData().GetWorkingSample();
  1065. if (null == WSample)
  1066. {
  1067. return false;
  1068. }
  1069. List<COTSSample> SampleList = new List<COTSSample>();
  1070. SampleList = GetResultData().GetSampleList();
  1071. int iCount = SampleList.Count();
  1072. if (0 == iCount)
  1073. {
  1074. return false;
  1075. }
  1076. for (int i = 0; i < iCount; i++)
  1077. {
  1078. if (SampleList[i].GetSwitch())
  1079. {
  1080. return true;
  1081. }
  1082. }
  1083. return false;
  1084. }
  1085. //获取BSE图像数据
  1086. public bool GetBSEImageSize(ref int iHeight, ref int iWidth)
  1087. {
  1088. COTSSample WSample = GetResultData().GetWorkingSample();
  1089. if (null == WSample)
  1090. {
  1091. return false;
  1092. }
  1093. if (!WSample.GetBSESize(out iHeight, out iWidth))
  1094. {
  1095. return false;
  1096. }
  1097. return true;
  1098. }
  1099. //获取图像尺寸
  1100. public string GetBSEImageResolution()
  1101. {
  1102. try
  1103. {
  1104. COTSSample WSample = GetResultData().GetWorkingSample();
  1105. if (null == WSample)
  1106. {
  1107. return "";
  1108. }
  1109. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  1110. if (!GetWorkSamplePerameter(WSample, ref SMInfo))
  1111. {
  1112. return "";
  1113. }
  1114. int iCount = SMInfo.SampleDataList.Count();
  1115. for (int i = 0; i < iCount; i++)
  1116. {
  1117. if (OTS_SAMPLE_PROP_GRID_ITEMS.IMAGE_RESOLUTION == SMInfo.SampleDataList[i].iSampleId)
  1118. {
  1119. String val = (String)SMInfo.SampleDataList[i].SampleVal;
  1120. return val;
  1121. }
  1122. }
  1123. return "";
  1124. }
  1125. catch (Exception)
  1126. {
  1127. return "";
  1128. }
  1129. }
  1130. //获取放大倍数和工作距离
  1131. public bool GetMagAndDistance(ref double SemMag, ref double dDistance)
  1132. {
  1133. COTSSample WSample = GetResultData().GetWorkingSample();
  1134. if (null == WSample)
  1135. {
  1136. return false;
  1137. }
  1138. //GetWorkingSampleSEMData(ref SemMag, ref dDistance);
  1139. GetWorkingSampleSEMData(ref dDistance, ref SemMag);
  1140. return true;
  1141. }
  1142. public bool GetWorkSamplePerameter(COTSSample Sample, ref OTSSamplePropertyInfo SMeasureInfo)
  1143. {
  1144. SMeasureInfo.ClearGrp();
  1145. //设置工作样品属性项
  1146. if (Sample.GetMsrParams().m_nPackId == OTS_SysType_ID.CleannessA)
  1147. {
  1148. Sample.SetPropItemGrpsWithOutIncASysLib();
  1149. }
  1150. else if (Sample.GetMsrParams().m_nPackId == OTS_SysType_ID.IncA)
  1151. {
  1152. Sample.SetPropItemGrpsForIncA();
  1153. }
  1154. //样品的标题名 (Treeview的根节点名)
  1155. SMeasureInfo.sSampleSoluName = GetResultData().GetFileName();
  1156. // Treeview 的样品信息
  1157. SMeasureInfo.TSampleParam.sSampleTitleName = GetResultData().GetFileName();
  1158. //获得 样品属性值
  1159. SMeasureInfo.bSwitch = Sample.GetSwitch();// (bool)jo.GetValue("bSwitch");
  1160. SMeasureInfo.TSampleParam.bParamLock = Sample.GetParamLock();// (bool)jo.GetValue("ParamLock");
  1161. //获取样品的测量区域信息
  1162. //获取样品名称
  1163. SMeasureInfo.SMeasurePara.sSampleName = Sample.GetName();// (String)SMeasurePara.GetValue("sNewSampleName");
  1164. // 获取测量区域形状
  1165. SMeasureInfo.SMeasurePara.iShape = (ShapeType)Sample.GetMsrDomain().GetShape();// (int)SMeasurePara.GetValue("iShape");
  1166. //获取样品孔名称
  1167. SMeasureInfo.SMeasurePara.sampleHoleName = Sample.GetSampleHoleName();// (String)SMeasurePara.GetValue("sHoleName");
  1168. //样品测量区域
  1169. // JObject rec = (JObject)SMeasurePara.GetValue("MeasureRect");
  1170. RectangleF rec = Sample.GetMsrDomain().GetDomainRect();
  1171. SMeasureInfo.SMeasurePara.MeasureRect = new Rectangle((int)rec.X, (int)rec.Y, (int)rec.Width, (int)rec.Height);
  1172. SMeasureInfo.TSampleParam.sWorkSampleName = Sample.GetName();// (String)TSampleParam.GetValue("sWorkSampleName");
  1173. SMeasureInfo.TSampleParam.bSwitch = Sample.GetSwitch();// (bool)TSampleParam.GetValue("bSwitch");
  1174. List<CPropItemGrp> ja = Sample.GetPropItemGrps();// (JArray)jo.GetValue("ItemGrp");
  1175. for (int i = 0; i < ja.Count; i++)
  1176. {
  1177. //获取GROUP ID和Grid的显示组的标题名
  1178. var grp = ja[i];
  1179. int grpId = (int)grp.GetGroupId();
  1180. String sTitle = (String)grp.GetName();
  1181. //获取样品属性ID和值
  1182. var SDataArr = grp.GetItemsList();
  1183. if (SDataArr.Count == 0)
  1184. continue;
  1185. SamplePropertyDataGroup smlgrp = new SamplePropertyDataGroup();
  1186. smlgrp.GroupId = (OTS_SAMPLE_PROP_GRID_ITEM_GROUPS)grpId;
  1187. smlgrp.sTitle = sTitle;
  1188. for (int j = 0; j < SDataArr.Count; j++)
  1189. {
  1190. var SDataObj = SDataArr[j];
  1191. SamplePropertyData SData = new SamplePropertyData();
  1192. int smplid = (int)SDataObj.GetSmplItemId();
  1193. SData.iSampleId = (OTS_SAMPLE_PROP_GRID_ITEMS)smplid;
  1194. if (SData.iSampleId == OTS_SAMPLE_PROP_GRID_ITEMS.WORKING_DISTANCE)
  1195. {
  1196. bool b = (bool)SDataObj.IsReadOnly();
  1197. }
  1198. SData.sSCaptionName = (String)SDataObj.GetName();
  1199. //------------------------------修改--------------------------
  1200. //bool MeasurementStatus = false;
  1201. //if (SDataObj.GetSmplItemId() == OTS_SAMPLE_PROP_GRID_ITEMS.SAMPLE_NAME) //"样品名")
  1202. //{
  1203. // for (int a = 0; a < ja.Count; a++)
  1204. // {
  1205. // var grpa = ja[a];
  1206. // var SDataArra = grpa.GetItemsList();
  1207. // for (int b = 0; b < SDataArra.Count; b++)
  1208. // {
  1209. // var SDataObb = SDataArra[b];
  1210. // if (SDataObb.GetSmplItemId() == OTS_SAMPLE_PROP_GRID_ITEMS.MEASURE_STATAU)//"测量状态")
  1211. // {
  1212. // if (Sample.GetItemValueStr(SDataObb.GetSmplItemId()) == "未测量")
  1213. // if (Sample.GetItemValue(SDataObb.GetSmplItemId()) == "未测量")
  1214. // {
  1215. // MeasurementStatus = false;
  1216. // }
  1217. // else
  1218. // {
  1219. // MeasurementStatus = true;
  1220. // }
  1221. // }
  1222. // }
  1223. // }
  1224. //}
  1225. //else
  1226. //{
  1227. // MeasurementStatus = false;
  1228. //}
  1229. //if (MeasurementStatus)
  1230. //{
  1231. // SData.bReadOnly = MeasurementStatus;
  1232. //}
  1233. //else
  1234. //{
  1235. // SData.bReadOnly = (bool)SDataObj.IsReadOnly();// OTS_ITEM_TYPES
  1236. //}
  1237. //---------------------------------------------------------------
  1238. int type = (int)SDataObj.GetTypeId();
  1239. SData.iSampleValType = (OTS_ITEM_TYPES)type;
  1240. SData.sDescriptionInfo = (String)SDataObj.GetDescription();
  1241. OTS_SAMPLE_PROP_GRID_ITEMS ItemId = SDataObj.GetSmplItemId();
  1242. SData.SampleVal = (String)Sample.GetItemValueStr(ItemId);
  1243. List<string> downStrList = new List<string>();
  1244. if (type == (int)OTS_ITEM_TYPES.COMBO)
  1245. {
  1246. Sample.GetPropComboStrings(SDataObj.GetSmplItemId(), downStrList);
  1247. }
  1248. else if (type == (int)OTS_ITEM_TYPES.FILE_LIST)
  1249. {
  1250. //the sample object dosen't know anything about the fileList infomation so it has to delay this duty here.
  1251. int iPos = -1;
  1252. List<string> sFileNameList = new List<string>();
  1253. if (OTS_SAMPLE_PROP_GRID_ITEMS.MEASURE_PARAM_FILE_NAME == (OTS_SAMPLE_PROP_GRID_ITEMS)smplid)
  1254. {
  1255. if (!this.GetMeasureParamFileName(ref iPos, ref sFileNameList))
  1256. {
  1257. return false;
  1258. }
  1259. foreach (var f in sFileNameList)
  1260. {
  1261. downStrList.Add(f);
  1262. }
  1263. }
  1264. if (OTS_SAMPLE_PROP_GRID_ITEMS.STD_FILE_NAME == (OTS_SAMPLE_PROP_GRID_ITEMS)smplid)
  1265. {
  1266. if (!this.GetSTDFileName(ref iPos, ref sFileNameList))
  1267. {
  1268. return false;
  1269. }
  1270. foreach (var f in sFileNameList)
  1271. {
  1272. downStrList.Add(f);
  1273. }
  1274. }
  1275. }
  1276. if (downStrList.Count > 0)
  1277. {
  1278. for (int k = 0; k < downStrList.Count; k++)
  1279. {
  1280. SData.comboDownList.Add((String)downStrList[k]);
  1281. }
  1282. }
  1283. smlgrp.SampleDataList.Add(SData);
  1284. }
  1285. SMeasureInfo.AddASampleDataGrp(smlgrp);
  1286. }
  1287. return true;
  1288. }
  1289. //保存测量样品的
  1290. public bool SaveMeasureSampleInfo()
  1291. {
  1292. if (!GetResultData().Save())
  1293. {
  1294. return false;
  1295. }
  1296. return true;
  1297. }
  1298. //获取测量Sample的开始时间
  1299. public bool GetMsrSampleStartTime(ref DateTime MsrFieldStartTime)
  1300. {
  1301. COTSSample WSample = GetResultData().GetWorkingSample();
  1302. if (null == WSample)
  1303. {
  1304. return false;
  1305. }
  1306. MsrFieldStartTime = (DateTime)WSample.GetMsrStatus().GetStartTime();
  1307. return true;
  1308. }
  1309. //获取测量已用时间
  1310. public bool GetMsrSampleUsedTime(ref TimeSpan TUsedTime)
  1311. {
  1312. COTSSample WSample = GetResultData().GetWorkingSample();
  1313. if (null == WSample)
  1314. {
  1315. return false;
  1316. }
  1317. TUsedTime = (TimeSpan)WSample.GetMsrStatus().GetUsedTime();
  1318. return true;
  1319. }
  1320. // 获取测量样品中之前已经测量完成Field帧图,(上一次未测量完成继续测试)
  1321. public bool GetBeforeCompleteField(ref string MsrSampleName, ref List<PointF> FieldList)
  1322. {
  1323. COTSSample WSample = GetResultData().GetWorkingSample();
  1324. if (null == WSample)
  1325. {
  1326. return false;
  1327. }
  1328. MsrSampleName = WSample.GetName();
  1329. FieldList = WSample.GetMsrStatus().GetCompletedFieldsCenter();
  1330. return true;
  1331. }
  1332. /// <summary>
  1333. /// 通过样品孔信息 返回默认测量区域大小
  1334. /// </summary>
  1335. /// <param name="cHoleClr"></param>
  1336. /// <returns></returns>
  1337. public RectangleF CalculateMsrArea(string cHoleName)
  1338. {
  1339. CHole cHoleClr = null;
  1340. foreach (CHole item in GetResultData().GetStage().GetHoleList())
  1341. {
  1342. if (item.GetName() == cHoleName)
  1343. {
  1344. cHoleClr = item;
  1345. }
  1346. }
  1347. CDomain CDomain = GetResultData().CalculateMsrArea(cHoleClr);
  1348. return CDomain.GetRectDomain();
  1349. }
  1350. /// <summary>
  1351. /// 获取已完成测量的结果文件路径
  1352. /// </summary>
  1353. /// <param name="mrFilePathList">返回测量结果文件路径</param>
  1354. /// <returns></returns>
  1355. public bool GetCompletedMeasureFileName(ref List<string> mrFilePathList)
  1356. {
  1357. //测量文件路径
  1358. string proFilePath = GetResultData().GetPathName();
  1359. //样品列表
  1360. List<COTSSample> sampleList = GetResultData().GetSampleList();
  1361. //获取样品数量
  1362. int sampleCount = sampleList.Count;
  1363. string mrSuffix = ".rst";
  1364. int existsCount = 0;
  1365. //获取测量文件路径
  1366. if (proFilePath.Equals("Untitled"))
  1367. {
  1368. return false;
  1369. }
  1370. string mrFolderPath = string.Empty;
  1371. try
  1372. {
  1373. mrFolderPath = proFilePath.Substring(0, proFilePath.LastIndexOf("\\"));
  1374. }
  1375. catch (Exception)
  1376. {
  1377. mrFolderPath = string.Empty;
  1378. }
  1379. for (int sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++)
  1380. {
  1381. int CompleteFieldsCount = sampleList[sampleIndex].GetMsrStatus().GetCompletedFields();
  1382. //如果样品已测量成功后再加载至报告程序中
  1383. if (CompleteFieldsCount > 0)
  1384. {
  1385. string sampleName = sampleList[sampleIndex].GetName();
  1386. string mrFilePath = mrFolderPath + "\\" + sampleName + "\\" + sampleName + mrSuffix;
  1387. //判断文件是否存在
  1388. if (File.Exists(mrFilePath))
  1389. {
  1390. if (mrFilePathList != null)
  1391. {
  1392. mrFilePathList.Add(mrFilePath);
  1393. }
  1394. existsCount++;
  1395. }
  1396. }
  1397. }
  1398. if (existsCount > 0)
  1399. {
  1400. return true;
  1401. }
  1402. return false;
  1403. }
  1404. /// <summary>
  1405. /// 获取工作样品的测量状态
  1406. /// </summary>
  1407. /// <param name="workingSampleName"></param>
  1408. /// <returns></returns>
  1409. public bool GetWorkSampleMeasureStatus()
  1410. {
  1411. bool reuslt = false;
  1412. COTSSample COTSSample = GetResultData().GetWorkingSample();
  1413. if (COTSSample == null) return false;
  1414. int sampleStatus = COTSSample.GetMsrStatus().GetCompletedFields();
  1415. if (sampleStatus > 0)
  1416. {
  1417. reuslt = true;
  1418. }
  1419. return reuslt;
  1420. }
  1421. }
  1422. }