OTSIncAMeasureAppForm.cs 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343
  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. OTSSysMgrTools.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 OTSSysMgrTools.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.m_ResultData;
  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.m_specialRanges.LoadParam();
  112. foreach (var s in this.m_ProjData.GetSampleList())
  113. {
  114. s.GetMsrParams().GetSpecialGrayRangeParam().LoadParam();
  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.m_DefaultParam.m_nPackId == OTS_SysType_ID.IncA)
  133. {
  134. this.Text += "(Inclusion)";
  135. }
  136. else if (m_ProjParam.m_DefaultParam.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 and 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. }
  160. PrepareIpcServer();
  161. }
  162. catch (Exception ex)
  163. {
  164. log.Error(" OTSIncAMeasureAppForm_Load:" + ex.ToString());
  165. }
  166. }
  167. public void ArrangWorkspaceWindow()
  168. {
  169. //Show 样品台窗口
  170. m_SamplepaceWindow.Show(dockPanel);
  171. //Show 测量状态窗口
  172. m_MessureStatuWindow.Show(dockPanel);
  173. //Show 测量结果窗口
  174. m_MeasureRetWindow.Show(dockPanel);
  175. m_SolutionWindows.Show(dockPanel, DockState.DockLeft);
  176. //Show 测量过程中Log显示窗口
  177. m_OTSMeasureOutputNlog.Show(dockPanel, DockState.DockRight);
  178. dockPanel.DockRightPortion = 365;
  179. m_SPropertyWindows.Show(dockPanel);
  180. m_SamplepaceWindow.Activate();
  181. }
  182. private void rbReport_Click(object sender, EventArgs e)
  183. {
  184. //测量结果文件路径列表
  185. List<string> mrFilePathList = new List<string>();
  186. //获取测量结果文件路径列表
  187. bool result = m_ProjParam.GetCompletedMeasureFileName(ref mrFilePathList);
  188. if (result)
  189. {
  190. for (int i = 0; i < mrFilePathList.Count; i++)
  191. {
  192. mrFilePathList[i] = mrFilePathList[i].Replace(" ", "^");
  193. }
  194. //转换为数组
  195. string[] resultFilePath = mrFilePathList.ToArray();
  196. System.Diagnostics.ProcessStartInfo process = new System.Diagnostics.ProcessStartInfo();
  197. process.FileName = "OTSIncAReportApp.exe";//打开app的路径
  198. string FilePath = string.Join(" ", resultFilePath);
  199. process.Arguments = FilePath;//多个参数用空格隔开
  200. process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
  201. System.Diagnostics.Process.Start(process);
  202. }
  203. }
  204. // sNewWorkSampleName: 新工作样品名
  205. public void Rev_SoluWindowReqSwitchWSample_Event(string sNewWorkSampleName)
  206. {
  207. if (!m_ProjParam.SetWorkSample(sNewWorkSampleName))
  208. {
  209. m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(m_ProjParam.GetWorkSampleName());
  210. return;
  211. }
  212. //获取新的样品名称
  213. string sNewName = m_ProjParam.GetWorkSampleName();
  214. if ("" == sNewName)
  215. {
  216. m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(sNewWorkSampleName);
  217. return;
  218. }
  219. //获取新工作样品属性值
  220. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  221. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  222. {
  223. m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(sNewWorkSampleName);
  224. return;
  225. }
  226. //设置获取帧图状态
  227. m_MessageStates = (int)MessageState.StartMeasure;
  228. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  229. //发送新的样品名给Treeview
  230. m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(sNewName);
  231. //发送想你的样品名给Sample
  232. m_SamplepaceWindow.SwitchWorkSample(sNewName);
  233. //根据节点设置样品台窗口中所选择的样品名称
  234. OTSSamplespaceWindow.m_SampleSelectName = sNewName;
  235. }
  236. public void Rev_SoluWindowReqCheckBosStatuChange_Event(string sSampleName, bool bCheckBoxStatu)
  237. {
  238. string sWSampleName = m_ProjParam.GetWorkSampleName();
  239. if ("" == sWSampleName)
  240. {
  241. //不修改Tteeview 的工作样品属性值
  242. m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(sSampleName, !bCheckBoxStatu);
  243. return;
  244. }
  245. //Treeview更改的工作样品数的CHECKBOX 状态
  246. if (!m_ProjParam.SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS.SWITCH, OTS_ITEM_TYPES.BOOL, bCheckBoxStatu))
  247. {
  248. //不修改Tteeview 的工作样品属性值
  249. m_SolutionWindows.Rev_MeasureApp_CheckboxStatuChange_Event(sSampleName, !bCheckBoxStatu);
  250. return;
  251. }
  252. // 设置 开始 ,停止 和检查参数 按钮状态
  253. m_RibbonFun.SetMeasureRibbonButnStatu();
  254. //修改Grid工作样品的SWITCH值
  255. OTSSamplePropertyInfo SMeasurenfo = new OTSSamplePropertyInfo();
  256. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMeasurenfo))
  257. {
  258. return;
  259. }
  260. m_SPropertyWindows.DisplaySampleMeasureInfo(SMeasurenfo);
  261. }
  262. // string sSampleOldName : 样品名原名
  263. //string sSampleNewName : 样品名新名
  264. public bool EditWorkSampleName(string sSampleOldName, string sSampleNewName)
  265. {
  266. if (!m_ProjParam.ChangeWorkSampleName(sSampleNewName))
  267. {
  268. return false;
  269. }
  270. // 获取修改名称后的工作样品属性值
  271. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  272. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  273. {
  274. return false;
  275. }
  276. //获取修改名称后的工作样品属性值发送给Grid显示
  277. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  278. //给样品台发送新的工作样品名称
  279. m_SamplepaceWindow.ChangeWorkSampleName(sSampleNewName);
  280. return true;
  281. }
  282. //OTSSolutionWindow窗口给MeasureApp窗口添加样品请求
  283. public void SoluwindowReqAddSample()
  284. {
  285. //Treeview右键点击添加新样品
  286. this.AddNewSampleMeasure();
  287. }
  288. //移动工作样品到其他样品孔,样品孔名称和测量区域都要改变,重新设置工作样品参数
  289. //SampleMeasurePara SMeasurePara:
  290. public SampleMeasurePara SetWorkSamplHoleAndMeasureArea(SampleMeasurePara SMeasurePara)
  291. {
  292. return m_ProjParam.SetWorkSampleHoleNameAndMeasureArea(SMeasurePara);
  293. }
  294. //当 SampleMeasurePara SetWorkSamplHoleAndMeasureArea(SampleMeasurePara SMeasurePara) 移动成功之后,需要调用此函数更新Grid的显示
  295. public void UpdateTreeSampleAndGridSampleVal()
  296. {
  297. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  298. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  299. {
  300. return;
  301. }
  302. //更新Grid的工作样品属性值
  303. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  304. }
  305. // 更新样品属性值
  306. public void UpDataSamplePropVal()
  307. {
  308. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  309. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  310. {
  311. log.Error("(OTSIncAMeasureAppForm.UpDataSamplePropVal) m_DataMgrFun.GetWorkSamplePropertyVal(m_DataMgrFun.GetWorkSample(), ref SMInfo) = false Failed !");
  312. return;
  313. }
  314. //更新Grid的工作样品属性值
  315. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  316. }
  317. private void OTSIncAMeasureAppForm_FormClosing(object sender, FormClosingEventArgs e)
  318. {
  319. try
  320. {
  321. if (m_MsrThreadWrapper.BGWorkThreadIsRunning ()) //当前正在测量
  322. {
  323. e.Cancel = true;
  324. return;
  325. }
  326. //判断测量结果文件修改后是否保存
  327. if (m_ProjData.IsModified())
  328. {
  329. string message = table["message2"].ToString();
  330. DialogResult lsdr = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
  331. if (lsdr == DialogResult.Yes)
  332. {
  333. //保存,退出
  334. m_ProjData.Save();
  335. //保存,直接退出
  336. Application.ExitThread();
  337. }
  338. else if (lsdr == DialogResult.No)
  339. {
  340. //不保存,直接退出
  341. Application.ExitThread();
  342. }
  343. else if (lsdr == DialogResult.Cancel)
  344. {
  345. //取消
  346. e.Cancel = true;
  347. return;
  348. }
  349. }
  350. log.Info("Disconnect SEM!");
  351. m_MsrThreadWrapper.DisconnectSEM();
  352. m_MsrThreadWrapper.SetWorkThreadPending();
  353. }
  354. catch (Exception ex)
  355. {
  356. string message = table["message3"].ToString();
  357. log.Error("OTSIncAMeasureAppForm_FormClosing-"+ message + ":" + ex.ToString());
  358. }
  359. //CloseAllContents();
  360. //m_MsrThreadWrapper.freeHw();
  361. Process.GetCurrentProcess().Kill();
  362. //Application.ExitThread();
  363. //Application.Exit();
  364. }
  365. //打开指定路径的文件
  366. private void ribbonOrbMenuItem1_OpenWorkspace_Click(object sender, EventArgs e)
  367. {
  368. OpenMeasureProjectFile();
  369. }
  370. //新建样品工作文件
  371. private void ribbonOrbMenuItem3_CreateWorkspace_Click(object sender, EventArgs e)
  372. {
  373. int iCreateNewFileResult = m_ProjParam.CreateNewFile();
  374. if (iCreateNewFileResult == 0)
  375. {
  376. log.Error("(OTSIncAMeasureAppForm.rbNew_CreateWorkspace_Click) m_DataMgrFun.CreateNewFile() Failed !");
  377. return;
  378. }
  379. else if(iCreateNewFileResult == 2)
  380. {
  381. log.Info("(OTSIncAMeasureAppForm.rbNew_CreateWorkspace_Click) m_DataMgrFun.CreateNewFile() Cancel !");
  382. return;
  383. }
  384. m_RibbonFun.SetAllRibbonButnStatus(true);
  385. //清除TREEVIEW和GRID上的显示的已经保存的样品信息
  386. m_SolutionWindows.m_TreeViewBase.DeleteAllTreeNode();
  387. m_SPropertyWindows.m_SampleGrid.HideGrid();
  388. //设置报告按钮
  389. rbPReport.Enabled = false;
  390. rbReport.Enabled = false;
  391. rbReClassify.Enabled = false;
  392. //新建项目时,设置属性窗体中的两个按钮也为不可用状态
  393. m_SPropertyWindows.TSLoad.Enabled = false;
  394. m_SPropertyWindows.TSSaveAs.Enabled = false;
  395. //绘制样品台
  396. m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(), m_ProjData.GetSEMStageData());
  397. //隐藏XrayTable控件
  398. m_MessureStatuWindow.HideXRayTable();
  399. //新建时重新初始化结果窗体结果
  400. m_MeasureRetWindow.SetInit();
  401. }
  402. // 新建样品时提示保存样品信息Messagebox
  403. public int ShowSaveInfoMsgBox()
  404. {
  405. string message = table["message4"].ToString();
  406. // DialogResult.OK
  407. DialogResult dResult = MessageBox.Show(message, "Tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
  408. if (dResult == DialogResult.Yes)
  409. {
  410. return (int)MessageBoxRev.DIALOG_YES;
  411. }
  412. else if (dResult == DialogResult.No)
  413. {
  414. return (int)MessageBoxRev.DIALOG_NO;
  415. }
  416. else
  417. {
  418. return (int)MessageBoxRev.DIALOG_CANCEL;
  419. }
  420. }
  421. //打开已经保存的工作文件
  422. private bool DisplayExistSampleFile()
  423. {
  424. List<CTreeSampleParam> TSampleParamList = new List<CTreeSampleParam>();
  425. List<SampleMeasurePara> SampleMeasureAreaList = new List<SampleMeasurePara>();
  426. int iSampleCount = m_ProjData.GetSampleList().Count;
  427. if (0 == iSampleCount)
  428. {
  429. return false;
  430. }
  431. for (int i = 0; i < iSampleCount; i++)
  432. {
  433. CTreeSampleParam CTSampleParam = new CTreeSampleParam();
  434. COTSSample SampleClr = (m_ProjData.GetSampleList())[i];
  435. CTSampleParam.sSampleTitleName = m_ProjData.GetFileName();
  436. CTSampleParam.sWorkSampleName = SampleClr.GetName();
  437. CTSampleParam.bSwitch = SampleClr.GetSwitch();
  438. CTSampleParam.bParamLock = SampleClr.GetParamLock();
  439. TSampleParamList.Add(CTSampleParam);
  440. }
  441. //获取工作样品
  442. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  443. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.m_ResultData.GetWorkingSample(), ref SMInfo))
  444. {
  445. log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(), ref SMInfo) = false Failed !");
  446. return false;
  447. }
  448. // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息
  449. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  450. // MeasureApp 给 OTSSolutionWindow 发送打开已保存的工作样品文件
  451. m_SolutionWindows.Rev_MeasureApp_OpenExistSampleFile_Event(TSampleParamList, SMInfo.TSampleParam);
  452. //MeasureApp 给 OTSSamplespaceWindow 发送已保存的工作样品文件
  453. if (!OpenExistSampleMeasureArea(ref SampleMeasureAreaList))
  454. {
  455. log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile) m_DataMgrFun.OpenExistSampleMeasureArea(ref SampleMeasureAreaList) = false Failed !");
  456. return false;
  457. }
  458. //打开已保存的样品后,将所有样品发送给样品台
  459. string sWSampleName = m_ProjParam.GetWorkSampleName();
  460. if ("" == sWSampleName)
  461. {
  462. log.Error("(OTSIncAMeasureAppForm.OpenExistSampleFile) m_DataMgrFun.GetWorkSampleName() = null Failed !");
  463. return false;
  464. }
  465. m_SamplepaceWindow.Rev_MeasureApp_OpenExistSampleFile_Event(m_ProjData.GetStage(), m_ProjData.GetSEMStageData(), SampleMeasureAreaList, sWSampleName);
  466. return true;
  467. }
  468. public bool OpenExistSampleMeasureArea(ref List<SampleMeasurePara> SampleMeasureAreaList)
  469. {
  470. int iSListCount = m_ProjData.GetSampleList().Count;
  471. if (0 == iSListCount)
  472. {
  473. return false;
  474. }
  475. for (int i = 0; i < iSListCount; i++)
  476. {
  477. SampleMeasurePara SampleMeasureArea = new SampleMeasurePara();
  478. //获取样品的测量区域信息
  479. //获取样品名称
  480. SampleMeasureArea.sSampleName = (m_ProjData.GetSampleList())[i].GetName();
  481. // 获取测量区域形状
  482. SampleMeasureArea.iShape = (int)(m_ProjData.GetSampleList())[i].GetMsrArea().GetShape();
  483. //获取样品孔名称
  484. SampleMeasureArea.sHoleName = (m_ProjData.GetSampleList())[i].GetSampleHoleName();
  485. //样品测量区域
  486. SampleMeasureArea.MeasureRect = (Rectangle)(m_ProjData.GetSampleList())[i].GetMsrArea().GetRectDomain();
  487. //多边形点集合
  488. SampleMeasureArea.PolygonPointRegion = (m_ProjData.GetSampleList())[i].GetMsrArea().GetPolygonPoint();
  489. List<PointF> PointRegionF = new List<PointF>();
  490. List<Point> PolygonPoint = m_ProjData.GetSampleList()[i].GetMsrArea().GetPolygonPoint();
  491. if (PolygonPoint != null)
  492. {
  493. foreach (var item in m_ProjData.GetSampleList()[i].GetMsrArea().GetPolygonPoint())
  494. {
  495. PointRegionF.Add(new PointF(item.X, item.Y));
  496. }
  497. }
  498. SampleMeasureArea.PolygonPointRegionF = PointRegionF;
  499. SampleMeasureArea.DrawPolygonPointRegionF = PointRegionF;
  500. SampleMeasureAreaList.Add(SampleMeasureArea);
  501. }
  502. return true;
  503. }
  504. //打开指定路径的文件
  505. private void rbOpen_Click(object sender, EventArgs e)
  506. {
  507. OpenMeasureProjectFile();
  508. }
  509. private void rbDeleteSample_Click(object sender, EventArgs e)
  510. {
  511. //删除样品(样品必须先选中)
  512. string sWSampleName = m_ProjParam.GetWorkSampleName();
  513. if ("" == sWSampleName)
  514. {
  515. log.Error("(OTSIncAMeasureAppForm.rbDeleteSample_Click) m_DataMgrFun.GetWorkSampleName() = null Failed");
  516. return;
  517. }
  518. string message = table["message5"].ToString();
  519. string message6 = table["message6"].ToString();
  520. string sDeleteSampleName = message;
  521. sDeleteSampleName += sWSampleName;
  522. sDeleteSampleName += message6;
  523. if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  524. {
  525. //删除样品成功
  526. if (!this.DeleteSample(sWSampleName))
  527. {
  528. log.Error("(OTSIncAMeasureAppForm.rbDeleteSample_Click) DeleteSample(sWSampleName) = false Failed, sWSampleName = " + sWSampleName);
  529. return;
  530. }
  531. //m_MeasureRetWindow.SetInit();
  532. sWSampleName = m_ProjParam.GetWorkSampleName();
  533. if ("" != sWSampleName)
  534. {
  535. m_SolutionWindows.m_TreeViewBase.GetTreeWorkSampleNode(sWSampleName);
  536. m_SolutionWindows.treeView1.Focus();
  537. }
  538. }
  539. }
  540. //返回删除的工作样品名
  541. public bool DeleteSample(string sDeleteWSampleName = "")
  542. {
  543. if (!m_ProjParam.DeleteWorkSample(sDeleteWSampleName))
  544. {
  545. log.Error("(OTSIncAMeasureAppForm.DeleteSample) m_DataMgrFun.DeleteWorkSample(sDeleteWSampleName) Failed, sDeleteWSampleName = " + sDeleteWSampleName);
  546. //return false;
  547. }
  548. // 设置 开始 ,停止 和检查参数 按钮状态
  549. m_RibbonFun.SetMeasureRibbonButnStatu();
  550. //设置 删除,复位,圆形,矩形 按钮状态
  551. m_RibbonFun.SetSampleRibbonButnStatus();
  552. // 更新报告ribbon按钮状态
  553. m_RibbonFun.SetAllRibbonButnStatus(true);
  554. int iSampleCount = m_ProjParam.GetSampleCount();
  555. if (0 == iSampleCount)
  556. {
  557. //给工作样品台发送删除样品和新的工作样品名称
  558. m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName, "");
  559. //清空样品对象列表
  560. if (OTSSamplespaceWindow.m_SampleGDIObjects != null)
  561. {
  562. //清空样品台窗口中样品、测量区域、帧图、照片位置对象列表
  563. OTSSamplespaceWindow.m_SampleGDIObjects.Clear();
  564. OTSSamplespaceWindow.m_MeasureGDIObjects.Clear();
  565. OTSSamplespaceWindow.m_MeasurePathGDIObjects.Clear();
  566. m_SamplepaceWindow.ClearImageAndSingleGDIObjects();
  567. }
  568. //样品全部删除完,将Treeview 和Grid 显示内容清空
  569. m_SPropertyWindows.PropGrid.Hide();
  570. m_SolutionWindows.treeView1.Nodes.Clear();
  571. m_MessureStatuWindow.HideXRayTable();
  572. m_MeasureRetWindow.SetInit();
  573. return true;
  574. }
  575. //获取新工作样品名称
  576. string sNewWSName = m_ProjParam.GetWorkSampleName();
  577. if ("" == sNewWSName)
  578. {
  579. log.Error("(OTSIncAMeasureAppForm.DeleteSample) m_DataMgrFun.GetWorkSampleName() = null Failed");
  580. return true;
  581. }
  582. //获取新的工作样品属性值
  583. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  584. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  585. {
  586. log.Error("(OTSIncAMeasureAppForm.DeleteSample) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(),ref SMInfo) = false Failed");
  587. return false;
  588. }
  589. //给SolutionWindow 发送新的工作样品名称
  590. m_SolutionWindows.Rev_MeasureApp_DeletSample_Event(m_ProjParam.GetWorkSampleName());
  591. //给工作样品台发送删除样品和新的工作样品名称
  592. m_SamplepaceWindow.DeleteWorkSample(sDeleteWSampleName, sNewWSName);
  593. // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息
  594. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  595. return true;
  596. }
  597. private void rbAddSample_Click(object sender, EventArgs e)
  598. {
  599. this.AddNewSampleMeasure();//the system will choose the empty hole one by one according to the holeNo sequence.
  600. }
  601. public void AddNewSampleMeasure(string sSampleHoleName = "")
  602. {
  603. //样品的属性值
  604. OTSSamplePropertyInfo SamplePropParam ;
  605. SamplePropParam = m_ProjParam.AddNewSampleMeasure(sSampleHoleName);
  606. if (null == SamplePropParam)
  607. {
  608. // 设置 开始 ,停止 和检查参数 按钮状态
  609. m_RibbonFun.SetMeasureRibbonButnStatu();
  610. log.Error("(OTSIncAMeasureAppForm.AddNewSample) m_DataMgrFun.AddNewSample(sSampleHoleName) = null ");
  611. return;
  612. }
  613. m_SPropertyWindows.TSSaveAs.Enabled = true;
  614. m_SPropertyWindows.TSLoad.Enabled = true;
  615. //给SampleWindow 发送样品信息
  616. OTSSamplePropertyInfo SMInfo = SamplePropParam;
  617. m_SamplepaceWindow.AddOneSampleArea(SMInfo.SMeasurePara);
  618. //给PropWindow 发送工作样品属性信息
  619. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  620. //给SoluWindow 发送样品显示信息
  621. m_SolutionWindows.AddSampleMeasure(SMInfo.TSampleParam);
  622. // 设置 开始 ,停止 和检查参数 按钮状态
  623. m_RibbonFun.SetMeasureRibbonButnStatu();
  624. //设置 删除,复位,圆形,矩形 按钮状态
  625. m_RibbonFun.SetSampleRibbonButnStatus();
  626. //清空帧图信息
  627. m_MessageStates = (int)MessageState.StartMeasure;
  628. m_SamplepaceWindow.ClearImageAndSingleGDIObjects();
  629. m_SamplepaceWindow.Invalidate();
  630. }
  631. private void rbSelectDlg_Click(object sender, EventArgs e)
  632. {
  633. //判断样品台是否有样品,如果有样品则不能设置默认参数
  634. if (m_ProjParam.GetSampleCount() > 0)
  635. {
  636. MessageBox.Show("Cann't setup preference parameter,for you have added some samples!");
  637. return;
  638. }
  639. ProgMgrInfoForm ProgMgrForm = new ProgMgrInfoForm();
  640. if (DialogResult.OK == ProgMgrForm.ShowDialog())
  641. {
  642. //m_DataMgrFun.SetSysPartSTDData(ProgMgrForm.GetCPartSTDDataClr());
  643. //检查\\Config\\SysData 是否有OTSProgMgrParam.pmf文件
  644. if (m_ProjParam.LoadParamFile() && m_ProjParam.LoadStageParamFile())
  645. {
  646. //检查\\Config\\SysData 是否有OTSProgMgrParam.pmf文件
  647. if (m_ProjParam.InitResultData())
  648. {
  649. m_RibbonFun.SetAllRibbonButnStatus(true);
  650. //当样品台上有样品,则不更新样品台数据
  651. if (0 == m_ProjParam.GetSampleCount())
  652. {
  653. //通过委托事件将样品台数据发送给SamplespaceWindwo
  654. m_SamplepaceWindow.InitStageDisplay(m_ProjData.GetStage(), m_ProjData.GetSEMStageData());
  655. }
  656. }
  657. else
  658. {
  659. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) this.CheckMeasureSysFileExist() = false");
  660. }
  661. }
  662. else
  663. {
  664. log.Error("(OTSIncAMeasureAppForm.rbSelectDlg_Click) (m_DataMgrFun.CheckParamFile() && m_DataMgrFun.CheckStageFile()) = false");
  665. }
  666. }
  667. }
  668. // 主Windows框右下角显示鼠标点的SEM坐标(样品台)
  669. public void ShowSemCoordvAL(string sSemCoord)
  670. {
  671. STSemCoordinate.Text = sSemCoord;
  672. // TSGrayVal.Text = sGrayVal;
  673. statusStrip1.Refresh();
  674. }
  675. //// 主Windows框右下角显示鼠标点的灰度值(测量图)
  676. public void ShowGrayVal(string sGrayVal)
  677. {
  678. TSGrayVal.Text = sGrayVal;
  679. statusStrip1.Refresh();
  680. }
  681. //获取工作样品测量锁
  682. public bool GetWorkSampleParamLock(ref CTreeSampleParam TSParamLock)
  683. {
  684. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  685. if (!m_ProjParam.GetWSampleParaLock(ref SMInfo))
  686. {
  687. return false;
  688. }
  689. TSParamLock = SMInfo.TSampleParam;
  690. return true;
  691. }
  692. /// <summary>
  693. /// 更新属性窗口
  694. /// </summary>
  695. public void UpdatePropertyVal()
  696. {
  697. //获取新的工作样品属性值
  698. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  699. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  700. {
  701. log.Error("(OTSIncAMeasureAppForm.SetSEMData) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(),ref SMInfo) = false Failed");
  702. }
  703. // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息
  704. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  705. }
  706. private void ribbonOrbMenuItemSaveAs_Click(object sender, EventArgs e)
  707. {
  708. bool iRev = m_ProjData.SaveAs();
  709. if (!iRev)
  710. {
  711. //log.Trace("(OTSIncAMeasureAppForm.ribbonOrbMenuItemSaveAs_Click) m_DataMgrFun.SaveAsFile() Failed !");
  712. return;
  713. }
  714. }
  715. private void rbSaveFile_Click(object sender, EventArgs e)
  716. {
  717. bool iRev = m_ProjData.Save();
  718. if (!iRev)
  719. {
  720. //log.Trace("(OTSIncAMeasureAppForm.rbSaveFile_Click) m_DataMgrFun.SaveFile() Failed !");
  721. return;
  722. }
  723. }
  724. private void rbCheckParam_Click(object sender, EventArgs e)
  725. {
  726. //检查样品测量参数
  727. if (m_ProjParam.CheckSampleParam(true))
  728. {
  729. string message = table["message7"].ToString();
  730. MessageBox.Show(message, "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  731. }
  732. }
  733. private void ribReset_Click(object sender, EventArgs e)
  734. {
  735. //调用样品台窗口中的复位方法
  736. m_SamplepaceWindow.ResetWorkSampleMeasure();
  737. }
  738. //绘制圆形测量区域
  739. private void ribCircle_Click(object sender, EventArgs e)
  740. {
  741. //修改工作样品的测量区域为圆形
  742. m_SamplepaceWindow.Rev_DDrawCircleMeasure_MeasureAppToSampleWindow_Event();
  743. }
  744. private void rbThreePoints_Click(object sender, EventArgs e)
  745. {
  746. //修改工作样品的测量区域为圆形
  747. m_SamplepaceWindow.Rev_DDrawCircleMeasureByThreePoints_MeasureAppToSampleWindow_Event();
  748. }
  749. //绘制矩形测量区域
  750. private void ribRectangle_Click(object sender, EventArgs e)
  751. {
  752. //修改工作样品的测量区域为矩形
  753. m_SamplepaceWindow.Rev_DDrawRectangleMeasure_MeasureAppToSampleWindow_Event();
  754. }
  755. private void rbExitApp_Click(object sender, EventArgs e)
  756. {
  757. this.Close();
  758. }
  759. /// <summary>
  760. /// 执行样品孔中照片后台线程
  761. /// </summary>
  762. private void StartSampleHoleImageBGWorkThread()
  763. {
  764. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning())
  765. {
  766. m_MessageStates = MessageState.ShotBSEPicture;
  767. m_MsrThreadWrapper.SetDoRunType((int)MSR_THREAD_RunSTATUS.RUNSampleHoleImage);
  768. m_MsrThreadWrapper.StartBGWorkThread();
  769. m_RibbonFun.SetMeasureRibbonButnStatu();
  770. }
  771. }
  772. private void rbStart_Click(object sender, EventArgs e)
  773. {
  774. if (!m_ProjParam.CheckSampleParam(false))
  775. {
  776. return;
  777. }
  778. if (!m_MsrThreadWrapper.BGWorkThreadIsRunning())
  779. {
  780. //设置消息类型 拍摄样品孔
  781. m_MessageStates = (int)MessageState.StartMeasure;
  782. m_MsrThreadWrapper.SetDoRunType((int)MSR_THREAD_RunSTATUS.RUNMEASURE);
  783. m_MsrThreadWrapper.StartBGWorkThread();
  784. m_RibbonFun.SetMeasureRibbonButnStatu();
  785. }
  786. }
  787. public void SetStartMeasureRibbonStatus()
  788. {
  789. //this.PropertyMeasureThreadRunFlag = true;
  790. ribView.Enabled = false;
  791. m_RibbonFun.SetToolButnStatu(false);
  792. //false: 将其他ribbon按钮设置为灰色
  793. rbPanelFile.Enabled = false;
  794. rbPanelSample.Enabled = false;
  795. m_SolutionWindows.Enabled = false;
  796. m_SPropertyWindows.Enabled = false;
  797. rbStart.Enabled = false;
  798. rbStop.Enabled = true;
  799. rbCheckParam.Enabled = false;
  800. }
  801. private void rbStop_Click(object sender, EventArgs e)
  802. {
  803. //如果当前正在测量,则停止测量线程
  804. if (MeasureThreadRunFlag)
  805. {
  806. //停止测量线程
  807. m_MsrThreadWrapper.SetMeasureThreadStatus(otsdataconst.OTS_MSR_THREAD_STATUS.STOPPED);
  808. }
  809. }
  810. private void rbRuler_Click(object sender, EventArgs e)
  811. {
  812. m_SamplepaceWindow.ShowRulerLocation();
  813. }
  814. private void rbSmapleName_Click(object sender, EventArgs e)
  815. {
  816. m_SamplepaceWindow.ChangeSampleHoleFont();
  817. }
  818. private void rbSmaplePhoto_Click(object sender, EventArgs e)
  819. {
  820. m_SamplepaceWindow.ChangeSampleHoleImage();
  821. }
  822. //当点击Ribbon停止按钮时,设置Ribbon状态
  823. public void SetStopMeasureRibbonStatus()
  824. {
  825. //this.PropertyMeasureThreadRunFlag = false;
  826. ribView.Enabled = true;
  827. m_RibbonFun.SetToolButnStatu(true);
  828. rbPanelFile.Enabled = true;
  829. rbPanelSample.Enabled = true;
  830. m_RibbonFun.SetMeasureRibbonButnStatu();
  831. m_SolutionWindows.Enabled = true;
  832. m_SPropertyWindows.Enabled = true;
  833. rbStart.Enabled = true;
  834. rbStop.Enabled = false;
  835. rbCheckParam.Enabled = true;
  836. }
  837. public bool SwitchMeasureSample(string sMsrSampleName)
  838. {
  839. if (!m_ProjParam.SetWorkSample(sMsrSampleName))
  840. {
  841. log.Error("(OTSIncAMeasureAppForm.SwitchMeasureSample) SetWorkSample(sMsrSampleName =" + sMsrSampleName + ") Failed !");
  842. return false;
  843. }
  844. OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();
  845. if (!m_ProjParam.GetWorkSamplePerameter(m_ProjParam.GetWorkSample(), ref SMInfo))
  846. {
  847. log.Error("(OTSIncAMeasureAppForm.SwitchMeasureSample) m_DataMgrFun.GetSamplePropertyVal(m_DataMgrFun.GetWorkSample(), ref SMInfo) = false Failed !");
  848. return false;
  849. }
  850. // MeasureApp 窗口给 OTSPropertyWindow窗口 Grid显示的样品属性信息
  851. m_SolutionWindows.Rev_MeasureApp_SwitchSample_Event(sMsrSampleName);
  852. m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);
  853. return true;
  854. }
  855. #region 开始获取样品孔中的照片
  856. /// <summary>
  857. /// 开始获取样品孔中的照片
  858. /// </summary>
  859. /// <param name="doRunType"></param>
  860. /// <param name="HoleID"></param>
  861. /// <param name="c_DomainMessure"></param>
  862. public void StartSampleHoleBSEImage(int doRunType, int HoleID, CDomain c_DomainMessure)
  863. {
  864. //线程执行类型 1:测量类型 2:获取样品孔图片类型
  865. m_MsrThreadWrapper.SetDoRunType(doRunType);
  866. //设置获取样品孔中照片所需的参数
  867. m_MsrThreadWrapper.SetHoleImagePreview(HoleID, c_DomainMessure);
  868. StartSampleHoleImageBGWorkThread();
  869. }
  870. #endregion
  871. private void rbRecover_Click(object sender, EventArgs e)
  872. {
  873. //关闭所有内容
  874. CloseAllContents();
  875. //显示样品属性窗口与树结构窗口
  876. m_SolutionWindows.Show(dockPanel, DockState.DockLeft);
  877. m_SPropertyWindows.Show(dockPanel);
  878. //显示样品台窗口 测量状态与测量结果窗口
  879. m_SamplepaceWindow.Show(dockPanel);
  880. m_MessureStatuWindow.Show(dockPanel);
  881. m_MeasureRetWindow.Show(dockPanel);
  882. //此处将在父窗体选项卡上显示
  883. foreach (Form child in this.MdiChildren)
  884. {
  885. if (child.Name == "OTSSamplespaceWindow")
  886. {
  887. child.Activate();
  888. break;
  889. }
  890. }
  891. }
  892. private void CloseAllContents()
  893. {
  894. m_SolutionWindows.DockPanel = null;
  895. m_SPropertyWindows.DockPanel = null;
  896. m_SamplepaceWindow.DockPanel = null;
  897. m_MessureStatuWindow.DockPanel = null;
  898. m_MeasureRetWindow.DockPanel = null;
  899. CloseAllDocuments();
  900. }
  901. private void CloseAllDocuments()
  902. {
  903. if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  904. {
  905. foreach (Form form in MdiChildren)
  906. form.Close();
  907. }
  908. else
  909. {
  910. IDockContent[] documents = dockPanel.DocumentsToArray();
  911. foreach (IDockContent content in documents)
  912. content.DockHandler.Close();
  913. }
  914. }
  915. private void rbMeasureCircle_Click(object sender, EventArgs e)
  916. {
  917. m_ProjParam.SetMeasureAreaShape((int)ShapeType.CIRCUL);
  918. //修改工作样品的测量区域为圆形
  919. m_SamplepaceWindow.changeShape((int)ShapeType.CIRCUL);
  920. }
  921. private void rbMeasureRectangle_Click(object sender, EventArgs e)
  922. {
  923. m_ProjParam.SetMeasureAreaShape((int)ShapeType.RECTANGLE);
  924. //修改工作样品的测量区域为矩形
  925. m_SamplepaceWindow.changeShape((int)ShapeType.RECTANGLE);
  926. }
  927. //ctrl+s组合键进行保存
  928. private void OTSIncAMeasureAppForm_KeyDown(object sender, KeyEventArgs e)
  929. {
  930. if (e.KeyCode == Keys.S && e.Modifiers == Keys.Control)
  931. {
  932. bool iRev = m_ProjData.Save();
  933. if (!iRev)
  934. {
  935. log.Error("(OTSIncAMeasureAppForm.rbSaveFile_Click) m_DataMgrFun.SaveFile() Failed !");
  936. return;
  937. }
  938. log.Error("(OTSIncAMeasureAppForm.rbSaveAs_Click) m_DataMgrFun.SaveFile() Success !");
  939. }
  940. }
  941. private void rbSTDEdit_Click_1(object sender, EventArgs e)
  942. {
  943. OpenFileDialog openFileDialog = new OpenFileDialog();
  944. openFileDialog.Filter = "(*.db)|*.db";
  945. openFileDialog.InitialDirectory = Application.StartupPath + "\\Config\\SysData\\";
  946. openFileDialog.RestoreDirectory = true;
  947. openFileDialog.FilterIndex = 1;
  948. if (openFileDialog.ShowDialog() == DialogResult.OK)
  949. {
  950. try
  951. {
  952. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", openFileDialog.FileName);
  953. p.WaitForExit();
  954. }
  955. catch (Exception ex)
  956. {
  957. log.Error("OTSPartA_STDEditor:" + ex.ToString());
  958. }
  959. }
  960. //reload the setup data just now
  961. foreach (var s in this.m_ProjData.GetSampleList())
  962. {
  963. var stdname= s.GetMsrParams().GetSTDName();
  964. if (stdname != "NoSTD")
  965. {
  966. if (!stdname.Contains(".db"))
  967. {
  968. stdname += ".db";
  969. }
  970. var m_classifyEngine = new COTSClassifyEngineClr(EngineType.ParticleClassifyEng, stdname);
  971. m_classifyEngine.ReloadEngineDB();
  972. }
  973. }
  974. }
  975. private void ribPolygon_Click(object sender, EventArgs e)
  976. {
  977. //修改工作样品的测量区域为矩形
  978. m_SamplepaceWindow.Rev_DDrawPolygonMeasure_MeasureAppToSampleWindow_Event();
  979. }
  980. private void rbReClassify_Click(object sender, EventArgs e)
  981. {
  982. if (m_ProjData.Reclassify())
  983. {
  984. m_ProjData.Save();
  985. MessageBox.Show("reclassification success");
  986. }
  987. else
  988. {
  989. MessageBox.Show("reclassification failed");
  990. }
  991. }
  992. /// <summary>
  993. /// 打开测量项目文件
  994. /// </summary>
  995. private void OpenMeasureProjectFile()
  996. {
  997. bool bOpenFlag=false;
  998. COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();
  999. if (ProjDataMgr.Load())
  1000. {
  1001. m_ProjParam.m_ResultData = ProjDataMgr;
  1002. m_ProjParam.InitResultData();
  1003. m_ProjData = ProjDataMgr;
  1004. bOpenFlag = true;
  1005. }
  1006. if (bOpenFlag)
  1007. {
  1008. if (!DisplayExistSampleFile())
  1009. {
  1010. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) OpenExistSampleFile() = false Failed !");
  1011. return;
  1012. }
  1013. m_RibbonFun.SetAllRibbonButnStatus(true);
  1014. }
  1015. else
  1016. {
  1017. log.Error("(OTSIncAMeasureAppForm.rbOpen_Click) m_DataMgrFun.OpenExistSampleFile() Failed !");
  1018. }
  1019. }
  1020. private void OTSIncAMeasureAppForm_FormClosed(object sender, FormClosedEventArgs e)
  1021. {
  1022. }
  1023. private void rbAbout_Click(object sender, EventArgs e)
  1024. {
  1025. About m_about = new About();
  1026. m_about.ShowDialog();
  1027. }
  1028. private void ribbonOrbRecentItem1_Click(object sender, EventArgs e)
  1029. {
  1030. System.Diagnostics.Process.Start("notepad.exe", CSpecialGrayRangeParam.GetParamFileFullName());
  1031. }
  1032. protected override void DefWndProc(ref Message m)
  1033. {
  1034. switch (m.Msg)
  1035. {
  1036. case MsgID:
  1037. //MSTMsg = new STMrsSampleRetThreadMsg();
  1038. //MSTMsg.STMThreadStu.cMsrStartTime = new char[(int)MEMORY_SIZE.TIME_SIZE];
  1039. //MSTMsg.STMThreadStu.cMsrEndTime = new char[(int)MEMORY_SIZE.TIME_SIZE];
  1040. //MSTMsg.STMSampleRetData.BSEData.FieldPos = new Point();
  1041. //MSTMsg.STMSampleRetData.SFieldata.FieldPos = new Point();
  1042. //MSTMsg.STMSampleRetData.StartMsrField.FieldPos = new Point();
  1043. //MSTMsg.STMSampleStu.cMsrSName = new char[(int)MEMORY_SIZE.SAMPLE_NAME_SIZE];
  1044. //MSTMsg = (STMrsSampleRetThreadMsg)Marshal.PtrToStructure(m.LParam, typeof(STMrsSampleRetThreadMsg));
  1045. ////以下为实时接收图片数据,因为图片传出来的只是指针,所以必须立即接收,否则指针指向的数据就会被析构。
  1046. //Byte[] bBSEData;
  1047. //int iHeight, iWidth;
  1048. //iHeight = MSTMsg.STMSampleRetData.BSEData.iBSEDataHeight;
  1049. //iWidth = MSTMsg.STMSampleRetData.BSEData.iBSEDataWidth;
  1050. //if (iHeight > 0 && iWidth > 0)
  1051. //{
  1052. // bBSEData = new Byte[iHeight * iWidth];
  1053. // Marshal.Copy(MSTMsg.STMSampleRetData.BSEData.pData, bBSEData, 0, iHeight * iWidth);
  1054. // MSTMsg.gbseData = bBSEData;
  1055. //}
  1056. ////申请
  1057. //shareRes.mutex.WaitOne();
  1058. //m_MSTMsg.Add(MSTMsg);
  1059. // 释放
  1060. //shareRes.mutex.ReleaseMutex();
  1061. break;
  1062. case LogMsgID:
  1063. m_LogMsg = new PostLogMsg();
  1064. m_LogMsg = (PostLogMsg)Marshal.PtrToStructure(m.LParam, typeof(PostLogMsg));
  1065. var log = NLog.LogManager.GetCurrentClassLogger();
  1066. string s = GetString(m_LogMsg.logMessage);
  1067. switch (m_LogMsg.logLevel)
  1068. {
  1069. case 1:
  1070. log.Trace(s);
  1071. break;
  1072. case 2:
  1073. log.Debug(s);
  1074. break;
  1075. case 3:
  1076. log.Info(s);
  1077. break;
  1078. case 4:
  1079. log.Warn(s);
  1080. break;
  1081. case 5:
  1082. log.Error(s);
  1083. break;
  1084. case 6:
  1085. log.Fatal(s);
  1086. break;
  1087. }
  1088. break;
  1089. default:
  1090. base.DefWndProc(ref m);
  1091. break;
  1092. }
  1093. }
  1094. private string GetString(char[] csStr)
  1095. {
  1096. int ilen = csStr.Length;
  1097. string csName = new string(csStr); //MSTMsg.STMSampleStu.cSName
  1098. csName.IndexOf('\0');
  1099. csName = csName.Substring(0, csName.IndexOf('\0'));
  1100. return csName;
  1101. }
  1102. private void PrepareIpcServer()
  1103. {
  1104. //Instantiate our server channel.
  1105. IpcServerChannel channel = new IpcServerChannel("ServerChannel");
  1106. //Register the server channel.
  1107. ChannelServices.RegisterChannel(channel, false);
  1108. //Register this service type.
  1109. RemotingConfiguration.RegisterWellKnownServiceType(typeof(IpcSEMController), "RemoteObject", WellKnownObjectMode.Singleton);
  1110. //RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject2), "RemoteObject2", WellKnownObjectMode.Singleton);
  1111. //Console.WriteLine("press return to exit");
  1112. //Console.ReadLine();
  1113. }
  1114. }
  1115. }