OTSIncAMeasureAppForm.cs 48 KB

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