using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PaintDotNet.Base.SettingModel;
using StageController;
using OpenCvSharp;
using System.Threading;
using System.Timers;
using PaintDotNet.Annotation.ImageCollect;
namespace PaintDotNet.ImageCollect.CameraEDOF
{
public partial class ParameterOneControl : UserControl
{
private LoadingStageModel m_loadingStageModel = Startup.instance.loadingStageModel;
private double _steppingZ => double.Parse(m_loadingStageModel.SteppingZ);
private double m_start;
public double StartPos
{
get => m_start;
set
{
m_start = value;
txtStart.Text = value.ToString("f3");
}
}
private double m_stop;
public double StopPos
{
get => m_stop;
set
{
m_stop = value;
txtStop.Text = value.ToString("f3");
}
}
public int Times
{
get => (int)(nudLayers.Value);
set
{
nudLayers.Value = value;
}
}
private double m_track;
public double Track
{
get => m_track * m_scale;
set
{
m_track = value;
txtDistance.Text = Math.Abs(m_track).ToString("F3");
}
}
///
/// 拍摄高度
///
public double PositionZ
{
set
{
lblHeight.Text = value.ToString("f3");
}
}
private int m_scale = 1;
public ZScanParameter ZScanParameter =>
new ZScanParameter() { Start = StartPos, Stop = StopPos, Times = Times, Track = Track };
private AxisController m_Stage;
private void InitializeLanguageText()
{
this.btnStartPos.Text = PdnResources.GetString("Menu.Start.text") + ":";
this.btnStopPos.Text = PdnResources.GetString("Menu.Cutoff.text") + ":";
this.label10.Text = PdnResources.GetString("Menu.Micron.text");
this.label9.Text = PdnResources.GetString("Menu.Shootingheight.text") + ":";
this.btnCalculate.Text = PdnResources.GetString("Menu.compute.text");
this.label6.Text = PdnResources.GetString("Menu.Layerspacing(micron).text") + ":";
this.label5.Text = PdnResources.GetString("Menu.Numberofshootinglayers.text") + ":";
this.label4.Text = PdnResources.GetString("Menu.Micron.text");
this.label3.Text = PdnResources.GetString("Menu.Micron.text");
}
private void InitializeButtonBackgroundImage()
{
btnContinuityUp.FlatStyle = FlatStyle.Flat;
btnContinuityUp.FlatAppearance.BorderSize = 0;
btnContinuityUp.BackgroundImageLayout = ImageLayout.Zoom;
btnContinuityUp.BackgroundImage = PdnResources.GetImageResource("Images.ButtonUp.png").Reference;
btnContinuityLower.FlatStyle = FlatStyle.Flat;
btnContinuityLower.FlatAppearance.BorderSize = 0;
btnContinuityLower.BackgroundImageLayout = ImageLayout.Zoom;
btnContinuityLower.BackgroundImage = PdnResources.GetImageResource("Images.ButtonDown.png").Reference;
}
public ParameterOneControl(AxisController axisController, ZScanParameter zscan = null)
{
m_Stage = axisController;
InitializeComponent();
InitializeLanguageText();
InitializeButtonBackgroundImage();
btnContinuityLower.MouseDown += btnContinuityLower_Start;
btnContinuityLower.MouseUp += btnZStop_Click;
btnContinuityUp.MouseDown += btnContinuityUp_Start;
btnContinuityUp.MouseUp += btnZStop_Click;
if (zscan != null)
{
StartPos = zscan.Start;
StopPos = zscan.Stop;
Times = zscan.Times;
Track = zscan.Track;
}
}
private void btnStartPos_Click(object sender, EventArgs e)
{
StartPos = m_Stage.Z;
}
private void btnStopPos_Click(object sender, EventArgs e)
{
StopPos = m_Stage.Z;
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
lblFix.Text = (trackBar1.Value * 25).ToString() + "%";
}
private void btnCalculate_Click(object sender, EventArgs e)
{
Calculate();
}
// 计算
public void Calculate()
{
if (Times < 2) Track = 0;
var len1 = (StopPos - StartPos) / (Times - 1);
var steps = Math.Ceiling(len1 / _steppingZ);
Track = steps * _steppingZ;
}
#region Z 运动
///
/// Z轴连续向上移动
///
///
///
protected virtual void btnContinuityUp_Start(object sender, EventArgs e)
{
m_Stage.GoTop(true);
}
///
/// Z轴连续向下移动
///
///
///
protected virtual void btnContinuityLower_Start(object sender, EventArgs e)
{
m_Stage.GoTop(false);
}
protected virtual void btnZStop_Click(object sender, EventArgs e)
{
m_Stage.FreeZ();
}
#endregion
public void updatelblHeight(double height)
{
lblHeight.Text = height.ToString("f3");
}
}
}