OTSIncAMeasureAppForm.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388
  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. if (openFileDialog.ShowDialog() != DialogResult.OK)
  980. {
  981. return ;
  982. }
  983. strPathName = openFileDialog.FileName;
  984. if (ProjDataMgr.Load(strPathName))
  985. {
  986. m_ProjData = ProjDataMgr;
  987. m_ProjParam.SetResultData(m_ProjData);
  988. m_ProjParam.InitResultData();
  989. bOpenFlag = true;
  990. }
  991. if (bOpenFlag)
  992. {
  993. if (!DisplayExistSampleFile())
  994. {
  995. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) OpenExistSampleFile() = false Failed !");
  996. return;
  997. }
  998. m_RibbonFun.SetAllRibbonButnStatus(true);
  999. }
  1000. else
  1001. {
  1002. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) m_DataMgrFun.OpenExistSampleFile() Failed !");
  1003. }
  1004. }
  1005. private void OTSIncAMeasureAppForm_FormClosed(object sender, FormClosedEventArgs e)
  1006. {
  1007. }
  1008. private void rbAbout_Click(object sender, EventArgs e)
  1009. {
  1010. About m_about = new About();
  1011. m_about.ShowDialog();
  1012. }
  1013. protected override void DefWndProc(ref Message m)
  1014. {
  1015. switch (m.Msg)
  1016. {
  1017. case MsgID:
  1018. break;
  1019. case LogMsgID:
  1020. m_LogMsg = new PostLogMsg();
  1021. m_LogMsg = (PostLogMsg)Marshal.PtrToStructure(m.LParam, typeof(PostLogMsg));
  1022. var log = NLog.LogManager.GetCurrentClassLogger();
  1023. string s = GetString(m_LogMsg.logMessage);
  1024. switch (m_LogMsg.logLevel)
  1025. {
  1026. case 1:
  1027. log.Trace(s);
  1028. break;
  1029. case 2:
  1030. log.Debug(s);
  1031. break;
  1032. case 3:
  1033. log.Info(s);
  1034. break;
  1035. case 4:
  1036. log.Warn(s);
  1037. break;
  1038. case 5:
  1039. log.Error(s);
  1040. break;
  1041. case 6:
  1042. log.Fatal(s);
  1043. break;
  1044. }
  1045. break;
  1046. default:
  1047. base.DefWndProc(ref m);
  1048. break;
  1049. }
  1050. }
  1051. private string GetString(char[] csStr)
  1052. {
  1053. int ilen = csStr.Length;
  1054. string csName = new string(csStr); //MSTMsg.STMSampleStu.cSName
  1055. csName.IndexOf('\0');
  1056. csName = csName.Substring(0, csName.IndexOf('\0'));
  1057. return csName;
  1058. }
  1059. private void PrepareIpcServer()
  1060. {
  1061. //Instantiate our server channel.
  1062. IpcServerChannel channel = new IpcServerChannel("ServerChannel");
  1063. //Register the server channel.
  1064. ChannelServices.RegisterChannel(channel, false);
  1065. //Register this service type.
  1066. RemotingConfiguration.RegisterWellKnownServiceType(typeof(IpcSEMController), "RemoteObject", WellKnownObjectMode.Singleton);
  1067. }
  1068. private void rbConnectHardware_Click_1(object sender, EventArgs e)
  1069. {
  1070. if (!m_MsrThreadWrapper.IsSEMConnected())
  1071. {
  1072. if (!m_MsrThreadWrapper.ConnectSEM())
  1073. {
  1074. MessageBox.Show("Connect failed!");
  1075. return;
  1076. }
  1077. }
  1078. this.rbConnectHardware.Enabled = false;
  1079. this.rbDisconnectHardware.Enabled = true;
  1080. log.Warn("SEM connect success!");
  1081. }
  1082. private void rbDisconnectHardware_Click_1(object sender, EventArgs e)
  1083. {
  1084. if (m_MsrThreadWrapper.IsSEMConnected())
  1085. {
  1086. m_MsrThreadWrapper.DisconnectSEM();
  1087. }
  1088. this.rbDisconnectHardware.Enabled = false;
  1089. this.rbConnectHardware.Enabled = true;
  1090. log.Warn("SEM Disconnect!");
  1091. }
  1092. private void rbinterrupt_Click(object sender, EventArgs e)
  1093. {
  1094. if (m_MsrThreadWrapper.IsSEMConnected())
  1095. {
  1096. m_MsrThreadWrapper.StopXrayAcquisition();
  1097. }
  1098. log.Warn("StopXrayAcquisition!");
  1099. }
  1100. private void rbAutoBeamOff_Click(object sender, EventArgs e)
  1101. {
  1102. if (m_ProjData.GetGenParam().AutoBeamOff)
  1103. {
  1104. m_ProjData.GetGenParam().AutoBeamOff = false;
  1105. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1106. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1107. }
  1108. else
  1109. {
  1110. m_ProjData.GetGenParam().AutoBeamOff = true;
  1111. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1112. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1113. }
  1114. }
  1115. }
  1116. }