From b18f8fc88909c0861234244e247e9f2dcb690249 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Wed, 10 Aug 2016 14:04:33 -0700 Subject: [PATCH 01/23] Made the name save in settings editor changed layername to a settings key --- SetupWizard/ImportSettingsPage.cs | 14 +++--- .../Settings/PrinterSettingsLayer.cs | 4 +- .../Settings/ProfileMigrations.cs | 2 +- .../Settings/SettingsHelpers.cs | 1 + .../SlicePresetsWindow/SlicePresetsWindow.cs | 7 +-- SlicerConfiguration/SliceSettingsWidget.cs | 49 ++++++------------- Submodules/MatterSlice | 2 +- Submodules/agg-sharp | 2 +- .../MatterControl/OemProfileTests.cs | 6 +-- 9 files changed, 34 insertions(+), 53 deletions(-) diff --git a/SetupWizard/ImportSettingsPage.cs b/SetupWizard/ImportSettingsPage.cs index 016383ad3..80d17f0d7 100644 --- a/SetupWizard/ImportSettingsPage.cs +++ b/SetupWizard/ImportSettingsPage.cs @@ -197,7 +197,7 @@ namespace MatterHackers.MatterControl HashSet skipKeys = new HashSet { - "layer_name", + SettingsKey.layer_name, "layer_id", }; @@ -225,9 +225,9 @@ namespace MatterHackers.MatterControl } } - if (!isMergeIntoUserLayer && material.ContainsKey("layer_name")) + if (!isMergeIntoUserLayer && material.ContainsKey(SettingsKey.layer_name)) { - destinationLayer["layer_name"] = material["layer_name"]; + destinationLayer[SettingsKey.layer_name] = material[SettingsKey.layer_name]; } } else if (selectedQuality > -1) @@ -242,9 +242,9 @@ namespace MatterHackers.MatterControl } } - if (!isMergeIntoUserLayer && quality.ContainsKey("layer_name")) + if (!isMergeIntoUserLayer && quality.ContainsKey(SettingsKey.layer_name)) { - destinationLayer["layer_name"] = quality["layer_name"]; + destinationLayer[SettingsKey.layer_name] = quality[SettingsKey.layer_name]; } } else @@ -268,7 +268,7 @@ namespace MatterHackers.MatterControl string successMessage = importPrinterSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath)); if (!isMergeIntoUserLayer) { - string sourceName = isMergeIntoUserLayer ? Path.GetFileNameWithoutExtension(settingsFilePath) : destinationLayer["layer_name"]; + string sourceName = isMergeIntoUserLayer ? Path.GetFileNameWithoutExtension(settingsFilePath) : destinationLayer[SettingsKey.layer_name]; successMessage = ImportSettingsPage.importSettingSuccessMessage.FormatWith(sourceName, sectionName); } @@ -464,7 +464,7 @@ namespace MatterHackers.MatterControl { case ProfileManager.ProfileExtension: newLayer = new PrinterSettingsLayer(); - newLayer["layer_name"] = Path.GetFileNameWithoutExtension(settingsFilePath); + newLayer[SettingsKey.layer_name] = Path.GetFileNameWithoutExtension(settingsFilePath); if (newQualityPresetButton.Checked) { diff --git a/SlicerConfiguration/Settings/PrinterSettingsLayer.cs b/SlicerConfiguration/Settings/PrinterSettingsLayer.cs index 049a7e396..5eda94dfe 100644 --- a/SlicerConfiguration/Settings/PrinterSettingsLayer.cs +++ b/SlicerConfiguration/Settings/PrinterSettingsLayer.cs @@ -73,11 +73,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration { get { - return ValueOrDefault("layer_name"); + return ValueOrDefault(SettingsKey.layer_name); } set { - this["layer_name"] = value; + this[SettingsKey.layer_name] = value; } } diff --git a/SlicerConfiguration/Settings/ProfileMigrations.cs b/SlicerConfiguration/Settings/ProfileMigrations.cs index 0881c4695..bb67b0c23 100644 --- a/SlicerConfiguration/Settings/ProfileMigrations.cs +++ b/SlicerConfiguration/Settings/ProfileMigrations.cs @@ -215,7 +215,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration break; case "MatterControl.LayerName": - layer.Add("layer_name", item.Value); + layer.Add(SettingsKey.layer_name, item.Value); break; case "MatterControl.LayerID": diff --git a/SlicerConfiguration/Settings/SettingsHelpers.cs b/SlicerConfiguration/Settings/SettingsHelpers.cs index ced8becbd..1a6172f9b 100644 --- a/SlicerConfiguration/Settings/SettingsHelpers.cs +++ b/SlicerConfiguration/Settings/SettingsHelpers.cs @@ -89,6 +89,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public const string spiral_vase = nameof(spiral_vase); public const string start_gcode = nameof(start_gcode); public const string oem_profile_token = nameof(oem_profile_token); + public const string layer_name = nameof(layer_name); }; public class SettingsHelpers diff --git a/SlicerConfiguration/SlicePresetsWindow/SlicePresetsWindow.cs b/SlicerConfiguration/SlicePresetsWindow/SlicePresetsWindow.cs index 6c5dbe689..174c43dee 100644 --- a/SlicerConfiguration/SlicePresetsWindow/SlicePresetsWindow.cs +++ b/SlicerConfiguration/SlicePresetsWindow/SlicePresetsWindow.cs @@ -136,10 +136,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration presetNameInput.ActualTextEditWidget.EditComplete += (s, e) => { - if (!this.Focused && this.Text != initialPresetName) - { - presetsContext.PersistenceLayer.Name = presetNameInput.Text; - } + ActiveSliceSettings.Instance.SetValue(SettingsKey.layer_name, presetNameInput.Text, presetsContext.PersistenceLayer); }; topRow.AddChild(presetNameInput); @@ -197,7 +194,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration UiThread.RunOnIdle(() => { string sanitizedName = numberMatch.Replace(presetNameInput.Text, "").Trim(); - string newProfileName = GetNonCollidingName(sanitizedName, presetsContext.PresetLayers.Select(preset => preset.ValueOrDefault("layer_name"))); + string newProfileName = GetNonCollidingName(sanitizedName, presetsContext.PresetLayers.Select(preset => preset.ValueOrDefault(SettingsKey.layer_name))); var clonedLayer = presetsContext.PersistenceLayer.Clone(); clonedLayer.Name = newProfileName; diff --git a/SlicerConfiguration/SliceSettingsWidget.cs b/SlicerConfiguration/SliceSettingsWidget.cs index 1013464e8..c4c152079 100644 --- a/SlicerConfiguration/SliceSettingsWidget.cs +++ b/SlicerConfiguration/SliceSettingsWidget.cs @@ -837,7 +837,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration }; intEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { - SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString(), persistenceLayer); + ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString(), persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); @@ -874,7 +874,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration }; doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { - SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString(), persistenceLayer); + ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString(), persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); @@ -945,12 +945,12 @@ namespace MatterHackers.MatterControl.SlicerConfiguration { foreach (string setting in settingData.SetSettingsOnChange) { - SaveSetting(setting, numberEdit.Value.ToString() + "mm", persistenceLayer); + ActiveSliceSettings.Instance.SetValue(setting, numberEdit.Value.ToString() + "mm", persistenceLayer); } } // also always save to the local setting - SaveSetting(settingData.SlicerConfigName, numberEdit.Value.ToString(), persistenceLayer); + ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, numberEdit.Value.ToString(), persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; @@ -987,7 +987,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration }; doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { - SaveSetting(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString(), persistenceLayer); + ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString(), persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); }; @@ -1030,7 +1030,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration text += "%"; } textEditWidget.Text = text; - SaveSetting(settingData.SlicerConfigName, textEditWidget.Text, persistenceLayer); + ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, textEditWidget.Text, persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); @@ -1105,7 +1105,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration textEditWidget.Text = text; startingText = stringEdit.Text; } - SaveSetting(settingData.SlicerConfigName, textEditWidget.Text, persistenceLayer); + ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, textEditWidget.Text, persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); @@ -1167,7 +1167,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration checkBoxWidget.Click += (sender, e) => { bool isChecked = ((CheckBox)sender).Checked; - SaveSetting(settingData.SlicerConfigName, isChecked ? "1" : "0", persistenceLayer); + ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, isChecked ? "1" : "0", persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); @@ -1192,7 +1192,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { - SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text, persistenceLayer); + ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, ((TextEditWidget)sender).Text, persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); @@ -1217,7 +1217,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { - SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text.Replace("\n", "\\n"), persistenceLayer); + ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, ((TextEditWidget)sender).Text.Replace("\n", "\\n"), persistenceLayer); settingsRow.UpdateStyle(); OnSettingsChanged(settingData); @@ -1286,7 +1286,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration newItem.Selected += (sender, e) => { MenuItem menuItem = ((MenuItem)sender); - SaveSetting(settingData.SlicerConfigName, menuItem.Text, persistenceLayer); + ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, menuItem.Text, persistenceLayer); settingsRow.UpdateStyle(); @@ -1317,7 +1317,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration checkBoxWidget.CheckedStateChanged += (sender, e) => { bool isChecked = ((CheckBox)sender).Checked; - SaveSetting(settingData.SlicerConfigName, isChecked ? "1" : "0", persistenceLayer); + ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, isChecked ? "1" : "0", persistenceLayer); settingsRow.UpdateStyle(); @@ -1362,7 +1362,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { - SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString(), persistenceLayer); + ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString(), persistenceLayer); settingsRow.UpdateStyle(); @@ -1377,7 +1377,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { - SaveSetting(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString(), persistenceLayer); + ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, xEditWidget.ActuallNumberEdit.Value.ToString() + "," + yEditWidget.ActuallNumberEdit.Value.ToString(), persistenceLayer); settingsRow.UpdateStyle(); @@ -1654,7 +1654,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration newItem.Selected += (sender, e) => { - SaveSetting(settingData.SlicerConfigName, valueLocal, persistenceLayer); + ActiveSliceSettings.Instance.SetValue(settingData.SlicerConfigName, valueLocal, persistenceLayer); OnSettingsChanged(settingData); internalTextWidget.Text = valueLocal; internalTextWidget.OnEditComplete(null); @@ -1726,24 +1726,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration } string newValue = string.Join(",", settings); - SaveSetting(slicerConfigName, newValue, persistenceLayer); - } - - protected void ReloadOptions(object sender, EventArgs e) - { - ApplicationController.Instance.ReloadAdvancedControlsPanel(); - } - - private static void SaveSetting(string name, string value, PrinterSettingsLayer persistenceLayer) - { - if (persistenceLayer == null) - { - ActiveSliceSettings.Instance.SetValue(name, value); - } - else - { - ActiveSliceSettings.Instance.SetValue(name, value, persistenceLayer); - } + ActiveSliceSettings.Instance.SetValue(slicerConfigName, newValue, persistenceLayer); } public override void OnDraw(Graphics2D graphics2D) diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index 0b4f2cd53..718e75cc6 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit 0b4f2cd533b66b436fda27cb64b96588d17dd3e2 +Subproject commit 718e75cc668e22ddf282091c02caa5a8e7a1bba9 diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 10849d735..5f0626862 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 10849d735d861506c3189f8c1f2ed58bc8e02936 +Subproject commit 5f0626862c0dab00a901fa9724a536cd3a784e82 diff --git a/Tests/MatterControl.Tests/MatterControl/OemProfileTests.cs b/Tests/MatterControl.Tests/MatterControl/OemProfileTests.cs index 9dbbaec66..d0406167c 100644 --- a/Tests/MatterControl.Tests/MatterControl/OemProfileTests.cs +++ b/Tests/MatterControl.Tests/MatterControl/OemProfileTests.cs @@ -189,9 +189,9 @@ namespace MatterControl.Tests.MatterControl { ValidateOnAllPrinters((printer, settings) => { - if (settings.OemLayer.ContainsKey("layer_name")) + if (settings.OemLayer.ContainsKey(SettingsKey.layer_name)) { - if (settings.OemLayer["layer_name"].ToUpper() == "ABS") + if (settings.OemLayer[SettingsKey.layer_name].ToUpper() == "ABS") { double absDensity = settings.GetValue(SettingsKey.filament_density); if (absDensity != 1.04) @@ -199,7 +199,7 @@ namespace MatterControl.Tests.MatterControl Assert.Fail("[filament_density] value should be set to ABS 1.04: " + printer.RelativeFilePath); } } - else if (settings.OemLayer["layer_name"].ToUpper() == "PLA") + else if (settings.OemLayer[SettingsKey.layer_name].ToUpper() == "PLA") { double absDensity = settings.GetValue(SettingsKey.filament_density); if (absDensity != 1.24) From e4a10442c22a43a8f6371963b3e5420485532fd3 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Wed, 10 Aug 2016 14:20:52 -0700 Subject: [PATCH 02/23] Made the drop list name update interactively. --- .../SettingsControlSelectors.cs | 21 +++++++++++++++++++ .../SlicePresetsWindow/SlicePresetsWindow.cs | 12 ++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/SlicerConfiguration/SettingsControlSelectors.cs b/SlicerConfiguration/SettingsControlSelectors.cs index 392ed0fc6..f1098bc86 100644 --- a/SlicerConfiguration/SettingsControlSelectors.cs +++ b/SlicerConfiguration/SettingsControlSelectors.cs @@ -56,6 +56,16 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public PresetSelectorWidget(string label, RGBA_Bytes accentColor, NamedSettingsLayers layerType, int extruderIndex) : base(FlowDirection.TopToBottom) { + SliceSettingsWidget.SettingChanged.RegisterEvent((s, e) => + { + StringEventArgs stringEvent = e as StringEventArgs; + if (stringEvent != null + && stringEvent.Data == SettingsKey.layer_name) + { + RebuildDropDownList(); + } + }, ref unregisterEvents); + this.extruderIndex = extruderIndex; this.layerType = layerType; @@ -320,6 +330,17 @@ namespace MatterHackers.MatterControl.SlicerConfiguration return dropDownList; } + private event EventHandler unregisterEvents; + + public override void OnClosed(EventArgs e) + { + if (unregisterEvents != null) + { + unregisterEvents(this, null); + } + base.OnClosed(e); + } + private void SettingsLayers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { RebuildDropDownList(); diff --git a/SlicerConfiguration/SlicePresetsWindow/SlicePresetsWindow.cs b/SlicerConfiguration/SlicePresetsWindow/SlicePresetsWindow.cs index 174c43dee..5caa7996e 100644 --- a/SlicerConfiguration/SlicePresetsWindow/SlicePresetsWindow.cs +++ b/SlicerConfiguration/SlicePresetsWindow/SlicePresetsWindow.cs @@ -137,6 +137,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration presetNameInput.ActualTextEditWidget.EditComplete += (s, e) => { ActiveSliceSettings.Instance.SetValue(SettingsKey.layer_name, presetNameInput.Text, presetsContext.PersistenceLayer); + SliceSettingsWidget.SettingChanged.CallEvents(null, new StringEventArgs(SettingsKey.layer_name)); }; topRow.AddChild(presetNameInput); @@ -223,16 +224,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration Button closeButton = buttonFactory.Generate("Close".Localize()); closeButton.Click += (sender, e) => { - UiThread.RunOnIdle(() => - { - if (initialPresetName != presetsContext.PersistenceLayer.Name) - { - // TODO: If we get to the point where we refresh rather than reload, we need - // to rebuild the target droplist to display the new name - ApplicationController.Instance.ReloadAdvancedControlsPanel(); - } - this.Close(); - }); + this.CloseOnIdle(); }; container.AddChild(duplicateButton); From 0b4bc4cbbc274bf44a520874f438d3e72a803ab8 Mon Sep 17 00:00:00 2001 From: Tyler Anderson Date: Wed, 10 Aug 2016 15:18:03 -0700 Subject: [PATCH 03/23] Switched custom GCode boxes to monospace font --- ControlElements/MHTextEditWidget.cs | 5 +++-- PrinterControls/TerminalWindow/TerminalWidget.cs | 7 +++++-- SlicerConfiguration/SliceSettingsWidget.cs | 10 +++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ControlElements/MHTextEditWidget.cs b/ControlElements/MHTextEditWidget.cs index 8ad73aed4..5940d93bf 100644 --- a/ControlElements/MHTextEditWidget.cs +++ b/ControlElements/MHTextEditWidget.cs @@ -1,4 +1,5 @@ using MatterHackers.Agg; +using MatterHackers.Agg.Font; using MatterHackers.Agg.UI; using MatterHackers.VectorMath; using System; @@ -16,10 +17,10 @@ namespace MatterHackers.MatterControl get { return actuallTextEditWidget; } } - public MHTextEditWidget(string text = "", double x = 0, double y = 0, double pointSize = 12, double pixelWidth = 0, double pixelHeight = 0, bool multiLine = false, int tabIndex = 0, string messageWhenEmptyAndNotSelected = "") + public MHTextEditWidget(string text = "", double x = 0, double y = 0, double pointSize = 12, double pixelWidth = 0, double pixelHeight = 0, bool multiLine = false, int tabIndex = 0, string messageWhenEmptyAndNotSelected = "", TypeFace typeFace = null) { Padding = new BorderDouble(3); - actuallTextEditWidget = new TextEditWidget(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine, tabIndex: tabIndex); + actuallTextEditWidget = new TextEditWidget(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine, tabIndex: tabIndex, typeFace: typeFace); actuallTextEditWidget.HAnchor = Agg.UI.HAnchor.ParentLeftRight; actuallTextEditWidget.MinimumSize = new Vector2(Math.Max(actuallTextEditWidget.MinimumSize.x, pixelWidth), Math.Max(actuallTextEditWidget.MinimumSize.y, pixelHeight)); actuallTextEditWidget.VAnchor = Agg.UI.VAnchor.ParentBottom; diff --git a/PrinterControls/TerminalWindow/TerminalWidget.cs b/PrinterControls/TerminalWindow/TerminalWidget.cs index 9bce5fdf0..ea05cec6c 100644 --- a/PrinterControls/TerminalWindow/TerminalWidget.cs +++ b/PrinterControls/TerminalWindow/TerminalWidget.cs @@ -29,6 +29,8 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.Agg; using MatterHackers.Agg.UI; +using MatterHackers.Agg.Font; +using MatterHackers.Agg.PlatformAbstract; using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.PrinterCommunication; @@ -138,7 +140,8 @@ namespace MatterHackers.MatterControl manualEntryLayout.BackgroundColor = this.backgroundColor; manualEntryLayout.HAnchor = HAnchor.ParentLeftRight; { - manualCommandTextEdit = new MHTextEditWidget(""); + string pathToFont = StaticData.Instance.ReadAllText(Path.Combine("Fonts", "LiberationMono.svg")); + manualCommandTextEdit = new MHTextEditWidget("", typeFace: TypeFace.LoadFrom(pathToFont)); //manualCommandTextEdit.BackgroundColor = RGBA_Bytes.White; manualCommandTextEdit.Margin = new BorderDouble(right: 3); manualCommandTextEdit.HAnchor = HAnchor.ParentLeftRight; @@ -304,4 +307,4 @@ namespace MatterHackers.MatterControl manualCommandTextEdit.Text = ""; } } -} \ No newline at end of file +} diff --git a/SlicerConfiguration/SliceSettingsWidget.cs b/SlicerConfiguration/SliceSettingsWidget.cs index 1013464e8..64f0d0f99 100644 --- a/SlicerConfiguration/SliceSettingsWidget.cs +++ b/SlicerConfiguration/SliceSettingsWidget.cs @@ -26,7 +26,9 @@ The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ + using MatterHackers.Agg; +using MatterHackers.Agg.Font; using MatterHackers.Agg.Image; using MatterHackers.Agg.PlatformAbstract; using MatterHackers.Agg.UI; @@ -37,6 +39,7 @@ using MatterHackers.SerialPortCommunication.FrostedSerial; using MatterHackers.VectorMath; using System; using System.Collections.Generic; +using System.IO; using System.Linq; namespace MatterHackers.MatterControl.SlicerConfiguration @@ -1210,11 +1213,12 @@ namespace MatterHackers.MatterControl.SlicerConfiguration case SliceSettingData.DataEditTypes.MULTI_LINE_TEXT: { string convertedNewLines = sliceSettingValue.Replace("\\n", "\n"); - var stringEdit = new MHTextEditWidget(convertedNewLines, pixelWidth: 320, pixelHeight: multiLineEditHeight, multiLine: true, tabIndex: tabIndexForItem++) + string pathToFont = StaticData.Instance.ReadAllText(Path.Combine("Fonts", "LiberationMono.svg")); + var stringEdit = new MHTextEditWidget(convertedNewLines, pixelWidth: 320, pixelHeight: multiLineEditHeight, multiLine: true, tabIndex: tabIndexForItem++, typeFace: TypeFace.LoadFrom(pathToFont)) { HAnchor = HAnchor.ParentLeftRight, }; - + stringEdit.ActualTextEditWidget.EditComplete += (sender, e) => { SaveSetting(settingData.SlicerConfigName, ((TextEditWidget)sender).Text.Replace("\n", "\\n"), persistenceLayer); @@ -1780,4 +1784,4 @@ namespace MatterHackers.MatterControl.SlicerConfiguration topToBottomItemList.AddChild(itemHolder, indexInChildrenList); } } -} \ No newline at end of file +} From ef0f2be119b6ed95a892c864c3081e7e86ce40c7 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Wed, 10 Aug 2016 15:40:09 -0700 Subject: [PATCH 04/23] Made a common static load of the mono spaced font --- ApplicationView/MainApplicationWidget.cs | 17 +++++++++++++++++ BrailleBuilder/View3DBrailleBuilder.cs | 9 ++++----- .../TerminalWindow/TerminalWidget.cs | 3 +-- .../TerminalWindow/TextScrollWidget.cs | 3 +-- SlicerConfiguration/SliceSettingsWidget.cs | 3 +-- Submodules/MatterSlice | 2 +- Submodules/agg-sharp | 2 +- 7 files changed, 26 insertions(+), 13 deletions(-) diff --git a/ApplicationView/MainApplicationWidget.cs b/ApplicationView/MainApplicationWidget.cs index 9990b328a..fdccdd3f3 100644 --- a/ApplicationView/MainApplicationWidget.cs +++ b/ApplicationView/MainApplicationWidget.cs @@ -48,6 +48,7 @@ using System.Threading.Tasks; namespace MatterHackers.MatterControl { + using Agg.Font; using OemProfileDictionary = Dictionary>; public abstract class ApplicationView : GuiWidget @@ -218,6 +219,22 @@ namespace MatterHackers.MatterControl } } + private static TypeFace monoSpacedTypeFace = null; + public static TypeFace MonoSpacedTypeFace + { + get + { + if (monoSpacedTypeFace == null) + { + monoSpacedTypeFace = TypeFace.LoadFrom(StaticData.Instance.ReadAllText(Path.Combine("Fonts", "LiberationMono.svg"))); + } + + return monoSpacedTypeFace; + } + + private set { } + } + /// /// Requests fresh content from online services, falling back to cached content if offline /// diff --git a/BrailleBuilder/View3DBrailleBuilder.cs b/BrailleBuilder/View3DBrailleBuilder.cs index 371c6f90c..54953f4f3 100644 --- a/BrailleBuilder/View3DBrailleBuilder.cs +++ b/BrailleBuilder/View3DBrailleBuilder.cs @@ -127,18 +127,17 @@ namespace MatterHackers.MatterControl.Plugins.BrailleBuilder internal struct MeshSelectInfo { - internal bool downOnPart; - internal PlaneShape hitPlane; internal Vector3 planeDownHitPos; internal Vector3 lastMoveDelta; } private TypeFace brailTypeFace; - private TypeFace boldTypeFace; + private TypeFace monoSpacedTypeFace; public View3DBrailleBuilder(Vector3 viewerVolume, Vector2 bedCenter, BedShape bedShape) { - boldTypeFace = TypeFace.LoadFrom(StaticData.Instance.ReadAllText(Path.Combine("Fonts", "LiberationMono.svg"))); + monoSpacedTypeFace = ApplicationController.MonoSpacedTypeFace; + brailTypeFace = TypeFace.LoadFrom(StaticData.Instance.ReadAllText(Path.Combine("Fonts", "Braille.svg"))); MeshGroupExtraData = new List(); @@ -374,7 +373,7 @@ namespace MatterHackers.MatterControl.Plugins.BrailleBuilder TypeFacePrinter brailPrinter = new TypeFacePrinter(brailleText, new StyledTypeFace(brailTypeFace, 12)); int firstNewCharacter = 0; - StyledTypeFace boldStyled = new StyledTypeFace(boldTypeFace, 12); + StyledTypeFace boldStyled = new StyledTypeFace(monoSpacedTypeFace, 12); if (includeText.Checked) { diff --git a/PrinterControls/TerminalWindow/TerminalWidget.cs b/PrinterControls/TerminalWindow/TerminalWidget.cs index ea05cec6c..1e5540dcc 100644 --- a/PrinterControls/TerminalWindow/TerminalWidget.cs +++ b/PrinterControls/TerminalWindow/TerminalWidget.cs @@ -140,8 +140,7 @@ namespace MatterHackers.MatterControl manualEntryLayout.BackgroundColor = this.backgroundColor; manualEntryLayout.HAnchor = HAnchor.ParentLeftRight; { - string pathToFont = StaticData.Instance.ReadAllText(Path.Combine("Fonts", "LiberationMono.svg")); - manualCommandTextEdit = new MHTextEditWidget("", typeFace: TypeFace.LoadFrom(pathToFont)); + manualCommandTextEdit = new MHTextEditWidget("", typeFace: ApplicationController.MonoSpacedTypeFace); //manualCommandTextEdit.BackgroundColor = RGBA_Bytes.White; manualCommandTextEdit.Margin = new BorderDouble(right: 3); manualCommandTextEdit.HAnchor = HAnchor.ParentLeftRight; diff --git a/PrinterControls/TerminalWindow/TextScrollWidget.cs b/PrinterControls/TerminalWindow/TextScrollWidget.cs index 6c877fe2c..c75255c39 100644 --- a/PrinterControls/TerminalWindow/TextScrollWidget.cs +++ b/PrinterControls/TerminalWindow/TextScrollWidget.cs @@ -91,8 +91,7 @@ namespace MatterHackers.MatterControl public TextScrollWidget(List sourceLines) { - string pathToFont = StaticData.Instance.ReadAllText(Path.Combine("Fonts", "LiberationMono.svg")); - printer = new TypeFacePrinter("", new StyledTypeFace(TypeFace.LoadFrom(pathToFont), 12)); + printer = new TypeFacePrinter("", new StyledTypeFace(ApplicationController.MonoSpacedTypeFace, 12)); printer.DrawFromHintedCache = true; this.allSourceLines = sourceLines; this.visibleLines = sourceLines; diff --git a/SlicerConfiguration/SliceSettingsWidget.cs b/SlicerConfiguration/SliceSettingsWidget.cs index 2d9f65771..7d09ba553 100644 --- a/SlicerConfiguration/SliceSettingsWidget.cs +++ b/SlicerConfiguration/SliceSettingsWidget.cs @@ -1213,8 +1213,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration case SliceSettingData.DataEditTypes.MULTI_LINE_TEXT: { string convertedNewLines = sliceSettingValue.Replace("\\n", "\n"); - string pathToFont = StaticData.Instance.ReadAllText(Path.Combine("Fonts", "LiberationMono.svg")); - var stringEdit = new MHTextEditWidget(convertedNewLines, pixelWidth: 320, pixelHeight: multiLineEditHeight, multiLine: true, tabIndex: tabIndexForItem++, typeFace: TypeFace.LoadFrom(pathToFont)) + var stringEdit = new MHTextEditWidget(convertedNewLines, pixelWidth: 320, pixelHeight: multiLineEditHeight, multiLine: true, tabIndex: tabIndexForItem++, typeFace: ApplicationController.MonoSpacedTypeFace) { HAnchor = HAnchor.ParentLeftRight, }; diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index 718e75cc6..e76e827b9 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit 718e75cc668e22ddf282091c02caa5a8e7a1bba9 +Subproject commit e76e827b9724ee4363d1b74e53ddfa61a342bb6d diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 5f0626862..7d6caf59e 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 5f0626862c0dab00a901fa9724a536cd3a784e82 +Subproject commit 7d6caf59efc2af50971616c26db7348aa1153f5b From bdf3e8f2a571502baee36347f67dfc1fcfbf9fab Mon Sep 17 00:00:00 2001 From: Matt Moening Date: Wed, 10 Aug 2016 16:38:58 -0700 Subject: [PATCH 05/23] Importing a printer/settings from a file will now notify the user if the file contains no valid user settings - ImportFomEisting now returns a bool of whether or not it succeeded - PrinterSettings now has a Contains method - merging or importing quality/material settings check to make sure at least one setting was importable and notifies user if not --- SetupWizard/ImportSettingsPage.cs | 89 +++++++++++++------ .../Settings/PrinterSettings.cs | 17 ++++ .../Settings/ProfileManager.cs | 35 ++++---- StaticData/Translations/Master.txt | 3 + 4 files changed, 104 insertions(+), 40 deletions(-) diff --git a/SetupWizard/ImportSettingsPage.cs b/SetupWizard/ImportSettingsPage.cs index 80d17f0d7..a1d9b94de 100644 --- a/SetupWizard/ImportSettingsPage.cs +++ b/SetupWizard/ImportSettingsPage.cs @@ -431,11 +431,18 @@ namespace MatterHackers.MatterControl { if(newPrinterButton.Checked) { - ProfileManager.ImportFromExisting(settingsFilePath); - WizardWindow.ChangeToPage(new ImportSucceeded(importPrinterSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath))) + if(ProfileManager.ImportFromExisting(settingsFilePath)) { - WizardWindow = this.WizardWindow, - }); + WizardWindow.ChangeToPage(new ImportSucceeded(importPrinterSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath))) + { + WizardWindow = this.WizardWindow, + }); + } + else + { + displayFailedToImportMessage(settingsFilePath); + } + } else if(mergeButton.Checked) { @@ -487,6 +494,7 @@ namespace MatterHackers.MatterControl var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath); string layerHeight; + bool containsValidSetting = false; bool isSlic3r = importType == ".slice" || settingsToImport.TryGetValue(SettingsKey.layer_height, out layerHeight); if (isSlic3r) { @@ -502,35 +510,49 @@ namespace MatterHackers.MatterControl foreach (var item in settingsToImport) { - string currentValue = ActiveSliceSettings.Instance.GetValue(item.Key, baseAndOEMCascade).Trim(); - // Compare the value to import to the layer cascade value and only set if different - if (currentValue != item.Value) + if(ActiveSliceSettings.Instance.Contains(item.Key)) { - newLayer[item.Key] = item.Value; + containsValidSetting = true; + string currentValue = ActiveSliceSettings.Instance.GetValue(item.Key, baseAndOEMCascade).Trim(); + // Compare the value to import to the layer cascade value and only set if different + if (currentValue != item.Value) + { + newLayer[item.Key] = item.Value; + } } + } - if (newMaterialPresetButton.Checked) + if(containsValidSetting) { - ActiveSliceSettings.Instance.MaterialLayers.Add(newLayer); + if (newMaterialPresetButton.Checked) + { + ActiveSliceSettings.Instance.MaterialLayers.Add(newLayer); + } + else + { + ActiveSliceSettings.Instance.QualityLayers.Add(newLayer); + } + + ActiveSliceSettings.Instance.Save(); + + WizardWindow.ChangeToPage(new ImportSucceeded(importSettingSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath), sectionName)) + { + WizardWindow = this.WizardWindow, + }); } else { - ActiveSliceSettings.Instance.QualityLayers.Add(newLayer); + displayFailedToImportMessage(settingsFilePath); } - ActiveSliceSettings.Instance.Save(); - - WizardWindow.ChangeToPage(new ImportSucceeded(importSettingSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath), sectionName)) - { - WizardWindow = this.WizardWindow, - }); } else { + displayFailedToImportMessage(settingsFilePath); // looks like a cura file #if DEBUG - throw new NotImplementedException("need to import from 'cure.ini' files"); + //throw new NotImplementedException("need to import from 'cure.ini' files"); #endif } break; @@ -562,23 +584,35 @@ namespace MatterHackers.MatterControl string layerHeight; bool isSlic3r = settingsToImport.TryGetValue(SettingsKey.layer_height, out layerHeight); + bool containsValidSetting = false; //if (isSlic3r) { var activeSettings = ActiveSliceSettings.Instance; foreach (var item in settingsToImport) { - // Compare the value to import to the layer cascade value and only set if different - string currentValue = activeSettings.GetValue(item.Key, null).Trim(); - if (currentValue != item.Value) + if(activeSettings.Contains(item.Key)) { - activeSettings.UserLayer[item.Key] = item.Value; + containsValidSetting = true; + string currentValue = activeSettings.GetValue(item.Key, null).Trim(); + // Compare the value to import to the layer cascade value and only set if different + if (currentValue != item.Value) + { + activeSettings.UserLayer[item.Key] = item.Value; + } } + } + if(containsValidSetting) + { + activeSettings.Save(); - activeSettings.Save(); - - UiThread.RunOnIdle(ApplicationController.Instance.ReloadAdvancedControlsPanel); + UiThread.RunOnIdle(ApplicationController.Instance.ReloadAdvancedControlsPanel); + } + else + { + displayFailedToImportMessage(settingsFilePath); + } } //else { @@ -598,5 +632,10 @@ namespace MatterHackers.MatterControl } Invalidate(); } + + private void displayFailedToImportMessage(string settingsFilePath) + { + StyledMessageBox.ShowMessageBox(null, "Oops! Settings file '{0}' did not contain any settings we could import.".Localize().FormatWith(Path.GetFileName(settingsFilePath)), "Unable to Import".Localize()); + } } } diff --git a/SlicerConfiguration/Settings/PrinterSettings.cs b/SlicerConfiguration/Settings/PrinterSettings.cs index aef26ffb0..d72dfdad7 100644 --- a/SlicerConfiguration/Settings/PrinterSettings.cs +++ b/SlicerConfiguration/Settings/PrinterSettings.cs @@ -371,6 +371,23 @@ namespace MatterHackers.MatterControl.SlicerConfiguration return ""; } + public bool Contains(string sliceSetting, IEnumerable layerCascade = null) + { + if (layerCascade == null) + { + layerCascade = defaultLayerCascade; + } + foreach (PrinterSettingsLayer layer in layerCascade) + { + string value; + if (layer.TryGetValue(sliceSetting, out value)) + { + return true; + } + } + return false; + } + [JsonIgnore] public PrinterSettingsLayer BaseLayer { diff --git a/SlicerConfiguration/Settings/ProfileManager.cs b/SlicerConfiguration/Settings/ProfileManager.cs index ab706050f..bc12d7d82 100644 --- a/SlicerConfiguration/Settings/ProfileManager.cs +++ b/SlicerConfiguration/Settings/ProfileManager.cs @@ -262,11 +262,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration } } - internal static void ImportFromExisting(string settingsFilePath) + internal static bool ImportFromExisting(string settingsFilePath) { if (string.IsNullOrEmpty(settingsFilePath) || !File.Exists(settingsFilePath)) { - return; + return false; } var printerInfo = new PrinterInfo @@ -274,7 +274,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration Name = Path.GetFileNameWithoutExtension(settingsFilePath), ID = Guid.NewGuid().ToString() }; - + bool importSuccessful = false; string importType = Path.GetExtension(settingsFilePath).ToLower(); switch (importType) { @@ -290,28 +290,33 @@ namespace MatterHackers.MatterControl.SlicerConfiguration Instance.Profiles.Add(printerInfo); profile.Save(); + importSuccessful = true; break; case ".ini": var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath); - - var layeredProfile = new PrinterSettings() + //Other import paths validate that this is a slicer or MC ini file via checking if layer_height is a setting + if(settingsToImport.ContainsKey(SettingsKey.layer_height)) { - ID = printerInfo.ID, - OemLayer = settingsToImport - }; + var layeredProfile = new PrinterSettings() + { + ID = printerInfo.ID, + OemLayer = settingsToImport + }; - // TODO: Resolve name conflicts - layeredProfile.UserLayer[SettingsKey.printer_name.ToString()] = printerInfo.Name; + // TODO: Resolve name conflicts + layeredProfile.UserLayer[SettingsKey.printer_name.ToString()] = printerInfo.Name; - layeredProfile.ClearValue(SettingsKey.device_token); - printerInfo.DeviceToken = ""; - Instance.Profiles.Add(printerInfo); - - layeredProfile.Save(); + layeredProfile.ClearValue(SettingsKey.device_token); + printerInfo.DeviceToken = ""; + Instance.Profiles.Add(printerInfo); + layeredProfile.Save(); + importSuccessful = true; + } break; } + return importSuccessful; } internal static async void AcquireNewProfile(string make, string model, string printerName) diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 484c45c86..b07986f33 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -5311,3 +5311,6 @@ Translated:There is a required update available. English:Import Printer Translated:Import Printer +English:Oops! Settings file '{0}' did not contain any settings we could import. +Translated:Oops! Settings file '{0}' did not contain any settings we could import. + From 5b8ff5cd29ef0682ae76ad4875d7aff2e94b983c Mon Sep 17 00:00:00 2001 From: Matt Moening Date: Thu, 11 Aug 2016 13:01:34 -0700 Subject: [PATCH 06/23] Changed TryGetValue to ContainsKey for clarity --- SetupWizard/ImportSettingsPage.cs | 2 +- SlicerConfiguration/Settings/PrinterSettings.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/SetupWizard/ImportSettingsPage.cs b/SetupWizard/ImportSettingsPage.cs index a1d9b94de..33de84c32 100644 --- a/SetupWizard/ImportSettingsPage.cs +++ b/SetupWizard/ImportSettingsPage.cs @@ -594,7 +594,7 @@ namespace MatterHackers.MatterControl if(activeSettings.Contains(item.Key)) { containsValidSetting = true; - string currentValue = activeSettings.GetValue(item.Key, null).Trim(); + string currentValue = activeSettings.GetValue(item.Key).Trim(); // Compare the value to import to the layer cascade value and only set if different if (currentValue != item.Value) { diff --git a/SlicerConfiguration/Settings/PrinterSettings.cs b/SlicerConfiguration/Settings/PrinterSettings.cs index d72dfdad7..a25720020 100644 --- a/SlicerConfiguration/Settings/PrinterSettings.cs +++ b/SlicerConfiguration/Settings/PrinterSettings.cs @@ -379,8 +379,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration } foreach (PrinterSettingsLayer layer in layerCascade) { - string value; - if (layer.TryGetValue(sliceSetting, out value)) + if (layer.ContainsKey(sliceSetting)) { return true; } From 5b42eac3018fc797de95f958ba7f8097c90af329 Mon Sep 17 00:00:00 2001 From: Matt Moening Date: Thu, 11 Aug 2016 14:59:23 -0700 Subject: [PATCH 07/23] Fixed import to not rely on layer_height validation - Import preset no longer checks for slicer and will validate import on weather or not any settigns were valid - calling Import from MenuOptionFIle will cause the same error message as importing a printer form the settings import page - Import to new printer now attempts to load values and validates success on importing a valid setting --- ApplicationView/MenuRow/MenuOptionFile.cs | 5 ++- SetupWizard/ImportSettingsPage.cs | 34 ++++------------ .../Settings/ProfileManager.cs | 40 ++++++++++++++----- 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/ApplicationView/MenuRow/MenuOptionFile.cs b/ApplicationView/MenuRow/MenuOptionFile.cs index 5898137c3..c922e87fb 100644 --- a/ApplicationView/MenuRow/MenuOptionFile.cs +++ b/ApplicationView/MenuRow/MenuOptionFile.cs @@ -65,7 +65,10 @@ namespace MatterHackers.MatterControl private void ImportSettingsFile(string settingsFilePath) { - ProfileManager.ImportFromExisting(settingsFilePath); + if(!ProfileManager.ImportFromExisting(settingsFilePath)) + { + StyledMessageBox.ShowMessageBox(null, "Oops! Settings file '{0}' did not contain any settings we could import.".Localize().FormatWith(Path.GetFileName(settingsFilePath)), "Unable to Import".Localize()); + } } private void importFile_Click() diff --git a/SetupWizard/ImportSettingsPage.cs b/SetupWizard/ImportSettingsPage.cs index 33de84c32..ebd3e5aeb 100644 --- a/SetupWizard/ImportSettingsPage.cs +++ b/SetupWizard/ImportSettingsPage.cs @@ -492,11 +492,8 @@ namespace MatterHackers.MatterControl case ".slice": // legacy presets file extension case ".ini": var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath); - string layerHeight; bool containsValidSetting = false; - bool isSlic3r = importType == ".slice" || settingsToImport.TryGetValue(SettingsKey.layer_height, out layerHeight); - if (isSlic3r) { newLayer = new PrinterSettingsLayer(); newLayer.Name = Path.GetFileNameWithoutExtension(settingsFilePath); @@ -547,14 +544,7 @@ namespace MatterHackers.MatterControl } } - else - { - displayFailedToImportMessage(settingsFilePath); - // looks like a cura file -#if DEBUG - //throw new NotImplementedException("need to import from 'cure.ini' files"); -#endif - } + break; default: @@ -580,18 +570,16 @@ namespace MatterHackers.MatterControl case ".slice": // old presets format case ".ini": - var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath); - string layerHeight; - - bool isSlic3r = settingsToImport.TryGetValue(SettingsKey.layer_height, out layerHeight); - bool containsValidSetting = false; - //if (isSlic3r) + // create a scope for variables { + var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath); + + bool containsValidSetting = false; var activeSettings = ActiveSliceSettings.Instance; foreach (var item in settingsToImport) { - if(activeSettings.Contains(item.Key)) + if (activeSettings.Contains(item.Key)) { containsValidSetting = true; string currentValue = activeSettings.GetValue(item.Key).Trim(); @@ -601,9 +589,8 @@ namespace MatterHackers.MatterControl activeSettings.UserLayer[item.Key] = item.Value; } } - } - if(containsValidSetting) + if (containsValidSetting) { activeSettings.Save(); @@ -613,13 +600,8 @@ namespace MatterHackers.MatterControl { displayFailedToImportMessage(settingsFilePath); } + WizardWindow.Close(); } - //else - { - // looks like a cura file - //throw new NotImplementedException("need to import from 'cure.ini' files"); - } - WizardWindow.Close(); break; default: diff --git a/SlicerConfiguration/Settings/ProfileManager.cs b/SlicerConfiguration/Settings/ProfileManager.cs index bc12d7d82..175b1442c 100644 --- a/SlicerConfiguration/Settings/ProfileManager.cs +++ b/SlicerConfiguration/Settings/ProfileManager.cs @@ -294,25 +294,43 @@ namespace MatterHackers.MatterControl.SlicerConfiguration break; case ".ini": - var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath); - //Other import paths validate that this is a slicer or MC ini file via checking if layer_height is a setting - if(settingsToImport.ContainsKey(SettingsKey.layer_height)) + //Scope variables { + var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath); var layeredProfile = new PrinterSettings() { ID = printerInfo.ID, - OemLayer = settingsToImport }; - // TODO: Resolve name conflicts - layeredProfile.UserLayer[SettingsKey.printer_name.ToString()] = printerInfo.Name; + bool containsValidSetting = false; + var activeSettings = layeredProfile; - layeredProfile.ClearValue(SettingsKey.device_token); - printerInfo.DeviceToken = ""; - Instance.Profiles.Add(printerInfo); + foreach (var item in settingsToImport) + { + if (activeSettings.Contains(item.Key)) + { + containsValidSetting = true; + string currentValue = activeSettings.GetValue(item.Key).Trim(); + // Compare the value to import to the layer cascade value and only set if different + if (currentValue != item.Value) + { + activeSettings.OemLayer[item.Key] = item.Value; + } + } + } + if(containsValidSetting) + { + // TODO: Resolve name conflicts + layeredProfile.UserLayer[SettingsKey.printer_name] = printerInfo.Name; - layeredProfile.Save(); - importSuccessful = true; + layeredProfile.ClearValue(SettingsKey.device_token); + printerInfo.DeviceToken = ""; + Instance.Profiles.Add(printerInfo); + + layeredProfile.Save(); + importSuccessful = true; + } + } break; } From 261b6136891d6f0cfa9c6866983333c657de99a6 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Thu, 11 Aug 2016 16:09:45 -0700 Subject: [PATCH 08/23] Made resume failed print able to be turned on and off Made show if set have an & operator Made a new test for parsing the show if set parameter --- .../PrinterConnectionAndCommunication.cs | 3 +- .../Settings/SettingsHelpers.cs | 2 + SlicerConfiguration/SliceSettingsWidget.cs | 41 ++++++++----- .../SlicerMapping/EngineMapingBase.cs | 3 +- .../SlicerMapping/MappingClasses.cs | 2 +- StaticData/SliceSettings/Layouts.txt | 4 +- StaticData/SliceSettings/Properties.json | 17 +++++- StaticData/Translations/Master.txt | 9 +++ .../MatterControl/SettingsParseTests.cs | 61 +++++++++++++++++++ 9 files changed, 122 insertions(+), 20 deletions(-) diff --git a/PrinterCommunication/PrinterConnectionAndCommunication.cs b/PrinterCommunication/PrinterConnectionAndCommunication.cs index c08421ccd..1cac99f52 100644 --- a/PrinterCommunication/PrinterConnectionAndCommunication.cs +++ b/PrinterCommunication/PrinterConnectionAndCommunication.cs @@ -2467,7 +2467,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication loadedGCode = GCodeFile.Load(gcodeFilename); gCodeFileStream0 = new GCodeFileStream(loadedGCode); - if(activePrintTask != null) // We are resuming a failed print (do lots of interesting stuff). + if(ActiveSliceSettings.Instance.GetValue(SettingsKey.resume_is_enabled) + && activePrintTask != null) // We are resuming a failed print (do lots of interesting stuff). { pauseHandlingStream1 = new PauseHandlingStream(new ResumePrintingStream(gCodeFileStream0, activePrintTask.PercentDone)); } diff --git a/SlicerConfiguration/Settings/SettingsHelpers.cs b/SlicerConfiguration/Settings/SettingsHelpers.cs index 1a6172f9b..850e4db2b 100644 --- a/SlicerConfiguration/Settings/SettingsHelpers.cs +++ b/SlicerConfiguration/Settings/SettingsHelpers.cs @@ -59,6 +59,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public const string device_token = nameof(device_token); public const string device_type = nameof(device_type); public const string extruder_count = nameof(extruder_count); + public const string resume_is_enabled = nameof(resume_is_enabled); public const string extruders_share_temperature = nameof(extruders_share_temperature); public const string filament_cost = nameof(filament_cost); public const string filament_density = nameof(filament_density); @@ -69,6 +70,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public const string has_fan = nameof(has_fan); public const string has_hardware_leveling = nameof(has_hardware_leveling); public const string has_heated_bed = nameof(has_heated_bed); + public const string bed_remove_part_temperature = nameof(bed_remove_part_temperature); public const string has_power_control = nameof(has_power_control); public const string has_sd_card_reader = nameof(has_sd_card_reader); public const string layer_height = nameof(layer_height); diff --git a/SlicerConfiguration/SliceSettingsWidget.cs b/SlicerConfiguration/SliceSettingsWidget.cs index 7d09ba553..e6443ce17 100644 --- a/SlicerConfiguration/SliceSettingsWidget.cs +++ b/SlicerConfiguration/SliceSettingsWidget.cs @@ -476,26 +476,39 @@ namespace MatterHackers.MatterControl.SlicerConfiguration return leftSideGroupTabs; } - private bool CheckIfShouldBeShown(SliceSettingData settingData) + public static bool ParseShowString(string unsplitSettings, PrinterSettings printerSettings, List layerCascade) { - bool settingShouldBeShown = true; - if (settingData.ShowIfSet != null - && settingData.ShowIfSet != "") + if (!string.IsNullOrEmpty(unsplitSettings)) { - string showValue = "0"; - string checkName = settingData.ShowIfSet; - if (checkName.StartsWith("!")) + string[] splitSettings = unsplitSettings.Split('&'); + + foreach (var inLookupSettings in splitSettings) { - showValue = "1"; - checkName = checkName.Substring(1); - } - string sliceSettingValue = GetActiveValue(checkName, layerCascade); - if (sliceSettingValue == showValue) - { - settingShouldBeShown = false; + var lookupSettings = inLookupSettings; + if (!string.IsNullOrEmpty(lookupSettings)) + { + string showValue = "0"; + if (lookupSettings.StartsWith("!")) + { + showValue = "1"; + lookupSettings = lookupSettings.Substring(1); + } + + string sliceSettingValue = printerSettings.GetValue(lookupSettings, layerCascade); + if (sliceSettingValue == showValue) + { + return false; + } + } } } + return true; + } + + private bool CheckIfShouldBeShown(SliceSettingData settingData) + { + bool settingShouldBeShown = ParseShowString(settingData.ShowIfSet, ActiveSliceSettings.Instance, layerCascade); if (viewFilter == NamedSettingsLayers.Material || viewFilter == NamedSettingsLayers.Quality) { if (!settingData.ShowAsOverride) diff --git a/SlicerConfiguration/SlicerMapping/EngineMapingBase.cs b/SlicerConfiguration/SlicerMapping/EngineMapingBase.cs index 8535618a2..259243450 100644 --- a/SlicerConfiguration/SlicerMapping/EngineMapingBase.cs +++ b/SlicerConfiguration/SlicerMapping/EngineMapingBase.cs @@ -65,6 +65,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration "print_leveling_required_to_print", "print_leveling_solution", "resume_first_layer_speed", + "resume_is_enabled", "resume_position_before_z_home", "resume_gcode", "temperature", @@ -72,7 +73,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration "z_homes_to_max", // TODO: merge the items below into the list above after some validation - setting that weren't previously mapped to Cura but probably should be. - "bed_remove_part_temperature", + SettingsKey.bed_remove_part_temperature, "extruder_wipe_temperature", "heat_extruder_before_homing", "include_firmware_updater", diff --git a/SlicerConfiguration/SlicerMapping/MappingClasses.cs b/SlicerConfiguration/SlicerMapping/MappingClasses.cs index 03166dbf1..6352db497 100644 --- a/SlicerConfiguration/SlicerMapping/MappingClasses.cs +++ b/SlicerConfiguration/SlicerMapping/MappingClasses.cs @@ -42,7 +42,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration new AsPercentOfReferenceOrDirect("first_layer_speed", "first_layer_speed", "infill_speed", 60), new AsPercentOfReferenceOrDirect("external_perimeter_speed","external_perimeter_speed", "perimeter_speed", 60), new AsPercentOfReferenceOrDirect("raft_print_speed", "raft_print_speed", "infill_speed", 60), - new MappedSetting("bed_remove_part_temperature","bed_remove_part_temperature"), + new MappedSetting(SettingsKey.bed_remove_part_temperature,SettingsKey.bed_remove_part_temperature), new MappedSetting("bridge_fan_speed","bridge_fan_speed"), new MappedSetting("bridge_speed","bridge_speed"), new MappedSetting("extruder_wipe_temperature","extruder_wipe_temperature"), diff --git a/StaticData/SliceSettings/Layouts.txt b/StaticData/SliceSettings/Layouts.txt index 96adefa4f..2e90660fb 100644 --- a/StaticData/SliceSettings/Layouts.txt +++ b/StaticData/SliceSettings/Layouts.txt @@ -321,9 +321,9 @@ Advanced manual_probe_paper_width Options Resume Failed Print - Speed + Resume Settings + resume_is_enabled resume_first_layer_speed - Homing resume_position_before_z_home Custom G-Code Start G-Code diff --git a/StaticData/SliceSettings/Properties.json b/StaticData/SliceSettings/Properties.json index 3514bc726..3190f0e7c 100644 --- a/StaticData/SliceSettings/Properties.json +++ b/StaticData/SliceSettings/Properties.json @@ -719,6 +719,20 @@ "DefaultValue": "10", "RebuildGCodeOnChange": false }, + { + "QuickMenuSettings": [ ], + "SetSettingsOnChange": [ ], + "SlicerConfigName": "resume_is_enabled", + "PresentationName": "Enable Resuming", + "HelpText": "When this is checked MatterControl will attempt to resume a print in the event of a failure, such as lost connection or lost power.", + "DataEditType": "CHECK_BOX", + "ExtraSettings": "", + "ShowAsOverride": false, + "ShowIfSet": "!has_hardware_leveling", + "ResetAtEndOfPrint": false, + "DefaultValue": "0", + "RebuildGCodeOnChange": false + }, { "QuickMenuSettings": [ ], "SetSettingsOnChange": [ ], @@ -731,6 +745,7 @@ "ShowIfSet": "!has_hardware_leveling", "ResetAtEndOfPrint": false, "DefaultValue": "0", + "ReloadUiWhenChanged": true, "RebuildGCodeOnChange": false }, { @@ -742,7 +757,7 @@ "DataEditType": "VECTOR2", "ExtraSettings": "mm", "ShowAsOverride": true, - "ShowIfSet": "!has_hardware_leveling", + "ShowIfSet": "!has_hardware_leveling&!z_homes_to_max", "ResetAtEndOfPrint": false, "DefaultValue": "0,0", "RebuildGCodeOnChange": false diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 484c45c86..ff2739112 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -5311,3 +5311,12 @@ Translated:There is a required update available. English:Import Printer Translated:Import Printer +English:Resume Settings +Translated:Resume Settings + +English:Enable Resuming +Translated:Enable Resuming + +English:When this is checked MatterControl will attempt to resume a print in the event of a failure, such as lost connection or lost power. +Translated:When this is checked MatterControl will attempt to resume a print in the event of a failure, such as lost connection or lost power. + diff --git a/Tests/MatterControl.Tests/MatterControl/SettingsParseTests.cs b/Tests/MatterControl.Tests/MatterControl/SettingsParseTests.cs index 6d54c2efd..827ea3adc 100644 --- a/Tests/MatterControl.Tests/MatterControl/SettingsParseTests.cs +++ b/Tests/MatterControl.Tests/MatterControl/SettingsParseTests.cs @@ -15,6 +15,67 @@ namespace MatterControl.Tests.MatterControl [TestFixture, Category("ConfigIni")] public class SettingsParseTests { + [Test] + public void CheckIfShouldBeShownParseTests() + { + + { + string[] settings = new string[] { SettingsKey.has_heated_bed, "0" }; + var profile = GettProfile(settings); + Assert.IsFalse(SliceSettingsWidget.ParseShowString("has_heated_bed", profile, null)); + Assert.IsTrue(SliceSettingsWidget.ParseShowString("!has_heated_bed", profile, null)); + } + + { + string[] settings = new string[] { SettingsKey.has_heated_bed, "1" }; + var profile = GettProfile(settings); + Assert.IsTrue(SliceSettingsWidget.ParseShowString("has_heated_bed", profile, null)); + Assert.IsFalse(SliceSettingsWidget.ParseShowString("!has_heated_bed", profile, null)); + } + + { + string[] settings = new string[] { SettingsKey.has_heated_bed, "0", SettingsKey.auto_connect, "0" }; + var profile = GettProfile(settings); + Assert.IsTrue(!SliceSettingsWidget.ParseShowString("has_heated_bed&auto_connect", profile, null)); + Assert.IsTrue(!SliceSettingsWidget.ParseShowString("has_heated_bed&!auto_connect", profile, null)); + Assert.IsTrue(!SliceSettingsWidget.ParseShowString("!has_heated_bed&auto_connect", profile, null)); + Assert.IsTrue(SliceSettingsWidget.ParseShowString("!has_heated_bed&!auto_connect", profile, null)); + } + { + string[] settings = new string[] { SettingsKey.has_heated_bed, "0", SettingsKey.auto_connect, "1" }; + var profile = GettProfile(settings); + Assert.IsTrue(!SliceSettingsWidget.ParseShowString("has_heated_bed&auto_connect", profile, null)); + Assert.IsTrue(!SliceSettingsWidget.ParseShowString("has_heated_bed&!auto_connect", profile, null)); + Assert.IsTrue(SliceSettingsWidget.ParseShowString("!has_heated_bed&auto_connect", profile, null)); + Assert.IsTrue(!SliceSettingsWidget.ParseShowString("!has_heated_bed&!auto_connect", profile, null)); + } + { + string[] settings = new string[] { SettingsKey.has_heated_bed, "1", SettingsKey.auto_connect, "0" }; + var profile = GettProfile(settings); + Assert.IsTrue(!SliceSettingsWidget.ParseShowString("has_heated_bed&auto_connect", profile, null)); + Assert.IsTrue(SliceSettingsWidget.ParseShowString("has_heated_bed&!auto_connect", profile, null)); + Assert.IsTrue(!SliceSettingsWidget.ParseShowString("!has_heated_bed&auto_connect", profile, null)); + Assert.IsTrue(!SliceSettingsWidget.ParseShowString("!has_heated_bed&!auto_connect", profile, null)); + } + { + string[] settings = new string[] { SettingsKey.has_heated_bed, "1", SettingsKey.auto_connect, "1" }; + var profile = GettProfile(settings); + Assert.IsTrue(SliceSettingsWidget.ParseShowString("has_heated_bed&auto_connect", profile, null)); + Assert.IsTrue(!SliceSettingsWidget.ParseShowString("has_heated_bed&!auto_connect", profile, null)); + Assert.IsTrue(!SliceSettingsWidget.ParseShowString("!has_heated_bed&auto_connect", profile, null)); + Assert.IsTrue(!SliceSettingsWidget.ParseShowString("!has_heated_bed&!auto_connect", profile, null)); + } + + { + string[] settings = new string[] { SettingsKey.has_heated_bed, "1", SettingsKey.auto_connect, "1", SettingsKey.has_fan, "1" }; + var profile = GettProfile(settings); + Assert.IsTrue(SliceSettingsWidget.ParseShowString("has_heated_bed&auto_connect&has_fan", profile, null)); + Assert.IsTrue(!SliceSettingsWidget.ParseShowString("has_heated_bed&auto_connect&!has_fan", profile, null)); + Assert.IsTrue(!SliceSettingsWidget.ParseShowString("has_heated_bed&!auto_connect&has_fan", profile, null)); + Assert.IsTrue(!SliceSettingsWidget.ParseShowString("!has_heated_bed&auto_connect&has_fan", profile, null)); + } + } + [Test] public void SupportInterfaceMaterialAssignedToExtruderOne() { From db86e2fe0fbb7529550b13b57e5fbdfe0a31c2ec Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Thu, 11 Aug 2016 17:18:32 -0700 Subject: [PATCH 09/23] Fixing the drop menu to hold the pencil on the left issue #1279 --- .../SettingsControlSelectors.cs | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/SlicerConfiguration/SettingsControlSelectors.cs b/SlicerConfiguration/SettingsControlSelectors.cs index f1098bc86..1bf1fdef1 100644 --- a/SlicerConfiguration/SettingsControlSelectors.cs +++ b/SlicerConfiguration/SettingsControlSelectors.cs @@ -49,7 +49,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration { private Button editButton; private NamedSettingsLayers layerType; - private DropDownList dropDownList; + GuiWidget pullDownContainer; private int extruderIndex; //For multiple materials @@ -87,14 +87,16 @@ namespace MatterHackers.MatterControl.SlicerConfiguration }; this.AddChild(labelText); - this.AddChild(GetPulldownContainer()); + pullDownContainer = new GuiWidget(HAnchor.ParentLeftRight, VAnchor.FitToChildren); + pullDownContainer.AddChild(GetPulldownContainer()); + this.AddChild(pullDownContainer); this.AddChild(new VerticalSpacer()); this.AddChild(accentBar); } - public virtual FlowLayoutWidget GetPulldownContainer() + public FlowLayoutWidget GetPulldownContainer() { - dropDownList = CreateDropdown(); + var dropDownList = CreateDropdown(); FlowLayoutWidget container = new FlowLayoutWidget(); container.HAnchor = HAnchor.ParentLeftRight; @@ -209,18 +211,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration private void RebuildDropDownList() { - // TODO: Consider adding a .Replace(existingWidget, newWidget) to GuiWidget - // Replace existing list with updated list - var parent = this.dropDownList.Parent; - - if (parent != null) - { - parent.RemoveChild(this.dropDownList); - this.dropDownList.Close(); - - this.dropDownList = CreateDropdown(); - parent.AddChild(this.dropDownList); - } + pullDownContainer.CloseAllChildren(); + pullDownContainer.AddChild(GetPulldownContainer()); } private void MenuItem_Selected(object sender, EventArgs e) From b96ff64a4e41fdce920b6fead91457efc66dbfb9 Mon Sep 17 00:00:00 2001 From: tellingmachine Date: Fri, 12 Aug 2016 11:27:40 -0700 Subject: [PATCH 10/23] Don't call uninitialized action. This action gets set by code that is part of CloudServices and not part of the common code. --- ApplicationView/MainApplicationWidget.cs | 51 +++++++++++++++--------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/ApplicationView/MainApplicationWidget.cs b/ApplicationView/MainApplicationWidget.cs index fdccdd3f3..9bd6ba146 100644 --- a/ApplicationView/MainApplicationWidget.cs +++ b/ApplicationView/MainApplicationWidget.cs @@ -489,24 +489,26 @@ namespace MatterHackers.MatterControl if (!System.IO.File.Exists(@"/storage/sdcard0/Download/LaunchTestPrint.stl")) { bool showAuthWindow = WizardWindow.ShouldShowAuthPanel?.Invoke() ?? false; - if (showAuthWindow) - { - //Launch window to prompt user to log in - UiThread.RunOnIdle(() => WizardWindow.ShowPrinterSetup()); - } - else - { - //If user in logged in sync before checking to prompt to create printer - ApplicationController.SyncPrinterProfiles().ContinueWith((task) => - { - ApplicationController.Instance.ReloadAdvancedControlsPanel(); - if (!ProfileManager.Instance.ActiveProfiles.Any()) - { - // Start the setup wizard if no profiles exist - UiThread.RunOnIdle(() => WizardWindow.ShowPrinterSetup()); - } - }); - } + if (showAuthWindow) + { + //Launch window to prompt user to log in + UiThread.RunOnIdle(() => WizardWindow.ShowPrinterSetup()); + } + else + { + //If user in logged in sync before checking to prompt to create printer + if (ApplicationController.SyncPrinterProfiles == null) + { + RunSetupIfRequired(); + } + else + { + ApplicationController.SyncPrinterProfiles.Invoke().ContinueWith((task) => + { + RunSetupIfRequired(); + }); + } + } if (OsInformation.OperatingSystem != OSType.Windows) { @@ -532,7 +534,18 @@ namespace MatterHackers.MatterControl }, 2); } } - private EventHandler unregisterEvent; + + private static void RunSetupIfRequired() + { + ApplicationController.Instance.ReloadAdvancedControlsPanel(); + if (!ProfileManager.Instance.ActiveProfiles.Any()) + { + // Start the setup wizard if no profiles exist + UiThread.RunOnIdle(() => WizardWindow.ShowPrinterSetup()); + } + } + + private EventHandler unregisterEvent; public void StartPrintingTest() { QueueData.Instance.RemoveAll(); From 72deb94de30fbed5da27305be1915ebf5952be7f Mon Sep 17 00:00:00 2001 From: John Lewin Date: Wed, 10 Aug 2016 09:38:36 -0700 Subject: [PATCH 11/23] Better convey that ChangeID expects a deviceToken param - Avoid recovery - use PrinterSettings.LoadFile rather than ProfileManager.LoadProfile --- SlicerConfiguration/Settings/SettingsHelpers.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/SlicerConfiguration/Settings/SettingsHelpers.cs b/SlicerConfiguration/Settings/SettingsHelpers.cs index 850e4db2b..ad7cfac1b 100644 --- a/SlicerConfiguration/Settings/SettingsHelpers.cs +++ b/SlicerConfiguration/Settings/SettingsHelpers.cs @@ -444,23 +444,23 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public bool MarkedForDelete { get; set; } = false; public string SHA1 { get; set; } - public void ChangeID(string newID) + public void ChangeID(string deviceToken) { if (ActiveSliceSettings.Instance.ID == this.ID) { - ActiveSliceSettings.Instance.ID = newID; + ActiveSliceSettings.Instance.ID = deviceToken; } string existingProfile = ProfilePath; if (File.Exists(existingProfile)) { - this.ID = newID; + this.ID = deviceToken; File.Move(existingProfile, ProfilePath); } - var profile = ProfileManager.LoadProfile(newID); - profile.ID = newID; - profile.SetValue(SettingsKey.device_token, newID); + var profile = PrinterSettings.LoadFile(ProfilePath); + profile.ID = deviceToken; + profile.SetValue(SettingsKey.device_token, deviceToken); ProfileManager.Instance.Save(); } From c22916c884d59b72d9b4f68fb753893124e4fc7c Mon Sep 17 00:00:00 2001 From: John Lewin Date: Wed, 10 Aug 2016 09:42:32 -0700 Subject: [PATCH 12/23] Move http profile acquisition into LoadProfileAsync --- SlicerConfiguration/Settings/ActiveSliceSettings.cs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/SlicerConfiguration/Settings/ActiveSliceSettings.cs b/SlicerConfiguration/Settings/ActiveSliceSettings.cs index 9c907604e..4fa81bc6f 100644 --- a/SlicerConfiguration/Settings/ActiveSliceSettings.cs +++ b/SlicerConfiguration/Settings/ActiveSliceSettings.cs @@ -159,18 +159,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration internal static async Task SwitchToProfile(string printerID) { - var profile = ProfileManager.LoadProfile(printerID); - ProfileManager.Instance.SetLastProfile(printerID); - - if (profile == null) - { - var printerInfo = ProfileManager.Instance[printerID]; - - profile = await ApplicationController.GetPrinterProfileAsync(printerInfo, null); - } - - Instance = profile ?? ProfileManager.LoadEmptyProfile(); + Instance = (await ProfileManager.LoadProfileAsync(printerID)) ?? ProfileManager.LoadEmptyProfile(); } private static void OnActivePrinterChanged(EventArgs e) From 3bc253a3feb4d1dd70e26868ffcd2cf801ca7c16 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Wed, 10 Aug 2016 09:44:50 -0700 Subject: [PATCH 13/23] Migrate recovery logic from PrinterSettings.LoadFile to PrinterSettings.RecoverProfile --- .../Settings/PrinterSettings.cs | 130 ++++++++---------- 1 file changed, 60 insertions(+), 70 deletions(-) diff --git a/SlicerConfiguration/Settings/PrinterSettings.cs b/SlicerConfiguration/Settings/PrinterSettings.cs index a25720020..bab9f8d9e 100644 --- a/SlicerConfiguration/Settings/PrinterSettings.cs +++ b/SlicerConfiguration/Settings/PrinterSettings.cs @@ -216,96 +216,90 @@ namespace MatterHackers.MatterControl.SlicerConfiguration /// User settings overrides /// public PrinterSettingsLayer UserLayer { get; } = new PrinterSettingsLayer(); - // - public static PrinterSettings LoadFile(string printerProfilePath) + + public static PrinterSettings LoadFile(string printerProfilePath, bool performMigrations = false) { - JObject jObject = null; - try + if (performMigrations) { - jObject = JObject.Parse(File.ReadAllText(printerProfilePath)); - } - catch - { - string profileKey = Path.GetFileNameWithoutExtension(printerProfilePath); - var profile = ProfileManager.Instance[profileKey]; + JObject jObject = null; - if (MatterControlApplication.IsLoading) + try { - UiThread.RunOnIdle(() => - { - bool userIsLoggedIn = !ShouldShowAuthPanel?.Invoke() ?? false; - if (userIsLoggedIn && profile != null) - { - if (profile != null) - { - RevertToMostRecentProfile(profile).ContinueWith((t) => WarnAboutRevert(profile)); - } - else - { - RevertToOemProfile(printerProfilePath); - WarnAboutRevert(profile); - } - } - }, 4); - - return ProfileManager.LoadEmptyProfile(); + jObject = JObject.Parse(File.ReadAllText(printerProfilePath)); } - else + catch { - bool userIsLoggedIn = !ShouldShowAuthPanel?.Invoke() ?? false; - if (userIsLoggedIn && profile != null) - { - RevertToMostRecentProfile(profile).ContinueWith((t) => WarnAboutRevert(profile)); - return ProfileManager.LoadEmptyProfile(); - } - else - { - WarnAboutRevert(profile); - return RevertToOemProfile(printerProfilePath); - } + return null; + } + + int documentVersion = jObject?.GetValue("DocumentVersion")?.Value() ?? PrinterSettings.LatestVersion; + if (documentVersion < PrinterSettings.LatestVersion) + { + printerProfilePath = ProfileMigrations.MigrateDocument(printerProfilePath, documentVersion); } } - int documentVersion = jObject?.GetValue("DocumentVersion")?.Value() ?? PrinterSettings.LatestVersion; - if (documentVersion < PrinterSettings.LatestVersion) - { - printerProfilePath = ProfileMigrations.MigrateDocument(printerProfilePath, documentVersion); - } - - // Reload the document with the new schema try { return JsonConvert.DeserializeObject(File.ReadAllText(printerProfilePath)); } catch { - return RevertToOemProfile(printerProfilePath); + return null; } } - static bool warningOpen = false; + public async static Task RecoverProfile(PrinterInfo printerInfo) + { + bool userIsLoggedIn = !ShouldShowAuthPanel?.Invoke() ?? false; + if (userIsLoggedIn && printerInfo != null) + { + // Attempt to load from MCWS history + var printerSettings = await GetMostRecentProfile(printerInfo); + if (printerSettings == null) + { + // Fall back to OemProfile defaults if load from history fails + printerSettings = RestoreFromOemProfile(printerInfo); + } + + if (printerSettings != null) + { + // Persist any profile recovered above as the current + printerSettings.Save(); + + // Update active instance without calling ReloadAll + ActiveSliceSettings.RefreshActiveInstance(printerSettings); + + WarnAboutRevert(printerInfo); + } + + return printerSettings; + } + + return null; + } + + private static bool warningWindowOpen = false; + public static void WarnAboutRevert(PrinterInfo profile) { - if (!warningOpen) + if (!warningWindowOpen) { - warningOpen = true; + warningWindowOpen = true; UiThread.RunOnIdle(() => { StyledMessageBox.ShowMessageBox((clicedOk) => { - warningOpen = false; + warningWindowOpen = false; }, String.Format("The profile you are attempting to load has been corrupted. We loaded your last usable {0} {1} profile from your recent profile history instead.".Localize(), profile.Make, profile.Model), "Recovered printer profile".Localize(), messageType: StyledMessageBox.MessageType.OK); }); } } - public static PrinterSettings RevertToOemProfile(string printerProfilePath) + public static PrinterSettings RestoreFromOemProfile(PrinterInfo profile) { - string profileKey = Path.GetFileNameWithoutExtension(printerProfilePath); - var profile = ProfileManager.Instance[profileKey]; - string publicProfileDeviceToken = OemSettings.Instance.OemProfiles[profile.Make][profile.Model]; - string publicProfileToLoad = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "temp", "cache", "profiles") + "\\" + publicProfileDeviceToken + ProfileManager.ProfileExtension; + string publicProfileToLoad = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "temp", "cache", "profiles", publicProfileDeviceToken + ProfileManager.ProfileExtension); var oemProfile = JsonConvert.DeserializeObject(File.ReadAllText(publicProfileToLoad)); oemProfile.ID = profile.ID; @@ -315,27 +309,23 @@ namespace MatterHackers.MatterControl.SlicerConfiguration oemProfile.Helpers.SetComPort(profile.ComPort); oemProfile.Save(); + //WarnAboutRevert(profile); + return oemProfile; } - private static async Task RevertToMostRecentProfile(PrinterInfo profile) + private static async Task GetMostRecentProfile(PrinterInfo printerInfo) { - var recentProfileHistoryItems = await ApplicationController.GetProfileHistory(profile.DeviceToken); + var recentProfileHistoryItems = await ApplicationController.GetProfileHistory(printerInfo.DeviceToken); if (recentProfileHistoryItems != null) { string profileToken = recentProfileHistoryItems.OrderByDescending(kvp => kvp.Key).FirstOrDefault().Value; - // Download the specified json profile and persist and activate if successful - var printerProfile = await ApplicationController.GetPrinterProfileAsync(profile, profileToken); - if (printerProfile != null) - { - // Persist downloaded profile - printerProfile.Save(); - - // Update active instance without calling ReloadAll - ActiveSliceSettings.RefreshActiveInstance(printerProfile); - } + // Download and return the specified json profile + return await ApplicationController.GetPrinterProfileAsync(printerInfo, profileToken); } + + return null; } /// From d0ce7a56005e52a68d161008640b6ddf8f7832e7 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Wed, 10 Aug 2016 09:49:32 -0700 Subject: [PATCH 14/23] Move recovery orchestration into ProfileManager.LoadProfileAsync --- SetupWizard/ImportSettingsPage.cs | 1 + .../Settings/ProfileManager.cs | 47 +++++++++++++------ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/SetupWizard/ImportSettingsPage.cs b/SetupWizard/ImportSettingsPage.cs index ebd3e5aeb..7bacd4a63 100644 --- a/SetupWizard/ImportSettingsPage.cs +++ b/SetupWizard/ImportSettingsPage.cs @@ -62,6 +62,7 @@ namespace MatterHackers.MatterControl this.destinationLayer = destinationLayer; this.sectionName = sectionName; + // TODO: Need to handle load failures for import attempts settingsToImport = PrinterSettings.LoadFile(settingsFilePath); this.headerLabel.Text = "Select What to Import".Localize(); diff --git a/SlicerConfiguration/Settings/ProfileManager.cs b/SlicerConfiguration/Settings/ProfileManager.cs index 175b1442c..697dc0ad3 100644 --- a/SlicerConfiguration/Settings/ProfileManager.cs +++ b/SlicerConfiguration/Settings/ProfileManager.cs @@ -124,7 +124,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration // Load the last selected printer profile or an empty profile ActiveSliceSettings.Instance = Instance.LoadLastProfile() ?? LoadEmptyProfile(); - // In either case, wire up the CollectionChanged event Instance.Profiles.CollectionChanged += Profiles_CollectionChanged; } @@ -206,7 +205,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public PrinterSettings LoadLastProfile() { - return LoadProfile(this.LastProfileID); + return LoadProfileAsync(this.LastProfileID); } public void SetLastProfile(string printerID) @@ -228,15 +227,17 @@ namespace MatterHackers.MatterControl.SlicerConfiguration } /// - /// Loads the specified PrinterProfile + /// Loads the specified PrinterProfile, performing recovery options if required /// /// The profile ID to load /// Return the in memory instance if already loaded. Alternatively, reload from disk /// - public static PrinterSettings LoadProfile(string profileID, bool useActiveInstance = true) + public static async Task LoadProfileAsync(string profileID, bool useActiveInstance = true) { + var printerInfo = ProfileManager.Instance[profileID]; + // Only load profiles by ID that are defined in the profiles document - if (ProfileManager.Instance[profileID] == null) + if (printerInfo == null) { return null; } @@ -246,19 +247,37 @@ namespace MatterHackers.MatterControl.SlicerConfiguration return ActiveSliceSettings.Instance; } - string profilePath = Path.Combine(ProfilesPath, profileID + ProfileManager.ProfileExtension); - return File.Exists(profilePath) ? LoadProfileFromDisk(profilePath) : null; - } + PrinterSettings printerSettings; - internal static PrinterSettings LoadProfileFromDisk(string profilePath) - { - if (File.Exists(profilePath)) + string profilePath = Path.Combine(ProfilesPath, profileID + ProfileManager.ProfileExtension); + if (!File.Exists(profilePath)) { - return PrinterSettings.LoadFile(profilePath); + // Attempt to load from MCWS if missing on disk + printerSettings = await ApplicationController.GetPrinterProfileAsync(printerInfo, null); + if (printerSettings != null) + { + // If successful, persist downloaded profile + printerSettings.Save(); + } + + return printerSettings; + } + + // LoadOrRecoverProfile - if exists on disk, attempt to load or fall back using recovery logic + printerSettings = PrinterSettings.LoadFile(profilePath, performMigrations: true); + if (printerSettings != null) + { + return printerSettings; } else { - return LoadEmptyProfile(); + int delayDuration = MatterControlApplication.IsLoading ? 4 : 0; + + // Schedule a recovery rather than blocking until the MCWS and/or OemProfile restore complete + UiThread.RunOnIdle(() => PrinterSettings.RecoverProfile(printerInfo), delayDuration); + + // Return a short lived profile which should be reset after recovery + return ProfileManager.LoadEmptyProfile(); } } @@ -279,7 +298,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration switch (importType) { case ProfileManager.ProfileExtension: - var profile = ProfileManager.LoadProfileFromDisk(settingsFilePath); + var profile = PrinterSettings.LoadFile(settingsFilePath); profile.ID = printerInfo.ID; profile.ClearValue(SettingsKey.device_token); printerInfo.DeviceToken = ""; From e7b82a47e4f42c27fb4667a0e07649d108a9e7c7 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Thu, 11 Aug 2016 10:35:23 -0700 Subject: [PATCH 15/23] Improve history recovery, try up to the last 5 history items --- .../Settings/PrinterSettings.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/SlicerConfiguration/Settings/PrinterSettings.cs b/SlicerConfiguration/Settings/PrinterSettings.cs index bab9f8d9e..ed75d5d69 100644 --- a/SlicerConfiguration/Settings/PrinterSettings.cs +++ b/SlicerConfiguration/Settings/PrinterSettings.cs @@ -255,7 +255,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration if (userIsLoggedIn && printerInfo != null) { // Attempt to load from MCWS history - var printerSettings = await GetMostRecentProfile(printerInfo); + var printerSettings = await GetFirstValidHistoryItem(printerInfo); if (printerSettings == null) { // Fall back to OemProfile defaults if load from history fails @@ -314,15 +314,25 @@ namespace MatterHackers.MatterControl.SlicerConfiguration return oemProfile; } - private static async Task GetMostRecentProfile(PrinterInfo printerInfo) + private static async Task GetFirstValidHistoryItem(PrinterInfo printerInfo) { var recentProfileHistoryItems = await ApplicationController.GetProfileHistory(printerInfo.DeviceToken); if (recentProfileHistoryItems != null) { - string profileToken = recentProfileHistoryItems.OrderByDescending(kvp => kvp.Key).FirstOrDefault().Value; - - // Download and return the specified json profile - return await ApplicationController.GetPrinterProfileAsync(printerInfo, profileToken); + // Iterate history, skipping the first item, limiting to the next five, attempt to load and return the first success + foreach (var keyValue in recentProfileHistoryItems.OrderByDescending(kvp => kvp.Key).Skip(1).Take(5)) + { + // Attempt to download and parse each profile, returning if successful + try + { + var printerSettings = await ApplicationController.GetPrinterProfileAsync(printerInfo, keyValue.Value); + if (printerSettings != null) + { + return printerSettings; + } + } + catch { } + }; } return null; From 6079694be5dcffd3b26a758efca8c3e41e12d9c0 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Thu, 11 Aug 2016 11:09:06 -0700 Subject: [PATCH 16/23] Prevent profile recovery during startup - Fix whitespace - Remove unused comportNames variable - Prevent assigning profile reload if already loaded --- .../Settings/ActiveSliceSettings.cs | 20 ++------- .../Settings/ProfileManager.cs | 41 +++++++++++++++---- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/SlicerConfiguration/Settings/ActiveSliceSettings.cs b/SlicerConfiguration/Settings/ActiveSliceSettings.cs index 4fa81bc6f..ddfb12571 100644 --- a/SlicerConfiguration/Settings/ActiveSliceSettings.cs +++ b/SlicerConfiguration/Settings/ActiveSliceSettings.cs @@ -78,16 +78,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration { OnActivePrinterChanged(null); - string[] comportNames = FrostedSerialPort.GetPortNames(); - if (ActiveSliceSettings.Instance.PrinterSelected) { if (Instance.GetValue(SettingsKey.auto_connect)) { UiThread.RunOnIdle(() => { - //PrinterConnectionAndCommunication.Instance.HaltConnectionThread(); - PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter(); + //PrinterConnectionAndCommunication.Instance.HaltConnectionThread(); + PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter(); }, 2); } } @@ -143,18 +141,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration static ActiveSliceSettings() { - // Load Startup Profile - var startupProfile = ProfileManager.Instance.LoadLastProfile(); - if (startupProfile != null) - { - Instance = startupProfile; - } - - if (Instance == null) - { - // Load an empty profile with just the MatterHackers base settings from config.json - Instance = ProfileManager.LoadEmptyProfile(); - } + // Load last profile or fall back to empty + Instance = ProfileManager.Instance.LoadLastProfileWithoutRecovery() ?? ProfileManager.LoadEmptyProfile(); } internal static async Task SwitchToProfile(string printerID) diff --git a/SlicerConfiguration/Settings/ProfileManager.cs b/SlicerConfiguration/Settings/ProfileManager.cs index 697dc0ad3..c7ce5b6ab 100644 --- a/SlicerConfiguration/Settings/ProfileManager.cs +++ b/SlicerConfiguration/Settings/ProfileManager.cs @@ -121,8 +121,16 @@ namespace MatterHackers.MatterControl.SlicerConfiguration Instance = new ProfileManager(); } - // Load the last selected printer profile or an empty profile - ActiveSliceSettings.Instance = Instance.LoadLastProfile() ?? LoadEmptyProfile(); + if (!MatterControlApplication.IsLoading && ActiveSliceSettings.Instance.ID != Instance.LastProfileID) + { + Task.Run(async () => + { + var lastProfile = await LoadProfileAsync(Instance.LastProfileID); + + // Load the last selected printer profile or an empty profile + ActiveSliceSettings.Instance = lastProfile ?? LoadEmptyProfile(); + }); + } // In either case, wire up the CollectionChanged event Instance.Profiles.CollectionChanged += Profiles_CollectionChanged; @@ -195,25 +203,22 @@ namespace MatterHackers.MatterControl.SlicerConfiguration get { string activeUserName = UserSettings.Instance.get("ActiveUserName"); - string settingsKey = $"ActiveProfileID-{activeUserName}"; - - return UserSettings.Instance.get(settingsKey); + return UserSettings.Instance.get($"ActiveProfileID-{activeUserName}"); } } public bool PrintersImported { get; set; } = false; - public PrinterSettings LoadLastProfile() + public PrinterSettings LoadLastProfileWithoutRecovery() { - return LoadProfileAsync(this.LastProfileID); + return LoadWithoutRecovery(this.LastProfileID); } public void SetLastProfile(string printerID) { string activeUserName = UserSettings.Instance.get("ActiveUserName"); - string settingsKey = $"ActiveProfileID-{activeUserName}"; - UserSettings.Instance.set(settingsKey, printerID); + UserSettings.Instance.set($"ActiveProfileID-{activeUserName}", printerID); } public string ProfilePath(PrinterInfo printer) @@ -226,6 +231,24 @@ namespace MatterHackers.MatterControl.SlicerConfiguration return Path.Combine(ProfileManager.ProfilesPath, printerID + ProfileExtension); } + public static PrinterSettings LoadWithoutRecovery(string profileID) + { + string profilePath = Path.Combine(ProfilesPath, profileID + ProfileManager.ProfileExtension); + if (File.Exists(profilePath)) + { + try + { + return PrinterSettings.LoadFile(profilePath); + } + catch + { + return null; + } + } + + return null; + } + /// /// Loads the specified PrinterProfile, performing recovery options if required /// From ea381ef7b113ee5fd1815416773cdf7ce02008fd Mon Sep 17 00:00:00 2001 From: John Lewin Date: Thu, 11 Aug 2016 11:23:05 -0700 Subject: [PATCH 17/23] Refactor LoadProfileAsync to reuse LoadWithoutRecovery --- .../Settings/ProfileManager.cs | 47 +++++++------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/SlicerConfiguration/Settings/ProfileManager.cs b/SlicerConfiguration/Settings/ProfileManager.cs index c7ce5b6ab..713578807 100644 --- a/SlicerConfiguration/Settings/ProfileManager.cs +++ b/SlicerConfiguration/Settings/ProfileManager.cs @@ -257,51 +257,38 @@ namespace MatterHackers.MatterControl.SlicerConfiguration /// public static async Task LoadProfileAsync(string profileID, bool useActiveInstance = true) { - var printerInfo = ProfileManager.Instance[profileID]; - - // Only load profiles by ID that are defined in the profiles document - if (printerInfo == null) - { - return null; - } - if (useActiveInstance && ActiveSliceSettings.Instance?.ID == profileID) { return ActiveSliceSettings.Instance; } - PrinterSettings printerSettings; - - string profilePath = Path.Combine(ProfilesPath, profileID + ProfileManager.ProfileExtension); - if (!File.Exists(profilePath)) + // Only load profiles by ID that are defined in the profiles document + var printerInfo = ProfileManager.Instance[profileID]; + if (printerInfo == null) { - // Attempt to load from MCWS if missing on disk - printerSettings = await ApplicationController.GetPrinterProfileAsync(printerInfo, null); - if (printerSettings != null) - { - // If successful, persist downloaded profile - printerSettings.Save(); - } - - return printerSettings; + return null; } - // LoadOrRecoverProfile - if exists on disk, attempt to load or fall back using recovery logic - printerSettings = PrinterSettings.LoadFile(profilePath, performMigrations: true); + // Attempt to load from disk, pull from the web or fall back using recovery logic + PrinterSettings printerSettings = LoadWithoutRecovery(profileID); if (printerSettings != null) { return printerSettings; } else { - int delayDuration = MatterControlApplication.IsLoading ? 4 : 0; - - // Schedule a recovery rather than blocking until the MCWS and/or OemProfile restore complete - UiThread.RunOnIdle(() => PrinterSettings.RecoverProfile(printerInfo), delayDuration); - - // Return a short lived profile which should be reset after recovery - return ProfileManager.LoadEmptyProfile(); + // Attempt to load from MCWS if missing on disk + printerSettings = await ApplicationController.GetPrinterProfileAsync?.Invoke (printerInfo, null); + if (printerSettings != null) + { + // If successful, persist downloaded profile and return + printerSettings.Save(); + return printerSettings; + } } + + // Otherwise attempt to recover to a working profile + return await PrinterSettings.RecoverProfile(printerInfo); } internal static bool ImportFromExisting(string settingsFilePath) From d4c075150575b02943112aeb5820b25817de927d Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 12 Aug 2016 13:03:47 -0700 Subject: [PATCH 18/23] Update ActiveSliceSettings.Instance before calling SettingChanged event --- SlicerConfiguration/Settings/ActiveSliceSettings.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SlicerConfiguration/Settings/ActiveSliceSettings.cs b/SlicerConfiguration/Settings/ActiveSliceSettings.cs index ddfb12571..de3551194 100644 --- a/SlicerConfiguration/Settings/ActiveSliceSettings.cs +++ b/SlicerConfiguration/Settings/ActiveSliceSettings.cs @@ -98,10 +98,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration { bool themeChanged = activeInstance.GetValue(SettingsKey.active_theme_index) != updatedProfile.GetValue(SettingsKey.active_theme_index); - SliceSettingsWidget.SettingChanged.CallEvents(null, new StringEventArgs(SettingsKey.printer_name)); - activeInstance = updatedProfile; + SliceSettingsWidget.SettingChanged.CallEvents(null, new StringEventArgs(SettingsKey.printer_name)); + if (themeChanged) { UiThread.RunOnIdle(() => SwitchToPrinterTheme(true)); From 70899bbedf31f6e6cad3f938e863c4ea7cb25e42 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 12 Aug 2016 13:18:45 -0700 Subject: [PATCH 19/23] Prevent unhandled exceptions when indexing into OemProfiles - Return null on caught exceptions - Issue MatterHackers/MatterControl#1285 --- .../Settings/PrinterSettings.cs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/SlicerConfiguration/Settings/PrinterSettings.cs b/SlicerConfiguration/Settings/PrinterSettings.cs index ed75d5d69..3c3bf3263 100644 --- a/SlicerConfiguration/Settings/PrinterSettings.cs +++ b/SlicerConfiguration/Settings/PrinterSettings.cs @@ -298,18 +298,22 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public static PrinterSettings RestoreFromOemProfile(PrinterInfo profile) { - string publicProfileDeviceToken = OemSettings.Instance.OemProfiles[profile.Make][profile.Model]; - string publicProfileToLoad = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "temp", "cache", "profiles", publicProfileDeviceToken + ProfileManager.ProfileExtension); + PrinterSettings oemProfile = null; - var oemProfile = JsonConvert.DeserializeObject(File.ReadAllText(publicProfileToLoad)); - oemProfile.ID = profile.ID; - oemProfile.SetValue(SettingsKey.printer_name, profile.Name); - oemProfile.DocumentVersion = PrinterSettings.LatestVersion; + try + { + string publicProfileDeviceToken = OemSettings.Instance.OemProfiles[profile.Make][profile.Model]; + string publicProfileToLoad = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "temp", "cache", "profiles", publicProfileDeviceToken + ProfileManager.ProfileExtension); - oemProfile.Helpers.SetComPort(profile.ComPort); - oemProfile.Save(); + oemProfile = JsonConvert.DeserializeObject(File.ReadAllText(publicProfileToLoad)); + oemProfile.ID = profile.ID; + oemProfile.SetValue(SettingsKey.printer_name, profile.Name); + oemProfile.DocumentVersion = PrinterSettings.LatestVersion; - //WarnAboutRevert(profile); + oemProfile.Helpers.SetComPort(profile.ComPort); + oemProfile.Save(); + } + catch { } return oemProfile; } From b498f80254cc210848de8156c59f2a32b13c14d4 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 12 Aug 2016 13:20:05 -0700 Subject: [PATCH 20/23] Fall back to dummy profile to assist Delete operations as last resort --- .../Settings/PrinterSettings.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/SlicerConfiguration/Settings/PrinterSettings.cs b/SlicerConfiguration/Settings/PrinterSettings.cs index 3c3bf3263..eb953a6af 100644 --- a/SlicerConfiguration/Settings/PrinterSettings.cs +++ b/SlicerConfiguration/Settings/PrinterSettings.cs @@ -261,7 +261,23 @@ namespace MatterHackers.MatterControl.SlicerConfiguration // Fall back to OemProfile defaults if load from history fails printerSettings = RestoreFromOemProfile(printerInfo); } - + + if (printerSettings == null) + { + // If we still have failed to recover a profile, create an empty profile with + // just enough data to delete the printer + printerSettings = ProfileManager.LoadEmptyProfile(); + printerSettings.ID = printerInfo.ID; + printerSettings.UserLayer[SettingsKey.device_token] = printerInfo.DeviceToken; + printerSettings.Helpers.SetComPort(printerInfo.ComPort); + printerSettings.SetValue(SettingsKey.printer_name, printerInfo.Name); + + // Add any setting value to the OemLayer to pass the .PrinterSelected property + printerSettings.OemLayer = new PrinterSettingsLayer(); + printerSettings.OemLayer.Add("empty", "setting"); + printerSettings.Save(); + } + if (printerSettings != null) { // Persist any profile recovered above as the current From c6658eaf2aa2ce39ee3b4ab3877ee25ff8087770 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Fri, 12 Aug 2016 15:07:04 -0700 Subject: [PATCH 21/23] Make the EULA come up faster. --- SetupWizard/LicenseAgreementPage.cs | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/SetupWizard/LicenseAgreementPage.cs b/SetupWizard/LicenseAgreementPage.cs index 53057661d..86393971e 100644 --- a/SetupWizard/LicenseAgreementPage.cs +++ b/SetupWizard/LicenseAgreementPage.cs @@ -48,29 +48,14 @@ public class LicenseAgreementPage : WizardPage scrollable.ScrollArea.HAnchor = HAnchor.ParentLeftRight; contentRow.AddChild(scrollable); - var textBox = new WrappedTextWidget("Loading End User License Agreement...", textColor: ActiveTheme.Instance.PrimaryTextColor, doubleBufferText: false); + var textBox = new WrappedTextWidget(eulaText, textColor: ActiveTheme.Instance.PrimaryTextColor, doubleBufferText: false) + { + DrawFromHintedCache = true, + Name = "LicenseAgreementPage", + }; scrollable.ScrollArea.Margin = new BorderDouble(0, 0, 15, 0); scrollable.AddChild(textBox); - // wrap the text on a thread and show it when it is ready - { - UiThread.RunOnIdle(async () => - { - WrappedTextWidget eulaTextBox = textBox; - await Task.Run(() => - { - eulaTextBox = new WrappedTextWidget(eulaText, textColor: ActiveTheme.Instance.PrimaryTextColor, doubleBufferText: false) - { - DrawFromHintedCache = true, - Name = "LicenseAgreementPage", - }; - }); - - scrollable.ScrollArea.RemoveChild(textBox); - scrollable.AddChild(eulaTextBox); - }); - } - var acceptButton = textImageButtonFactory.Generate("Accept".Localize()); acceptButton.Click += (s, e) => { From 5237ef09dacfb602688ca31f23a9d1d74d4260e6 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 12 Aug 2016 15:59:53 -0700 Subject: [PATCH 22/23] Assign ActiveSliceSettings.Instance on the UI thread --- SlicerConfiguration/Settings/ProfileManager.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SlicerConfiguration/Settings/ProfileManager.cs b/SlicerConfiguration/Settings/ProfileManager.cs index 713578807..b4b5287d0 100644 --- a/SlicerConfiguration/Settings/ProfileManager.cs +++ b/SlicerConfiguration/Settings/ProfileManager.cs @@ -125,10 +125,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration { Task.Run(async () => { + // Load or download on a background thread var lastProfile = await LoadProfileAsync(Instance.LastProfileID); - // Load the last selected printer profile or an empty profile - ActiveSliceSettings.Instance = lastProfile ?? LoadEmptyProfile(); + UiThread.RunOnIdle(() => + { + // Assign on the UI thread + ActiveSliceSettings.Instance = lastProfile ?? LoadEmptyProfile(); + }); }); } From 4e83bab707d59263efec8fbb500bed00cec1a57c Mon Sep 17 00:00:00 2001 From: John Lewin Date: Mon, 15 Aug 2016 13:34:38 -0700 Subject: [PATCH 23/23] Avoid null conditional result on awaited call to workaround Mono error - Issue MatterHackers/MCCentral#283 --- SlicerConfiguration/Settings/ProfileManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SlicerConfiguration/Settings/ProfileManager.cs b/SlicerConfiguration/Settings/ProfileManager.cs index b4b5287d0..5496b34a5 100644 --- a/SlicerConfiguration/Settings/ProfileManager.cs +++ b/SlicerConfiguration/Settings/ProfileManager.cs @@ -279,10 +279,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration { return printerSettings; } - else + else if (ApplicationController.GetPrinterProfileAsync != null) { // Attempt to load from MCWS if missing on disk - printerSettings = await ApplicationController.GetPrinterProfileAsync?.Invoke (printerInfo, null); + printerSettings = await ApplicationController.GetPrinterProfileAsync(printerInfo, null); if (printerSettings != null) { // If successful, persist downloaded profile and return