OTSIncAMeasureAppForm.cs 53 KB

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