OTSIncAMeasureAppForm.cs 50 KB

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