UControl_Init.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  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. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  107. //显示导入的切孔数量
  108. lblCutHoleCount.Text = string.Format("成功导入{0}个切孔", ListCutHole.Count);
  109. tbCutHoleFilePath.Text = CutHoleFilePath;
  110. //保存测量文件
  111. if (Directory.Exists(FormHOZMainObject.m_MeasureFile.FilePath))
  112. {
  113. FormHOZMainObject.m_MeasureFile.Save();
  114. }
  115. }
  116. }
  117. }
  118. catch (Exception ex)
  119. {
  120. NLog.LogManager.GetCurrentClassLogger().Error(ex.Message);
  121. }
  122. }
  123. private void pbCutHoleFile_Click(object sender, EventArgs e)
  124. {
  125. }
  126. #endregion
  127. #region 根据一个切孔文件,自动计算其他切孔信息
  128. /// <summary>
  129. /// 根据一个切孔,自动计算其他切孔信息
  130. /// </summary>
  131. /// <param name="sender"></param>
  132. /// <param name="e"></param>
  133. ///
  134. private void btnCutHoleAuto_Click(object sender, EventArgs e)
  135. {
  136. try
  137. {
  138. if (FormHOZMainObject.m_MeasureFile == null)
  139. {
  140. MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  141. }
  142. else
  143. {
  144. if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
  145. {
  146. MessageBox.Show("导入切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  147. }
  148. else
  149. {
  150. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  151. if (ListCutHole != null)
  152. {
  153. if (ListCutHole.Count > 0)
  154. {
  155. //根据切孔文件的一个切孔,自动计算其他切孔位置
  156. float centerX = 65;
  157. float centerY = 65;
  158. float firstX = ListCutHole[0].Position.X;
  159. float firstY = ListCutHole[0].Position.Y;
  160. //距离
  161. float distance = Convert.ToSingle(config.AppSettings.Settings["distance"].Value.ToString());
  162. //矩阵 4*4
  163. int rag = Convert.ToInt32(config.AppSettings.Settings["rag"].Value.ToString());
  164. List<PointF> cutHolePoint = new List<PointF>();
  165. //根据一个切孔点计算其他切孔信息
  166. cutHolePoint = AnalysisPosition(centerX, centerY, firstX, firstY, distance, rag);
  167. if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromAnalysisPosition(cutHolePoint))
  168. {
  169. MessageBox.Show("生成切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  170. }
  171. else
  172. {
  173. //文件路径
  174. string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
  175. //重新获取切孔列表信息
  176. ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  177. //创建切孔列表信息
  178. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  179. //显示导入的切孔数量
  180. lblCutHoleCount.Text = string.Format("成功生成{0}个切孔", ListCutHole.Count);
  181. tbCutHoleFilePath.Text = CutHoleFilePath;
  182. }
  183. }
  184. }
  185. //保存测量文件
  186. if (FormHOZMainObject.IsSave)
  187. {
  188. FormHOZMainObject.m_MeasureFile.Save();
  189. }
  190. }
  191. }
  192. }
  193. catch (Exception ex)
  194. {
  195. LogManager.LogError(ex.Message);
  196. }
  197. }
  198. private void pbCutHoleAuto_Click(object sender, EventArgs e)
  199. {
  200. }
  201. /// <summary>
  202. /// 分析点坐标
  203. /// </summary>
  204. /// <param name="centerX">中心点X轴坐标</param>
  205. /// <param name="centerY">中心点Y轴坐标</param>
  206. /// <param name="firstX">第一个点X轴坐标</param>
  207. /// <param name="firstY">第一个点Y轴坐标</param>
  208. /// <param name="distance">点与点的距离</param>
  209. /// <param name="rag">行、列数</param>
  210. /// <param name="ptsx">计算生成所有X轴坐标</param>
  211. /// <param name="ptsy">计算生成所有Y轴坐标</param>
  212. public List<PointF> AnalysisPosition(float centerX, float centerY, float firstX, float firstY, float distance, int rag)
  213. {
  214. //求样品1的水平角度
  215. double angle = 0;
  216. //清空所有点信息
  217. List<float> ptsx = new List<float>();
  218. List<float> ptsy = new List<float>();
  219. //将第一个点加入到点信息中
  220. ptsx.Add(firstX);
  221. ptsy.Add(firstY);
  222. //计算第一个点与X轴的交角度数
  223. angle = Math.Atan2(ptsy[0] - centerY, centerX - ptsx[0]) * 180 / Math.PI;
  224. //这里是求与第一个点横向排列的其他点的移动角度
  225. //就是按45度向左向右移动的度
  226. angle = 45 - angle;
  227. angle = angle * Math.PI / 180;
  228. float tx = 0;
  229. float ty = 0;
  230. for (int j = 0; j < rag; j++)
  231. {
  232. //计算每行第一个点的坐标
  233. if (j > 0)
  234. {
  235. tx = (float)(distance * j * Math.Sin(angle));
  236. ty = (float)(distance * j * Math.Cos(angle));
  237. ptsx.Add(tx + ptsx[0]);
  238. ptsy.Add(ptsy[0] - ty);
  239. }
  240. //计算每行其他点的坐标
  241. for (int i = 1; i < rag; i++)
  242. {
  243. tx = (float)(distance * i * Math.Cos(angle));
  244. ty = (float)(distance * i * Math.Sin(angle));
  245. ptsx.Add(tx + ptsx[j * rag]);
  246. ptsy.Add(ty + ptsy[j * rag]);
  247. }
  248. }
  249. List<PointF> pts = new List<PointF>();
  250. for (int i = 0; i < ptsx.Count; i++)
  251. {
  252. //增加的点
  253. PointF pf = new PointF();
  254. pf.X = ptsx[i];
  255. pf.Y = ptsy[i];
  256. pts.Add(pf);
  257. }
  258. return pts;
  259. }
  260. #endregion
  261. #region 加载PT模板文件
  262. private void btnPTTemplateFile_Click(object sender, EventArgs e)
  263. {
  264. string FilePathName;
  265. string fileNameWithoutExtension;
  266. //新建一个文件对话框
  267. OpenFileDialog pOpenFileDialog = new OpenFileDialog();
  268. //设置对话框标题
  269. pOpenFileDialog.Title = "选择模板文件";
  270. //默认目录
  271. pOpenFileDialog.InitialDirectory= @"\\192.168.1.101\fib auto\FIB Recipe\";
  272. //设置打开文件类型
  273. pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
  274. ////监测文件是否存在
  275. //pOpenFileDialog.CheckFileExists = true;
  276. //文件打开后执行以下程序
  277. if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
  278. {
  279. FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
  280. fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
  281. this.txtWPTF.Text = FilePathName;
  282. }
  283. }
  284. private void pbTemplateFile_Click(object sender, EventArgs e)
  285. {
  286. }
  287. #endregion
  288. #region 加载FIB模板文件
  289. private void btnFIBTemplateFile_Click(object sender, EventArgs e)
  290. {
  291. string FilePathName;
  292. string fileNameWithoutExtension;
  293. //新建一个文件对话框
  294. OpenFileDialog pOpenFileDialog = new OpenFileDialog();
  295. //设置对话框标题
  296. pOpenFileDialog.Title = "选择模板文件";
  297. //默认目录
  298. pOpenFileDialog.InitialDirectory = @"\\192.168.1.101\fib auto\FIB Recipe\";
  299. //设置打开文件类型
  300. pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
  301. ////监测文件是否存在
  302. //pOpenFileDialog.CheckFileExists = true;
  303. //文件打开后执行以下程序
  304. if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
  305. {
  306. FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
  307. fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
  308. this.txtWFIBF.Text = FilePathName;
  309. }
  310. }
  311. private void pbFIBTemplateFile_Click(object sender, EventArgs e)
  312. {
  313. }
  314. #endregion
  315. #region 创建与读取样品参数、配置文件
  316. private void btnEditConfig_Click(object sender, EventArgs e)
  317. {
  318. DirectoryInfo TheFolder = new DirectoryInfo(System.Environment.CurrentDirectory + "\\SampleTemplate");
  319. Process pro = Process.Start(@"C:\Windows\notepad.exe", TheFolder.ToString()+ "\\" + cbbWYP.Text);//打开程序B
  320. }
  321. /// <summary>
  322. /// 获取测量参数,初始化窗体中的控件信息
  323. /// </summary>
  324. /// <returns></returns>
  325. public bool GetMeasureParamFromHMI()
  326. {
  327. //从当前界面内获取参数
  328. var m_param = formHOZMain.m_MeasureFile.MParam;
  329. m_param.Is_Photograph = chkWIsP.Checked;//是否仅拍照
  330. m_param.PT = chkWPT.Checked;//是否有PT
  331. // m_param.Tilt = chkWqxkc.Checked;//是否倾斜样品台
  332. if (chkWIsP.Checked)
  333. {
  334. m_param.Tilt = false;
  335. }else
  336. {
  337. m_param.Tilt = true; ;
  338. }
  339. m_param.EDS = chkEDS.Checked;
  340. m_param.EDSZ = Convert.ToSingle(txtEDSZ.Text) ;
  341. m_param.EDSV = Convert.ToSingle(txtEDSV.Text);
  342. m_param.EDSA = Convert.ToSingle(txtEDSA.Text) ;
  343. m_param.EDSParam.XrayCollectMode = Convert.ToInt16(cboXrayMode.Text);
  344. //自动对焦模式
  345. //cfm.FocusMode = chkManul.Checked;
  346. m_param.PTTemp = txtWPTF.Text;//PT文件路径
  347. m_param.FIBTemp = txtWFIBF.Text;//FIB文件路径
  348. m_param.ScanRotCor = Convert.ToSingle(txtScanRotCur.Text);
  349. m_param.PixelSizeCor = Convert.ToSingle(txtYPSCur.Text);
  350. m_param.SampleType = cbbWYP.Text;//样品类型
  351. m_param.Firm = cbbWCS.Text;//厂商类型
  352. return true;
  353. }
  354. /// <summary>
  355. /// 编辑confing 文件信息
  356. /// </summary>
  357. public bool SaveParamToConfigfile()
  358. {
  359. try
  360. {
  361. //厂商
  362. List<String> _firms = firms.ToList();
  363. if ((_firms.IndexOf(cbbWCS.Text) < 0)
  364. || (!_firms.Contains(cbbWCS.Text)))
  365. {
  366. _firms.Add(cbbWCS.Text);
  367. string wFirms = string.Join(",", _firms.ToArray());
  368. config.AppSettings.Settings["Firms"].Value = wFirms;
  369. }
  370. var m_Prm = formHOZMain.m_MeasureFile.MParam;
  371. config.AppSettings.Settings["Is_Photograph"].Value = m_Prm.Is_Photograph.ToString();
  372. config.AppSettings.Settings["PT_Depostion"].Value = m_Prm.PT.ToString();
  373. config.AppSettings.Settings["PT_ELYFile"].Value = m_Prm.PTTemp;
  374. config.AppSettings.Settings["FIB_ELYFile"].Value = m_Prm.FIBTemp;
  375. config.AppSettings.Settings["ScanRotCur"].Value = m_Prm.ScanRotCor.ToString();
  376. config.AppSettings.Settings["PixelSize_Y_Cur"].Value = m_Prm.PixelSizeCor.ToString();
  377. config.AppSettings.Settings["LastSampleType"].Value = m_Prm.SampleType;
  378. config.AppSettings.Settings["Is_Title"].Value = m_Prm.Tilt.ToString();
  379. config.AppSettings.Settings["Is_EDS"].Value = m_Prm.EDS.ToString();
  380. config.AppSettings.Settings["EDS_Z"].Value = m_Prm.EDSZ.ToString();
  381. config.AppSettings.Settings["EDS_V"].Value = m_Prm.EDSV.ToString();
  382. config.AppSettings.Settings["EDS_A"].Value = m_Prm.EDSA.ToString();
  383. config.Save(ConfigurationSaveMode.Full);
  384. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  385. return true;
  386. }
  387. catch (Exception ex)
  388. {
  389. LogManager.LogError(ex.Message);
  390. return false;
  391. }
  392. }
  393. /// <summary>
  394. /// 绑定下拉菜单
  395. /// </summary>
  396. /// <param name="cb"></param>
  397. /// <param name="strGroup"></param>
  398. private void BindComboxData(ComboBox cb, string[] strGroup)
  399. {
  400. for (int i = 0; i < strGroup.Length; i++)
  401. {
  402. if (!strGroup[i].Equals(""))
  403. {
  404. cb.Items.Add(strGroup[i]);
  405. }
  406. }
  407. }
  408. /// <summary>
  409. /// 读取Config文件信息
  410. /// </summary>
  411. public void DisplayInitialParam()
  412. {
  413. cbbWYP.Items.Clear();
  414. cbbWCS.Items.Clear();
  415. string firm = config.AppSettings.Settings["Firms"].Value.ToString();
  416. string ScanRotCur = config.AppSettings.Settings["ScanRotCur"].Value.ToString();
  417. txtScanRotCur.Text = ScanRotCur;
  418. txtYPSCur.Text= config.AppSettings.Settings["PixelSize_Y_Cur"].Value.ToString();
  419. //厂商
  420. firms = firm.Split(',');
  421. BindComboxData(cbbWCS, firms);
  422. //设置配置文件默认值
  423. chkWIsP.Checked=Convert.ToBoolean(config.AppSettings.Settings["Is_Photograph"].Value);
  424. chkWPT.Checked = Convert.ToBoolean(config.AppSettings.Settings["PT_Depostion"].Value);
  425. // chkWqxkc.Checked = Convert.ToBoolean(config.AppSettings.Settings["Is_Title"].Value);
  426. txtWPTF.Text = config.AppSettings.Settings["PT_ELYFile"].Value;
  427. txtWFIBF.Text = config.AppSettings.Settings["FIB_ELYFile"].Value;
  428. cbbWYP.Text = config.AppSettings.Settings["LastSampleType"].Value;
  429. cbbWCS.Text = config.AppSettings.Settings["LastSelectFirm"].Value;
  430. chkEDS.Checked = Convert.ToBoolean(config.AppSettings.Settings["Is_EDS"].Value);
  431. txtEDSZ.Text= Convert.ToString(config.AppSettings.Settings["EDS_Z"].Value);
  432. txtEDSV.Text = Convert.ToString(config.AppSettings.Settings["EDS_V"].Value);
  433. txtEDSA.Text = Convert.ToString(config.AppSettings.Settings["EDS_A"].Value);
  434. cboXrayMode.Text = Convert.ToString(config.AppSettings.Settings["EDS_XrayMode"].Value);
  435. }
  436. /// <summary>
  437. /// 根据所选路径,读取模板文件
  438. /// </summary>
  439. public void ReadConfigInfo()
  440. {
  441. if (!ReadConfigPath.Equals(""))
  442. {
  443. DisplayInitialParam();
  444. ConfigFile cfm = new ConfigFile(FormHOZMainObject.m_MeasureFile.MParam);
  445. cfm.Read(ReadConfigPath);
  446. chkWIsP.Checked = cfm.m_Config.Is_Photograph;
  447. chkWPT.Checked = cfm.m_Config.PT;
  448. //自动对焦模式
  449. //cfm.FocusMode = chkManul.Checked;
  450. txtWPTF.Text = cfm.m_Config.PTTemp;
  451. txtWFIBF.Text = cfm.m_Config.FIBTemp;
  452. cbbWYP.Text = cfm.m_Config.SampleType;
  453. cbbWCS.Text = cfm.m_Config.Firm;
  454. }
  455. }
  456. /// <summary>
  457. /// 修改配置文件默认值
  458. /// </summary>
  459. /// <param name="sender"></param>
  460. /// <param name="e"></param>
  461. private void btnSaveDefalutPara_Click(object sender, EventArgs e)
  462. {
  463. if (chkWPT.Checked)
  464. {
  465. if (txtWPTF.Text == "")
  466. {
  467. MessageBox.Show("PT文件路径不能为空");
  468. return;
  469. }
  470. }
  471. if (txtWFIBF.Text == "")
  472. {
  473. MessageBox.Show("FIB文件路径不能为空");
  474. return;
  475. }
  476. GetMeasureParamFromHMI();
  477. SaveParamToConfigfile();
  478. //获取测量结果文件位置,并保存测量结果文件
  479. if (formHOZMain.m_MeasureFile.SaveAs())
  480. {
  481. //设置已保存状态
  482. formHOZMain.IsSave = true;
  483. }
  484. FormHOZMainObject.m_MeasureFile.IsModified = true;
  485. Form fParent = this.ParentForm;
  486. fParent.Close();
  487. }
  488. #endregion
  489. #region 删除下拉菜单选择项
  490. #endregion
  491. #region 根据是否仅拍照,进行逻辑判断
  492. private void chkWIsP_CheckedChanged(object sender, EventArgs e)
  493. {
  494. if (chkWIsP.Checked)
  495. {
  496. // chkWIsP.Text = "仅SEM拍照(倾斜角度为0)";
  497. // chkWqxkc.Checked = false;
  498. // chkWqxkc.Visible = false;
  499. chkWPT.Checked = false;
  500. chkWPT.Visible = false;
  501. label61.Visible = false;
  502. label59.Visible = false;
  503. txtWFIBF.Visible = false;
  504. txtWPTF.Visible = false;
  505. btnPTTemplateFile.Visible = false;
  506. btnFIBTemplateFile.Visible = false;
  507. //label58.Visible = false;
  508. //cbbWXZ.Visible = false;
  509. chkEDS.Visible = false;
  510. //label18.Visible = false;
  511. //label19.Visible = false;
  512. //txtEDSZ.Visible = false;
  513. //cbbWFIB.Visible = false;
  514. //pbDelWFIB.Visible = false;
  515. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.Photo;
  516. }
  517. else
  518. {
  519. // chkWIsP.Text = "仅SEM拍照";
  520. // chkWqxkc.Visible = true;
  521. chkWPT.Visible = true;
  522. label61.Visible = true;
  523. label59.Visible = true;
  524. txtWFIBF.Visible = true;
  525. txtWPTF.Visible = true;
  526. btnPTTemplateFile.Visible = true;
  527. btnFIBTemplateFile.Visible = true;
  528. //label58.Visible = true;
  529. //cbbWXZ.Visible = true;
  530. chkEDS.Visible = true;
  531. //label2.Visible = true;
  532. //cbbWFIB.Visible = true;
  533. //pbDelWFIB.Visible = true;
  534. //label18.Visible = true;
  535. //label19.Visible = true;
  536. //txtEDSZ.Visible = true;
  537. if (!chkWPT.Checked)
  538. {
  539. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  540. }
  541. }
  542. CreateCutHoleList();
  543. }
  544. #endregion
  545. #region 创建切孔列表
  546. private void CreateCutHoleList()
  547. {
  548. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  549. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  550. }
  551. #endregion
  552. #region 设置流程类型
  553. private void chkWPT_CheckedChanged(object sender, EventArgs e)
  554. {
  555. if (chkWPT.Checked)
  556. {
  557. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.PT;
  558. }
  559. else
  560. {
  561. if (!chkWIsP.Checked)
  562. {
  563. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  564. }
  565. }
  566. CreateCutHoleList();
  567. }
  568. #endregion
  569. #region 关闭按钮 鼠标操作事件
  570. private void pbClose_MouseEnter(object sender, EventArgs e)
  571. {
  572. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  573. }
  574. private void pbClose_MouseLeave(object sender, EventArgs e)
  575. {
  576. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  577. }
  578. #endregion
  579. #region 输入限制只能是数字
  580. private void textBox_KeyPress(string text, object sender, KeyPressEventArgs e)
  581. {
  582. //判断按键是不是要输入的类型。
  583. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
  584. e.Handled = true;
  585. //小数点的处理。
  586. if ((int)e.KeyChar == 46) //小数点
  587. {
  588. if (text.Length <= 0)
  589. e.Handled = true; //小数点不能在第一位
  590. else
  591. {
  592. float f;
  593. float oldf;
  594. bool b1 = false, b2 = false;
  595. b1 = float.TryParse(text, out oldf);
  596. b2 = float.TryParse(text + e.KeyChar.ToString(), out f);
  597. if (b2 == false)
  598. {
  599. if (b1 == true)
  600. e.Handled = true;
  601. else
  602. e.Handled = false;
  603. }
  604. }
  605. }
  606. }
  607. private void ComboBox_KeyPress(string text, object sender, KeyPressEventArgs e)
  608. {
  609. //允许输入数字、小数点、删除键和负号
  610. if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.') && e.KeyChar != (char)('-'))
  611. {
  612. MessageBox.Show("请输入正确的数字");
  613. text = "";
  614. e.Handled = true;
  615. }
  616. if (e.KeyChar == (char)('-'))
  617. {
  618. if (text != "")
  619. {
  620. MessageBox.Show("请输入正确的数字");
  621. text = "";
  622. e.Handled = true;
  623. }
  624. }
  625. //小数点只能输入一次
  626. if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text.IndexOf('.') != -1)
  627. {
  628. MessageBox.Show("请输入正确的数字");
  629. text = "";
  630. e.Handled = true;
  631. }
  632. //第一位不能为小数点
  633. if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text == "")
  634. {
  635. MessageBox.Show("请输入正确的数字");
  636. text = "";
  637. e.Handled = true;
  638. }
  639. //第一位是0,第二位必须为小数点
  640. if (e.KeyChar != (char)('.') && ((ComboBox)sender).Text == "0")
  641. {
  642. MessageBox.Show("请输入正确的数字");
  643. text = "";
  644. e.Handled = true;
  645. }
  646. //第一位是负号,第二位不能为小数点
  647. if (((ComboBox)sender).Text == "-" && e.KeyChar == (char)('.'))
  648. {
  649. MessageBox.Show("请输入正确的数字");
  650. text = "";
  651. e.Handled = true;
  652. }
  653. }
  654. //private void cbbWPZD_KeyPress(object sender, KeyPressEventArgs e)
  655. //{
  656. // ComboBox_KeyPress(cbbWPZD.Text, sender, e);
  657. //}
  658. //private void cbbWPZF_KeyPress(object sender, KeyPressEventArgs e)
  659. //{
  660. // ComboBox_KeyPress(cbbWPZF.Text, sender, e);
  661. //}
  662. //private void cbbWQGD_KeyPress(object sender, KeyPressEventArgs e)
  663. //{
  664. // ComboBox_KeyPress(cbbWQGD.Text, sender, e);
  665. //}
  666. //private void cbbWQGF_KeyPress(object sender, KeyPressEventArgs e)
  667. //{
  668. // ComboBox_KeyPress(cbbWQGF.Text, sender, e);
  669. //}
  670. //private void cbbWLZ_KeyPress(object sender, KeyPressEventArgs e)
  671. //{
  672. // ComboBox_KeyPress(cbbWLZ.Text, sender, e);
  673. //}
  674. #endregion
  675. #region Z轴的保护范围
  676. private void chkWqxkc_CheckedChanged(object sender, EventArgs e)
  677. {
  678. //if (chkWqxkc.Checked)
  679. //{
  680. // label3.Visible = true;
  681. // cbbYDZZDX.Visible = true;
  682. //}
  683. //else
  684. //{
  685. // label3.Visible = false;
  686. // cbbYDZZDX.Visible = false;
  687. //}
  688. }
  689. //private void txtYPSCur_TextChanged(object sender, EventArgs e)
  690. //{
  691. // if (txtYPSCur.Text != "")
  692. // {
  693. // if (Convert.ToSingle(txtYPSCur.Text) > 5)
  694. // {
  695. // MessageBox.Show("数值最大为5");
  696. // txtYPSCur.Text = "5";
  697. // }
  698. // }
  699. // else
  700. // {
  701. // txtYPSCur.Text = "1";
  702. // }
  703. //}
  704. private void txtYPSCur_KeyPress(object sender, KeyPressEventArgs e)
  705. {
  706. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
  707. {
  708. e.Handled = true;
  709. }
  710. }
  711. #endregion
  712. #region 参数确认
  713. private void SaveMeasureFile()
  714. {
  715. //界面上的参数
  716. GetMeasureParamFromHMI();
  717. //配置文件中的参数
  718. //FormHOZMainObject.m_MeasureFile.MParam.ZDistance = Convert.ToSingle(ConfigurationManager.AppSettings["ZDistance"].ToString());
  719. FormHOZMainObject.m_MeasureFile.IsModified = true;
  720. if (Directory.Exists(FormHOZMainObject.m_MeasureFile.FilePath))//如果已经存在硬盘上要重新保存文件
  721. {
  722. FormHOZMainObject.m_MeasureFile.Save();
  723. }
  724. }
  725. private void button1_Click(object sender, EventArgs e)
  726. {
  727. //保存测量文件的参数
  728. SaveMeasureFile();
  729. }
  730. #endregion
  731. private void btnHandSavePoints_Click(object sender, EventArgs e)
  732. {
  733. UserControls.FormExportPoints uCExport = new UserControls.FormExportPoints();
  734. uCExport.ShowDialog();
  735. List<CutHole> ListCutHole = uCExport.ListCutHole;
  736. //文件路径
  737. //string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
  738. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  739. FormHOZMainObject.m_MeasureFile.ListCutHole = ListCutHole;
  740. //显示导入的切孔数量
  741. lblCutHoleCount.Text = string.Format("成功导入{0}个切孔", ListCutHole.Count);
  742. //tbCutHoleFilePath.Text = CutHoleFilePath;
  743. //保存测量文件
  744. if (Directory.Exists(FormHOZMainObject.m_MeasureFile.FilePath))
  745. {
  746. FormHOZMainObject.m_MeasureFile.Save();
  747. }
  748. }
  749. private void cbbWYP_SelectedIndexChanged(object sender, EventArgs e)
  750. {
  751. FormHOZMainObject.m_MeasureFile.MParam.loadParamFromSampleTypeTemplate(cbbWYP.Text);
  752. SetTypel();
  753. }
  754. private void SetTypel()
  755. {
  756. //if (cbbWYP.Text == "0")
  757. //{
  758. //cbbWCS.Text = FormHOZMainObject.m_MeasureFile.MParam.VendorType0;//厂商
  759. txtVot.Text = FormHOZMainObject.m_MeasureFile.MParam.Voltage.ToString();//电压
  760. txtIprobe.Text = FormHOZMainObject.m_MeasureFile.MParam.Iprobe.ToString();
  761. txtMag1.Text = FormHOZMainObject.m_MeasureFile.MParam.Location_Magnification.ToString();//定位放大倍数
  762. txtMag2.Text = FormHOZMainObject.m_MeasureFile.MParam.Straighten_Magnification.ToString();//拉直放大倍数
  763. txtMag3.Text = FormHOZMainObject.m_MeasureFile.MParam.FindCrossMagnification.ToString();
  764. //cbbWPZD.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoVoltageeType0;//拍照电压
  765. txtMag4.Text = FormHOZMainObject.m_MeasureFile.MParam.Photograph_Magnification.ToString();//拍照放大倍数
  766. //cbbEDSV.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMVoltageeType0;//能谱电压值
  767. //cbbEDSA.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMCurrentType0;//能谱电流值
  768. // label4.Text = "0-AA Hole";
  769. //}
  770. //else
  771. // if (cbbWYP.Text == "1")
  772. //{
  773. // //cbbWCS.Text = FormHOZMainObject.m_MeasureFile.MParam.VendorType1;//厂商
  774. // cbbWLZ.Text = FormHOZMainObject.m_MeasureFile.MParam.StraightenTimesType1;//拉直放大倍数
  775. // cbbWQGD.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningVoltageeType1;//定位电压
  776. // cbbWQGF.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningTimesType1;//定位放大倍数
  777. // cbbWPZD.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoVoltageeType1;//拍照电压
  778. // cbbWPZF.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoTimesType1;//拍照放大倍数
  779. // cbbEDSV.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMVoltageeType1;//能谱电压值
  780. // cbbEDSA.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMCurrentType1;//能谱电流值
  781. // label4.Text = "1-AA区";
  782. //}
  783. //else
  784. // if (cbbWYP.Text == "2")
  785. //{
  786. // //cbbWCS.Text = FormHOZMainObject.m_MeasureFile.MParam.VendorType2;//厂商
  787. // cbbWLZ.Text = FormHOZMainObject.m_MeasureFile.MParam.StraightenTimesType2;//拉直放大倍数
  788. // cbbWQGD.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningVoltageeType2;//定位电压
  789. // cbbWQGF.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningTimesType2;//定位放大倍数
  790. // cbbWPZD.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoVoltageeType2;//拍照电压
  791. // cbbWPZF.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoTimesType2;//拍照放大倍数
  792. // cbbEDSV.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMVoltageeType2;//能谱电压值
  793. // cbbEDSA.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMCurrentType2;//能谱电流值
  794. // label4.Text = "2-Pad bending";
  795. //}
  796. //else
  797. // if (cbbWYP.Text == "3")
  798. //{
  799. // //cbbWCS.Text = FormHOZMainObject.m_MeasureFile.MParam.VendorType3;//厂商
  800. // cbbWLZ.Text = FormHOZMainObject.m_MeasureFile.MParam.StraightenTimesType3;//拉直放大倍数
  801. // cbbWQGD.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningVoltageeType3;//定位电压
  802. // cbbWQGF.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningTimesType3;//定位放大倍数
  803. // cbbWPZD.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoVoltageeType3;//拍照电压
  804. // cbbWPZF.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoTimesType3;//拍照放大倍数
  805. // cbbEDSV.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMVoltageeType3;//能谱电压值
  806. // cbbEDSA.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMCurrentType3;//能谱电流值
  807. // label4.Text = "3-DDIC";
  808. //}
  809. //else
  810. // if (cbbWYP.Text == "4")
  811. //{
  812. // //cbbWCS.Text = FormHOZMainObject.m_MeasureFile.MParam.VendorType3;//厂商
  813. // cbbWLZ.Text = FormHOZMainObject.m_MeasureFile.MParam.StraightenTimesType4;//拉直放大倍数
  814. // cbbWQGD.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningVoltageeType4;//定位电压
  815. // cbbWQGF.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningTimesType4;//定位放大倍数
  816. // cbbWPZD.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoVoltageeType4;//拍照电压
  817. // cbbWPZF.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoTimesType4;//拍照放大倍数
  818. // cbbEDSV.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMVoltageeType4;//能谱电压值
  819. // cbbEDSA.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMCurrentType4;//能谱电流值
  820. // label4.Text = "4-射频IC-1";
  821. //}
  822. //else
  823. // if (cbbWYP.Text == "5")
  824. //{
  825. // //cbbWCS.Text = FormHOZMainObject.m_MeasureFile.MParam.VendorType3;//厂商
  826. // cbbWLZ.Text = FormHOZMainObject.m_MeasureFile.MParam.StraightenTimesType5;//拉直放大倍数
  827. // cbbWQGD.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningVoltageeType5;//定位电压
  828. // cbbWQGF.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningTimesType5;//定位放大倍数
  829. // cbbWPZD.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoVoltageeType5;//拍照电压
  830. // cbbWPZF.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoTimesType5;//拍照放大倍数
  831. // cbbEDSV.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMVoltageeType5;//能谱电压值
  832. // cbbEDSA.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMCurrentType5;//能谱电流值
  833. // label4.Text = "5-射频IC-1";
  834. //}
  835. }
  836. }
  837. }