OTSIncAMeasureAppForm.cs 60 KB

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