ParameterOneControl.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using PaintDotNet.Base.SettingModel;
  11. using StageController;
  12. using OpenCvSharp;
  13. using System.Threading;
  14. using System.Timers;
  15. using PaintDotNet.Annotation.ImageCollect;
  16. namespace PaintDotNet.ImageCollect.CameraEDOF
  17. {
  18. public partial class ParameterOneControl : UserControl
  19. {
  20. private LoadingStageModel m_loadingStageModel = Startup.instance.loadingStageModel;
  21. private double _steppingZ => double.Parse(m_loadingStageModel.SteppingZ);
  22. private double m_start;
  23. public double StartPos
  24. {
  25. get => m_start;
  26. set
  27. {
  28. m_start = value;
  29. txtStart.Text = value.ToString("f3");
  30. }
  31. }
  32. private double m_stop;
  33. public double StopPos
  34. {
  35. get => m_stop;
  36. set
  37. {
  38. m_stop = value;
  39. txtStop.Text = value.ToString("f3");
  40. }
  41. }
  42. public int Times
  43. {
  44. get => (int)(nudLayers.Value);
  45. set
  46. {
  47. nudLayers.Value = value;
  48. }
  49. }
  50. private double m_track;
  51. public double Track
  52. {
  53. get => m_track * m_scale;
  54. set
  55. {
  56. m_track = value;
  57. txtDistance.Text = Math.Abs(m_track).ToString("F3");
  58. }
  59. }
  60. /// <summary>
  61. /// 拍摄高度
  62. /// </summary>
  63. public double PositionZ
  64. {
  65. set
  66. {
  67. lblHeight.Text = value.ToString("f3");
  68. }
  69. }
  70. private int m_scale = 1;
  71. public ZScanParameter ZScanParameter =>
  72. new ZScanParameter() { Start = StartPos, Stop = StopPos, Times = Times, Track = Track };
  73. private AxisController m_Stage;
  74. private void InitializeLanguageText()
  75. {
  76. this.btnStartPos.Text = PdnResources.GetString("Menu.Start.text") + ":";
  77. this.btnStopPos.Text = PdnResources.GetString("Menu.Cutoff.text") + ":";
  78. this.label10.Text = PdnResources.GetString("Menu.Micron.text");
  79. this.label9.Text = PdnResources.GetString("Menu.Shootingheight.text") + ":";
  80. this.btnCalculate.Text = PdnResources.GetString("Menu.compute.text");
  81. this.label6.Text = PdnResources.GetString("Menu.Layerspacing(micron).text") + ":";
  82. this.label5.Text = PdnResources.GetString("Menu.Numberofshootinglayers.text") + ":";
  83. this.label4.Text = PdnResources.GetString("Menu.Micron.text");
  84. this.label3.Text = PdnResources.GetString("Menu.Micron.text");
  85. }
  86. private void InitializeButtonBackgroundImage()
  87. {
  88. btnContinuityUp.FlatStyle = FlatStyle.Flat;
  89. btnContinuityUp.FlatAppearance.BorderSize = 0;
  90. btnContinuityUp.BackgroundImageLayout = ImageLayout.Zoom;
  91. btnContinuityUp.BackgroundImage = PdnResources.GetImageResource("Images.ButtonUp.png").Reference;
  92. btnContinuityLower.FlatStyle = FlatStyle.Flat;
  93. btnContinuityLower.FlatAppearance.BorderSize = 0;
  94. btnContinuityLower.BackgroundImageLayout = ImageLayout.Zoom;
  95. btnContinuityLower.BackgroundImage = PdnResources.GetImageResource("Images.ButtonDown.png").Reference;
  96. }
  97. public ParameterOneControl(AxisController axisController, ZScanParameter zscan = null)
  98. {
  99. m_Stage = axisController;
  100. InitializeComponent();
  101. InitializeLanguageText();
  102. InitializeButtonBackgroundImage();
  103. btnContinuityLower.MouseDown += btnContinuityLower_Start;
  104. btnContinuityLower.MouseUp += btnZStop_Click;
  105. btnContinuityUp.MouseDown += btnContinuityUp_Start;
  106. btnContinuityUp.MouseUp += btnZStop_Click;
  107. if (zscan != null)
  108. {
  109. StartPos = zscan.Start;
  110. StopPos = zscan.Stop;
  111. Times = zscan.Times;
  112. Track = zscan.Track;
  113. }
  114. }
  115. private void btnStartPos_Click(object sender, EventArgs e)
  116. {
  117. StartPos = m_Stage.Z;
  118. }
  119. private void btnStopPos_Click(object sender, EventArgs e)
  120. {
  121. StopPos = m_Stage.Z;
  122. }
  123. private void trackBar1_Scroll(object sender, EventArgs e)
  124. {
  125. lblFix.Text = (trackBar1.Value * 25).ToString() + "%";
  126. }
  127. private void btnCalculate_Click(object sender, EventArgs e)
  128. {
  129. Calculate();
  130. }
  131. // 计算
  132. public void Calculate()
  133. {
  134. if (Times < 2) Track = 0;
  135. var len1 = (StopPos - StartPos) / (Times - 1);
  136. var steps = Math.Ceiling(len1 / _steppingZ);
  137. Track = steps * _steppingZ;
  138. }
  139. #region Z 运动
  140. /// <summary>
  141. /// Z轴连续向上移动
  142. /// </summary>
  143. /// <param name="sender"></param>
  144. /// <param name="e"></param>
  145. protected virtual void btnContinuityUp_Start(object sender, EventArgs e)
  146. {
  147. m_Stage.GoTop(true);
  148. }
  149. /// <summary>
  150. /// Z轴连续向下移动
  151. /// </summary>
  152. /// <param name="sender"></param>
  153. /// <param name="e"></param>
  154. protected virtual void btnContinuityLower_Start(object sender, EventArgs e)
  155. {
  156. m_Stage.GoTop(false);
  157. }
  158. protected virtual void btnZStop_Click(object sender, EventArgs e)
  159. {
  160. m_Stage.FreeZ();
  161. }
  162. #endregion
  163. public void updatelblHeight(double height)
  164. {
  165. lblHeight.Text = height.ToString("f3");
  166. }
  167. }
  168. }