COTSMeasureParam.cs 56 KB

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