OTSMeasureParam.cs 56 KB

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