COTSMeasureParam.cs 59 KB

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