diff --git a/MatterControl.Printing/Settings/PrinterSettings.cs b/MatterControl.Printing/Settings/PrinterSettings.cs index 6018747e3..37f2a201a 100644 --- a/MatterControl.Printing/Settings/PrinterSettings.cs +++ b/MatterControl.Printing/Settings/PrinterSettings.cs @@ -1317,6 +1317,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration layerCascade = DefaultLayerCascade; } + if (settingsKey == "external_perimeters_first") + { + var a = 0; + } + string settingsValue = null; foreach (PrinterSettingsLayer layer in layerCascade) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 73ce469b0..787694d92 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -449,12 +449,25 @@ namespace MatterHackers.MatterControl public event EventHandler ReloadSettingsTriggered; - public void ReloadSettings(PrinterConfig printer) + public void UpdateAllSettingsStyles(PrinterConfig printer) { var printerTabPage = this.MainView.Descendants().Where(page => page.Printer == printer).FirstOrDefault(); if (printerTabPage != null) { - ApplicationController.Instance.IsReloading = true; + var sliceSettingsWidget = printerTabPage.Descendants().FirstOrDefault(); + if (sliceSettingsWidget != null) + { + sliceSettingsWidget.UpdateAllStyles(); + } + } + } + + public void ReloadSettings(PrinterConfig printer) + { + var printerTabPage = this.MainView.Descendants().Where(page => page.Printer == printer).FirstOrDefault(); + if (printerTabPage != null) + { + Instance.IsReloading = true; var settingsContext = new SettingsContext( printer, null, @@ -475,7 +488,7 @@ namespace MatterHackers.MatterControl } sideBar.ReplacePage("Slice Settings", new SliceSettingsWidget(printer, settingsContext, Theme)); - ApplicationController.Instance.IsReloading = false; + Instance.IsReloading = false; } ReloadSettingsTriggered?.Invoke(null, null); @@ -1069,13 +1082,15 @@ namespace MatterHackers.MatterControl { if (printer != null || this.ActivePrinters.Count() == 1) { - // If unspecified but count is one, select the one active printer - if (printer == null) + // If unspecified but count is one, select the one active printer + if (printer == null) { printer = this.ActivePrinters.First(); } - DialogWindow.Show( + printer.ForceSceneSettingsUpdate(); + + DialogWindow.Show( new ExportPrintItemPage(libraryItems, centerOnBed, printer)); } else @@ -2020,7 +2035,7 @@ namespace MatterHackers.MatterControl var gcodeFilePath = await editContext.GCodeFilePath(printerConfig); var printItemName = editContext.SourceItem.Name; - printerConfig.StartingNewPrint(); + printerConfig.ForceSceneSettingsUpdate(); // Exit if called in a non-applicable state if (printerConfig.Connection.CommunicationState != CommunicationStates.Connected diff --git a/MatterControlLib/ApplicationView/Config/PrinterConfig.cs b/MatterControlLib/ApplicationView/Config/PrinterConfig.cs index 513d24697..58ef1fc26 100644 --- a/MatterControlLib/ApplicationView/Config/PrinterConfig.cs +++ b/MatterControlLib/ApplicationView/Config/PrinterConfig.cs @@ -57,10 +57,10 @@ namespace MatterHackers.MatterControl private double heatDistance = 0; private double heatStart = 0; - private PrinterConfig() + // Hide the default constructor + private PrinterConfig() { - this.Connection = new PrinterConnection(this); - } + } public bool PrintButtonEnabled() { @@ -71,37 +71,39 @@ namespace MatterHackers.MatterControl private PrinterSettingsLayer sceneOverrides = new PrinterSettingsLayer(); - private RunningInterval checkForSceneLayer; private object locker = new object(); private ulong undoBufferHashCode = ulong.MaxValue; private int sceneChildrenCount = 0; + private RunningInterval sceneLayerUpdateInterval; - public void StartingNewPrint() + /// + /// Make sure any settings object that has been added to the scene is processed right away + /// + public void ForceSceneSettingsUpdate() { - undoBufferHashCode = ulong.MaxValue; + undoBufferHashCode = ulong.MaxValue; + UpdateSceneLayer(); } - private PrinterSettingsLayer GetSceneLayer() - { + private void UpdateSceneLayer() + { var scene = Bed?.Scene; if (scene != null) { var undoBuffer = scene.UndoBuffer; - if (sceneOverrides != null - && undoBuffer != null + if (scene.Children.Count == 0 + || (undoBuffer != null && undoBufferHashCode == undoBuffer.GetLongHashCode() - && sceneChildrenCount == scene.Children.Count) + && sceneChildrenCount == scene.Children.Count)) { - return sceneOverrides; + return; } - var foundPartSettings = false; var newSceneOverrides = new PrinterSettingsLayer(); // accumulate all the scene overrides ordered by their names, which is the order they will be in the design tree foreach (var partSettingsObject in scene.DescendantsAndSelf().Where(c => c is PartSettingsObject3D && c.Parent?.WorldPrintable() == true).OrderBy(i => i.Name)) { - foundPartSettings = true; var settings = ((PartSettingsObject3D)partSettingsObject).Overrides; foreach (var setting in settings) { @@ -110,7 +112,7 @@ namespace MatterHackers.MatterControl } var same = newSceneOverrides.Count == sceneOverrides.Count && !newSceneOverrides.Except(sceneOverrides).Any(); - // if settings count and keys the same, check the value of the settings + // if settings count and keys are the same, check the value of the settings if (same && sceneOverrides.Count > 0) { // check each setting if it is the same @@ -126,66 +128,54 @@ namespace MatterHackers.MatterControl // if they are different if (!same) { - var settingsToUpdate = new HashSet(); + var settingsToRevert = new PrinterSettingsLayer(); + var settingsToSet = new PrinterSettingsLayer(); + foreach (var kvp in sceneOverrides) { - settingsToUpdate.Add(kvp.Key); - } + if (!newSceneOverrides.ContainsKey(kvp.Key)) + { + settingsToRevert[kvp.Key] = kvp.Value; + } + } + foreach (var kvp in newSceneOverrides) { - settingsToUpdate.Add(kvp.Key); - } + if (newSceneOverrides[kvp.Key] != kvp.Value) + { + settingsToSet[kvp.Key] = newSceneOverrides[kvp.Key]; + } + } - // store that current set - sceneOverrides = newSceneOverrides; + // store that current set + sceneOverrides = newSceneOverrides; - // we are about to update settings but they are stored in the scene not the profile so we don't have to save anything - var updateList = settingsToUpdate.ToList(); ProfileManager.SaveOnSingleSettingChange = false; - for (int i = 0; i < updateList.Count; i++) - { - Settings.OnSettingChanged(updateList[i]); - } - ProfileManager.SaveOnSingleSettingChange = true; - } - - if (foundPartSettings) - { - lock (locker) - { - if (checkForSceneLayer == null) - { - checkForSceneLayer = UiThread.SetInterval(() => - { - GetSceneLayer(); - }, .5); - } - } + Settings.RestoreConflictingUserOverrides(settingsToRevert); + foreach(var setting in newSceneOverrides) + { + Settings.SetValue(setting.Key, setting.Value, sceneOverrides); + } + ProfileManager.SaveOnSingleSettingChange = true; + ApplicationController.Instance.UpdateAllSettingsStyles(this); } - else if (checkForSceneLayer != null) - { - lock (locker) - { - // we don't have a scene layer so remove the interval - UiThread.ClearInterval(checkForSceneLayer); - checkForSceneLayer = null; - } - } - // return the current set - if (undoBuffer != null) + // return the current set + if (undoBuffer != null) { undoBufferHashCode = undoBuffer.GetLongHashCode(); } sceneChildrenCount = scene.Children.Count; - return sceneOverrides; } - - return null; } - public PrinterConfig(PrinterSettings settings) + private PrinterSettingsLayer GetSceneLayer() + { + return sceneOverrides; + } + + public PrinterConfig(PrinterSettings settings) { this.Settings = settings; @@ -211,6 +201,11 @@ namespace MatterHackers.MatterControl this.Bed.InvalidateBedMesh(); this.Settings.SettingChanged += Printer_SettingChanged; + + sceneLayerUpdateInterval = UiThread.SetInterval(() => + { + UpdateSceneLayer(); + }, .5); } @@ -478,8 +473,11 @@ namespace MatterHackers.MatterControl public void Dispose() { - // Unregister listeners - this.Settings.SettingChanged -= Printer_SettingChanged; + UiThread.ClearInterval(sceneLayerUpdateInterval); + sceneLayerUpdateInterval = null; + + // Unregister listeners + this.Settings.SettingChanged -= Printer_SettingChanged; this.Connection.CommunicationStateChanged -= Connection_CommunicationStateChanged; this.Connection.DetailedPrintingStateChanged -= Connection_CommunicationStateChanged; this.Connection.PrintFinished -= Connection_PrintFinished; diff --git a/MatterControlLib/Library/Widgets/AddMaterialDialog.cs b/MatterControlLib/Library/Widgets/AddMaterialDialog.cs index 6f2aef4d5..b100140bc 100644 --- a/MatterControlLib/Library/Widgets/AddMaterialDialog.cs +++ b/MatterControlLib/Library/Widgets/AddMaterialDialog.cs @@ -30,7 +30,6 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.Localizations; -using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.SlicerConfiguration; using System; diff --git a/MatterControlLib/SlicerConfiguration/UIFields/DoubleField.cs b/MatterControlLib/SlicerConfiguration/UIFields/DoubleField.cs index 83d765b82..04d83b063 100644 --- a/MatterControlLib/SlicerConfiguration/UIFields/DoubleField.cs +++ b/MatterControlLib/SlicerConfiguration/UIFields/DoubleField.cs @@ -28,8 +28,6 @@ either expressed or implied, of the FreeBSD Project. */ using MatterHackers.Agg.UI; -using MatterHackers.DataConverters3D; -using MatterHackers.MatterControl.DesignTools; namespace MatterHackers.MatterControl.SlicerConfiguration {