From 1f3e3981f9703e35be553fd3f9782d5763f465df Mon Sep 17 00:00:00 2001 From: MatterHackers Date: Sat, 11 Mar 2023 12:56:04 -0800 Subject: [PATCH] Improved bambu studio open with --- .../ApplicationView/ApplicationController.cs | 10 +- .../CustomWidgets/ExportPrintItemPage.cs | 5 +- .../ExportStlToExecutable.cs | 100 ++++++++++++------ .../Library/OpenInto/OpenWithBambuStudio.cs | 48 +++++++++ StaticData/Icons/bambu icon.png | Bin 0 -> 1877 bytes StaticData/Translations/Master.txt | 3 + 6 files changed, 129 insertions(+), 37 deletions(-) rename MatterControlLib/Library/{Export => OpenInto}/ExportStlToExecutable.cs (64%) create mode 100644 MatterControlLib/Library/OpenInto/OpenWithBambuStudio.cs create mode 100644 StaticData/Icons/bambu icon.png 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 0000000000000000000000000000000000000000..9c34c3b90fd510f47476c658f9a5b8f300388a5c GIT binary patch literal 1877 zcmeAS@N?(olHy`uVBq!ia0y~yU|7Y#z_5~oiGhK^q`|P7fq{XsILO_JVcj{ImkbOH zEa{HEjtmSN`?>!lvNA9*a29w(7BevL9R^{>5@=M}EIanDO*v@#mIEGZjy}eVPaivt|c;UeX4hIh%;&|EL@sI1j(Ek-31xc1V z#cdO>%J2Ml!R4Tiiu0N!7kGje3Ta0KsU=RIE&b2q`Jau;E?I5KEz9wp>sP#UZS3sZ zdAm28-)YbPz32Pmec$iCEnPnUdh>Vtd++S-SHJhHyq(*(+mkQ3Zn@$9%QNn0o_TNb ztX%4|b??u)$Nu=?5I!CCuW;ean{%(Pwm0-oW!M>bm)HK;N(Y1etv?;Focobjckqwc zGxk91$L&8^KS$4ycX`_*|4jT$eqx=#R^z%E@q<+1e8tc6v({>_h_beuvix0-%;yk= z8TB03t8SUOl-boh5dA7}W`;WB!9U8DmxSU?N#pn&zJq_Jz53>1axL}W1OM>&@{6s1{X^CSJZG0H)?@h`{p48Z z(VwkXXFpkASv)!a`6BWAHot#9+57oQ>m}J@8IS_E_k5p%;^RJ?K3(_Ou)gZ?#@Okn z(q-#UTdUtSWOp>!pPKOR$qDhl`g7yzcRV#O=D&ZgJT5l)^VKPrm`W2)8TPj))SZ6t z=bp`$`it)MHRWrUpS^Q+eudJ${m^#%a_xrPK=GcxKvvA*~EQsf4{!cH2L*AjmfxqItN;By z_v`;SGxnclOH}`SdddI(*5@tdQ+_hAe2!*%{{7j?WbOUAzjp54e|^pi|LFV@@5B8k z%cq|46*!YGS^MwFo#0P*K7F`m{NH3oaV__Ux63Xj)Oj!aRBgPt=H<6zmrC|eWiL~?%Q)~`t?80R^5CY_U~l%^R+ggBXf^eepX>S_~g6WzIXQpZq9sXKFRpR)IY}k z>+akv*`a>*dh&xmCne=ifzsKN|Gmd<<<6`3$~p$5qcqUyx`}C4dP@Y>n=fL~JT4(qd zmGRjejI&V}>h#!h@=qcIC>JibUi?#XO?meIefx77rmHuD&jk-bd$9?j8 z;b-hV{`XHX+P@?9lfTBi&$re~Yp=gPHv&_XYmzmSAlA={oH* z|Mxncgc