Revise int and double fields
This commit is contained in:
parent
bb3602c3ff
commit
2e343e5af8
5 changed files with 37 additions and 35 deletions
|
|
@ -228,6 +228,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
private void MenuItem_Selected(object sender, EventArgs e)
|
||||
{
|
||||
// When a preset is selected store the current values of all known settings to compare against after applying the preset
|
||||
Dictionary<string, string> settingBeforeChange = new Dictionary<string, string>();
|
||||
foreach (var keyName in PrinterSettings.KnownSettings)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -870,7 +870,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
switch (settingData.DataEditType)
|
||||
{
|
||||
case SliceSettingData.DataEditTypes.INT:
|
||||
uiField = new NumberField();
|
||||
uiField = new IntField();
|
||||
break;
|
||||
|
||||
case SliceSettingData.DataEditTypes.DOUBLE:
|
||||
|
|
@ -886,7 +886,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
else
|
||||
{
|
||||
uiField = new DoubleField();
|
||||
}
|
||||
};
|
||||
break;
|
||||
|
||||
case SliceSettingData.DataEditTypes.DOUBLE_OR_PERCENT:
|
||||
|
|
@ -1003,7 +1003,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
settingsContext.SetValue(settingData.SlicerConfigName, uiField.Value);
|
||||
}
|
||||
|
||||
settingsContext.SetValue(settingData.SlicerConfigName, uiField.Value);
|
||||
settingsRow.UpdateStyle();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,26 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
public class NumberField : BasicField, IUIField
|
||||
public class IntField : NumberField
|
||||
{
|
||||
private int intValue;
|
||||
|
||||
protected override string ConvertValue(string newValue)
|
||||
{
|
||||
decimal.TryParse(this.Value, out decimal currentValue);
|
||||
intValue = (int)currentValue;
|
||||
|
||||
return intValue.ToString();
|
||||
}
|
||||
|
||||
protected override void OnValueChanged(FieldChangedEventArgs fieldChangedEventArgs)
|
||||
{
|
||||
numberEdit.ActuallNumberEdit.Value = intValue;
|
||||
base.OnValueChanged(fieldChangedEventArgs);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class NumberField : BasicField, IUIField
|
||||
{
|
||||
protected MHNumberEdit numberEdit;
|
||||
|
||||
|
|
@ -98,14 +117,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
this.Content = numberEdit;
|
||||
}
|
||||
|
||||
protected override void OnValueChanged(FieldChangedEventArgs fieldChangedEventArgs)
|
||||
{
|
||||
int.TryParse(this.Value, out int currentValue);
|
||||
numberEdit.ActuallNumberEdit.Value = currentValue;
|
||||
|
||||
base.OnValueChanged(fieldChangedEventArgs);
|
||||
}
|
||||
}
|
||||
|
||||
public class TextField : BasicField, IUIField
|
||||
|
|
|
|||
|
|
@ -28,18 +28,27 @@ either expressed or implied, of the FreeBSD Project.
|
|||
*/
|
||||
|
||||
using System;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
public class DoubleField : NumberField
|
||||
{
|
||||
public static int DoubleEditWidth = (int)(60 * GuiWidget.DeviceScale + .5);
|
||||
private double doubleValue;
|
||||
|
||||
public void OnValueChanged(string text)
|
||||
protected override string ConvertValue(string newValue)
|
||||
{
|
||||
double.TryParse(text, out double currentValue);
|
||||
numberEdit.ActuallNumberEdit.Value = currentValue;
|
||||
double.TryParse(newValue, out double currentValue);
|
||||
doubleValue = (int)currentValue;
|
||||
|
||||
return doubleValue.ToString();
|
||||
}
|
||||
|
||||
protected override void OnValueChanged(FieldChangedEventArgs fieldChangedEventArgs)
|
||||
{
|
||||
numberEdit.ActuallNumberEdit.Value = doubleValue;
|
||||
base.OnValueChanged(fieldChangedEventArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,25 +33,6 @@ using MatterHackers.Agg.UI;
|
|||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
|
||||
public class DoubleOrMmField : ValueOrUnitsField
|
||||
{
|
||||
protected override string ConvertValue(string newValue)
|
||||
{
|
||||
string text = newValue.Trim();
|
||||
|
||||
int tokenIndex = text.IndexOf(unitsToken);
|
||||
bool hasUnitsToken = tokenIndex != -1;
|
||||
if (hasUnitsToken)
|
||||
{
|
||||
text = text.Substring(0, tokenIndex);
|
||||
}
|
||||
|
||||
double.TryParse(text, out double currentValue);
|
||||
return currentValue + (hasUnitsToken ? unitsToken : "");
|
||||
}
|
||||
}
|
||||
|
||||
public class BoundDoubleField : TextField
|
||||
{
|
||||
private const string ValuesDifferToken = "-";
|
||||
|
|
@ -82,6 +63,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
// If this setting sets other settings, then do that.
|
||||
if (ChangesMultipleOtherSettings)
|
||||
{
|
||||
// Iterate over each bound setting pushing the current value into each
|
||||
for (int i = 0; i < settingData.SetSettingsOnChange.Count; i++)
|
||||
{
|
||||
string slicerConfigName = settingData.SetSettingsOnChange[i]["TargetSetting"];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue