OTSIncAMeasureAppForm.cs 50 KB

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