From d10975d0a90b821d5f8bfda6cbf4d420d18b4c99 Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Sun, 22 May 2022 17:39:36 -0700 Subject: [PATCH 1/3] Limiting the processing of CSG to bounds overlap --- .../PartPreviewWindow/View3D/Actions/SubtractObject3D.cs | 6 ------ Submodules/agg-sharp | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D.cs index 6b95c7935..9f9808947 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D.cs @@ -155,12 +155,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D { foreach (var keep in keepObjects.Select((r) => (obj3D: r, matrix: r.WorldMatrix())).ToList()) { - progressStatus.Status = "Copy Remove"; - reporter?.Report(progressStatus); - - progressStatus.Status = "Copy Keep"; - reporter?.Report(progressStatus); - progressStatus.Status = "Do CSG"; reporter?.Report(progressStatus); var result = BooleanProcessing.Do(keep.obj3D.Mesh, diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index ba0221a7c..3ed0d3e0d 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit ba0221a7cfee2aeceb8980ed2113d107b42709c0 +Subproject commit 3ed0d3e0d5fe7368273223553b87e86895efe281 From 7154180e50c0fa1975a216e5451dac3a7ca4db3f Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Mon, 23 May 2022 11:08:42 -0700 Subject: [PATCH 2/3] make new part opens not undo to an empty plate --- MatterControlLib/ApplicationView/ApplicationController.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 8b3c9f282..beaf71761 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -762,7 +762,12 @@ namespace MatterHackers.MatterControl await this.MainView.CreateNewDesignTab(false); var workspace = this.Workspaces.Last(); - workspace.SceneContext.AddToPlate(selectedLibraryItems); + var insertionGroup = workspace.SceneContext.AddToPlate(selectedLibraryItems); + + // wait for the insertion to finish + await insertionGroup.LoadingItemsTask; + // then clear the undo buffer so we don't ask to save and undoing does not remove the starting part + workspace.SceneContext.Scene.UndoBuffer.ClearHistory(); } internal void BlinkTab(ITab tab) From e218b6b96130eed39d3a8b143c6894fffc4c31a0 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Mon, 23 May 2022 15:11:49 -0700 Subject: [PATCH 3/3] Make Part Setting have undo support Make checking for scene overrides check if the scene has changed first faster MeshAllowedBounds calculation --- .../Settings/PrinterSettings.cs | 82 +++++++++++++------ .../ApplicationView/Config/PrinterConfig.cs | 10 ++- .../PrinterExtensionMethods.cs | 2 +- .../Operations/PartSettingsObject3D.cs | 46 ++++++++--- Submodules/agg-sharp | 2 +- 5 files changed, 103 insertions(+), 39 deletions(-) diff --git a/MatterControl.Printing/Settings/PrinterSettings.cs b/MatterControl.Printing/Settings/PrinterSettings.cs index 4139265e4..6018747e3 100644 --- a/MatterControl.Printing/Settings/PrinterSettings.cs +++ b/MatterControl.Printing/Settings/PrinterSettings.cs @@ -367,6 +367,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration } } + + [JsonIgnore] + private RectangleDouble _meshAllowedBounds; + /// /// The bounds that a mesh can be placed at and the gcode it creates will be within the bed /// @@ -375,38 +379,48 @@ namespace MatterHackers.MatterControl.SlicerConfiguration { get { - var firstLayerExtrusionWidth = GetDouble(SettingsKey.first_layer_extrusion_width); - var bedBounds = BedBounds; - var totalOffset = 0.0; - - if (GetBool(SettingsKey.create_raft)) - { - // The slicing engine creates a raft 3x the extrusion width - firstLayerExtrusionWidth *= 3; - totalOffset += firstLayerExtrusionWidth; - totalOffset += GetDouble(SettingsKey.raft_extra_distance_around_part); - } - - if (GetBool(SettingsKey.create_skirt)) + if (_meshAllowedBounds.Width == 0) { - totalOffset += GetValue(SettingsKey.skirt_distance); - totalOffset += (GetDouble(SettingsKey.skirts) + .5) * firstLayerExtrusionWidth; - // for every 400mm of min skirt length add another skirt loops - totalOffset += GetDouble(SettingsKey.min_skirt_length) / (20 * 20); + CacluateMeshAllowedBounds(); } - if (GetBool(SettingsKey.create_brim) - && !GetBool(SettingsKey.create_raft)) - { - totalOffset += GetValue(SettingsKey.brims) * GetDouble(SettingsKey.first_layer_extrusion_width); - } - - bedBounds.Inflate(-totalOffset); - - return bedBounds; + return _meshAllowedBounds; } } + private void CacluateMeshAllowedBounds() + { + var firstLayerExtrusionWidth = GetDouble(SettingsKey.first_layer_extrusion_width); + var bedBounds = BedBounds; + var totalOffset = 0.0; + + if (GetBool(SettingsKey.create_raft)) + { + // The slicing engine creates a raft 3x the extrusion width + firstLayerExtrusionWidth *= 3; + totalOffset += firstLayerExtrusionWidth; + totalOffset += GetDouble(SettingsKey.raft_extra_distance_around_part); + } + + if (GetBool(SettingsKey.create_skirt)) + { + totalOffset += GetValue(SettingsKey.skirt_distance); + totalOffset += (GetDouble(SettingsKey.skirts) + .5) * firstLayerExtrusionWidth; + // for every 400mm of min skirt length add another skirt loops + totalOffset += GetDouble(SettingsKey.min_skirt_length) / (20 * 20); + } + + if (GetBool(SettingsKey.create_brim) + && !GetBool(SettingsKey.create_raft)) + { + totalOffset += GetValue(SettingsKey.brims) * GetDouble(SettingsKey.first_layer_extrusion_width); + } + + bedBounds.Inflate(-totalOffset); + + _meshAllowedBounds = bedBounds; + } + [JsonIgnore] public IEnumerable DefaultLayerCascade { @@ -1028,6 +1042,22 @@ namespace MatterHackers.MatterControl.SlicerConfiguration this.ResetHotendBounds(); } + if (slicerConfigName == SettingsKey.first_layer_extrusion_width + || slicerConfigName == SettingsKey.create_raft + || slicerConfigName == SettingsKey.raft_extra_distance_around_part + || slicerConfigName == SettingsKey.create_skirt + || slicerConfigName == SettingsKey.skirt_distance + || slicerConfigName == SettingsKey.skirts + || slicerConfigName == SettingsKey.min_skirt_length + || slicerConfigName == SettingsKey.create_brim + || slicerConfigName == SettingsKey.print_center + || slicerConfigName == SettingsKey.bed_size + || slicerConfigName == SettingsKey.bed_shape) + { + // cleare this so it will be recaculated + _meshAllowedBounds = new RectangleDouble(); + } + SettingChanged?.Invoke(this, new StringEventArgs(slicerConfigName)); AnyPrinterSettingChanged?.Invoke(this, new StringEventArgs(slicerConfigName)); } diff --git a/MatterControlLib/ApplicationView/Config/PrinterConfig.cs b/MatterControlLib/ApplicationView/Config/PrinterConfig.cs index 1d08a2a07..3472dcfe3 100644 --- a/MatterControlLib/ApplicationView/Config/PrinterConfig.cs +++ b/MatterControlLib/ApplicationView/Config/PrinterConfig.cs @@ -72,13 +72,20 @@ namespace MatterHackers.MatterControl private RunningInterval checkForSceneLayer; private object locker = new object(); + private ulong undoBufferHashCode = 0; private PrinterSettingsLayer GetSceneLayer() { var scene = Bed?.Scene; if (scene != null) { - var foundPartSettings = false; + if (sceneOverrides != null + && undoBufferHashCode == scene.UndoBuffer.GetLongHashCode()) + { + return sceneOverrides; + } + + 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)) @@ -155,6 +162,7 @@ namespace MatterHackers.MatterControl } // return the current set + undoBufferHashCode = scene.UndoBuffer.GetLongHashCode(); return sceneOverrides; } diff --git a/MatterControlLib/ApplicationView/PrinterExtensionMethods.cs b/MatterControlLib/ApplicationView/PrinterExtensionMethods.cs index c171cf771..2b82b0d67 100644 --- a/MatterControlLib/ApplicationView/PrinterExtensionMethods.cs +++ b/MatterControlLib/ApplicationView/PrinterExtensionMethods.cs @@ -50,7 +50,7 @@ namespace MatterHackers.MatterControl } var worldMatrix = item.WorldMatrix(); - // probably need , true (require precision) + // probably need, true (require precision) var aabb = item.Mesh.GetAxisAlignedBoundingBox(worldMatrix); var bed = printerConfig.Bed; diff --git a/MatterControlLib/DesignTools/Operations/PartSettingsObject3D.cs b/MatterControlLib/DesignTools/Operations/PartSettingsObject3D.cs index 385f708d5..be8f1a98e 100644 --- a/MatterControlLib/DesignTools/Operations/PartSettingsObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/PartSettingsObject3D.cs @@ -170,6 +170,9 @@ namespace MatterHackers.MatterControl.DesignTools.Operations { Action = () => { + var startingOverrides = new PrinterSettingsLayer(Overrides); + var editOverrides = new PrinterSettingsLayer(Overrides); + var settingsContext = new SettingsContext(containingPrinter, null, NamedSettingsLayers.All); foreach (var setting in containingPrinter.Settings.UserLayer.ToList()) { @@ -180,21 +183,30 @@ namespace MatterHackers.MatterControl.DesignTools.Operations && SliceSettingsLayouts.ContainesKey(SliceSettingsLayouts.SliceSettings(), setting.Key) && SliceSettingsTabView.CheckIfShouldBeShown(PrinterSettings.SettingsData[setting.Key], settingsContext)) { - Overrides[setting.Key] = setting.Value; + editOverrides[setting.Key] = setting.Value; } } - foreach (var setting in Overrides.ToList()) + foreach (var setting in editOverrides.ToList()) { if (!SliceSettingsLayouts.ContainesKey(SliceSettingsLayouts.SliceSettings(), setting.Key) || !SliceSettingsTabView.CheckIfShouldBeShown(PrinterSettings.SettingsData[setting.Key], settingsContext)) { - Overrides.Remove(setting.Key); + editOverrides.Remove(setting.Key); } } - - UpdateSettingsDisplay(); + var scene = this.ContainingScene(); + scene.UndoBuffer.AddAndDo(new UndoRedoActions(() => + { + Overrides = new PrinterSettingsLayer(startingOverrides); + UpdateSettingsDisplay(); + }, + () => + { + Overrides = new PrinterSettingsLayer(editOverrides); + UpdateSettingsDisplay(); + })); }, Name = "Add User Overrides".Localize(), HelpText = "Copy in all current user overides".Localize() @@ -207,7 +219,9 @@ namespace MatterHackers.MatterControl.DesignTools.Operations Action = () => { var settings = new PrinterSettings(); - settings.GetSceneLayer = () => Overrides; + var startingOverrides = new PrinterSettingsLayer(Overrides); + var editOverrides = new PrinterSettingsLayer(Overrides); + settings.GetSceneLayer = () => editOverrides; var printer = new PrinterConfig(settings); if (containingPrinter != null) { @@ -216,9 +230,9 @@ namespace MatterHackers.MatterControl.DesignTools.Operations // set this after the PrinterConfig is constructed to change it to overrides // set this after the PrinterConfig is constructed to change it to overrides - settings.GetSceneLayer = () => Overrides; + settings.GetSceneLayer = () => editOverrides; - var presetsContext = new PresetsContext(null, Overrides) + var presetsContext = new PresetsContext(null, editOverrides) { LayerType = NamedSettingsLayers.Scene, }; @@ -227,9 +241,21 @@ namespace MatterHackers.MatterControl.DesignTools.Operations editPartSettingsPresetsPage.Closed += (s, e2) => { ApplicationController.Instance.AcitveSlicePresetsPage = null; - UpdateSettingsDisplay(); - }; + // push the new settings into this object + var scene = this.ContainingScene(); + scene.UndoBuffer.AddAndDo(new UndoRedoActions(() => + { + Overrides = new PrinterSettingsLayer(startingOverrides); + UpdateSettingsDisplay(); + }, + () => + { + Overrides = new PrinterSettingsLayer(editOverrides); + UpdateSettingsDisplay(); + })); + }; + ApplicationController.Instance.AcitveSlicePresetsPage = editPartSettingsPresetsPage; DialogWindow.Show(editPartSettingsPresetsPage); }, diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 3ed0d3e0d..09c9c93a8 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 3ed0d3e0d5fe7368273223553b87e86895efe281 +Subproject commit 09c9c93a84e57821ec65c17114acb629ac5320af