From cea64103ec105ed58a261305315a98122e1494b5 Mon Sep 17 00:00:00 2001 From: Sebastian M Date: Mon, 13 Feb 2023 00:54:14 +0100 Subject: [PATCH] Allow negative test values for stepper (#1144) * Allow negative test values for stepper * Fixed validation check for numbers and negeative numbers --- UI/Panels/Output/StepperPanel.cs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/UI/Panels/Output/StepperPanel.cs b/UI/Panels/Output/StepperPanel.cs index eaad061c3..05dbc6fb6 100644 --- a/UI/Panels/Output/StepperPanel.cs +++ b/UI/Panels/Output/StepperPanel.cs @@ -119,12 +119,20 @@ private void inputRevTextBox_Validating(object sender, CancelEventArgs e) try { - e.Cancel = !(Int16.Parse(value) > 0); + // all boxes should only accept + // positive numbers, + // exception is the test value textbox + var v = Int16.Parse(value); + if (sender != stepperTestValueTextBox) + e.Cancel = !(v > 0); } catch (Exception ex) { e.Cancel = true; + displayError(sender as Control, i18n._tr("uiMessageValidationMustBeNumber")); + return; } + if (e.Cancel) { displayError(sender as Control, i18n._tr("uiMessagePanelsStepperInputRevolutionsMustBeGreaterThan0")); @@ -162,21 +170,16 @@ private void stepperAddressesComboBox_SelectedValueChanged(object sender, EventA internal void SetStepperProfile(StepperProfilePreset profilePreset) { - this.StepperProfile = profilePreset; - if (outputRevTextBox.Text == "") - { - outputRevTextBox.Text = this.StepperProfile.StepsPerRevolution.ToString(); - } - - if (AccelerationTextBox.Text == "") + // we assume that it is safe to update the values + // when we have a different id + if (StepperProfile?.id != profilePreset.id) { - AccelerationTextBox.Text = this.StepperProfile.Acceleration.ToString(); + outputRevTextBox.Text = profilePreset.StepsPerRevolution.ToString(); + AccelerationTextBox.Text = profilePreset.Acceleration.ToString(); + SpeedTextBox.Text = profilePreset.Speed.ToString(); } - if (SpeedTextBox.Text == "") - { - SpeedTextBox.Text = this.StepperProfile.Speed.ToString(); - } + this.StepperProfile = profilePreset; } private void ResetButton_Click(object sender, EventArgs e)