MainForm.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using MeasureData;
  11. using MeasureThread;
  12. namespace WindowsFormsApp1
  13. {
  14. public partial class MainForm : Form
  15. {
  16. #region 成员变量
  17. private BackgroundWorker m_BackgroundWorker;// 申明后台对象
  18. /// <summary>
  19. /// 测量文件
  20. /// </summary>
  21. public MeasureFile m_MeasureFile;
  22. /// 测量线程
  23. public Measure m_Ms;
  24. #endregion
  25. #region 构造函数
  26. public MainForm()
  27. {
  28. InitializeComponent();
  29. m_BackgroundWorker = new BackgroundWorker(); // 实例化后台对象
  30. m_BackgroundWorker.WorkerReportsProgress = true; // 设置可以通告进度
  31. m_BackgroundWorker.WorkerSupportsCancellation = true; // 设置可以取消
  32. m_BackgroundWorker.DoWork += new DoWorkEventHandler(DoWork);
  33. m_BackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(UpdateProgress);
  34. m_BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedWork);
  35. }
  36. #endregion
  37. #region 测量线程
  38. void DoWork(object sender, DoWorkEventArgs e)
  39. {
  40. m_Ms = new Measure();
  41. m_Ms.InitMeas(m_MeasureFile);
  42. m_Ms.SendThreadStatus += new ThreadStatusHandler(displayMessage); //注册事件
  43. //自动测量的全过程
  44. m_Ms.DoMeasure();
  45. //定位
  46. //切割
  47. //分析位置
  48. //截面
  49. }
  50. public void displayMessage(object sender, ThreadStatusEventArgs e)
  51. {
  52. //主界面显示内容
  53. this.BeginInvoke((Action)delegate
  54. {
  55. this.LogText.Text += e.Time.ToString() + e.State + "\n";
  56. });
  57. }
  58. void UpdateProgress(object sender, ProgressChangedEventArgs e)
  59. {
  60. }
  61. void CompletedWork(object sender, RunWorkerCompletedEventArgs e)
  62. {
  63. }
  64. #endregion
  65. #region 按钮操作
  66. /// <summary>
  67. /// 新建文件
  68. /// </summary>
  69. /// <param name="sender"></param>
  70. /// <param name="e"></param>
  71. private void btnNewFile_Click(object sender, EventArgs e)
  72. {
  73. m_MeasureFile = new MeasureFile();
  74. if (!m_MeasureFile.New())
  75. {
  76. return;
  77. }
  78. else
  79. {
  80. MessageBox.Show("新建测量文件成功。");
  81. }
  82. }
  83. /// <summary>
  84. /// 保存文件
  85. /// </summary>
  86. /// <param name="sender"></param>
  87. /// <param name="e"></param>
  88. private void btnSaveFile_Click(object sender, EventArgs e)
  89. {
  90. if (m_MeasureFile == null)
  91. {
  92. MessageBox.Show("请新建一个测量文件");
  93. }
  94. else
  95. {
  96. m_MeasureFile.Save();
  97. }
  98. }
  99. /// <summary>
  100. /// 打开文件
  101. /// </summary>
  102. /// <param name="sender"></param>
  103. /// <param name="e"></param>
  104. private void btnOpenFile_Click(object sender, EventArgs e)
  105. {
  106. }
  107. /// <summary>
  108. /// 停止
  109. /// </summary>
  110. /// <param name="sender"></param>
  111. /// <param name="e"></param>
  112. private void button4_Click(object sender, EventArgs e)
  113. {
  114. if (m_BackgroundWorker.IsBusy)
  115. {
  116. m_BackgroundWorker.CancelAsync();
  117. }
  118. }
  119. /// <summary>
  120. /// 加载切割孔
  121. /// </summary>
  122. /// <param name="sender"></param>
  123. /// <param name="e"></param>
  124. private void btnLoadCutHoles_Click(object sender, EventArgs e)
  125. {
  126. if (m_MeasureFile == null)
  127. {
  128. MessageBox.Show("请新建一个测量文件");
  129. }
  130. else
  131. {
  132. if (!m_MeasureFile.GetCutHolesFromFile(""))
  133. {
  134. MessageBox.Show("导入切孔失败");
  135. }
  136. this.CutHoleGridView.Rows.Clear();
  137. List<CutHole> listHoles = m_MeasureFile.ListCutHole;
  138. foreach (CutHole hole in listHoles)
  139. {
  140. //在CutHoleGridView中,添加切孔信息
  141. int index = this.CutHoleGridView.Rows.Add();
  142. this.CutHoleGridView.Rows[index].Cells[0].Value = hole.HoleName;
  143. SemPosition pos = hole.Position;
  144. this.CutHoleGridView.Rows[index].Cells[1].Value = pos.X;
  145. this.CutHoleGridView.Rows[index].Cells[2].Value = pos.Y;
  146. this.CutHoleGridView.Rows[index].Cells[3].Value = pos.Z;
  147. this.CutHoleGridView.Rows[index].Cells[4].Value = pos.M;
  148. this.CutHoleGridView.Rows[index].Cells[5].Value = pos.R;
  149. this.CutHoleGridView.Rows[index].Cells[6].Value = pos.T;
  150. }
  151. }
  152. }
  153. /// <summary>
  154. /// 启动
  155. /// </summary>
  156. /// <param name="sender"></param>
  157. /// <param name="e"></param>
  158. private void button3_Click(object sender, EventArgs e)
  159. {
  160. if (m_MeasureFile == null)
  161. {
  162. MessageBox.Show("请新建一个测量文件");
  163. }
  164. else
  165. {
  166. if (m_BackgroundWorker.IsBusy)
  167. {
  168. MessageBox.Show("线程已经运行");
  169. return;
  170. }
  171. m_BackgroundWorker.RunWorkerAsync(this);
  172. }
  173. }
  174. /// <summary>
  175. /// 调区FIB模板
  176. /// </summary>
  177. /// <param name="sender"></param>
  178. /// <param name="e"></param>
  179. private void btFIB_Click(object sender, EventArgs e)
  180. {
  181. string FilePathName;
  182. string fileNameWithoutExtension;
  183. //新建一个文件对话框
  184. OpenFileDialog pOpenFileDialog = new OpenFileDialog();
  185. //设置对话框标题
  186. pOpenFileDialog.Title = "选择模板文件";
  187. //设置打开文件类型
  188. pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
  189. //监测文件是否存在
  190. pOpenFileDialog.CheckFileExists = true;
  191. //文件打开后执行以下程序
  192. if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
  193. {
  194. FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
  195. fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
  196. this.tBFIBTemp.Text = fileNameWithoutExtension;
  197. }
  198. }
  199. private void btParamOK_Click(object sender, EventArgs e)
  200. {
  201. if (m_MeasureFile == null)
  202. {
  203. MessageBox.Show("请新建一个测量文件");
  204. this.LogText.Text += "请新建一个测量文件";
  205. }
  206. else
  207. {
  208. m_MeasureFile.MParam.PT = this.cBIsPT.Checked;
  209. m_MeasureFile.MParam.SampleName = this.tBSampleName.Text;
  210. m_MeasureFile.MParam.FIBTemp = this.tBFIBTemp.Text;
  211. m_MeasureFile.MParam.FocusMode = this.cBIsManul.Checked;
  212. MessageBox.Show("参数设置成功");
  213. }
  214. }
  215. #endregion
  216. //定位操作
  217. private void button5_Click(object sender, EventArgs e)
  218. {
  219. }
  220. //切割操作
  221. private void button6_Click(object sender, EventArgs e)
  222. {
  223. }
  224. //分析位置操作
  225. private void button7_Click(object sender, EventArgs e)
  226. {
  227. }
  228. //观测截面
  229. private void button1_Click(object sender, EventArgs e)
  230. {
  231. }
  232. }
  233. }