OTSIncAMeasureAppForm.cs 63 KB

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