CameraAutomaticDepth.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. using System;
  2. using System.Drawing;
  3. using System.Threading;
  4. using System.Windows.Forms;
  5. using OpenCvSharp;
  6. using PaintDotNet.Camera;
  7. using StageController;
  8. namespace PaintDotNet.ImageCollect.CameraEDOF
  9. {
  10. /// <summary>
  11. /// 自动景深扩展
  12. /// </summary>
  13. internal class CameraAutomaticDepth : FloatingToolForm
  14. {
  15. /// <summary>
  16. /// Required designer variable.
  17. /// </summary>
  18. private System.ComponentModel.IContainer components = null;
  19. /// <summary>
  20. /// Clean up any resources being used.
  21. /// </summary>
  22. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  23. protected override void Dispose(bool disposing)
  24. {
  25. if (disposing && (components != null))
  26. {
  27. components.Dispose();
  28. }
  29. base.Dispose(disposing);
  30. }
  31. #region Windows Form Designer generated code
  32. private void InitializeLanguageText()
  33. {
  34. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  35. this.btnCreatImgFile.Text = PdnResources.GetString("Menu.Createpicture.text");
  36. this.btnWorking.Text = PdnResources.GetString("Menu.Started.text");
  37. this.groupBox2.Text = PdnResources.GetString("Menu.paramssettings.text");
  38. this.rdoMod2.Text = PdnResources.GetString("Menu.Model2.Text");
  39. this.rdoMod1.Text = PdnResources.GetString("Menu.imagecapture.Autoeldexpansion.patternone.text");
  40. this.groupBox4.Text = PdnResources.GetString("Menu.ImageCollection.AutomaticDepth.Text");
  41. this.label1.Text = PdnResources.GetString("Menu.imagecapture.Autoeldexpansion.Shootingmode.text") + ":";
  42. this.Text = PdnResources.GetString("Menu.ImageCollection.AutomaticDepth.Text");
  43. this.groupBox3.Text = PdnResources.GetString("Menu.Preview.text");
  44. }
  45. /// <summary>
  46. /// Required method for Designer support - do not modify
  47. /// the contents of this method with the code editor.
  48. /// </summary>
  49. private void InitializeComponent()
  50. {
  51. this.groupBox1 = new System.Windows.Forms.GroupBox();
  52. this.btnZClear = new System.Windows.Forms.Button();
  53. this.btnCreatImgFile = new System.Windows.Forms.Button();
  54. this.btnWorking = new System.Windows.Forms.Button();
  55. this.groupBox2 = new System.Windows.Forms.GroupBox();
  56. this.controlPanel = new System.Windows.Forms.Panel();
  57. this.rdoMod2 = new System.Windows.Forms.RadioButton();
  58. this.rdoMod1 = new System.Windows.Forms.RadioButton();
  59. this.label1 = new System.Windows.Forms.Label();
  60. this.splitContainer1 = new System.Windows.Forms.SplitContainer();
  61. this.groupBox3 = new System.Windows.Forms.GroupBox();
  62. this.picPreview = new System.Windows.Forms.PictureBox();
  63. this.groupBox4 = new System.Windows.Forms.GroupBox();
  64. this.picDepth = new System.Windows.Forms.PictureBox();
  65. this.groupBox1.SuspendLayout();
  66. this.groupBox2.SuspendLayout();
  67. ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
  68. this.splitContainer1.Panel1.SuspendLayout();
  69. this.splitContainer1.Panel2.SuspendLayout();
  70. this.splitContainer1.SuspendLayout();
  71. this.groupBox3.SuspendLayout();
  72. ((System.ComponentModel.ISupportInitialize)(this.picPreview)).BeginInit();
  73. this.groupBox4.SuspendLayout();
  74. ((System.ComponentModel.ISupportInitialize)(this.picDepth)).BeginInit();
  75. this.SuspendLayout();
  76. //
  77. // groupBox1
  78. //
  79. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  80. | System.Windows.Forms.AnchorStyles.Right)));
  81. this.groupBox1.Controls.Add(this.btnZClear);
  82. this.groupBox1.Controls.Add(this.btnCreatImgFile);
  83. this.groupBox1.Controls.Add(this.btnWorking);
  84. this.groupBox1.Location = new System.Drawing.Point(9, 10);
  85. this.groupBox1.Margin = new System.Windows.Forms.Padding(2);
  86. this.groupBox1.Name = "groupBox1";
  87. this.groupBox1.Padding = new System.Windows.Forms.Padding(2);
  88. this.groupBox1.Size = new System.Drawing.Size(935, 70);
  89. this.groupBox1.TabIndex = 0;
  90. this.groupBox1.TabStop = false;
  91. this.groupBox1.Text = "操作";
  92. //
  93. // btnZClear
  94. //
  95. this.btnZClear.Location = new System.Drawing.Point(661, 24);
  96. this.btnZClear.Name = "btnZClear";
  97. this.btnZClear.Size = new System.Drawing.Size(75, 23);
  98. this.btnZClear.TabIndex = 2;
  99. this.btnZClear.Text = "Z Clear";
  100. this.btnZClear.UseVisualStyleBackColor = true;
  101. this.btnZClear.Click += new System.EventHandler(this.btnZClear_Click);
  102. //
  103. // btnCreatImgFile
  104. //
  105. this.btnCreatImgFile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  106. this.btnCreatImgFile.Location = new System.Drawing.Point(852, 22);
  107. this.btnCreatImgFile.Margin = new System.Windows.Forms.Padding(2);
  108. this.btnCreatImgFile.Name = "btnCreatImgFile";
  109. this.btnCreatImgFile.Size = new System.Drawing.Size(69, 27);
  110. this.btnCreatImgFile.TabIndex = 1;
  111. this.btnCreatImgFile.Text = "创建图片";
  112. this.btnCreatImgFile.UseVisualStyleBackColor = true;
  113. this.btnCreatImgFile.Click += new System.EventHandler(this.btnCreatImgFile_Click);
  114. //
  115. // btnWorking
  116. //
  117. this.btnWorking.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  118. this.btnWorking.Location = new System.Drawing.Point(758, 22);
  119. this.btnWorking.Margin = new System.Windows.Forms.Padding(2);
  120. this.btnWorking.Name = "btnWorking";
  121. this.btnWorking.Size = new System.Drawing.Size(67, 27);
  122. this.btnWorking.TabIndex = 0;
  123. this.btnWorking.Text = "开始";
  124. this.btnWorking.UseVisualStyleBackColor = true;
  125. this.btnWorking.Click += new System.EventHandler(this.btnWorking_Click);
  126. //
  127. // groupBox2
  128. //
  129. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  130. | System.Windows.Forms.AnchorStyles.Left)));
  131. this.groupBox2.Controls.Add(this.controlPanel);
  132. this.groupBox2.Controls.Add(this.rdoMod2);
  133. this.groupBox2.Controls.Add(this.rdoMod1);
  134. this.groupBox2.Controls.Add(this.label1);
  135. this.groupBox2.Location = new System.Drawing.Point(9, 94);
  136. this.groupBox2.Margin = new System.Windows.Forms.Padding(2);
  137. this.groupBox2.Name = "groupBox2";
  138. this.groupBox2.Padding = new System.Windows.Forms.Padding(2);
  139. this.groupBox2.Size = new System.Drawing.Size(295, 420);
  140. this.groupBox2.TabIndex = 1;
  141. this.groupBox2.TabStop = false;
  142. this.groupBox2.Text = "参数设置";
  143. //
  144. // controlPanel
  145. //
  146. this.controlPanel.Location = new System.Drawing.Point(4, 59);
  147. this.controlPanel.Margin = new System.Windows.Forms.Padding(2);
  148. this.controlPanel.Name = "controlPanel";
  149. this.controlPanel.Size = new System.Drawing.Size(281, 350);
  150. this.controlPanel.TabIndex = 3;
  151. //
  152. // rdoMod2
  153. //
  154. this.rdoMod2.AutoSize = true;
  155. this.rdoMod2.Location = new System.Drawing.Point(164, 30);
  156. this.rdoMod2.Margin = new System.Windows.Forms.Padding(2);
  157. this.rdoMod2.Name = "rdoMod2";
  158. this.rdoMod2.Size = new System.Drawing.Size(14, 13);
  159. this.rdoMod2.TabIndex = 2;
  160. this.rdoMod2.UseVisualStyleBackColor = true;
  161. this.rdoMod2.Visible = false;
  162. this.rdoMod2.CheckedChanged += new System.EventHandler(this.rdoMod2_CheckedChanged);
  163. //
  164. // rdoMod1
  165. //
  166. this.rdoMod1.AutoSize = true;
  167. this.rdoMod1.Checked = true;
  168. this.rdoMod1.Location = new System.Drawing.Point(90, 29);
  169. this.rdoMod1.Margin = new System.Windows.Forms.Padding(2);
  170. this.rdoMod1.Name = "rdoMod1";
  171. this.rdoMod1.Size = new System.Drawing.Size(14, 13);
  172. this.rdoMod1.TabIndex = 1;
  173. this.rdoMod1.TabStop = true;
  174. this.rdoMod1.UseVisualStyleBackColor = true;
  175. this.rdoMod1.CheckedChanged += new System.EventHandler(this.rdoMod1_CheckedChanged);
  176. //
  177. // label1
  178. //
  179. this.label1.AutoSize = true;
  180. this.label1.Location = new System.Drawing.Point(16, 30);
  181. this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
  182. this.label1.Name = "label1";
  183. this.label1.Size = new System.Drawing.Size(0, 12);
  184. this.label1.TabIndex = 0;
  185. //
  186. // splitContainer1
  187. //
  188. this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  189. | System.Windows.Forms.AnchorStyles.Left)
  190. | System.Windows.Forms.AnchorStyles.Right)));
  191. this.splitContainer1.Location = new System.Drawing.Point(309, 91);
  192. this.splitContainer1.Margin = new System.Windows.Forms.Padding(2);
  193. this.splitContainer1.Name = "splitContainer1";
  194. //
  195. // splitContainer1.Panel1
  196. //
  197. this.splitContainer1.Panel1.Controls.Add(this.groupBox3);
  198. //
  199. // splitContainer1.Panel2
  200. //
  201. this.splitContainer1.Panel2.Controls.Add(this.groupBox4);
  202. this.splitContainer1.Size = new System.Drawing.Size(636, 427);
  203. this.splitContainer1.SplitterDistance = 279;
  204. this.splitContainer1.SplitterWidth = 3;
  205. this.splitContainer1.TabIndex = 4;
  206. //
  207. // groupBox3
  208. //
  209. this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  210. | System.Windows.Forms.AnchorStyles.Left)
  211. | System.Windows.Forms.AnchorStyles.Right)));
  212. this.groupBox3.Controls.Add(this.picPreview);
  213. this.groupBox3.Location = new System.Drawing.Point(2, 2);
  214. this.groupBox3.Margin = new System.Windows.Forms.Padding(2);
  215. this.groupBox3.Name = "groupBox3";
  216. this.groupBox3.Padding = new System.Windows.Forms.Padding(2);
  217. this.groupBox3.Size = new System.Drawing.Size(274, 422);
  218. this.groupBox3.TabIndex = 3;
  219. this.groupBox3.TabStop = false;
  220. this.groupBox3.Text = "预览";
  221. //
  222. // picPreview
  223. //
  224. this.picPreview.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  225. | System.Windows.Forms.AnchorStyles.Right)));
  226. this.picPreview.Location = new System.Drawing.Point(15, 59);
  227. this.picPreview.Margin = new System.Windows.Forms.Padding(2);
  228. this.picPreview.Name = "picPreview";
  229. this.picPreview.Size = new System.Drawing.Size(247, 338);
  230. this.picPreview.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
  231. this.picPreview.TabIndex = 0;
  232. this.picPreview.TabStop = false;
  233. //
  234. // groupBox4
  235. //
  236. this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  237. | System.Windows.Forms.AnchorStyles.Left)
  238. | System.Windows.Forms.AnchorStyles.Right)));
  239. this.groupBox4.Controls.Add(this.picDepth);
  240. this.groupBox4.Location = new System.Drawing.Point(2, 2);
  241. this.groupBox4.Margin = new System.Windows.Forms.Padding(2);
  242. this.groupBox4.Name = "groupBox4";
  243. this.groupBox4.Padding = new System.Windows.Forms.Padding(2);
  244. this.groupBox4.Size = new System.Drawing.Size(355, 422);
  245. this.groupBox4.TabIndex = 4;
  246. this.groupBox4.TabStop = false;
  247. this.groupBox4.Text = "自动景深扩展";
  248. //
  249. // picDepth
  250. //
  251. this.picDepth.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  252. | System.Windows.Forms.AnchorStyles.Right)));
  253. this.picDepth.Location = new System.Drawing.Point(13, 59);
  254. this.picDepth.Margin = new System.Windows.Forms.Padding(2);
  255. this.picDepth.Name = "picDepth";
  256. this.picDepth.Size = new System.Drawing.Size(327, 338);
  257. this.picDepth.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
  258. this.picDepth.TabIndex = 1;
  259. this.picDepth.TabStop = false;
  260. //
  261. // CameraAutomaticDepth
  262. //
  263. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  264. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  265. this.ClientSize = new System.Drawing.Size(953, 523);
  266. this.Controls.Add(this.splitContainer1);
  267. this.Controls.Add(this.groupBox2);
  268. this.Controls.Add(this.groupBox1);
  269. this.Margin = new System.Windows.Forms.Padding(2);
  270. this.Name = "CameraAutomaticDepth";
  271. this.Text = "自动景深扩展";
  272. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.CameraAutomaticDepth_FormClosing);
  273. this.Load += new System.EventHandler(this.CameraAutomaticDepth_Load);
  274. this.Controls.SetChildIndex(this.groupBox1, 0);
  275. this.Controls.SetChildIndex(this.groupBox2, 0);
  276. this.Controls.SetChildIndex(this.splitContainer1, 0);
  277. this.groupBox1.ResumeLayout(false);
  278. this.groupBox2.ResumeLayout(false);
  279. this.groupBox2.PerformLayout();
  280. this.splitContainer1.Panel1.ResumeLayout(false);
  281. this.splitContainer1.Panel2.ResumeLayout(false);
  282. ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
  283. this.splitContainer1.ResumeLayout(false);
  284. this.groupBox3.ResumeLayout(false);
  285. ((System.ComponentModel.ISupportInitialize)(this.picPreview)).EndInit();
  286. this.groupBox4.ResumeLayout(false);
  287. ((System.ComponentModel.ISupportInitialize)(this.picDepth)).EndInit();
  288. this.ResumeLayout(false);
  289. }
  290. #endregion
  291. #region 控件
  292. private System.Windows.Forms.GroupBox groupBox1;
  293. private System.Windows.Forms.Button btnCreatImgFile;
  294. private System.Windows.Forms.Button btnWorking;
  295. private System.Windows.Forms.GroupBox groupBox2;
  296. private System.Windows.Forms.RadioButton rdoMod2;
  297. private System.Windows.Forms.RadioButton rdoMod1;
  298. private System.Windows.Forms.Label label1;
  299. private System.Windows.Forms.Panel controlPanel;
  300. private System.Windows.Forms.SplitContainer splitContainer1;
  301. private System.Windows.Forms.GroupBox groupBox3;
  302. private System.Windows.Forms.PictureBox picPreview;
  303. private System.Windows.Forms.GroupBox groupBox4;
  304. private System.Windows.Forms.PictureBox picDepth;
  305. #endregion
  306. private AppWorkspace m_appWorkspace;
  307. // 已移动次数
  308. private int m_moveTimes;
  309. // 当前位置
  310. private double m_currentStep => m_Stage.Z;
  311. private ICamera m_camera => CameraManager.CurrentCamera;
  312. private AxisController m_Stage;
  313. private ParameterOneControl m_parameterOne;
  314. private bool m_isWorking;
  315. private Mat m_matClone;
  316. private Mat[] Coll_Ori = new Mat[2];
  317. private Mat m_merge;
  318. private Button btnZClear;
  319. public CameraAutomaticDepth(AppWorkspace appWorkspace)
  320. {
  321. this.m_appWorkspace = appWorkspace;
  322. // this.DoubleBuffered = true;//设置本窗体
  323. //SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  324. //SetStyle(ControlStyles.UserPaint, true);
  325. //SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
  326. //SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
  327. InitializeComponent();
  328. InitializeLanguageText();
  329. }
  330. /// <summary>
  331. /// 加载数据
  332. /// </summary>
  333. public void InitializeData()
  334. {
  335. try
  336. {
  337. m_Stage = AxisController.GetInstance();
  338. CameraManager.FrameCallback += CallbackDraw;
  339. // 默认选中显示模式一
  340. rdoMod1.Checked = true;
  341. controlPanel.Controls.Clear();
  342. m_parameterOne = new ParameterOneControl(m_Stage);
  343. controlPanel.Controls.Add(m_parameterOne);
  344. }
  345. catch (Exception ex)
  346. {
  347. MessageBox.Show(ex.Message);
  348. }
  349. }
  350. private void CameraAutomaticDepth_Load(object sender, EventArgs e)
  351. {
  352. InitializeData();
  353. }
  354. object obj = new object();
  355. /// <summary>
  356. /// 绘制
  357. /// </summary>
  358. /// <param name="pBuf"></param>
  359. /// <param name="obj"></param>
  360. public void CallbackDraw(Bitmap frame)
  361. {
  362. if (frame == null)
  363. return;
  364. m_matClone = PaintDotNet.Camera.Tools.ToMat(frame);
  365. picPreview.Image = (Image)frame.Clone();
  366. }
  367. private void rdoMod1_CheckedChanged(object sender, EventArgs e)
  368. {
  369. controlPanel.Controls.Clear();
  370. ParameterOneControl parameterOne = new ParameterOneControl(m_Stage);
  371. controlPanel.Controls.Add(parameterOne);
  372. }
  373. private void rdoMod2_CheckedChanged(object sender, EventArgs e)
  374. {
  375. controlPanel.Controls.Clear();
  376. ParameterTwoControl parameterTwo = new ParameterTwoControl();
  377. controlPanel.Controls.Add(parameterTwo);
  378. }
  379. private void CameraAutomaticDepth_FormClosing(object sender, FormClosingEventArgs e)
  380. {
  381. CameraManager.FrameCallback -= CallbackDraw;
  382. }
  383. private void btnWorking_Click(object sender, EventArgs e)
  384. {
  385. m_merge = null;
  386. try
  387. {
  388. if (!m_camera.IsOpen())
  389. {
  390. MessageBox.Show(PdnResources.GetString("Menu.merafoundpleaseconfirthatthecameraisconne.Text"));
  391. return;
  392. }
  393. if (m_isWorking)
  394. {
  395. StopWorking();
  396. return;
  397. }
  398. if (m_parameterOne.StopPos == 0 || m_parameterOne.StartPos == 0)
  399. {
  400. MessageBox.Show(PdnResources.GetString("Menu.Pleasesetthestartandstoppositions2.Text"));
  401. return;
  402. }
  403. // 重新自动计算,防止没有手动点击计算
  404. m_parameterOne.Calculate();
  405. var zscanparm = m_parameterOne.ZScanParameter;
  406. m_Stage.ZScan(zscanparm.Start, zscanparm.Track, zscanparm.Times, Shooting, null, StopWorking);
  407. m_isWorking = true;
  408. btnWorking.Text = PdnResources.GetString("Menu.stop.text");
  409. m_moveTimes = 0;
  410. // 禁用控件
  411. m_parameterOne.Enabled = false;
  412. }
  413. catch (Exception ex)
  414. {
  415. MessageBox.Show(ex.Message);
  416. }
  417. }
  418. private void StopWorking()
  419. {
  420. m_Stage.FreeZ();
  421. m_isWorking = false;
  422. this.Invoke(new Action(() =>
  423. {
  424. // 更改控件状态
  425. m_parameterOne.Enabled = true;
  426. btnWorking.Text = PdnResources.GetString("Menu.Started.text");
  427. }));
  428. }
  429. int m_captureWait = 200;
  430. private void Shooting()
  431. {
  432. Thread.Sleep(m_captureWait);
  433. // 修改拍摄高度
  434. this.Invoke(new Action(() =>
  435. {
  436. m_parameterOne.updatelblHeight(m_currentStep);
  437. }));
  438. if (m_merge == null)
  439. {
  440. m_merge = m_matClone;
  441. }
  442. else
  443. {
  444. Coll_Ori[1] = m_matClone;
  445. Coll_Ori[0] = m_merge;
  446. m_merge = Merge.GetMergeMatForCamera(Coll_Ori);
  447. }
  448. picDepth.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(m_merge);
  449. GC.Collect();
  450. ++m_moveTimes;
  451. if (m_moveTimes == m_parameterOne.Times)
  452. {
  453. // StopWorking();
  454. return;
  455. }
  456. }
  457. #region 等待机制
  458. bool _waitFlag = false;
  459. private void ResetWait()
  460. { _waitFlag = false; }
  461. private void Wait()
  462. {
  463. _waitFlag = true;
  464. while (_waitFlag)
  465. {
  466. Thread.Sleep(100);
  467. }
  468. }
  469. #endregion
  470. private void btnCreatImgFile_Click(object sender, EventArgs e)
  471. {
  472. if (m_merge == null)
  473. {
  474. MessageBox.Show(PdnResources.GetString("Menu.ofimageshavenotyetbeengene.Text"));
  475. return;
  476. }
  477. DocumentWorkspace dw = m_appWorkspace.AddNewDocumentWorkspace();
  478. Document document = Document.FromImageMat(m_merge.Clone());
  479. dw.Document = document;
  480. dw.xmlSaveModel = Startup.instance.ruleDB;
  481. dw.InitRulerInfo();
  482. m_appWorkspace.ActiveDocumentWorkspace = dw;
  483. }
  484. #region StageEvents
  485. public void OnUpdatePosition()
  486. {
  487. try //可能出现窗口销毁后回调
  488. {
  489. if (!this.IsDisposed)
  490. this.Invoke(new Action(() =>
  491. {
  492. m_parameterOne.PositionZ = m_Stage.Z;
  493. }));
  494. }
  495. catch { }
  496. }
  497. public void OnTimeoutConnect()
  498. {
  499. StopWorking();
  500. MessageBox.Show(PdnResources.GetString("Menu.Theconsoleresponsetimeout.Text"));
  501. }
  502. public void OnErrorSend()
  503. {
  504. StopWorking();
  505. MessageBox.Show(PdnResources.GetString("Menu.Replydataarsingerror.Text"));
  506. }
  507. #endregion
  508. private void btnZClear_Click(object sender, EventArgs e)
  509. {
  510. m_Stage.ClearPosZ();
  511. }
  512. }
  513. }