UControl_Init.cs 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  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. //自动对焦模式
  325. //cfm.FocusMode = chkManul.Checked;
  326. cfm.PTTemp = txtWPTF.Text;//PT文件路径
  327. cfm.FIBTemp = txtWFIBF.Text;//FIB文件路径
  328. cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);//来自放大倍数
  329. cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);//定位的放大倍数
  330. cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);//定位的放大电压
  331. cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);//拍照的放大倍数
  332. cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);//拍照的电压
  333. cfm.FIB_Magnification = Convert.ToSingle(cbbWFIB.Text);//FIB的放大倍数
  334. if (cbbWXZ.SelectedIndex == 0)//校正角度
  335. {
  336. cfm.Correction_Angle = 36;
  337. }
  338. else
  339. {
  340. cfm.Correction_Angle = 54;
  341. }
  342. cfm.SampleName = cbbWYP.Text;//样品类型
  343. cfm.Firm = cbbWCS.Text;//厂商类型
  344. return cfm;
  345. }
  346. public void SaveTemplateFile()
  347. {
  348. //获取当前文件的参数
  349. MeasureParam cfm = FormHOZMainObject.m_MeasureFile.MParam;
  350. //根据界面显示内容更新参数
  351. cfm.Is_Photograph = chkWIsP.Checked;
  352. cfm.PT = chkWPT.Checked;
  353. cfm.Title = chkWqxkc.Checked;//是否倾斜样品台
  354. //自动对焦模式
  355. //cfm.FocusMode = chkManul.Checked;
  356. cfm.PTTemp = txtWPTF.Text;
  357. cfm.FIBTemp = txtWFIBF.Text;
  358. cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
  359. cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
  360. cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
  361. cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
  362. cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
  363. cfm.FIB_Magnification = Convert.ToSingle(cbbWFIB.Text);
  364. if (cbbWXZ.SelectedIndex == 0)
  365. {
  366. cfm.Correction_Angle = 36;
  367. }
  368. else
  369. {
  370. cfm.Correction_Angle = 54;
  371. }
  372. cfm.SampleName = cbbWYP.Text;
  373. cfm.Firm = cbbWCS.Text;
  374. //保存配置文件中的参数
  375. cfm.ZDistance = Convert.ToSingle(ConfigurationManager.AppSettings["ZDistance"].ToString());
  376. cfm.AutoFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  377. cfm.AutoFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  378. cfm.AutoFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  379. cfm.AutoFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  380. cfm.AutoFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  381. cfm.FIBFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_UP"].ToString());
  382. cfm.FIBFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Down"].ToString());
  383. cfm.FIBFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Step"].ToString());
  384. cfm.FIBFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Range"].ToString());
  385. cfm.FIBFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_FStep"].ToString());
  386. cfm.AutoStigX.UP = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_UP"].ToString());
  387. cfm.AutoStigX.Down = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Down"].ToString());
  388. cfm.AutoStigX.Step = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Step"].ToString());
  389. cfm.AutoStigX.Range = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Range"].ToString());
  390. cfm.AutoStigX.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_FStep"].ToString());
  391. cfm.AutoStigY.UP = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_UP"].ToString());
  392. cfm.AutoStigY.Down = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Down"].ToString());
  393. cfm.AutoStigY.Step = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Step"].ToString());
  394. cfm.AutoStigY.Range = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Range"].ToString());
  395. cfm.AutoStigY.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_FStep"].ToString());
  396. ConfigFile cf = new ConfigFile(cfm);
  397. m_TemplateFilePath = ConfigurationManager.AppSettings["TemplateFilePath"].ToString();
  398. //如果路径不存在,要求选择一个路径
  399. if (!Directory.Exists(m_TemplateFilePath))
  400. {
  401. //创建路径
  402. //Directory.CreateDirectory(m_TemplateFilePath);
  403. FolderBrowserDialog dialog = new FolderBrowserDialog();
  404. dialog.Description = "请选择文件路径";
  405. //dialog.RootFolder = Environment.SpecialFolder.Programs;
  406. if (dialog.ShowDialog() == DialogResult.OK)
  407. {
  408. m_TemplateFilePath = dialog.SelectedPath;
  409. config.AppSettings.Settings["TemplateFilePath"].Value = m_TemplateFilePath;
  410. config.Save(ConfigurationSaveMode.Modified);
  411. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  412. }
  413. }
  414. SaveFileDialog saveFileDialog = new SaveFileDialog();
  415. //设置默认打开路径(绝对路径)
  416. saveFileDialog.InitialDirectory = m_TemplateFilePath;
  417. saveFileDialog.Filter = "样品参数文件|*.cfg";
  418. if (saveFileDialog.ShowDialog() == DialogResult.OK)
  419. {
  420. cf.Save(saveFileDialog.FileName);
  421. }
  422. else
  423. {
  424. return;
  425. }
  426. //编辑Config文件
  427. EditConfig();
  428. }
  429. /// <summary>
  430. /// 编辑confing 文件信息
  431. /// </summary>
  432. public bool EditConfig()
  433. {
  434. try
  435. {
  436. //设置数据源信息
  437. //样品类型
  438. List<String> _sT = sT.ToList();
  439. if ((_sT.IndexOf(cbbWYP.Text) < 0)
  440. || (!_sT.Contains(cbbWYP.Text)))
  441. {
  442. _sT.Add(cbbWYP.Text);
  443. string wsT = string.Join(",", _sT.ToArray());
  444. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  445. }
  446. //厂商
  447. List<String> _firms = firms.ToList();
  448. if( (_firms.IndexOf(cbbWCS.Text) < 0)
  449. || (!_firms.Contains(cbbWCS.Text)))
  450. {
  451. _firms.Add(cbbWCS.Text);
  452. string wFirms = string.Join(",", _firms.ToArray());
  453. config.AppSettings.Settings["Firm"].Value = wFirms;
  454. }
  455. //拍照电压
  456. List<String> _WPZD = WPZD.ToList();
  457. if((_WPZD.IndexOf(cbbWPZD.Text) < 0)
  458. || (!_WPZD.Contains(cbbWPZD.Text)))
  459. {
  460. _WPZD.Add(cbbWPZD.Text);
  461. string wWPZD = string.Join(",", _WPZD.ToArray());
  462. config.AppSettings.Settings["WPZD"].Value = wWPZD;
  463. }
  464. //拍照放大位数
  465. List<String> _WPZF = WPZF.ToList();
  466. if ((_WPZF.IndexOf(cbbWPZF.Text) < 0)
  467. || (!_WPZF.Contains(cbbWPZF.Text)))
  468. {
  469. _WPZF.Add(cbbWPZF.Text);
  470. string wWPZF = string.Join(",", _WPZF.ToArray());
  471. config.AppSettings.Settings["WPZF"].Value = wWPZF;
  472. }
  473. //定位切割电压
  474. List<String> _WQGD = WQGD.ToList();
  475. if ((_WQGD.IndexOf(cbbWQGD.Text) < 0)
  476. || (!_WQGD.Contains(cbbWQGD.Text)))
  477. {
  478. _WQGD.Add(cbbWQGD.Text);
  479. string wWQGD = string.Join(",", _WQGD.ToArray());
  480. config.AppSettings.Settings["WQGD"].Value = wWQGD;
  481. }
  482. //定位切割放大位数
  483. List<String> _WQGF = WQGF.ToList();
  484. if ((_WQGF.IndexOf(cbbWQGF.Text) < 0)
  485. || (!_WQGF.Contains(cbbWQGF.Text)))
  486. {
  487. _WQGF.Add(cbbWQGF.Text);
  488. string wWQGF = string.Join(",", _WQGF.ToArray());
  489. config.AppSettings.Settings["WQGF"].Value = wWQGF;
  490. }
  491. //拉直操作放大位数
  492. List<String> _WLZ = WLZ.ToList();
  493. if ((_WLZ.IndexOf(cbbWLZ.Text) < 0)
  494. || (!_WLZ.Contains(cbbWLZ.Text)))
  495. {
  496. _WLZ.Add(cbbWLZ.Text);
  497. string wWLZ = string.Join(",", _WLZ.ToArray());
  498. config.AppSettings.Settings["WLZ"].Value = wWLZ;
  499. }
  500. //FIB放大位数
  501. List<String> _WFIB = WFIB.ToList();
  502. if ((_WFIB.IndexOf(cbbWFIB.Text) < 0)
  503. ||(!_WFIB.Contains(cbbWFIB.Text)))
  504. {
  505. _WFIB.Add(cbbWFIB.Text);
  506. string wWFIB = string.Join(",", _WFIB.ToArray());
  507. config.AppSettings.Settings["WFIB"].Value = wWFIB;
  508. }
  509. MeasureParam cfm = new MeasureParam();
  510. cfm = FormHOZMainObject.m_MeasureFile.MParam;
  511. cfm.Is_Photograph = chkWIsP.Checked;
  512. cfm.FocusMode = Convert.ToInt32(config.AppSettings.Settings["Focus_Mode"].Value);
  513. cfm.PT = chkWPT.Checked;
  514. //自动对焦模式
  515. //cfm.FocusMode = chkManul.Checked;
  516. cfm.PTTemp = txtWPTF.Text;
  517. cfm.FIBTemp = txtWFIBF.Text;
  518. cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
  519. cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
  520. cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
  521. cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
  522. cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
  523. cfm.FIB_Magnification = Convert.ToSingle(cbbWFIB.Text);
  524. //倾斜观测
  525. cfm.Title = chkWqxkc.Checked;
  526. //移动Z轴大小
  527. cfm.ZDistance = Convert.ToSingle(cbbYDZZDX.Text);
  528. if (cbbWXZ.SelectedIndex == 0)
  529. {
  530. cfm.Correction_Angle = 36;
  531. }
  532. else
  533. {
  534. cfm.Correction_Angle = 54;
  535. }
  536. cfm.SampleName = cbbWYP.Text;
  537. cfm.Firm = cbbWCS.Text;
  538. //设置配置文件默认值
  539. config.AppSettings.Settings["Is_Photograph"].Value = cfm.Is_Photograph.ToString();
  540. config.AppSettings.Settings["PT_Depostion"].Value = cfm.PT.ToString();
  541. config.AppSettings.Settings["PT_ELYFile"].Value = cfm.PTTemp;
  542. config.AppSettings.Settings["FIB_ELYFile"].Value = cfm.FIBTemp;
  543. config.AppSettings.Settings["Stretch_Magnification"].Value = cfm.Stretch_Magnification.ToString();
  544. config.AppSettings.Settings["Location_Magnification"].Value = cfm.Location_Magnification.ToString();
  545. config.AppSettings.Settings["Location_Voltage"].Value = cfm.Location_Voltage.ToString();
  546. config.AppSettings.Settings["Photograph_Magnification"].Value = cfm.Photograph_Magnification.ToString();
  547. config.AppSettings.Settings["Photograph_Voltage"].Value = cfm.Photograph_Voltage.ToString();
  548. config.AppSettings.Settings["Correction_Angle"].Value = cfm.Correction_Angle.ToString();
  549. config.AppSettings.Settings["SampleName"].Value = cfm.SampleName;
  550. config.AppSettings.Settings["Firms"].Value = cfm.Firm;
  551. config.AppSettings.Settings["FIB_Magnification"].Value = cfm.FIB_Magnification.ToString();
  552. config.AppSettings.Settings["Is_Title"].Value = cfm.Title.ToString();
  553. config.AppSettings.Settings["ZDistance"].Value = cfm.ZDistance.ToString();
  554. config.Save(ConfigurationSaveMode.Modified);
  555. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  556. return true;
  557. }
  558. catch (Exception ex)
  559. {
  560. LogManager.LogError(ex.Message);
  561. return false;
  562. }
  563. }
  564. /// <summary>
  565. /// 删除config文件节点中内容信息
  566. /// </summary>
  567. public bool DelConfigNodeContentInfo(string delControlName, string selName)
  568. {
  569. try
  570. {
  571. switch (delControlName)
  572. {
  573. case "WYP":
  574. //样品类型
  575. List<String> _sT = sT.ToList();
  576. _sT.Remove(selName);
  577. string wsT = string.Join(",", _sT.ToArray());
  578. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  579. break;
  580. case "WCS":
  581. //厂商
  582. List<String> _firms = firms.ToList();
  583. _firms.Remove(selName);
  584. string wFirms = string.Join(",", _firms.ToArray());
  585. config.AppSettings.Settings["Firm"].Value = wFirms;
  586. break;
  587. case "WPZD":
  588. //拍照电压
  589. List<String> _WPZD = WPZD.ToList();
  590. _WPZD.Remove(selName);
  591. string wWPZD = string.Join(",", _WPZD.ToArray());
  592. config.AppSettings.Settings["WPZD"].Value = wWPZD;
  593. break;
  594. case "WPZF":
  595. //拍照放大位数
  596. List<String> _WPZF = WPZF.ToList();
  597. _WPZF.Remove(selName);
  598. string wWPZF = string.Join(",", _WPZF.ToArray());
  599. config.AppSettings.Settings["WPZF"].Value = wWPZF;
  600. break;
  601. case "WQGD"://定位切割电压
  602. List<String> _WQGD = WQGD.ToList();
  603. _WQGD.Remove(selName);
  604. string wWQGD = string.Join(",", _WQGD.ToArray());
  605. config.AppSettings.Settings["WQGD"].Value = wWQGD;
  606. break;
  607. case "WQGF": //定位切割放大位数
  608. List<String> _WQGF = WQGF.ToList();
  609. _WQGF.Remove(selName);
  610. string wWQGF = string.Join(",", _WQGF.ToArray());
  611. config.AppSettings.Settings["WQGF"].Value = wWQGF;
  612. break;
  613. case "WLZ":
  614. //拉直操作放大位数
  615. List<String> _WLZ = WLZ.ToList();
  616. _WLZ.Remove(selName);
  617. string wWLZ = string.Join(",", _WLZ.ToArray());
  618. config.AppSettings.Settings["WLZ"].Value = wWLZ;
  619. break;
  620. case "WFIB":
  621. //FIB放大倍数
  622. List<String> _WFIB = WFIB.ToList();
  623. _WFIB.Remove(selName);
  624. string wWFIB = string.Join(",", _WFIB.ToArray());
  625. config.AppSettings.Settings["WFIB"].Value = wWFIB;
  626. break;
  627. }
  628. config.Save(ConfigurationSaveMode.Modified);
  629. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  630. return true;
  631. }
  632. catch (Exception ex)
  633. {
  634. LogManager.LogError(ex.Message);
  635. return true;
  636. }
  637. }
  638. /// <summary>
  639. /// 绑定下拉菜单
  640. /// </summary>
  641. /// <param name="cb"></param>
  642. /// <param name="strGroup"></param>
  643. private void BindComboxData(ComboBox cb, string[] strGroup)
  644. {
  645. for (int i = 0; i < strGroup.Length; i++)
  646. {
  647. if (!strGroup[i].Equals(""))
  648. {
  649. cb.Items.Add(strGroup[i]);
  650. }
  651. }
  652. }
  653. /// <summary>
  654. /// 读取Config文件信息
  655. /// </summary>
  656. public void ReloadConfig()
  657. {
  658. cbbWYP.Items.Clear();
  659. cbbWCS.Items.Clear();
  660. cbbWPZD.Items.Clear();
  661. cbbWPZF.Items.Clear();
  662. cbbWQGD.Items.Clear();
  663. cbbWQGF.Items.Clear();
  664. cbbWLZ.Items.Clear();
  665. cbbWFIB.Items.Clear();
  666. cbbYDZZDX.Text = "0";
  667. m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString();
  668. string sample_Type = config.AppSettings.Settings["Sample_Type"].Value.ToString();
  669. string firm = config.AppSettings.Settings["Firm"].Value.ToString();
  670. string WPZDTemp = config.AppSettings.Settings["WPZD"].Value.ToString();
  671. string WPZFTemp = config.AppSettings.Settings["WPZF"].Value.ToString();
  672. string WQGDTemp = config.AppSettings.Settings["WQGD"].Value.ToString();
  673. string WQGFTemp = config.AppSettings.Settings["WQGF"].Value.ToString();
  674. string WLZTemp = config.AppSettings.Settings["WLZ"].Value.ToString();
  675. string WFIBTemp = config.AppSettings.Settings["WFIB"].Value.ToString();
  676. //string ZZDistance = config.AppSettings.Settings["ZDistance"].Value.ToString();
  677. //样品类型
  678. sT = sample_Type.Split(',');
  679. BindComboxData(cbbWYP, sT);
  680. //厂商
  681. firms = firm.Split(',');
  682. BindComboxData(cbbWCS, firms);
  683. //拍照电压
  684. WPZD = WPZDTemp.Split(',');
  685. BindComboxData(cbbWPZD, WPZD);
  686. //拍照放大位数
  687. WPZF = WPZFTemp.Split(',');
  688. BindComboxData(cbbWPZF, WPZF);
  689. //定位切割电压
  690. WQGD = WQGDTemp.Split(',');
  691. BindComboxData(cbbWQGD, WQGD);
  692. //定位切割放大位数
  693. WQGF = WQGFTemp.Split(',');
  694. BindComboxData(cbbWQGF, WQGF);
  695. //拉直操作放大位数
  696. WLZ = WLZTemp.Split(',');
  697. BindComboxData(cbbWLZ, WLZ);
  698. //FIB放大倍数
  699. WFIB = WFIBTemp.Split(',');
  700. BindComboxData(cbbWFIB, WFIB);
  701. //设置配置文件默认值
  702. chkWIsP.Checked=Convert.ToBoolean(config.AppSettings.Settings["Is_Photograph"].Value);
  703. chkWPT.Checked = Convert.ToBoolean(config.AppSettings.Settings["PT_Depostion"].Value);
  704. //倾斜观测
  705. chkWqxkc.Checked = Convert.ToBoolean(config.AppSettings.Settings["Is_Title"].Value);
  706. //移动Z轴大小
  707. cbbYDZZDX.Text = config.AppSettings.Settings["ZDistance"].Value;
  708. //自动对焦模式
  709. //chkManul.Checked = Convert.ToBoolean(config.AppSettings.Settings["Focus_Mode"].Value);
  710. txtWPTF.Text = config.AppSettings.Settings["PT_ELYFile"].Value;
  711. txtWFIBF.Text = config.AppSettings.Settings["FIB_ELYFile"].Value;
  712. cbbWLZ.Text = config.AppSettings.Settings["Stretch_Magnification"].Value;
  713. cbbWQGF.Text = config.AppSettings.Settings["Location_Magnification"].Value;
  714. cbbWQGD.Text = config.AppSettings.Settings["Location_Voltage"].Value;
  715. cbbWPZF.Text = config.AppSettings.Settings["Photograph_Magnification"].Value;
  716. cbbWPZD.Text = config.AppSettings.Settings["Photograph_Voltage"].Value;
  717. cbbWFIB.Text = config.AppSettings.Settings["FIB_Magnification"].Value;
  718. string Correction_Angle = config.AppSettings.Settings["Correction_Angle"].Value;
  719. //if (Convert.ToBoolean(config.AppSettings.Settings["Is_Title"].Value))
  720. //{
  721. // cbbYDZZDX.Visible = true;
  722. // label3.Visible = true;
  723. //}
  724. //else
  725. //{
  726. // cbbYDZZDX.Visible = false;
  727. // label3.Visible = false;
  728. //}
  729. if (Correction_Angle == "36")
  730. {
  731. cbbWXZ.SelectedIndex = 0;
  732. }
  733. else
  734. {
  735. cbbWXZ.SelectedIndex = 1;
  736. }
  737. cbbWYP.Text = config.AppSettings.Settings["SampleName"].Value;
  738. cbbWCS.Text = config.AppSettings.Settings["Firms"].Value;
  739. }
  740. /// <summary>
  741. /// 根据所选路径,读取模板文件
  742. /// </summary>
  743. public void ReadConfigInfo()
  744. {
  745. if (!ReadConfigPath.Equals(""))
  746. {
  747. ReloadConfig();
  748. ConfigFile cfm = new ConfigFile(FormHOZMainObject.m_MeasureFile.MParam);
  749. cfm.Read(ReadConfigPath);
  750. chkWIsP.Checked = cfm.m_Config.Is_Photograph;
  751. chkWPT.Checked = cfm.m_Config.PT;
  752. //自动对焦模式
  753. //cfm.FocusMode = chkManul.Checked;
  754. txtWPTF.Text = cfm.m_Config.PTTemp;
  755. txtWFIBF.Text = cfm.m_Config.FIBTemp;
  756. cbbWLZ.Text = cfm.m_Config.Stretch_Magnification.ToString();
  757. cbbWQGF.Text = cfm.m_Config.Location_Magnification.ToString();
  758. cbbWQGD.Text = cfm.m_Config.Location_Voltage.ToString();
  759. cbbWPZF.Text = cfm.m_Config.Photograph_Magnification.ToString();
  760. cbbWPZD.Text = cfm.m_Config.Photograph_Voltage.ToString();
  761. cbbWFIB.Text = cfm.m_Config.FIB_Magnification.ToString();
  762. string Correction_Angle = cfm.m_Config.Correction_Angle.ToString();
  763. if (Correction_Angle == "36")
  764. {
  765. cbbWXZ.SelectedIndex = 0;
  766. }
  767. else
  768. {
  769. cbbWXZ.SelectedIndex = 1;
  770. }
  771. cbbWYP.Text = cfm.m_Config.SampleName;
  772. cbbWCS.Text = cfm.m_Config.Firm;
  773. }
  774. }
  775. /// <summary>
  776. /// 修改配置文件默认值
  777. /// </summary>
  778. /// <param name="sender"></param>
  779. /// <param name="e"></param>
  780. private void btnSaveDefalutPara_Click(object sender, EventArgs e)
  781. {
  782. if (Convert.ToInt32(cbbWFIB.Text) < 200)
  783. {
  784. MessageBox.Show("FIB最小放大倍数为200倍");
  785. }
  786. else
  787. {
  788. if (EditConfig())
  789. {
  790. MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  791. }
  792. //增加一个测量文件的参数修改
  793. SaveMeasureFile();
  794. }
  795. }
  796. #endregion
  797. #region 删除下拉菜单选择项
  798. private void DelComboBoxItem_Click(object sender, EventArgs e)
  799. {
  800. if (MessageBox.Show("是否删除所选项信息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  801. {
  802. PictureBox pbDel = (PictureBox)sender;
  803. string ctrlName = pbDel.Name.Substring(5, pbDel.Name.Length - 5);
  804. if (DelComboBoxItem(ctrlName))
  805. {
  806. //重新加载
  807. ReloadConfig();
  808. }
  809. }
  810. }
  811. /// <summary>
  812. /// 删除下拉菜单选择项
  813. /// </summary>
  814. public bool DelComboBoxItem(string controlName)
  815. {
  816. string delName = controlName;
  817. foreach (Control item in this.Controls)
  818. {
  819. if (item is ComboBox)
  820. {
  821. if (item.Name.Contains(delName))
  822. {
  823. ComboBox cb = (ComboBox)item;
  824. return DelConfigNodeContentInfo(delName, cb.Text);
  825. }
  826. }
  827. }
  828. return false;
  829. }
  830. #endregion
  831. #region 根据是否仅拍照,进行逻辑判断
  832. private void chkWIsP_CheckedChanged(object sender, EventArgs e)
  833. {
  834. if (chkWIsP.Checked)
  835. {
  836. chkWPT.Checked = false;
  837. chkWPT.Visible = false;
  838. label61.Visible = false;
  839. label59.Visible = false;
  840. txtWFIBF.Visible = false;
  841. txtWPTF.Visible = false;
  842. pbPTTemplateFile.Visible = false;
  843. pbFIBTemplateFile.Visible = false;
  844. label58.Visible = false;
  845. cbbWXZ.Visible = false;
  846. label2.Visible = false;
  847. cbbWFIB.Visible = false;
  848. pbDelWFIB.Visible = false;
  849. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.Photo;
  850. }
  851. else
  852. {
  853. chkWPT.Visible = true;
  854. label61.Visible = true;
  855. label59.Visible = true;
  856. txtWFIBF.Visible = true;
  857. txtWPTF.Visible = true;
  858. pbPTTemplateFile.Visible = true;
  859. pbFIBTemplateFile.Visible = true;
  860. label58.Visible = true;
  861. cbbWXZ.Visible = true;
  862. label2.Visible = true;
  863. cbbWFIB.Visible = true;
  864. pbDelWFIB.Visible = true;
  865. if (!chkWPT.Checked)
  866. {
  867. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  868. }
  869. }
  870. CreateCutHoleList();
  871. }
  872. #endregion
  873. #region 从配置文件中读取测量参数
  874. public MeasureParam GetMeasureParam()
  875. {
  876. MeasureParam cfm = new MeasureParam();
  877. //设置配置文件默认值
  878. bool bResult = false;
  879. bool.TryParse(config.AppSettings.Settings["Is_Photograph"].Value, out bResult);
  880. cfm.Is_Photograph = bResult;
  881. bool.TryParse(config.AppSettings.Settings["PT_Depostion"].Value, out bResult);
  882. cfm.PT = bResult;
  883. cfm.PTTemp = config.AppSettings.Settings["PT_ELYFile"].Value;
  884. cfm.FIBTemp = config.AppSettings.Settings["FIB_ELYFile"].Value;
  885. float fResult = (float)0.0;
  886. float.TryParse(config.AppSettings.Settings["Stretch_Magnification"].Value, out fResult);
  887. cfm.Stretch_Magnification = fResult;
  888. float.TryParse(config.AppSettings.Settings["Location_Magnification"].Value, out fResult);
  889. cfm.Location_Magnification = fResult;
  890. float.TryParse(config.AppSettings.Settings["Location_Voltage"].Value, out fResult);
  891. cfm.Location_Voltage = fResult;
  892. float.TryParse(config.AppSettings.Settings["Photograph_Magnification"].Value, out fResult);
  893. cfm.Photograph_Magnification = fResult;
  894. float.TryParse(config.AppSettings.Settings["Photograph_Voltage"].Value, out fResult);
  895. cfm.Photograph_Voltage = fResult;
  896. float.TryParse(config.AppSettings.Settings["Correction_Angle"].Value, out fResult);
  897. cfm.Correction_Angle = fResult;
  898. cfm.SampleName = config.AppSettings.Settings["SampleName"].Value;
  899. cfm.Firm = config.AppSettings.Settings["Firms"].Value;
  900. cfm.AutoFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  901. cfm.AutoFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  902. cfm.AutoFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  903. cfm.AutoFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  904. cfm.AutoFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  905. cfm.FIBFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_UP"].ToString());
  906. cfm.FIBFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Down"].ToString());
  907. cfm.FIBFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Step"].ToString());
  908. cfm.FIBFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Range"].ToString());
  909. cfm.FIBFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_FStep"].ToString());
  910. cfm.AutoStigX.UP = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_UP"].ToString());
  911. cfm.AutoStigX.Down = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Down"].ToString());
  912. cfm.AutoStigX.Step = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Step"].ToString());
  913. cfm.AutoStigX.Range = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Range"].ToString());
  914. cfm.AutoStigX.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_FStep"].ToString());
  915. cfm.AutoStigY.UP = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_UP"].ToString());
  916. cfm.AutoStigY.Down = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Down"].ToString());
  917. cfm.AutoStigY.Step = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Step"].ToString());
  918. cfm.AutoStigY.Range = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Range"].ToString());
  919. cfm.AutoStigY.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_FStep"].ToString());
  920. bool.TryParse(config.AppSettings.Settings["Is_Title"].Value, out bResult);
  921. cfm.Title = bResult;
  922. float.TryParse(config.AppSettings.Settings["ZDistance"].Value, out fResult);
  923. cfm.ZDistance = fResult;
  924. return cfm;
  925. }
  926. #endregion
  927. #region 创建切孔列表
  928. private void CreateCutHoleList()
  929. {
  930. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  931. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  932. }
  933. #endregion
  934. #region 设置流程类型
  935. private void chkWPT_CheckedChanged(object sender, EventArgs e)
  936. {
  937. if (chkWPT.Checked)
  938. {
  939. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.PT;
  940. }
  941. else
  942. {
  943. if (!chkWIsP.Checked)
  944. {
  945. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  946. }
  947. }
  948. CreateCutHoleList();
  949. }
  950. #endregion
  951. #region 关闭按钮 鼠标操作事件
  952. private void pbClose_MouseEnter(object sender, EventArgs e)
  953. {
  954. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Red;
  955. }
  956. private void pbClose_MouseLeave(object sender, EventArgs e)
  957. {
  958. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Gray;
  959. }
  960. #endregion
  961. #region 输入限制只能是数字
  962. private void ComboBox_KeyPress(string text, object sender, KeyPressEventArgs e)
  963. {
  964. //允许输入数字、小数点、删除键和负号
  965. if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.') && e.KeyChar != (char)('-'))
  966. {
  967. MessageBox.Show("请输入正确的数字");
  968. text = "";
  969. e.Handled = true;
  970. }
  971. if (e.KeyChar == (char)('-'))
  972. {
  973. if (text != "")
  974. {
  975. MessageBox.Show("请输入正确的数字");
  976. text = "";
  977. e.Handled = true;
  978. }
  979. }
  980. //小数点只能输入一次
  981. if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text.IndexOf('.') != -1)
  982. {
  983. MessageBox.Show("请输入正确的数字");
  984. text = "";
  985. e.Handled = true;
  986. }
  987. //第一位不能为小数点
  988. if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text == "")
  989. {
  990. MessageBox.Show("请输入正确的数字");
  991. text = "";
  992. e.Handled = true;
  993. }
  994. //第一位是0,第二位必须为小数点
  995. if (e.KeyChar != (char)('.') && ((ComboBox)sender).Text == "0")
  996. {
  997. MessageBox.Show("请输入正确的数字");
  998. text = "";
  999. e.Handled = true;
  1000. }
  1001. //第一位是负号,第二位不能为小数点
  1002. if (((ComboBox)sender).Text == "-" && e.KeyChar == (char)('.'))
  1003. {
  1004. MessageBox.Show("请输入正确的数字");
  1005. text = "";
  1006. e.Handled = true;
  1007. }
  1008. }
  1009. private void cbbWPZD_KeyPress(object sender, KeyPressEventArgs e)
  1010. {
  1011. ComboBox_KeyPress(cbbWPZD.Text, sender, e);
  1012. }
  1013. private void cbbWPZF_KeyPress(object sender, KeyPressEventArgs e)
  1014. {
  1015. ComboBox_KeyPress(cbbWPZF.Text, sender, e);
  1016. }
  1017. private void cbbWQGD_KeyPress(object sender, KeyPressEventArgs e)
  1018. {
  1019. ComboBox_KeyPress(cbbWQGD.Text, sender, e);
  1020. }
  1021. private void cbbWQGF_KeyPress(object sender, KeyPressEventArgs e)
  1022. {
  1023. ComboBox_KeyPress(cbbWQGF.Text, sender, e);
  1024. }
  1025. private void cbbWLZ_KeyPress(object sender, KeyPressEventArgs e)
  1026. {
  1027. ComboBox_KeyPress(cbbWLZ.Text, sender, e);
  1028. }
  1029. private void cbbWFIB_KeyPress(object sender, KeyPressEventArgs e)
  1030. {
  1031. ComboBox_KeyPress(cbbWFIB.Text, sender, e);
  1032. }
  1033. #endregion
  1034. #region Z轴的保护范围
  1035. private void chkWqxkc_CheckedChanged(object sender, EventArgs e)
  1036. {
  1037. //if (chkWqxkc.Checked)
  1038. //{
  1039. // label3.Visible = true;
  1040. // cbbYDZZDX.Visible = true;
  1041. //}
  1042. //else
  1043. //{
  1044. // label3.Visible = false;
  1045. // cbbYDZZDX.Visible = false;
  1046. //}
  1047. }
  1048. private void cbbYDZZDX_TextChanged(object sender, EventArgs e)
  1049. {
  1050. if (cbbYDZZDX.Text!="")
  1051. {
  1052. if (Convert.ToSingle(cbbYDZZDX.Text)>40)
  1053. {
  1054. MessageBox.Show("数值最大为40");
  1055. cbbYDZZDX.Text = "40";
  1056. }
  1057. }
  1058. else
  1059. {
  1060. cbbYDZZDX.Text = "0";
  1061. }
  1062. }
  1063. private void cbbYDZZDX_KeyPress(object sender, KeyPressEventArgs e)
  1064. {
  1065. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
  1066. {
  1067. e.Handled = true;
  1068. }
  1069. }
  1070. #endregion
  1071. #region 参数确认
  1072. private void SaveMeasureFile()
  1073. {
  1074. //界面上的参数
  1075. FormHOZMainObject.m_MeasureFile.MParam = GetMeasureParamInfo();
  1076. //配置文件中的参数
  1077. FormHOZMainObject.m_MeasureFile.MParam.ZDistance = Convert.ToSingle(ConfigurationManager.AppSettings["ZDistance"].ToString());
  1078. FormHOZMainObject.m_MeasureFile.MParam.AutoFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  1079. FormHOZMainObject.m_MeasureFile.MParam.AutoFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  1080. FormHOZMainObject.m_MeasureFile.MParam.AutoFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  1081. FormHOZMainObject.m_MeasureFile.MParam.AutoFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  1082. FormHOZMainObject.m_MeasureFile.MParam.AutoFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  1083. FormHOZMainObject.m_MeasureFile.MParam.FIBFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_UP"].ToString());
  1084. FormHOZMainObject.m_MeasureFile.MParam.FIBFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Down"].ToString());
  1085. FormHOZMainObject.m_MeasureFile.MParam.FIBFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Step"].ToString());
  1086. FormHOZMainObject.m_MeasureFile.MParam.FIBFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Range"].ToString());
  1087. FormHOZMainObject.m_MeasureFile.MParam.FIBFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_FStep"].ToString());
  1088. FormHOZMainObject.m_MeasureFile.MParam.AutoStigX.UP = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_UP"].ToString());
  1089. FormHOZMainObject.m_MeasureFile.MParam.AutoStigX.Down = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Down"].ToString());
  1090. FormHOZMainObject.m_MeasureFile.MParam.AutoStigX.Step = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Step"].ToString());
  1091. FormHOZMainObject.m_MeasureFile.MParam.AutoStigX.Range = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Range"].ToString());
  1092. FormHOZMainObject.m_MeasureFile.MParam.AutoStigX.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_FStep"].ToString());
  1093. FormHOZMainObject.m_MeasureFile.MParam.AutoStigY.UP = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_UP"].ToString());
  1094. FormHOZMainObject.m_MeasureFile.MParam.AutoStigY.Down = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Down"].ToString());
  1095. FormHOZMainObject.m_MeasureFile.MParam.AutoStigY.Step = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Step"].ToString());
  1096. FormHOZMainObject.m_MeasureFile.MParam.AutoStigY.Range = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Range"].ToString());
  1097. FormHOZMainObject.m_MeasureFile.MParam.AutoStigY.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_FStep"].ToString());
  1098. FormHOZMainObject.m_MeasureFile.IsModified = true;
  1099. if (Directory.Exists(FormHOZMainObject.m_MeasureFile.FilePath))//如果已经存在硬盘上要重新保存文件
  1100. {
  1101. FormHOZMainObject.m_MeasureFile.Save();
  1102. }
  1103. }
  1104. private void button1_Click(object sender, EventArgs e)
  1105. {
  1106. //保存测量文件的参数
  1107. SaveMeasureFile();
  1108. }
  1109. #endregion
  1110. }
  1111. }