OTSIncAMeasureAppForm.cs 54 KB

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