OTSIncAMeasureAppForm.cs 48 KB

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