using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MeasureData; using MeasureThread; namespace WindowsFormsApp1 { public partial class MainForm : Form { #region 成员变量 private BackgroundWorker m_BackgroundWorker;// 申明后台对象 /// /// 测量文件 /// public MeasureFile m_MeasureFile; /// 测量线程 public Measure m_Ms; #endregion #region 构造函数 public MainForm() { InitializeComponent(); m_BackgroundWorker = new BackgroundWorker(); // 实例化后台对象 m_BackgroundWorker.WorkerReportsProgress = true; // 设置可以通告进度 m_BackgroundWorker.WorkerSupportsCancellation = true; // 设置可以取消 m_BackgroundWorker.DoWork += new DoWorkEventHandler(DoWork); m_BackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(UpdateProgress); m_BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedWork); } #endregion #region 测量线程 void DoWork(object sender, DoWorkEventArgs e) { m_Ms = new Measure(); m_Ms.InitMeas(m_MeasureFile); m_Ms.SendThreadStatus += new ThreadStatusHandler(displayMessage); //注册事件 //自动测量的全过程 m_Ms.DoMeasure(); //定位 //切割 //分析位置 //截面 } public void displayMessage(object sender, ThreadStatusEventArgs e) { //主界面显示内容 this.BeginInvoke((Action)delegate { this.LogText.Text += e.Time.ToString() + e.State + "\n"; }); } void UpdateProgress(object sender, ProgressChangedEventArgs e) { } void CompletedWork(object sender, RunWorkerCompletedEventArgs e) { } #endregion #region 按钮操作 /// /// 新建文件 /// /// /// private void btnNewFile_Click(object sender, EventArgs e) { m_MeasureFile = new MeasureFile(); if (!m_MeasureFile.New()) { return; } else { MessageBox.Show("新建测量文件成功。"); } } /// /// 保存文件 /// /// /// private void btnSaveFile_Click(object sender, EventArgs e) { if (m_MeasureFile == null) { MessageBox.Show("请新建一个测量文件"); } else { m_MeasureFile.Save(); } } /// /// 打开文件 /// /// /// private void btnOpenFile_Click(object sender, EventArgs e) { } /// /// 停止 /// /// /// private void button4_Click(object sender, EventArgs e) { if (m_BackgroundWorker.IsBusy) { m_BackgroundWorker.CancelAsync(); } } /// /// 加载切割孔 /// /// /// private void btnLoadCutHoles_Click(object sender, EventArgs e) { if (m_MeasureFile == null) { MessageBox.Show("请新建一个测量文件"); } else { if (!m_MeasureFile.GetCutHolesFromFile("")) { MessageBox.Show("导入切孔失败"); } this.CutHoleGridView.Rows.Clear(); List listHoles = m_MeasureFile.ListCutHole; foreach (CutHole hole in listHoles) { //在CutHoleGridView中,添加切孔信息 int index = this.CutHoleGridView.Rows.Add(); this.CutHoleGridView.Rows[index].Cells[0].Value = hole.HoleName; SemPosition pos = hole.Position; this.CutHoleGridView.Rows[index].Cells[1].Value = pos.X; this.CutHoleGridView.Rows[index].Cells[2].Value = pos.Y; this.CutHoleGridView.Rows[index].Cells[3].Value = pos.Z; this.CutHoleGridView.Rows[index].Cells[4].Value = pos.M; this.CutHoleGridView.Rows[index].Cells[5].Value = pos.R; this.CutHoleGridView.Rows[index].Cells[6].Value = pos.T; } } } /// /// 启动 /// /// /// private void button3_Click(object sender, EventArgs e) { if (m_MeasureFile == null) { MessageBox.Show("请新建一个测量文件"); } else { if (m_BackgroundWorker.IsBusy) { MessageBox.Show("线程已经运行"); return; } m_BackgroundWorker.RunWorkerAsync(this); } } /// /// 调区FIB模板 /// /// /// private void btFIB_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.tBFIBTemp.Text = fileNameWithoutExtension; } } private void btParamOK_Click(object sender, EventArgs e) { if (m_MeasureFile == null) { MessageBox.Show("请新建一个测量文件"); this.LogText.Text += "请新建一个测量文件"; } else { m_MeasureFile.MParam.PT = this.cBIsPT.Checked; m_MeasureFile.MParam.SampleName = this.tBSampleName.Text; m_MeasureFile.MParam.FIBTemp = this.tBFIBTemp.Text; m_MeasureFile.MParam.FocusMode = this.cBIsManul.Checked; MessageBox.Show("参数设置成功"); } } #endregion //定位操作 private void button5_Click(object sender, EventArgs e) { } //切割操作 private void button6_Click(object sender, EventArgs e) { } //分析位置操作 private void button7_Click(object sender, EventArgs e) { } //观测截面 private void button1_Click(object sender, EventArgs e) { } } }