UControl_Init.cs 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  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. //20201029:注释
  16. //初始化窗口管理的是参数,包括,测量文件使用的参数,配置文件中的参数(默认参数),或者保存成参数文件。
  17. //初始化窗口中显示的参数是测量文件在使用的参数。
  18. //点击确认,对当前修改的参数保存到测量文件中去。
  19. //点击保存默认设置,当前修改的参数保存到AppConfig中,下次打开时作为默认值打开。
  20. //点击保存成配置文件,将以文件的形式将参数保存在文件中
  21. //参数又分为两种类型,客户操作可见的类型,在AppConfig中参数,
  22. //客户操作的参数,可以每次都针对测量进行修改
  23. //这类参数包括:
  24. //是否是倾斜的样品台
  25. //是否仅拍照
  26. //是否使用PT
  27. //PT加工文件
  28. //FIB加工文件
  29. //样品名称
  30. //厂商
  31. //拉直操作的放大倍数
  32. //定位的电压
  33. //定位的放大倍数
  34. //拍照的电压
  35. //拍照的放大倍数
  36. //AppConfig中的参数,通常不需要修改,每次修改要在配置文件中修改,要重新启动程序
  37. //这类参数包括:
  38. //四组对焦参数
  39. //Z轴的移动距离
  40. //各个参数需要有一系列的默认值,并且各个值可以修改,删除
  41. namespace HOZProject
  42. {
  43. public partial class UControl_Init : UserControl
  44. {
  45. #region 成员变量
  46. //可供选择的各个参数的值列表
  47. String[] sT;//样品类型列表
  48. String[] firms;//厂商列表
  49. String[] WPZD;//拍照电压列表
  50. String[] WPZF;//拍照放大倍数列表
  51. String[] WQGD;//定位电压列表
  52. String[] WQGF;//定位电压放大倍数列表
  53. String[] WLZ;//拉直电压列表
  54. String[] WFIB;//FIB电压列表
  55. //配置文件
  56. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  57. //依附与主工作窗口
  58. private FormHOZMain formHOZMain;
  59. public FormHOZMain FormHOZMainObject { get => formHOZMain; set => formHOZMain = value; }
  60. //模板路径
  61. private string readConfigPath;
  62. public string ReadConfigPath { get => readConfigPath; set => readConfigPath = value; }
  63. //模板文件默认路径
  64. private string m_TemplateFilePath;
  65. #endregion
  66. #region 构造方法
  67. public UControl_Init(FormHOZMain formHOZ)
  68. {
  69. InitializeComponent();
  70. FormHOZMainObject = formHOZ;
  71. }
  72. #endregion
  73. #region 窗体加载
  74. private void UControl_Init_Load(object sender, EventArgs e)
  75. {
  76. //从配置文件中读取一系列的信息
  77. //ReloadConfig();
  78. }
  79. #endregion
  80. #region 关闭窗体
  81. private void btnClose_Click(object sender, EventArgs e)
  82. {
  83. //按照当前的值,更新测量文件的参数
  84. SaveMeasureFile();
  85. Form fParent = this.ParentForm;
  86. fParent.Close();
  87. }
  88. #endregion
  89. #region 加载切孔文件,生成切孔列表
  90. private void pbCutHoleFile_Click(object sender, EventArgs e)
  91. {
  92. try
  93. {
  94. if (FormHOZMainObject.m_MeasureFile == null)
  95. {
  96. MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  97. }
  98. else
  99. {
  100. if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
  101. {
  102. MessageBox.Show("导入切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  103. }
  104. else
  105. {
  106. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  107. //文件路径
  108. string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
  109. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  110. //显示导入的切孔数量
  111. lblCutHoleCount.Text = string.Format("成功导入{0}个切孔", ListCutHole.Count);
  112. tbCutHoleFilePath.Text = CutHoleFilePath;
  113. //保存测量文件
  114. if (Directory.Exists(FormHOZMainObject.m_MeasureFile.FilePath))
  115. {
  116. FormHOZMainObject.m_MeasureFile.Save();
  117. }
  118. }
  119. }
  120. }
  121. catch (Exception ex)
  122. {
  123. LogManager.LogError(ex.Message);
  124. }
  125. }
  126. #endregion
  127. #region 根据一个切孔文件,自动计算其他切孔信息
  128. /// <summary>
  129. /// 根据一个切孔,自动计算其他切孔信息
  130. /// </summary>
  131. /// <param name="sender"></param>
  132. /// <param name="e"></param>
  133. private void pbCutHoleAuto_Click(object sender, EventArgs e)
  134. {
  135. try
  136. {
  137. if (FormHOZMainObject.m_MeasureFile == null)
  138. {
  139. MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  140. }
  141. else
  142. {
  143. if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
  144. {
  145. MessageBox.Show("导入切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  146. }
  147. else
  148. {
  149. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  150. if (ListCutHole != null)
  151. {
  152. if (ListCutHole.Count > 0)
  153. {
  154. //根据切孔文件的一个切孔,自动计算其他切孔位置
  155. float centerX = 65;
  156. float centerY = 65;
  157. float firstX = ListCutHole[0].Position.X;
  158. float firstY = ListCutHole[0].Position.Y;
  159. //距离
  160. float distance = Convert.ToSingle(config.AppSettings.Settings["distance"].Value.ToString());
  161. //矩阵 4*4
  162. int rag = Convert.ToInt32(config.AppSettings.Settings["rag"].Value.ToString());
  163. List<PointF> cutHolePoint = new List<PointF>();
  164. //根据一个切孔点计算其他切孔信息
  165. cutHolePoint = AnalysisPosition(centerX, centerY, firstX, firstY, distance, rag);
  166. if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromAnalysisPosition(cutHolePoint))
  167. {
  168. MessageBox.Show("生成切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  169. }
  170. else
  171. {
  172. //文件路径
  173. string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
  174. //重新获取切孔列表信息
  175. ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  176. //创建切孔列表信息
  177. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  178. //显示导入的切孔数量
  179. lblCutHoleCount.Text = string.Format("成功生成{0}个切孔", ListCutHole.Count);
  180. tbCutHoleFilePath.Text = CutHoleFilePath;
  181. }
  182. }
  183. }
  184. //保存测量文件
  185. if (FormHOZMainObject.IsSave)
  186. {
  187. FormHOZMainObject.m_MeasureFile.Save();
  188. }
  189. }
  190. }
  191. }
  192. catch (Exception ex)
  193. {
  194. LogManager.LogError(ex.Message);
  195. }
  196. }
  197. /// <summary>
  198. /// 分析点坐标
  199. /// </summary>
  200. /// <param name="centerX">中心点X轴坐标</param>
  201. /// <param name="centerY">中心点Y轴坐标</param>
  202. /// <param name="firstX">第一个点X轴坐标</param>
  203. /// <param name="firstY">第一个点Y轴坐标</param>
  204. /// <param name="distance">点与点的距离</param>
  205. /// <param name="rag">行、列数</param>
  206. /// <param name="ptsx">计算生成所有X轴坐标</param>
  207. /// <param name="ptsy">计算生成所有Y轴坐标</param>
  208. public List<PointF> AnalysisPosition(float centerX, float centerY, float firstX, float firstY, float distance, int rag)
  209. {
  210. //求样品1的水平角度
  211. double angle = 0;
  212. //清空所有点信息
  213. List<float> ptsx = new List<float>();
  214. List<float> ptsy = new List<float>();
  215. //将第一个点加入到点信息中
  216. ptsx.Add(firstX);
  217. ptsy.Add(firstY);
  218. //计算第一个点与X轴的交角度数
  219. angle = Math.Atan2(ptsy[0] - centerY, centerX - ptsx[0]) * 180 / Math.PI;
  220. //这里是求与第一个点横向排列的其他点的移动角度
  221. //就是按45度向左向右移动的度
  222. angle = 45 - angle;
  223. angle = angle * Math.PI / 180;
  224. float tx = 0;
  225. float ty = 0;
  226. for (int j = 0; j < rag; j++)
  227. {
  228. //计算每行第一个点的坐标
  229. if (j > 0)
  230. {
  231. tx = (float)(distance * j * Math.Sin(angle));
  232. ty = (float)(distance * j * Math.Cos(angle));
  233. ptsx.Add(tx + ptsx[0]);
  234. ptsy.Add(ptsy[0] - ty);
  235. }
  236. //计算每行其他点的坐标
  237. for (int i = 1; i < rag; i++)
  238. {
  239. tx = (float)(distance * i * Math.Cos(angle));
  240. ty = (float)(distance * i * Math.Sin(angle));
  241. ptsx.Add(tx + ptsx[j * rag]);
  242. ptsy.Add(ty + ptsy[j * rag]);
  243. }
  244. }
  245. List<PointF> pts = new List<PointF>();
  246. for (int i = 0; i < ptsx.Count; i++)
  247. {
  248. //增加的点
  249. PointF pf = new PointF();
  250. pf.X = ptsx[i];
  251. pf.Y = ptsy[i];
  252. pts.Add(pf);
  253. }
  254. return pts;
  255. }
  256. #endregion
  257. #region 加载PT模板文件
  258. private void pbTemplateFile_Click(object sender, EventArgs e)
  259. {
  260. string FilePathName;
  261. string fileNameWithoutExtension;
  262. //新建一个文件对话框
  263. OpenFileDialog pOpenFileDialog = new OpenFileDialog();
  264. //设置对话框标题
  265. pOpenFileDialog.Title = "选择模板文件";
  266. //设置打开文件类型
  267. pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
  268. ////监测文件是否存在
  269. //pOpenFileDialog.CheckFileExists = true;
  270. //文件打开后执行以下程序
  271. if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
  272. {
  273. FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
  274. fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
  275. this.txtWPTF.Text = FilePathName;
  276. }
  277. }
  278. #endregion
  279. #region 加载FIB模板文件
  280. private void pbFIBTemplateFile_Click(object sender, EventArgs e)
  281. {
  282. string FilePathName;
  283. string fileNameWithoutExtension;
  284. //新建一个文件对话框
  285. OpenFileDialog pOpenFileDialog = new OpenFileDialog();
  286. //设置对话框标题
  287. pOpenFileDialog.Title = "选择模板文件";
  288. //设置打开文件类型
  289. pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
  290. ////监测文件是否存在
  291. //pOpenFileDialog.CheckFileExists = true;
  292. //文件打开后执行以下程序
  293. if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
  294. {
  295. FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
  296. fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
  297. this.txtWFIBF.Text = FilePathName;
  298. }
  299. }
  300. #endregion
  301. #region 创建与读取样品参数、配置文件
  302. private void btnCreateConfig_Click(object sender, EventArgs e)
  303. {
  304. if (Convert.ToInt32(cbbWFIB.Text) < 200)
  305. {
  306. MessageBox.Show("FIB最小放大倍数为200倍");
  307. }
  308. else
  309. {
  310. SaveTemplateFile();
  311. }
  312. }
  313. /// <summary>
  314. /// 获取测量参数,初始化窗体中的控件信息
  315. /// </summary>
  316. /// <returns></returns>
  317. public MeasureParam GetMeasureParamInfo()
  318. {
  319. //从当前界面内获取参数
  320. MeasureParam cfm = new MeasureParam();
  321. cfm.Is_Photograph = chkWIsP.Checked;//是否仅拍照
  322. cfm.PT = chkWPT.Checked;//是否有PT
  323. cfm.Title = chkWqxkc.Checked;//是否倾斜样品台
  324. //cfm.EDS =
  325. //自动对焦模式
  326. //cfm.FocusMode = chkManul.Checked;
  327. cfm.PTTemp = txtWPTF.Text;//PT文件路径
  328. cfm.FIBTemp = txtWFIBF.Text;//FIB文件路径
  329. cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);//来自放大倍数
  330. cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);//定位的放大倍数
  331. cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);//定位的放大电压
  332. cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);//拍照的放大倍数
  333. cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);//拍照的电压
  334. cfm.FIB_Magnification = Convert.ToSingle(cbbWFIB.Text);//FIB的放大倍数
  335. if (cbbWXZ.SelectedIndex == 0)//校正角度
  336. {
  337. cfm.Correction_Angle = 36;
  338. }
  339. else
  340. {
  341. cfm.Correction_Angle = 54;
  342. }
  343. cfm.SampleName = cbbWYP.Text;//样品类型
  344. cfm.Firm = cbbWCS.Text;//厂商类型
  345. return cfm;
  346. }
  347. public void SaveTemplateFile()
  348. {
  349. //获取当前文件的参数
  350. MeasureParam cfm = FormHOZMainObject.m_MeasureFile.MParam;
  351. //根据界面显示内容更新参数
  352. cfm.Is_Photograph = chkWIsP.Checked;
  353. cfm.PT = chkWPT.Checked;
  354. cfm.Title = chkWqxkc.Checked;//是否倾斜样品台
  355. //自动对焦模式
  356. //cfm.FocusMode = chkManul.Checked;
  357. cfm.PTTemp = txtWPTF.Text;
  358. cfm.FIBTemp = txtWFIBF.Text;
  359. cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
  360. cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
  361. cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
  362. cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
  363. cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
  364. cfm.FIB_Magnification = Convert.ToSingle(cbbWFIB.Text);
  365. if (cbbWXZ.SelectedIndex == 0)
  366. {
  367. cfm.Correction_Angle = 36;
  368. }
  369. else
  370. {
  371. cfm.Correction_Angle = 54;
  372. }
  373. cfm.SampleName = cbbWYP.Text;
  374. cfm.Firm = cbbWCS.Text;
  375. //保存配置文件中的参数
  376. cfm.ZDistance = Convert.ToSingle(ConfigurationManager.AppSettings["ZDistance"].ToString());
  377. cfm.AutoFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  378. cfm.AutoFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  379. cfm.AutoFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  380. cfm.AutoFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  381. cfm.AutoFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  382. cfm.FIBFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_UP"].ToString());
  383. cfm.FIBFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Down"].ToString());
  384. cfm.FIBFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Step"].ToString());
  385. cfm.FIBFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Range"].ToString());
  386. cfm.FIBFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_FStep"].ToString());
  387. cfm.AutoStigX.UP = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_UP"].ToString());
  388. cfm.AutoStigX.Down = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Down"].ToString());
  389. cfm.AutoStigX.Step = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Step"].ToString());
  390. cfm.AutoStigX.Range = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Range"].ToString());
  391. cfm.AutoStigX.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_FStep"].ToString());
  392. cfm.AutoStigY.UP = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_UP"].ToString());
  393. cfm.AutoStigY.Down = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Down"].ToString());
  394. cfm.AutoStigY.Step = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Step"].ToString());
  395. cfm.AutoStigY.Range = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Range"].ToString());
  396. cfm.AutoStigY.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_FStep"].ToString());
  397. ConfigFile cf = new ConfigFile(cfm);
  398. m_TemplateFilePath = ConfigurationManager.AppSettings["TemplateFilePath"].ToString();
  399. //如果路径不存在,要求选择一个路径
  400. if (!Directory.Exists(m_TemplateFilePath))
  401. {
  402. //创建路径
  403. //Directory.CreateDirectory(m_TemplateFilePath);
  404. FolderBrowserDialog dialog = new FolderBrowserDialog();
  405. dialog.Description = "请选择文件路径";
  406. //dialog.RootFolder = Environment.SpecialFolder.Programs;
  407. if (dialog.ShowDialog() == DialogResult.OK)
  408. {
  409. m_TemplateFilePath = dialog.SelectedPath;
  410. config.AppSettings.Settings["TemplateFilePath"].Value = m_TemplateFilePath;
  411. config.Save(ConfigurationSaveMode.Modified);
  412. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  413. }
  414. }
  415. SaveFileDialog saveFileDialog = new SaveFileDialog();
  416. //设置默认打开路径(绝对路径)
  417. saveFileDialog.InitialDirectory = m_TemplateFilePath;
  418. saveFileDialog.Filter = "样品参数文件|*.cfg";
  419. if (saveFileDialog.ShowDialog() == DialogResult.OK)
  420. {
  421. cf.Save(saveFileDialog.FileName);
  422. }
  423. else
  424. {
  425. return;
  426. }
  427. //编辑Config文件
  428. EditConfig();
  429. }
  430. /// <summary>
  431. /// 编辑confing 文件信息
  432. /// </summary>
  433. public bool EditConfig()
  434. {
  435. try
  436. {
  437. //设置数据源信息
  438. //样品类型
  439. List<String> _sT = sT.ToList();
  440. if ((_sT.IndexOf(cbbWYP.Text) < 0)
  441. || (!_sT.Contains(cbbWYP.Text)))
  442. {
  443. _sT.Add(cbbWYP.Text);
  444. string wsT = string.Join(",", _sT.ToArray());
  445. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  446. }
  447. //厂商
  448. List<String> _firms = firms.ToList();
  449. if( (_firms.IndexOf(cbbWCS.Text) < 0)
  450. || (!_firms.Contains(cbbWCS.Text)))
  451. {
  452. _firms.Add(cbbWCS.Text);
  453. string wFirms = string.Join(",", _firms.ToArray());
  454. config.AppSettings.Settings["Firm"].Value = wFirms;
  455. }
  456. //拍照电压
  457. List<String> _WPZD = WPZD.ToList();
  458. if((_WPZD.IndexOf(cbbWPZD.Text) < 0)
  459. || (!_WPZD.Contains(cbbWPZD.Text)))
  460. {
  461. _WPZD.Add(cbbWPZD.Text);
  462. string wWPZD = string.Join(",", _WPZD.ToArray());
  463. config.AppSettings.Settings["WPZD"].Value = wWPZD;
  464. }
  465. //拍照放大位数
  466. List<String> _WPZF = WPZF.ToList();
  467. if ((_WPZF.IndexOf(cbbWPZF.Text) < 0)
  468. || (!_WPZF.Contains(cbbWPZF.Text)))
  469. {
  470. _WPZF.Add(cbbWPZF.Text);
  471. string wWPZF = string.Join(",", _WPZF.ToArray());
  472. config.AppSettings.Settings["WPZF"].Value = wWPZF;
  473. }
  474. //定位切割电压
  475. List<String> _WQGD = WQGD.ToList();
  476. if ((_WQGD.IndexOf(cbbWQGD.Text) < 0)
  477. || (!_WQGD.Contains(cbbWQGD.Text)))
  478. {
  479. _WQGD.Add(cbbWQGD.Text);
  480. string wWQGD = string.Join(",", _WQGD.ToArray());
  481. config.AppSettings.Settings["WQGD"].Value = wWQGD;
  482. }
  483. //定位切割放大位数
  484. List<String> _WQGF = WQGF.ToList();
  485. if ((_WQGF.IndexOf(cbbWQGF.Text) < 0)
  486. || (!_WQGF.Contains(cbbWQGF.Text)))
  487. {
  488. _WQGF.Add(cbbWQGF.Text);
  489. string wWQGF = string.Join(",", _WQGF.ToArray());
  490. config.AppSettings.Settings["WQGF"].Value = wWQGF;
  491. }
  492. //拉直操作放大位数
  493. List<String> _WLZ = WLZ.ToList();
  494. if ((_WLZ.IndexOf(cbbWLZ.Text) < 0)
  495. || (!_WLZ.Contains(cbbWLZ.Text)))
  496. {
  497. _WLZ.Add(cbbWLZ.Text);
  498. string wWLZ = string.Join(",", _WLZ.ToArray());
  499. config.AppSettings.Settings["WLZ"].Value = wWLZ;
  500. }
  501. //FIB放大位数
  502. List<String> _WFIB = WFIB.ToList();
  503. if ((_WFIB.IndexOf(cbbWFIB.Text) < 0)
  504. ||(!_WFIB.Contains(cbbWFIB.Text)))
  505. {
  506. _WFIB.Add(cbbWFIB.Text);
  507. string wWFIB = string.Join(",", _WFIB.ToArray());
  508. config.AppSettings.Settings["WFIB"].Value = wWFIB;
  509. }
  510. MeasureParam cfm = new MeasureParam();
  511. cfm = FormHOZMainObject.m_MeasureFile.MParam;
  512. cfm.Is_Photograph = chkWIsP.Checked;
  513. cfm.FocusMode = Convert.ToInt32(config.AppSettings.Settings["Focus_Mode"].Value);
  514. cfm.PT = chkWPT.Checked;
  515. //自动对焦模式
  516. //cfm.FocusMode = chkManul.Checked;
  517. cfm.PTTemp = txtWPTF.Text;
  518. cfm.FIBTemp = txtWFIBF.Text;
  519. cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
  520. cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
  521. cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
  522. cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
  523. cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
  524. cfm.FIB_Magnification = Convert.ToSingle(cbbWFIB.Text);
  525. //倾斜观测
  526. cfm.Title = chkWqxkc.Checked;
  527. //移动Z轴大小
  528. cfm.ZDistance = Convert.ToSingle(cbbYDZZDX.Text);
  529. if (cbbWXZ.SelectedIndex == 0)
  530. {
  531. cfm.Correction_Angle = 36;
  532. }
  533. else
  534. {
  535. cfm.Correction_Angle = 54;
  536. }
  537. cfm.SampleName = cbbWYP.Text;
  538. cfm.Firm = cbbWCS.Text;
  539. //设置配置文件默认值
  540. config.AppSettings.Settings["Is_Photograph"].Value = cfm.Is_Photograph.ToString();
  541. config.AppSettings.Settings["PT_Depostion"].Value = cfm.PT.ToString();
  542. config.AppSettings.Settings["PT_ELYFile"].Value = cfm.PTTemp;
  543. config.AppSettings.Settings["FIB_ELYFile"].Value = cfm.FIBTemp;
  544. config.AppSettings.Settings["Stretch_Magnification"].Value = cfm.Stretch_Magnification.ToString();
  545. config.AppSettings.Settings["Location_Magnification"].Value = cfm.Location_Magnification.ToString();
  546. config.AppSettings.Settings["Location_Voltage"].Value = cfm.Location_Voltage.ToString();
  547. config.AppSettings.Settings["Photograph_Magnification"].Value = cfm.Photograph_Magnification.ToString();
  548. config.AppSettings.Settings["Photograph_Voltage"].Value = cfm.Photograph_Voltage.ToString();
  549. config.AppSettings.Settings["Correction_Angle"].Value = cfm.Correction_Angle.ToString();
  550. config.AppSettings.Settings["SampleName"].Value = cfm.SampleName;
  551. config.AppSettings.Settings["Firms"].Value = cfm.Firm;
  552. config.AppSettings.Settings["FIB_Magnification"].Value = cfm.FIB_Magnification.ToString();
  553. config.AppSettings.Settings["Is_Title"].Value = cfm.Title.ToString();
  554. config.AppSettings.Settings["ZDistance"].Value = cfm.ZDistance.ToString();
  555. config.Save(ConfigurationSaveMode.Modified);
  556. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  557. return true;
  558. }
  559. catch (Exception ex)
  560. {
  561. LogManager.LogError(ex.Message);
  562. return false;
  563. }
  564. }
  565. /// <summary>
  566. /// 删除config文件节点中内容信息
  567. /// </summary>
  568. public bool DelConfigNodeContentInfo(string delControlName, string selName)
  569. {
  570. try
  571. {
  572. switch (delControlName)
  573. {
  574. case "WYP":
  575. //样品类型
  576. List<String> _sT = sT.ToList();
  577. _sT.Remove(selName);
  578. string wsT = string.Join(",", _sT.ToArray());
  579. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  580. break;
  581. case "WCS":
  582. //厂商
  583. List<String> _firms = firms.ToList();
  584. _firms.Remove(selName);
  585. string wFirms = string.Join(",", _firms.ToArray());
  586. config.AppSettings.Settings["Firm"].Value = wFirms;
  587. break;
  588. case "WPZD":
  589. //拍照电压
  590. List<String> _WPZD = WPZD.ToList();
  591. _WPZD.Remove(selName);
  592. string wWPZD = string.Join(",", _WPZD.ToArray());
  593. config.AppSettings.Settings["WPZD"].Value = wWPZD;
  594. break;
  595. case "WPZF":
  596. //拍照放大位数
  597. List<String> _WPZF = WPZF.ToList();
  598. _WPZF.Remove(selName);
  599. string wWPZF = string.Join(",", _WPZF.ToArray());
  600. config.AppSettings.Settings["WPZF"].Value = wWPZF;
  601. break;
  602. case "WQGD"://定位切割电压
  603. List<String> _WQGD = WQGD.ToList();
  604. _WQGD.Remove(selName);
  605. string wWQGD = string.Join(",", _WQGD.ToArray());
  606. config.AppSettings.Settings["WQGD"].Value = wWQGD;
  607. break;
  608. case "WQGF": //定位切割放大位数
  609. List<String> _WQGF = WQGF.ToList();
  610. _WQGF.Remove(selName);
  611. string wWQGF = string.Join(",", _WQGF.ToArray());
  612. config.AppSettings.Settings["WQGF"].Value = wWQGF;
  613. break;
  614. case "WLZ":
  615. //拉直操作放大位数
  616. List<String> _WLZ = WLZ.ToList();
  617. _WLZ.Remove(selName);
  618. string wWLZ = string.Join(",", _WLZ.ToArray());
  619. config.AppSettings.Settings["WLZ"].Value = wWLZ;
  620. break;
  621. case "WFIB":
  622. //FIB放大倍数
  623. List<String> _WFIB = WFIB.ToList();
  624. _WFIB.Remove(selName);
  625. string wWFIB = string.Join(",", _WFIB.ToArray());
  626. config.AppSettings.Settings["WFIB"].Value = wWFIB;
  627. break;
  628. }
  629. config.Save(ConfigurationSaveMode.Modified);
  630. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  631. return true;
  632. }
  633. catch (Exception ex)
  634. {
  635. LogManager.LogError(ex.Message);
  636. return true;
  637. }
  638. }
  639. /// <summary>
  640. /// 绑定下拉菜单
  641. /// </summary>
  642. /// <param name="cb"></param>
  643. /// <param name="strGroup"></param>
  644. private void BindComboxData(ComboBox cb, string[] strGroup)
  645. {
  646. for (int i = 0; i < strGroup.Length; i++)
  647. {
  648. if (!strGroup[i].Equals(""))
  649. {
  650. cb.Items.Add(strGroup[i]);
  651. }
  652. }
  653. }
  654. /// <summary>
  655. /// 读取Config文件信息
  656. /// </summary>
  657. public void ReloadConfig()
  658. {
  659. cbbWYP.Items.Clear();
  660. cbbWCS.Items.Clear();
  661. cbbWPZD.Items.Clear();
  662. cbbWPZF.Items.Clear();
  663. cbbWQGD.Items.Clear();
  664. cbbWQGF.Items.Clear();
  665. cbbWLZ.Items.Clear();
  666. cbbWFIB.Items.Clear();
  667. cbbYDZZDX.Text = "0";
  668. m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString();
  669. string sample_Type = config.AppSettings.Settings["Sample_Type"].Value.ToString();
  670. string firm = config.AppSettings.Settings["Firm"].Value.ToString();
  671. string WPZDTemp = config.AppSettings.Settings["WPZD"].Value.ToString();
  672. string WPZFTemp = config.AppSettings.Settings["WPZF"].Value.ToString();
  673. string WQGDTemp = config.AppSettings.Settings["WQGD"].Value.ToString();
  674. string WQGFTemp = config.AppSettings.Settings["WQGF"].Value.ToString();
  675. string WLZTemp = config.AppSettings.Settings["WLZ"].Value.ToString();
  676. string WFIBTemp = config.AppSettings.Settings["WFIB"].Value.ToString();
  677. //string ZZDistance = config.AppSettings.Settings["ZDistance"].Value.ToString();
  678. //样品类型
  679. sT = sample_Type.Split(',');
  680. BindComboxData(cbbWYP, sT);
  681. //厂商
  682. firms = firm.Split(',');
  683. BindComboxData(cbbWCS, firms);
  684. //拍照电压
  685. WPZD = WPZDTemp.Split(',');
  686. BindComboxData(cbbWPZD, WPZD);
  687. //拍照放大位数
  688. WPZF = WPZFTemp.Split(',');
  689. BindComboxData(cbbWPZF, WPZF);
  690. //定位切割电压
  691. WQGD = WQGDTemp.Split(',');
  692. BindComboxData(cbbWQGD, WQGD);
  693. //定位切割放大位数
  694. WQGF = WQGFTemp.Split(',');
  695. BindComboxData(cbbWQGF, WQGF);
  696. //拉直操作放大位数
  697. WLZ = WLZTemp.Split(',');
  698. BindComboxData(cbbWLZ, WLZ);
  699. //FIB放大倍数
  700. WFIB = WFIBTemp.Split(',');
  701. BindComboxData(cbbWFIB, WFIB);
  702. //设置配置文件默认值
  703. chkWIsP.Checked=Convert.ToBoolean(config.AppSettings.Settings["Is_Photograph"].Value);
  704. chkWPT.Checked = Convert.ToBoolean(config.AppSettings.Settings["PT_Depostion"].Value);
  705. //倾斜观测
  706. chkWqxkc.Checked = Convert.ToBoolean(config.AppSettings.Settings["Is_Title"].Value);
  707. //移动Z轴大小
  708. cbbYDZZDX.Text = config.AppSettings.Settings["ZDistance"].Value;
  709. //自动对焦模式
  710. //chkManul.Checked = Convert.ToBoolean(config.AppSettings.Settings["Focus_Mode"].Value);
  711. txtWPTF.Text = config.AppSettings.Settings["PT_ELYFile"].Value;
  712. txtWFIBF.Text = config.AppSettings.Settings["FIB_ELYFile"].Value;
  713. cbbWLZ.Text = config.AppSettings.Settings["Stretch_Magnification"].Value;
  714. cbbWQGF.Text = config.AppSettings.Settings["Location_Magnification"].Value;
  715. cbbWQGD.Text = config.AppSettings.Settings["Location_Voltage"].Value;
  716. cbbWPZF.Text = config.AppSettings.Settings["Photograph_Magnification"].Value;
  717. cbbWPZD.Text = config.AppSettings.Settings["Photograph_Voltage"].Value;
  718. cbbWFIB.Text = config.AppSettings.Settings["FIB_Magnification"].Value;
  719. string Correction_Angle = config.AppSettings.Settings["Correction_Angle"].Value;
  720. //if (Convert.ToBoolean(config.AppSettings.Settings["Is_Title"].Value))
  721. //{
  722. // cbbYDZZDX.Visible = true;
  723. // label3.Visible = true;
  724. //}
  725. //else
  726. //{
  727. // cbbYDZZDX.Visible = false;
  728. // label3.Visible = false;
  729. //}
  730. if (Correction_Angle == "36")
  731. {
  732. cbbWXZ.SelectedIndex = 0;
  733. }
  734. else
  735. {
  736. cbbWXZ.SelectedIndex = 1;
  737. }
  738. cbbWYP.Text = config.AppSettings.Settings["SampleName"].Value;
  739. cbbWCS.Text = config.AppSettings.Settings["Firms"].Value;
  740. }
  741. /// <summary>
  742. /// 根据所选路径,读取模板文件
  743. /// </summary>
  744. public void ReadConfigInfo()
  745. {
  746. if (!ReadConfigPath.Equals(""))
  747. {
  748. ReloadConfig();
  749. ConfigFile cfm = new ConfigFile(FormHOZMainObject.m_MeasureFile.MParam);
  750. cfm.Read(ReadConfigPath);
  751. chkWIsP.Checked = cfm.m_Config.Is_Photograph;
  752. chkWPT.Checked = cfm.m_Config.PT;
  753. //自动对焦模式
  754. //cfm.FocusMode = chkManul.Checked;
  755. txtWPTF.Text = cfm.m_Config.PTTemp;
  756. txtWFIBF.Text = cfm.m_Config.FIBTemp;
  757. cbbWLZ.Text = cfm.m_Config.Stretch_Magnification.ToString();
  758. cbbWQGF.Text = cfm.m_Config.Location_Magnification.ToString();
  759. cbbWQGD.Text = cfm.m_Config.Location_Voltage.ToString();
  760. cbbWPZF.Text = cfm.m_Config.Photograph_Magnification.ToString();
  761. cbbWPZD.Text = cfm.m_Config.Photograph_Voltage.ToString();
  762. cbbWFIB.Text = cfm.m_Config.FIB_Magnification.ToString();
  763. string Correction_Angle = cfm.m_Config.Correction_Angle.ToString();
  764. if (Correction_Angle == "36")
  765. {
  766. cbbWXZ.SelectedIndex = 0;
  767. }
  768. else
  769. {
  770. cbbWXZ.SelectedIndex = 1;
  771. }
  772. cbbWYP.Text = cfm.m_Config.SampleName;
  773. cbbWCS.Text = cfm.m_Config.Firm;
  774. }
  775. }
  776. /// <summary>
  777. /// 修改配置文件默认值
  778. /// </summary>
  779. /// <param name="sender"></param>
  780. /// <param name="e"></param>
  781. private void btnSaveDefalutPara_Click(object sender, EventArgs e)
  782. {
  783. if (Convert.ToInt32(cbbWFIB.Text) < 200)
  784. {
  785. MessageBox.Show("FIB最小放大倍数为200倍");
  786. }
  787. else
  788. {
  789. if (EditConfig())
  790. {
  791. MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  792. }
  793. //增加一个测量文件的参数修改
  794. SaveMeasureFile();
  795. }
  796. }
  797. #endregion
  798. #region 删除下拉菜单选择项
  799. private void DelComboBoxItem_Click(object sender, EventArgs e)
  800. {
  801. if (MessageBox.Show("是否删除所选项信息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  802. {
  803. PictureBox pbDel = (PictureBox)sender;
  804. string ctrlName = pbDel.Name.Substring(5, pbDel.Name.Length - 5);
  805. if (DelComboBoxItem(ctrlName))
  806. {
  807. //重新加载
  808. ReloadConfig();
  809. }
  810. }
  811. }
  812. /// <summary>
  813. /// 删除下拉菜单选择项
  814. /// </summary>
  815. public bool DelComboBoxItem(string controlName)
  816. {
  817. string delName = controlName;
  818. foreach (Control item in this.Controls)
  819. {
  820. if (item is ComboBox)
  821. {
  822. if (item.Name.Contains(delName))
  823. {
  824. ComboBox cb = (ComboBox)item;
  825. return DelConfigNodeContentInfo(delName, cb.Text);
  826. }
  827. }
  828. }
  829. return false;
  830. }
  831. #endregion
  832. #region 根据是否仅拍照,进行逻辑判断
  833. private void chkWIsP_CheckedChanged(object sender, EventArgs e)
  834. {
  835. if (chkWIsP.Checked)
  836. {
  837. chkWPT.Checked = false;
  838. chkWPT.Visible = false;
  839. label61.Visible = false;
  840. label59.Visible = false;
  841. txtWFIBF.Visible = false;
  842. txtWPTF.Visible = false;
  843. pbPTTemplateFile.Visible = false;
  844. pbFIBTemplateFile.Visible = false;
  845. label58.Visible = false;
  846. cbbWXZ.Visible = false;
  847. label2.Visible = false;
  848. cbbWFIB.Visible = false;
  849. pbDelWFIB.Visible = false;
  850. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.Photo;
  851. }
  852. else
  853. {
  854. chkWPT.Visible = true;
  855. label61.Visible = true;
  856. label59.Visible = true;
  857. txtWFIBF.Visible = true;
  858. txtWPTF.Visible = true;
  859. pbPTTemplateFile.Visible = true;
  860. pbFIBTemplateFile.Visible = true;
  861. label58.Visible = true;
  862. cbbWXZ.Visible = true;
  863. label2.Visible = true;
  864. cbbWFIB.Visible = true;
  865. pbDelWFIB.Visible = true;
  866. if (!chkWPT.Checked)
  867. {
  868. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  869. }
  870. }
  871. CreateCutHoleList();
  872. }
  873. #endregion
  874. #region 从配置文件中读取测量参数
  875. public MeasureParam GetMeasureParam()
  876. {
  877. MeasureParam cfm = new MeasureParam();
  878. //设置配置文件默认值
  879. bool bResult = false;
  880. bool.TryParse(config.AppSettings.Settings["Is_Photograph"].Value, out bResult);
  881. cfm.Is_Photograph = bResult;
  882. bool.TryParse(config.AppSettings.Settings["PT_Depostion"].Value, out bResult);
  883. cfm.PT = bResult;
  884. cfm.PTTemp = config.AppSettings.Settings["PT_ELYFile"].Value;
  885. cfm.FIBTemp = config.AppSettings.Settings["FIB_ELYFile"].Value;
  886. float fResult = (float)0.0;
  887. float.TryParse(config.AppSettings.Settings["Stretch_Magnification"].Value, out fResult);
  888. cfm.Stretch_Magnification = fResult;
  889. float.TryParse(config.AppSettings.Settings["Location_Magnification"].Value, out fResult);
  890. cfm.Location_Magnification = fResult;
  891. float.TryParse(config.AppSettings.Settings["Location_Voltage"].Value, out fResult);
  892. cfm.Location_Voltage = fResult;
  893. float.TryParse(config.AppSettings.Settings["Photograph_Magnification"].Value, out fResult);
  894. cfm.Photograph_Magnification = fResult;
  895. float.TryParse(config.AppSettings.Settings["Photograph_Voltage"].Value, out fResult);
  896. cfm.Photograph_Voltage = fResult;
  897. float.TryParse(config.AppSettings.Settings["Correction_Angle"].Value, out fResult);
  898. cfm.Correction_Angle = fResult;
  899. cfm.SampleName = config.AppSettings.Settings["SampleName"].Value;
  900. cfm.Firm = config.AppSettings.Settings["Firms"].Value;
  901. cfm.AutoFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  902. cfm.AutoFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  903. cfm.AutoFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  904. cfm.AutoFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  905. cfm.AutoFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  906. cfm.FIBFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_UP"].ToString());
  907. cfm.FIBFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Down"].ToString());
  908. cfm.FIBFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Step"].ToString());
  909. cfm.FIBFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Range"].ToString());
  910. cfm.FIBFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_FStep"].ToString());
  911. cfm.AutoStigX.UP = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_UP"].ToString());
  912. cfm.AutoStigX.Down = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Down"].ToString());
  913. cfm.AutoStigX.Step = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Step"].ToString());
  914. cfm.AutoStigX.Range = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Range"].ToString());
  915. cfm.AutoStigX.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_FStep"].ToString());
  916. cfm.AutoStigY.UP = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_UP"].ToString());
  917. cfm.AutoStigY.Down = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Down"].ToString());
  918. cfm.AutoStigY.Step = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Step"].ToString());
  919. cfm.AutoStigY.Range = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Range"].ToString());
  920. cfm.AutoStigY.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_FStep"].ToString());
  921. bool.TryParse(config.AppSettings.Settings["Is_Title"].Value, out bResult);
  922. cfm.Title = bResult;
  923. float.TryParse(config.AppSettings.Settings["ZDistance"].Value, out fResult);
  924. cfm.ZDistance = fResult;
  925. return cfm;
  926. }
  927. #endregion
  928. #region 创建切孔列表
  929. private void CreateCutHoleList()
  930. {
  931. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  932. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  933. }
  934. #endregion
  935. #region 设置流程类型
  936. private void chkWPT_CheckedChanged(object sender, EventArgs e)
  937. {
  938. if (chkWPT.Checked)
  939. {
  940. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.PT;
  941. }
  942. else
  943. {
  944. if (!chkWIsP.Checked)
  945. {
  946. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  947. }
  948. }
  949. CreateCutHoleList();
  950. }
  951. #endregion
  952. #region 关闭按钮 鼠标操作事件
  953. private void pbClose_MouseEnter(object sender, EventArgs e)
  954. {
  955. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Red;
  956. }
  957. private void pbClose_MouseLeave(object sender, EventArgs e)
  958. {
  959. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Gray;
  960. }
  961. #endregion
  962. #region 输入限制只能是数字
  963. private void ComboBox_KeyPress(string text, object sender, KeyPressEventArgs e)
  964. {
  965. //允许输入数字、小数点、删除键和负号
  966. if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.') && e.KeyChar != (char)('-'))
  967. {
  968. MessageBox.Show("请输入正确的数字");
  969. text = "";
  970. e.Handled = true;
  971. }
  972. if (e.KeyChar == (char)('-'))
  973. {
  974. if (text != "")
  975. {
  976. MessageBox.Show("请输入正确的数字");
  977. text = "";
  978. e.Handled = true;
  979. }
  980. }
  981. //小数点只能输入一次
  982. if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text.IndexOf('.') != -1)
  983. {
  984. MessageBox.Show("请输入正确的数字");
  985. text = "";
  986. e.Handled = true;
  987. }
  988. //第一位不能为小数点
  989. if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text == "")
  990. {
  991. MessageBox.Show("请输入正确的数字");
  992. text = "";
  993. e.Handled = true;
  994. }
  995. //第一位是0,第二位必须为小数点
  996. if (e.KeyChar != (char)('.') && ((ComboBox)sender).Text == "0")
  997. {
  998. MessageBox.Show("请输入正确的数字");
  999. text = "";
  1000. e.Handled = true;
  1001. }
  1002. //第一位是负号,第二位不能为小数点
  1003. if (((ComboBox)sender).Text == "-" && e.KeyChar == (char)('.'))
  1004. {
  1005. MessageBox.Show("请输入正确的数字");
  1006. text = "";
  1007. e.Handled = true;
  1008. }
  1009. }
  1010. private void cbbWPZD_KeyPress(object sender, KeyPressEventArgs e)
  1011. {
  1012. ComboBox_KeyPress(cbbWPZD.Text, sender, e);
  1013. }
  1014. private void cbbWPZF_KeyPress(object sender, KeyPressEventArgs e)
  1015. {
  1016. ComboBox_KeyPress(cbbWPZF.Text, sender, e);
  1017. }
  1018. private void cbbWQGD_KeyPress(object sender, KeyPressEventArgs e)
  1019. {
  1020. ComboBox_KeyPress(cbbWQGD.Text, sender, e);
  1021. }
  1022. private void cbbWQGF_KeyPress(object sender, KeyPressEventArgs e)
  1023. {
  1024. ComboBox_KeyPress(cbbWQGF.Text, sender, e);
  1025. }
  1026. private void cbbWLZ_KeyPress(object sender, KeyPressEventArgs e)
  1027. {
  1028. ComboBox_KeyPress(cbbWLZ.Text, sender, e);
  1029. }
  1030. private void cbbWFIB_KeyPress(object sender, KeyPressEventArgs e)
  1031. {
  1032. ComboBox_KeyPress(cbbWFIB.Text, sender, e);
  1033. }
  1034. #endregion
  1035. #region Z轴的保护范围
  1036. private void chkWqxkc_CheckedChanged(object sender, EventArgs e)
  1037. {
  1038. //if (chkWqxkc.Checked)
  1039. //{
  1040. // label3.Visible = true;
  1041. // cbbYDZZDX.Visible = true;
  1042. //}
  1043. //else
  1044. //{
  1045. // label3.Visible = false;
  1046. // cbbYDZZDX.Visible = false;
  1047. //}
  1048. }
  1049. private void cbbYDZZDX_TextChanged(object sender, EventArgs e)
  1050. {
  1051. if (cbbYDZZDX.Text!="")
  1052. {
  1053. if (Convert.ToSingle(cbbYDZZDX.Text)>40)
  1054. {
  1055. MessageBox.Show("数值最大为40");
  1056. cbbYDZZDX.Text = "40";
  1057. }
  1058. }
  1059. else
  1060. {
  1061. cbbYDZZDX.Text = "0";
  1062. }
  1063. }
  1064. private void cbbYDZZDX_KeyPress(object sender, KeyPressEventArgs e)
  1065. {
  1066. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
  1067. {
  1068. e.Handled = true;
  1069. }
  1070. }
  1071. #endregion
  1072. #region 参数确认
  1073. private void SaveMeasureFile()
  1074. {
  1075. //界面上的参数
  1076. FormHOZMainObject.m_MeasureFile.MParam = GetMeasureParamInfo();
  1077. //配置文件中的参数
  1078. FormHOZMainObject.m_MeasureFile.MParam.ZDistance = Convert.ToSingle(ConfigurationManager.AppSettings["ZDistance"].ToString());
  1079. FormHOZMainObject.m_MeasureFile.MParam.AutoFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  1080. FormHOZMainObject.m_MeasureFile.MParam.AutoFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  1081. FormHOZMainObject.m_MeasureFile.MParam.AutoFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  1082. FormHOZMainObject.m_MeasureFile.MParam.AutoFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  1083. FormHOZMainObject.m_MeasureFile.MParam.AutoFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  1084. FormHOZMainObject.m_MeasureFile.MParam.FIBFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_UP"].ToString());
  1085. FormHOZMainObject.m_MeasureFile.MParam.FIBFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Down"].ToString());
  1086. FormHOZMainObject.m_MeasureFile.MParam.FIBFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Step"].ToString());
  1087. FormHOZMainObject.m_MeasureFile.MParam.FIBFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Range"].ToString());
  1088. FormHOZMainObject.m_MeasureFile.MParam.FIBFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_FStep"].ToString());
  1089. FormHOZMainObject.m_MeasureFile.MParam.AutoStigX.UP = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_UP"].ToString());
  1090. FormHOZMainObject.m_MeasureFile.MParam.AutoStigX.Down = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Down"].ToString());
  1091. FormHOZMainObject.m_MeasureFile.MParam.AutoStigX.Step = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Step"].ToString());
  1092. FormHOZMainObject.m_MeasureFile.MParam.AutoStigX.Range = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Range"].ToString());
  1093. FormHOZMainObject.m_MeasureFile.MParam.AutoStigX.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_FStep"].ToString());
  1094. FormHOZMainObject.m_MeasureFile.MParam.AutoStigY.UP = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_UP"].ToString());
  1095. FormHOZMainObject.m_MeasureFile.MParam.AutoStigY.Down = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Down"].ToString());
  1096. FormHOZMainObject.m_MeasureFile.MParam.AutoStigY.Step = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Step"].ToString());
  1097. FormHOZMainObject.m_MeasureFile.MParam.AutoStigY.Range = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Range"].ToString());
  1098. FormHOZMainObject.m_MeasureFile.MParam.AutoStigY.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_FStep"].ToString());
  1099. FormHOZMainObject.m_MeasureFile.IsModified = true;
  1100. if (Directory.Exists(FormHOZMainObject.m_MeasureFile.FilePath))//如果已经存在硬盘上要重新保存文件
  1101. {
  1102. FormHOZMainObject.m_MeasureFile.Save();
  1103. }
  1104. }
  1105. private void button1_Click(object sender, EventArgs e)
  1106. {
  1107. //保存测量文件的参数
  1108. SaveMeasureFile();
  1109. }
  1110. #endregion
  1111. }
  1112. }