OTSIncAMeasureAppForm.cs 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  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. m_SamplepaceWindow.ReadSEMDataAndSetToCurrentSample();
  559. //给PropWindow 发送工作样品属性信息
  560. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  561. //给SoluWindow 发送样品显示信息
  562. m_SolutionWindows.AddSampleMeasure(SMInfo.TSampleParam);
  563. // 设置 开始 ,停止 和检查参数 按钮状态
  564. m_RibbonFun.SetMeasureRibbonButnStatu();
  565. //设置 删除,复位,圆形,矩形 按钮状态
  566. m_RibbonFun.SetSampleRibbonButnStatus();
  567. //清空帧图信息
  568. SetRunType(MSR_RUN_TYPE.RUNMEASURE);
  569. }
  570. private void rbSelectDlg_Click(object sender, EventArgs e)
  571. {
  572. //判断样品台是否有样品,如果有样品则不能设置默认参数
  573. if (m_ProjParam.GetSampleCount() > 0)
  574. {
  575. MessageBox.Show("Cann't setup preference parameter,for you have added some samples!");
  576. return;
  577. }
  578. ProgMgrInfoForm ProgMgrForm = new ProgMgrInfoForm();
  579. if (DialogResult.OK == ProgMgrForm.ShowDialog())
  580. {
  581. if (m_ProjParam.LoadParamFile() && m_ProjParam.LoadStageParamFile())
  582. {
  583. if (m_ProjParam.InitResultData())
  584. {
  585. m_RibbonFun.SetAllRibbonButnStatus(true);
  586. //当样品台上有样品,则不更新样品台数据
  587. if (0 == m_ProjParam.GetSampleCount())
  588. {
  589. m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(), m_ProjData.GetSEMStageData());
  590. }
  591. }
  592. else
  593. {
  594. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) this.CheckMeasureSysFileExist() = false");
  595. }
  596. }
  597. else
  598. {
  599. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) (m_DataMgrFun.CheckParamFile() && m_DataMgrFun.CheckStageFile()) = false");
  600. }
  601. }
  602. }
  603. // 主Windows框右下角显示鼠标点的SEM坐标(样品台)
  604. public void ShowSemCoordvAL(string sSemCoord)
  605. {
  606. STSemCoordinate.Text = sSemCoord;
  607. statusStrip1.Refresh();
  608. }
  609. //// 主Windows框右下角显示鼠标点的灰度值(测量图)
  610. public void ShowGrayVal(string sGrayVal)
  611. {
  612. TSGrayVal.Text = sGrayVal;
  613. statusStrip1.Refresh();
  614. }
  615. //获取工作样品测量锁
  616. public bool GetWorkSampleParamLock(ref CTreeSampleParam TSParamLock)
  617. {
  618. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  619. if (!m_ProjParam.GetWSampleParaLock(ref SMInfo))
  620. {
  621. return false;
  622. }
  623. TSParamLock = SMInfo.TSampleParam;
  624. return true;
  625. }
  626. /// <summary>
  627. /// 更新属性窗口
  628. /// </summary>
  629. public void UpdatePropertyVal()
  630. {
  631. //获取新的工作样品属性值
  632. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  633. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  634. {
  635. log.Error("(OTSIncAMeasureAppForm.SetSEMData) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(),ref SMInfo) = false Failed");
  636. }
  637. // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息
  638. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  639. }
  640. private void ribbonOrbMenuItemSaveAs_Click(object sender, EventArgs e)
  641. {
  642. bool iRev = m_ProjData.SaveAs();
  643. if (!iRev)
  644. {
  645. return;
  646. }
  647. }
  648. private void rbSaveFile_Click(object sender, EventArgs e)
  649. {
  650. bool iRev = m_ProjData.Save();
  651. if (!iRev)
  652. {
  653. return;
  654. }
  655. }
  656. private void rbCheckParam_Click(object sender, EventArgs e)
  657. {
  658. //检查样品测量参数
  659. if (m_ProjParam.CheckSampleParam(true))
  660. {
  661. string message = table["message7"].ToString();
  662. MessageBox.Show(message, "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  663. }
  664. }
  665. private void ribReset_Click(object sender, EventArgs e)
  666. {
  667. //调用样品台窗口中的复位方法
  668. m_SamplepaceWindow.ResetWorkSampleMeasure();
  669. }
  670. //绘制圆形测量区域
  671. private void ribCircle_Click(object sender, EventArgs e)
  672. {
  673. //修改工作样品的测量区域为圆形
  674. m_SamplepaceWindow.DrawCircleMeasure();
  675. }
  676. private void rbThreePoints_Click(object sender, EventArgs e)
  677. {
  678. //修改工作样品的测量区域为圆形
  679. m_SamplepaceWindow.DrawCircleMeasureByThreePoints();
  680. }
  681. private void rbRingShape_Click(object sender, EventArgs e)
  682. {
  683. //修改工作样品的测量区域为圆形
  684. m_SamplepaceWindow.DrawRingShapeArea();
  685. }
  686. //绘制矩形测量区域
  687. private void ribRectangle_Click(object sender, EventArgs e)
  688. {
  689. //修改工作样品的测量区域为矩形
  690. m_SamplepaceWindow.DrawRectangleMeasure();
  691. }
  692. private void rbExitApp_Click(object sender, EventArgs e)
  693. {
  694. this.Close();
  695. }
  696. private void rbStart_Click(object sender, EventArgs e)
  697. {
  698. if (!m_ProjParam.CheckSampleParam(false))
  699. {
  700. return;
  701. }
  702. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning() && !m_MsrThreadWrapper.BgWorkIsPaused())
  703. {
  704. SetRunType(MSR_RUN_TYPE.RUNMEASURE);
  705. //m_MsrThreadWrapper.SetDoRunType(MSR_RUN_TYPE.RUNMEASURE);
  706. m_MsrThreadWrapper.StartBGWorkThread();
  707. m_RibbonFun.SetMeasureRibbonButnStatu();
  708. }
  709. else //thread is in pausing state
  710. {
  711. SetRunType(MSR_RUN_TYPE.RUNMEASURE);
  712. //m_MsrThreadWrapper.SetDoRunType(MSR_RUN_TYPE.RUNMEASURE);
  713. m_MsrThreadWrapper.SetMeasureThreadStatus(OTS_MSR_THREAD_STATUS.INPROCESS);
  714. m_RibbonFun.SetMeasureRibbonButnStatu();
  715. }
  716. }
  717. public void SetStartMeasureRibbonStatus()
  718. {
  719. ribView.Enabled = false;
  720. m_RibbonFun.SetToolButnStatu(false);
  721. //false: 将其他ribbon按钮设置为灰色
  722. rbPanelFile.Enabled = false;
  723. rbPanelSample.Enabled = false;
  724. m_SolutionWindows.Enabled = false;
  725. m_SPropertyWindows.Enabled = false;
  726. rbStart.Enabled = false;
  727. //rbPause.Enabled = true;
  728. rbStop.Enabled = true;
  729. rbCheckParam.Enabled = false;
  730. }
  731. private void rbStop_Click(object sender, EventArgs e)
  732. {
  733. //如果当前正在测量,则停止测量线程
  734. if (MeasureThreadRunFlag)
  735. {
  736. //停止测量线程
  737. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.STOPPED);
  738. }
  739. else if (m_MsrThreadWrapper.m_measure.GetMsrThreadStatus() .GetStatus()== OTS_MSR_THREAD_STATUS.PAUSED)
  740. {
  741. foreach (KeyValuePair<string, CSmplMeasure> smpl in m_MsrThreadWrapper.m_measure.mapSmplMsr)
  742. {
  743. if (smpl.Value.GetSample().GetMsrStatus().GetStatus() == OTS_MSR_SAMPLE_STATUS.PAUSED)
  744. {
  745. smpl.Value.TheLastWorkOfSampleMeasure();
  746. return;
  747. }
  748. }
  749. }
  750. }
  751. private void rbPause_Click(object sender, EventArgs e)
  752. {
  753. //如果当前正在测量,则停止测量线程
  754. if (MeasureThreadRunFlag)
  755. {
  756. //停止测量线程
  757. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.PAUSED);
  758. }
  759. }
  760. private void rbRuler_Click(object sender, EventArgs e)
  761. {
  762. m_SamplepaceWindow.ShowRulerLocation();
  763. }
  764. private void rbSmapleName_Click(object sender, EventArgs e)
  765. {
  766. //m_SamplepaceWindow.ChangeSampleHoleFont();
  767. }
  768. private void rbSmaplePhoto_Click(object sender, EventArgs e)
  769. {
  770. m_SamplepaceWindow.ChangeSampleHoleImage();
  771. }
  772. //当点击Ribbon停止按钮时,设置Ribbon状态
  773. public void SetStopMeasureRibbonStatus()
  774. {
  775. ribView.Enabled = true;
  776. m_RibbonFun.SetToolButnStatu(true);
  777. rbPanelFile.Enabled = true;
  778. rbPanelSample.Enabled = true;
  779. m_RibbonFun.SetMeasureRibbonButnStatu();
  780. m_SolutionWindows.Enabled = true;
  781. m_SPropertyWindows.Enabled = true;
  782. rbStart.Enabled = true;
  783. rbPause.Enabled = false;
  784. rbStop.Enabled = false;
  785. rbCheckParam.Enabled = true;
  786. }
  787. public void SetPauseMeasureRibbonStatus()
  788. {
  789. ribView.Enabled = true;
  790. m_RibbonFun.SetToolButnStatu(true);
  791. rbPanelFile.Enabled = true;
  792. rbPanelSample.Enabled = true;
  793. m_RibbonFun.SetMeasureRibbonButnStatu();
  794. m_SolutionWindows.Enabled = true;
  795. m_SPropertyWindows.Enabled = true;
  796. rbStart.Enabled = true;
  797. rbPause.Enabled = false;
  798. rbStop.Enabled = true;
  799. rbCheckParam.Enabled = false;
  800. }
  801. public bool SwitchMeasureSample(string sMsrSampleName)
  802. {
  803. if (!m_ProjParam.SetWorkSample(sMsrSampleName))
  804. {
  805. log.Error("(OTSIncAMeasureAppForm.SwitchMeasureSample) SetWorkSample(sMsrSampleName =" + sMsrSampleName + ") Failed !");
  806. return false;
  807. }
  808. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  809. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  810. {
  811. log.Error("(OTSIncAMeasureAppForm.SwitchMeasureSample) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(), ref SMInfo) = false Failed !");
  812. return false;
  813. }
  814. // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息
  815. m_SolutionWindows.SwitchSample(sMsrSampleName);
  816. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  817. return true;
  818. }
  819. #region 开始获取样品孔中的照片
  820. /// <summary>
  821. /// 开始获取样品孔中的照片
  822. /// </summary>
  823. /// <param name="doRunType"></param>
  824. /// <param name="HoleID"></param>
  825. /// <param name="c_DomainMessure"></param>
  826. public void StartSampleHoleBSEImage(int HoleID)
  827. {
  828. //设置获取样品孔中照片所需的参数
  829. m_MsrThreadWrapper.SetHoleImagePreview(HoleID);
  830. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning())
  831. {
  832. m_MsrThreadWrapper.StartBGWorkThread();
  833. m_RibbonFun.SetMeasureRibbonButnStatu();
  834. }
  835. }
  836. #endregion
  837. private void rbRecover_Click(object sender, EventArgs e)
  838. {
  839. //关闭所有内容
  840. CloseAllContents();
  841. //显示样品属性窗口与树结构窗口
  842. m_SolutionWindows.Show(dockPanel, DockState.DockLeft);
  843. m_SPropertyWindows.Show(dockPanel);
  844. //显示样品台窗口 测量状态与测量结果窗口
  845. m_SamplepaceWindow.Show(dockPanel);
  846. m_MessureStatuWindow.Show(dockPanel);
  847. m_MeasureRetWindow.Show(dockPanel);
  848. //此处将在父窗体选项卡上显示
  849. foreach (Form child in this.MdiChildren)
  850. {
  851. if (child.Name == "OTSSamplespaceWindow")
  852. {
  853. child.Activate();
  854. break;
  855. }
  856. }
  857. }
  858. private void CloseAllContents()
  859. {
  860. m_SolutionWindows.DockPanel = null;
  861. m_SPropertyWindows.DockPanel = null;
  862. m_SamplepaceWindow.DockPanel = null;
  863. m_MessureStatuWindow.DockPanel = null;
  864. m_MeasureRetWindow.DockPanel = null;
  865. CloseAllDocuments();
  866. }
  867. private void CloseAllDocuments()
  868. {
  869. if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  870. {
  871. foreach (Form form in MdiChildren)
  872. form.Close();
  873. }
  874. else
  875. {
  876. IDockContent[] documents = dockPanel.DocumentsToArray();
  877. foreach (IDockContent content in documents)
  878. content.DockHandler.Close();
  879. }
  880. }
  881. private void rbMeasureCircle_Click(object sender, EventArgs e)
  882. {
  883. m_ProjParam.SetMeasureAreaShape(ShapeType.CIRCUL);
  884. //修改工作样品的测量区域为圆形
  885. m_SamplepaceWindow.changeShape(ShapeType.CIRCUL);
  886. }
  887. private void rbMeasureRectangle_Click(object sender, EventArgs e)
  888. {
  889. m_ProjParam.SetMeasureAreaShape(ShapeType.RECTANGLE);
  890. //修改工作样品的测量区域为矩形
  891. m_SamplepaceWindow.changeShape(ShapeType.RECTANGLE);
  892. }
  893. //ctrl+s组合键进行保存
  894. private void OTSIncAMeasureAppForm_KeyDown(object sender, KeyEventArgs e)
  895. {
  896. if (e.KeyCode == Keys.S && e.Modifiers == Keys.Control)
  897. {
  898. bool iRev = m_ProjData.Save();
  899. if (!iRev)
  900. {
  901. log.Error("(OTSIncAMeasureAppForm.rbSaveFile_Click) m_DataMgrFun.SaveFile() Failed !");
  902. return;
  903. }
  904. log.Error("(OTSIncAMeasureAppForm.rbSaveAs_Click) m_DataMgrFun.SaveFile() Success !");
  905. }
  906. }
  907. private void rbSTDEdit_Click_1(object sender, EventArgs e)
  908. {
  909. OpenFileDialog openFileDialog = new OpenFileDialog();
  910. openFileDialog.Filter = "(*.db)|*.db";
  911. openFileDialog.InitialDirectory = Application.StartupPath + "\\Config\\SysData\\";
  912. openFileDialog.RestoreDirectory = true;
  913. openFileDialog.FilterIndex = 1;
  914. if (openFileDialog.ShowDialog() == DialogResult.OK)
  915. {
  916. try
  917. {
  918. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", openFileDialog.FileName);
  919. p.WaitForExit();
  920. }
  921. catch (Exception ex)
  922. {
  923. log.Error("OTSPartA_STDEditor:" + ex.ToString());
  924. }
  925. }
  926. //reload the setup data just now
  927. foreach (var s in this.m_ProjData.GetSampleList())
  928. {
  929. var stdname= s.GetMsrParams().GetSTDName();
  930. if (stdname != "NoSTD")
  931. {
  932. if (!stdname.Contains(".db"))
  933. {
  934. stdname += ".db";
  935. }
  936. var m_classifyEngine = new COTSClassifyEngineClr(EngineType.ParticleClassifyEng, stdname);
  937. m_classifyEngine.ReloadEngineDB();
  938. }
  939. }
  940. }
  941. private void rbSysMgrApp_Click(object sender, EventArgs e)
  942. {
  943. try
  944. {
  945. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSSysMgrApp.exe");
  946. p.WaitForExit();
  947. }
  948. catch (Exception ex)
  949. {
  950. log.Error("OTSSysMgrApp:" + ex.ToString());
  951. }
  952. }
  953. private void ribPolygon_Click(object sender, EventArgs e)
  954. {
  955. //修改工作样品的测量区域为矩形
  956. m_SamplepaceWindow.DrawPolygonMeasure();
  957. }
  958. private void rbReClassify_Click(object sender, EventArgs e)
  959. {
  960. if (m_ProjData.Reclassify())
  961. {
  962. m_ProjData.Save();
  963. MessageBox.Show("reclassification success");
  964. }
  965. else
  966. {
  967. MessageBox.Show("reclassification failed");
  968. }
  969. }
  970. /// <summary>
  971. /// 打开测量项目文件
  972. /// </summary>
  973. private void OpenMeasureProjectFile()
  974. {
  975. bool bOpenFlag=false;
  976. COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();
  977. string strPathName;
  978. // file open dialog
  979. OpenFileDialog openFileDialog = new OpenFileDialog();
  980. openFileDialog.Filter = "Probject Files (*.prj)|*.prj";
  981. if (openFileDialog.ShowDialog() != DialogResult.OK)
  982. {
  983. return ;
  984. }
  985. strPathName = openFileDialog.FileName;
  986. if (ProjDataMgr.Load(strPathName))
  987. {
  988. m_ProjData = ProjDataMgr;
  989. m_ProjParam.SetResultData(m_ProjData);
  990. m_ProjParam.InitResultData();
  991. bOpenFlag = true;
  992. }
  993. if (bOpenFlag)
  994. {
  995. if (!DisplayExistSampleFile())
  996. {
  997. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) OpenExistSampleFile() = false Failed !");
  998. return;
  999. }
  1000. m_RibbonFun.SetAllRibbonButnStatus(true);
  1001. }
  1002. else
  1003. {
  1004. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) m_DataMgrFun.OpenExistSampleFile() Failed !");
  1005. }
  1006. }
  1007. private void OTSIncAMeasureAppForm_FormClosed(object sender, FormClosedEventArgs e)
  1008. {
  1009. }
  1010. private void rbAbout_Click(object sender, EventArgs e)
  1011. {
  1012. About m_about = new About();
  1013. m_about.ShowDialog();
  1014. }
  1015. protected override void DefWndProc(ref Message m)
  1016. {
  1017. switch (m.Msg)
  1018. {
  1019. case MsgID:
  1020. break;
  1021. case LogMsgID:
  1022. m_LogMsg = new PostLogMsg();
  1023. m_LogMsg = (PostLogMsg)Marshal.PtrToStructure(m.LParam, typeof(PostLogMsg));
  1024. var log = NLog.LogManager.GetCurrentClassLogger();
  1025. string s = GetString(m_LogMsg.logMessage);
  1026. switch (m_LogMsg.logLevel)
  1027. {
  1028. case 1:
  1029. log.Trace(s);
  1030. break;
  1031. case 2:
  1032. log.Debug(s);
  1033. break;
  1034. case 3:
  1035. log.Info(s);
  1036. break;
  1037. case 4:
  1038. log.Warn(s);
  1039. break;
  1040. case 5:
  1041. log.Error(s);
  1042. break;
  1043. case 6:
  1044. log.Fatal(s);
  1045. break;
  1046. }
  1047. break;
  1048. default:
  1049. base.DefWndProc(ref m);
  1050. break;
  1051. }
  1052. }
  1053. private string GetString(char[] csStr)
  1054. {
  1055. int ilen = csStr.Length;
  1056. string csName = new string(csStr); //MSTMsg.STMSampleStu.cSName
  1057. csName.IndexOf('\0');
  1058. csName = csName.Substring(0, csName.IndexOf('\0'));
  1059. return csName;
  1060. }
  1061. private void PrepareIpcServer()
  1062. {
  1063. //Instantiate our server channel.
  1064. IpcServerChannel channel = new IpcServerChannel("ServerChannel");
  1065. //Register the server channel.
  1066. ChannelServices.RegisterChannel(channel, false);
  1067. //Register this service type.
  1068. RemotingConfiguration.RegisterWellKnownServiceType(typeof(IpcSEMController), "RemoteObject", WellKnownObjectMode.Singleton);
  1069. }
  1070. private void rbConnectHardware_Click_1(object sender, EventArgs e)
  1071. {
  1072. if (!m_MsrThreadWrapper.IsSEMConnected())
  1073. {
  1074. if (!m_MsrThreadWrapper.ConnectSEM())
  1075. {
  1076. MessageBox.Show("Connect failed!");
  1077. return;
  1078. }
  1079. }
  1080. this.rbConnectHardware.Enabled = false;
  1081. this.rbDisconnectHardware.Enabled = true;
  1082. log.Warn("SEM connect success!");
  1083. }
  1084. private void rbDisconnectHardware_Click_1(object sender, EventArgs e)
  1085. {
  1086. if (m_MsrThreadWrapper.IsSEMConnected())
  1087. {
  1088. m_MsrThreadWrapper.DisconnectSEM();
  1089. }
  1090. this.rbDisconnectHardware.Enabled = false;
  1091. this.rbConnectHardware.Enabled = true;
  1092. log.Warn("SEM Disconnect!");
  1093. }
  1094. private void rbinterrupt_Click(object sender, EventArgs e)
  1095. {
  1096. if (m_MsrThreadWrapper.IsSEMConnected())
  1097. {
  1098. m_MsrThreadWrapper.StopXrayAcquisition();
  1099. }
  1100. log.Warn("StopXrayAcquisition!");
  1101. }
  1102. private void rbAutoBeamOff_Click(object sender, EventArgs e)
  1103. {
  1104. if (m_ProjData.GetGenParam().AutoBeamOff)
  1105. {
  1106. m_ProjData.GetGenParam().AutoBeamOff = false;
  1107. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1108. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1109. }
  1110. else
  1111. {
  1112. m_ProjData.GetGenParam().AutoBeamOff = true;
  1113. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1114. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1115. }
  1116. }
  1117. }
  1118. }