OTSIncAMeasureAppForm.cs 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using OTS.WinFormsUI.Docking;
  6. using System.Runtime.InteropServices;
  7. using System.Collections;
  8. using CefSharp;
  9. using OTSDataType;
  10. using OTSModelSharp;
  11. using OTSModelSharp.ResourceManage;
  12. using static OTSDataType.otsdataconst;
  13. using System.Diagnostics;
  14. using OTSModelSharp.ServiceCenter;
  15. using OTSMeasureApp._0_OTSModel.Measure.ParamData;
  16. using OTSCLRINTERFACE;
  17. using System.IO;
  18. using System.Management;
  19. using System.Xml;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Runtime.Remoting.Channels.Ipc;
  23. using System.Runtime.Remoting.Channels;
  24. using System.Runtime.Remoting;
  25. using OTSMeasureApp.ServiceCenter;
  26. namespace OTSMeasureApp
  27. {
  28. public enum ShapeType
  29. {
  30. CIRCUL = 0, //圆形
  31. RECTANGLE = 1 //矩形
  32. };
  33. enum MessageBoxRev
  34. {
  35. DIALOG_YES = 0,
  36. DIALOG_NO = 1,
  37. DIALOG_CANCEL = 2
  38. }
  39. public partial class OTSIncAMeasureAppForm : Form
  40. {
  41. public static string m_SamplespaceWindowName = "样品台";
  42. public static string m_MeasureStauWindowName = "测量状态";
  43. public static string m_MeasureRetWindowName = "测量结果";
  44. public static string m_NoWindowName = "未知工作窗口";
  45. //国际化
  46. OTSCommon.Language lan;
  47. Hashtable table;
  48. public OTSRibbonFun m_RibbonFun = null;
  49. // 初始化日志类
  50. NLog.Logger log ;
  51. private PostLogMsg m_LogMsg;
  52. public const int MsgID = 0x0464;
  53. public const int LogMsgID = 0x0465;
  54. // Control m_ControlWindow = null;
  55. public OTSMeasureResultWindow m_MeasureRetWindow = null;
  56. public OTSMeasureStatusWindow m_MessureStatuWindow = null;
  57. public OTSSamplespaceWindow m_SamplepaceWindow = null;
  58. public OTSMeasureOutputNlog m_OTSMeasureOutputNlog = null;
  59. public COTSMeasureParam m_ProjParam = null;
  60. public COTSMsrPrjResultData m_ProjData;
  61. public OTSSolutionWindow m_SolutionWindows = null;
  62. public OTSPropertyWindow m_SPropertyWindows = null;
  63. //测量线程对象
  64. public CMeasureThreadWrapper m_MsrThreadWrapper = null;
  65. // 测量线程当前状态 True: 正在测量; False: 测量结束
  66. public bool MeasureThreadRunFlag { get => m_MsrThreadWrapper.BGWorkThreadIsRunning(); }
  67. public MSR_RUN_TYPE GetRunType()
  68. {
  69. return m_MsrThreadWrapper.GetDoRunType();
  70. }
  71. public void SetRunType(MSR_RUN_TYPE value)
  72. {
  73. m_MsrThreadWrapper.SetDoRunType(value);
  74. }
  75. public FileSystemWatcher fileWatcher = new FileSystemWatcher(Application.StartupPath+ @"\Config\SysData");
  76. public OTSIncAMeasureAppForm()
  77. {
  78. InitializeComponent();
  79. //国际化
  80. lan = new OTSCommon.Language(this);
  81. table = lan.GetNameTable(this.Name);
  82. m_SamplespaceWindowName = table["m_samplespacewindowname"].ToString();
  83. m_MeasureStauWindowName = table["m_measurestauwindowname"].ToString();
  84. m_MeasureRetWindowName = table["m_measureretwindowname"].ToString();
  85. m_NoWindowName = table["m_nowindowname"].ToString();
  86. m_OTSMeasureOutputNlog = new OTSMeasureOutputNlog();
  87. m_OTSMeasureOutputNlog.Show();
  88. // 初始化Docpanle
  89. m_SolutionWindows = new OTSSolutionWindow(this);
  90. m_SPropertyWindows = new OTSPropertyWindow(this);
  91. m_MeasureRetWindow = new OTSMeasureResultWindow(this);
  92. m_MeasureRetWindow.Text = m_MeasureRetWindowName;
  93. m_MessureStatuWindow = new OTSMeasureStatusWindow(this);
  94. m_MessureStatuWindow.Text = m_MeasureStauWindowName;
  95. m_SamplepaceWindow = new OTSSamplespaceWindow(this);
  96. m_SamplepaceWindow.Text = m_SamplespaceWindowName;
  97. //和DataMgr进行数据交互类
  98. m_ProjParam = new COTSMeasureParam(this);
  99. m_ProjData = m_ProjParam.GetResultData();
  100. //初始化Ribbon类,操作Ribbon按钮的可用或者不可用
  101. m_RibbonFun = new OTSRibbonFun(this);
  102. //初始化测量线程
  103. m_MsrThreadWrapper = new CMeasureThreadWrapper(this);//must be the last sentence of this procedure.
  104. fileWatcher.Changed += FileWatcher_Changed;
  105. fileWatcher.EnableRaisingEvents=true;
  106. }
  107. private void FileWatcher_Changed(object sender, FileSystemEventArgs e)
  108. {
  109. if (e.Name == "SpecialGrayConfig.xml")
  110. {
  111. m_ProjParam.SpecialRanges.IsInited = false;
  112. foreach (var s in this.m_ProjData.GetSampleList())
  113. {
  114. s.GetMsrParams().GetSpecialGrayRangeParam().IsInited = false;
  115. }
  116. }
  117. }
  118. private void OTSIncAMeasureAppForm_Load(object sender, EventArgs e)
  119. {
  120. try
  121. {
  122. ArrangWorkspaceWindow();
  123. log = NLog.LogManager.GetCurrentClassLogger();
  124. if (m_ProjParam.LoadParamFile() && m_ProjParam.LoadStageParamFile())
  125. {
  126. m_ProjParam.LoadSpecialGrayRangeParamFile();
  127. if (m_ProjParam.InitResultData())
  128. {
  129. m_RibbonFun.SetAllRibbonButnStatus(true);
  130. m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(),m_ProjData.GetSEMStageData());
  131. //添加启动系统界面显示
  132. if (m_ProjParam.GetDefaultParam().m_systemTypeId == OTS_SysType_ID.IncA)
  133. {
  134. this.Text += "(Inclusion)";
  135. }
  136. else if (m_ProjParam.GetDefaultParam().m_systemTypeId == OTS_SysType_ID.CleannessA)
  137. {
  138. this.Text += "(Cleanness)";
  139. }
  140. else if (m_ProjParam.GetDefaultParam().m_systemTypeId == OTS_SysType_ID.MiningA)
  141. {
  142. this.Text += "(Mining)";
  143. }
  144. }
  145. else
  146. {
  147. log.Error(" InitResultData() failed");
  148. }
  149. }
  150. else
  151. {
  152. log.Error("(OTSIncAMeasureAppForm.OTSIncAMeasureAppForm_Load) (LoadParamFile() && LoadStageParamFile()) failed");
  153. }
  154. if (!m_MsrThreadWrapper.ConnectSEM())
  155. {
  156. MessageBox.Show("Connect SEM failed!Please goto the SysMgrApp.exe to setup the proper parameter or check other parameter of the EDS software");
  157. System.Diagnostics.ProcessStartInfo process = new System.Diagnostics.ProcessStartInfo();
  158. process.FileName = "OTSSysMgrApp.exe";//打开app的路径
  159. process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
  160. System.Diagnostics.Process.Start(process);
  161. this.rbConnectHardware.Enabled = true;
  162. this.rbDisconnectHardware.Enabled = false;
  163. }
  164. this.rbConnectHardware.Enabled = false;
  165. this.rbDisconnectHardware.Enabled = true;
  166. log.Warn("SEM connect success!");
  167. PrepareIpcServer();
  168. log.Info("Ipc server start success!");
  169. //----------------------Test Code, Don't delete
  170. //var f = new BaseFunctionTest();
  171. //f.ShowDialog();
  172. //----------------------
  173. }
  174. catch (Exception ex)
  175. {
  176. log.Error(" OTSIncAMeasureAppForm_Load:" + ex.ToString());
  177. }
  178. }
  179. public void ArrangWorkspaceWindow()
  180. {
  181. //Show 样品台窗口
  182. m_SamplepaceWindow.Show(dockPanel);
  183. //Show 测量状态窗口
  184. m_MessureStatuWindow.Show(dockPanel);
  185. //Show 测量结果窗口
  186. m_MeasureRetWindow.Show(dockPanel);
  187. m_SolutionWindows.Show(dockPanel, DockState.DockLeft);
  188. //Show 测量过程中Log显示窗口
  189. m_OTSMeasureOutputNlog.Show(dockPanel, DockState.DockRight);
  190. dockPanel.DockRightPortion = 365;
  191. m_SPropertyWindows.Show(dockPanel);
  192. m_SamplepaceWindow.Activate();
  193. }
  194. private void rbReport_Click(object sender, EventArgs e)
  195. {
  196. //测量结果文件路径列表
  197. List<string> mrFilePathList = new List<string>();
  198. //获取测量结果文件路径列表
  199. bool result = m_ProjParam.GetCompletedMeasureFileName(ref mrFilePathList);
  200. if (result)
  201. {
  202. for (int i = 0; i < mrFilePathList.Count; i++)
  203. {
  204. mrFilePathList[i] = mrFilePathList[i].Replace(" ", "^");
  205. }
  206. //转换为数组
  207. string[] resultFilePath = mrFilePathList.ToArray();
  208. System.Diagnostics.ProcessStartInfo process = new System.Diagnostics.ProcessStartInfo();
  209. process.FileName = "OTSIncAReportApp.exe";//打开app的路径
  210. string FilePath = string.Join(" ", resultFilePath);
  211. process.Arguments = FilePath;//多个参数用空格隔开
  212. process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
  213. System.Diagnostics.Process.Start(process);
  214. }
  215. }
  216. // sNewWorkSampleName: 新工作样品名
  217. public void SwitchWSample(string sNewWorkSampleName)
  218. {
  219. m_ProjParam.SetWorkSample(sNewWorkSampleName);
  220. m_SolutionWindows.SwitchSample(sNewWorkSampleName);
  221. //获取新工作样品属性值
  222. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  223. m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo);
  224. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  225. //发送想你的样品名给Sample
  226. m_SamplepaceWindow.SwitchWorkSample(sNewWorkSampleName);
  227. }
  228. public void Rev_SoluWindowReqCheckBosStatuChange_Event(string sSampleName, bool bCheckBoxStatu)
  229. {
  230. string sWSampleName = m_ProjParam.GetWorkSampleName();
  231. if ("" == sWSampleName)
  232. {
  233. //不修改Tteeview 的工作样品属性值
  234. m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(sSampleName, !bCheckBoxStatu);
  235. return;
  236. }
  237. //Treeview更改的工作样品数的CHECKBOX 状态
  238. if (!m_ProjParam.SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS.SWITCH, OTS_ITEM_TYPES.BOOL, bCheckBoxStatu))
  239. {
  240. //不修改Tteeview 的工作样品属性值
  241. m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(sSampleName, !bCheckBoxStatu);
  242. return;
  243. }
  244. // 设置 开始 ,停止 和检查参数 按钮状态
  245. m_RibbonFun.SetMeasureRibbonButnStatu();
  246. //修改Grid工作样品的SWITCH值
  247. OTSSamplePropertyInfo SMeasurenfo = new OTSSamplePropertyInfo();
  248. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMeasurenfo))
  249. {
  250. return;
  251. }
  252. m_SPropertyWindows.DisplaySampleMeasureInfo(SMeasurenfo);
  253. }
  254. public bool EditWorkSampleName(string sSampleOldName, string sSampleNewName)
  255. {
  256. if (!m_ProjParam.ChangeWorkSampleName(sSampleNewName))
  257. {
  258. return false;
  259. }
  260. // 获取修改名称后的工作样品属性值
  261. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  262. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  263. {
  264. return false;
  265. }
  266. //获取修改名称后的工作样品属性值发送给Grid显示
  267. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  268. //给样品台发送新的工作样品名称
  269. m_SamplepaceWindow.ChangeWorkSampleName(sSampleNewName);
  270. return true;
  271. }
  272. public void SoluwindowReqAddSample()
  273. {
  274. //Treeview右键点击添加新样品
  275. this.AddNewSampleMeasure();
  276. }
  277. private void OTSIncAMeasureAppForm_FormClosing(object sender, FormClosingEventArgs e)
  278. {
  279. try
  280. {
  281. if (m_MsrThreadWrapper.BGWorkThreadIsRunning ()) //当前正在测量
  282. {
  283. e.Cancel = true;
  284. return;
  285. }
  286. if (m_MsrThreadWrapper.IsHavingNotCompleteSamples()) //当前正在测量
  287. {
  288. e.Cancel = true;
  289. MessageBox.Show("There is one sample is still in pausing state,please stop it!");
  290. return;
  291. }
  292. //判断测量结果文件修改后是否保存
  293. if (m_ProjData.IsModified())
  294. {
  295. string message = table["message2"].ToString();
  296. DialogResult lsdr = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
  297. if (lsdr == DialogResult.Yes)
  298. {
  299. //保存,退出
  300. m_ProjData.Save();
  301. //保存,直接退出
  302. Application.ExitThread();
  303. }
  304. else if (lsdr == DialogResult.No)
  305. {
  306. //不保存,直接退出
  307. Application.ExitThread();
  308. }
  309. else if (lsdr == DialogResult.Cancel)
  310. {
  311. //取消
  312. e.Cancel = true;
  313. return;
  314. }
  315. }
  316. log.Info("Disconnect SEM!");
  317. m_MsrThreadWrapper.DisconnectSEM();
  318. m_MsrThreadWrapper.SetWorkThreadPending();
  319. }
  320. catch (Exception ex)
  321. {
  322. string message = table["message3"].ToString();
  323. log.Error("OTSIncAMeasureAppForm_FormClosing-"+ message + ":" + ex.ToString());
  324. }
  325. Process.GetCurrentProcess().Kill();
  326. }
  327. //打开指定路径的文件
  328. private void ribbonOrbMenuItem1_OpenWorkspace_Click(object sender, EventArgs e)
  329. {
  330. OpenMeasureProjectFile();
  331. //UpdatePropertyVal();
  332. }
  333. //新建样品工作文件
  334. private void ribbonOrbMenuItem3_CreateWorkspace_Click(object sender, EventArgs e)
  335. {
  336. int iCreateNewFileResult = m_ProjParam.CreateNewFile();
  337. if (iCreateNewFileResult == 0)
  338. {
  339. log.Error("(OTSIncAMeasureAppForm.rbNew_CreateWorkspace_Click) m_DataMgrFun.CreateNewFile() Failed !");
  340. return;
  341. }
  342. else if(iCreateNewFileResult == 2)
  343. {
  344. log.Info("(OTSIncAMeasureAppForm.rbNew_CreateWorkspace_Click) m_DataMgrFun.CreateNewFile() Cancel !");
  345. return;
  346. }
  347. m_RibbonFun.SetAllRibbonButnStatus(true);
  348. //清除TREEVIEW和GRID上的显示的已经保存的样品信息
  349. m_SolutionWindows.m_TreeViewBase.DeleteAllTreeNode();
  350. m_SPropertyWindows.m_SampleGrid.HideGrid();
  351. //设置报告按钮
  352. rbPReport.Enabled = false;
  353. rbReport.Enabled = false;
  354. rbReClassify.Enabled = true;
  355. //新建项目时,设置属性窗体中的两个按钮也为不可用状态
  356. m_SPropertyWindows.TSLoad.Enabled = false;
  357. m_SPropertyWindows.TSSaveAs.Enabled = false;
  358. //绘制样品台
  359. m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(), m_ProjData.GetSEMStageData());
  360. //隐藏XrayTable控件
  361. m_MessureStatuWindow.HideXRayTable();
  362. //新建时重新初始化结果窗体结果
  363. m_MeasureRetWindow.SetInit();
  364. }
  365. // 新建样品时提示保存样品信息Messagebox
  366. public int ShowSaveInfoMsgBox()
  367. {
  368. string message = table["message4"].ToString();
  369. DialogResult dResult = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
  370. if (dResult == DialogResult.Yes)
  371. {
  372. return (int)MessageBoxRev.DIALOG_YES;
  373. }
  374. else if (dResult == DialogResult.No)
  375. {
  376. return (int)MessageBoxRev.DIALOG_NO;
  377. }
  378. else
  379. {
  380. return (int)MessageBoxRev.DIALOG_CANCEL;
  381. }
  382. }
  383. //打开已经保存的工作文件
  384. private bool DisplayExistSampleFile()
  385. {
  386. List<CTreeSampleParam> TSampleParamList = new List<CTreeSampleParam>();
  387. List<SampleMeasurePara> SampleMeasureAreaList = new List<SampleMeasurePara>();
  388. int iSampleCount = m_ProjData.GetSampleList().Count;
  389. if (0 == iSampleCount)
  390. {
  391. return false;
  392. }
  393. for (int i = 0; i < iSampleCount; i++)
  394. {
  395. CTreeSampleParam CTSampleParam = new CTreeSampleParam();
  396. COTSSample SampleClr = (m_ProjData.GetSampleList())[i];
  397. CTSampleParam.sSampleTitleName = m_ProjData.GetFileName();
  398. CTSampleParam.sWorkSampleName = SampleClr.GetName();
  399. CTSampleParam.bSwitch = SampleClr.GetSwitch();
  400. CTSampleParam.bParamLock = SampleClr.GetParamLock();
  401. TSampleParamList.Add(CTSampleParam);
  402. }
  403. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  404. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetResultData().GetWorkingSample(), ref SMInfo))
  405. {
  406. log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(), ref SMInfo) = false Failed !");
  407. return false;
  408. }
  409. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  410. m_SolutionWindows.OpenExistSampleFile(TSampleParamList, SMInfo.TSampleParam);
  411. if (!OpenExistSampleMeasureArea(ref SampleMeasureAreaList))
  412. {
  413. log.Error(" OpenExistSampleMeasureArea(ref SampleMeasureAreaList) Failed !");
  414. return false;
  415. }
  416. string sWSampleName = m_ProjParam.GetWorkSampleName();
  417. if ("" == sWSampleName)
  418. {
  419. log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile) m_DataMgrFun.GetWorkSampleName() = null !");
  420. return false;
  421. }
  422. m_SamplepaceWindow.OpenExistSampleFile(m_ProjData.GetStage(), m_ProjData.GetSEMStageData(), SampleMeasureAreaList);
  423. return true;
  424. }
  425. public bool OpenExistSampleMeasureArea(ref List<SampleMeasurePara> SampleMeasureParaList)
  426. {
  427. int iSListCount = m_ProjData.GetSampleList().Count;
  428. if (0 == iSListCount)
  429. {
  430. return false;
  431. }
  432. for (int i = 0; i < iSListCount; i++)
  433. {
  434. SampleMeasurePara SampleMeasureArea = new SampleMeasurePara();
  435. //获取样品的测量区域信息
  436. //获取样品名称
  437. SampleMeasureArea.sSampleName = (m_ProjData.GetSampleList())[i].GetName();
  438. // 获取测量区域形状
  439. SampleMeasureArea.iShape = (ShapeType)m_ProjData.GetSampleList()[i].GetMsrDomain().GetShape();
  440. //获取样品孔名称
  441. SampleMeasureArea.sampleHoleName = (m_ProjData.GetSampleList())[i].GetSampleHoleName();
  442. //样品测量区域
  443. SampleMeasureArea.MeasureRect =(m_ProjData.GetSampleList())[i].GetMsrDomain().GetRectDomain();
  444. //多边形点集合
  445. List<PointF> PointRegionF = new List<PointF>();
  446. List<Point> PolygonPoint = m_ProjData.GetSampleList()[i].GetMsrDomain().GetPolygonPoint();
  447. if (PolygonPoint != null)
  448. {
  449. foreach (var item in m_ProjData.GetSampleList()[i].GetMsrDomain().GetPolygonPoint())
  450. {
  451. PointRegionF.Add(new PointF(item.X, item.Y));
  452. }
  453. }
  454. SampleMeasureArea.DrawPolygonPointList = PointRegionF;
  455. SampleMeasureParaList.Add(SampleMeasureArea);
  456. }
  457. return true;
  458. }
  459. //打开指定路径的文件
  460. private void rbOpen_Click(object sender, EventArgs e)
  461. {
  462. OpenMeasureProjectFile();
  463. }
  464. private void rbDeleteSample_Click(object sender, EventArgs e)
  465. {
  466. //删除样品(样品必须先选中)
  467. string sWSampleName = m_ProjParam.GetWorkSampleName();
  468. if ("" == sWSampleName)
  469. {
  470. log.Error("(OTSIncAMeasureAppForm.rbDeleteSample_Click) m_DataMgrFun.GetWorkSampleName() = null Failed");
  471. return;
  472. }
  473. string message = table["message5"].ToString();
  474. string message6 = table["message6"].ToString();
  475. string sDeleteSampleName = message;
  476. sDeleteSampleName += sWSampleName;
  477. sDeleteSampleName += message6;
  478. if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  479. {
  480. //删除样品成功
  481. DeleteSample(sWSampleName);
  482. sWSampleName = m_ProjParam.GetWorkSampleName();
  483. if ("" != sWSampleName)
  484. {
  485. m_SolutionWindows.m_TreeViewBase.GetTreeWorkSampleNode(sWSampleName);
  486. m_SolutionWindows.treeView1.Focus();
  487. }
  488. }
  489. }
  490. //返回删除的工作样品名
  491. public void DeleteSample(string sDeleteWSampleName = "")
  492. {
  493. if (m_MsrThreadWrapper.m_measure.mapSmplMsr.ContainsKey(sDeleteWSampleName))
  494. {
  495. m_MsrThreadWrapper.m_measure.mapSmplMsr.Remove(sDeleteWSampleName);
  496. }
  497. if (!m_ProjParam.DeleteWorkSample(sDeleteWSampleName))
  498. {
  499. log.Error("(OTSIncAMeasureAppForm.DeleteSample) m_DataMgrFun.DeleteWorkSample(sDeleteWSampleName) Failed, sDeleteWSampleName = " + sDeleteWSampleName);
  500. }
  501. // 设置 开始 ,停止 和检查参数 按钮状态
  502. m_RibbonFun.SetMeasureRibbonButnStatu();
  503. //设置 删除,复位,圆形,矩形 按钮状态
  504. m_RibbonFun.SetSampleRibbonButnStatus();
  505. // 更新报告ribbon按钮状态
  506. m_RibbonFun.SetAllRibbonButnStatus(true);
  507. int iSampleCount = m_ProjParam.GetSampleCount();
  508. if (0 == iSampleCount)
  509. {
  510. //给工作样品台发送删除样品和新的工作样品名称
  511. m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName);
  512. m_SPropertyWindows.PropGrid.Hide();
  513. m_SolutionWindows.treeView1.Nodes.Clear();
  514. m_MessureStatuWindow.HideXRayTable();
  515. m_MeasureRetWindow.SetInit();
  516. return ;
  517. }
  518. else
  519. {
  520. string sNewWSName = m_ProjParam.GetWorkSampleName();
  521. if ("" == sNewWSName)
  522. {
  523. log.Error("(OTSIncAMeasureAppForm.DeleteSample) m_DataMgrFun.GetWorkSampleName() = null Failed");
  524. return ;
  525. }
  526. m_SolutionWindows.DeletCurrentSampleNode();
  527. m_SolutionWindows.DisplaySample(sNewWSName);
  528. //将测量状态初始化
  529. m_MessureStatuWindow.SetMeasureStatusInit();
  530. //给工作样品台发送删除样品和新的工作样品名称
  531. m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName);
  532. //设置工作样品
  533. SwitchWSample(sNewWSName);
  534. }
  535. return ;
  536. }
  537. private void rbAddSample_Click(object sender, EventArgs e)
  538. {
  539. this.AddNewSampleMeasure();//the system will choose the empty hole one by one according to the holeNo sequence.
  540. }
  541. public void AddNewSampleMeasure(string sSampleHoleName = "")
  542. {
  543. //样品的属性值
  544. OTSSamplePropertyInfo SMInfo = m_ProjParam.AddNewSampleMeasure(sSampleHoleName);
  545. if (null == SMInfo)
  546. {
  547. // 设置 开始 ,停止 和检查参数 按钮状态
  548. m_RibbonFun.SetMeasureRibbonButnStatu();
  549. log.Error("(OTSIncAMeasureAppForm.AddNewSample) m_DataMgrFun.AddNewSample(sSampleHoleName) = null ");
  550. return;
  551. }
  552. m_SPropertyWindows.TSSaveAs.Enabled = true;
  553. m_SPropertyWindows.TSLoad.Enabled = true;
  554. //给SampleWindow 发送样品信息
  555. m_SamplepaceWindow.AddSampleArea(SMInfo.SMeasurePara);
  556. m_SamplepaceWindow.ReadSEMDataAndSetToCurrentSample();
  557. //给PropWindow 发送工作样品属性信息
  558. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  559. //给SoluWindow 发送样品显示信息
  560. m_SolutionWindows.AddSampleMeasure(SMInfo.TSampleParam);
  561. // 设置 开始 ,停止 和检查参数 按钮状态
  562. m_RibbonFun.SetMeasureRibbonButnStatu();
  563. //设置 删除,复位,圆形,矩形 按钮状态
  564. m_RibbonFun.SetSampleRibbonButnStatus();
  565. //清空帧图信息
  566. SetRunType(MSR_RUN_TYPE.RUNMEASURE);
  567. }
  568. private void rbSelectDlg_Click(object sender, EventArgs e)
  569. {
  570. //判断样品台是否有样品,如果有样品则不能设置默认参数
  571. if (m_ProjParam.GetSampleCount() > 0)
  572. {
  573. MessageBox.Show("Cann't setup preference parameter,for you have added some samples!");
  574. return;
  575. }
  576. ProgMgrInfoForm ProgMgrForm = new ProgMgrInfoForm();
  577. if (DialogResult.OK == ProgMgrForm.ShowDialog())
  578. {
  579. if (m_ProjParam.LoadParamFile() && m_ProjParam.LoadStageParamFile())
  580. {
  581. if (m_ProjParam.InitResultData())
  582. {
  583. m_RibbonFun.SetAllRibbonButnStatus(true);
  584. //当样品台上有样品,则不更新样品台数据
  585. if (0 == m_ProjParam.GetSampleCount())
  586. {
  587. m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(), m_ProjData.GetSEMStageData());
  588. }
  589. }
  590. else
  591. {
  592. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) this.CheckMeasureSysFileExist() = false");
  593. }
  594. }
  595. else
  596. {
  597. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) (m_DataMgrFun.CheckParamFile() && m_DataMgrFun.CheckStageFile()) = false");
  598. }
  599. }
  600. }
  601. // 主Windows框右下角显示鼠标点的SEM坐标(样品台)
  602. public void ShowSemCoordvAL(string sSemCoord)
  603. {
  604. STSemCoordinate.Text = sSemCoord;
  605. statusStrip1.Refresh();
  606. }
  607. //// 主Windows框右下角显示鼠标点的灰度值(测量图)
  608. public void ShowGrayVal(string sGrayVal)
  609. {
  610. TSGrayVal.Text = sGrayVal;
  611. statusStrip1.Refresh();
  612. }
  613. //获取工作样品测量锁
  614. public bool GetWorkSampleParamLock(ref CTreeSampleParam TSParamLock)
  615. {
  616. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  617. if (!m_ProjParam.GetWSampleParaLock(ref SMInfo))
  618. {
  619. return false;
  620. }
  621. TSParamLock = SMInfo.TSampleParam;
  622. return true;
  623. }
  624. /// <summary>
  625. /// 更新属性窗口
  626. /// </summary>
  627. public void UpdatePropertyVal()
  628. {
  629. //获取新的工作样品属性值
  630. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  631. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  632. {
  633. log.Error("(OTSIncAMeasureAppForm.SetSEMData) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(),ref SMInfo) = false Failed");
  634. }
  635. // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息
  636. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  637. }
  638. private void ribbonOrbMenuItemSaveAs_Click(object sender, EventArgs e)
  639. {
  640. bool iRev = m_ProjData.SaveAs();
  641. if (!iRev)
  642. {
  643. return;
  644. }
  645. }
  646. private void rbSaveFile_Click(object sender, EventArgs e)
  647. {
  648. bool iRev = m_ProjData.Save();
  649. if (!iRev)
  650. {
  651. return;
  652. }
  653. }
  654. private void rbCheckParam_Click(object sender, EventArgs e)
  655. {
  656. //检查样品测量参数
  657. if (m_ProjParam.CheckSampleParam(true))
  658. {
  659. string message = table["message7"].ToString();
  660. MessageBox.Show(message, "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  661. }
  662. }
  663. private void ribReset_Click(object sender, EventArgs e)
  664. {
  665. //调用样品台窗口中的复位方法
  666. m_SamplepaceWindow.ResetWorkSampleMeasure();
  667. }
  668. //绘制圆形测量区域
  669. private void ribCircle_Click(object sender, EventArgs e)
  670. {
  671. //修改工作样品的测量区域为圆形
  672. m_SamplepaceWindow.DrawCircleMeasure();
  673. }
  674. private void rbThreePoints_Click(object sender, EventArgs e)
  675. {
  676. //修改工作样品的测量区域为圆形
  677. m_SamplepaceWindow.DrawCircleMeasureByThreePoints();
  678. }
  679. private void rbRingShape_Click(object sender, EventArgs e)
  680. {
  681. //修改工作样品的测量区域为圆形
  682. m_SamplepaceWindow.DrawRingShapeArea();
  683. }
  684. //绘制矩形测量区域
  685. private void ribRectangle_Click(object sender, EventArgs e)
  686. {
  687. //修改工作样品的测量区域为矩形
  688. m_SamplepaceWindow.DrawRectangleMeasure();
  689. }
  690. private void rbExitApp_Click(object sender, EventArgs e)
  691. {
  692. this.Close();
  693. }
  694. private void rbStart_Click(object sender, EventArgs e)
  695. {
  696. if (!m_ProjParam.CheckSampleParam(false))
  697. {
  698. return;
  699. }
  700. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning() && !m_MsrThreadWrapper.BgWorkIsPaused())
  701. {
  702. SetRunType(MSR_RUN_TYPE.RUNMEASURE);
  703. //m_MsrThreadWrapper.SetDoRunType(MSR_RUN_TYPE.RUNMEASURE);
  704. m_MsrThreadWrapper.StartBGWorkThread();
  705. m_RibbonFun.SetMeasureRibbonButnStatu();
  706. }
  707. else //thread is in pausing state
  708. {
  709. SetRunType(MSR_RUN_TYPE.RUNMEASURE);
  710. //m_MsrThreadWrapper.SetDoRunType(MSR_RUN_TYPE.RUNMEASURE);
  711. m_MsrThreadWrapper.SetMeasureThreadStatus(OTS_MSR_THREAD_STATUS.INPROCESS);
  712. m_RibbonFun.SetMeasureRibbonButnStatu();
  713. }
  714. }
  715. public void SetStartMeasureRibbonStatus()
  716. {
  717. ribView.Enabled = false;
  718. m_RibbonFun.SetToolButnStatu(false);
  719. //false: 将其他ribbon按钮设置为灰色
  720. rbPanelFile.Enabled = false;
  721. rbPanelSample.Enabled = false;
  722. m_SolutionWindows.Enabled = false;
  723. m_SPropertyWindows.Enabled = false;
  724. rbStart.Enabled = false;
  725. //rbPause.Enabled = true;
  726. rbStop.Enabled = true;
  727. rbCheckParam.Enabled = false;
  728. }
  729. private void rbStop_Click(object sender, EventArgs e)
  730. {
  731. //如果当前正在测量,则停止测量线程
  732. if (MeasureThreadRunFlag)
  733. {
  734. //停止测量线程
  735. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.STOPPED);
  736. }
  737. else if (m_MsrThreadWrapper.m_measure.GetMsrThreadStatus() .GetStatus()== OTS_MSR_THREAD_STATUS.PAUSED)
  738. {
  739. foreach (KeyValuePair<string, CSmplMeasure> smpl in m_MsrThreadWrapper.m_measure.mapSmplMsr)
  740. {
  741. if (smpl.Value.GetSample().GetMsrStatus().GetStatus() == OTS_MSR_SAMPLE_STATUS.PAUSED)
  742. {
  743. smpl.Value.TheLastWorkOfSampleMeasure();
  744. return;
  745. }
  746. }
  747. }
  748. }
  749. private void rbPause_Click(object sender, EventArgs e)
  750. {
  751. //如果当前正在测量,则停止测量线程
  752. if (MeasureThreadRunFlag)
  753. {
  754. //停止测量线程
  755. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.PAUSED);
  756. }
  757. }
  758. private void rbRuler_Click(object sender, EventArgs e)
  759. {
  760. m_SamplepaceWindow.ShowRulerLocation();
  761. }
  762. private void rbSmapleName_Click(object sender, EventArgs e)
  763. {
  764. //m_SamplepaceWindow.ChangeSampleHoleFont();
  765. }
  766. private void rbSmaplePhoto_Click(object sender, EventArgs e)
  767. {
  768. m_SamplepaceWindow.ChangeSampleHoleImage();
  769. }
  770. //当点击Ribbon停止按钮时,设置Ribbon状态
  771. public void SetStopMeasureRibbonStatus()
  772. {
  773. ribView.Enabled = true;
  774. m_RibbonFun.SetToolButnStatu(true);
  775. rbPanelFile.Enabled = true;
  776. rbPanelSample.Enabled = true;
  777. m_RibbonFun.SetMeasureRibbonButnStatu();
  778. m_SolutionWindows.Enabled = true;
  779. m_SPropertyWindows.Enabled = true;
  780. rbStart.Enabled = true;
  781. rbPause.Enabled = false;
  782. rbStop.Enabled = false;
  783. rbCheckParam.Enabled = true;
  784. }
  785. public void SetPauseMeasureRibbonStatus()
  786. {
  787. ribView.Enabled = true;
  788. m_RibbonFun.SetToolButnStatu(true);
  789. rbPanelFile.Enabled = true;
  790. rbPanelSample.Enabled = true;
  791. m_RibbonFun.SetMeasureRibbonButnStatu();
  792. m_SolutionWindows.Enabled = true;
  793. m_SPropertyWindows.Enabled = true;
  794. rbStart.Enabled = true;
  795. rbPause.Enabled = false;
  796. rbStop.Enabled = true;
  797. rbCheckParam.Enabled = false;
  798. }
  799. public bool SwitchMeasureSample(string sMsrSampleName)
  800. {
  801. if (!m_ProjParam.SetWorkSample(sMsrSampleName))
  802. {
  803. log.Error("(OTSIncAMeasureAppForm.SwitchMeasureSample) SetWorkSample(sMsrSampleName =" + sMsrSampleName + ") Failed !");
  804. return false;
  805. }
  806. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  807. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  808. {
  809. log.Error("(OTSIncAMeasureAppForm.SwitchMeasureSample) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(), ref SMInfo) = false Failed !");
  810. return false;
  811. }
  812. // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息
  813. m_SolutionWindows.SwitchSample(sMsrSampleName);
  814. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  815. return true;
  816. }
  817. #region 开始获取样品孔中的照片
  818. /// <summary>
  819. /// 开始获取样品孔中的照片
  820. /// </summary>
  821. /// <param name="doRunType"></param>
  822. /// <param name="HoleID"></param>
  823. /// <param name="c_DomainMessure"></param>
  824. public void StartSampleHoleBSEImage(int HoleID)
  825. {
  826. //设置获取样品孔中照片所需的参数
  827. m_MsrThreadWrapper.SetHoleImagePreview(HoleID);
  828. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning())
  829. {
  830. m_MsrThreadWrapper.StartBGWorkThread();
  831. m_RibbonFun.SetMeasureRibbonButnStatu();
  832. }
  833. }
  834. #endregion
  835. private void rbRecover_Click(object sender, EventArgs e)
  836. {
  837. //关闭所有内容
  838. CloseAllContents();
  839. //显示样品属性窗口与树结构窗口
  840. m_SolutionWindows.Show(dockPanel, DockState.DockLeft);
  841. m_SPropertyWindows.Show(dockPanel);
  842. //显示样品台窗口 测量状态与测量结果窗口
  843. m_SamplepaceWindow.Show(dockPanel);
  844. m_MessureStatuWindow.Show(dockPanel);
  845. m_MeasureRetWindow.Show(dockPanel);
  846. //此处将在父窗体选项卡上显示
  847. foreach (Form child in this.MdiChildren)
  848. {
  849. if (child.Name == "OTSSamplespaceWindow")
  850. {
  851. child.Activate();
  852. break;
  853. }
  854. }
  855. }
  856. private void CloseAllContents()
  857. {
  858. m_SolutionWindows.DockPanel = null;
  859. m_SPropertyWindows.DockPanel = null;
  860. m_SamplepaceWindow.DockPanel = null;
  861. m_MessureStatuWindow.DockPanel = null;
  862. m_MeasureRetWindow.DockPanel = null;
  863. CloseAllDocuments();
  864. }
  865. private void CloseAllDocuments()
  866. {
  867. if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  868. {
  869. foreach (Form form in MdiChildren)
  870. form.Close();
  871. }
  872. else
  873. {
  874. IDockContent[] documents = dockPanel.DocumentsToArray();
  875. foreach (IDockContent content in documents)
  876. content.DockHandler.Close();
  877. }
  878. }
  879. private void rbMeasureCircle_Click(object sender, EventArgs e)
  880. {
  881. m_ProjParam.SetMeasureAreaShape(ShapeType.CIRCUL);
  882. //修改工作样品的测量区域为圆形
  883. m_SamplepaceWindow.changeShape(ShapeType.CIRCUL);
  884. }
  885. private void rbMeasureRectangle_Click(object sender, EventArgs e)
  886. {
  887. m_ProjParam.SetMeasureAreaShape(ShapeType.RECTANGLE);
  888. //修改工作样品的测量区域为矩形
  889. m_SamplepaceWindow.changeShape(ShapeType.RECTANGLE);
  890. }
  891. //ctrl+s组合键进行保存
  892. private void OTSIncAMeasureAppForm_KeyDown(object sender, KeyEventArgs e)
  893. {
  894. if (e.KeyCode == Keys.S && e.Modifiers == Keys.Control)
  895. {
  896. bool iRev = m_ProjData.Save();
  897. if (!iRev)
  898. {
  899. log.Error("(OTSIncAMeasureAppForm.rbSaveFile_Click) m_DataMgrFun.SaveFile() Failed !");
  900. return;
  901. }
  902. log.Error("(OTSIncAMeasureAppForm.rbSaveAs_Click) m_DataMgrFun.SaveFile() Success !");
  903. }
  904. }
  905. private void rbSTDEdit_Click_1(object sender, EventArgs e)
  906. {
  907. OpenFileDialog openFileDialog = new OpenFileDialog();
  908. openFileDialog.Filter = "(*.db)|*.db";
  909. openFileDialog.InitialDirectory = Application.StartupPath + "\\Config\\SysData\\";
  910. openFileDialog.RestoreDirectory = true;
  911. openFileDialog.FilterIndex = 1;
  912. if (openFileDialog.ShowDialog() == DialogResult.OK)
  913. {
  914. try
  915. {
  916. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", openFileDialog.FileName);
  917. p.WaitForExit();
  918. }
  919. catch (Exception ex)
  920. {
  921. log.Error("OTSPartA_STDEditor:" + ex.ToString());
  922. }
  923. }
  924. //reload the setup data just now
  925. foreach (var s in this.m_ProjData.GetSampleList())
  926. {
  927. var stdname= s.GetMsrParams().GetSTDName();
  928. if (stdname != "NoSTDDB")
  929. {
  930. if (!stdname.Contains(".db"))
  931. {
  932. stdname += ".db";
  933. }
  934. var m_classifyEngine = new COTSClassifyEngineClr(EngineType.ParticleClassifyEng, stdname);
  935. m_classifyEngine.ReloadEngineDB();
  936. }
  937. }
  938. }
  939. private void rbSysMgrApp_Click(object sender, EventArgs e)
  940. {
  941. try
  942. {
  943. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSSysMgrApp.exe");
  944. p.WaitForExit();
  945. }
  946. catch (Exception ex)
  947. {
  948. log.Error("OTSSysMgrApp:" + ex.ToString());
  949. }
  950. }
  951. private void ribPolygon_Click(object sender, EventArgs e)
  952. {
  953. //修改工作样品的测量区域为矩形
  954. m_SamplepaceWindow.DrawPolygonMeasure();
  955. }
  956. private void rbReClassify_Click(object sender, EventArgs e)
  957. {
  958. this.Cursor = Cursors.WaitCursor;
  959. if (m_ProjData.Reclassify())
  960. {
  961. m_ProjData.Save();
  962. MessageBox.Show("reclassification success");
  963. }
  964. else
  965. {
  966. MessageBox.Show("reclassification failed");
  967. }
  968. this.Cursor = Cursors.Default;
  969. }
  970. /// <summary>
  971. /// 打开测量项目文件
  972. /// </summary>
  973. private void OpenMeasureProjectFile()
  974. {
  975. bool bOpenFlag=false;
  976. COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();
  977. string strPathName;
  978. // file open dialog
  979. OpenFileDialog openFileDialog = new OpenFileDialog();
  980. openFileDialog.Filter = "Probject Files (*.prj)|*.prj";
  981. if (openFileDialog.ShowDialog() != DialogResult.OK)
  982. {
  983. return ;
  984. }
  985. strPathName = openFileDialog.FileName;
  986. this.Cursor = Cursors.WaitCursor;
  987. if (ProjDataMgr.Load(strPathName))
  988. {
  989. m_ProjData = ProjDataMgr;
  990. m_ProjParam.SetResultData(m_ProjData);
  991. m_ProjParam.InitResultData();
  992. bOpenFlag = true;
  993. }
  994. this.Cursor = Cursors.Default;
  995. if (bOpenFlag)
  996. {
  997. if (!DisplayExistSampleFile())
  998. {
  999. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) OpenExistSampleFile() = false Failed !");
  1000. return;
  1001. }
  1002. m_RibbonFun.SetAllRibbonButnStatus(true);
  1003. }
  1004. else
  1005. {
  1006. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) m_DataMgrFun.OpenExistSampleFile() Failed !");
  1007. }
  1008. }
  1009. private void OTSIncAMeasureAppForm_FormClosed(object sender, FormClosedEventArgs e)
  1010. {
  1011. }
  1012. private void rbAbout_Click(object sender, EventArgs e)
  1013. {
  1014. About m_about = new About();
  1015. m_about.ShowDialog();
  1016. }
  1017. protected override void DefWndProc(ref Message m)
  1018. {
  1019. switch (m.Msg)
  1020. {
  1021. case MsgID:
  1022. break;
  1023. case LogMsgID:
  1024. m_LogMsg = new PostLogMsg();
  1025. m_LogMsg = (PostLogMsg)Marshal.PtrToStructure(m.LParam, typeof(PostLogMsg));
  1026. var log = NLog.LogManager.GetCurrentClassLogger();
  1027. string s = GetString(m_LogMsg.logMessage);
  1028. switch (m_LogMsg.logLevel)
  1029. {
  1030. case 1:
  1031. log.Trace(s);
  1032. break;
  1033. case 2:
  1034. log.Debug(s);
  1035. break;
  1036. case 3:
  1037. log.Info(s);
  1038. break;
  1039. case 4:
  1040. log.Warn(s);
  1041. break;
  1042. case 5:
  1043. log.Error(s);
  1044. break;
  1045. case 6:
  1046. log.Fatal(s);
  1047. break;
  1048. }
  1049. break;
  1050. default:
  1051. base.DefWndProc(ref m);
  1052. break;
  1053. }
  1054. }
  1055. private string GetString(char[] csStr)
  1056. {
  1057. int ilen = csStr.Length;
  1058. string csName = new string(csStr); //MSTMsg.STMSampleStu.cSName
  1059. csName.IndexOf('\0');
  1060. csName = csName.Substring(0, csName.IndexOf('\0'));
  1061. return csName;
  1062. }
  1063. private void PrepareIpcServer()
  1064. {
  1065. //Instantiate our server channel.
  1066. IpcServerChannel channel = new IpcServerChannel("ServerChannel");
  1067. //Register the server channel.
  1068. ChannelServices.RegisterChannel(channel, false);
  1069. //Register this service type.
  1070. RemotingConfiguration.RegisterWellKnownServiceType(typeof(IpcSEMController), "RemoteObject", WellKnownObjectMode.Singleton);
  1071. }
  1072. private void rbConnectHardware_Click_1(object sender, EventArgs e)
  1073. {
  1074. if (!m_MsrThreadWrapper.IsSEMConnected())
  1075. {
  1076. if (!m_MsrThreadWrapper.ConnectSEM())
  1077. {
  1078. MessageBox.Show("Connect failed!");
  1079. return;
  1080. }
  1081. }
  1082. this.rbConnectHardware.Enabled = false;
  1083. this.rbDisconnectHardware.Enabled = true;
  1084. log.Warn("SEM connect success!");
  1085. }
  1086. private void rbDisconnectHardware_Click_1(object sender, EventArgs e)
  1087. {
  1088. if (m_MsrThreadWrapper.IsSEMConnected())
  1089. {
  1090. m_MsrThreadWrapper.DisconnectSEM();
  1091. }
  1092. this.rbDisconnectHardware.Enabled = false;
  1093. this.rbConnectHardware.Enabled = true;
  1094. log.Warn("SEM Disconnect!");
  1095. }
  1096. private void rbinterrupt_Click(object sender, EventArgs e)
  1097. {
  1098. if (m_MsrThreadWrapper.IsSEMConnected())
  1099. {
  1100. m_MsrThreadWrapper.StopXrayAcquisition();
  1101. }
  1102. log.Warn("StopXrayAcquisition!");
  1103. }
  1104. private void rbAutoBeamOff_Click(object sender, EventArgs e)
  1105. {
  1106. if (m_ProjData.GetGenParam().AutoBeamOff)
  1107. {
  1108. m_ProjData.GetGenParam().AutoBeamOff = false;
  1109. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1110. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1111. }
  1112. else
  1113. {
  1114. m_ProjData.GetGenParam().AutoBeamOff = true;
  1115. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1116. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1117. }
  1118. }
  1119. }
  1120. }