OTSIncAMeasureAppForm.cs 53 KB

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