OTSIncAMeasureAppForm.cs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751
  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. m_ProjRstData = m_ProjParam.GetResultData();
  403. SetAllRibbonButnStatus(true);
  404. //清除TREEVIEW和GRID上的显示的已经保存的样品信息
  405. m_SolutionWindows.m_TreeViewBase.DeleteAllTreeNode();
  406. m_SPropertyWindows.m_SampleGrid.HideGrid();
  407. //设置报告按钮
  408. rbPReport.Enabled = false;
  409. rbReport.Enabled = false;
  410. rbReClassify.Enabled = true;
  411. //新建项目时,设置属性窗体中的两个按钮也为不可用状态
  412. m_SPropertyWindows.TSLoad.Enabled = false;
  413. m_SPropertyWindows.TSSaveAs.Enabled = false;
  414. //绘制样品台
  415. m_SamplepaceWindow.InitStageDisplay(m_ProjRstData.GetStageHolder(), m_ProjRstData.GetSEMStageData());
  416. //隐藏XrayTable控件
  417. m_MessureStatuWindow.HideXRayTable();
  418. //新建时重新初始化结果窗体结果
  419. m_MeasureResultWindow.SetInit();
  420. }
  421. // 新建样品时提示保存样品信息Messagebox
  422. public int ShowSaveInfoMsgBox()
  423. {
  424. string message = table["message4"].ToString();
  425. DialogResult dResult = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
  426. if (dResult == DialogResult.Yes)
  427. {
  428. return (int)MessageBoxRev.DIALOG_YES;
  429. }
  430. else if (dResult == DialogResult.No)
  431. {
  432. return (int)MessageBoxRev.DIALOG_NO;
  433. }
  434. else
  435. {
  436. return (int)MessageBoxRev.DIALOG_CANCEL;
  437. }
  438. }
  439. //打开已经保存的工作文件
  440. private bool DisplayExistSampleFile()
  441. {
  442. List<CTreeSampleParam> TSampleParamList = new List<CTreeSampleParam>();
  443. List<SampleMeasurePara> SampleMeasureParaList = new List<SampleMeasurePara>();
  444. int iSampleCount = m_ProjRstData.GetSampleList().Count;
  445. if (0 == iSampleCount)
  446. {
  447. return false;
  448. }
  449. for (int i = 0; i < iSampleCount; i++)
  450. {
  451. CTreeSampleParam CTSampleParam = new CTreeSampleParam();
  452. COTSSample SampleClr = (m_ProjRstData.GetSampleList())[i];
  453. CTSampleParam.sSampleTitleName = m_ProjRstData.GetFileName();
  454. CTSampleParam.sWorkSampleName = SampleClr.GetName();
  455. CTSampleParam.bSwitch = SampleClr.GetSwitch();
  456. TSampleParamList.Add(CTSampleParam);
  457. }
  458. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  459. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  460. m_SolutionWindows.DisplayExistSampleFile(TSampleParamList, SMInfo.TSampleParam);
  461. if (!InitExistSampleMeasureParam(ref SampleMeasureParaList))
  462. {
  463. log.Error(" OpenExistSampleMeasureArea(ref SampleMeasureAreaList) Failed !");
  464. return false;
  465. }
  466. string sWSampleName = m_ProjParam.GetWorkSampleName();
  467. if ("" == sWSampleName)
  468. {
  469. log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile) m_DataMgrFun.GetWorkSampleName() = null !");
  470. return false;
  471. }
  472. m_SamplepaceWindow.DisplayVisualStage(m_ProjRstData.GetStageHolder(), m_ProjRstData.GetSEMStageData());
  473. m_SamplepaceWindow.DisplayExistSamples( SampleMeasureParaList);
  474. m_MeasureResultWindow.UpdateResultInfoBySampleName(sWSampleName);
  475. return true;
  476. }
  477. public bool InitExistSampleMeasureParam(ref List<SampleMeasurePara> SampleMeasureParaList)
  478. {
  479. int iSListCount = m_ProjRstData.GetSampleList().Count;
  480. if (0 == iSListCount)
  481. {
  482. return false;
  483. }
  484. for (int i = 0; i < iSListCount; i++)
  485. {
  486. SampleMeasurePara SampleMeasureParam =new SampleMeasurePara(m_ProjRstData.GetSampleList()[i]);
  487. SampleMeasureParaList.Add(SampleMeasureParam);
  488. }
  489. return true;
  490. }
  491. //打开指定路径的文件
  492. private void rbOpen_Click(object sender, EventArgs e)
  493. {
  494. OpenMeasureProjectFile();
  495. }
  496. private void rbDeleteSample_Click(object sender, EventArgs e)
  497. {
  498. //删除样品(样品必须先选中)
  499. string sWSampleName = m_ProjParam.GetWorkSampleName();
  500. if ("" == sWSampleName)
  501. {
  502. log.Error("(OTSIncAMeasureAppForm.rbDeleteSample_Click) m_DataMgrFun.GetWorkSampleName() = null Failed");
  503. return;
  504. }
  505. string message = table["message5"].ToString();
  506. string message6 = table["message6"].ToString();
  507. string sDeleteSampleName = message;
  508. sDeleteSampleName += sWSampleName;
  509. sDeleteSampleName += message6;
  510. if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  511. {
  512. //删除样品成功
  513. DeleteSample(sWSampleName);
  514. sWSampleName = m_ProjParam.GetWorkSampleName();
  515. if ("" != sWSampleName)
  516. {
  517. m_SolutionWindows.m_TreeViewBase.GetTreeWorkSampleNode(sWSampleName);
  518. m_SolutionWindows.treeView1.Focus();
  519. }
  520. }
  521. }
  522. public void SetRibbonButonWorkListStatu(List<int> RibbonButnIDList, bool bFlag)
  523. {
  524. if (RibbonButnIDList.Count == 0)
  525. {
  526. return;
  527. }
  528. for (int i = 0; i < RibbonButnIDList.Count; i++)
  529. {
  530. if (RibbonButnIDList[i] == (int)RibbonButnID.NewDocment)
  531. {
  532. rbNewDocument.Enabled = bFlag;
  533. continue;
  534. }
  535. if (RibbonButnIDList[i] == (int)RibbonButnID.File_NewDocment)
  536. {
  537. rbNew.Enabled = bFlag;
  538. continue;
  539. }
  540. if (RibbonButnIDList[i] == (int)RibbonButnID.OpenDocment)
  541. {
  542. rbOpenFile.Enabled = bFlag;
  543. continue;
  544. }
  545. if (RibbonButnIDList[i] == (int)RibbonButnID.File_OpenDocment)
  546. {
  547. rbOpen.Enabled = bFlag;
  548. continue;
  549. }
  550. if (RibbonButnIDList[i] == (int)RibbonButnID.Save)
  551. {
  552. rbSaveFile.Enabled = bFlag;
  553. continue;
  554. }
  555. if (RibbonButnIDList[i] == (int)RibbonButnID.File_Save)
  556. {
  557. rbSave.Enabled = bFlag;
  558. continue;
  559. }
  560. if (RibbonButnIDList[i] == (int)RibbonButnID.SaveAs)
  561. {
  562. rvSaveAsFile.Enabled = bFlag;
  563. continue;
  564. }
  565. if (RibbonButnIDList[i] == (int)RibbonButnID.File_SaveAs)
  566. {
  567. rbSaveAs.Enabled = bFlag;
  568. continue;
  569. }
  570. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_AddSampl)
  571. {
  572. rbAddSample.Enabled = bFlag;
  573. continue;
  574. }
  575. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_DeleteSample)
  576. {
  577. rbDeleteSample.Enabled = bFlag;
  578. continue;
  579. }
  580. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_Reset)
  581. {
  582. ribInvers.Enabled = bFlag;
  583. continue;
  584. }
  585. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_DrawCircle)
  586. {
  587. ribCircle.Enabled = bFlag;
  588. continue;
  589. }
  590. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_DrawRectang)
  591. {
  592. ribRectangle.Enabled = bFlag;
  593. continue;
  594. }
  595. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_DrawPolygon)
  596. {
  597. ribPolygon.Enabled = bFlag;
  598. continue;
  599. }
  600. if (RibbonButnIDList[i] == (int)RibbonButnID.View_Ruler)
  601. {
  602. rbRuler.Enabled = bFlag;
  603. continue;
  604. }
  605. if (RibbonButnIDList[i] == (int)RibbonButnID.View_SPhoto)
  606. {
  607. rbSmaplePhoto.Enabled = bFlag;
  608. continue;
  609. }
  610. if (RibbonButnIDList[i] == (int)RibbonButnID.View_SName)
  611. {
  612. rbSmapleName.Enabled = bFlag;
  613. continue;
  614. }
  615. if (RibbonButnIDList[i] == (int)RibbonButnID.View_Recover)
  616. {
  617. rbRecover.Enabled = bFlag;
  618. continue;
  619. }
  620. if (RibbonButnIDList[i] == (int)RibbonButnID.File_Base)
  621. {
  622. rbMenu.Tabs[0].Panels[0].Enabled = bFlag;
  623. continue;
  624. }
  625. if (RibbonButnIDList[i] == (int)RibbonButnID.Sample_Base)
  626. {
  627. rbPanelSample.Enabled = bFlag;
  628. continue;
  629. }
  630. if (RibbonButnIDList[i] == (int)RibbonButnID.Funciton_Base)
  631. {
  632. rbPanelFunction.Enabled = bFlag;
  633. continue;
  634. }
  635. if (RibbonButnIDList[i] == (int)RibbonButnID.View_Base)
  636. {
  637. rbMenu.Tabs[1].Panels[0].Enabled = bFlag;
  638. continue;
  639. }
  640. if (RibbonButnIDList[i] == (int)RibbonButnID.Fun_Report)
  641. {
  642. rbMenu.Tabs[1].Panels[0].Enabled = bFlag;
  643. continue;
  644. }
  645. if (RibbonButnIDList[i] == (int)RibbonButnID.ShotImage)
  646. {
  647. ribonBtnShot.Enabled = bFlag;
  648. continue;
  649. }
  650. }
  651. }
  652. //设置 删除,复位,圆形,矩形 按钮状态
  653. public void SetSampleRibbonButnStatus()
  654. {
  655. List<int> RibbonIdList = new List<int>();
  656. RibbonIdList.Add((int)RibbonButnID.Sample_DeleteSample);
  657. RibbonIdList.Add((int)RibbonButnID.Sample_Reset);
  658. RibbonIdList.Add((int)RibbonButnID.Sample_DrawCircle);
  659. RibbonIdList.Add((int)RibbonButnID.Sample_DrawRectang);
  660. RibbonIdList.Add((int)RibbonButnID.Sample_DrawPolygon);
  661. RibbonIdList.Add((int)RibbonButnID.ShotImage);
  662. if (0 == m_ProjParam.GetSampleCount())
  663. {
  664. SetRibbonButonWorkListStatu(RibbonIdList, false);
  665. }
  666. else
  667. {
  668. SetRibbonButonWorkListStatu(RibbonIdList, true);
  669. }
  670. }
  671. public void SetReprotRibbonButnStatu()
  672. {
  673. //设置跳转至报告程序按钮状态
  674. rbPReport.Enabled = false;
  675. rbReport.Enabled = false;
  676. rbReClassify.Enabled = true;
  677. //判断打开的文件是否存在测量结果文件路径
  678. List<string> mrFilePathList = new List<string>();
  679. bool result = m_ProjParam.GetCompletedMeasureFileName(ref mrFilePathList);
  680. //根据结果设置报告按钮启用状态
  681. if (result)
  682. {
  683. rbPReport.Enabled = true;
  684. rbReport.Enabled = true;
  685. rbReClassify.Enabled = true;
  686. }
  687. else
  688. {
  689. rbPReport.Enabled = false;
  690. rbReport.Enabled = false;
  691. rbReClassify.Enabled = true;
  692. }
  693. }
  694. //返回删除的工作样品名
  695. public void DeleteSample(string sDeleteWSampleName = "")
  696. {
  697. if (m_MsrThreadWrapper.m_measure.mapSmplMsr.ContainsKey(sDeleteWSampleName))
  698. {
  699. m_MsrThreadWrapper.m_measure.mapSmplMsr.Remove(sDeleteWSampleName);
  700. }
  701. m_ProjParam.DeleteWorkSample(sDeleteWSampleName);
  702. // 设置 开始 ,停止 和检查参数 按钮状态
  703. SetMeasureRibbonButnStatu();
  704. //设置 删除,复位,圆形,矩形 按钮状态
  705. SetSampleRibbonButnStatus();
  706. // 更新报告ribbon按钮状态
  707. SetAllRibbonButnStatus(true);
  708. int iSampleCount = m_ProjParam.GetSampleCount();
  709. if (0 == iSampleCount)
  710. {
  711. //给工作样品台发送删除样品和新的工作样品名称
  712. m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName);
  713. m_SPropertyWindows.PropGrid.Hide();
  714. m_SPropertyWindows.toolStripButton_refresh.Enabled = false;
  715. m_SPropertyWindows.TSSaveAs.Enabled = false;
  716. m_SolutionWindows.treeView1.Nodes.Clear();
  717. m_MessureStatuWindow.HideXRayTable();
  718. m_MeasureResultWindow.SetInit();
  719. return ;
  720. }
  721. else
  722. {
  723. string sNewWSName = m_ProjParam.GetWorkSampleName();
  724. if ("" == sNewWSName)
  725. {
  726. log.Error("(OTSIncAMeasureAppForm.DeleteSample) m_DataMgrFun.GetWorkSampleName() = null Failed");
  727. return ;
  728. }
  729. m_SolutionWindows.DeletCurrentSampleNode();
  730. m_SolutionWindows.DisplaySample(sNewWSName);
  731. //将测量状态初始化
  732. m_MessureStatuWindow.SetMeasureStatusInit();
  733. //给工作样品台发送删除样品和新的工作样品名称
  734. m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName);
  735. //设置工作样品
  736. SwitchWSample(sNewWSName);
  737. }
  738. return ;
  739. }
  740. private void rbAddSample_Click(object sender, EventArgs e)
  741. {
  742. this.AddNewSampleMeasure();//the system will choose the empty hole one by one according to the holeNo sequence.
  743. }
  744. public void AddNewSampleMeasure(string sSampleHoleName = "")
  745. {
  746. OTSSampleVisualPropertyInfo SMInfo = m_ProjParam.AddNewSampleMeasure(sSampleHoleName);
  747. if (null == SMInfo)
  748. {
  749. // 设置 开始 ,停止 和检查参数 按钮状态
  750. SetMeasureRibbonButnStatu();
  751. log.Error("(OTSIncAMeasureAppForm.AddNewSample) m_DataMgrFun.AddNewSample(sSampleHoleName) = null ");
  752. return;
  753. }
  754. m_SPropertyWindows.TSSaveAs.Enabled = true;
  755. m_SPropertyWindows.TSLoad.Enabled = true;
  756. m_SPropertyWindows.TSEdit.Enabled = false;
  757. m_SPropertyWindows.TSEdit.Visible = false;
  758. //给SampleWindow 发送样品信息
  759. m_SamplepaceWindow.AddSampleArea(SMInfo.SMeasurePara);
  760. m_SamplepaceWindow.ReadSEMDataAndSetToCurrentSample();
  761. //给PropWindow 发送工作样品属性信息
  762. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  763. //给SoluWindow 发送样品显示信息
  764. m_SolutionWindows.AddSampleMeasure(SMInfo.TSampleParam);
  765. // 设置 开始 ,停止 和检查参数 按钮状态
  766. SetMeasureRibbonButnStatu();
  767. //设置 删除,复位,圆形,矩形 按钮状态
  768. SetSampleRibbonButnStatus();
  769. }
  770. public void InitCurrentSampleState()
  771. {
  772. OTSSampleVisualPropertyInfo SMInfo = m_ProjParam.GetWorkingSampleVisualPropertyInfo();
  773. if (null == SMInfo)
  774. {
  775. // 设置 开始 ,停止 和检查参数 按钮状态
  776. SetMeasureRibbonButnStatu();
  777. log.Error("(OTSIncAMeasureAppForm.AddNewSample) m_DataMgrFun.AddNewSample(sSampleHoleName) = null ");
  778. return;
  779. }
  780. m_SPropertyWindows.TSSaveAs.Enabled = true;
  781. m_SPropertyWindows.TSLoad.Enabled = true;
  782. m_SamplepaceWindow.ReadSEMDataAndSetToCurrentSample();
  783. //给PropWindow 发送工作样品属性信息
  784. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  785. // 设置 开始 ,停止 和检查参数 按钮状态
  786. SetMeasureRibbonButnStatu();
  787. //设置 删除,复位,圆形,矩形 按钮状态
  788. SetSampleRibbonButnStatus();
  789. }
  790. private void rbSelectDlg_Click(object sender, EventArgs e)
  791. {
  792. ProgMgrInfoForm ProgMgrForm = new ProgMgrInfoForm();
  793. if (DialogResult.OK == ProgMgrForm.ShowDialog())
  794. {
  795. if (m_ProjParam.LoadParamFile())
  796. {
  797. if (m_ProjParam.InitResultData())
  798. {
  799. SetAllRibbonButnStatus(true);
  800. //当样品台上有样品,则不更新样品台数据
  801. if (0 == m_ProjParam.GetSampleCount())
  802. {
  803. m_SamplepaceWindow.InitStageDisplay(m_ProjRstData.GetStageHolder(), m_ProjRstData.GetSEMStageData());
  804. }
  805. }
  806. else
  807. {
  808. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) this.CheckMeasureSysFileExist() = false");
  809. }
  810. }
  811. else
  812. {
  813. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) (m_DataMgrFun.CheckParamFile() && m_DataMgrFun.CheckStageFile()) = false");
  814. }
  815. }
  816. }
  817. // 主Windows框右下角显示鼠标点的SEM坐标(样品台)
  818. public void ShowSemCoordvAL(string sSemCoord)
  819. {
  820. STSemCoordinate.Text = sSemCoord;
  821. statusStrip1.Refresh();
  822. }
  823. //// 主Windows框右下角显示鼠标点的灰度值(测量图)
  824. public void ShowGrayVal(string sGrayVal)
  825. {
  826. TSGrayVal.Text = sGrayVal;
  827. statusStrip1.Refresh();
  828. }
  829. //获取工作样品测量锁
  830. public bool GetWorkSampleParamLock(ref CTreeSampleParam TSParamLock)
  831. {
  832. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  833. TSParamLock = SMInfo.TSampleParam;
  834. return true;
  835. }
  836. /// <summary>
  837. /// 更新属性窗口
  838. /// </summary>
  839. public void UpdatePropertyVal()
  840. {
  841. //获取新的工作样品属性值
  842. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  843. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  844. }
  845. private void ribbonOrbMenuItemSaveAs_Click(object sender, EventArgs e)
  846. {
  847. bool iRev = m_ProjRstData.SaveAs();
  848. if (!iRev)
  849. {
  850. return;
  851. }
  852. foreach (var spl in m_ProjParam.MeasureSampleList)
  853. {
  854. m_SamplepaceWindow.InitSampleMeasure(spl, 0);
  855. }
  856. m_SamplepaceWindow.PrepareVisualMeasureField(m_SamplepaceWindow.GetWorkingVisualSample());
  857. }
  858. private void rbSaveFile_Click(object sender, EventArgs e)
  859. {
  860. bool iRev = m_ProjRstData.Save();
  861. if (!iRev)
  862. {
  863. return;
  864. }
  865. }
  866. private void rbCheckParam_Click(object sender, EventArgs e)
  867. {
  868. //检查样品测量参数
  869. if (m_ProjParam.CheckSampleParam(true))
  870. {
  871. string message = table["message7"].ToString();
  872. MessageBox.Show(message, "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  873. }
  874. }
  875. private void ribReset_Click(object sender, EventArgs e)
  876. {
  877. //调用样品台窗口中的复位方法
  878. m_SamplepaceWindow.InverseSelectWorkSampleMeasure();
  879. }
  880. //绘制圆形测量区域
  881. private void ribCircle_Click(object sender, EventArgs e)
  882. {
  883. //修改工作样品的测量区域为圆形
  884. m_SamplepaceWindow.DrawCircleMeasure();
  885. }
  886. private void rbThreePoints_Click(object sender, EventArgs e)
  887. {
  888. //修改工作样品的测量区域为圆形
  889. m_SamplepaceWindow.DrawCircleMeasureByThreePoints();
  890. }
  891. private void rbRingShape_Click(object sender, EventArgs e)
  892. {
  893. //修改工作样品的测量区域为圆形
  894. m_SamplepaceWindow.DrawRingShapeArea();
  895. }
  896. //绘制矩形测量区域
  897. private void ribRectangle_Click(object sender, EventArgs e)
  898. {
  899. //修改工作样品的测量区域为矩形
  900. m_SamplepaceWindow.DrawRectangleMeasure();
  901. }
  902. private void rbExitApp_Click(object sender, EventArgs e)
  903. {
  904. this.Close();
  905. }
  906. private void rbStart_Click(object sender, EventArgs e)
  907. {
  908. if (!m_ProjParam.CheckSampleParam(false))
  909. {
  910. return;
  911. }
  912. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning() && !m_MsrThreadWrapper.BgWorkIsPaused())
  913. {
  914. m_MsrThreadWrapper.StartBGWorkThread();
  915. SetMeasureRibbonButnStatu();
  916. }
  917. else //thread is in pausing state
  918. {
  919. m_MsrThreadWrapper.SetMeasureThreadStatus(OTS_MSR_THREAD_STATUS.INPROCESS);
  920. SetMeasureRibbonButnStatu();
  921. }
  922. }
  923. public void SetStartMeasureRibbonStatus()
  924. {
  925. ribView.Enabled = false;
  926. SetToolButnStatu(false);
  927. //false: 将其他ribbon按钮设置为灰色
  928. rbPanelFile.Enabled = false;
  929. rbPanelSample.Enabled = false;
  930. m_SolutionWindows.Enabled = false;
  931. m_SPropertyWindows.Enabled = false;
  932. rbStart.Enabled = false;
  933. //rbPause.Enabled = true;
  934. rbStop.Enabled = true;
  935. rbCheckParam.Enabled = false;
  936. }
  937. public void SetToolButnStatu(bool bStatu)
  938. {
  939. rbNewDocument.Enabled = bStatu;
  940. rbOpenFile.Enabled = bStatu;
  941. rbSaveFile.Enabled = bStatu;
  942. rvSaveAsFile.Enabled = bStatu;
  943. rbExitApp.Enabled = bStatu;
  944. rbSelectDlg.Enabled = bStatu;
  945. }
  946. private void rbStop_Click(object sender, EventArgs e)
  947. {
  948. //如果当前正在测量,则停止测量线程
  949. if (MeasureThreadRunFlag)
  950. {
  951. //停止测量线程
  952. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.STOPPED);
  953. }
  954. else if (m_MsrThreadWrapper.m_measure.GetMsrThreadStatusobj() .GetStatus()== OTS_MSR_THREAD_STATUS.PAUSED)
  955. {
  956. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.STOPPED);
  957. foreach (KeyValuePair<string, CSmplMeasure> smpl in m_MsrThreadWrapper.m_measure.mapSmplMsr)
  958. {
  959. if (smpl.Value.GetSample().GetMsrStatus().GetStatus() == OTS_MSR_SAMPLE_STATUS.PAUSED)
  960. {
  961. smpl.Value.TheLastWorkOfSampleMeasure();
  962. SetStopMeasureRibbonStatus();
  963. return;
  964. }
  965. }
  966. }
  967. }
  968. private void rbPause_Click(object sender, EventArgs e)
  969. {
  970. //如果当前正在测量,则停止测量线程
  971. if (MeasureThreadRunFlag)
  972. {
  973. //停止测量线程
  974. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.PAUSED);
  975. }
  976. }
  977. private void rbRuler_Click(object sender, EventArgs e)
  978. {
  979. m_SamplepaceWindow.ShowRulerLocation();
  980. }
  981. private void rbSmapleName_Click(object sender, EventArgs e)
  982. {
  983. //m_SamplepaceWindow.ChangeSampleHoleFont();
  984. }
  985. private void rbSmaplePhoto_Click(object sender, EventArgs e)
  986. {
  987. m_SamplepaceWindow.ChangeSampleHoleImage();
  988. }
  989. //当点击Ribbon停止按钮时,设置Ribbon状态
  990. public void SetStopMeasureRibbonStatus()
  991. {
  992. ribView.Enabled = true;
  993. SetToolButnStatu(true);
  994. rbPanelFile.Enabled = true;
  995. rbPanelSample.Enabled = true;
  996. SetMeasureRibbonButnStatu();
  997. m_SolutionWindows.Enabled = true;
  998. m_SPropertyWindows.Enabled = true;
  999. rbStart.Enabled = true;
  1000. rbPause.Enabled = false;
  1001. rbStop.Enabled = false;
  1002. rbCheckParam.Enabled = true;
  1003. //激活跳转至报告程序按钮
  1004. rbPReport.Enabled = true;
  1005. rbReport.Enabled = true;
  1006. }
  1007. public void SetPauseMeasureRibbonStatus()
  1008. {
  1009. ribView.Enabled = true;
  1010. SetToolButnStatu(true);
  1011. rbPanelFile.Enabled = true;
  1012. rbPanelSample.Enabled = true;
  1013. SetMeasureRibbonButnStatu();
  1014. m_SolutionWindows.Enabled = true;
  1015. m_SPropertyWindows.Enabled = true;
  1016. rbStart.Enabled = true;
  1017. rbPause.Enabled = false;
  1018. rbStop.Enabled = true;
  1019. rbCheckParam.Enabled = false;
  1020. //激活跳转至报告程序按钮
  1021. rbPReport.Enabled = true;
  1022. rbReport.Enabled = true;
  1023. }
  1024. public bool SwitchDisplayMeasureSample(string sMsrSampleName)
  1025. {
  1026. OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(m_ProjParam.GetWorkSample(),m_ProjParam.GetDefaultParam().GetSysType());
  1027. m_SolutionWindows.SwitchSample(sMsrSampleName);
  1028. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  1029. return true;
  1030. }
  1031. #region 开始获取样品孔中的照片
  1032. /// <summary>
  1033. /// 开始获取样品孔中的照片
  1034. /// </summary>
  1035. /// <param name="doRunType"></param>
  1036. /// <param name="HoleID"></param>
  1037. /// <param name="c_DomainMessure"></param>
  1038. public void StartSampleHoleBSEImage()
  1039. {
  1040. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning())
  1041. {
  1042. m_MsrThreadWrapper.StartBGWorkThread();
  1043. SetMeasureRibbonButnStatu();
  1044. }
  1045. }
  1046. #endregion
  1047. private void rbRecover_Click(object sender, EventArgs e)
  1048. {
  1049. //关闭所有内容
  1050. CloseAllContents();
  1051. //显示样品属性窗口与树结构窗口
  1052. m_SolutionWindows.Show(dockPanel, DockState.DockLeft);
  1053. m_SPropertyWindows.Show(dockPanel);
  1054. //显示样品台窗口 测量状态与测量结果窗口
  1055. m_SamplepaceWindow.Show(dockPanel);
  1056. m_MessureStatuWindow.Show(dockPanel);
  1057. m_MeasureResultWindow.Show(dockPanel);
  1058. //此处将在父窗体选项卡上显示
  1059. foreach (Form child in this.MdiChildren)
  1060. {
  1061. if (child.Name == "OTSSamplespaceWindow")
  1062. {
  1063. child.Activate();
  1064. break;
  1065. }
  1066. }
  1067. }
  1068. private void CloseAllContents()
  1069. {
  1070. m_SolutionWindows.DockPanel = null;
  1071. m_SPropertyWindows.DockPanel = null;
  1072. m_SamplepaceWindow.DockPanel = null;
  1073. m_MessureStatuWindow.DockPanel = null;
  1074. m_MeasureResultWindow.DockPanel = null;
  1075. CloseAllDocuments();
  1076. }
  1077. private void CloseAllDocuments()
  1078. {
  1079. if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  1080. {
  1081. foreach (Form form in MdiChildren)
  1082. form.Close();
  1083. }
  1084. else
  1085. {
  1086. IDockContent[] documents = dockPanel.DocumentsToArray();
  1087. foreach (IDockContent content in documents)
  1088. content.DockHandler.Close();
  1089. }
  1090. }
  1091. private void rbMeasureCircle_Click(object sender, EventArgs e)
  1092. {
  1093. m_ProjParam.SetMeasureAreaShape(ShapeType.CIRCLE);
  1094. //修改工作样品的测量区域为圆形
  1095. m_SamplepaceWindow.changeShape(ShapeType.CIRCLE);
  1096. }
  1097. private void rbMeasureRectangle_Click(object sender, EventArgs e)
  1098. {
  1099. m_ProjParam.SetMeasureAreaShape(ShapeType.RECTANGLE);
  1100. //修改工作样品的测量区域为矩形
  1101. m_SamplepaceWindow.changeShape(ShapeType.RECTANGLE);
  1102. }
  1103. //ctrl+s组合键进行保存
  1104. private void OTSIncAMeasureAppForm_KeyDown(object sender, KeyEventArgs e)
  1105. {
  1106. if (e.KeyCode == Keys.S && e.Modifiers == Keys.Control)
  1107. {
  1108. bool iRev = m_ProjRstData.Save();
  1109. if (!iRev)
  1110. {
  1111. log.Error("(OTSIncAMeasureAppForm.rbSaveFile_Click) m_DataMgrFun.SaveFile() Failed !");
  1112. return;
  1113. }
  1114. log.Error("(OTSIncAMeasureAppForm.rbSaveAs_Click) m_DataMgrFun.SaveFile() Success !");
  1115. }
  1116. }
  1117. private void rbSTDEdit_Click_1(object sender, EventArgs e)
  1118. {
  1119. OpenFileDialog openFileDialog = new OpenFileDialog();
  1120. openFileDialog.Filter = "(*.db)|*.db";
  1121. openFileDialog.InitialDirectory = Application.StartupPath + "\\Config\\SysData\\";
  1122. openFileDialog.RestoreDirectory = true;
  1123. openFileDialog.FilterIndex = 1;
  1124. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1125. {
  1126. try
  1127. {
  1128. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", "\""+openFileDialog.FileName+ "\"");
  1129. p.WaitForExit();
  1130. }
  1131. catch (Exception ex)
  1132. {
  1133. log.Error("OTSPartA_STDEditor:" + ex.ToString());
  1134. }
  1135. }
  1136. //reload the setup data just now
  1137. foreach (var s in this.m_ProjRstData.GetSampleList())
  1138. {
  1139. var stdname= s.GetMsrParams().GetSTDName();
  1140. if (stdname != "NoSTDDB")
  1141. {
  1142. if (!stdname.Contains(".db"))
  1143. {
  1144. stdname += ".db";
  1145. }
  1146. var m_classifyEngine = new COTSClassifyEngineClr(EngineType.ExpressionClassifyEng, stdname);
  1147. m_classifyEngine.ReloadEngineDB();
  1148. }
  1149. }
  1150. }
  1151. private void rbSysMgrApp_Click(object sender, EventArgs e)
  1152. {
  1153. try
  1154. {
  1155. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSSysMgrApp.exe");
  1156. p.WaitForExit();
  1157. }
  1158. catch (Exception ex)
  1159. {
  1160. log.Error("OTSSysMgrApp:" + ex.ToString());
  1161. }
  1162. }
  1163. private void ribPolygon_Click(object sender, EventArgs e)
  1164. {
  1165. //修改工作样品的测量区域为矩形
  1166. m_SamplepaceWindow.DrawPolygonMeasure();
  1167. }
  1168. private void rbReClassify_Click(object sender, EventArgs e)
  1169. {
  1170. frmReclassifyCondition reCon = new frmReclassifyCondition();
  1171. reCon.ShowDialog();
  1172. this.Cursor = Cursors.WaitCursor;
  1173. if (reCon.DialogResult == DialogResult.OK)
  1174. {
  1175. if (m_ProjRstData.Reclassify(reCon.ignoreUserModify))
  1176. {
  1177. m_ProjRstData.Save();
  1178. MessageBox.Show("reclassification success");
  1179. }
  1180. else
  1181. {
  1182. MessageBox.Show("reclassification failed");
  1183. }
  1184. }
  1185. this.Cursor = Cursors.Default;
  1186. }
  1187. /// <summary>
  1188. /// 打开测量项目文件
  1189. /// </summary>
  1190. private void OpenMeasureProjectFile()
  1191. {
  1192. bool bOpenFlag=false;
  1193. COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();
  1194. string strPathName;
  1195. // file open dialog
  1196. OpenFileDialog openFileDialog = new OpenFileDialog();
  1197. openFileDialog.Filter = "Probject Files (*.prj)|*.prj";
  1198. if (openFileDialog.ShowDialog() != DialogResult.OK)
  1199. {
  1200. return ;
  1201. }
  1202. strPathName = openFileDialog.FileName;
  1203. this.Cursor = Cursors.WaitCursor;
  1204. if (ProjDataMgr.Load(strPathName))
  1205. {
  1206. m_ProjRstData = ProjDataMgr;
  1207. m_ProjParam.SetResultData(m_ProjRstData);
  1208. m_ProjParam.InitResultData();
  1209. bOpenFlag = true;
  1210. }
  1211. this.Cursor = Cursors.Default;
  1212. if (bOpenFlag)
  1213. {
  1214. if (!DisplayExistSampleFile())
  1215. {
  1216. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) OpenExistSampleFile() = false Failed !");
  1217. return;
  1218. }
  1219. SetAllRibbonButnStatus(true);
  1220. }
  1221. else
  1222. {
  1223. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) m_DataMgrFun.OpenExistSampleFile() Failed !");
  1224. }
  1225. }
  1226. private void OTSIncAMeasureAppForm_FormClosed(object sender, FormClosedEventArgs e)
  1227. {
  1228. }
  1229. private void rbAbout_Click(object sender, EventArgs e)
  1230. {
  1231. var SystemType = m_ProjParam.GetDefaultParam().SystemTypeId;
  1232. if (SystemType == OTS_SysType_ID.IncA)
  1233. {
  1234. OTSSplashScreen_IncA m_about = new OTSSplashScreen_IncA();
  1235. m_about.TopMost = false;
  1236. m_about.ShowInTaskbar = true;
  1237. m_about.Show();
  1238. }
  1239. else if (SystemType == OTS_SysType_ID.TCCleannessA|| SystemType == OTS_SysType_ID.BatteryCleannessA)
  1240. {
  1241. OTSSplashScreen_Cleanness m_about = new OTSSplashScreen_Cleanness();
  1242. m_about.TopMost = false;
  1243. m_about.ShowInTaskbar = true;
  1244. m_about.Show();
  1245. }
  1246. else if (SystemType == OTS_SysType_ID.SteelMineral)
  1247. {
  1248. OTSSplashScreen_SteelMineral m_about = new OTSSplashScreen_SteelMineral();
  1249. m_about.TopMost = false;
  1250. m_about.ShowInTaskbar = true;
  1251. m_about.Show();
  1252. }
  1253. }
  1254. protected override void DefWndProc(ref Message m)
  1255. {
  1256. switch (m.Msg)
  1257. {
  1258. case MsgID:
  1259. break;
  1260. case LogMsgID:
  1261. m_LogMsg = new PostLogMsg();
  1262. m_LogMsg = (PostLogMsg)Marshal.PtrToStructure(m.LParam, typeof(PostLogMsg));
  1263. var log = NLog.LogManager.GetCurrentClassLogger();
  1264. string s = GetString(m_LogMsg.logMessage);
  1265. switch (m_LogMsg.logLevel)
  1266. {
  1267. case 1:
  1268. log.Trace(s);
  1269. break;
  1270. case 2:
  1271. log.Debug(s);
  1272. break;
  1273. case 3:
  1274. log.Info(s);
  1275. break;
  1276. case 4:
  1277. log.Warn(s);
  1278. break;
  1279. case 5:
  1280. log.Error(s);
  1281. break;
  1282. case 6:
  1283. log.Fatal(s);
  1284. break;
  1285. }
  1286. break;
  1287. default:
  1288. base.DefWndProc(ref m);
  1289. break;
  1290. }
  1291. }
  1292. private string GetString(char[] csStr)
  1293. {
  1294. int ilen = csStr.Length;
  1295. string csName = new string(csStr); //MSTMsg.STMSampleStu.cSName
  1296. csName.IndexOf('\0');
  1297. csName = csName.Substring(0, csName.IndexOf('\0'));
  1298. return csName;
  1299. }
  1300. private void PrepareIpcServer()
  1301. {
  1302. //Instantiate our server channel.
  1303. IpcServerChannel channel = new IpcServerChannel("ServerChannel");
  1304. //Register the server channel.
  1305. ChannelServices.RegisterChannel(channel, false);
  1306. //Register this service type.
  1307. RemotingConfiguration.RegisterWellKnownServiceType(typeof(IpcSEMController), "RemoteObject", WellKnownObjectMode.Singleton);
  1308. }
  1309. private void rbConnectHardware_Click_1(object sender, EventArgs e)
  1310. {
  1311. if (!m_MsrThreadWrapper.IsSEMConnected())
  1312. {
  1313. if (!m_MsrThreadWrapper.ConnectSEM())
  1314. {
  1315. MessageBox.Show("Connect failed!");
  1316. return;
  1317. }
  1318. }
  1319. this.rbConnectHardware.Enabled = false;
  1320. this.rbDisconnectHardware.Enabled = true;
  1321. log.Warn("SEM connect success!");
  1322. }
  1323. private void rbDisconnectHardware_Click_1(object sender, EventArgs e)
  1324. {
  1325. if (m_MsrThreadWrapper.IsSEMConnected())
  1326. {
  1327. m_MsrThreadWrapper.DisconnectSEM();
  1328. }
  1329. this.rbDisconnectHardware.Enabled = false;
  1330. this.rbConnectHardware.Enabled = true;
  1331. log.Warn("SEM Disconnect!");
  1332. }
  1333. private void rbinterrupt_Click(object sender, EventArgs e)
  1334. {
  1335. if (m_MsrThreadWrapper.IsSEMConnected())
  1336. {
  1337. m_MsrThreadWrapper.StopXrayAcquisition();
  1338. }
  1339. log.Warn("StopXrayAcquisition!");
  1340. }
  1341. private void rbAutoBeamOff_Click(object sender, EventArgs e)
  1342. {
  1343. if (m_ProjRstData.GetGenParam().AutoBeamOff)
  1344. {
  1345. m_ProjRstData.GetGenParam().AutoBeamOff = false;
  1346. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1347. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1348. }
  1349. else
  1350. {
  1351. m_ProjRstData.GetGenParam().AutoBeamOff = true;
  1352. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1353. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1354. }
  1355. }
  1356. private void OTSIncAMeasureAppForm_Activated(object sender, EventArgs e)
  1357. {
  1358. }
  1359. private void ribbonButton2_Click(object sender, EventArgs e)
  1360. {
  1361. frmReclassifyCondition reCon= new frmReclassifyCondition();
  1362. reCon.ShowDialog();
  1363. this.Cursor = Cursors.WaitCursor;
  1364. if (reCon.DialogResult == DialogResult.OK)
  1365. {
  1366. if (m_ProjRstData.Reclassify(reCon.ignoreUserModify))
  1367. {
  1368. m_ProjRstData.Save();
  1369. MessageBox.Show("reclassification success");
  1370. }
  1371. else
  1372. {
  1373. MessageBox.Show("reclassification failed");
  1374. }
  1375. }
  1376. this.Cursor = Cursors.Default;
  1377. }
  1378. private void ribonBtnShot_Click(object sender, EventArgs e)
  1379. {
  1380. m_SamplepaceWindow.DrawOnlyShotMeasure();
  1381. }
  1382. private void ribbonButton4_Click(object sender, EventArgs e)
  1383. {
  1384. m_SamplepaceWindow.DrawRectangleBytTwoPoint();
  1385. }
  1386. }
  1387. }