123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- 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;// 申明后台对象
- /// <summary>
- /// 测量文件
- /// </summary>
- 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 按钮操作
- /// <summary>
- /// 新建文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnNewFile_Click(object sender, EventArgs e)
- {
- m_MeasureFile = new MeasureFile();
- if (!m_MeasureFile.New())
- {
- return;
- }
- else
- {
- MessageBox.Show("新建测量文件成功。");
- }
- }
- /// <summary>
- /// 保存文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSaveFile_Click(object sender, EventArgs e)
- {
- if (m_MeasureFile == null)
- {
- MessageBox.Show("请新建一个测量文件");
- }
- else
- {
- m_MeasureFile.Save();
- }
- }
- /// <summary>
- /// 打开文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnOpenFile_Click(object sender, EventArgs e)
- {
- }
- /// <summary>
- /// 停止
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- if (m_BackgroundWorker.IsBusy)
- {
- m_BackgroundWorker.CancelAsync();
- }
- }
- /// <summary>
- /// 加载切割孔
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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<CutHole> 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;
- }
- }
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 调区FIB模板
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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)
- {
- }
- }
- }
|