OTSIncAMeasureAppForm.cs 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  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. OTSCommon.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 OTSCommon.Language(this);
  81. table = lan.GetNameTable(this.Name);
  82. m_SamplespaceWindowName = table["m_samplespacewindowname"].ToString();
  83. m_MeasureStauWindowName = table["m_measurestauwindowname"].ToString();
  84. m_MeasureRetWindowName = table["m_measureretwindowname"].ToString();
  85. m_NoWindowName = table["m_nowindowname"].ToString();
  86. m_OTSMeasureOutputNlog = new OTSMeasureOutputNlog();
  87. m_OTSMeasureOutputNlog.Show();
  88. // 初始化Docpanle
  89. m_SolutionWindows = new OTSSolutionWindow(this);
  90. m_SPropertyWindows = new OTSPropertyWindow(this);
  91. m_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.GetResultData();
  100. //初始化Ribbon类,操作Ribbon按钮的可用或者不可用
  101. m_RibbonFun = new OTSRibbonFun(this);
  102. //初始化测量线程
  103. m_MsrThreadWrapper = new CMeasureThreadWrapper(this);//must be the last sentence of this procedure.
  104. fileWatcher.Changed += FileWatcher_Changed;
  105. fileWatcher.EnableRaisingEvents=true;
  106. }
  107. private void FileWatcher_Changed(object sender, FileSystemEventArgs e)
  108. {
  109. if (e.Name == "SpecialGrayConfig.xml")
  110. {
  111. m_ProjParam.SpecialRanges.IsInited = false;
  112. foreach (var s in this.m_ProjData.GetSampleList())
  113. {
  114. s.GetMsrParams().GetSpecialGrayRangeParam().IsInited = false;
  115. }
  116. }
  117. }
  118. private void OTSIncAMeasureAppForm_Load(object sender, EventArgs e)
  119. {
  120. try
  121. {
  122. ArrangWorkspaceWindow();
  123. log = NLog.LogManager.GetCurrentClassLogger();
  124. if (m_ProjParam.LoadParamFile() && m_ProjParam.LoadStageParamFile())
  125. {
  126. m_ProjParam.LoadSpecialGrayRangeParamFile();
  127. if (m_ProjParam.InitResultData())
  128. {
  129. m_RibbonFun.SetAllRibbonButnStatus(true);
  130. m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(),m_ProjData.GetSEMStageData());
  131. //添加启动系统界面显示
  132. if (m_ProjParam.GetDefaultParam().m_nPackId == OTS_SysType_ID.IncA)
  133. {
  134. this.Text += "(Inclusion)";
  135. }
  136. else if (m_ProjParam.GetDefaultParam().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.GetResultData().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. if (m_ProjParam.LoadParamFile() && m_ProjParam.LoadStageParamFile())
  650. {
  651. if (m_ProjParam.InitResultData())
  652. {
  653. m_RibbonFun.SetAllRibbonButnStatus(true);
  654. //当样品台上有样品,则不更新样品台数据
  655. if (0 == m_ProjParam.GetSampleCount())
  656. {
  657. m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(), m_ProjData.GetSEMStageData());
  658. }
  659. }
  660. else
  661. {
  662. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) this.CheckMeasureSysFileExist() = false");
  663. }
  664. }
  665. else
  666. {
  667. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) (m_DataMgrFun.CheckParamFile() && m_DataMgrFun.CheckStageFile()) = false");
  668. }
  669. }
  670. }
  671. // 主Windows框右下角显示鼠标点的SEM坐标(样品台)
  672. public void ShowSemCoordvAL(string sSemCoord)
  673. {
  674. STSemCoordinate.Text = sSemCoord;
  675. // TSGrayVal.Text = sGrayVal;
  676. statusStrip1.Refresh();
  677. }
  678. //// 主Windows框右下角显示鼠标点的灰度值(测量图)
  679. public void ShowGrayVal(string sGrayVal)
  680. {
  681. TSGrayVal.Text = sGrayVal;
  682. statusStrip1.Refresh();
  683. }
  684. //获取工作样品测量锁
  685. public bool GetWorkSampleParamLock(ref CTreeSampleParam TSParamLock)
  686. {
  687. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  688. if (!m_ProjParam.GetWSampleParaLock(ref SMInfo))
  689. {
  690. return false;
  691. }
  692. TSParamLock = SMInfo.TSampleParam;
  693. return true;
  694. }
  695. /// <summary>
  696. /// 更新属性窗口
  697. /// </summary>
  698. public void UpdatePropertyVal()
  699. {
  700. //获取新的工作样品属性值
  701. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  702. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  703. {
  704. log.Error("(OTSIncAMeasureAppForm.SetSEMData) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(),ref SMInfo) = false Failed");
  705. }
  706. // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息
  707. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  708. }
  709. private void ribbonOrbMenuItemSaveAs_Click(object sender, EventArgs e)
  710. {
  711. bool iRev = m_ProjData.SaveAs();
  712. if (!iRev)
  713. {
  714. //log.Trace("(OTSIncAMeasureAppForm.ribbonOrbMenuItemSaveAs_Click) m_DataMgrFun.SaveAsFile() Failed !");
  715. return;
  716. }
  717. }
  718. private void rbSaveFile_Click(object sender, EventArgs e)
  719. {
  720. bool iRev = m_ProjData.Save();
  721. if (!iRev)
  722. {
  723. //log.Trace("(OTSIncAMeasureAppForm.rbSaveFile_Click) m_DataMgrFun.SaveFile() Failed !");
  724. return;
  725. }
  726. }
  727. private void rbCheckParam_Click(object sender, EventArgs e)
  728. {
  729. //检查样品测量参数
  730. if (m_ProjParam.CheckSampleParam(true))
  731. {
  732. string message = table["message7"].ToString();
  733. MessageBox.Show(message, "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  734. }
  735. }
  736. private void ribReset_Click(object sender, EventArgs e)
  737. {
  738. //调用样品台窗口中的复位方法
  739. m_SamplepaceWindow.ResetWorkSampleMeasure();
  740. }
  741. //绘制圆形测量区域
  742. private void ribCircle_Click(object sender, EventArgs e)
  743. {
  744. //修改工作样品的测量区域为圆形
  745. m_SamplepaceWindow.Rev_DDrawCircleMeasure_MeasureAppToSampleWindow_Event();
  746. }
  747. private void rbThreePoints_Click(object sender, EventArgs e)
  748. {
  749. //修改工作样品的测量区域为圆形
  750. m_SamplepaceWindow.Rev_DDrawCircleMeasureByThreePoints_MeasureAppToSampleWindow_Event();
  751. }
  752. //绘制矩形测量区域
  753. private void ribRectangle_Click(object sender, EventArgs e)
  754. {
  755. //修改工作样品的测量区域为矩形
  756. m_SamplepaceWindow.Rev_DDrawRectangleMeasure_MeasureAppToSampleWindow_Event();
  757. }
  758. private void rbExitApp_Click(object sender, EventArgs e)
  759. {
  760. this.Close();
  761. }
  762. /// <summary>
  763. /// 执行样品孔中照片后台线程
  764. /// </summary>
  765. private void StartSampleHoleImageBGWorkThread()
  766. {
  767. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning())
  768. {
  769. m_MessageStates = MessageState.ShotBSEPicture;
  770. m_MsrThreadWrapper.SetDoRunType((int)MSR_THREAD_RunSTATUS.RUNSampleHoleImage);
  771. m_MsrThreadWrapper.StartBGWorkThread();
  772. m_RibbonFun.SetMeasureRibbonButnStatu();
  773. }
  774. }
  775. private void rbStart_Click(object sender, EventArgs e)
  776. {
  777. if (!m_ProjParam.CheckSampleParam(false))
  778. {
  779. return;
  780. }
  781. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning())
  782. {
  783. //设置消息类型 拍摄样品孔
  784. m_MessageStates = (int)MessageState.StartMeasure;
  785. m_MsrThreadWrapper.SetDoRunType((int)MSR_THREAD_RunSTATUS.RUNMEASURE);
  786. m_MsrThreadWrapper.StartBGWorkThread();
  787. m_RibbonFun.SetMeasureRibbonButnStatu();
  788. }
  789. }
  790. public void SetStartMeasureRibbonStatus()
  791. {
  792. //this.PropertyMeasureThreadRunFlag = true;
  793. ribView.Enabled = false;
  794. m_RibbonFun.SetToolButnStatu(false);
  795. //false: 将其他ribbon按钮设置为灰色
  796. rbPanelFile.Enabled = false;
  797. rbPanelSample.Enabled = false;
  798. m_SolutionWindows.Enabled = false;
  799. m_SPropertyWindows.Enabled = false;
  800. rbStart.Enabled = false;
  801. rbStop.Enabled = true;
  802. rbCheckParam.Enabled = false;
  803. }
  804. private void rbStop_Click(object sender, EventArgs e)
  805. {
  806. //如果当前正在测量,则停止测量线程
  807. if (MeasureThreadRunFlag)
  808. {
  809. //停止测量线程
  810. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.STOPPED);
  811. }
  812. }
  813. private void rbRuler_Click(object sender, EventArgs e)
  814. {
  815. m_SamplepaceWindow.ShowRulerLocation();
  816. }
  817. private void rbSmapleName_Click(object sender, EventArgs e)
  818. {
  819. m_SamplepaceWindow.ChangeSampleHoleFont();
  820. }
  821. private void rbSmaplePhoto_Click(object sender, EventArgs e)
  822. {
  823. m_SamplepaceWindow.ChangeSampleHoleImage();
  824. }
  825. //当点击Ribbon停止按钮时,设置Ribbon状态
  826. public void SetStopMeasureRibbonStatus()
  827. {
  828. //this.PropertyMeasureThreadRunFlag = false;
  829. ribView.Enabled = true;
  830. m_RibbonFun.SetToolButnStatu(true);
  831. rbPanelFile.Enabled = true;
  832. rbPanelSample.Enabled = true;
  833. m_RibbonFun.SetMeasureRibbonButnStatu();
  834. m_SolutionWindows.Enabled = true;
  835. m_SPropertyWindows.Enabled = true;
  836. rbStart.Enabled = true;
  837. rbStop.Enabled = false;
  838. rbCheckParam.Enabled = true;
  839. }
  840. public bool SwitchMeasureSample(string sMsrSampleName)
  841. {
  842. if (!m_ProjParam.SetWorkSample(sMsrSampleName))
  843. {
  844. log.Error("(OTSIncAMeasureAppForm.SwitchMeasureSample) SetWorkSample(sMsrSampleName =" + sMsrSampleName + ") Failed !");
  845. return false;
  846. }
  847. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  848. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  849. {
  850. log.Error("(OTSIncAMeasureAppForm.SwitchMeasureSample) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(), ref SMInfo) = false Failed !");
  851. return false;
  852. }
  853. // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息
  854. m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(sMsrSampleName);
  855. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  856. return true;
  857. }
  858. #region 开始获取样品孔中的照片
  859. /// <summary>
  860. /// 开始获取样品孔中的照片
  861. /// </summary>
  862. /// <param name="doRunType"></param>
  863. /// <param name="HoleID"></param>
  864. /// <param name="c_DomainMessure"></param>
  865. public void StartSampleHoleBSEImage(int doRunType, int HoleID, CDomain c_DomainMessure)
  866. {
  867. //线程执行类型 1:测量类型 2:获取样品孔图片类型
  868. m_MsrThreadWrapper.SetDoRunType(doRunType);
  869. //设置获取样品孔中照片所需的参数
  870. m_MsrThreadWrapper.SetHoleImagePreview(HoleID, c_DomainMessure);
  871. StartSampleHoleImageBGWorkThread();
  872. }
  873. #endregion
  874. private void rbRecover_Click(object sender, EventArgs e)
  875. {
  876. //关闭所有内容
  877. CloseAllContents();
  878. //显示样品属性窗口与树结构窗口
  879. m_SolutionWindows.Show(dockPanel, DockState.DockLeft);
  880. m_SPropertyWindows.Show(dockPanel);
  881. //显示样品台窗口 测量状态与测量结果窗口
  882. m_SamplepaceWindow.Show(dockPanel);
  883. m_MessureStatuWindow.Show(dockPanel);
  884. m_MeasureRetWindow.Show(dockPanel);
  885. //此处将在父窗体选项卡上显示
  886. foreach (Form child in this.MdiChildren)
  887. {
  888. if (child.Name == "OTSSamplespaceWindow")
  889. {
  890. child.Activate();
  891. break;
  892. }
  893. }
  894. }
  895. private void CloseAllContents()
  896. {
  897. m_SolutionWindows.DockPanel = null;
  898. m_SPropertyWindows.DockPanel = null;
  899. m_SamplepaceWindow.DockPanel = null;
  900. m_MessureStatuWindow.DockPanel = null;
  901. m_MeasureRetWindow.DockPanel = null;
  902. CloseAllDocuments();
  903. }
  904. private void CloseAllDocuments()
  905. {
  906. if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  907. {
  908. foreach (Form form in MdiChildren)
  909. form.Close();
  910. }
  911. else
  912. {
  913. IDockContent[] documents = dockPanel.DocumentsToArray();
  914. foreach (IDockContent content in documents)
  915. content.DockHandler.Close();
  916. }
  917. }
  918. private void rbMeasureCircle_Click(object sender, EventArgs e)
  919. {
  920. m_ProjParam.SetMeasureAreaShape((int)ShapeType.CIRCUL);
  921. //修改工作样品的测量区域为圆形
  922. m_SamplepaceWindow.changeShape((int)ShapeType.CIRCUL);
  923. }
  924. private void rbMeasureRectangle_Click(object sender, EventArgs e)
  925. {
  926. m_ProjParam.SetMeasureAreaShape((int)ShapeType.RECTANGLE);
  927. //修改工作样品的测量区域为矩形
  928. m_SamplepaceWindow.changeShape((int)ShapeType.RECTANGLE);
  929. }
  930. //ctrl+s组合键进行保存
  931. private void OTSIncAMeasureAppForm_KeyDown(object sender, KeyEventArgs e)
  932. {
  933. if (e.KeyCode == Keys.S && e.Modifiers == Keys.Control)
  934. {
  935. bool iRev = m_ProjData.Save();
  936. if (!iRev)
  937. {
  938. log.Error("(OTSIncAMeasureAppForm.rbSaveFile_Click) m_DataMgrFun.SaveFile() Failed !");
  939. return;
  940. }
  941. log.Error("(OTSIncAMeasureAppForm.rbSaveAs_Click) m_DataMgrFun.SaveFile() Success !");
  942. }
  943. }
  944. private void rbSTDEdit_Click_1(object sender, EventArgs e)
  945. {
  946. OpenFileDialog openFileDialog = new OpenFileDialog();
  947. openFileDialog.Filter = "(*.db)|*.db";
  948. openFileDialog.InitialDirectory = Application.StartupPath + "\\Config\\SysData\\";
  949. openFileDialog.RestoreDirectory = true;
  950. openFileDialog.FilterIndex = 1;
  951. if (openFileDialog.ShowDialog() == DialogResult.OK)
  952. {
  953. try
  954. {
  955. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", openFileDialog.FileName);
  956. p.WaitForExit();
  957. }
  958. catch (Exception ex)
  959. {
  960. log.Error("OTSPartA_STDEditor:" + ex.ToString());
  961. }
  962. }
  963. //reload the setup data just now
  964. foreach (var s in this.m_ProjData.GetSampleList())
  965. {
  966. var stdname= s.GetMsrParams().GetSTDName();
  967. if (stdname != "NoSTD")
  968. {
  969. if (!stdname.Contains(".db"))
  970. {
  971. stdname += ".db";
  972. }
  973. var m_classifyEngine = new COTSClassifyEngineClr(EngineType.ParticleClassifyEng, stdname);
  974. m_classifyEngine.ReloadEngineDB();
  975. }
  976. }
  977. }
  978. private void rbSysMgrApp_Click(object sender, EventArgs e)
  979. {
  980. try
  981. {
  982. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSSysMgrApp.exe");
  983. p.WaitForExit();
  984. }
  985. catch (Exception ex)
  986. {
  987. log.Error("OTSSysMgrApp:" + ex.ToString());
  988. }
  989. }
  990. private void ribPolygon_Click(object sender, EventArgs e)
  991. {
  992. //修改工作样品的测量区域为矩形
  993. m_SamplepaceWindow.Rev_DDrawPolygonMeasure_MeasureAppToSampleWindow_Event();
  994. }
  995. private void rbReClassify_Click(object sender, EventArgs e)
  996. {
  997. if (m_ProjData.Reclassify())
  998. {
  999. m_ProjData.Save();
  1000. MessageBox.Show("reclassification success");
  1001. }
  1002. else
  1003. {
  1004. MessageBox.Show("reclassification failed");
  1005. }
  1006. }
  1007. /// <summary>
  1008. /// 打开测量项目文件
  1009. /// </summary>
  1010. private void OpenMeasureProjectFile()
  1011. {
  1012. bool bOpenFlag=false;
  1013. COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();
  1014. if (ProjDataMgr.Load())
  1015. {
  1016. m_ProjParam.SetResultData(ProjDataMgr);
  1017. m_ProjParam.InitResultData();
  1018. m_ProjData = ProjDataMgr;
  1019. bOpenFlag = true;
  1020. }
  1021. if (bOpenFlag)
  1022. {
  1023. if (!DisplayExistSampleFile())
  1024. {
  1025. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) OpenExistSampleFile() = false Failed !");
  1026. return;
  1027. }
  1028. m_RibbonFun.SetAllRibbonButnStatus(true);
  1029. }
  1030. else
  1031. {
  1032. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) m_DataMgrFun.OpenExistSampleFile() Failed !");
  1033. }
  1034. }
  1035. private void OTSIncAMeasureAppForm_FormClosed(object sender, FormClosedEventArgs e)
  1036. {
  1037. }
  1038. private void rbAbout_Click(object sender, EventArgs e)
  1039. {
  1040. About m_about = new About();
  1041. m_about.ShowDialog();
  1042. }
  1043. protected override void DefWndProc(ref Message m)
  1044. {
  1045. switch (m.Msg)
  1046. {
  1047. case MsgID:
  1048. //MSTMsg = new STMrsSampleRetThreadMsg();
  1049. //MSTMsg.STMThreadStu.cMsrStartTime = new char[(int)MEMORY_SIZE.TIME_SIZE];
  1050. //MSTMsg.STMThreadStu.cMsrEndTime = new char[(int)MEMORY_SIZE.TIME_SIZE];
  1051. //MSTMsg.STMSampleRetData.BSEData.FieldPos = new Point();
  1052. //MSTMsg.STMSampleRetData.SFieldata.FieldPos = new Point();
  1053. //MSTMsg.STMSampleRetData.StartMsrField.FieldPos = new Point();
  1054. //MSTMsg.STMSampleStu.cMsrSName = new char[(int)MEMORY_SIZE.SAMPLE_NAME_SIZE];
  1055. //MSTMsg = (STMrsSampleRetThreadMsg)Marshal.PtrToStructure(m.LParam, typeof(STMrsSampleRetThreadMsg));
  1056. ////以下为实时接收图片数据,因为图片传出来的只是指针,所以必须立即接收,否则指针指向的数据就会被析构。
  1057. //Byte[] bBSEData;
  1058. //int iHeight, iWidth;
  1059. //iHeight = MSTMsg.STMSampleRetData.BSEData.iBSEDataHeight;
  1060. //iWidth = MSTMsg.STMSampleRetData.BSEData.iBSEDataWidth;
  1061. //if (iHeight > 0 && iWidth > 0)
  1062. //{
  1063. // bBSEData = new Byte[iHeight * iWidth];
  1064. // Marshal.Copy(MSTMsg.STMSampleRetData.BSEData.pData, bBSEData, 0, iHeight * iWidth);
  1065. // MSTMsg.gbseData = bBSEData;
  1066. //}
  1067. ////申请
  1068. //shareRes.mutex.WaitOne();
  1069. //m_MSTMsg.Add(MSTMsg);
  1070. // 释放
  1071. //shareRes.mutex.ReleaseMutex();
  1072. break;
  1073. case LogMsgID:
  1074. m_LogMsg = new PostLogMsg();
  1075. m_LogMsg = (PostLogMsg)Marshal.PtrToStructure(m.LParam, typeof(PostLogMsg));
  1076. var log = NLog.LogManager.GetCurrentClassLogger();
  1077. string s = GetString(m_LogMsg.logMessage);
  1078. switch (m_LogMsg.logLevel)
  1079. {
  1080. case 1:
  1081. log.Trace(s);
  1082. break;
  1083. case 2:
  1084. log.Debug(s);
  1085. break;
  1086. case 3:
  1087. log.Info(s);
  1088. break;
  1089. case 4:
  1090. log.Warn(s);
  1091. break;
  1092. case 5:
  1093. log.Error(s);
  1094. break;
  1095. case 6:
  1096. log.Fatal(s);
  1097. break;
  1098. }
  1099. break;
  1100. default:
  1101. base.DefWndProc(ref m);
  1102. break;
  1103. }
  1104. }
  1105. private string GetString(char[] csStr)
  1106. {
  1107. int ilen = csStr.Length;
  1108. string csName = new string(csStr); //MSTMsg.STMSampleStu.cSName
  1109. csName.IndexOf('\0');
  1110. csName = csName.Substring(0, csName.IndexOf('\0'));
  1111. return csName;
  1112. }
  1113. private void PrepareIpcServer()
  1114. {
  1115. //Instantiate our server channel.
  1116. IpcServerChannel channel = new IpcServerChannel("ServerChannel");
  1117. //Register the server channel.
  1118. ChannelServices.RegisterChannel(channel, false);
  1119. //Register this service type.
  1120. RemotingConfiguration.RegisterWellKnownServiceType(typeof(IpcSEMController), "RemoteObject", WellKnownObjectMode.Singleton);
  1121. //RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject2), "RemoteObject2", WellKnownObjectMode.Singleton);
  1122. //Console.WriteLine("press return to exit");
  1123. //Console.ReadLine();
  1124. }
  1125. private void rbConnectHardware_Click_1(object sender, EventArgs e)
  1126. {
  1127. if (!m_MsrThreadWrapper.IsSEMConnected())
  1128. {
  1129. if (!m_MsrThreadWrapper.ConnectSEM())
  1130. {
  1131. MessageBox.Show("Connect failed!");
  1132. return;
  1133. }
  1134. }
  1135. this.rbConnectHardware.Enabled = false;
  1136. this.rbDisconnectHardware.Enabled = true;
  1137. log.Warn("SEM connect success!");
  1138. }
  1139. private void rbDisconnectHardware_Click_1(object sender, EventArgs e)
  1140. {
  1141. if (m_MsrThreadWrapper.IsSEMConnected())
  1142. {
  1143. m_MsrThreadWrapper.DisconnectSEM();
  1144. }
  1145. this.rbDisconnectHardware.Enabled = false;
  1146. this.rbConnectHardware.Enabled = true;
  1147. log.Warn("SEM Disconnect!");
  1148. }
  1149. private void rbinterrupt_Click(object sender, EventArgs e)
  1150. {
  1151. if (m_MsrThreadWrapper.IsSEMConnected())
  1152. {
  1153. m_MsrThreadWrapper.StopXrayAcquisition();
  1154. }
  1155. log.Warn("StopXrayAcquisition!");
  1156. }
  1157. private void rbAutoBeamOff_Click(object sender, EventArgs e)
  1158. {
  1159. if (m_ProjData.GetGenParam().AutoBeamOff)
  1160. {
  1161. m_ProjData.GetGenParam().AutoBeamOff = false;
  1162. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1163. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1164. }
  1165. else
  1166. {
  1167. m_ProjData.GetGenParam().AutoBeamOff = true;
  1168. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1169. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1170. }
  1171. }
  1172. }
  1173. }