OTSIncAMeasureAppForm.cs 48 KB

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