From 8964c599196499b58d6a6d842e17529edf2daece Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sat, 13 Jan 2018 11:38:46 -0800 Subject: [PATCH] Clamp extruder_count - Issue MatterHackers/MCCentral#2616 Add extruder count constraints --- SlicerConfiguration/SliceSettingsWidget.cs | 11 ++++++++++- SlicerConfiguration/UIFields/IntField.cs | 12 ++++++++++-- Submodules/agg-sharp | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/SlicerConfiguration/SliceSettingsWidget.cs b/SlicerConfiguration/SliceSettingsWidget.cs index 92cc2e237..9560791c7 100644 --- a/SlicerConfiguration/SliceSettingsWidget.cs +++ b/SlicerConfiguration/SliceSettingsWidget.cs @@ -469,7 +469,16 @@ namespace MatterHackers.MatterControl.SlicerConfiguration switch (settingData.DataEditType) { case SliceSettingData.DataEditTypes.INT: - uiField = new IntField(); + + var intField = new IntField(); + uiField = intField; + + if (settingData.SlicerConfigName == "extruder_count") + { + intField.MaxValue = 4; + intField.MinValue = 0; + } + break; case SliceSettingData.DataEditTypes.DOUBLE: diff --git a/SlicerConfiguration/UIFields/IntField.cs b/SlicerConfiguration/UIFields/IntField.cs index d258b71ca..c5ade67d5 100644 --- a/SlicerConfiguration/UIFields/IntField.cs +++ b/SlicerConfiguration/UIFields/IntField.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2017, Lars Brubaker, John Lewin +Copyright (c) 2018, Lars Brubaker, John Lewin All rights reserved. Redistribution and use in source and binary forms, with or without @@ -27,6 +27,7 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ +using System; namespace MatterHackers.MatterControl.SlicerConfiguration { @@ -34,10 +35,17 @@ namespace MatterHackers.MatterControl.SlicerConfiguration { private int intValue; + public int MinValue { get; set; } = int.MinValue; + + public int MaxValue { get; set; } = int.MaxValue; + protected override string ConvertValue(string newValue) { decimal.TryParse(newValue, out decimal currentValue); - intValue = (int)currentValue; + + // Clamp to range + intValue = Math.Min((int)currentValue, this.MaxValue); + intValue = Math.Max(intValue, this.MinValue); return intValue.ToString(); } diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 62ffc915f..e28826c49 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 62ffc915f217c8a2232810fb4f567f9b4b1009f3 +Subproject commit e28826c49a73ed885dd459b4631f021d6d26406c