UControl_Init.cs 60 KB

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