UControl_Init.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using MeasureData;
  11. using System.Configuration;
  12. using FileManager;
  13. using System.IO;
  14. using System.Runtime.InteropServices;
  15. using System.Diagnostics;
  16. //20201029:注释
  17. //初始化窗口管理的是参数,包括,测量文件使用的参数,配置文件中的参数(默认参数),或者保存成参数文件。
  18. //初始化窗口中显示的参数是测量文件在使用的参数。
  19. //点击确认,对当前修改的参数保存到测量文件中去。
  20. //点击保存默认设置,当前修改的参数保存到AppConfig中,下次打开时作为默认值打开。
  21. //点击保存成配置文件,将以文件的形式将参数保存在文件中
  22. //参数又分为两种类型,客户操作可见的类型,在AppConfig中参数,
  23. //客户操作的参数,可以每次都针对测量进行修改
  24. //这类参数包括:
  25. //是否是倾斜的样品台
  26. //是否仅拍照
  27. //是否使用PT
  28. //PT加工文件
  29. //FIB加工文件
  30. //样品名称
  31. //厂商
  32. //拉直操作的放大倍数
  33. //定位的电压
  34. //定位的放大倍数
  35. //拍照的电压
  36. //拍照的放大倍数
  37. //AppConfig中的参数,通常不需要修改,每次修改要在配置文件中修改,要重新启动程序
  38. //这类参数包括:
  39. //四组对焦参数
  40. //Z轴的移动距离
  41. //各个参数需要有一系列的默认值,并且各个值可以修改,删除
  42. namespace HOZProject
  43. {
  44. public partial class UControl_Init : UserControl
  45. {
  46. #region 成员变量
  47. //可供选择的各个参数的值列表
  48. String[] firms;//厂商列表
  49. //配置文件
  50. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  51. //依附与主工作窗口
  52. private FormHOZMain formHOZMain;
  53. public FormHOZMain FormHOZMainObject { get => formHOZMain; set => formHOZMain = value; }
  54. //模板路径
  55. private string readConfigPath;
  56. public string ReadConfigPath { get => readConfigPath; set => readConfigPath = value; }
  57. //模板文件默认路径
  58. #endregion
  59. #region 构造方法
  60. public UControl_Init(FormHOZMain formHOZ)
  61. {
  62. InitializeComponent();
  63. FormHOZMainObject = formHOZ;
  64. }
  65. #endregion
  66. #region 窗体加载
  67. private void UControl_Init_Load(object sender, EventArgs e)
  68. {
  69. //从配置文件中读取一系列的信息
  70. cbbWYP.Items.Clear();
  71. DirectoryInfo TheFolder = new DirectoryInfo(System.Environment.CurrentDirectory + "\\SampleTemplate");
  72. foreach (FileInfo fi in TheFolder.GetFiles())//遍历文件夹下所有文件
  73. {
  74. cbbWYP.Items.Add(fi.Name);
  75. }
  76. SetTypel();
  77. }
  78. #endregion
  79. #region 关闭窗体
  80. private void btnClose_Click(object sender, EventArgs e)
  81. {
  82. Form fParent = this.ParentForm;
  83. fParent.Close();
  84. }
  85. #endregion
  86. #region 加载切孔文件,生成切孔列表
  87. private void btnCutHoleFile_Click(object sender, EventArgs e)
  88. {
  89. try
  90. {
  91. if (FormHOZMainObject.m_MeasureFile == null)
  92. {
  93. MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  94. }
  95. else
  96. {
  97. if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
  98. {
  99. MessageBox.Show("导入切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  100. }
  101. else
  102. {
  103. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  104. //文件路径
  105. string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
  106. //string CutHoleFilePath = "d://";
  107. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  108. //显示导入的切孔数量
  109. lblCutHoleCount.Text = string.Format("成功导入{0}个切孔", ListCutHole.Count);
  110. tbCutHoleFilePath.Text = CutHoleFilePath;
  111. //保存测量文件
  112. if (Directory.Exists(FormHOZMainObject.m_MeasureFile.FilePath))
  113. {
  114. FormHOZMainObject.m_MeasureFile.Save();
  115. }
  116. }
  117. }
  118. }
  119. catch (Exception ex)
  120. {
  121. NLog.LogManager.GetCurrentClassLogger().Error(ex.Message);
  122. }
  123. }
  124. private void pbCutHoleFile_Click(object sender, EventArgs e)
  125. {
  126. }
  127. #endregion
  128. #region 根据一个切孔文件,自动计算其他切孔信息
  129. /// <summary>
  130. /// 根据一个切孔,自动计算其他切孔信息
  131. /// </summary>
  132. /// <param name="sender"></param>
  133. /// <param name="e"></param>
  134. ///
  135. private void btnCutHoleAuto_Click(object sender, EventArgs e)
  136. {
  137. try
  138. {
  139. if (FormHOZMainObject.m_MeasureFile == null)
  140. {
  141. MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  142. }
  143. else
  144. {
  145. if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
  146. {
  147. MessageBox.Show("导入切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  148. }
  149. else
  150. {
  151. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  152. if (ListCutHole != null)
  153. {
  154. if (ListCutHole.Count > 0)
  155. {
  156. //根据切孔文件的一个切孔,自动计算其他切孔位置
  157. float centerX = 65;
  158. float centerY = 65;
  159. float firstX = ListCutHole[0].Position.X;
  160. float firstY = ListCutHole[0].Position.Y;
  161. //距离
  162. float distance = Convert.ToSingle(config.AppSettings.Settings["distance"].Value.ToString());
  163. //矩阵 4*4
  164. int rag = Convert.ToInt32(config.AppSettings.Settings["rag"].Value.ToString());
  165. List<PointF> cutHolePoint = new List<PointF>();
  166. //根据一个切孔点计算其他切孔信息
  167. cutHolePoint = AnalysisPosition(centerX, centerY, firstX, firstY, distance, rag);
  168. if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromAnalysisPosition(cutHolePoint))
  169. {
  170. MessageBox.Show("生成切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  171. }
  172. else
  173. {
  174. //文件路径
  175. string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
  176. //重新获取切孔列表信息
  177. ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  178. //创建切孔列表信息
  179. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  180. //显示导入的切孔数量
  181. lblCutHoleCount.Text = string.Format("成功生成{0}个切孔", ListCutHole.Count);
  182. tbCutHoleFilePath.Text = CutHoleFilePath;
  183. }
  184. }
  185. }
  186. //保存测量文件
  187. if (FormHOZMainObject.IsSave)
  188. {
  189. FormHOZMainObject.m_MeasureFile.Save();
  190. }
  191. }
  192. }
  193. }
  194. catch (Exception ex)
  195. {
  196. LogManager.LogError(ex.Message);
  197. }
  198. }
  199. private void pbCutHoleAuto_Click(object sender, EventArgs e)
  200. {
  201. }
  202. /// <summary>
  203. /// 分析点坐标
  204. /// </summary>
  205. /// <param name="centerX">中心点X轴坐标</param>
  206. /// <param name="centerY">中心点Y轴坐标</param>
  207. /// <param name="firstX">第一个点X轴坐标</param>
  208. /// <param name="firstY">第一个点Y轴坐标</param>
  209. /// <param name="distance">点与点的距离</param>
  210. /// <param name="rag">行、列数</param>
  211. /// <param name="ptsx">计算生成所有X轴坐标</param>
  212. /// <param name="ptsy">计算生成所有Y轴坐标</param>
  213. public List<PointF> AnalysisPosition(float centerX, float centerY, float firstX, float firstY, float distance, int rag)
  214. {
  215. //求样品1的水平角度
  216. double angle = 0;
  217. //清空所有点信息
  218. List<float> ptsx = new List<float>();
  219. List<float> ptsy = new List<float>();
  220. //将第一个点加入到点信息中
  221. ptsx.Add(firstX);
  222. ptsy.Add(firstY);
  223. //计算第一个点与X轴的交角度数
  224. angle = Math.Atan2(ptsy[0] - centerY, centerX - ptsx[0]) * 180 / Math.PI;
  225. //这里是求与第一个点横向排列的其他点的移动角度
  226. //就是按45度向左向右移动的度
  227. angle = 45 - angle;
  228. angle = angle * Math.PI / 180;
  229. float tx = 0;
  230. float ty = 0;
  231. for (int j = 0; j < rag; j++)
  232. {
  233. //计算每行第一个点的坐标
  234. if (j > 0)
  235. {
  236. tx = (float)(distance * j * Math.Sin(angle));
  237. ty = (float)(distance * j * Math.Cos(angle));
  238. ptsx.Add(tx + ptsx[0]);
  239. ptsy.Add(ptsy[0] - ty);
  240. }
  241. //计算每行其他点的坐标
  242. for (int i = 1; i < rag; i++)
  243. {
  244. tx = (float)(distance * i * Math.Cos(angle));
  245. ty = (float)(distance * i * Math.Sin(angle));
  246. ptsx.Add(tx + ptsx[j * rag]);
  247. ptsy.Add(ty + ptsy[j * rag]);
  248. }
  249. }
  250. List<PointF> pts = new List<PointF>();
  251. for (int i = 0; i < ptsx.Count; i++)
  252. {
  253. //增加的点
  254. PointF pf = new PointF();
  255. pf.X = ptsx[i];
  256. pf.Y = ptsy[i];
  257. pts.Add(pf);
  258. }
  259. return pts;
  260. }
  261. #endregion
  262. #region 加载PT模板文件
  263. private void btnPTTemplateFile_Click(object sender, EventArgs e)
  264. {
  265. string FilePathName;
  266. string fileNameWithoutExtension;
  267. //新建一个文件对话框
  268. OpenFileDialog pOpenFileDialog = new OpenFileDialog();
  269. //设置对话框标题
  270. pOpenFileDialog.Title = "选择模板文件";
  271. //默认目录
  272. pOpenFileDialog.InitialDirectory = FormHOZMainObject.m_MeasureFile.MParam.RemoteHintELYPath;
  273. //设置打开文件类型
  274. pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
  275. ////监测文件是否存在
  276. //pOpenFileDialog.CheckFileExists = true;
  277. //文件打开后执行以下程序
  278. if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
  279. {
  280. FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
  281. fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
  282. this.txtWPTF.Text = FilePathName;
  283. }
  284. }
  285. private void pbTemplateFile_Click(object sender, EventArgs e)
  286. {
  287. }
  288. #endregion
  289. #region 加载FIB模板文件
  290. private void btnFIBTemplateFile_Click(object sender, EventArgs e)
  291. {
  292. string FilePathName;
  293. string fileNameWithoutExtension;
  294. //新建一个文件对话框
  295. OpenFileDialog pOpenFileDialog = new OpenFileDialog();
  296. //设置对话框标题
  297. pOpenFileDialog.Title = "选择模板文件";
  298. //默认目录
  299. pOpenFileDialog.InitialDirectory = FormHOZMainObject.m_MeasureFile.MParam.RemoteMLFPath;
  300. //设置打开文件类型
  301. pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
  302. ////监测文件是否存在
  303. //pOpenFileDialog.CheckFileExists = true;
  304. //文件打开后执行以下程序
  305. if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
  306. {
  307. FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
  308. fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
  309. this.txtWFIBF.Text = FilePathName;
  310. }
  311. }
  312. private void pbFIBTemplateFile_Click(object sender, EventArgs e)
  313. {
  314. }
  315. #endregion
  316. #region 创建与读取样品参数、配置文件
  317. private void btnEditConfig_Click(object sender, EventArgs e)
  318. {
  319. DirectoryInfo TheFolder = new DirectoryInfo(System.Environment.CurrentDirectory + "\\SampleTemplate");
  320. Process pro = Process.Start(@"C:\Windows\notepad.exe", TheFolder.ToString()+ "\\" + cbbWYP.Text);//打开程序B
  321. }
  322. /// <summary>
  323. /// 获取测量参数,初始化窗体中的控件信息
  324. /// </summary>
  325. /// <returns></returns>
  326. public bool GetMeasureParamFromHMI()
  327. {
  328. //从当前界面内获取参数
  329. var m_param = formHOZMain.m_MeasureFile.MParam;
  330. m_param.IfPT = chkWPT.Checked;//是否有PT
  331. // m_param.Tilt = chkWqxkc.Checked;//是否倾斜样品台
  332. //是否仅拍照
  333. if (chkWIsP.Checked == true)
  334. {
  335. m_param.IsTiltCorrectionToRun = false;
  336. m_param.IsStraightenToRun = false;
  337. m_param.IsGetFibPositionToRun = false;
  338. m_param.IsFibCutingToRun = false;
  339. m_param.IsMoveToCenterToRun = false;
  340. m_param.IsShotSectionToRun = true;
  341. m_param.IsEDSToRun = false;
  342. }
  343. if (chkWIsP.Checked)
  344. {
  345. m_param.IfTilt = false;
  346. }else
  347. {
  348. m_param.IfTilt = true; ;
  349. }
  350. m_param.IsEDSToRun = chkEDS.Checked;
  351. m_param.EDSZ = Convert.ToSingle(txtEDSZ.Text) ;
  352. m_param.EDSV = Convert.ToSingle(txtEDSV.Text);
  353. m_param.EDSA = Convert.ToSingle(txtEDSA.Text) ;
  354. m_param.EDSParam.XrayCollectMode = Convert.ToInt16(cboXrayMode.Text);
  355. //自动对焦模式
  356. //cfm.FocusMode = chkManul.Checked;
  357. m_param.RemotePTOriginalEly = txtWPTF.Text;//PT文件路径
  358. m_param.RemoteFIBOriginalEly = txtWFIBF.Text;//FIB文件路径
  359. m_param.ScanRotCor = Convert.ToSingle(txtScanRotCur.Text);
  360. m_param.PixelSizeCor = Convert.ToSingle(txtYPSCur.Text);
  361. m_param.SampleType = cbbWYP.Text;//样品类型
  362. m_param.Firm = cbbWCS.Text;//厂商类型
  363. return true;
  364. }
  365. /// <summary>
  366. /// 编辑confing 文件信息
  367. /// </summary>
  368. public bool SaveParamToConfigfile()
  369. {
  370. try
  371. {
  372. //厂商
  373. List<String> _firms = firms.ToList();
  374. if ((_firms.IndexOf(cbbWCS.Text) < 0)
  375. || (!_firms.Contains(cbbWCS.Text)))
  376. {
  377. _firms.Add(cbbWCS.Text);
  378. string wFirms = string.Join(",", _firms.ToArray());
  379. config.AppSettings.Settings["Firms"].Value = wFirms;
  380. }
  381. var m_Prm = formHOZMain.m_MeasureFile.MParam;
  382. config.AppSettings.Settings["Is_Photograph"].Value = m_Prm.IsShotSectionToRun.ToString();
  383. config.AppSettings.Settings["PT_Depostion"].Value = m_Prm.IfPT.ToString();
  384. config.AppSettings.Settings["PT_ELYFile"].Value = m_Prm.RemotePTOriginalEly;
  385. config.AppSettings.Settings["FIB_ELYFile"].Value = m_Prm.RemoteFIBOriginalEly;
  386. config.AppSettings.Settings["ScanRotCur"].Value = m_Prm.ScanRotCor.ToString();
  387. config.AppSettings.Settings["PixelSize_Y_Cur"].Value = m_Prm.PixelSizeCor.ToString();
  388. config.AppSettings.Settings["LastSampleType"].Value = m_Prm.SampleType;
  389. config.AppSettings.Settings["Is_Title"].Value = m_Prm.IfTilt.ToString();
  390. config.AppSettings.Settings["Is_EDS"].Value = m_Prm.IsEDSToRun.ToString();
  391. config.AppSettings.Settings["EDS_Z"].Value = m_Prm.EDSZ.ToString();
  392. config.AppSettings.Settings["EDS_V"].Value = m_Prm.EDSV.ToString();
  393. config.AppSettings.Settings["EDS_A"].Value = m_Prm.EDSA.ToString();
  394. config.Save(ConfigurationSaveMode.Full);
  395. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  396. return true;
  397. }
  398. catch (Exception ex)
  399. {
  400. LogManager.LogError(ex.Message);
  401. return false;
  402. }
  403. }
  404. /// <summary>
  405. /// 绑定下拉菜单
  406. /// </summary>
  407. /// <param name="cb"></param>
  408. /// <param name="strGroup"></param>
  409. private void BindComboxData(ComboBox cb, string[] strGroup)
  410. {
  411. for (int i = 0; i < strGroup.Length; i++)
  412. {
  413. if (!strGroup[i].Equals(""))
  414. {
  415. cb.Items.Add(strGroup[i]);
  416. }
  417. }
  418. }
  419. /// <summary>
  420. /// 读取Config文件信息
  421. /// </summary>
  422. public void DisplayInitialParam()
  423. {
  424. cbbWYP.Items.Clear();
  425. cbbWCS.Items.Clear();
  426. string firm = config.AppSettings.Settings["Firms"].Value.ToString();
  427. string ScanRotCur = config.AppSettings.Settings["ScanRotCur"].Value.ToString();
  428. txtScanRotCur.Text = ScanRotCur;
  429. txtYPSCur.Text= config.AppSettings.Settings["PixelSize_Y_Cur"].Value.ToString();
  430. //厂商
  431. firms = firm.Split(',');
  432. BindComboxData(cbbWCS, firms);
  433. //设置配置文件默认值
  434. //chkWIsP.Checked=Convert.ToBoolean(config.AppSettings.Settings["Is_Photograph"].Value);
  435. chkWPT.Checked = Convert.ToBoolean(config.AppSettings.Settings["PT_Depostion"].Value);
  436. // chkWqxkc.Checked = Convert.ToBoolean(config.AppSettings.Settings["Is_Title"].Value);
  437. txtWPTF.Text = config.AppSettings.Settings["PT_ELYFile"].Value;
  438. txtWFIBF.Text = config.AppSettings.Settings["FIB_ELYFile"].Value;
  439. cbbWYP.Text = config.AppSettings.Settings["LastSampleType"].Value;
  440. cbbWCS.Text = config.AppSettings.Settings["LastSelectFirm"].Value;
  441. chkEDS.Checked = Convert.ToBoolean(config.AppSettings.Settings["Is_EDS"].Value);
  442. txtEDSZ.Text= Convert.ToString(config.AppSettings.Settings["EDS_Z"].Value);
  443. txtEDSV.Text = Convert.ToString(config.AppSettings.Settings["EDS_V"].Value);
  444. txtEDSA.Text = Convert.ToString(config.AppSettings.Settings["EDS_A"].Value);
  445. cboXrayMode.Text = Convert.ToString(config.AppSettings.Settings["EDS_XrayMode"].Value);
  446. }
  447. /// <summary>
  448. /// 根据所选路径,读取模板文件
  449. /// </summary>
  450. public void ReadConfigInfo()
  451. {
  452. if (!ReadConfigPath.Equals(""))
  453. {
  454. DisplayInitialParam();
  455. ConfigFile cfm = new ConfigFile(FormHOZMainObject.m_MeasureFile.MParam);
  456. cfm.Read(ReadConfigPath);
  457. chkWIsP.Checked = cfm.m_Config.IsShotSectionToRun;
  458. chkWPT.Checked = cfm.m_Config.IfPT;
  459. //自动对焦模式
  460. //cfm.FocusMode = chkManul.Checked;
  461. txtWPTF.Text = cfm.m_Config.RemotePTOriginalEly;
  462. txtWFIBF.Text = cfm.m_Config.RemoteFIBOriginalEly;
  463. cbbWYP.Text = cfm.m_Config.SampleType;
  464. cbbWCS.Text = cfm.m_Config.Firm;
  465. }
  466. }
  467. /// <summary>
  468. /// 修改配置文件默认值
  469. /// </summary>
  470. /// <param name="sender"></param>
  471. /// <param name="e"></param>
  472. private void btnSaveDefalutPara_Click(object sender, EventArgs e)
  473. {
  474. if (chkWPT.Checked)
  475. {
  476. if (txtWPTF.Text == "")
  477. {
  478. MessageBox.Show("PT文件路径不能为空");
  479. return;
  480. }
  481. }
  482. if (txtWFIBF.Text == "")
  483. {
  484. MessageBox.Show("FIB文件路径不能为空");
  485. return;
  486. }
  487. GetMeasureParamFromHMI();
  488. SaveParamToConfigfile();
  489. //获取测量结果文件位置,并保存测量结果文件
  490. if (formHOZMain.m_MeasureFile.SaveAs())
  491. {
  492. //设置已保存状态
  493. formHOZMain.IsSave = true;
  494. }
  495. FormHOZMainObject.m_MeasureFile.IsModified = true;
  496. Form fParent = this.ParentForm;
  497. fParent.Close();
  498. }
  499. #endregion
  500. #region 删除下拉菜单选择项
  501. #endregion
  502. #region 根据是否仅拍照,进行逻辑判断
  503. private void chkWIsP_CheckedChanged(object sender, EventArgs e)
  504. {
  505. if (chkWIsP.Checked)
  506. {
  507. // chkWIsP.Text = "仅SEM拍照(倾斜角度为0)";
  508. // chkWqxkc.Checked = false;
  509. // chkWqxkc.Visible = false;
  510. chkWPT.Checked = false;
  511. chkWPT.Visible = false;
  512. label61.Visible = false;
  513. label59.Visible = false;
  514. txtWFIBF.Visible = false;
  515. txtWPTF.Visible = false;
  516. btnPTTemplateFile.Visible = false;
  517. btnFIBTemplateFile.Visible = false;
  518. //label58.Visible = false;
  519. //cbbWXZ.Visible = false;
  520. chkEDS.Visible = false;
  521. //label18.Visible = false;
  522. //label19.Visible = false;
  523. //txtEDSZ.Visible = false;
  524. //cbbWFIB.Visible = false;
  525. //pbDelWFIB.Visible = false;
  526. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.Photo;
  527. }
  528. else
  529. {
  530. // chkWIsP.Text = "仅SEM拍照";
  531. // chkWqxkc.Visible = true;
  532. chkWPT.Visible = true;
  533. label61.Visible = true;
  534. label59.Visible = true;
  535. txtWFIBF.Visible = true;
  536. txtWPTF.Visible = true;
  537. btnPTTemplateFile.Visible = true;
  538. btnFIBTemplateFile.Visible = true;
  539. //label58.Visible = true;
  540. //cbbWXZ.Visible = true;
  541. chkEDS.Visible = true;
  542. //label2.Visible = true;
  543. //cbbWFIB.Visible = true;
  544. //pbDelWFIB.Visible = true;
  545. //label18.Visible = true;
  546. //label19.Visible = true;
  547. //txtEDSZ.Visible = true;
  548. if (!chkWPT.Checked)
  549. {
  550. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  551. }
  552. }
  553. CreateCutHoleList();
  554. }
  555. #endregion
  556. #region 创建切孔列表
  557. private void CreateCutHoleList()
  558. {
  559. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  560. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  561. }
  562. #endregion
  563. #region 设置流程类型
  564. private void chkWPT_CheckedChanged(object sender, EventArgs e)
  565. {
  566. if (chkWPT.Checked)
  567. {
  568. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.PT;
  569. }
  570. else
  571. {
  572. if (!chkWIsP.Checked)
  573. {
  574. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  575. }
  576. }
  577. CreateCutHoleList();
  578. }
  579. #endregion
  580. #region 关闭按钮 鼠标操作事件
  581. private void pbClose_MouseEnter(object sender, EventArgs e)
  582. {
  583. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  584. }
  585. private void pbClose_MouseLeave(object sender, EventArgs e)
  586. {
  587. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  588. }
  589. #endregion
  590. #region 输入限制只能是数字
  591. private void textBox_KeyPress(string text, object sender, KeyPressEventArgs e)
  592. {
  593. //判断按键是不是要输入的类型。
  594. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
  595. e.Handled = true;
  596. //小数点的处理。
  597. if ((int)e.KeyChar == 46) //小数点
  598. {
  599. if (text.Length <= 0)
  600. e.Handled = true; //小数点不能在第一位
  601. else
  602. {
  603. float f;
  604. float oldf;
  605. bool b1 = false, b2 = false;
  606. b1 = float.TryParse(text, out oldf);
  607. b2 = float.TryParse(text + e.KeyChar.ToString(), out f);
  608. if (b2 == false)
  609. {
  610. if (b1 == true)
  611. e.Handled = true;
  612. else
  613. e.Handled = false;
  614. }
  615. }
  616. }
  617. }
  618. private void ComboBox_KeyPress(string text, object sender, KeyPressEventArgs e)
  619. {
  620. //允许输入数字、小数点、删除键和负号
  621. if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.') && e.KeyChar != (char)('-'))
  622. {
  623. MessageBox.Show("请输入正确的数字");
  624. text = "";
  625. e.Handled = true;
  626. }
  627. if (e.KeyChar == (char)('-'))
  628. {
  629. if (text != "")
  630. {
  631. MessageBox.Show("请输入正确的数字");
  632. text = "";
  633. e.Handled = true;
  634. }
  635. }
  636. //小数点只能输入一次
  637. if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text.IndexOf('.') != -1)
  638. {
  639. MessageBox.Show("请输入正确的数字");
  640. text = "";
  641. e.Handled = true;
  642. }
  643. //第一位不能为小数点
  644. if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text == "")
  645. {
  646. MessageBox.Show("请输入正确的数字");
  647. text = "";
  648. e.Handled = true;
  649. }
  650. //第一位是0,第二位必须为小数点
  651. if (e.KeyChar != (char)('.') && ((ComboBox)sender).Text == "0")
  652. {
  653. MessageBox.Show("请输入正确的数字");
  654. text = "";
  655. e.Handled = true;
  656. }
  657. //第一位是负号,第二位不能为小数点
  658. if (((ComboBox)sender).Text == "-" && e.KeyChar == (char)('.'))
  659. {
  660. MessageBox.Show("请输入正确的数字");
  661. text = "";
  662. e.Handled = true;
  663. }
  664. }
  665. //private void cbbWPZD_KeyPress(object sender, KeyPressEventArgs e)
  666. //{
  667. // ComboBox_KeyPress(cbbWPZD.Text, sender, e);
  668. //}
  669. //private void cbbWPZF_KeyPress(object sender, KeyPressEventArgs e)
  670. //{
  671. // ComboBox_KeyPress(cbbWPZF.Text, sender, e);
  672. //}
  673. //private void cbbWQGD_KeyPress(object sender, KeyPressEventArgs e)
  674. //{
  675. // ComboBox_KeyPress(cbbWQGD.Text, sender, e);
  676. //}
  677. //private void cbbWQGF_KeyPress(object sender, KeyPressEventArgs e)
  678. //{
  679. // ComboBox_KeyPress(cbbWQGF.Text, sender, e);
  680. //}
  681. //private void cbbWLZ_KeyPress(object sender, KeyPressEventArgs e)
  682. //{
  683. // ComboBox_KeyPress(cbbWLZ.Text, sender, e);
  684. //}
  685. #endregion
  686. #region Z轴的保护范围
  687. private void chkWqxkc_CheckedChanged(object sender, EventArgs e)
  688. {
  689. //if (chkWqxkc.Checked)
  690. //{
  691. // label3.Visible = true;
  692. // cbbYDZZDX.Visible = true;
  693. //}
  694. //else
  695. //{
  696. // label3.Visible = false;
  697. // cbbYDZZDX.Visible = false;
  698. //}
  699. }
  700. //private void txtYPSCur_TextChanged(object sender, EventArgs e)
  701. //{
  702. // if (txtYPSCur.Text != "")
  703. // {
  704. // if (Convert.ToSingle(txtYPSCur.Text) > 5)
  705. // {
  706. // MessageBox.Show("数值最大为5");
  707. // txtYPSCur.Text = "5";
  708. // }
  709. // }
  710. // else
  711. // {
  712. // txtYPSCur.Text = "1";
  713. // }
  714. //}
  715. private void txtYPSCur_KeyPress(object sender, KeyPressEventArgs e)
  716. {
  717. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
  718. {
  719. e.Handled = true;
  720. }
  721. }
  722. #endregion
  723. #region 参数确认
  724. private void SaveMeasureFile()
  725. {
  726. //界面上的参数
  727. GetMeasureParamFromHMI();
  728. //配置文件中的参数
  729. //FormHOZMainObject.m_MeasureFile.MParam.ZDistance = Convert.ToSingle(ConfigurationManager.AppSettings["ZDistance"].ToString());
  730. FormHOZMainObject.m_MeasureFile.IsModified = true;
  731. if (Directory.Exists(FormHOZMainObject.m_MeasureFile.FilePath))//如果已经存在硬盘上要重新保存文件
  732. {
  733. FormHOZMainObject.m_MeasureFile.Save();
  734. }
  735. }
  736. private void button1_Click(object sender, EventArgs e)
  737. {
  738. //保存测量文件的参数
  739. SaveMeasureFile();
  740. }
  741. #endregion
  742. private void btnHandSavePoints_Click(object sender, EventArgs e)
  743. {
  744. UserControls.FormExportPoints uCExport = new UserControls.FormExportPoints();
  745. uCExport.ShowDialog();
  746. List<CutHole> ListCutHole = uCExport.ListCutHole;
  747. //文件路径
  748. //string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
  749. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  750. FormHOZMainObject.m_MeasureFile.ListCutHole = ListCutHole;
  751. //显示导入的切孔数量
  752. lblCutHoleCount.Text = string.Format("成功导入{0}个切孔", ListCutHole.Count);
  753. //tbCutHoleFilePath.Text = CutHoleFilePath;
  754. //保存测量文件
  755. if (Directory.Exists(FormHOZMainObject.m_MeasureFile.FilePath))
  756. {
  757. FormHOZMainObject.m_MeasureFile.Save();
  758. }
  759. }
  760. private void cbbWYP_SelectedIndexChanged(object sender, EventArgs e)
  761. {
  762. FormHOZMainObject.m_MeasureFile.MParam.loadParamFromSampleTypeTemplate(cbbWYP.Text);
  763. SetTypel();
  764. }
  765. private void SetTypel()
  766. {
  767. txtVot.Text = FormHOZMainObject.m_MeasureFile.MParam.Voltage.ToString();//电压
  768. txtIprobe.Text = FormHOZMainObject.m_MeasureFile.MParam.Iprobe.ToString();
  769. txtMag1.Text = FormHOZMainObject.m_MeasureFile.MParam.Location_Magnification.ToString();//定位放大倍数
  770. txtMag2.Text = FormHOZMainObject.m_MeasureFile.MParam.Straighten_Magnification.ToString();//拉直放大倍数
  771. txtMag3.Text = FormHOZMainObject.m_MeasureFile.MParam.MoveToCenterMagnification.ToString();
  772. txtMag4.Text = FormHOZMainObject.m_MeasureFile.MParam.Photograph_Magnification.ToString();//拍照放大倍数
  773. }
  774. }
  775. }