OTSIncAMeasureAppForm.cs 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using OTS.WinFormsUI.Docking;
  6. using System.Runtime.InteropServices;
  7. using System.Collections;
  8. using OTSDataType;
  9. using OTSModelSharp;
  10. using OTSModelSharp.ResourceManage;
  11. using static OTSDataType.otsdataconst;
  12. using System.Diagnostics;
  13. using OTSCLRINTERFACE;
  14. using System.Xml;
  15. using System.Runtime.Remoting.Channels.Ipc;
  16. using System.Runtime.Remoting.Channels;
  17. using System.Runtime.Remoting;
  18. using OTSMeasureApp.ServiceCenter;
  19. using OTSMeasureApp._10_OTSSplashScreen;
  20. using System.Threading;
  21. using OTSMeasureApp._1_OTSMeasure.Measure.ParamData;
  22. namespace OTSMeasureApp
  23. {
  24. enum MessageBoxRev
  25. {
  26. DIALOG_YES = 0,
  27. DIALOG_NO = 1,
  28. DIALOG_CANCEL = 2
  29. }
  30. public partial class OTSIncAMeasureAppForm : Form
  31. {
  32. Thread th ;
  33. public static string m_SamplespaceWindowName = "样品台";
  34. public static string m_MeasureStauWindowName = "测量状态";
  35. public static string m_MeasureRetWindowName = "测量结果";
  36. public static string m_NoWindowName = "未知工作窗口";
  37. //国际化
  38. OTSCommon.Language lan;
  39. Hashtable table;
  40. // 初始化日志类
  41. NLog.Logger log ;
  42. private PostLogMsg m_LogMsg;
  43. public const int MsgID = 0x0464;
  44. public const int LogMsgID = 0x0465;
  45. public OTSMeasureResultWindow m_MeasureResultWindow = null;
  46. public OTSMeasureStatusWindow m_MessureStatuWindow = null;
  47. public OTSSamplespaceWindow m_SamplepaceWindow = null;
  48. public OTSMeasureOutputNlog m_OTSMeasureOutputNlog = null;
  49. public COTSMeasureParam m_ProjParam = null;
  50. public COTSMsrPrjResultData m_ProjRstData;
  51. public OTSSolutionWindow m_SolutionWindows = null;
  52. public OTSPropertyWindow m_SPropertyWindows = null;
  53. //测量线程对象
  54. public CMeasureThreadWrapper m_MsrThreadWrapper = null;
  55. // 测量线程当前状态 True: 正在测量; False: 测量结束
  56. public bool MeasureThreadRunFlag { get => m_MsrThreadWrapper.BGWorkThreadIsRunning(); }
  57. Form sp;
  58. public OTSIncAMeasureAppForm()
  59. {
  60. th = new Thread(new ThreadStart(DoSplash));
  61. th.Start();
  62. InitializeComponent();
  63. //国际化
  64. lan = new OTSCommon.Language(this);
  65. table = lan.GetNameTable(this.Name);
  66. m_SamplespaceWindowName = table["m_samplespacewindowname"].ToString();
  67. m_MeasureStauWindowName = table["m_measurestauwindowname"].ToString();
  68. m_MeasureRetWindowName = table["m_measureretwindowname"].ToString();
  69. m_NoWindowName = table["m_nowindowname"].ToString();
  70. m_OTSMeasureOutputNlog = new OTSMeasureOutputNlog();
  71. m_OTSMeasureOutputNlog.Show();
  72. // 初始化Docpanle
  73. m_SolutionWindows = new OTSSolutionWindow(this);
  74. m_SPropertyWindows = new OTSPropertyWindow(this);
  75. m_MeasureResultWindow = new OTSMeasureResultWindow(this);
  76. m_MeasureResultWindow.Text = m_MeasureRetWindowName;
  77. m_MessureStatuWindow = new OTSMeasureStatusWindow(this);
  78. m_MessureStatuWindow.Text = m_MeasureStauWindowName;
  79. m_SamplepaceWindow = new OTSSamplespaceWindow(this);
  80. m_SamplepaceWindow.Text = m_SamplespaceWindowName;
  81. m_ProjParam = new COTSMeasureParam(this);
  82. m_ProjRstData = m_ProjParam.GetResultData();
  83. //初始化测量线程
  84. m_MsrThreadWrapper = new CMeasureThreadWrapper(this);//must be the last sentence of this procedure.
  85. }
  86. public void SetAllRibbonButnStatus(bool bRibStstu)
  87. {
  88. rbPanelSample.Enabled = bRibStstu;
  89. rbPanelFunction.Enabled = bRibStstu;
  90. rbMenu.Tabs[0].Panels[0].Enabled = bRibStstu; //Menu中的基本功能中的文件 rbMenu.Tabs[0]=基本功能; rbMenu.Tabs[0].Panels[0]=文件
  91. rbMenu.Tabs[1].Panels[0].Enabled = bRibStstu; //Menu中的视图功能中的视图 rbMenu.Tabs[1]=视图功能; rbMenu.Tabs[1].Panels[0]=视图
  92. // m_MeasureAppForm.rbNew.Enabled = false;
  93. //下拉菜单中的 新建,打开,保存,另存为
  94. rbNewDocument.Enabled = bRibStstu;
  95. rbOpenFile.Enabled = bRibStstu;
  96. rbSaveFile.Enabled = bRibStstu;
  97. rvSaveAsFile.Enabled = bRibStstu;
  98. rbOpenFile.Enabled = true;
  99. rbOpen.Enabled = true;
  100. if (bRibStstu)
  101. {
  102. //设置开始,停止,检查参数按钮
  103. SetMeasureRibbonButnStatu();
  104. //设置 删除,复位,圆形,矩形 按钮状态
  105. SetSampleRibbonButnStatus();
  106. //设置 跳转至报告 按钮状态
  107. SetReprotRibbonButnStatu();
  108. }
  109. }
  110. private void OTSIncAMeasureAppForm_Load(object sender, EventArgs e)
  111. {
  112. try
  113. {
  114. ArrangWorkspaceWindow();
  115. log = NLog.LogManager.GetCurrentClassLogger();
  116. if (m_ProjParam.LoadParamFile())
  117. {
  118. if (m_ProjParam.InitResultData())
  119. {
  120. SetAllRibbonButnStatus(true);
  121. m_SamplepaceWindow.InitStageDisplay(m_ProjRstData.GetStageHolder(),m_ProjRstData.GetSEMStageData());
  122. //添加启动系统界面显示
  123. var SystemType = m_ProjParam.GetDefaultParam().SystemTypeId;
  124. if (SystemType == OTS_SysType_ID.IncA)
  125. {
  126. this.Text += "(IncA)";
  127. }
  128. else if (SystemType == OTS_SysType_ID.TCCleannessA)
  129. {
  130. this.Text += "(TCCleannessA)";
  131. }
  132. else if (SystemType == OTS_SysType_ID.BatteryCleannessA)
  133. {
  134. this.Text += "(BatteryCleannessA)";
  135. }
  136. else
  137. {
  138. this.Text += "(SteelMineral)";
  139. }
  140. }
  141. else
  142. {
  143. log.Error(" InitResultData() failed");
  144. }
  145. m_MsrThreadWrapper.m_measure.m_pMeasureParam = m_ProjParam;
  146. }
  147. else
  148. {
  149. log.Error("(OTSIncAMeasureAppForm.OTSIncAMeasureAppForm_Load) (LoadParamFile() && LoadStageParamFile()) failed");
  150. }
  151. if (!m_MsrThreadWrapper.ConnectSEM())
  152. {
  153. MessageBox.Show("Connect SEM failed!Please goto the SysMgrApp.exe to setup the proper parameter or check other parameter of the EDS software");
  154. System.Diagnostics.ProcessStartInfo process = new System.Diagnostics.ProcessStartInfo();
  155. process.FileName = "OTSSysMgrApp.exe";//打开app的路径
  156. process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
  157. System.Diagnostics.Process.Start(process);
  158. this.rbConnectHardware.Enabled = true;
  159. this.rbDisconnectHardware.Enabled = false;
  160. }
  161. this.rbConnectHardware.Enabled = false;
  162. this.rbDisconnectHardware.Enabled = true;
  163. log.Warn("SEM connect success!");
  164. PrepareIpcServer();
  165. log.Info("Ipc server start success!");
  166. //----------------------Test Code, Don't delete
  167. //var f = new BaseFunctionTest();
  168. //f.ShowDialog();
  169. //----------------------
  170. }
  171. catch (Exception ex)
  172. {
  173. log.Error(" OTSIncAMeasureAppForm_Load:" + ex.ToString());
  174. }
  175. sp.Close();
  176. this.Activate();
  177. }
  178. public void ArrangWorkspaceWindow()
  179. {
  180. //Show 样品台窗口
  181. m_SamplepaceWindow.Show(dockPanel);
  182. //Show 测量状态窗口
  183. m_MessureStatuWindow.Show(dockPanel);
  184. //Show 测量结果窗口
  185. m_MeasureResultWindow.Show(dockPanel);
  186. m_SolutionWindows.Show(dockPanel, DockState.DockLeft);
  187. //Show 测量过程中Log显示窗口
  188. m_OTSMeasureOutputNlog.Show(dockPanel, DockState.DockRight);
  189. dockPanel.DockRightPortion = 365;
  190. m_SPropertyWindows.Show(dockPanel);
  191. m_SamplepaceWindow.Activate();
  192. }
  193. private void DoSplash()
  194. {
  195. string path = @".\Config\SysData\OTSProgMgrParam.pmf";
  196. XmlDocument xmlDocument = new XmlDocument();
  197. xmlDocument.Load(path);
  198. XmlNode node = xmlDocument.SelectSingleNode("XMLData");
  199. XmlElement xe = (XmlElement)node;
  200. string str = xe.GetAttribute("SysType");
  201. if (str == "IncA")
  202. {
  203. sp = new OTSSplashScreen_IncA();
  204. sp.ShowDialog();
  205. }
  206. else if (str == "TCCleannessA" || str == "BatteryCleannessA")
  207. {
  208. sp = new OTSSplashScreen_Cleanness();
  209. sp.ShowDialog();
  210. }
  211. else if (str == "SteelMineral")
  212. {
  213. sp = new OTSSplashScreen_SteelMineral();
  214. sp.ShowDialog();
  215. }
  216. }
  217. private void rbReport_Click(object sender, EventArgs e)
  218. {
  219. //测量结果文件路径列表
  220. List<string> mrFilePathList = new List<string>();
  221. //获取测量结果文件路径列表
  222. bool result = m_ProjParam.GetCompletedMeasureFileName(ref mrFilePathList);
  223. if (result)
  224. {
  225. for (int i = 0; i < mrFilePathList.Count; i++)
  226. {
  227. mrFilePathList[i] = mrFilePathList[i].Replace(" ", "^");
  228. }
  229. //转换为数组
  230. string[] resultFilePath = mrFilePathList.ToArray();
  231. System.Diagnostics.ProcessStartInfo process = new System.Diagnostics.ProcessStartInfo();
  232. process.FileName = "OTSIncAReportApp.exe";//打开app的路径
  233. string FilePath = string.Join(" ", resultFilePath);
  234. process.Arguments = FilePath;//多个参数用空格隔开
  235. process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
  236. System.Diagnostics.Process.Start(process);
  237. }
  238. }
  239. // sNewWorkSampleName: 新工作样品名
  240. public void SwitchWSample(string sNewWorkSampleName)
  241. {
  242. m_ProjParam.SetWorkSample(sNewWorkSampleName);
  243. m_SolutionWindows.SwitchSample(sNewWorkSampleName);
  244. //获取新工作样品属性值
  245. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  246. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  247. //发送想你的样品名给Sample
  248. m_SamplepaceWindow.SwitchWorkSample(sNewWorkSampleName);
  249. }
  250. public void SoluWindowCheckBoxStatuChange(string sSampleName, bool bCheckBoxStatu)
  251. {
  252. string sWSampleName = m_ProjParam.GetWorkSampleName();
  253. if ("" == sWSampleName)
  254. {
  255. //不修改Tteeview 的工作样品属性值
  256. m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(sSampleName, !bCheckBoxStatu);
  257. return;
  258. }
  259. //Treeview更改的工作样品数的CHECKBOX 状态
  260. if (!m_ProjParam.SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS.SWITCH, OTS_ITEM_TYPES.BOOL, bCheckBoxStatu))
  261. {
  262. //不修改Tteeview 的工作样品属性值
  263. m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(sSampleName, !bCheckBoxStatu);
  264. return;
  265. }
  266. // 设置 开始 ,停止 和检查参数 按钮状态
  267. SetMeasureRibbonButnStatu();
  268. //修改Grid工作样品的SWITCH值
  269. OTSSampleVisualPropertyInfo SMeasurenfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  270. m_SPropertyWindows.DisplaySampleMeasureInfo(SMeasurenfo);
  271. }
  272. public void SetMeasureRibbonButnStatu()
  273. {
  274. bool bSampleCheckBoxFalg = m_ProjParam.GetSampleCheckBoxStatus();
  275. bool bFlag;
  276. if (!bSampleCheckBoxFalg)
  277. {
  278. bFlag = false;
  279. }
  280. else
  281. {
  282. bFlag = true;
  283. }
  284. if (MeasureThreadRunFlag) //当正在测量时,开始按钮变灰色
  285. {
  286. rbStart.Enabled = false;
  287. }
  288. else
  289. {
  290. rbStart.Enabled = bFlag;
  291. }
  292. if (MeasureThreadRunFlag) //当前正在运行的时候,才可以点击暂停
  293. {
  294. rbPause.Enabled = bFlag;
  295. }
  296. else
  297. {
  298. rbPause.Enabled = false;
  299. }
  300. if (bFlag && MeasureThreadRunFlag) //当前正在运行的时候,才可以点击停止
  301. {
  302. rbStop.Enabled = bFlag;
  303. }
  304. else
  305. {
  306. rbStop.Enabled = false;
  307. }
  308. if (MeasureThreadRunFlag)
  309. {
  310. rbCheckParam.Enabled = false;
  311. }
  312. else
  313. {
  314. rbCheckParam.Enabled = bFlag;
  315. }
  316. }
  317. public bool EditWorkSampleName(string sSampleOldName, string sSampleNewName)
  318. {
  319. if (!m_ProjParam.ChangeWorkSampleName(sSampleNewName))
  320. {
  321. return false;
  322. }
  323. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  324. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  325. m_SamplepaceWindow.ChangeWorkSampleName(sSampleNewName);
  326. return true;
  327. }
  328. public void SoluwindowReqAddSample()
  329. {
  330. //Treeview右键点击添加新样品
  331. this.AddNewSampleMeasure();
  332. }
  333. private void OTSIncAMeasureAppForm_FormClosing(object sender, FormClosingEventArgs e)
  334. {
  335. try
  336. {
  337. if (m_MsrThreadWrapper.BGWorkThreadIsRunning ()) //当前正在测量
  338. {
  339. e.Cancel = true;
  340. return;
  341. }
  342. if (m_MsrThreadWrapper.IsHavingNotCompleteSamples()) //当前正在测量
  343. {
  344. e.Cancel = true;
  345. MessageBox.Show("There is one sample is still in pausing state,please stop it!");
  346. return;
  347. }
  348. //判断测量结果文件修改后是否保存
  349. if (m_ProjRstData.IsModified())
  350. {
  351. string message = table["message2"].ToString();
  352. DialogResult lsdr = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
  353. if (lsdr == DialogResult.Yes)
  354. {
  355. //保存,退出
  356. m_ProjRstData.Save();
  357. //保存,直接退出
  358. Application.ExitThread();
  359. }
  360. else if (lsdr == DialogResult.No)
  361. {
  362. //不保存,直接退出
  363. Application.ExitThread();
  364. }
  365. else if (lsdr == DialogResult.Cancel)
  366. {
  367. //取消
  368. e.Cancel = true;
  369. return;
  370. }
  371. }
  372. log.Info("Disconnect SEM!");
  373. m_MsrThreadWrapper.DisconnectSEM();
  374. m_MsrThreadWrapper.SetWorkThreadPending();
  375. }
  376. catch (Exception ex)
  377. {
  378. string message = table["message3"].ToString();
  379. log.Error("OTSIncAMeasureAppForm_FormClosing-"+ message + ":" + ex.ToString());
  380. }
  381. Process.GetCurrentProcess().Kill();
  382. }
  383. //打开指定路径的文件
  384. private void ribbonOrbMenuItem1_OpenWorkspace_Click(object sender, EventArgs e)
  385. {
  386. OpenMeasureProjectFile();
  387. }
  388. //新建样品工作文件
  389. private void ribbonOrbMenuItem3_CreateWorkspace_Click(object sender, EventArgs e)
  390. {
  391. int iCreateNewFileResult = m_ProjParam.CreateNewFile();
  392. if (iCreateNewFileResult == 0)
  393. {
  394. log.Error("(OTSIncAMeasureAppForm.rbNew_CreateWorkspace_Click) m_DataMgrFun.CreateNewFile() Failed !");
  395. return;
  396. }
  397. else if(iCreateNewFileResult == 2)
  398. {
  399. log.Info("(OTSIncAMeasureAppForm.rbNew_CreateWorkspace_Click) m_DataMgrFun.CreateNewFile() Cancel !");
  400. return;
  401. }
  402. SetAllRibbonButnStatus(true);
  403. //清除TREEVIEW和GRID上的显示的已经保存的样品信息
  404. m_SolutionWindows.m_TreeViewBase.DeleteAllTreeNode();
  405. m_SPropertyWindows.m_SampleGrid.HideGrid();
  406. //设置报告按钮
  407. rbPReport.Enabled = false;
  408. rbReport.Enabled = false;
  409. rbReClassify.Enabled = true;
  410. //新建项目时,设置属性窗体中的两个按钮也为不可用状态
  411. m_SPropertyWindows.TSLoad.Enabled = false;
  412. m_SPropertyWindows.TSSaveAs.Enabled = false;
  413. //绘制样品台
  414. m_SamplepaceWindow.InitStageDisplay(m_ProjRstData.GetStageHolder(), m_ProjRstData.GetSEMStageData());
  415. //隐藏XrayTable控件
  416. m_MessureStatuWindow.HideXRayTable();
  417. //新建时重新初始化结果窗体结果
  418. m_MeasureResultWindow.SetInit();
  419. }
  420. // 新建样品时提示保存样品信息Messagebox
  421. public int ShowSaveInfoMsgBox()
  422. {
  423. string message = table["message4"].ToString();
  424. DialogResult dResult = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
  425. if (dResult == DialogResult.Yes)
  426. {
  427. return (int)MessageBoxRev.DIALOG_YES;
  428. }
  429. else if (dResult == DialogResult.No)
  430. {
  431. return (int)MessageBoxRev.DIALOG_NO;
  432. }
  433. else
  434. {
  435. return (int)MessageBoxRev.DIALOG_CANCEL;
  436. }
  437. }
  438. //打开已经保存的工作文件
  439. private bool DisplayExistSampleFile()
  440. {
  441. List<CTreeSampleParam> TSampleParamList = new List<CTreeSampleParam>();
  442. List<SampleMeasurePara> SampleMeasureParaList = new List<SampleMeasurePara>();
  443. int iSampleCount = m_ProjRstData.GetSampleList().Count;
  444. if (0 == iSampleCount)
  445. {
  446. return false;
  447. }
  448. for (int i = 0; i < iSampleCount; i++)
  449. {
  450. CTreeSampleParam CTSampleParam = new CTreeSampleParam();
  451. COTSSample SampleClr = (m_ProjRstData.GetSampleList())[i];
  452. CTSampleParam.sSampleTitleName = m_ProjRstData.GetFileName();
  453. CTSampleParam.sWorkSampleName = SampleClr.GetName();
  454. CTSampleParam.bSwitch = SampleClr.GetSwitch();
  455. TSampleParamList.Add(CTSampleParam);
  456. }
  457. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  458. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  459. m_SolutionWindows.DisplayExistSampleFile(TSampleParamList, SMInfo.TSampleParam);
  460. if (!InitExistSampleMeasureParam(ref SampleMeasureParaList))
  461. {
  462. log.Error(" OpenExistSampleMeasureArea(ref SampleMeasureAreaList) Failed !");
  463. return false;
  464. }
  465. string sWSampleName = m_ProjParam.GetWorkSampleName();
  466. if ("" == sWSampleName)
  467. {
  468. log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile) m_DataMgrFun.GetWorkSampleName() = null !");
  469. return false;
  470. }
  471. m_SamplepaceWindow.DisplayVisualStage(m_ProjRstData.GetStageHolder(), m_ProjRstData.GetSEMStageData());
  472. m_SamplepaceWindow.DisplayExistSamples( SampleMeasureParaList);
  473. m_MeasureResultWindow.UpdateResultInfoBySampleName(sWSampleName);
  474. return true;
  475. }
  476. public bool InitExistSampleMeasureParam(ref List<SampleMeasurePara> SampleMeasureParaList)
  477. {
  478. int iSListCount = m_ProjRstData.GetSampleList().Count;
  479. if (0 == iSListCount)
  480. {
  481. return false;
  482. }
  483. for (int i = 0; i < iSListCount; i++)
  484. {
  485. SampleMeasurePara SampleMeasureParam =new SampleMeasurePara(m_ProjRstData.GetSampleList()[i]);
  486. SampleMeasureParaList.Add(SampleMeasureParam);
  487. }
  488. return true;
  489. }
  490. //打开指定路径的文件
  491. private void rbOpen_Click(object sender, EventArgs e)
  492. {
  493. OpenMeasureProjectFile();
  494. }
  495. private void rbDeleteSample_Click(object sender, EventArgs e)
  496. {
  497. //删除样品(样品必须先选中)
  498. string sWSampleName = m_ProjParam.GetWorkSampleName();
  499. if ("" == sWSampleName)
  500. {
  501. log.Error("(OTSIncAMeasureAppForm.rbDeleteSample_Click) m_DataMgrFun.GetWorkSampleName() = null Failed");
  502. return;
  503. }
  504. string message = table["message5"].ToString();
  505. string message6 = table["message6"].ToString();
  506. string sDeleteSampleName = message;
  507. sDeleteSampleName += sWSampleName;
  508. sDeleteSampleName += message6;
  509. if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  510. {
  511. //删除样品成功
  512. DeleteSample(sWSampleName);
  513. sWSampleName = m_ProjParam.GetWorkSampleName();
  514. if ("" != sWSampleName)
  515. {
  516. m_SolutionWindows.m_TreeViewBase.GetTreeWorkSampleNode(sWSampleName);
  517. m_SolutionWindows.treeView1.Focus();
  518. }
  519. }
  520. }
  521. public void SetRibbonButonWorkListStatu(List<int> RibbonButnIDList, bool bFlag)
  522. {
  523. if (RibbonButnIDList.Count == 0)
  524. {
  525. return;
  526. }
  527. for (int i = 0; i < RibbonButnIDList.Count; i++)
  528. {
  529. if (RibbonButnIDList[i] == (int)RibbonButnID.NewDocment)
  530. {
  531. rbNewDocument.Enabled = bFlag;
  532. continue;
  533. }
  534. if (RibbonButnIDList[i] == (int)RibbonButnID.File_NewDocment)
  535. {
  536. rbNew.Enabled = bFlag;
  537. continue;
  538. }
  539. if (RibbonButnIDList[i] == (int)RibbonButnID.OpenDocment)
  540. {
  541. rbOpenFile.Enabled = bFlag;
  542. continue;
  543. }
  544. if (RibbonButnIDList[i] == (int)RibbonButnID.File_OpenDocment)
  545. {
  546. rbOpen.Enabled = bFlag;
  547. continue;
  548. }
  549. if (RibbonButnIDList[i] == (int)RibbonButnID.Save)
  550. {
  551. rbSaveFile.Enabled = bFlag;
  552. continue;
  553. }
  554. if (RibbonButnIDList[i] == (int)RibbonButnID.File_Save)
  555. {
  556. rbSave.Enabled = bFlag;
  557. continue;
  558. }
  559. if (RibbonButnIDList[i] == (int)RibbonButnID.SaveAs)
  560. {
  561. rvSaveAsFile.Enabled = bFlag;
  562. continue;
  563. }
  564. if (RibbonButnIDList[i] == (int)RibbonButnID.File_SaveAs)
  565. {
  566. rbSaveAs.Enabled = bFlag;
  567. continue;
  568. }
  569. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_AddSampl)
  570. {
  571. rbAddSample.Enabled = bFlag;
  572. continue;
  573. }
  574. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_DeleteSample)
  575. {
  576. rbDeleteSample.Enabled = bFlag;
  577. continue;
  578. }
  579. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_Reset)
  580. {
  581. ribInvers.Enabled = bFlag;
  582. continue;
  583. }
  584. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_DrawCircle)
  585. {
  586. ribCircle.Enabled = bFlag;
  587. continue;
  588. }
  589. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_DrawRectang)
  590. {
  591. ribRectangle.Enabled = bFlag;
  592. continue;
  593. }
  594. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_DrawPolygon)
  595. {
  596. ribPolygon.Enabled = bFlag;
  597. continue;
  598. }
  599. if (RibbonButnIDList[i] == (int)RibbonButnID.View_Ruler)
  600. {
  601. rbRuler.Enabled = bFlag;
  602. continue;
  603. }
  604. if (RibbonButnIDList[i] == (int)RibbonButnID.View_SPhoto)
  605. {
  606. rbSmaplePhoto.Enabled = bFlag;
  607. continue;
  608. }
  609. if (RibbonButnIDList[i] == (int)RibbonButnID.View_SName)
  610. {
  611. rbSmapleName.Enabled = bFlag;
  612. continue;
  613. }
  614. if (RibbonButnIDList[i] == (int)RibbonButnID.View_Recover)
  615. {
  616. rbRecover.Enabled = bFlag;
  617. continue;
  618. }
  619. if (RibbonButnIDList[i] == (int)RibbonButnID.File_Base)
  620. {
  621. rbMenu.Tabs[0].Panels[0].Enabled = bFlag;
  622. continue;
  623. }
  624. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_Base)
  625. {
  626. rbPanelSample.Enabled = bFlag;
  627. continue;
  628. }
  629. if (RibbonButnIDList[i] == (int)RibbonButnID.Funciton_Base)
  630. {
  631. rbPanelFunction.Enabled = bFlag;
  632. continue;
  633. }
  634. if (RibbonButnIDList[i] == (int)RibbonButnID.View_Base)
  635. {
  636. rbMenu.Tabs[1].Panels[0].Enabled = bFlag;
  637. continue;
  638. }
  639. if (RibbonButnIDList[i] == (int)RibbonButnID.Fun_Report)
  640. {
  641. rbMenu.Tabs[1].Panels[0].Enabled = bFlag;
  642. continue;
  643. }
  644. if (RibbonButnIDList[i] == (int)RibbonButnID.ShotImage)
  645. {
  646. ribonBtnShot.Enabled = bFlag;
  647. continue;
  648. }
  649. }
  650. }
  651. //设置 删除,复位,圆形,矩形 按钮状态
  652. public void SetSampleRibbonButnStatus()
  653. {
  654. List<int> RibbonIdList = new List<int>();
  655. RibbonIdList.Add((int)RibbonButnID.Sample_DeleteSample);
  656. RibbonIdList.Add((int)RibbonButnID.Sample_Reset);
  657. RibbonIdList.Add((int)RibbonButnID.Sample_DrawCircle);
  658. RibbonIdList.Add((int)RibbonButnID.Sample_DrawRectang);
  659. RibbonIdList.Add((int)RibbonButnID.Sample_DrawPolygon);
  660. RibbonIdList.Add((int)RibbonButnID.ShotImage);
  661. if (0 == m_ProjParam.GetSampleCount())
  662. {
  663. SetRibbonButonWorkListStatu(RibbonIdList, false);
  664. }
  665. else
  666. {
  667. SetRibbonButonWorkListStatu(RibbonIdList, true);
  668. }
  669. }
  670. public void SetReprotRibbonButnStatu()
  671. {
  672. //设置跳转至报告程序按钮状态
  673. rbPReport.Enabled = false;
  674. rbReport.Enabled = false;
  675. rbReClassify.Enabled = true;
  676. //判断打开的文件是否存在测量结果文件路径
  677. List<string> mrFilePathList = new List<string>();
  678. bool result = m_ProjParam.GetCompletedMeasureFileName(ref mrFilePathList);
  679. //根据结果设置报告按钮启用状态
  680. if (result)
  681. {
  682. rbPReport.Enabled = true;
  683. rbReport.Enabled = true;
  684. rbReClassify.Enabled = true;
  685. }
  686. else
  687. {
  688. rbPReport.Enabled = false;
  689. rbReport.Enabled = false;
  690. rbReClassify.Enabled = true;
  691. }
  692. }
  693. //返回删除的工作样品名
  694. public void DeleteSample(string sDeleteWSampleName = "")
  695. {
  696. if (m_MsrThreadWrapper.m_measure.mapSmplMsr.ContainsKey(sDeleteWSampleName))
  697. {
  698. m_MsrThreadWrapper.m_measure.mapSmplMsr.Remove(sDeleteWSampleName);
  699. }
  700. m_ProjParam.DeleteWorkSample(sDeleteWSampleName);
  701. // 设置 开始 ,停止 和检查参数 按钮状态
  702. SetMeasureRibbonButnStatu();
  703. //设置 删除,复位,圆形,矩形 按钮状态
  704. SetSampleRibbonButnStatus();
  705. // 更新报告ribbon按钮状态
  706. SetAllRibbonButnStatus(true);
  707. int iSampleCount = m_ProjParam.GetSampleCount();
  708. if (0 == iSampleCount)
  709. {
  710. //给工作样品台发送删除样品和新的工作样品名称
  711. m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName);
  712. m_SPropertyWindows.PropGrid.Hide();
  713. m_SPropertyWindows.toolStripButton_refresh.Enabled = false;
  714. m_SPropertyWindows.TSSaveAs.Enabled = false;
  715. m_SolutionWindows.treeView1.Nodes.Clear();
  716. m_MessureStatuWindow.HideXRayTable();
  717. m_MeasureResultWindow.SetInit();
  718. return ;
  719. }
  720. else
  721. {
  722. string sNewWSName = m_ProjParam.GetWorkSampleName();
  723. if ("" == sNewWSName)
  724. {
  725. log.Error("(OTSIncAMeasureAppForm.DeleteSample) m_DataMgrFun.GetWorkSampleName() = null Failed");
  726. return ;
  727. }
  728. m_SolutionWindows.DeletCurrentSampleNode();
  729. m_SolutionWindows.DisplaySample(sNewWSName);
  730. //将测量状态初始化
  731. m_MessureStatuWindow.SetMeasureStatusInit();
  732. //给工作样品台发送删除样品和新的工作样品名称
  733. m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName);
  734. //设置工作样品
  735. SwitchWSample(sNewWSName);
  736. }
  737. return ;
  738. }
  739. private void rbAddSample_Click(object sender, EventArgs e)
  740. {
  741. this.AddNewSampleMeasure();//the system will choose the empty hole one by one according to the holeNo sequence.
  742. }
  743. public void AddNewSampleMeasure(string sSampleHoleName = "")
  744. {
  745. OTSSampleVisualPropertyInfo SMInfo = m_ProjParam.AddNewSampleMeasure(sSampleHoleName);
  746. if (null == SMInfo)
  747. {
  748. // 设置 开始 ,停止 和检查参数 按钮状态
  749. SetMeasureRibbonButnStatu();
  750. log.Error("(OTSIncAMeasureAppForm.AddNewSample) m_DataMgrFun.AddNewSample(sSampleHoleName) = null ");
  751. return;
  752. }
  753. m_SPropertyWindows.TSSaveAs.Enabled = true;
  754. m_SPropertyWindows.TSLoad.Enabled = true;
  755. m_SPropertyWindows.TSEdit.Enabled = false;
  756. m_SPropertyWindows.TSEdit.Visible = false;
  757. //给SampleWindow 发送样品信息
  758. m_SamplepaceWindow.AddSampleArea(SMInfo.SMeasurePara);
  759. m_SamplepaceWindow.ReadSEMDataAndSetToCurrentSample();
  760. //给PropWindow 发送工作样品属性信息
  761. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  762. //给SoluWindow 发送样品显示信息
  763. m_SolutionWindows.AddSampleMeasure(SMInfo.TSampleParam);
  764. // 设置 开始 ,停止 和检查参数 按钮状态
  765. SetMeasureRibbonButnStatu();
  766. //设置 删除,复位,圆形,矩形 按钮状态
  767. SetSampleRibbonButnStatus();
  768. }
  769. public void InitCurrentSampleState()
  770. {
  771. OTSSampleVisualPropertyInfo SMInfo = m_ProjParam.GetWorkingSampleVisualPropertyInfo();
  772. if (null == SMInfo)
  773. {
  774. // 设置 开始 ,停止 和检查参数 按钮状态
  775. SetMeasureRibbonButnStatu();
  776. log.Error("(OTSIncAMeasureAppForm.AddNewSample) m_DataMgrFun.AddNewSample(sSampleHoleName) = null ");
  777. return;
  778. }
  779. m_SPropertyWindows.TSSaveAs.Enabled = true;
  780. m_SPropertyWindows.TSLoad.Enabled = true;
  781. m_SamplepaceWindow.ReadSEMDataAndSetToCurrentSample();
  782. //给PropWindow 发送工作样品属性信息
  783. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  784. // 设置 开始 ,停止 和检查参数 按钮状态
  785. SetMeasureRibbonButnStatu();
  786. //设置 删除,复位,圆形,矩形 按钮状态
  787. SetSampleRibbonButnStatus();
  788. }
  789. private void rbSelectDlg_Click(object sender, EventArgs e)
  790. {
  791. ProgMgrInfoForm ProgMgrForm = new ProgMgrInfoForm();
  792. if (DialogResult.OK == ProgMgrForm.ShowDialog())
  793. {
  794. if (m_ProjParam.LoadParamFile())
  795. {
  796. if (m_ProjParam.InitResultData())
  797. {
  798. SetAllRibbonButnStatus(true);
  799. //当样品台上有样品,则不更新样品台数据
  800. if (0 == m_ProjParam.GetSampleCount())
  801. {
  802. m_SamplepaceWindow.InitStageDisplay(m_ProjRstData.GetStageHolder(), m_ProjRstData.GetSEMStageData());
  803. }
  804. }
  805. else
  806. {
  807. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) this.CheckMeasureSysFileExist() = false");
  808. }
  809. }
  810. else
  811. {
  812. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) (m_DataMgrFun.CheckParamFile() && m_DataMgrFun.CheckStageFile()) = false");
  813. }
  814. }
  815. }
  816. // 主Windows框右下角显示鼠标点的SEM坐标(样品台)
  817. public void ShowSemCoordvAL(string sSemCoord)
  818. {
  819. STSemCoordinate.Text = sSemCoord;
  820. statusStrip1.Refresh();
  821. }
  822. //// 主Windows框右下角显示鼠标点的灰度值(测量图)
  823. public void ShowGrayVal(string sGrayVal)
  824. {
  825. TSGrayVal.Text = sGrayVal;
  826. statusStrip1.Refresh();
  827. }
  828. //获取工作样品测量锁
  829. public bool GetWorkSampleParamLock(ref CTreeSampleParam TSParamLock)
  830. {
  831. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  832. TSParamLock = SMInfo.TSampleParam;
  833. return true;
  834. }
  835. /// <summary>
  836. /// 更新属性窗口
  837. /// </summary>
  838. public void UpdatePropertyVal()
  839. {
  840. //获取新的工作样品属性值
  841. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  842. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  843. }
  844. private void ribbonOrbMenuItemSaveAs_Click(object sender, EventArgs e)
  845. {
  846. bool iRev = m_ProjRstData.SaveAs();
  847. if (!iRev)
  848. {
  849. return;
  850. }
  851. foreach (var spl in m_ProjParam.MeasureSampleList)
  852. {
  853. m_SamplepaceWindow.InitSampleMeasure(spl, 0);
  854. }
  855. m_SamplepaceWindow.PrepareVisualMeasureField(m_SamplepaceWindow.GetWorkingVisualSample());
  856. }
  857. private void rbSaveFile_Click(object sender, EventArgs e)
  858. {
  859. bool iRev = m_ProjRstData.Save();
  860. if (!iRev)
  861. {
  862. return;
  863. }
  864. }
  865. private void rbCheckParam_Click(object sender, EventArgs e)
  866. {
  867. //检查样品测量参数
  868. if (m_ProjParam.CheckSampleParam(true))
  869. {
  870. string message = table["message7"].ToString();
  871. MessageBox.Show(message, "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  872. }
  873. }
  874. private void ribReset_Click(object sender, EventArgs e)
  875. {
  876. //调用样品台窗口中的复位方法
  877. m_SamplepaceWindow.InverseSelectWorkSampleMeasure();
  878. }
  879. //绘制圆形测量区域
  880. private void ribCircle_Click(object sender, EventArgs e)
  881. {
  882. //修改工作样品的测量区域为圆形
  883. m_SamplepaceWindow.DrawCircleMeasure();
  884. }
  885. private void rbThreePoints_Click(object sender, EventArgs e)
  886. {
  887. //修改工作样品的测量区域为圆形
  888. m_SamplepaceWindow.DrawCircleMeasureByThreePoints();
  889. }
  890. private void rbRingShape_Click(object sender, EventArgs e)
  891. {
  892. //修改工作样品的测量区域为圆形
  893. m_SamplepaceWindow.DrawRingShapeArea();
  894. }
  895. //绘制矩形测量区域
  896. private void ribRectangle_Click(object sender, EventArgs e)
  897. {
  898. //修改工作样品的测量区域为矩形
  899. m_SamplepaceWindow.DrawRectangleMeasure();
  900. }
  901. private void rbExitApp_Click(object sender, EventArgs e)
  902. {
  903. this.Close();
  904. }
  905. private void rbStart_Click(object sender, EventArgs e)
  906. {
  907. if (!m_ProjParam.CheckSampleParam(false))
  908. {
  909. return;
  910. }
  911. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning() && !m_MsrThreadWrapper.BgWorkIsPaused())
  912. {
  913. m_MsrThreadWrapper.StartBGWorkThread();
  914. SetMeasureRibbonButnStatu();
  915. }
  916. else //thread is in pausing state
  917. {
  918. m_MsrThreadWrapper.SetMeasureThreadStatus(OTS_MSR_THREAD_STATUS.INPROCESS);
  919. SetMeasureRibbonButnStatu();
  920. }
  921. }
  922. public void SetStartMeasureRibbonStatus()
  923. {
  924. ribView.Enabled = false;
  925. SetToolButnStatu(false);
  926. //false: 将其他ribbon按钮设置为灰色
  927. rbPanelFile.Enabled = false;
  928. rbPanelSample.Enabled = false;
  929. m_SolutionWindows.Enabled = false;
  930. m_SPropertyWindows.Enabled = false;
  931. rbStart.Enabled = false;
  932. //rbPause.Enabled = true;
  933. rbStop.Enabled = true;
  934. rbCheckParam.Enabled = false;
  935. }
  936. public void SetToolButnStatu(bool bStatu)
  937. {
  938. rbNewDocument.Enabled = bStatu;
  939. rbOpenFile.Enabled = bStatu;
  940. rbSaveFile.Enabled = bStatu;
  941. rvSaveAsFile.Enabled = bStatu;
  942. rbExitApp.Enabled = bStatu;
  943. rbSelectDlg.Enabled = bStatu;
  944. }
  945. private void rbStop_Click(object sender, EventArgs e)
  946. {
  947. //如果当前正在测量,则停止测量线程
  948. if (MeasureThreadRunFlag)
  949. {
  950. //停止测量线程
  951. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.STOPPED);
  952. }
  953. else if (m_MsrThreadWrapper.m_measure.GetMsrThreadStatusobj() .GetStatus()== OTS_MSR_THREAD_STATUS.PAUSED)
  954. {
  955. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.STOPPED);
  956. foreach (KeyValuePair<string, CSmplMeasure> smpl in m_MsrThreadWrapper.m_measure.mapSmplMsr)
  957. {
  958. if (smpl.Value.GetSample().GetMsrStatus().GetStatus() == OTS_MSR_SAMPLE_STATUS.PAUSED)
  959. {
  960. smpl.Value.TheLastWorkOfSampleMeasure();
  961. SetStopMeasureRibbonStatus();
  962. return;
  963. }
  964. }
  965. }
  966. }
  967. private void rbPause_Click(object sender, EventArgs e)
  968. {
  969. //如果当前正在测量,则停止测量线程
  970. if (MeasureThreadRunFlag)
  971. {
  972. //停止测量线程
  973. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.PAUSED);
  974. }
  975. }
  976. private void rbRuler_Click(object sender, EventArgs e)
  977. {
  978. m_SamplepaceWindow.ShowRulerLocation();
  979. }
  980. private void rbSmapleName_Click(object sender, EventArgs e)
  981. {
  982. //m_SamplepaceWindow.ChangeSampleHoleFont();
  983. }
  984. private void rbSmaplePhoto_Click(object sender, EventArgs e)
  985. {
  986. m_SamplepaceWindow.ChangeSampleHoleImage();
  987. }
  988. //当点击Ribbon停止按钮时,设置Ribbon状态
  989. public void SetStopMeasureRibbonStatus()
  990. {
  991. ribView.Enabled = true;
  992. SetToolButnStatu(true);
  993. rbPanelFile.Enabled = true;
  994. rbPanelSample.Enabled = true;
  995. SetMeasureRibbonButnStatu();
  996. m_SolutionWindows.Enabled = true;
  997. m_SPropertyWindows.Enabled = true;
  998. rbStart.Enabled = true;
  999. rbPause.Enabled = false;
  1000. rbStop.Enabled = false;
  1001. rbCheckParam.Enabled = true;
  1002. //激活跳转至报告程序按钮
  1003. rbPReport.Enabled = true;
  1004. rbReport.Enabled = true;
  1005. }
  1006. public void SetPauseMeasureRibbonStatus()
  1007. {
  1008. ribView.Enabled = true;
  1009. SetToolButnStatu(true);
  1010. rbPanelFile.Enabled = true;
  1011. rbPanelSample.Enabled = true;
  1012. SetMeasureRibbonButnStatu();
  1013. m_SolutionWindows.Enabled = true;
  1014. m_SPropertyWindows.Enabled = true;
  1015. rbStart.Enabled = true;
  1016. rbPause.Enabled = false;
  1017. rbStop.Enabled = true;
  1018. rbCheckParam.Enabled = false;
  1019. //激活跳转至报告程序按钮
  1020. rbPReport.Enabled = true;
  1021. rbReport.Enabled = true;
  1022. }
  1023. public bool SwitchDisplayMeasureSample(string sMsrSampleName)
  1024. {
  1025. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  1026. m_SolutionWindows.SwitchSample(sMsrSampleName);
  1027. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  1028. return true;
  1029. }
  1030. #region 开始获取样品孔中的照片
  1031. /// <summary>
  1032. /// 开始获取样品孔中的照片
  1033. /// </summary>
  1034. /// <param name="doRunType"></param>
  1035. /// <param name="HoleID"></param>
  1036. /// <param name="c_DomainMessure"></param>
  1037. public void StartSampleHoleBSEImage()
  1038. {
  1039. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning())
  1040. {
  1041. m_MsrThreadWrapper.StartBGWorkThread();
  1042. SetMeasureRibbonButnStatu();
  1043. }
  1044. }
  1045. #endregion
  1046. private void rbRecover_Click(object sender, EventArgs e)
  1047. {
  1048. //关闭所有内容
  1049. CloseAllContents();
  1050. //显示样品属性窗口与树结构窗口
  1051. m_SolutionWindows.Show(dockPanel, DockState.DockLeft);
  1052. m_SPropertyWindows.Show(dockPanel);
  1053. //显示样品台窗口 测量状态与测量结果窗口
  1054. m_SamplepaceWindow.Show(dockPanel);
  1055. m_MessureStatuWindow.Show(dockPanel);
  1056. m_MeasureResultWindow.Show(dockPanel);
  1057. //此处将在父窗体选项卡上显示
  1058. foreach (Form child in this.MdiChildren)
  1059. {
  1060. if (child.Name == "OTSSamplespaceWindow")
  1061. {
  1062. child.Activate();
  1063. break;
  1064. }
  1065. }
  1066. }
  1067. private void CloseAllContents()
  1068. {
  1069. m_SolutionWindows.DockPanel = null;
  1070. m_SPropertyWindows.DockPanel = null;
  1071. m_SamplepaceWindow.DockPanel = null;
  1072. m_MessureStatuWindow.DockPanel = null;
  1073. m_MeasureResultWindow.DockPanel = null;
  1074. CloseAllDocuments();
  1075. }
  1076. private void CloseAllDocuments()
  1077. {
  1078. if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  1079. {
  1080. foreach (Form form in MdiChildren)
  1081. form.Close();
  1082. }
  1083. else
  1084. {
  1085. IDockContent[] documents = dockPanel.DocumentsToArray();
  1086. foreach (IDockContent content in documents)
  1087. content.DockHandler.Close();
  1088. }
  1089. }
  1090. private void rbMeasureCircle_Click(object sender, EventArgs e)
  1091. {
  1092. m_ProjParam.SetMeasureAreaShape(ShapeType.CIRCLE);
  1093. //修改工作样品的测量区域为圆形
  1094. m_SamplepaceWindow.changeShape(ShapeType.CIRCLE);
  1095. }
  1096. private void rbMeasureRectangle_Click(object sender, EventArgs e)
  1097. {
  1098. m_ProjParam.SetMeasureAreaShape(ShapeType.RECTANGLE);
  1099. //修改工作样品的测量区域为矩形
  1100. m_SamplepaceWindow.changeShape(ShapeType.RECTANGLE);
  1101. }
  1102. //ctrl+s组合键进行保存
  1103. private void OTSIncAMeasureAppForm_KeyDown(object sender, KeyEventArgs e)
  1104. {
  1105. if (e.KeyCode == Keys.S && e.Modifiers == Keys.Control)
  1106. {
  1107. bool iRev = m_ProjRstData.Save();
  1108. if (!iRev)
  1109. {
  1110. log.Error("(OTSIncAMeasureAppForm.rbSaveFile_Click) m_DataMgrFun.SaveFile() Failed !");
  1111. return;
  1112. }
  1113. log.Error("(OTSIncAMeasureAppForm.rbSaveAs_Click) m_DataMgrFun.SaveFile() Success !");
  1114. }
  1115. }
  1116. private void rbSTDEdit_Click_1(object sender, EventArgs e)
  1117. {
  1118. OpenFileDialog openFileDialog = new OpenFileDialog();
  1119. openFileDialog.Filter = "(*.db)|*.db";
  1120. openFileDialog.InitialDirectory = Application.StartupPath + "\\Config\\SysData\\";
  1121. openFileDialog.RestoreDirectory = true;
  1122. openFileDialog.FilterIndex = 1;
  1123. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1124. {
  1125. try
  1126. {
  1127. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", "\""+openFileDialog.FileName+ "\"");
  1128. p.WaitForExit();
  1129. }
  1130. catch (Exception ex)
  1131. {
  1132. log.Error("OTSPartA_STDEditor:" + ex.ToString());
  1133. }
  1134. }
  1135. //reload the setup data just now
  1136. foreach (var s in this.m_ProjRstData.GetSampleList())
  1137. {
  1138. var stdname= s.GetMsrParams().GetSTDName();
  1139. if (stdname != "NoSTDDB")
  1140. {
  1141. if (!stdname.Contains(".db"))
  1142. {
  1143. stdname += ".db";
  1144. }
  1145. var m_classifyEngine = new COTSClassifyEngineClr(EngineType.ExpressionClassifyEng, stdname);
  1146. m_classifyEngine.ReloadEngineDB();
  1147. }
  1148. }
  1149. }
  1150. private void rbSysMgrApp_Click(object sender, EventArgs e)
  1151. {
  1152. try
  1153. {
  1154. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSSysMgrApp.exe");
  1155. p.WaitForExit();
  1156. }
  1157. catch (Exception ex)
  1158. {
  1159. log.Error("OTSSysMgrApp:" + ex.ToString());
  1160. }
  1161. }
  1162. private void ribPolygon_Click(object sender, EventArgs e)
  1163. {
  1164. //修改工作样品的测量区域为矩形
  1165. m_SamplepaceWindow.DrawPolygonMeasure();
  1166. }
  1167. private void rbReClassify_Click(object sender, EventArgs e)
  1168. {
  1169. frmReclassifyCondition reCon = new frmReclassifyCondition();
  1170. reCon.ShowDialog();
  1171. this.Cursor = Cursors.WaitCursor;
  1172. if (reCon.DialogResult == DialogResult.OK)
  1173. {
  1174. if (m_ProjRstData.Reclassify(reCon.ignoreUserModify))
  1175. {
  1176. m_ProjRstData.Save();
  1177. MessageBox.Show("reclassification success");
  1178. }
  1179. else
  1180. {
  1181. MessageBox.Show("reclassification failed");
  1182. }
  1183. }
  1184. this.Cursor = Cursors.Default;
  1185. }
  1186. /// <summary>
  1187. /// 打开测量项目文件
  1188. /// </summary>
  1189. private void OpenMeasureProjectFile()
  1190. {
  1191. bool bOpenFlag=false;
  1192. COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();
  1193. string strPathName;
  1194. // file open dialog
  1195. OpenFileDialog openFileDialog = new OpenFileDialog();
  1196. openFileDialog.Filter = "Probject Files (*.prj)|*.prj";
  1197. if (openFileDialog.ShowDialog() != DialogResult.OK)
  1198. {
  1199. return ;
  1200. }
  1201. strPathName = openFileDialog.FileName;
  1202. this.Cursor = Cursors.WaitCursor;
  1203. if (ProjDataMgr.Load(strPathName))
  1204. {
  1205. m_ProjRstData = ProjDataMgr;
  1206. m_ProjParam.SetResultData(m_ProjRstData);
  1207. m_ProjParam.InitResultData();
  1208. bOpenFlag = true;
  1209. }
  1210. this.Cursor = Cursors.Default;
  1211. if (bOpenFlag)
  1212. {
  1213. if (!DisplayExistSampleFile())
  1214. {
  1215. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) OpenExistSampleFile() = false Failed !");
  1216. return;
  1217. }
  1218. SetAllRibbonButnStatus(true);
  1219. }
  1220. else
  1221. {
  1222. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) m_DataMgrFun.OpenExistSampleFile() Failed !");
  1223. }
  1224. }
  1225. private void OTSIncAMeasureAppForm_FormClosed(object sender, FormClosedEventArgs e)
  1226. {
  1227. }
  1228. private void rbAbout_Click(object sender, EventArgs e)
  1229. {
  1230. var SystemType = m_ProjParam.GetDefaultParam().SystemTypeId;
  1231. if (SystemType == OTS_SysType_ID.IncA)
  1232. {
  1233. OTSSplashScreen_IncA m_about = new OTSSplashScreen_IncA();
  1234. m_about.TopMost = false;
  1235. m_about.ShowInTaskbar = true;
  1236. m_about.Show();
  1237. }
  1238. else if (SystemType == OTS_SysType_ID.TCCleannessA|| SystemType == OTS_SysType_ID.BatteryCleannessA)
  1239. {
  1240. OTSSplashScreen_Cleanness m_about = new OTSSplashScreen_Cleanness();
  1241. m_about.TopMost = false;
  1242. m_about.ShowInTaskbar = true;
  1243. m_about.Show();
  1244. }
  1245. else if (SystemType == OTS_SysType_ID.SteelMineral)
  1246. {
  1247. OTSSplashScreen_SteelMineral m_about = new OTSSplashScreen_SteelMineral();
  1248. m_about.TopMost = false;
  1249. m_about.ShowInTaskbar = true;
  1250. m_about.Show();
  1251. }
  1252. }
  1253. protected override void DefWndProc(ref Message m)
  1254. {
  1255. switch (m.Msg)
  1256. {
  1257. case MsgID:
  1258. break;
  1259. case LogMsgID:
  1260. m_LogMsg = new PostLogMsg();
  1261. m_LogMsg = (PostLogMsg)Marshal.PtrToStructure(m.LParam, typeof(PostLogMsg));
  1262. var log = NLog.LogManager.GetCurrentClassLogger();
  1263. string s = GetString(m_LogMsg.logMessage);
  1264. switch (m_LogMsg.logLevel)
  1265. {
  1266. case 1:
  1267. log.Trace(s);
  1268. break;
  1269. case 2:
  1270. log.Debug(s);
  1271. break;
  1272. case 3:
  1273. log.Info(s);
  1274. break;
  1275. case 4:
  1276. log.Warn(s);
  1277. break;
  1278. case 5:
  1279. log.Error(s);
  1280. break;
  1281. case 6:
  1282. log.Fatal(s);
  1283. break;
  1284. }
  1285. break;
  1286. default:
  1287. base.DefWndProc(ref m);
  1288. break;
  1289. }
  1290. }
  1291. private string GetString(char[] csStr)
  1292. {
  1293. int ilen = csStr.Length;
  1294. string csName = new string(csStr); //MSTMsg.STMSampleStu.cSName
  1295. csName.IndexOf('\0');
  1296. csName = csName.Substring(0, csName.IndexOf('\0'));
  1297. return csName;
  1298. }
  1299. private void PrepareIpcServer()
  1300. {
  1301. //Instantiate our server channel.
  1302. IpcServerChannel channel = new IpcServerChannel("ServerChannel");
  1303. //Register the server channel.
  1304. ChannelServices.RegisterChannel(channel, false);
  1305. //Register this service type.
  1306. RemotingConfiguration.RegisterWellKnownServiceType(typeof(IpcSEMController), "RemoteObject", WellKnownObjectMode.Singleton);
  1307. }
  1308. private void rbConnectHardware_Click_1(object sender, EventArgs e)
  1309. {
  1310. if (!m_MsrThreadWrapper.IsSEMConnected())
  1311. {
  1312. if (!m_MsrThreadWrapper.ConnectSEM())
  1313. {
  1314. MessageBox.Show("Connect failed!");
  1315. return;
  1316. }
  1317. }
  1318. this.rbConnectHardware.Enabled = false;
  1319. this.rbDisconnectHardware.Enabled = true;
  1320. log.Warn("SEM connect success!");
  1321. }
  1322. private void rbDisconnectHardware_Click_1(object sender, EventArgs e)
  1323. {
  1324. if (m_MsrThreadWrapper.IsSEMConnected())
  1325. {
  1326. m_MsrThreadWrapper.DisconnectSEM();
  1327. }
  1328. this.rbDisconnectHardware.Enabled = false;
  1329. this.rbConnectHardware.Enabled = true;
  1330. log.Warn("SEM Disconnect!");
  1331. }
  1332. private void rbinterrupt_Click(object sender, EventArgs e)
  1333. {
  1334. if (m_MsrThreadWrapper.IsSEMConnected())
  1335. {
  1336. m_MsrThreadWrapper.StopXrayAcquisition();
  1337. }
  1338. log.Warn("StopXrayAcquisition!");
  1339. }
  1340. private void rbAutoBeamOff_Click(object sender, EventArgs e)
  1341. {
  1342. if (m_ProjRstData.GetGenParam().AutoBeamOff)
  1343. {
  1344. m_ProjRstData.GetGenParam().AutoBeamOff = false;
  1345. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1346. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1347. }
  1348. else
  1349. {
  1350. m_ProjRstData.GetGenParam().AutoBeamOff = true;
  1351. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1352. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1353. }
  1354. }
  1355. private void OTSIncAMeasureAppForm_Activated(object sender, EventArgs e)
  1356. {
  1357. }
  1358. private void ribbonButton2_Click(object sender, EventArgs e)
  1359. {
  1360. frmReclassifyCondition reCon= new frmReclassifyCondition();
  1361. reCon.ShowDialog();
  1362. this.Cursor = Cursors.WaitCursor;
  1363. if (reCon.DialogResult == DialogResult.OK)
  1364. {
  1365. if (m_ProjRstData.Reclassify(reCon.ignoreUserModify))
  1366. {
  1367. m_ProjRstData.Save();
  1368. MessageBox.Show("reclassification success");
  1369. }
  1370. else
  1371. {
  1372. MessageBox.Show("reclassification failed");
  1373. }
  1374. }
  1375. this.Cursor = Cursors.Default;
  1376. }
  1377. private void ribonBtnShot_Click(object sender, EventArgs e)
  1378. {
  1379. m_SamplepaceWindow.DrawOnlyShotMeasure();
  1380. }
  1381. }
  1382. }