OTSIncAMeasureAppForm.cs 50 KB

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