OTSIncAMeasureAppForm.cs 53 KB

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