OTSIncAMeasureAppForm.cs 52 KB

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