using CoreUnit.Common; using CoreUnit.Scanner.UserControl.ScannerCanvas; using System; using System.Windows.Forms; namespace CoreUnit.Scanner.UserControl.Canvas.Dialog { public partial class ZigzagEditorDlg : FormBase { public ZigzagEditorDlg(int selectedIndex) { InitializeComponent(); m_selectedIndex = selectedIndex; if (m_selectedIndex < 1) { m_scannerParam = ScannerCanvasUserCtrl.ScannerParams[0].Clone(); } else { m_scannerParam = ScannerCanvasUserCtrl.ScannerParams[m_selectedIndex - 1].Clone(); } Initialize(); } ScannerParam m_scannerParam; int m_selectedIndex = 0; private void Initialize() { ScannerParamToDialog(); } private void ScannerParamToDialog() { double pitch = m_scannerParam.ZigzagWobbelPitch; double amplitude = m_scannerParam.ZigzagWobbelAmplitude; double radius = m_scannerParam.ZigzagWobbelRadius; double vertexAngle = Math.Atan(pitch / amplitude / 2); double linearVelocity = m_scannerParam.ZigzagWobbelLinearVelocity; textBoxAmplitude.Text = amplitude.ToString("F3"); textBoxPitch.Text = pitch.ToString("F3"); textBoxRadius.Text = radius.ToString("F3"); textBoxLinearVelocity.Text = linearVelocity.ToString("F3"); double lineSpeed = 100; if (!m_scannerParam.CalculateLineSpeed(amplitude, pitch, radius, linearVelocity, out lineSpeed)) { throw new Exception("Fail to calculate line Speed"); } textBoxLineSpeed.Text = lineSpeed.ToString("f3"); textBoxVertexAngle.Text = (vertexAngle * 180 / Math.PI).ToString("f3"); } private void buttonCalculateLineSpeed_Click(object sender, EventArgs e) { try { double pitch = Convert.ToDouble(textBoxPitch.Text); double amplitude = Convert.ToDouble(textBoxAmplitude.Text); double radius = Convert.ToDouble(textBoxRadius.Text); double vertexAngle = Math.Atan(pitch / amplitude / 2); double linearVelocity = Convert.ToDouble(textBoxLinearVelocity.Text); double lineSpeed = 100; if (!m_scannerParam.CalculateLineSpeed(amplitude, pitch, radius, linearVelocity, out lineSpeed)) { throw new Exception("Fail to calculate line Speed"); } textBoxLineSpeed.Text = lineSpeed.ToString("f3"); textBoxVertexAngle.Text = (vertexAngle * 180 / Math.PI).ToString("f3"); } catch { MessageBox.Show("Please Check Paramter"); } } private void textBoxAmplitude_Leave(object sender, EventArgs e) { double amplitude = 0.8; double radius = 0.1; if (double.TryParse(textBoxAmplitude.Text, out amplitude) && double.TryParse(textBoxRadius.Text, out radius)) { if (amplitude < radius * 2) { amplitude = radius * 2; } textBoxAmplitude.Text = amplitude.ToString(); } else { amplitude = radius * 2; textBoxAmplitude.Text = amplitude.ToString(); } } private void textBoxPitch_Leave(object sender, EventArgs e) { double radius = 0.1; double pitch = 0.8; if (double.TryParse(textBoxPitch.Text, out pitch) && double.TryParse(textBoxRadius.Text, out radius)) { if (pitch < radius * 4) { pitch = radius * 4; } textBoxPitch.Text = pitch.ToString(); } else { pitch = radius * 4; textBoxPitch.Text = pitch.ToString(); } } private void textBoxRadius_Leave(object sender, EventArgs e) { double amplitude = 0.8; double radius = 0.1; double pitch = 0.8; if (double.TryParse(textBoxPitch.Text, out pitch) && double.TryParse(textBoxRadius.Text, out radius) && double.TryParse(textBoxAmplitude.Text, out amplitude)) { if (radius > Math.Min(pitch * 0.25, amplitude * 0.5)) { radius = Math.Min(pitch * 0.25, amplitude * 0.5); } textBoxRadius.Text = radius.ToString(); } else { radius = Math.Min(amplitude * 0.5, pitch * 0.25); textBoxRadius.Text = radius.ToString(); } } private void DialogToScannerParam() { try { m_scannerParam.ZigzagWobbelAmplitude = Convert.ToDouble(textBoxAmplitude.Text); m_scannerParam.ZigzagWobbelPitch = Convert.ToDouble(textBoxPitch.Text); m_scannerParam.ZigzagWobbelRadius = Convert.ToDouble(textBoxRadius.Text); m_scannerParam.ZigzagWobbelLinearVelocity = Convert.ToDouble(textBoxLinearVelocity.Text); ScannerCanvasUserCtrl.ScannerParams[m_selectedIndex - 1] = m_scannerParam.Clone(); } catch { MessageBox.Show("Check the Paramter Value"); } } private void btnOk_Click(object sender, EventArgs e) { DialogToScannerParam(); this.DialogResult = DialogResult.OK; this.Close(); } private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } } }