OTSIncAMeasureAppForm.cs 49 KB

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