UControl_Init.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  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. m_param.EDS = chkEDS.Checked;
  333. m_param.EDSZ = Convert.ToSingle(txtEDSZ.Text) ;
  334. m_param.EDSV = Convert.ToSingle(txtEDSV.Text);
  335. m_param.EDSA = Convert.ToSingle(txtEDSA.Text) ;
  336. m_param.EDSParam.XrayCollectMode = Convert.ToInt16(cboXrayMode.Text);
  337. //自动对焦模式
  338. //cfm.FocusMode = chkManul.Checked;
  339. m_param.PTTemp = txtWPTF.Text;//PT文件路径
  340. m_param.FIBTemp = txtWFIBF.Text;//FIB文件路径
  341. m_param.ScanRotCor = Convert.ToSingle(txtScanRotCur.Text);
  342. m_param.PixelSizeCor = Convert.ToSingle(txtYPSCur.Text);
  343. m_param.SampleType = cbbWYP.Text;//样品类型
  344. m_param.Firm = cbbWCS.Text;//厂商类型
  345. return true;
  346. }
  347. /// <summary>
  348. /// 编辑confing 文件信息
  349. /// </summary>
  350. public bool SaveParamToConfigfile()
  351. {
  352. try
  353. {
  354. //厂商
  355. List<String> _firms = firms.ToList();
  356. if ((_firms.IndexOf(cbbWCS.Text) < 0)
  357. || (!_firms.Contains(cbbWCS.Text)))
  358. {
  359. _firms.Add(cbbWCS.Text);
  360. string wFirms = string.Join(",", _firms.ToArray());
  361. config.AppSettings.Settings["Firms"].Value = wFirms;
  362. }
  363. var m_Prm = formHOZMain.m_MeasureFile.MParam;
  364. config.AppSettings.Settings["Is_Photograph"].Value = m_Prm.Is_Photograph.ToString();
  365. config.AppSettings.Settings["PT_Depostion"].Value = m_Prm.PT.ToString();
  366. config.AppSettings.Settings["PT_ELYFile"].Value = m_Prm.PTTemp;
  367. config.AppSettings.Settings["FIB_ELYFile"].Value = m_Prm.FIBTemp;
  368. config.AppSettings.Settings["ScanRotCur"].Value = m_Prm.ScanRotCor.ToString();
  369. config.AppSettings.Settings["PixelSize_Y_Cur"].Value = m_Prm.PixelSizeCor.ToString();
  370. config.AppSettings.Settings["LastSampleType"].Value = m_Prm.SampleType;
  371. config.AppSettings.Settings["Is_Title"].Value = m_Prm.Tilt.ToString();
  372. config.AppSettings.Settings["Is_EDS"].Value = m_Prm.EDS.ToString();
  373. config.AppSettings.Settings["EDS_Z"].Value = m_Prm.EDSZ.ToString();
  374. config.AppSettings.Settings["EDS_V"].Value = m_Prm.EDSV.ToString();
  375. config.AppSettings.Settings["EDS_A"].Value = m_Prm.EDSA.ToString();
  376. config.Save(ConfigurationSaveMode.Full);
  377. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  378. return true;
  379. }
  380. catch (Exception ex)
  381. {
  382. LogManager.LogError(ex.Message);
  383. return false;
  384. }
  385. }
  386. /// <summary>
  387. /// 绑定下拉菜单
  388. /// </summary>
  389. /// <param name="cb"></param>
  390. /// <param name="strGroup"></param>
  391. private void BindComboxData(ComboBox cb, string[] strGroup)
  392. {
  393. for (int i = 0; i < strGroup.Length; i++)
  394. {
  395. if (!strGroup[i].Equals(""))
  396. {
  397. cb.Items.Add(strGroup[i]);
  398. }
  399. }
  400. }
  401. /// <summary>
  402. /// 读取Config文件信息
  403. /// </summary>
  404. public void DisplayInitialParam()
  405. {
  406. cbbWYP.Items.Clear();
  407. cbbWCS.Items.Clear();
  408. string firm = config.AppSettings.Settings["Firms"].Value.ToString();
  409. string ScanRotCur = config.AppSettings.Settings["ScanRotCur"].Value.ToString();
  410. txtScanRotCur.Text = ScanRotCur;
  411. txtYPSCur.Text= config.AppSettings.Settings["PixelSize_Y_Cur"].Value.ToString();
  412. //厂商
  413. firms = firm.Split(',');
  414. BindComboxData(cbbWCS, firms);
  415. //设置配置文件默认值
  416. chkWIsP.Checked=Convert.ToBoolean(config.AppSettings.Settings["Is_Photograph"].Value);
  417. chkWPT.Checked = Convert.ToBoolean(config.AppSettings.Settings["PT_Depostion"].Value);
  418. chkWqxkc.Checked = Convert.ToBoolean(config.AppSettings.Settings["Is_Title"].Value);
  419. txtWPTF.Text = config.AppSettings.Settings["PT_ELYFile"].Value;
  420. txtWFIBF.Text = config.AppSettings.Settings["FIB_ELYFile"].Value;
  421. cbbWYP.Text = config.AppSettings.Settings["LastSampleType"].Value;
  422. cbbWCS.Text = config.AppSettings.Settings["LastSelectFirm"].Value;
  423. chkEDS.Checked = Convert.ToBoolean(config.AppSettings.Settings["Is_EDS"].Value);
  424. txtEDSZ.Text= Convert.ToString(config.AppSettings.Settings["EDS_Z"].Value);
  425. txtEDSV.Text = Convert.ToString(config.AppSettings.Settings["EDS_V"].Value);
  426. txtEDSA.Text = Convert.ToString(config.AppSettings.Settings["EDS_A"].Value);
  427. cboXrayMode.Text = Convert.ToString(config.AppSettings.Settings["EDS_XrayMode"].Value);
  428. }
  429. /// <summary>
  430. /// 根据所选路径,读取模板文件
  431. /// </summary>
  432. public void ReadConfigInfo()
  433. {
  434. if (!ReadConfigPath.Equals(""))
  435. {
  436. DisplayInitialParam();
  437. ConfigFile cfm = new ConfigFile(FormHOZMainObject.m_MeasureFile.MParam);
  438. cfm.Read(ReadConfigPath);
  439. chkWIsP.Checked = cfm.m_Config.Is_Photograph;
  440. chkWPT.Checked = cfm.m_Config.PT;
  441. //自动对焦模式
  442. //cfm.FocusMode = chkManul.Checked;
  443. txtWPTF.Text = cfm.m_Config.PTTemp;
  444. txtWFIBF.Text = cfm.m_Config.FIBTemp;
  445. cbbWYP.Text = cfm.m_Config.SampleType;
  446. cbbWCS.Text = cfm.m_Config.Firm;
  447. }
  448. }
  449. /// <summary>
  450. /// 修改配置文件默认值
  451. /// </summary>
  452. /// <param name="sender"></param>
  453. /// <param name="e"></param>
  454. private void btnSaveDefalutPara_Click(object sender, EventArgs e)
  455. {
  456. if (chkWPT.Checked)
  457. {
  458. if (txtWPTF.Text == "")
  459. {
  460. MessageBox.Show("PT文件路径不能为空");
  461. return;
  462. }
  463. }
  464. if (txtWFIBF.Text == "")
  465. {
  466. MessageBox.Show("FIB文件路径不能为空");
  467. return;
  468. }
  469. GetMeasureParamFromHMI();
  470. SaveParamToConfigfile();
  471. //获取测量结果文件位置,并保存测量结果文件
  472. if (formHOZMain.m_MeasureFile.SaveAs())
  473. {
  474. //设置已保存状态
  475. formHOZMain.IsSave = true;
  476. }
  477. FormHOZMainObject.m_MeasureFile.IsModified = true;
  478. Form fParent = this.ParentForm;
  479. fParent.Close();
  480. }
  481. #endregion
  482. #region 删除下拉菜单选择项
  483. #endregion
  484. #region 根据是否仅拍照,进行逻辑判断
  485. private void chkWIsP_CheckedChanged(object sender, EventArgs e)
  486. {
  487. if (chkWIsP.Checked)
  488. {
  489. chkWqxkc.Checked = false;
  490. chkWqxkc.Visible = false;
  491. chkWPT.Checked = false;
  492. chkWPT.Visible = false;
  493. label61.Visible = false;
  494. label59.Visible = false;
  495. txtWFIBF.Visible = false;
  496. txtWPTF.Visible = false;
  497. btnPTTemplateFile.Visible = false;
  498. btnFIBTemplateFile.Visible = false;
  499. //label58.Visible = false;
  500. //cbbWXZ.Visible = false;
  501. chkEDS.Visible = false;
  502. //label18.Visible = false;
  503. //label19.Visible = false;
  504. //txtEDSZ.Visible = false;
  505. //cbbWFIB.Visible = false;
  506. //pbDelWFIB.Visible = false;
  507. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.Photo;
  508. }
  509. else
  510. {
  511. chkWqxkc.Visible = true;
  512. chkWPT.Visible = true;
  513. label61.Visible = true;
  514. label59.Visible = true;
  515. txtWFIBF.Visible = true;
  516. txtWPTF.Visible = true;
  517. btnPTTemplateFile.Visible = true;
  518. btnFIBTemplateFile.Visible = true;
  519. //label58.Visible = true;
  520. //cbbWXZ.Visible = true;
  521. chkEDS.Visible = true;
  522. //label2.Visible = true;
  523. //cbbWFIB.Visible = true;
  524. //pbDelWFIB.Visible = true;
  525. //label18.Visible = true;
  526. //label19.Visible = true;
  527. //txtEDSZ.Visible = true;
  528. if (!chkWPT.Checked)
  529. {
  530. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  531. }
  532. }
  533. CreateCutHoleList();
  534. }
  535. #endregion
  536. #region 创建切孔列表
  537. private void CreateCutHoleList()
  538. {
  539. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  540. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  541. }
  542. #endregion
  543. #region 设置流程类型
  544. private void chkWPT_CheckedChanged(object sender, EventArgs e)
  545. {
  546. if (chkWPT.Checked)
  547. {
  548. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.PT;
  549. }
  550. else
  551. {
  552. if (!chkWIsP.Checked)
  553. {
  554. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  555. }
  556. }
  557. CreateCutHoleList();
  558. }
  559. #endregion
  560. #region 关闭按钮 鼠标操作事件
  561. private void pbClose_MouseEnter(object sender, EventArgs e)
  562. {
  563. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  564. }
  565. private void pbClose_MouseLeave(object sender, EventArgs e)
  566. {
  567. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  568. }
  569. #endregion
  570. #region 输入限制只能是数字
  571. private void textBox_KeyPress(string text, object sender, KeyPressEventArgs e)
  572. {
  573. //判断按键是不是要输入的类型。
  574. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
  575. e.Handled = true;
  576. //小数点的处理。
  577. if ((int)e.KeyChar == 46) //小数点
  578. {
  579. if (text.Length <= 0)
  580. e.Handled = true; //小数点不能在第一位
  581. else
  582. {
  583. float f;
  584. float oldf;
  585. bool b1 = false, b2 = false;
  586. b1 = float.TryParse(text, out oldf);
  587. b2 = float.TryParse(text + e.KeyChar.ToString(), out f);
  588. if (b2 == false)
  589. {
  590. if (b1 == true)
  591. e.Handled = true;
  592. else
  593. e.Handled = false;
  594. }
  595. }
  596. }
  597. }
  598. private void ComboBox_KeyPress(string text, object sender, KeyPressEventArgs e)
  599. {
  600. //允许输入数字、小数点、删除键和负号
  601. if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.') && e.KeyChar != (char)('-'))
  602. {
  603. MessageBox.Show("请输入正确的数字");
  604. text = "";
  605. e.Handled = true;
  606. }
  607. if (e.KeyChar == (char)('-'))
  608. {
  609. if (text != "")
  610. {
  611. MessageBox.Show("请输入正确的数字");
  612. text = "";
  613. e.Handled = true;
  614. }
  615. }
  616. //小数点只能输入一次
  617. if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text.IndexOf('.') != -1)
  618. {
  619. MessageBox.Show("请输入正确的数字");
  620. text = "";
  621. e.Handled = true;
  622. }
  623. //第一位不能为小数点
  624. if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text == "")
  625. {
  626. MessageBox.Show("请输入正确的数字");
  627. text = "";
  628. e.Handled = true;
  629. }
  630. //第一位是0,第二位必须为小数点
  631. if (e.KeyChar != (char)('.') && ((ComboBox)sender).Text == "0")
  632. {
  633. MessageBox.Show("请输入正确的数字");
  634. text = "";
  635. e.Handled = true;
  636. }
  637. //第一位是负号,第二位不能为小数点
  638. if (((ComboBox)sender).Text == "-" && e.KeyChar == (char)('.'))
  639. {
  640. MessageBox.Show("请输入正确的数字");
  641. text = "";
  642. e.Handled = true;
  643. }
  644. }
  645. //private void cbbWPZD_KeyPress(object sender, KeyPressEventArgs e)
  646. //{
  647. // ComboBox_KeyPress(cbbWPZD.Text, sender, e);
  648. //}
  649. //private void cbbWPZF_KeyPress(object sender, KeyPressEventArgs e)
  650. //{
  651. // ComboBox_KeyPress(cbbWPZF.Text, sender, e);
  652. //}
  653. //private void cbbWQGD_KeyPress(object sender, KeyPressEventArgs e)
  654. //{
  655. // ComboBox_KeyPress(cbbWQGD.Text, sender, e);
  656. //}
  657. //private void cbbWQGF_KeyPress(object sender, KeyPressEventArgs e)
  658. //{
  659. // ComboBox_KeyPress(cbbWQGF.Text, sender, e);
  660. //}
  661. //private void cbbWLZ_KeyPress(object sender, KeyPressEventArgs e)
  662. //{
  663. // ComboBox_KeyPress(cbbWLZ.Text, sender, e);
  664. //}
  665. #endregion
  666. #region Z轴的保护范围
  667. private void chkWqxkc_CheckedChanged(object sender, EventArgs e)
  668. {
  669. //if (chkWqxkc.Checked)
  670. //{
  671. // label3.Visible = true;
  672. // cbbYDZZDX.Visible = true;
  673. //}
  674. //else
  675. //{
  676. // label3.Visible = false;
  677. // cbbYDZZDX.Visible = false;
  678. //}
  679. }
  680. //private void txtYPSCur_TextChanged(object sender, EventArgs e)
  681. //{
  682. // if (txtYPSCur.Text != "")
  683. // {
  684. // if (Convert.ToSingle(txtYPSCur.Text) > 5)
  685. // {
  686. // MessageBox.Show("数值最大为5");
  687. // txtYPSCur.Text = "5";
  688. // }
  689. // }
  690. // else
  691. // {
  692. // txtYPSCur.Text = "1";
  693. // }
  694. //}
  695. private void txtYPSCur_KeyPress(object sender, KeyPressEventArgs e)
  696. {
  697. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
  698. {
  699. e.Handled = true;
  700. }
  701. }
  702. #endregion
  703. #region 参数确认
  704. private void SaveMeasureFile()
  705. {
  706. //界面上的参数
  707. GetMeasureParamFromHMI();
  708. //配置文件中的参数
  709. //FormHOZMainObject.m_MeasureFile.MParam.ZDistance = Convert.ToSingle(ConfigurationManager.AppSettings["ZDistance"].ToString());
  710. FormHOZMainObject.m_MeasureFile.IsModified = true;
  711. if (Directory.Exists(FormHOZMainObject.m_MeasureFile.FilePath))//如果已经存在硬盘上要重新保存文件
  712. {
  713. FormHOZMainObject.m_MeasureFile.Save();
  714. }
  715. }
  716. private void button1_Click(object sender, EventArgs e)
  717. {
  718. //保存测量文件的参数
  719. SaveMeasureFile();
  720. }
  721. #endregion
  722. private void btnHandSavePoints_Click(object sender, EventArgs e)
  723. {
  724. UserControls.FormExportPoints uCExport = new UserControls.FormExportPoints();
  725. uCExport.ShowDialog();
  726. List<CutHole> ListCutHole = uCExport.ListCutHole;
  727. //文件路径
  728. //string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
  729. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  730. FormHOZMainObject.m_MeasureFile.ListCutHole = ListCutHole;
  731. //显示导入的切孔数量
  732. lblCutHoleCount.Text = string.Format("成功导入{0}个切孔", ListCutHole.Count);
  733. //tbCutHoleFilePath.Text = CutHoleFilePath;
  734. //保存测量文件
  735. if (Directory.Exists(FormHOZMainObject.m_MeasureFile.FilePath))
  736. {
  737. FormHOZMainObject.m_MeasureFile.Save();
  738. }
  739. }
  740. private void cbbWYP_SelectedIndexChanged(object sender, EventArgs e)
  741. {
  742. FormHOZMainObject.m_MeasureFile.MParam.loadParamFromSampleTypeTemplate(cbbWYP.Text);
  743. SetTypel();
  744. }
  745. private void SetTypel()
  746. {
  747. //if (cbbWYP.Text == "0")
  748. //{
  749. //cbbWCS.Text = FormHOZMainObject.m_MeasureFile.MParam.VendorType0;//厂商
  750. txtVot.Text = FormHOZMainObject.m_MeasureFile.MParam.Voltage.ToString();//电压
  751. txtIprobe.Text = FormHOZMainObject.m_MeasureFile.MParam.Iprobe.ToString();
  752. txtMag1.Text = FormHOZMainObject.m_MeasureFile.MParam.Location_Magnification.ToString();//定位放大倍数
  753. txtMag2.Text = FormHOZMainObject.m_MeasureFile.MParam.Straighten_Magnification.ToString();//拉直放大倍数
  754. txtMag3.Text = FormHOZMainObject.m_MeasureFile.MParam.FindCrossMagnification.ToString();
  755. //cbbWPZD.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoVoltageeType0;//拍照电压
  756. txtMag4.Text = FormHOZMainObject.m_MeasureFile.MParam.Photograph_Magnification.ToString();//拍照放大倍数
  757. //cbbEDSV.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMVoltageeType0;//能谱电压值
  758. //cbbEDSA.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMCurrentType0;//能谱电流值
  759. // label4.Text = "0-AA Hole";
  760. //}
  761. //else
  762. // if (cbbWYP.Text == "1")
  763. //{
  764. // //cbbWCS.Text = FormHOZMainObject.m_MeasureFile.MParam.VendorType1;//厂商
  765. // cbbWLZ.Text = FormHOZMainObject.m_MeasureFile.MParam.StraightenTimesType1;//拉直放大倍数
  766. // cbbWQGD.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningVoltageeType1;//定位电压
  767. // cbbWQGF.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningTimesType1;//定位放大倍数
  768. // cbbWPZD.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoVoltageeType1;//拍照电压
  769. // cbbWPZF.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoTimesType1;//拍照放大倍数
  770. // cbbEDSV.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMVoltageeType1;//能谱电压值
  771. // cbbEDSA.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMCurrentType1;//能谱电流值
  772. // label4.Text = "1-AA区";
  773. //}
  774. //else
  775. // if (cbbWYP.Text == "2")
  776. //{
  777. // //cbbWCS.Text = FormHOZMainObject.m_MeasureFile.MParam.VendorType2;//厂商
  778. // cbbWLZ.Text = FormHOZMainObject.m_MeasureFile.MParam.StraightenTimesType2;//拉直放大倍数
  779. // cbbWQGD.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningVoltageeType2;//定位电压
  780. // cbbWQGF.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningTimesType2;//定位放大倍数
  781. // cbbWPZD.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoVoltageeType2;//拍照电压
  782. // cbbWPZF.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoTimesType2;//拍照放大倍数
  783. // cbbEDSV.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMVoltageeType2;//能谱电压值
  784. // cbbEDSA.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMCurrentType2;//能谱电流值
  785. // label4.Text = "2-Pad bending";
  786. //}
  787. //else
  788. // if (cbbWYP.Text == "3")
  789. //{
  790. // //cbbWCS.Text = FormHOZMainObject.m_MeasureFile.MParam.VendorType3;//厂商
  791. // cbbWLZ.Text = FormHOZMainObject.m_MeasureFile.MParam.StraightenTimesType3;//拉直放大倍数
  792. // cbbWQGD.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningVoltageeType3;//定位电压
  793. // cbbWQGF.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningTimesType3;//定位放大倍数
  794. // cbbWPZD.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoVoltageeType3;//拍照电压
  795. // cbbWPZF.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoTimesType3;//拍照放大倍数
  796. // cbbEDSV.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMVoltageeType3;//能谱电压值
  797. // cbbEDSA.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMCurrentType3;//能谱电流值
  798. // label4.Text = "3-DDIC";
  799. //}
  800. //else
  801. // if (cbbWYP.Text == "4")
  802. //{
  803. // //cbbWCS.Text = FormHOZMainObject.m_MeasureFile.MParam.VendorType3;//厂商
  804. // cbbWLZ.Text = FormHOZMainObject.m_MeasureFile.MParam.StraightenTimesType4;//拉直放大倍数
  805. // cbbWQGD.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningVoltageeType4;//定位电压
  806. // cbbWQGF.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningTimesType4;//定位放大倍数
  807. // cbbWPZD.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoVoltageeType4;//拍照电压
  808. // cbbWPZF.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoTimesType4;//拍照放大倍数
  809. // cbbEDSV.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMVoltageeType4;//能谱电压值
  810. // cbbEDSA.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMCurrentType4;//能谱电流值
  811. // label4.Text = "4-射频IC-1";
  812. //}
  813. //else
  814. // if (cbbWYP.Text == "5")
  815. //{
  816. // //cbbWCS.Text = FormHOZMainObject.m_MeasureFile.MParam.VendorType3;//厂商
  817. // cbbWLZ.Text = FormHOZMainObject.m_MeasureFile.MParam.StraightenTimesType5;//拉直放大倍数
  818. // cbbWQGD.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningVoltageeType5;//定位电压
  819. // cbbWQGF.Text = FormHOZMainObject.m_MeasureFile.MParam.PositioningTimesType5;//定位放大倍数
  820. // cbbWPZD.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoVoltageeType5;//拍照电压
  821. // cbbWPZF.Text = FormHOZMainObject.m_MeasureFile.MParam.PhotoTimesType5;//拍照放大倍数
  822. // cbbEDSV.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMVoltageeType5;//能谱电压值
  823. // cbbEDSA.Text = FormHOZMainObject.m_MeasureFile.MParam.SEMCurrentType5;//能谱电流值
  824. // label4.Text = "5-射频IC-1";
  825. //}
  826. }
  827. }
  828. }