COTSMeasureParam.cs 58 KB

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