From 0416a941d73896318199f3971d3e98829f5e4429 Mon Sep 17 00:00:00 2001 From: MatterHackers Date: Sat, 11 Mar 2023 10:56:32 -0800 Subject: [PATCH] improve primary operations --- .../ApplicationView/SceneOperations.cs | 59 ------------------- .../CustomWidgets/ExportPrintItemPage.cs | 2 +- .../Operations/Image/ImageToPathObject3D_2.cs | 14 +---- .../Operations/Path/InflatePathObject3D.cs | 14 +---- .../Operations/Path/OutlinePathObject3D.cs | 4 +- .../Operations/Path/SmoothPathObject3D.cs | 12 +--- .../DesignTools/Primitives/BoxPathObject3D.cs | 2 +- .../DesignTools/Primitives/ImageObject3D.cs | 13 +++- .../DesignTools/Primitives/TextObject3D.cs | 18 +++++- .../Library/Export/GCodeExport.cs | 2 +- .../Library/Export/IExportPlugin.cs | 4 +- MatterControlLib/Library/Export/StlExport.cs | 45 ++++++++++---- .../RunningTaskStatusPanel.cs | 3 +- StaticData/Translations/Master.txt | 12 ++++ 14 files changed, 83 insertions(+), 121 deletions(-) diff --git a/MatterControlLib/ApplicationView/SceneOperations.cs b/MatterControlLib/ApplicationView/SceneOperations.cs index 859a341bb..8662604f4 100644 --- a/MatterControlLib/ApplicationView/SceneOperations.cs +++ b/MatterControlLib/ApplicationView/SceneOperations.cs @@ -68,8 +68,6 @@ namespace MatterHackers.MatterControl private static Dictionary OperationsById { get; } = new Dictionary(); - private static Dictionary> PrimaryOperations { get; } = new Dictionary>(); - public static SceneOperation AddBaseOperation() { return new SceneOperation("AddBase") @@ -264,16 +262,6 @@ namespace MatterHackers.MatterControl return null; } - public static IEnumerable GetPrimaryOperations(Type type) - { - if (PrimaryOperations.ContainsKey(type)) - { - return PrimaryOperations[type]; - } - - return null; - } - public static PopupMenu GetToolbarOverflowMenu(ThemeConfig theme, ISceneContext sceneContext, Func includeInToolbarOverflow = null) { var popupMenu = new PopupMenu(theme); @@ -712,7 +700,6 @@ namespace MatterHackers.MatterControl return true; } -#if DEBUG // path items if (includePaths && selectedItem.VisiblePaths().Count() > 1 @@ -720,7 +707,6 @@ namespace MatterHackers.MatterControl { return true; } -#endif } return false; @@ -742,9 +728,7 @@ namespace MatterHackers.MatterControl ArrangeAllPartsOperation(), new SceneSelectionSeparator(), LayFlatOperation(), -#if DEBUG RebuildOperation(), -#endif GroupOperation(), UngroupOperation(), new SceneSelectionSeparator(), @@ -886,42 +870,6 @@ namespace MatterHackers.MatterControl // register legacy types so they still show, they don't have ui to create so they don't have icons set dynamically Icons.Add(typeof(AlignObject3D), (theme) => StaticData.Instance.LoadIcon("align_left_dark.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply()); - // image operations - PrimaryOperations.Add(typeof(ImageObject3D), new List { SceneOperations.ById("ImageConverter"), SceneOperations.ById("ImageToPath"), }); - - // path operations - PrimaryOperations.Add(typeof(ImageToPathObject3D_2), new List - { - SceneOperations.ById("LinearExtrude"), SceneOperations.ById("Revolve"), SceneOperations.ById("SmoothPath") - }); - PrimaryOperations.Add(typeof(SmoothPathObject3D), new List - { - SceneOperations.ById("LinearExtrude"), SceneOperations.ById("Revolve"), SceneOperations.ById("InflatePath"), SceneOperations.ById("OutlinePath") - }); - PrimaryOperations.Add(typeof(TextObject3D), new List - { - SceneOperations.ById("LinearExtrude"), SceneOperations.ById("Revolve"), SceneOperations.ById("InflatePath"), SceneOperations.ById("OutlinePath") - }); - PrimaryOperations.Add(typeof(BoxPathObject3D), new List - { - SceneOperations.ById("LinearExtrude"), SceneOperations.ById("Revolve"), SceneOperations.ById("InflatePath"), SceneOperations.ById("OutlinePath") - }); - PrimaryOperations.Add(typeof(InflatePathObject3D), new List - { - SceneOperations.ById("LinearExtrude"), SceneOperations.ById("Revolve"), SceneOperations.ById("OutlinePath") - }); - PrimaryOperations.Add(typeof(OutlinePathObject3D), new List - { - SceneOperations.ById("LinearExtrude"), SceneOperations.ById("Revolve"), SceneOperations.ById("InflatePath") - }); - PrimaryOperations.Add(typeof(LinearExtrudeObject3D), new List - { - SceneOperations.ById("AddBase") - }); - - // default operations - PrimaryOperations.Add(typeof(Object3D), new List { SceneOperations.ById("Scale") }); - Icons.Add(typeof(ImageObject3D), (theme) => StaticData.Instance.LoadIcon("image_converter.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply()); } @@ -933,13 +881,11 @@ namespace MatterHackers.MatterControl TitleGetter = () => "Combine".Localize(), Action = (sceneContext) => { -#if DEBUG if (sceneContext.Scene.SelectedItem.VisiblePaths().Count() > 1) { new MergePathObject3D("Combine".Localize(), ClipperLib.ClipType.ctUnion).WrapSelectedItemAndSelect(sceneContext.Scene); } else -#endif { new CombineObject3D_2().WrapSelectedItemAndSelect(sceneContext.Scene); } @@ -1102,13 +1048,11 @@ namespace MatterHackers.MatterControl TitleGetter = () => "Intersect".Localize(), Action = (sceneContext) => { -#if DEBUG if (sceneContext.Scene.SelectedItem.VisiblePaths().Count() > 1) { new MergePathObject3D("Intersect".Localize(), ClipperLib.ClipType.ctIntersection).WrapSelectedItemAndSelect(sceneContext.Scene); } else -#endif { new IntersectionObject3D_2().WrapSelectedItemAndSelect(sceneContext.Scene); } @@ -1382,13 +1326,11 @@ namespace MatterHackers.MatterControl TitleGetter = () => "Subtract".Localize(), Action = (sceneContext) => { -#if DEBUG if (sceneContext.Scene.SelectedItem.VisiblePaths().Count() > 1) { new SubtractPathObject3D().WrapSelectedItemAndSelect(sceneContext.Scene); } else -#endif { var subtractItem = new SubtractObject3D_2(); subtractItem.WrapSelectedItemAndSelect(sceneContext.Scene); @@ -1539,5 +1481,4 @@ namespace MatterHackers.MatterControl { IEnumerable GetOperations(); } - } \ No newline at end of file diff --git a/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs b/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs index 0d63fc141..77f7ae394 100644 --- a/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs +++ b/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs @@ -156,7 +156,7 @@ namespace MatterHackers.MatterControl if (plugin is IExportWithOptions pluginWithOptions) { - var optionPanel = pluginWithOptions.GetOptionsPanel(libraryItems); + var optionPanel = pluginWithOptions.GetOptionsPanel(libraryItems, pluginButton); if (optionPanel != null) { optionPanel.HAnchor = HAnchor.Stretch; diff --git a/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D_2.cs b/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D_2.cs index 90ff4511c..3d90db928 100644 --- a/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D_2.cs +++ b/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D_2.cs @@ -52,8 +52,8 @@ using Polygons = System.Collections.Generic.List true; [HideFromEditor] diff --git a/MatterControlLib/DesignTools/Operations/Path/InflatePathObject3D.cs b/MatterControlLib/DesignTools/Operations/Path/InflatePathObject3D.cs index 0714c2761..05a2d50fa 100644 --- a/MatterControlLib/DesignTools/Operations/Path/InflatePathObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/Path/InflatePathObject3D.cs @@ -50,8 +50,8 @@ namespace MatterHackers.MatterControl.DesignTools.Operations Sharp, } - public class InflatePathObject3D : Object3D, IEditorDraw, IObject3DControlsProvider - { + public class InflatePathObject3D : PathObject3D, IEditorDraw, IObject3DControlsProvider + { public InflatePathObject3D() { Name = "Inflate Path".Localize(); @@ -135,15 +135,5 @@ namespace MatterHackers.MatterControl.DesignTools.Operations return joinType; } - - public void DrawEditor(Object3DControlsLayer layer, DrawEventArgs e) - { - this.DrawPath(); - } - - public AxisAlignedBoundingBox GetEditorWorldspaceAABB(Object3DControlsLayer layer) - { - return this.GetWorldspaceAabbOfDrawPath(); - } } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/Operations/Path/OutlinePathObject3D.cs b/MatterControlLib/DesignTools/Operations/Path/OutlinePathObject3D.cs index 61344a27b..c69d868a0 100644 --- a/MatterControlLib/DesignTools/Operations/Path/OutlinePathObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/Path/OutlinePathObject3D.cs @@ -45,8 +45,8 @@ using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.DesignTools.Operations { - public class OutlinePathObject3D : Object3D, IEditorDraw, IObject3DControlsProvider - { + public class OutlinePathObject3D : PathObject3D, IEditorDraw, IObject3DControlsProvider + { public OutlinePathObject3D() { Name = "Outline Path".Localize(); diff --git a/MatterControlLib/DesignTools/Operations/Path/SmoothPathObject3D.cs b/MatterControlLib/DesignTools/Operations/Path/SmoothPathObject3D.cs index 7f496d5e6..37cf8e9c4 100644 --- a/MatterControlLib/DesignTools/Operations/Path/SmoothPathObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/Path/SmoothPathObject3D.cs @@ -44,7 +44,7 @@ using Polygons = System.Collections.Generic.List GetOperations() + { + yield return SceneOperations.ById("ImageConverter"); + yield return SceneOperations.ById("ImageToPath"); + } + } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/Primitives/TextObject3D.cs b/MatterControlLib/DesignTools/Primitives/TextObject3D.cs index 96e615c73..366786c29 100644 --- a/MatterControlLib/DesignTools/Primitives/TextObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/TextObject3D.cs @@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project. */ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; @@ -60,8 +61,8 @@ namespace MatterHackers.MatterControl.DesignTools } [HideChildrenFromTreeView] - public class TextObject3D : Object3D, IPropertyGridModifier, IEditorDraw - { + public class TextObject3D : Object3D, IPropertyGridModifier, IEditorDraw, IPrimaryOperationsSpecifier + { private bool refreshToolBar; [JsonConverter(typeof(StringEnumConverter))] @@ -367,5 +368,16 @@ namespace MatterHackers.MatterControl.DesignTools { return this.GetWorldspaceAabbOfDrawPath(); } - } + + public IEnumerable GetOperations() + { + if (Output == OutputDimensions.Output2D) + { + return PathObject3D.GetOperations(this.GetType()); + } + + // return no enumerations + return Enumerable.Empty(); + } + } } \ No newline at end of file diff --git a/MatterControlLib/Library/Export/GCodeExport.cs b/MatterControlLib/Library/Export/GCodeExport.cs index ca6fad08c..f10e08fed 100644 --- a/MatterControlLib/Library/Export/GCodeExport.cs +++ b/MatterControlLib/Library/Export/GCodeExport.cs @@ -110,7 +110,7 @@ namespace MatterHackers.MatterControl.Library.Export public virtual bool ExportPossible(ILibraryAsset libraryItem) => true; - public GuiWidget GetOptionsPanel(IEnumerable libraryItems) + public GuiWidget GetOptionsPanel(IEnumerable libraryItems, RadioButton radioButton) { var container = new FlowLayoutWidget() { diff --git a/MatterControlLib/Library/Export/IExportPlugin.cs b/MatterControlLib/Library/Export/IExportPlugin.cs index 01511de63..aca362876 100644 --- a/MatterControlLib/Library/Export/IExportPlugin.cs +++ b/MatterControlLib/Library/Export/IExportPlugin.cs @@ -62,6 +62,6 @@ namespace MatterHackers.MatterControl public interface IExportWithOptions : IExportPlugin { - GuiWidget GetOptionsPanel(IEnumerable libraryItems); - } + GuiWidget GetOptionsPanel(IEnumerable libraryItems, RadioButton radioButton); + } } diff --git a/MatterControlLib/Library/Export/StlExport.cs b/MatterControlLib/Library/Export/StlExport.cs index fafa66d0d..b38678700 100644 --- a/MatterControlLib/Library/Export/StlExport.cs +++ b/MatterControlLib/Library/Export/StlExport.cs @@ -46,7 +46,9 @@ namespace MatterHackers.MatterControl.Library.Export { private bool mergeMeshes = true; - public int Priority => 2; + private bool saveMultipleStls = false; + + public int Priority => 2; public string ButtonText => "STL File".Localize(); @@ -82,8 +84,8 @@ namespace MatterHackers.MatterControl.Library.Export first = false; } - if (!await MeshExport.ExportMesh(item, filename, mergeMeshes, progress)) - { + if (!await MeshExport.ExportMesh(item, filename, mergeMeshes, progress, saveMultipleStls)) + { badExports.Add(item.Name); } } @@ -103,8 +105,8 @@ namespace MatterHackers.MatterControl.Library.Export }; } - public GuiWidget GetOptionsPanel(IEnumerable libraryItems) - { + public GuiWidget GetOptionsPanel(IEnumerable libraryItems, RadioButton radioButton) + { var exportMeshCount = 0; foreach (var item in libraryItems.OfType()) { @@ -119,19 +121,21 @@ namespace MatterHackers.MatterControl.Library.Export { return null; } - - var container = new FlowLayoutWidget() - { + + var container = new FlowLayoutWidget(FlowDirection.TopToBottom) + { Margin = new BorderDouble(left: 40, bottom: 10), }; var theme = AppContext.Theme; - var unionAllPartsCheckbox = new CheckBox("Merge faces into single mesh".Localize(), theme.TextColor, 10) - { + // add union checkbox + var unionAllPartsCheckbox = new CheckBox("Performe Union".Localize(), theme.TextColor, 10) + { Checked = true, Cursor = Cursors.Hand, - ToolTipText = "Disable to expart all faces without merging".Localize() + ToolTipText = "Performe a union before exporting. Might be slower but can clean up some models.".Localize(), + Margin = new BorderDouble(0, 3) }; unionAllPartsCheckbox.CheckedStateChanged += (s, e) => { @@ -139,7 +143,22 @@ namespace MatterHackers.MatterControl.Library.Export }; container.AddChild(unionAllPartsCheckbox); - return container; - } + // add separate checkbox + var saveAsSeparateSTLsCheckbox = new CheckBox("Save Each Separately".Localize(), theme.TextColor, 10) + { + Checked = false, + Cursor = Cursors.Hand, + ToolTipText = "Save every object as a separate STL using its name. The save filename will be used if no name can be found.".Localize(), + Margin = new BorderDouble(0, 3) + }; + saveAsSeparateSTLsCheckbox.CheckedStateChanged += (s, e) => + { + radioButton.InvokeClick(); + saveMultipleStls = saveAsSeparateSTLsCheckbox.Checked; + }; + container.AddChild(saveAsSeparateSTLsCheckbox); + + return container; + } } } diff --git a/MatterControlLib/PartPreviewWindow/RunningTaskStatusPanel.cs b/MatterControlLib/PartPreviewWindow/RunningTaskStatusPanel.cs index 992ad191a..0751ba3df 100644 --- a/MatterControlLib/PartPreviewWindow/RunningTaskStatusPanel.cs +++ b/MatterControlLib/PartPreviewWindow/RunningTaskStatusPanel.cs @@ -90,7 +90,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private void TaskDetails_ProgressChanged(object sender, (double progress0To1, string status) e) { - if (e.status.StartsWith("[[send to terminal]]")) + if (e.status != null + && e.status.StartsWith("[[send to terminal]]")) { // strip of the prefix e.status = e.status.Substring("[[send to terminal]]".Length); diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 6f4f7acb7..3034ef94f 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -3514,6 +3514,12 @@ Translated:PEI Bed Temperature English:Percentage of Translated:Percentage of +English:Performe a union before exporting. Might be slower but can clean up some models. +Translated:Performe a union before exporting. Might be slower but can clean up some models. + +English:Performe Union +Translated:Performe Union + English:Perimeter Acceleration Translated:Perimeter Acceleration @@ -4363,6 +4369,12 @@ Translated:Save changes ? English:Save Changes? Translated:Save Changes? +English:Save Each Separately +Translated:Save Each Separately + +English:Save every object as a separate STL using its name. The save filename will be used if no name can be found. +Translated:Save every object as a separate STL using its name. The save filename will be used if no name can be found. + English:Save file: Translated:Save file: