UControl_Init.cs 52 KB

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