MainForm.cs 8.1 KB

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