diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 71e6ff818..fcff0eea4 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -47,6 +47,7 @@ using System.Threading.Tasks; using global::MatterControl.Printing; using Markdig.Agg; using Markdig.Syntax.Inlines; +using MatterControlLib.Library.OpenInto; using MatterHackers.Agg; using MatterHackers.Agg.Font; using MatterHackers.Agg.Image; @@ -328,7 +329,14 @@ namespace MatterHackers.MatterControl popupMenu.CreateSubMenu("Modify".Localize(), menuTheme, (modifyMenu) => SceneOperations.AddModifyItems(modifyMenu, menuTheme, sceneContext)); - } + + if (OpenIntoExecutable.FoundInstalledExecutable) + { + popupMenu.CreateSubMenu("Open With".Localize(), + menuTheme, + (modifyMenu) => OpenIntoExecutable.AddOption(modifyMenu, menuTheme, sceneContext)); + } + } else { // Create items directly in the referenced menu diff --git a/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs b/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs index 9bb4b2f44..8611586aa 100644 --- a/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs +++ b/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using MatterControlLib.Library.OpenInto; using MatterHackers.Agg; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; @@ -42,7 +43,7 @@ using MatterHackers.MatterControl.PartPreviewWindow; namespace MatterHackers.MatterControl { - public class ExportPrintItemPage : DialogPage + public class ExportPrintItemPage : DialogPage { private CheckBox showInFolderAfterSave; @@ -245,7 +246,7 @@ namespace MatterHackers.MatterControl return; } - if (exportPlugin is ExportStlToExecutable) + if (exportPlugin is OpenIntoExecutable) { ApplicationController.Instance.Tasks.Execute( "Saving".Localize() + "...", diff --git a/MatterControlLib/Library/Export/ExportStlToExecutable.cs b/MatterControlLib/Library/OpenInto/ExportStlToExecutable.cs similarity index 64% rename from MatterControlLib/Library/Export/ExportStlToExecutable.cs rename to MatterControlLib/Library/OpenInto/ExportStlToExecutable.cs index c333ff42b..16d732e2c 100644 --- a/MatterControlLib/Library/Export/ExportStlToExecutable.cs +++ b/MatterControlLib/Library/OpenInto/ExportStlToExecutable.cs @@ -27,10 +27,15 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ -using MatterHackers.Agg.Image; +using Lucene.Net.Support; using MatterHackers.Agg.Platform; +using MatterHackers.Agg.UI; +using MatterHackers.DataConverters3D; using MatterHackers.Localizations; +using MatterHackers.MatterControl; using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.Library; +using MatterHackers.MatterControl.Library.Export; using Microsoft.Win32; using System; using System.Collections.Generic; @@ -40,27 +45,9 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -namespace MatterHackers.MatterControl.Library.Export +namespace MatterControlLib.Library.OpenInto { - public class ExportToBambuStudio : ExportStlToExecutable, IExportPlugin - { - public ExportToBambuStudio() - { - - } - - protected override string regExKeyName => @" Bambu.Studio.1\Shell\Open\Command"; - - public override string ButtonText => "Bambu Studio".Localize(); - - public override string DisabledReason => "Bambu Studio not installed"; - - public void Initialize(PrinterConfig printer) - { - } - } - - public abstract class ExportStlToExecutable + public abstract class OpenIntoExecutable { private string pathToExe; @@ -70,11 +57,63 @@ namespace MatterHackers.MatterControl.Library.Export abstract public string ButtonText { get; } - public string FileExtension => ".stl"; + abstract public string Icon { get; } - public string ExtensionFilter => "Save as STL|*.stl"; + public static IEnumerable GetAvailableOpenWith() + { + yield return new OpenIntoBambuStudio(); + } - public ImageBuffer Icon { get; } = StaticData.Instance.LoadIcon(Path.Combine("filetypes", "stl.png")); + public static bool FoundInstalledExecutable + { + get + { + foreach (var openWith in GetAvailableOpenWith()) + { + if (openWith.Enabled) + { + return true; + } + } + + return false; + } + } + + public static void AddOption(PopupMenu popupMenu, ThemeConfig theme, ISceneContext sceneContext) + { + foreach (var openWith in GetAvailableOpenWith()) + { + if (!openWith.Enabled) + { + continue; + } + + var menuItem = popupMenu.CreateMenuItem(openWith.ButtonText, StaticData.Instance.LoadIcon(openWith.Icon, 16, 16)); + var selectedItem = sceneContext.Scene.SelectedItem; + if (selectedItem == null) + { + selectedItem = sceneContext.Scene; + } + + menuItem.Click += (s, e) => + { + if (selectedItem == null + || !selectedItem.VisibleMeshes().Any()) + { + return; + } + + ApplicationController.Instance.Tasks.Execute( + "Twist".Localize(), + null, + async (reporter, cancellationToken) => + { + await openWith.Generate(new[] { new InMemoryLibraryItem(selectedItem) }, reporter); + }); + }; + } + } public bool Enabled { @@ -86,7 +125,7 @@ namespace MatterHackers.MatterControl.Library.Export if (key != null) { pathToExe = key.GetValue("").ToString(); - + var regex = "C:.+.exe"; var match = System.Text.RegularExpressions.Regex.Match(pathToExe, regex); pathToExe = match.Value; @@ -99,14 +138,7 @@ namespace MatterHackers.MatterControl.Library.Export } } - public abstract string DisabledReason { get; } - - public bool ExportPossible(ILibraryAsset libraryItem) => true; - - public async Task> Generate(IEnumerable libraryItems, - string noPath, - Action progress, - CancellationToken cancellationToken) + public async Task> Generate(IEnumerable libraryItems, Action progress) { string exportTempFileFolder = Path.Combine(ApplicationDataStorage.Instance.ApplicationTempDataPath, "ExportToExe"); Directory.CreateDirectory(exportTempFileFolder); @@ -138,7 +170,7 @@ namespace MatterHackers.MatterControl.Library.Export new ValidationError(ValidationErrors.ItemToSTLExportInvalid) { Error = "One or more items cannot be exported as STL".Localize(), - Details = String.Join("\n", bedExports.ToArray()) + Details = string.Join("\n", bedExports.ToArray()) } }; } diff --git a/MatterControlLib/Library/OpenInto/OpenWithBambuStudio.cs b/MatterControlLib/Library/OpenInto/OpenWithBambuStudio.cs new file mode 100644 index 000000000..f7165e2d3 --- /dev/null +++ b/MatterControlLib/Library/OpenInto/OpenWithBambuStudio.cs @@ -0,0 +1,48 @@ +/* +Copyright (c) 2017, Lars Brubaker, John Lewin +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +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.Localizations; +using MatterHackers.MatterControl; + +namespace MatterControlLib.Library.OpenInto +{ + public class OpenIntoBambuStudio : OpenIntoExecutable + { + public OpenIntoBambuStudio() + { + + } + + protected override string regExKeyName => @" Bambu.Studio.1\Shell\Open\Command"; + + public override string ButtonText => "Bambu Studio".Localize(); + + public override string Icon => "bambu icon.png"; + } +} \ No newline at end of file diff --git a/StaticData/Icons/bambu icon.png b/StaticData/Icons/bambu icon.png new file mode 100644 index 000000000..9c34c3b90 Binary files /dev/null and b/StaticData/Icons/bambu icon.png differ diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 21c8e89a5..a552b7be6 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -3376,6 +3376,9 @@ Translated:Open Recent English:Open Settings View Options Translated:Open Settings View Options +English:Open With +Translated:Open With + English:OpenSCAD not installed Translated:OpenSCAD not installed