UControl_Init.cs 39 KB

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