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