OTSIncAMeasureAppForm.cs 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using OTS.WinFormsUI.Docking;
  6. using System.Runtime.InteropServices;
  7. using System.Collections;
  8. using CefSharp;
  9. using OTSDataType;
  10. using OTSModelSharp;
  11. using OTSModelSharp.ResourceManage;
  12. using static OTSDataType.otsdataconst;
  13. using System.Diagnostics;
  14. using OTSModelSharp.ServiceInterface;
  15. using OTSMeasureApp._0_OTSModel.Measure.ParamData;
  16. using OTSCLRINTERFACE;
  17. using System.IO;
  18. using System.Management;
  19. using System.Xml;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Runtime.Remoting.Channels.Ipc;
  23. using System.Runtime.Remoting.Channels;
  24. using System.Runtime.Remoting;
  25. using OTSMeasureApp.ServiceCenter;
  26. namespace OTSMeasureApp
  27. {
  28. public enum MessageState
  29. {
  30. StartMeasure = 0, //开始测量
  31. ShotBSEPicture = 1, //拍摄样品孔图片
  32. MeasureBSEPicture = 2 //拍摄测量区域图片
  33. };
  34. enum ShapeType
  35. {
  36. CIRCUL = 0, //圆形
  37. RECTANGLE = 1 //矩形
  38. };
  39. enum MessageBoxRev
  40. {
  41. DIALOG_YES = 0,
  42. DIALOG_NO = 1,
  43. DIALOG_CANCEL = 2
  44. }
  45. public partial class OTSIncAMeasureAppForm : Form
  46. {
  47. public static string m_SamplespaceWindowName = "样品台";
  48. public static string m_MeasureStauWindowName = "测量状态";
  49. public static string m_MeasureRetWindowName = "测量结果";
  50. public static string m_NoWindowName = "未知工作窗口";
  51. //国际化
  52. OTSCommon.Language lan;
  53. Hashtable table;
  54. public OTSRibbonFun m_RibbonFun = null;
  55. //判断信息来源 拍摄样品孔图片 或是 测量开始
  56. public MessageState m_MessageStates = (int)MessageState.StartMeasure;
  57. // 初始化日志类
  58. NLog.Logger log ;
  59. private PostLogMsg m_LogMsg;
  60. public const int MsgID = 0x0464;
  61. public const int LogMsgID = 0x0465;
  62. // Control m_ControlWindow = null;
  63. public OTSMeasureResultWindow m_MeasureRetWindow = null;
  64. public OTSMeasureStatusWindow m_MessureStatuWindow = null;
  65. public OTSSamplespaceWindow m_SamplepaceWindow = null;
  66. public OTSMeasureOutputNlog m_OTSMeasureOutputNlog = null;
  67. public COTSMeasureParam m_ProjParam = null;
  68. public COTSMsrPrjResultData m_ProjData;
  69. public OTSSolutionWindow m_SolutionWindows = null;
  70. public OTSPropertyWindow m_SPropertyWindows = null;
  71. //测量线程对象
  72. public CMeasureThreadWrapper m_MsrThreadWrapper = null;
  73. // 测量线程当前状态 True: 正在测量; False: 测量结束
  74. public bool MeasureThreadRunFlag { get => m_MsrThreadWrapper.BGWorkThreadIsRunning(); }
  75. public FileSystemWatcher fileWatcher = new FileSystemWatcher(Application.StartupPath+ @"\Config\SysData");
  76. public OTSIncAMeasureAppForm()
  77. {
  78. InitializeComponent();
  79. //国际化
  80. lan = new OTSCommon.Language(this);
  81. table = lan.GetNameTable(this.Name);
  82. m_SamplespaceWindowName = table["m_samplespacewindowname"].ToString();
  83. m_MeasureStauWindowName = table["m_measurestauwindowname"].ToString();
  84. m_MeasureRetWindowName = table["m_measureretwindowname"].ToString();
  85. m_NoWindowName = table["m_nowindowname"].ToString();
  86. m_OTSMeasureOutputNlog = new OTSMeasureOutputNlog();
  87. m_OTSMeasureOutputNlog.Show();
  88. // 初始化Docpanle
  89. m_SolutionWindows = new OTSSolutionWindow(this);
  90. m_SPropertyWindows = new OTSPropertyWindow(this);
  91. m_MeasureRetWindow = new OTSMeasureResultWindow(this);
  92. m_MeasureRetWindow.Text = m_MeasureRetWindowName;
  93. m_MessureStatuWindow = new OTSMeasureStatusWindow(this);
  94. m_MessureStatuWindow.Text = m_MeasureStauWindowName;
  95. m_SamplepaceWindow = new OTSSamplespaceWindow(this);
  96. m_SamplepaceWindow.Text = m_SamplespaceWindowName;
  97. //和DataMgr进行数据交互类
  98. m_ProjParam = new COTSMeasureParam(this);
  99. m_ProjData = m_ProjParam.GetResultData();
  100. //初始化Ribbon类,操作Ribbon按钮的可用或者不可用
  101. m_RibbonFun = new OTSRibbonFun(this);
  102. //初始化测量线程
  103. m_MsrThreadWrapper = new CMeasureThreadWrapper(this);//must be the last sentence of this procedure.
  104. fileWatcher.Changed += FileWatcher_Changed;
  105. fileWatcher.EnableRaisingEvents=true;
  106. }
  107. private void FileWatcher_Changed(object sender, FileSystemEventArgs e)
  108. {
  109. if (e.Name == "SpecialGrayConfig.xml")
  110. {
  111. m_ProjParam.SpecialRanges.IsInited = false;
  112. foreach (var s in this.m_ProjData.GetSampleList())
  113. {
  114. s.GetMsrParams().GetSpecialGrayRangeParam().IsInited = false;
  115. }
  116. }
  117. }
  118. private void OTSIncAMeasureAppForm_Load(object sender, EventArgs e)
  119. {
  120. try
  121. {
  122. ArrangWorkspaceWindow();
  123. log = NLog.LogManager.GetCurrentClassLogger();
  124. if (m_ProjParam.LoadParamFile() && m_ProjParam.LoadStageParamFile())
  125. {
  126. m_ProjParam.LoadSpecialGrayRangeParamFile();
  127. if (m_ProjParam.InitResultData())
  128. {
  129. m_RibbonFun.SetAllRibbonButnStatus(true);
  130. m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(),m_ProjData.GetSEMStageData());
  131. //添加启动系统界面显示
  132. if (m_ProjParam.GetDefaultParam().m_nPackId == OTS_SysType_ID.IncA)
  133. {
  134. this.Text += "(Inclusion)";
  135. }
  136. else if (m_ProjParam.GetDefaultParam().m_nPackId == OTS_SysType_ID.CleannessA)
  137. {
  138. this.Text += "(Cleanness)";
  139. }
  140. }
  141. else
  142. {
  143. log.Error("(OTSIncAMeasureAppForm.OTSIncAMeasureAppForm_Load) InitResultData() failed");
  144. }
  145. }
  146. else
  147. {
  148. log.Error("(OTSIncAMeasureAppForm.OTSIncAMeasureAppForm_Load) (LoadParamFile() && LoadStageParamFile()) failed");
  149. }
  150. if (!m_MsrThreadWrapper.ConnectSEM())
  151. {
  152. MessageBox.Show("Connect SEM failed!Please goto the SysMgrApp.exe to setup the proper parameter or check other parameter of the EDS software");
  153. System.Diagnostics.ProcessStartInfo process = new System.Diagnostics.ProcessStartInfo();
  154. process.FileName = "OTSSysMgrApp.exe";//打开app的路径
  155. //string FilePath = string.Join(" ",m_ProjData.GetPathName());
  156. //process.Arguments = FilePath;//多个参数用空格隔开
  157. process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
  158. System.Diagnostics.Process.Start(process);
  159. this.rbConnectHardware.Enabled = true;
  160. this.rbDisconnectHardware.Enabled = false;
  161. //this.StatusConnection.Text = "Connect Failed!";
  162. }
  163. this.rbConnectHardware.Enabled = false;
  164. this.rbDisconnectHardware.Enabled = true;
  165. log.Warn("SEM connect success!");
  166. PrepareIpcServer();
  167. log.Info("Ipc server start success!");
  168. }
  169. catch (Exception ex)
  170. {
  171. log.Error(" OTSIncAMeasureAppForm_Load:" + ex.ToString());
  172. }
  173. }
  174. public void ArrangWorkspaceWindow()
  175. {
  176. //Show 样品台窗口
  177. m_SamplepaceWindow.Show(dockPanel);
  178. //Show 测量状态窗口
  179. m_MessureStatuWindow.Show(dockPanel);
  180. //Show 测量结果窗口
  181. m_MeasureRetWindow.Show(dockPanel);
  182. m_SolutionWindows.Show(dockPanel, DockState.DockLeft);
  183. //Show 测量过程中Log显示窗口
  184. m_OTSMeasureOutputNlog.Show(dockPanel, DockState.DockRight);
  185. dockPanel.DockRightPortion = 365;
  186. m_SPropertyWindows.Show(dockPanel);
  187. m_SamplepaceWindow.Activate();
  188. }
  189. private void rbReport_Click(object sender, EventArgs e)
  190. {
  191. //测量结果文件路径列表
  192. List<string> mrFilePathList = new List<string>();
  193. //获取测量结果文件路径列表
  194. bool result = m_ProjParam.GetCompletedMeasureFileName(ref mrFilePathList);
  195. if (result)
  196. {
  197. for (int i = 0; i < mrFilePathList.Count; i++)
  198. {
  199. mrFilePathList[i] = mrFilePathList[i].Replace(" ", "^");
  200. }
  201. //转换为数组
  202. string[] resultFilePath = mrFilePathList.ToArray();
  203. System.Diagnostics.ProcessStartInfo process = new System.Diagnostics.ProcessStartInfo();
  204. process.FileName = "OTSIncAReportApp.exe";//打开app的路径
  205. string FilePath = string.Join(" ", resultFilePath);
  206. process.Arguments = FilePath;//多个参数用空格隔开
  207. process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
  208. System.Diagnostics.Process.Start(process);
  209. }
  210. }
  211. // sNewWorkSampleName: 新工作样品名
  212. public void SwitchWSample(string sNewWorkSampleName)
  213. {
  214. if (!m_ProjParam.SetWorkSample(sNewWorkSampleName))
  215. {
  216. m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(m_ProjParam.GetWorkSampleName());
  217. return;
  218. }
  219. //获取新的样品名称
  220. string sNewName = m_ProjParam.GetWorkSampleName();
  221. if ("" == sNewName)
  222. {
  223. m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(sNewWorkSampleName);
  224. return;
  225. }
  226. //获取新工作样品属性值
  227. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  228. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  229. {
  230. m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(sNewWorkSampleName);
  231. return;
  232. }
  233. //设置获取帧图状态
  234. m_MessageStates = (int)MessageState.StartMeasure;
  235. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  236. //发送新的样品名给Treeview
  237. m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(sNewName);
  238. //发送想你的样品名给Sample
  239. m_SamplepaceWindow.SwitchWorkSample(sNewName);
  240. //根据节点设置样品台窗口中所选择的样品名称
  241. OTSSamplespaceWindow.m_SampleSelectName = sNewName;
  242. }
  243. public void Rev_SoluWindowReqCheckBosStatuChange_Event(string sSampleName, bool bCheckBoxStatu)
  244. {
  245. string sWSampleName = m_ProjParam.GetWorkSampleName();
  246. if ("" == sWSampleName)
  247. {
  248. //不修改Tteeview 的工作样品属性值
  249. m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(sSampleName, !bCheckBoxStatu);
  250. return;
  251. }
  252. //Treeview更改的工作样品数的CHECKBOX 状态
  253. if (!m_ProjParam.SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS.SWITCH, OTS_ITEM_TYPES.BOOL, bCheckBoxStatu))
  254. {
  255. //不修改Tteeview 的工作样品属性值
  256. m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(sSampleName, !bCheckBoxStatu);
  257. return;
  258. }
  259. // 设置 开始 ,停止 和检查参数 按钮状态
  260. m_RibbonFun.SetMeasureRibbonButnStatu();
  261. //修改Grid工作样品的SWITCH值
  262. OTSSamplePropertyInfo SMeasurenfo = new OTSSamplePropertyInfo();
  263. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMeasurenfo))
  264. {
  265. return;
  266. }
  267. m_SPropertyWindows.DisplaySampleMeasureInfo(SMeasurenfo);
  268. }
  269. // string sSampleOldName : 样品名原名
  270. //string sSampleNewName : 样品名新名
  271. public bool EditWorkSampleName(string sSampleOldName, string sSampleNewName)
  272. {
  273. if (!m_ProjParam.ChangeWorkSampleName(sSampleNewName))
  274. {
  275. return false;
  276. }
  277. // 获取修改名称后的工作样品属性值
  278. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  279. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  280. {
  281. return false;
  282. }
  283. //获取修改名称后的工作样品属性值发送给Grid显示
  284. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  285. //给样品台发送新的工作样品名称
  286. m_SamplepaceWindow.ChangeWorkSampleName(sSampleNewName);
  287. return true;
  288. }
  289. //OTSSolutionWindow窗口给MeasureApp窗口添加样品请求
  290. public void SoluwindowReqAddSample()
  291. {
  292. //Treeview右键点击添加新样品
  293. this.AddNewSampleMeasure();
  294. }
  295. //移动工作样品到其他样品孔,样品孔名称和测量区域都要改变,重新设置工作样品参数
  296. //SampleMeasurePara SMeasurePara:
  297. public SampleMeasurePara SetWorkSamplHoleAndMeasureArea(SampleMeasurePara SMeasurePara)
  298. {
  299. return m_ProjParam.SetWorkSampleHoleNameAndMeasureArea(SMeasurePara);
  300. }
  301. //当 SampleMeasurePara SetWorkSamplHoleAndMeasureArea(SampleMeasurePara SMeasurePara) 移动成功之后,需要调用此函数更新Grid的显示
  302. public void UpdateTreeSampleAndGridSampleVal()
  303. {
  304. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  305. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  306. {
  307. return;
  308. }
  309. //更新Grid的工作样品属性值
  310. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  311. }
  312. // 更新样品属性值
  313. public void UpDataSamplePropVal()
  314. {
  315. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  316. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  317. {
  318. log.Error("(OTSIncAMeasureAppForm.UpDataSamplePropVal) m_DataMgrFun.GetWorkSamplePropertyVal(m_DataMgrFun.GetWorkSample(), ref SMInfo) = false Failed !");
  319. return;
  320. }
  321. //更新Grid的工作样品属性值
  322. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  323. }
  324. private void OTSIncAMeasureAppForm_FormClosing(object sender, FormClosingEventArgs e)
  325. {
  326. try
  327. {
  328. if (m_MsrThreadWrapper.BGWorkThreadIsRunning ()) //当前正在测量
  329. {
  330. e.Cancel = true;
  331. return;
  332. }
  333. if (m_MsrThreadWrapper.IsHavingNotCompleteSamples()) //当前正在测量
  334. {
  335. e.Cancel = true;
  336. MessageBox.Show("There is one sample is still in pausing state,please stop it!");
  337. return;
  338. }
  339. //判断测量结果文件修改后是否保存
  340. if (m_ProjData.IsModified())
  341. {
  342. string message = table["message2"].ToString();
  343. DialogResult lsdr = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
  344. if (lsdr == DialogResult.Yes)
  345. {
  346. //保存,退出
  347. m_ProjData.Save();
  348. //保存,直接退出
  349. Application.ExitThread();
  350. }
  351. else if (lsdr == DialogResult.No)
  352. {
  353. //不保存,直接退出
  354. Application.ExitThread();
  355. }
  356. else if (lsdr == DialogResult.Cancel)
  357. {
  358. //取消
  359. e.Cancel = true;
  360. return;
  361. }
  362. }
  363. log.Info("Disconnect SEM!");
  364. m_MsrThreadWrapper.DisconnectSEM();
  365. m_MsrThreadWrapper.SetWorkThreadPending();
  366. }
  367. catch (Exception ex)
  368. {
  369. string message = table["message3"].ToString();
  370. log.Error("OTSIncAMeasureAppForm_FormClosing-"+ message + ":" + ex.ToString());
  371. }
  372. //CloseAllContents();
  373. //m_MsrThreadWrapper.freeHw();
  374. Process.GetCurrentProcess().Kill();
  375. //Application.ExitThread();
  376. //Application.Exit();
  377. }
  378. //打开指定路径的文件
  379. private void ribbonOrbMenuItem1_OpenWorkspace_Click(object sender, EventArgs e)
  380. {
  381. OpenMeasureProjectFile();
  382. }
  383. //新建样品工作文件
  384. private void ribbonOrbMenuItem3_CreateWorkspace_Click(object sender, EventArgs e)
  385. {
  386. int iCreateNewFileResult = m_ProjParam.CreateNewFile();
  387. if (iCreateNewFileResult == 0)
  388. {
  389. log.Error("(OTSIncAMeasureAppForm.rbNew_CreateWorkspace_Click) m_DataMgrFun.CreateNewFile() Failed !");
  390. return;
  391. }
  392. else if(iCreateNewFileResult == 2)
  393. {
  394. log.Info("(OTSIncAMeasureAppForm.rbNew_CreateWorkspace_Click) m_DataMgrFun.CreateNewFile() Cancel !");
  395. return;
  396. }
  397. m_RibbonFun.SetAllRibbonButnStatus(true);
  398. //清除TREEVIEW和GRID上的显示的已经保存的样品信息
  399. m_SolutionWindows.m_TreeViewBase.DeleteAllTreeNode();
  400. m_SPropertyWindows.m_SampleGrid.HideGrid();
  401. //设置报告按钮
  402. rbPReport.Enabled = false;
  403. rbReport.Enabled = false;
  404. rbReClassify.Enabled = true;
  405. //新建项目时,设置属性窗体中的两个按钮也为不可用状态
  406. m_SPropertyWindows.TSLoad.Enabled = false;
  407. m_SPropertyWindows.TSSaveAs.Enabled = false;
  408. //绘制样品台
  409. m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(), m_ProjData.GetSEMStageData());
  410. //隐藏XrayTable控件
  411. m_MessureStatuWindow.HideXRayTable();
  412. //新建时重新初始化结果窗体结果
  413. m_MeasureRetWindow.SetInit();
  414. }
  415. // 新建样品时提示保存样品信息Messagebox
  416. public int ShowSaveInfoMsgBox()
  417. {
  418. string message = table["message4"].ToString();
  419. // DialogResult.OK
  420. DialogResult dResult = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
  421. if (dResult == DialogResult.Yes)
  422. {
  423. return (int)MessageBoxRev.DIALOG_YES;
  424. }
  425. else if (dResult == DialogResult.No)
  426. {
  427. return (int)MessageBoxRev.DIALOG_NO;
  428. }
  429. else
  430. {
  431. return (int)MessageBoxRev.DIALOG_CANCEL;
  432. }
  433. }
  434. //打开已经保存的工作文件
  435. private bool DisplayExistSampleFile()
  436. {
  437. List<CTreeSampleParam> TSampleParamList = new List<CTreeSampleParam>();
  438. List<SampleMeasurePara> SampleMeasureAreaList = new List<SampleMeasurePara>();
  439. int iSampleCount = m_ProjData.GetSampleList().Count;
  440. if (0 == iSampleCount)
  441. {
  442. return false;
  443. }
  444. for (int i = 0; i < iSampleCount; i++)
  445. {
  446. CTreeSampleParam CTSampleParam = new CTreeSampleParam();
  447. COTSSample SampleClr = (m_ProjData.GetSampleList())[i];
  448. CTSampleParam.sSampleTitleName = m_ProjData.GetFileName();
  449. CTSampleParam.sWorkSampleName = SampleClr.GetName();
  450. CTSampleParam.bSwitch = SampleClr.GetSwitch();
  451. CTSampleParam.bParamLock = SampleClr.GetParamLock();
  452. TSampleParamList.Add(CTSampleParam);
  453. }
  454. //获取工作样品
  455. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  456. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetResultData().GetWorkingSample(), ref SMInfo))
  457. {
  458. log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(), ref SMInfo) = false Failed !");
  459. return false;
  460. }
  461. // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息
  462. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  463. // MeasureApp 给 OTSSolutionWindow 发送打开已保存的工作样品文件
  464. m_SolutionWindows.Rev_MeasureApp_OpenExistSampleFile_Event(TSampleParamList, SMInfo.TSampleParam);
  465. //MeasureApp 给 OTSSamplespaceWindow 发送已保存的工作样品文件
  466. if (!OpenExistSampleMeasureArea(ref SampleMeasureAreaList))
  467. {
  468. log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile) m_DataMgrFun.OpenExistSampleMeasureArea(ref SampleMeasureAreaList) = false Failed !");
  469. return false;
  470. }
  471. //打开已保存的样品后,将所有样品发送给样品台
  472. string sWSampleName = m_ProjParam.GetWorkSampleName();
  473. if ("" == sWSampleName)
  474. {
  475. log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile) m_DataMgrFun.GetWorkSampleName() = null Failed !");
  476. return false;
  477. }
  478. m_SamplepaceWindow.OpenExistSampleFile_Event(m_ProjData.GetStage(), m_ProjData.GetSEMStageData(), SampleMeasureAreaList, sWSampleName);
  479. return true;
  480. }
  481. public bool OpenExistSampleMeasureArea(ref List<SampleMeasurePara> SampleMeasureAreaList)
  482. {
  483. int iSListCount = m_ProjData.GetSampleList().Count;
  484. if (0 == iSListCount)
  485. {
  486. return false;
  487. }
  488. for (int i = 0; i < iSListCount; i++)
  489. {
  490. SampleMeasurePara SampleMeasureArea = new SampleMeasurePara();
  491. //获取样品的测量区域信息
  492. //获取样品名称
  493. SampleMeasureArea.sSampleName = (m_ProjData.GetSampleList())[i].GetName();
  494. // 获取测量区域形状
  495. SampleMeasureArea.iShape = (int)(m_ProjData.GetSampleList())[i].GetMsrArea().GetShape();
  496. //获取样品孔名称
  497. SampleMeasureArea.sHoleName = (m_ProjData.GetSampleList())[i].GetSampleHoleName();
  498. //样品测量区域
  499. SampleMeasureArea.MeasureRect = (Rectangle)(m_ProjData.GetSampleList())[i].GetMsrArea().GetRectDomain();
  500. //多边形点集合
  501. SampleMeasureArea.PolygonPointRegion = (m_ProjData.GetSampleList())[i].GetMsrArea().GetPolygonPoint();
  502. List<PointF> PointRegionF = new List<PointF>();
  503. List<Point> PolygonPoint = m_ProjData.GetSampleList()[i].GetMsrArea().GetPolygonPoint();
  504. if (PolygonPoint != null)
  505. {
  506. foreach (var item in m_ProjData.GetSampleList()[i].GetMsrArea().GetPolygonPoint())
  507. {
  508. PointRegionF.Add(new PointF(item.X, item.Y));
  509. }
  510. }
  511. SampleMeasureArea.PolygonPointRegionF = PointRegionF;
  512. SampleMeasureArea.DrawPolygonPointRegionF = PointRegionF;
  513. SampleMeasureAreaList.Add(SampleMeasureArea);
  514. }
  515. return true;
  516. }
  517. //打开指定路径的文件
  518. private void rbOpen_Click(object sender, EventArgs e)
  519. {
  520. OpenMeasureProjectFile();
  521. }
  522. private void rbDeleteSample_Click(object sender, EventArgs e)
  523. {
  524. //删除样品(样品必须先选中)
  525. string sWSampleName = m_ProjParam.GetWorkSampleName();
  526. if ("" == sWSampleName)
  527. {
  528. log.Error("(OTSIncAMeasureAppForm.rbDeleteSample_Click) m_DataMgrFun.GetWorkSampleName() = null Failed");
  529. return;
  530. }
  531. string message = table["message5"].ToString();
  532. string message6 = table["message6"].ToString();
  533. string sDeleteSampleName = message;
  534. sDeleteSampleName += sWSampleName;
  535. sDeleteSampleName += message6;
  536. if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  537. {
  538. //删除样品成功
  539. if (!this.DeleteSample(sWSampleName))
  540. {
  541. log.Error("(OTSIncAMeasureAppForm.rbDeleteSample_Click) DeleteSample(sWSampleName) = false Failed, sWSampleName = " + sWSampleName);
  542. return;
  543. }
  544. //m_MeasureRetWindow.SetInit();
  545. sWSampleName = m_ProjParam.GetWorkSampleName();
  546. if ("" != sWSampleName)
  547. {
  548. m_SolutionWindows.m_TreeViewBase.GetTreeWorkSampleNode(sWSampleName);
  549. m_SolutionWindows.treeView1.Focus();
  550. }
  551. }
  552. }
  553. //返回删除的工作样品名
  554. public bool DeleteSample(string sDeleteWSampleName = "")
  555. {
  556. if (!m_ProjParam.DeleteWorkSample(sDeleteWSampleName))
  557. {
  558. log.Error("(OTSIncAMeasureAppForm.DeleteSample) m_DataMgrFun.DeleteWorkSample(sDeleteWSampleName) Failed, sDeleteWSampleName = " + sDeleteWSampleName);
  559. //return false;
  560. }
  561. // 设置 开始 ,停止 和检查参数 按钮状态
  562. m_RibbonFun.SetMeasureRibbonButnStatu();
  563. //设置 删除,复位,圆形,矩形 按钮状态
  564. m_RibbonFun.SetSampleRibbonButnStatus();
  565. // 更新报告ribbon按钮状态
  566. m_RibbonFun.SetAllRibbonButnStatus(true);
  567. int iSampleCount = m_ProjParam.GetSampleCount();
  568. if (0 == iSampleCount)
  569. {
  570. //给工作样品台发送删除样品和新的工作样品名称
  571. m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName, "");
  572. //清空样品对象列表
  573. if (OTSSamplespaceWindow.m_SampleGDIObjects != null)
  574. {
  575. //清空样品台窗口中样品、测量区域、帧图、照片位置对象列表
  576. OTSSamplespaceWindow.m_SampleGDIObjects.Clear();
  577. OTSSamplespaceWindow.m_MeasureGDIObjects.Clear();
  578. OTSSamplespaceWindow.m_MeasurePathGDIObjects.Clear();
  579. m_SamplepaceWindow.ClearImageAndSingleGDIObjects();
  580. }
  581. //样品全部删除完,将Treeview 和Grid 显示内容清空
  582. m_SPropertyWindows.PropGrid.Hide();
  583. m_SolutionWindows.treeView1.Nodes.Clear();
  584. m_MessureStatuWindow.HideXRayTable();
  585. m_MeasureRetWindow.SetInit();
  586. return true;
  587. }
  588. //获取新工作样品名称
  589. string sNewWSName = m_ProjParam.GetWorkSampleName();
  590. if ("" == sNewWSName)
  591. {
  592. log.Error("(OTSIncAMeasureAppForm.DeleteSample) m_DataMgrFun.GetWorkSampleName() = null Failed");
  593. return true;
  594. }
  595. //获取新的工作样品属性值
  596. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  597. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  598. {
  599. log.Error("(OTSIncAMeasureAppForm.DeleteSample) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(),ref SMInfo) = false Failed");
  600. return false;
  601. }
  602. //给SolutionWindow 发送新的工作样品名称
  603. m_SolutionWindows.Rev_MeasureApp_DeletSample_Event(m_ProjParam.GetWorkSampleName());
  604. //给工作样品台发送删除样品和新的工作样品名称
  605. m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName, sNewWSName);
  606. // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息
  607. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  608. return true;
  609. }
  610. private void rbAddSample_Click(object sender, EventArgs e)
  611. {
  612. this.AddNewSampleMeasure();//the system will choose the empty hole one by one according to the holeNo sequence.
  613. }
  614. public void AddNewSampleMeasure(string sSampleHoleName = "")
  615. {
  616. //样品的属性值
  617. OTSSamplePropertyInfo SamplePropParam ;
  618. SamplePropParam = m_ProjParam.AddNewSampleMeasure(sSampleHoleName);
  619. if (null == SamplePropParam)
  620. {
  621. // 设置 开始 ,停止 和检查参数 按钮状态
  622. m_RibbonFun.SetMeasureRibbonButnStatu();
  623. log.Error("(OTSIncAMeasureAppForm.AddNewSample) m_DataMgrFun.AddNewSample(sSampleHoleName) = null ");
  624. return;
  625. }
  626. m_SPropertyWindows.TSSaveAs.Enabled = true;
  627. m_SPropertyWindows.TSLoad.Enabled = true;
  628. //给SampleWindow 发送样品信息
  629. OTSSamplePropertyInfo SMInfo = SamplePropParam;
  630. m_SamplepaceWindow.AddOneSampleArea(SMInfo.SMeasurePara);
  631. //给PropWindow 发送工作样品属性信息
  632. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  633. //给SoluWindow 发送样品显示信息
  634. m_SolutionWindows.AddSampleMeasure(SMInfo.TSampleParam);
  635. // 设置 开始 ,停止 和检查参数 按钮状态
  636. m_RibbonFun.SetMeasureRibbonButnStatu();
  637. //设置 删除,复位,圆形,矩形 按钮状态
  638. m_RibbonFun.SetSampleRibbonButnStatus();
  639. //清空帧图信息
  640. m_MessageStates = (int)MessageState.StartMeasure;
  641. m_SamplepaceWindow.ClearImageAndSingleGDIObjects();
  642. m_SamplepaceWindow.Invalidate();
  643. }
  644. private void rbSelectDlg_Click(object sender, EventArgs e)
  645. {
  646. //判断样品台是否有样品,如果有样品则不能设置默认参数
  647. if (m_ProjParam.GetSampleCount() > 0)
  648. {
  649. MessageBox.Show("Cann't setup preference parameter,for you have added some samples!");
  650. return;
  651. }
  652. ProgMgrInfoForm ProgMgrForm = new ProgMgrInfoForm();
  653. if (DialogResult.OK == ProgMgrForm.ShowDialog())
  654. {
  655. if (m_ProjParam.LoadParamFile() && m_ProjParam.LoadStageParamFile())
  656. {
  657. if (m_ProjParam.InitResultData())
  658. {
  659. m_RibbonFun.SetAllRibbonButnStatus(true);
  660. //当样品台上有样品,则不更新样品台数据
  661. if (0 == m_ProjParam.GetSampleCount())
  662. {
  663. m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(), m_ProjData.GetSEMStageData());
  664. }
  665. }
  666. else
  667. {
  668. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) this.CheckMeasureSysFileExist() = false");
  669. }
  670. }
  671. else
  672. {
  673. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) (m_DataMgrFun.CheckParamFile() && m_DataMgrFun.CheckStageFile()) = false");
  674. }
  675. }
  676. }
  677. // 主Windows框右下角显示鼠标点的SEM坐标(样品台)
  678. public void ShowSemCoordvAL(string sSemCoord)
  679. {
  680. STSemCoordinate.Text = sSemCoord;
  681. // TSGrayVal.Text = sGrayVal;
  682. statusStrip1.Refresh();
  683. }
  684. //// 主Windows框右下角显示鼠标点的灰度值(测量图)
  685. public void ShowGrayVal(string sGrayVal)
  686. {
  687. TSGrayVal.Text = sGrayVal;
  688. statusStrip1.Refresh();
  689. }
  690. //获取工作样品测量锁
  691. public bool GetWorkSampleParamLock(ref CTreeSampleParam TSParamLock)
  692. {
  693. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  694. if (!m_ProjParam.GetWSampleParaLock(ref SMInfo))
  695. {
  696. return false;
  697. }
  698. TSParamLock = SMInfo.TSampleParam;
  699. return true;
  700. }
  701. /// <summary>
  702. /// 更新属性窗口
  703. /// </summary>
  704. public void UpdatePropertyVal()
  705. {
  706. //获取新的工作样品属性值
  707. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  708. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  709. {
  710. log.Error("(OTSIncAMeasureAppForm.SetSEMData) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(),ref SMInfo) = false Failed");
  711. }
  712. // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息
  713. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  714. }
  715. private void ribbonOrbMenuItemSaveAs_Click(object sender, EventArgs e)
  716. {
  717. bool iRev = m_ProjData.SaveAs();
  718. if (!iRev)
  719. {
  720. return;
  721. }
  722. }
  723. private void rbSaveFile_Click(object sender, EventArgs e)
  724. {
  725. bool iRev = m_ProjData.Save();
  726. if (!iRev)
  727. {
  728. //log.Trace("(OTSIncAMeasureAppForm.rbSaveFile_Click) m_DataMgrFun.SaveFile() Failed !");
  729. return;
  730. }
  731. }
  732. private void rbCheckParam_Click(object sender, EventArgs e)
  733. {
  734. //检查样品测量参数
  735. if (m_ProjParam.CheckSampleParam(true))
  736. {
  737. string message = table["message7"].ToString();
  738. MessageBox.Show(message, "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  739. }
  740. }
  741. private void ribReset_Click(object sender, EventArgs e)
  742. {
  743. //调用样品台窗口中的复位方法
  744. m_SamplepaceWindow.ResetWorkSampleMeasure();
  745. }
  746. //绘制圆形测量区域
  747. private void ribCircle_Click(object sender, EventArgs e)
  748. {
  749. //修改工作样品的测量区域为圆形
  750. m_SamplepaceWindow.Rev_DDrawCircleMeasure_MeasureAppToSampleWindow_Event();
  751. }
  752. private void rbThreePoints_Click(object sender, EventArgs e)
  753. {
  754. //修改工作样品的测量区域为圆形
  755. m_SamplepaceWindow.Rev_DDrawCircleMeasureByThreePoints_MeasureAppToSampleWindow_Event();
  756. }
  757. //绘制矩形测量区域
  758. private void ribRectangle_Click(object sender, EventArgs e)
  759. {
  760. //修改工作样品的测量区域为矩形
  761. m_SamplepaceWindow.Rev_DDrawRectangleMeasure_MeasureAppToSampleWindow_Event();
  762. }
  763. private void rbExitApp_Click(object sender, EventArgs e)
  764. {
  765. this.Close();
  766. }
  767. /// <summary>
  768. /// 执行样品孔中照片后台线程
  769. /// </summary>
  770. private void StartSampleHoleImageBGWorkThread()
  771. {
  772. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning())
  773. {
  774. m_MessageStates = MessageState.ShotBSEPicture;
  775. m_MsrThreadWrapper.SetDoRunType((int)MSR_THREAD_RunSTATUS.RUNSampleHoleImage);
  776. m_MsrThreadWrapper.StartBGWorkThread();
  777. m_RibbonFun.SetMeasureRibbonButnStatu();
  778. }
  779. }
  780. private void rbStart_Click(object sender, EventArgs e)
  781. {
  782. if (!m_ProjParam.CheckSampleParam(false))
  783. {
  784. return;
  785. }
  786. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning())
  787. {
  788. //设置消息类型 拍摄样品孔
  789. m_MessageStates = (int)MessageState.StartMeasure;
  790. m_MsrThreadWrapper.SetDoRunType((int)MSR_THREAD_RunSTATUS.RUNMEASURE);
  791. m_MsrThreadWrapper.StartBGWorkThread();
  792. m_RibbonFun.SetMeasureRibbonButnStatu();
  793. }
  794. else //thread is in pausing state
  795. {
  796. m_MsrThreadWrapper.SetMeasureThreadStatus(OTS_MSR_THREAD_STATUS.INPROCESS);
  797. m_RibbonFun.SetMeasureRibbonButnStatu();
  798. }
  799. }
  800. public void SetStartMeasureRibbonStatus()
  801. {
  802. //this.PropertyMeasureThreadRunFlag = true;
  803. ribView.Enabled = false;
  804. m_RibbonFun.SetToolButnStatu(false);
  805. //false: 将其他ribbon按钮设置为灰色
  806. rbPanelFile.Enabled = false;
  807. rbPanelSample.Enabled = false;
  808. m_SolutionWindows.Enabled = false;
  809. m_SPropertyWindows.Enabled = false;
  810. rbStart.Enabled = false;
  811. rbPause.Enabled = true;
  812. rbStop.Enabled = true;
  813. rbCheckParam.Enabled = false;
  814. }
  815. private void rbStop_Click(object sender, EventArgs e)
  816. {
  817. //如果当前正在测量,则停止测量线程
  818. if (MeasureThreadRunFlag)
  819. {
  820. //停止测量线程
  821. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.STOPPED);
  822. }
  823. else if (m_MsrThreadWrapper.m_MsrThread.GetMsrThreadStatus() .GetStatus()== OTS_MSR_THREAD_STATUS.PAUSED)
  824. {
  825. foreach (KeyValuePair<string, CSmplMeasure> smpl in m_MsrThreadWrapper.m_MsrThread.mapSmplMsr)
  826. {
  827. if (smpl.Value.GetSample().GetMsrStatus().GetStatus() == OTS_MSR_SAMPLE_STATUS.PAUSED)
  828. {
  829. smpl.Value.TheLastWorkOfSampleMeasure();
  830. return;
  831. }
  832. }
  833. }
  834. }
  835. private void rbPause_Click(object sender, EventArgs e)
  836. {
  837. //如果当前正在测量,则停止测量线程
  838. if (MeasureThreadRunFlag)
  839. {
  840. //停止测量线程
  841. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.PAUSED);
  842. }
  843. }
  844. private void rbRuler_Click(object sender, EventArgs e)
  845. {
  846. m_SamplepaceWindow.ShowRulerLocation();
  847. }
  848. private void rbSmapleName_Click(object sender, EventArgs e)
  849. {
  850. m_SamplepaceWindow.ChangeSampleHoleFont();
  851. }
  852. private void rbSmaplePhoto_Click(object sender, EventArgs e)
  853. {
  854. m_SamplepaceWindow.ChangeSampleHoleImage();
  855. }
  856. //当点击Ribbon停止按钮时,设置Ribbon状态
  857. public void SetStopMeasureRibbonStatus()
  858. {
  859. //this.PropertyMeasureThreadRunFlag = false;
  860. ribView.Enabled = true;
  861. m_RibbonFun.SetToolButnStatu(true);
  862. rbPanelFile.Enabled = true;
  863. rbPanelSample.Enabled = true;
  864. m_RibbonFun.SetMeasureRibbonButnStatu();
  865. m_SolutionWindows.Enabled = true;
  866. m_SPropertyWindows.Enabled = true;
  867. rbStart.Enabled = true;
  868. rbPause.Enabled = false;
  869. rbStop.Enabled = false;
  870. rbCheckParam.Enabled = true;
  871. }
  872. public void SetPauseMeasureRibbonStatus()
  873. {
  874. //this.PropertyMeasureThreadRunFlag = false;
  875. ribView.Enabled = true;
  876. m_RibbonFun.SetToolButnStatu(true);
  877. rbPanelFile.Enabled = true;
  878. rbPanelSample.Enabled = true;
  879. m_RibbonFun.SetMeasureRibbonButnStatu();
  880. m_SolutionWindows.Enabled = true;
  881. m_SPropertyWindows.Enabled = true;
  882. rbStart.Enabled = true;
  883. rbPause.Enabled = false;
  884. rbStop.Enabled = true;
  885. rbCheckParam.Enabled = false;
  886. }
  887. public bool SwitchMeasureSample(string sMsrSampleName)
  888. {
  889. if (!m_ProjParam.SetWorkSample(sMsrSampleName))
  890. {
  891. log.Error("(OTSIncAMeasureAppForm.SwitchMeasureSample) SetWorkSample(sMsrSampleName =" + sMsrSampleName + ") Failed !");
  892. return false;
  893. }
  894. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  895. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  896. {
  897. log.Error("(OTSIncAMeasureAppForm.SwitchMeasureSample) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(), ref SMInfo) = false Failed !");
  898. return false;
  899. }
  900. // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息
  901. m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(sMsrSampleName);
  902. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  903. return true;
  904. }
  905. #region 开始获取样品孔中的照片
  906. /// <summary>
  907. /// 开始获取样品孔中的照片
  908. /// </summary>
  909. /// <param name="doRunType"></param>
  910. /// <param name="HoleID"></param>
  911. /// <param name="c_DomainMessure"></param>
  912. public void StartSampleHoleBSEImage(int doRunType, int HoleID, CDomain c_DomainMessure)
  913. {
  914. //线程执行类型 1:测量类型 2:获取样品孔图片类型
  915. m_MsrThreadWrapper.SetDoRunType(doRunType);
  916. //设置获取样品孔中照片所需的参数
  917. m_MsrThreadWrapper.SetHoleImagePreview(HoleID, c_DomainMessure);
  918. StartSampleHoleImageBGWorkThread();
  919. }
  920. #endregion
  921. private void rbRecover_Click(object sender, EventArgs e)
  922. {
  923. //关闭所有内容
  924. CloseAllContents();
  925. //显示样品属性窗口与树结构窗口
  926. m_SolutionWindows.Show(dockPanel, DockState.DockLeft);
  927. m_SPropertyWindows.Show(dockPanel);
  928. //显示样品台窗口 测量状态与测量结果窗口
  929. m_SamplepaceWindow.Show(dockPanel);
  930. m_MessureStatuWindow.Show(dockPanel);
  931. m_MeasureRetWindow.Show(dockPanel);
  932. //此处将在父窗体选项卡上显示
  933. foreach (Form child in this.MdiChildren)
  934. {
  935. if (child.Name == "OTSSamplespaceWindow")
  936. {
  937. child.Activate();
  938. break;
  939. }
  940. }
  941. }
  942. private void CloseAllContents()
  943. {
  944. m_SolutionWindows.DockPanel = null;
  945. m_SPropertyWindows.DockPanel = null;
  946. m_SamplepaceWindow.DockPanel = null;
  947. m_MessureStatuWindow.DockPanel = null;
  948. m_MeasureRetWindow.DockPanel = null;
  949. CloseAllDocuments();
  950. }
  951. private void CloseAllDocuments()
  952. {
  953. if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  954. {
  955. foreach (Form form in MdiChildren)
  956. form.Close();
  957. }
  958. else
  959. {
  960. IDockContent[] documents = dockPanel.DocumentsToArray();
  961. foreach (IDockContent content in documents)
  962. content.DockHandler.Close();
  963. }
  964. }
  965. private void rbMeasureCircle_Click(object sender, EventArgs e)
  966. {
  967. m_ProjParam.SetMeasureAreaShape((int)ShapeType.CIRCUL);
  968. //修改工作样品的测量区域为圆形
  969. m_SamplepaceWindow.changeShape((int)ShapeType.CIRCUL);
  970. }
  971. private void rbMeasureRectangle_Click(object sender, EventArgs e)
  972. {
  973. m_ProjParam.SetMeasureAreaShape((int)ShapeType.RECTANGLE);
  974. //修改工作样品的测量区域为矩形
  975. m_SamplepaceWindow.changeShape((int)ShapeType.RECTANGLE);
  976. }
  977. //ctrl+s组合键进行保存
  978. private void OTSIncAMeasureAppForm_KeyDown(object sender, KeyEventArgs e)
  979. {
  980. if (e.KeyCode == Keys.S && e.Modifiers == Keys.Control)
  981. {
  982. bool iRev = m_ProjData.Save();
  983. if (!iRev)
  984. {
  985. log.Error("(OTSIncAMeasureAppForm.rbSaveFile_Click) m_DataMgrFun.SaveFile() Failed !");
  986. return;
  987. }
  988. log.Error("(OTSIncAMeasureAppForm.rbSaveAs_Click) m_DataMgrFun.SaveFile() Success !");
  989. }
  990. }
  991. private void rbSTDEdit_Click_1(object sender, EventArgs e)
  992. {
  993. OpenFileDialog openFileDialog = new OpenFileDialog();
  994. openFileDialog.Filter = "(*.db)|*.db";
  995. openFileDialog.InitialDirectory = Application.StartupPath + "\\Config\\SysData\\";
  996. openFileDialog.RestoreDirectory = true;
  997. openFileDialog.FilterIndex = 1;
  998. if (openFileDialog.ShowDialog() == DialogResult.OK)
  999. {
  1000. try
  1001. {
  1002. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", openFileDialog.FileName);
  1003. p.WaitForExit();
  1004. }
  1005. catch (Exception ex)
  1006. {
  1007. log.Error("OTSPartA_STDEditor:" + ex.ToString());
  1008. }
  1009. }
  1010. //reload the setup data just now
  1011. foreach (var s in this.m_ProjData.GetSampleList())
  1012. {
  1013. var stdname= s.GetMsrParams().GetSTDName();
  1014. if (stdname != "NoSTD")
  1015. {
  1016. if (!stdname.Contains(".db"))
  1017. {
  1018. stdname += ".db";
  1019. }
  1020. var m_classifyEngine = new COTSClassifyEngineClr(EngineType.ParticleClassifyEng, stdname);
  1021. m_classifyEngine.ReloadEngineDB();
  1022. }
  1023. }
  1024. }
  1025. private void rbSysMgrApp_Click(object sender, EventArgs e)
  1026. {
  1027. try
  1028. {
  1029. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSSysMgrApp.exe");
  1030. p.WaitForExit();
  1031. }
  1032. catch (Exception ex)
  1033. {
  1034. log.Error("OTSSysMgrApp:" + ex.ToString());
  1035. }
  1036. }
  1037. private void ribPolygon_Click(object sender, EventArgs e)
  1038. {
  1039. //修改工作样品的测量区域为矩形
  1040. m_SamplepaceWindow.Rev_DDrawPolygonMeasure_MeasureAppToSampleWindow_Event();
  1041. }
  1042. private void rbReClassify_Click(object sender, EventArgs e)
  1043. {
  1044. if (m_ProjData.Reclassify())
  1045. {
  1046. m_ProjData.Save();
  1047. MessageBox.Show("reclassification success");
  1048. }
  1049. else
  1050. {
  1051. MessageBox.Show("reclassification failed");
  1052. }
  1053. }
  1054. /// <summary>
  1055. /// 打开测量项目文件
  1056. /// </summary>
  1057. private void OpenMeasureProjectFile()
  1058. {
  1059. bool bOpenFlag=false;
  1060. COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();
  1061. if (ProjDataMgr.Load())
  1062. {
  1063. m_ProjData = ProjDataMgr;
  1064. m_ProjParam.SetResultData(m_ProjData);
  1065. m_ProjParam.InitResultData();
  1066. bOpenFlag = true;
  1067. }
  1068. if (bOpenFlag)
  1069. {
  1070. if (!DisplayExistSampleFile())
  1071. {
  1072. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) OpenExistSampleFile() = false Failed !");
  1073. return;
  1074. }
  1075. m_RibbonFun.SetAllRibbonButnStatus(true);
  1076. }
  1077. else
  1078. {
  1079. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) m_DataMgrFun.OpenExistSampleFile() Failed !");
  1080. }
  1081. }
  1082. private void OTSIncAMeasureAppForm_FormClosed(object sender, FormClosedEventArgs e)
  1083. {
  1084. }
  1085. private void rbAbout_Click(object sender, EventArgs e)
  1086. {
  1087. About m_about = new About();
  1088. m_about.ShowDialog();
  1089. }
  1090. protected override void DefWndProc(ref Message m)
  1091. {
  1092. switch (m.Msg)
  1093. {
  1094. case MsgID:
  1095. //MSTMsg = new STMrsSampleRetThreadMsg();
  1096. //MSTMsg.STMThreadStu.cMsrStartTime = new char[(int)MEMORY_SIZE.TIME_SIZE];
  1097. //MSTMsg.STMThreadStu.cMsrEndTime = new char[(int)MEMORY_SIZE.TIME_SIZE];
  1098. //MSTMsg.STMSampleRetData.BSEData.FieldPos = new Point();
  1099. //MSTMsg.STMSampleRetData.SFieldata.FieldPos = new Point();
  1100. //MSTMsg.STMSampleRetData.StartMsrField.FieldPos = new Point();
  1101. //MSTMsg.STMSampleStu.cMsrSName = new char[(int)MEMORY_SIZE.SAMPLE_NAME_SIZE];
  1102. //MSTMsg = (STMrsSampleRetThreadMsg)Marshal.PtrToStructure(m.LParam, typeof(STMrsSampleRetThreadMsg));
  1103. ////以下为实时接收图片数据,因为图片传出来的只是指针,所以必须立即接收,否则指针指向的数据就会被析构。
  1104. //Byte[] bBSEData;
  1105. //int iHeight, iWidth;
  1106. //iHeight = MSTMsg.STMSampleRetData.BSEData.iBSEDataHeight;
  1107. //iWidth = MSTMsg.STMSampleRetData.BSEData.iBSEDataWidth;
  1108. //if (iHeight > 0 && iWidth > 0)
  1109. //{
  1110. // bBSEData = new Byte[iHeight * iWidth];
  1111. // Marshal.Copy(MSTMsg.STMSampleRetData.BSEData.pData, bBSEData, 0, iHeight * iWidth);
  1112. // MSTMsg.gbseData = bBSEData;
  1113. //}
  1114. ////申请
  1115. //shareRes.mutex.WaitOne();
  1116. //m_MSTMsg.Add(MSTMsg);
  1117. // 释放
  1118. //shareRes.mutex.ReleaseMutex();
  1119. break;
  1120. case LogMsgID:
  1121. m_LogMsg = new PostLogMsg();
  1122. m_LogMsg = (PostLogMsg)Marshal.PtrToStructure(m.LParam, typeof(PostLogMsg));
  1123. var log = NLog.LogManager.GetCurrentClassLogger();
  1124. string s = GetString(m_LogMsg.logMessage);
  1125. switch (m_LogMsg.logLevel)
  1126. {
  1127. case 1:
  1128. log.Trace(s);
  1129. break;
  1130. case 2:
  1131. log.Debug(s);
  1132. break;
  1133. case 3:
  1134. log.Info(s);
  1135. break;
  1136. case 4:
  1137. log.Warn(s);
  1138. break;
  1139. case 5:
  1140. log.Error(s);
  1141. break;
  1142. case 6:
  1143. log.Fatal(s);
  1144. break;
  1145. }
  1146. break;
  1147. default:
  1148. base.DefWndProc(ref m);
  1149. break;
  1150. }
  1151. }
  1152. private string GetString(char[] csStr)
  1153. {
  1154. int ilen = csStr.Length;
  1155. string csName = new string(csStr); //MSTMsg.STMSampleStu.cSName
  1156. csName.IndexOf('\0');
  1157. csName = csName.Substring(0, csName.IndexOf('\0'));
  1158. return csName;
  1159. }
  1160. private void PrepareIpcServer()
  1161. {
  1162. //Instantiate our server channel.
  1163. IpcServerChannel channel = new IpcServerChannel("ServerChannel");
  1164. //Register the server channel.
  1165. ChannelServices.RegisterChannel(channel, false);
  1166. //Register this service type.
  1167. RemotingConfiguration.RegisterWellKnownServiceType(typeof(IpcSEMController), "RemoteObject", WellKnownObjectMode.Singleton);
  1168. }
  1169. private void rbConnectHardware_Click_1(object sender, EventArgs e)
  1170. {
  1171. if (!m_MsrThreadWrapper.IsSEMConnected())
  1172. {
  1173. if (!m_MsrThreadWrapper.ConnectSEM())
  1174. {
  1175. MessageBox.Show("Connect failed!");
  1176. return;
  1177. }
  1178. }
  1179. this.rbConnectHardware.Enabled = false;
  1180. this.rbDisconnectHardware.Enabled = true;
  1181. log.Warn("SEM connect success!");
  1182. }
  1183. private void rbDisconnectHardware_Click_1(object sender, EventArgs e)
  1184. {
  1185. if (m_MsrThreadWrapper.IsSEMConnected())
  1186. {
  1187. m_MsrThreadWrapper.DisconnectSEM();
  1188. }
  1189. this.rbDisconnectHardware.Enabled = false;
  1190. this.rbConnectHardware.Enabled = true;
  1191. log.Warn("SEM Disconnect!");
  1192. }
  1193. private void rbinterrupt_Click(object sender, EventArgs e)
  1194. {
  1195. if (m_MsrThreadWrapper.IsSEMConnected())
  1196. {
  1197. m_MsrThreadWrapper.StopXrayAcquisition();
  1198. }
  1199. log.Warn("StopXrayAcquisition!");
  1200. }
  1201. private void rbAutoBeamOff_Click(object sender, EventArgs e)
  1202. {
  1203. if (m_ProjData.GetGenParam().AutoBeamOff)
  1204. {
  1205. m_ProjData.GetGenParam().AutoBeamOff = false;
  1206. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1207. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_off;
  1208. }
  1209. else
  1210. {
  1211. m_ProjData.GetGenParam().AutoBeamOff = true;
  1212. rbAutoBeamOff.Image = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1213. rbAutoBeamOff.SmallImage = global::OTSMeasureApp.Properties.Resources.AutoBeamOff_on;
  1214. }
  1215. }
  1216. }
  1217. }