Improved bambu studio open with
This commit is contained in:
parent
57ac7d9415
commit
1f3e3981f9
6 changed files with 129 additions and 37 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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() + "...",
|
||||
|
|
|
|||
|
|
@ -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<OpenIntoExecutable> 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<List<ValidationError>> Generate(IEnumerable<ILibraryItem> libraryItems,
|
||||
string noPath,
|
||||
Action<double, string> progress,
|
||||
CancellationToken cancellationToken)
|
||||
public async Task<List<ValidationError>> Generate(IEnumerable<ILibraryItem> libraryItems, Action<double, string> 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())
|
||||
}
|
||||
};
|
||||
}
|
||||
48
MatterControlLib/Library/OpenInto/OpenWithBambuStudio.cs
Normal file
48
MatterControlLib/Library/OpenInto/OpenWithBambuStudio.cs
Normal file
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
BIN
StaticData/Icons/bambu icon.png
Normal file
BIN
StaticData/Icons/bambu icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue