MainForm.cs 8.8 KB

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