12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using MeasureData;
- using System.Configuration;
- using FileManager;
- using System.IO;
- using System.Runtime.InteropServices;
- namespace HOZProject
- {
- public partial class UControl_Init : UserControl
- {
- #region 成员变量
- String[] sT;
- String[] firms;
- String[] WPZD;
- String[] WPZF;
- String[] WQGD;
- String[] WQGF;
- String[] WLZ;
- String[] WFIB;
- Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- private FormHOZMain formHOZMain;
- public FormHOZMain FormHOZMainObject { get => formHOZMain; set => formHOZMain = value; }
- //模板路径
- private string readConfigPath;
- public string ReadConfigPath { get => readConfigPath; set => readConfigPath = value; }
- //模板文件默认路径
- private string m_TemplateFilePath;
- #endregion
- #region 构造方法
- public UControl_Init(FormHOZMain formHOZ)
- {
- InitializeComponent();
- FormHOZMainObject = formHOZ;
- }
- #endregion
- #region 窗体加载
- private void UControl_Init_Load(object sender, EventArgs e)
- {
- }
- #endregion
- #region 关闭窗体
- private void btnClose_Click(object sender, EventArgs e)
- {
- Form fParent = this.ParentForm;
- fParent.Close();
- }
- #endregion
- #region 加载切孔文件,生成切孔列表
- private void pbCutHoleFile_Click(object sender, EventArgs e)
- {
- try
- {
- if (FormHOZMainObject.m_MeasureFile == null)
- {
- MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
- {
- MessageBox.Show("导入切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else
- {
- List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
- //文件路径
- string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
- FormHOZMainObject.CreateCutHoleList(ListCutHole);
- //显示导入的切孔数量
- lblCutHoleCount.Text = string.Format("成功导入{0}个切孔", ListCutHole.Count);
- tbCutHoleFilePath.Text = CutHoleFilePath;
- //保存测量文件
- if (FormHOZMainObject.IsSave)
- {
- FormHOZMainObject.m_MeasureFile.Save();
- }
- }
- }
- }
- catch (Exception ex)
- {
- LogManager.LogError(ex.Message);
- }
- }
- #endregion
- #region 根据一个切孔文件,自动计算其他切孔信息
- /// <summary>
- /// 根据一个切孔,自动计算其他切孔信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void pbCutHoleAuto_Click(object sender, EventArgs e)
- {
- try
- {
- if (FormHOZMainObject.m_MeasureFile == null)
- {
- MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
- {
- MessageBox.Show("导入切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else
- {
- List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
- if (ListCutHole != null)
- {
- if (ListCutHole.Count > 0)
- {
- //根据切孔文件的一个切孔,自动计算其他切孔位置
- float centerX = 65;
- float centerY = 65;
- float firstX = ListCutHole[0].Position.X;
- float firstY = ListCutHole[0].Position.Y;
- //距离
- float distance = Convert.ToSingle(config.AppSettings.Settings["distance"].Value.ToString());
- //矩阵 4*4
- int rag = Convert.ToInt32(config.AppSettings.Settings["rag"].Value.ToString());
- List<PointF> cutHolePoint = new List<PointF>();
- //根据一个切孔点计算其他切孔信息
- cutHolePoint = AnalysisPosition(centerX, centerY, firstX, firstY, distance, rag);
- if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromAnalysisPosition(cutHolePoint))
- {
- MessageBox.Show("生成切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else
- {
- //文件路径
- string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
- //重新获取切孔列表信息
- ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
- //创建切孔列表信息
- FormHOZMainObject.CreateCutHoleList(ListCutHole);
- //显示导入的切孔数量
- lblCutHoleCount.Text = string.Format("成功生成{0}个切孔", ListCutHole.Count);
- tbCutHoleFilePath.Text = CutHoleFilePath;
- }
- }
- }
- //保存测量文件
- if (FormHOZMainObject.IsSave)
- {
- FormHOZMainObject.m_MeasureFile.Save();
- }
- }
- }
- }
- catch (Exception ex)
- {
- LogManager.LogError(ex.Message);
- }
- }
- /// <summary>
- /// 分析点坐标
- /// </summary>
- /// <param name="centerX">中心点X轴坐标</param>
- /// <param name="centerY">中心点Y轴坐标</param>
- /// <param name="firstX">第一个点X轴坐标</param>
- /// <param name="firstY">第一个点Y轴坐标</param>
- /// <param name="distance">点与点的距离</param>
- /// <param name="rag">行、列数</param>
- /// <param name="ptsx">计算生成所有X轴坐标</param>
- /// <param name="ptsy">计算生成所有Y轴坐标</param>
- public List<PointF> AnalysisPosition(float centerX, float centerY, float firstX, float firstY, float distance, int rag)
- {
- //求样品1的水平角度
- double angle = 0;
- //清空所有点信息
- List<float> ptsx = new List<float>();
- List<float> ptsy = new List<float>();
- //将第一个点加入到点信息中
- ptsx.Add(firstX);
- ptsy.Add(firstY);
- //计算第一个点与X轴的交角度数
- angle = Math.Atan2(ptsy[0] - centerY, centerX - ptsx[0]) * 180 / Math.PI;
- //这里是求与第一个点横向排列的其他点的移动角度
- //就是按45度向左向右移动的度
- angle = 45 - angle;
- angle = angle * Math.PI / 180;
- float tx = 0;
- float ty = 0;
- for (int j = 0; j < rag; j++)
- {
- //计算每行第一个点的坐标
- if (j > 0)
- {
- tx = (float)(distance * j * Math.Sin(angle));
- ty = (float)(distance * j * Math.Cos(angle));
- ptsx.Add(tx + ptsx[0]);
- ptsy.Add(ptsy[0] - ty);
- }
- //计算每行其他点的坐标
- for (int i = 1; i < rag; i++)
- {
- tx = (float)(distance * i * Math.Cos(angle));
- ty = (float)(distance * i * Math.Sin(angle));
- ptsx.Add(tx + ptsx[j * rag]);
- ptsy.Add(ty + ptsy[j * rag]);
- }
- }
- List<PointF> pts = new List<PointF>();
- for (int i = 0; i < ptsx.Count; i++)
- {
- //增加的点
- PointF pf = new PointF();
- pf.X = ptsx[i];
- pf.Y = ptsy[i];
- pts.Add(pf);
- }
- return pts;
- }
- #endregion
- #region 加载PT模板文件
- private void pbTemplateFile_Click(object sender, EventArgs e)
- {
- string FilePathName;
- string fileNameWithoutExtension;
- //新建一个文件对话框
- OpenFileDialog pOpenFileDialog = new OpenFileDialog();
- //设置对话框标题
- pOpenFileDialog.Title = "选择模板文件";
- //设置打开文件类型
- pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
- ////监测文件是否存在
- //pOpenFileDialog.CheckFileExists = true;
-
- //文件打开后执行以下程序
- if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
- {
- FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
- fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
- this.txtWPTF.Text = FilePathName;
- }
- }
- #endregion
- #region 加载FIB模板文件
- private void pbFIBTemplateFile_Click(object sender, EventArgs e)
- {
- string FilePathName;
- string fileNameWithoutExtension;
- //新建一个文件对话框
- OpenFileDialog pOpenFileDialog = new OpenFileDialog();
- //设置对话框标题
- pOpenFileDialog.Title = "选择模板文件";
- //设置打开文件类型
- pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
- ////监测文件是否存在
- //pOpenFileDialog.CheckFileExists = true;
- //文件打开后执行以下程序
- if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
- {
- FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
- fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
- this.txtWFIBF.Text = FilePathName;
- }
- }
- #endregion
- #region 创建与读取样品参数、配置文件
- private void btnCreateConfig_Click(object sender, EventArgs e)
- {
- if (Convert.ToInt32(cbbWFIB.Text) < 200)
- {
- MessageBox.Show("FIB最小放大倍数为200倍");
- }
- else
- {
- SaveTemplateFile();
- }
- }
- /// <summary>
- /// 获取测量参数,初始化窗体中的控件信息
- /// </summary>
- /// <returns></returns>
- public MeasureParam GetMeasureParamInfo()
- {
- MeasureParam cfm = new MeasureParam();
- cfm.Is_Photograph = chkWIsP.Checked;
- cfm.PT = chkWPT.Checked;
- //自动对焦模式
- //cfm.FocusMode = chkManul.Checked;
- cfm.PTTemp = txtWPTF.Text;
- cfm.FIBTemp = txtWFIBF.Text;
- cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
- cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
- cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
- cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
- cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
- cfm.FIB_Magnification = Convert.ToSingle(cbbWFIB.Text);
- if (cbbWXZ.SelectedIndex == 0)
- {
- cfm.Correction_Angle = 36;
- }
- else
- {
- cfm.Correction_Angle = 54;
- }
- cfm.SampleName = cbbWYP.Text;
- cfm.Firm = cbbWCS.Text;
- return cfm;
- }
- public void SaveTemplateFile()
- {
- MeasureParam cfm = new MeasureParam();
- cfm.Is_Photograph = chkWIsP.Checked;
- cfm.PT = chkWPT.Checked;
- //自动对焦模式
- //cfm.FocusMode = chkManul.Checked;
- cfm.PTTemp = txtWPTF.Text;
- cfm.FIBTemp = txtWFIBF.Text;
- cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
- cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
- cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
- cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
- cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
- cfm.FIB_Magnification = Convert.ToSingle(cbbWFIB.Text);
- if (cbbWXZ.SelectedIndex == 0)
- {
- cfm.Correction_Angle = 36;
- }
- else
- {
- cfm.Correction_Angle = 54;
- }
- cfm.SampleName = cbbWYP.Text;
- cfm.Firm = cbbWCS.Text;
- ConfigFile cf = new ConfigFile(cfm);
- if (!m_TemplateFilePath.Equals(""))
- {
- if (!Directory.Exists(m_TemplateFilePath))
- {
- //创建路径
- //Directory.CreateDirectory(m_TemplateFilePath);
- FolderBrowserDialog dialog = new FolderBrowserDialog();
- dialog.Description = "请选择文件路径";
- //dialog.RootFolder = Environment.SpecialFolder.Programs;
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- m_TemplateFilePath = dialog.SelectedPath;
- config.AppSettings.Settings["TemplateFilePath"].Value = m_TemplateFilePath;
- config.Save(ConfigurationSaveMode.Modified);
- ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
- }
- }
- }
- SaveFileDialog saveFileDialog = new SaveFileDialog();
- //设置默认打开路径(绝对路径)
- saveFileDialog.InitialDirectory = m_TemplateFilePath;
- saveFileDialog.Filter = "样品参数文件|*.cfg";
- if (saveFileDialog.ShowDialog() == DialogResult.OK)
- {
- cf.Save(saveFileDialog.FileName);
- }
- else
- {
- return;
- }
- //编辑Config文件
- EditConfig();
- }
- /// <summary>
- /// 编辑confing 文件信息
- /// </summary>
- public bool EditConfig()
- {
- try
- {
- //设置数据源信息
- //样品类型
- List<String> _sT = sT.ToList();
- if (_sT.IndexOf(cbbWYP.Text) < 0)
- {
- _sT.Add(cbbWYP.Text);
- string wsT = string.Join(",", _sT.ToArray());
- config.AppSettings.Settings["Sample_Type"].Value = wsT;
- }
- //厂商
- List<String> _firms = firms.ToList();
- if (_firms.IndexOf(cbbWCS.Text) < 0)
- {
- _firms.Add(cbbWCS.Text);
- string wFirms = string.Join(",", _firms.ToArray());
- config.AppSettings.Settings["Firm"].Value = wFirms;
- }
- //拍照电压
- List<String> _WPZD = WPZD.ToList();
- if (_WPZD.IndexOf(cbbWPZD.Text) < 0)
- {
- _WPZD.Add(cbbWPZD.Text);
- string wWPZD = string.Join(",", _WPZD.ToArray());
- config.AppSettings.Settings["WPZD"].Value = wWPZD;
- }
- //拍照放大位数
- List<String> _WPZF = WPZF.ToList();
- if (_WPZF.IndexOf(cbbWPZF.Text) < 0)
- {
- _WPZF.Add(cbbWPZF.Text);
- string wWPZF = string.Join(",", _WPZF.ToArray());
- config.AppSettings.Settings["WPZF"].Value = wWPZF;
- }
- //定位切割电压
- List<String> _WQGD = WQGD.ToList();
- if (_WQGD.IndexOf(cbbWQGD.Text) < 0)
- {
- _WQGD.Add(cbbWQGD.Text);
- string wWQGD = string.Join(",", _WQGD.ToArray());
- config.AppSettings.Settings["WQGD"].Value = wWQGD;
- }
- //定位切割放大位数
- List<String> _WQGF = WQGF.ToList();
- if (_WQGF.IndexOf(cbbWQGF.Text) < 0)
- {
- _WQGF.Add(cbbWQGF.Text);
- string wWQGF = string.Join(",", _WQGF.ToArray());
- config.AppSettings.Settings["WQGF"].Value = wWQGF;
- }
- //拉直操作放大位数
- List<String> _WLZ = WLZ.ToList();
- if (_WLZ.IndexOf(cbbWLZ.Text) < 0)
- {
- _WLZ.Add(cbbWLZ.Text);
- string wWLZ = string.Join(",", _WLZ.ToArray());
- config.AppSettings.Settings["WLZ"].Value = wWLZ;
- }
- //FIB放大位数
- List<String> _WFIB = WFIB.ToList();
- if (_WFIB.IndexOf(cbbWFIB.Text) < 0)
- {
- _WFIB.Add(cbbWFIB.Text);
- string wWFIB = string.Join(",", _WFIB.ToArray());
- config.AppSettings.Settings["WFIB"].Value = wWFIB;
- }
- MeasureParam cfm = new MeasureParam();
- cfm.Is_Photograph = chkWIsP.Checked;
-
- cfm.FocusMode = Convert.ToInt32(config.AppSettings.Settings["Focus_Mode"].Value);
- cfm.PT = chkWPT.Checked;
- //自动对焦模式
- //cfm.FocusMode = chkManul.Checked;
- cfm.PTTemp = txtWPTF.Text;
- cfm.FIBTemp = txtWFIBF.Text;
- cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
- cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
- cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
- cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
- cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
- cfm.FIB_Magnification = Convert.ToSingle(cbbWFIB.Text);
- //倾斜观测
- cfm.Title = chkWqxkc.Checked;
- //移动Z轴大小
- cfm.ZDistance = Convert.ToSingle(cbbYDZZDX.Text);
- if (cbbWXZ.SelectedIndex == 0)
- {
- cfm.Correction_Angle = 36;
- }
- else
- {
- cfm.Correction_Angle = 54;
- }
- cfm.SampleName = cbbWYP.Text;
- cfm.Firm = cbbWCS.Text;
- //设置配置文件默认值
- config.AppSettings.Settings["Is_Photograph"].Value = cfm.Is_Photograph.ToString();
- config.AppSettings.Settings["PT_Depostion"].Value = cfm.PT.ToString();
- config.AppSettings.Settings["PT_ELYFile"].Value = cfm.PTTemp;
- config.AppSettings.Settings["FIB_ELYFile"].Value = cfm.FIBTemp;
- config.AppSettings.Settings["Stretch_Magnification"].Value = cfm.Stretch_Magnification.ToString();
- config.AppSettings.Settings["Location_Magnification"].Value = cfm.Location_Magnification.ToString();
- config.AppSettings.Settings["Location_Voltage"].Value = cfm.Location_Voltage.ToString();
- config.AppSettings.Settings["Photograph_Magnification"].Value = cfm.Photograph_Magnification.ToString();
- config.AppSettings.Settings["Photograph_Voltage"].Value = cfm.Photograph_Voltage.ToString();
- config.AppSettings.Settings["Correction_Angle"].Value = cfm.Correction_Angle.ToString();
- config.AppSettings.Settings["SampleName"].Value = cfm.SampleName;
- config.AppSettings.Settings["Firms"].Value = cfm.Firm;
- config.AppSettings.Settings["Is_Title"].Value = cfm.Title.ToString();
- config.AppSettings.Settings["ZDistance"].Value = cfm.ZDistance.ToString();
- config.Save(ConfigurationSaveMode.Modified);
- ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
- return true;
- }
- catch (Exception ex)
- {
- LogManager.LogError(ex.Message);
- return false;
- }
- }
- /// <summary>
- /// 删除config文件节点中内容信息
- /// </summary>
- public bool DelConfigNodeContentInfo(string delControlName, string selName)
- {
- try
- {
- switch (delControlName)
- {
- case "WYP":
- //样品类型
- List<String> _sT = sT.ToList();
- _sT.Remove(selName);
- string wsT = string.Join(",", _sT.ToArray());
- config.AppSettings.Settings["Sample_Type"].Value = wsT;
- break;
- case "WCS":
- //厂商
- List<String> _firms = firms.ToList();
- _firms.Remove(selName);
- string wFirms = string.Join(",", _firms.ToArray());
- config.AppSettings.Settings["Firm"].Value = wFirms;
- break;
- case "WPZD":
- //拍照电压
- List<String> _WPZD = WPZD.ToList();
- _WPZD.Remove(selName);
- string wWPZD = string.Join(",", _WPZD.ToArray());
- config.AppSettings.Settings["WPZD"].Value = wWPZD;
- break;
- case "WPZF":
- //拍照放大位数
- List<String> _WPZF = WPZF.ToList();
- _WPZF.Remove(selName);
- string wWPZF = string.Join(",", _WPZF.ToArray());
- config.AppSettings.Settings["WPZF"].Value = wWPZF;
- break;
- case "WQGD"://定位切割电压
- List<String> _WQGD = WQGD.ToList();
- _WQGD.Remove(selName);
- string wWQGD = string.Join(",", _WQGD.ToArray());
- config.AppSettings.Settings["WQGD"].Value = wWQGD;
- break;
- case "WQGF": //定位切割放大位数
- List<String> _WQGF = WQGF.ToList();
- _WQGF.Remove(selName);
- string wWQGF = string.Join(",", _WQGF.ToArray());
- config.AppSettings.Settings["WQGF"].Value = wWQGF;
- break;
- case "WLZ":
- //拉直操作放大位数
- List<String> _WLZ = WLZ.ToList();
- _WLZ.Remove(selName);
- string wWLZ = string.Join(",", _WLZ.ToArray());
- config.AppSettings.Settings["WLZ"].Value = wWLZ;
- break;
- }
- config.Save(ConfigurationSaveMode.Modified);
- ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
- return true;
- }
- catch (Exception ex)
- {
- LogManager.LogError(ex.Message);
- return true;
- }
- }
- /// <summary>
- /// 绑定下拉菜单
- /// </summary>
- /// <param name="cb"></param>
- /// <param name="strGroup"></param>
- private void BindComboxData(ComboBox cb, string[] strGroup)
- {
- for (int i = 0; i < strGroup.Length; i++)
- {
- if (!strGroup[i].Equals(""))
- {
- cb.Items.Add(strGroup[i]);
- }
- }
- }
- /// <summary>
- /// 读取Config文件信息
- /// </summary>
- public void ReloadConfig()
- {
- cbbWYP.Items.Clear();
- cbbWCS.Items.Clear();
- cbbWPZD.Items.Clear();
- cbbWPZF.Items.Clear();
- cbbWQGD.Items.Clear();
- cbbWQGF.Items.Clear();
- cbbWLZ.Items.Clear();
- cbbWFIB.Items.Clear();
- cbbYDZZDX.Text = "0";
- m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString();
- string sample_Type = config.AppSettings.Settings["Sample_Type"].Value.ToString();
- string firm = config.AppSettings.Settings["Firm"].Value.ToString();
- string WPZDTemp = config.AppSettings.Settings["WPZD"].Value.ToString();
- string WPZFTemp = config.AppSettings.Settings["WPZF"].Value.ToString();
- string WQGDTemp = config.AppSettings.Settings["WQGD"].Value.ToString();
- string WQGFTemp = config.AppSettings.Settings["WQGF"].Value.ToString();
- string WLZTemp = config.AppSettings.Settings["WLZ"].Value.ToString();
- string WFIBTemp = config.AppSettings.Settings["WFIB"].Value.ToString();
- //string ZZDistance = config.AppSettings.Settings["ZDistance"].Value.ToString();
-
-
- //样品类型
- sT = sample_Type.Split(',');
- BindComboxData(cbbWYP, sT);
- //厂商
- firms = firm.Split(',');
- BindComboxData(cbbWCS, firms);
- //拍照电压
- WPZD = WPZDTemp.Split(',');
- BindComboxData(cbbWPZD, WPZD);
- //拍照放大位数
- WPZF = WPZFTemp.Split(',');
- BindComboxData(cbbWPZF, WPZF);
- //定位切割电压
- WQGD = WQGDTemp.Split(',');
- BindComboxData(cbbWQGD, WQGD);
- //定位切割放大位数
- WQGF = WQGFTemp.Split(',');
- BindComboxData(cbbWQGF, WQGF);
- //拉直操作放大位数
- WLZ = WLZTemp.Split(',');
- BindComboxData(cbbWLZ, WLZ);
- //FIB放大倍数
- WFIB = WFIBTemp.Split(',');
- BindComboxData(cbbWFIB, WFIB);
-
- //设置配置文件默认值
- chkWIsP.Checked=Convert.ToBoolean(config.AppSettings.Settings["Is_Photograph"].Value);
- chkWPT.Checked = Convert.ToBoolean(config.AppSettings.Settings["PT_Depostion"].Value);
- //倾斜观测
- chkWqxkc.Checked = Convert.ToBoolean(config.AppSettings.Settings["Is_Title"].Value);
- //移动Z轴大小
- cbbYDZZDX.Text = config.AppSettings.Settings["ZDistance"].Value;
- //自动对焦模式
- //chkManul.Checked = Convert.ToBoolean(config.AppSettings.Settings["Focus_Mode"].Value);
- txtWPTF.Text = config.AppSettings.Settings["PT_ELYFile"].Value;
- txtWFIBF.Text = config.AppSettings.Settings["FIB_ELYFile"].Value;
- cbbWLZ.Text = config.AppSettings.Settings["Stretch_Magnification"].Value;
- cbbWQGF.Text = config.AppSettings.Settings["Location_Magnification"].Value;
- cbbWQGD.Text = config.AppSettings.Settings["Location_Voltage"].Value;
- cbbWPZF.Text = config.AppSettings.Settings["Photograph_Magnification"].Value;
- cbbWPZD.Text = config.AppSettings.Settings["Photograph_Voltage"].Value;
- cbbWFIB.Text = config.AppSettings.Settings["FIB_Magnification"].Value;
- string Correction_Angle = config.AppSettings.Settings["Correction_Angle"].Value;
- if (Convert.ToBoolean(config.AppSettings.Settings["Is_Title"].Value))
- {
- cbbYDZZDX.Visible = true;
- label3.Visible = true;
- }
- else
- {
- cbbYDZZDX.Visible = false;
- label3.Visible = false;
- }
- if (Correction_Angle == "36")
- {
- cbbWXZ.SelectedIndex = 0;
- }
- else
- {
- cbbWXZ.SelectedIndex = 1;
- }
- cbbWYP.Text = config.AppSettings.Settings["SampleName"].Value;
- cbbWCS.Text = config.AppSettings.Settings["Firms"].Value;
- }
- /// <summary>
- /// 根据所选路径,读取模板文件
- /// </summary>
- public void ReadConfigInfo()
- {
- if (!ReadConfigPath.Equals(""))
- {
- ReloadConfig();
- ConfigFile cfm = new ConfigFile(new MeasureParam());
- cfm.Read(ReadConfigPath);
- chkWIsP.Checked = cfm.m_Config.Is_Photograph;
- chkWPT.Checked = cfm.m_Config.PT;
- //自动对焦模式
- //cfm.FocusMode = chkManul.Checked;
- txtWPTF.Text = cfm.m_Config.PTTemp;
- txtWFIBF.Text = cfm.m_Config.FIBTemp;
- cbbWLZ.Text = cfm.m_Config.Stretch_Magnification.ToString();
- cbbWQGF.Text = cfm.m_Config.Location_Magnification.ToString();
- cbbWQGD.Text = cfm.m_Config.Location_Voltage.ToString();
- cbbWPZF.Text = cfm.m_Config.Photograph_Magnification.ToString();
- cbbWPZD.Text = cfm.m_Config.Photograph_Voltage.ToString();
- cbbWFIB.Text = cfm.m_Config.FIB_Magnification.ToString();
- string Correction_Angle = cfm.m_Config.Correction_Angle.ToString();
- if (Correction_Angle == "36")
- {
- cbbWXZ.SelectedIndex = 0;
- }
- else
- {
- cbbWXZ.SelectedIndex = 1;
- }
- cbbWYP.Text = cfm.m_Config.SampleName;
- cbbWCS.Text = cfm.m_Config.Firm;
- }
- }
- /// <summary>
- /// 修改配置文件默认值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSaveDefalutPara_Click(object sender, EventArgs e)
- {
- if (Convert.ToInt32(cbbWFIB.Text) < 200)
- {
- MessageBox.Show("FIB最小放大倍数为200倍");
- }
- else
- {
- if (EditConfig())
- {
- MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- }
- #endregion
- #region 删除下拉菜单选择项
- private void DelComboBoxItem_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("是否删除所选项信息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
- {
- PictureBox pbDel = (PictureBox)sender;
- string ctrlName = pbDel.Name.Substring(5, pbDel.Name.Length - 5);
- if (DelComboBoxItem(ctrlName))
- {
- //重新加载
- ReloadConfig();
- }
- }
- }
- /// <summary>
- /// 删除下拉菜单选择项
- /// </summary>
- public bool DelComboBoxItem(string controlName)
- {
- string delName = controlName;
- foreach (Control item in this.Controls)
- {
- if (item is ComboBox)
- {
- if (item.Name.Contains(delName))
- {
- ComboBox cb = (ComboBox)item;
- return DelConfigNodeContentInfo(delName, cb.Text);
- }
- }
- }
- return false;
- }
- #endregion
- #region 根据是否仅拍照,进行逻辑判断
- private void chkWIsP_CheckedChanged(object sender, EventArgs e)
- {
- if (chkWIsP.Checked)
- {
- chkWPT.Checked = false;
- chkWPT.Visible = false;
- label61.Visible = false;
- label59.Visible = false;
- txtWFIBF.Visible = false;
- txtWPTF.Visible = false;
- pbPTTemplateFile.Visible = false;
- pbFIBTemplateFile.Visible = false;
- label58.Visible = false;
- cbbWXZ.Visible = false;
- label2.Visible = false;
- cbbWFIB.Visible = false;
- FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.Photo;
- }
- else
- {
- chkWPT.Visible = true;
- label61.Visible = true;
- label59.Visible = true;
- txtWFIBF.Visible = true;
- txtWPTF.Visible = true;
- pbPTTemplateFile.Visible = true;
- pbFIBTemplateFile.Visible = true;
- label58.Visible = true;
- cbbWXZ.Visible = true;
- label2.Visible = true;
- cbbWFIB.Visible = true;
- if (!chkWPT.Checked)
- {
- FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
- }
- }
- CreateCutHoleList();
- }
- #endregion
- public MeasureParam GetMeasureParam()
- {
- MeasureParam cfm = new MeasureParam();
- //设置配置文件默认值
- bool bResult = false;
- bool.TryParse(config.AppSettings.Settings["Is_Photograph"].Value, out bResult);
- cfm.Is_Photograph = bResult;
- bool.TryParse(config.AppSettings.Settings["PT_Depostion"].Value, out bResult);
- cfm.PT = bResult;
- cfm.PTTemp = config.AppSettings.Settings["PT_ELYFile"].Value;
- cfm.FIBTemp = config.AppSettings.Settings["FIB_ELYFile"].Value;
- float fResult = (float)0.0;
- float.TryParse(config.AppSettings.Settings["Stretch_Magnification"].Value, out fResult);
- cfm.Stretch_Magnification = fResult;
- float.TryParse(config.AppSettings.Settings["Location_Magnification"].Value, out fResult);
- cfm.Location_Magnification = fResult;
- float.TryParse(config.AppSettings.Settings["Location_Voltage"].Value, out fResult);
- cfm.Location_Voltage = fResult;
- float.TryParse(config.AppSettings.Settings["Photograph_Magnification"].Value, out fResult);
- cfm.Photograph_Magnification = fResult;
- float.TryParse(config.AppSettings.Settings["Photograph_Voltage"].Value, out fResult);
- cfm.Photograph_Voltage = fResult;
- float.TryParse(config.AppSettings.Settings["Correction_Angle"].Value, out fResult);
- cfm.Correction_Angle = fResult;
- cfm.SampleName = config.AppSettings.Settings["SampleName"].Value;
- cfm.Firm = config.AppSettings.Settings["Firms"].Value;
- cfm.AutoFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
- cfm.AutoFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
- cfm.AutoFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
- cfm.AutoFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
- cfm.AutoFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
- cfm.FIBFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
- cfm.FIBFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
- cfm.FIBFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
- cfm.FIBFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
- cfm.FIBFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
- cfm.AutoStigX.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
- cfm.AutoStigX.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
- cfm.AutoStigX.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
- cfm.AutoStigX.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
- cfm.AutoStigX.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
- cfm.AutoStigY.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
- cfm.AutoStigY.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
- cfm.AutoStigY.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
- cfm.AutoStigY.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
- cfm.AutoStigY.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
- bool.TryParse(config.AppSettings.Settings["Is_Title"].Value, out bResult);
- cfm.Title = bResult;
- float.TryParse(config.AppSettings.Settings["ZDistance"].Value, out fResult);
- cfm.ZDistance = fResult;
- return cfm;
- }
- #region 创建切孔列表
- private void CreateCutHoleList()
- {
- List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
- FormHOZMainObject.CreateCutHoleList(ListCutHole);
- }
- #endregion
- #region 设置流程类型
- private void chkWPT_CheckedChanged(object sender, EventArgs e)
- {
- if (chkWPT.Checked)
- {
- FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.PT;
- }
- else
- {
- if (!chkWIsP.Checked)
- {
- FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
- }
- }
- CreateCutHoleList();
- }
- #endregion
- #region 关闭按钮 鼠标操作事件
- private void pbClose_MouseEnter(object sender, EventArgs e)
- {
- pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Red;
- }
- private void pbClose_MouseLeave(object sender, EventArgs e)
- {
- pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Gray;
- }
- #endregion
- #region 输入限制只能是数字
- private void ComboBox_KeyPress(string text, object sender, KeyPressEventArgs e)
- {
- //允许输入数字、小数点、删除键和负号
- if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.') && e.KeyChar != (char)('-'))
- {
- MessageBox.Show("请输入正确的数字");
- text = "";
- e.Handled = true;
- }
- if (e.KeyChar == (char)('-'))
- {
- if (text != "")
- {
- MessageBox.Show("请输入正确的数字");
- text = "";
- e.Handled = true;
- }
- }
- //小数点只能输入一次
- if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text.IndexOf('.') != -1)
- {
- MessageBox.Show("请输入正确的数字");
- text = "";
- e.Handled = true;
- }
- //第一位不能为小数点
- if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text == "")
- {
- MessageBox.Show("请输入正确的数字");
- text = "";
- e.Handled = true;
- }
- //第一位是0,第二位必须为小数点
- if (e.KeyChar != (char)('.') && ((ComboBox)sender).Text == "0")
- {
- MessageBox.Show("请输入正确的数字");
- text = "";
- e.Handled = true;
- }
- //第一位是负号,第二位不能为小数点
- if (((ComboBox)sender).Text == "-" && e.KeyChar == (char)('.'))
- {
- MessageBox.Show("请输入正确的数字");
- text = "";
- e.Handled = true;
- }
- }
- private void cbbWPZD_KeyPress(object sender, KeyPressEventArgs e)
- {
- ComboBox_KeyPress(cbbWPZD.Text, sender, e);
- }
- private void cbbWPZF_KeyPress(object sender, KeyPressEventArgs e)
- {
- ComboBox_KeyPress(cbbWPZF.Text, sender, e);
- }
- private void cbbWQGD_KeyPress(object sender, KeyPressEventArgs e)
- {
- ComboBox_KeyPress(cbbWQGD.Text, sender, e);
- }
- private void cbbWQGF_KeyPress(object sender, KeyPressEventArgs e)
- {
- ComboBox_KeyPress(cbbWQGF.Text, sender, e);
- }
- private void cbbWLZ_KeyPress(object sender, KeyPressEventArgs e)
- {
- ComboBox_KeyPress(cbbWLZ.Text, sender, e);
- }
- private void cbbWFIB_KeyPress(object sender, KeyPressEventArgs e)
- {
- ComboBox_KeyPress(cbbWFIB.Text, sender, e);
- }
- #endregion
- private void chkWqxkc_CheckedChanged(object sender, EventArgs e)
- {
- if (chkWqxkc.Checked)
- {
- label3.Visible = true;
- cbbYDZZDX.Visible = true;
- }
- else
- {
- label3.Visible = false;
- cbbYDZZDX.Visible = false;
- }
- }
- #region 拖动控件
- [DllImportAttribute("user32.dll")]
- private extern static bool ReleaseCapture();
- [DllImportAttribute("user32.dll")]
- private extern static int SendMessage(IntPtr handle, int m, int p, int h);
- private void panelEx4_MouseDown(object sender, MouseEventArgs e)
- {
- //DevComponents.DotNetBar.PanelEx p = (DevComponents.DotNetBar.PanelEx)sender;
- //if (e.Button == MouseButtons.Left)
- //{
- // this.Cursor = Cursors.SizeAll;
- // ReleaseCapture();
- // SendMessage(p.Handle, 0xA1, 0x2, 0); this.Cursor = Cursors.Default;
- //}
- }
- #endregion
- private void cbbYDZZDX_TextChanged(object sender, EventArgs e)
- {
- if (cbbYDZZDX.Text!="")
- {
- if (Convert.ToSingle(cbbYDZZDX.Text)>40)
- {
- MessageBox.Show("数值最大为40");
- cbbYDZZDX.Text = "40";
- }
- }
- else
- {
- cbbYDZZDX.Text = "0";
- }
-
- }
- private void cbbYDZZDX_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
- {
- e.Handled = true;
- }
- }
- }
- }
|