diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index af2df4f5a..d7f00bbe3 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -129,6 +129,8 @@ namespace MatterHackers.MatterControl public event EventHandler AnyPrintComplete; + public static string[] ShellFileExtensions => new string[] { ".stl", ".amf", ".3mf", ".obj", ".mcx", ".png", ".jpg", ".jpeg" }; + public bool IsMatterControlPro() { var result = ApplicationController.Instance.UserHasPro?.Invoke(); diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixCornerControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixCornerControl.cs index 0693bf261..83cc85855 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixCornerControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixCornerControl.cs @@ -469,6 +469,10 @@ namespace MatterHackers.Plugins.EditorTools newSize.Z = newSize.Z <= minimumSize ? minimumSize : newSize.Z; scaleAmount.Z = newSize.Z / originalSelectedBounds.ZSize; } + + var maxXY = Math.Max(scaleAmount.X, scaleAmount.Y); + scaleAmount.X = maxXY; + scaleAmount.Y = maxXY; } return scaleAmount; diff --git a/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs b/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs index f11fe3344..5b02e262c 100644 --- a/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs +++ b/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs @@ -84,40 +84,29 @@ namespace MatterHackers.MatterControl.DesignTools return item; } + private static object loadLock = new object(); + private static IObject3D sheetObject; + public override Mesh Mesh { get { - if (this.Children.Count == 0 - || this.Children.Where(i => i.Mesh == null).Any()) + if (this.Children.Count == 0) { - this.Children.Modify((list) => + lock (loadLock) { - list.Clear(); - Mesh border; - using (Stream stlStream = StaticData.Instance.OpenStream(Path.Combine("Stls", "sheet_border.stl"))) + if (sheetObject == null) { - border = StlProcessing.Load(stlStream, CancellationToken.None); + sheetObject = MeshContentProvider.LoadMCX(StaticData.Instance.OpenStream(Path.Combine("Stls", "sheet_icon.mcx"))); } - list.Add(new Object3D() - { - Mesh = border, - Color = new Color("#9D9D9D") - }); - Mesh boxes; - using (Stream stlStream = StaticData.Instance.OpenStream(Path.Combine("Stls", "sheet_boxes.stl"))) - { - boxes = StlProcessing.Load(stlStream, CancellationToken.None); - } - list.Add(new Object3D() - { - Mesh = boxes, - Color = new Color("#117c43") - }); - var aabb = border.GetAxisAlignedBoundingBox(); - this.Matrix *= Matrix4X4.CreateScale(20 / aabb.XSize); - }); + this.Children.Modify((list) => + { + list.Clear(); + + list.Add(sheetObject.Clone()); + }); + } } return null; diff --git a/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs b/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs index 3b9eefb40..97bfef931 100644 --- a/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs +++ b/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs @@ -58,6 +58,23 @@ namespace MatterHackers.MatterControl private ImageBuffer defaultIcon = new ImageBuffer(); + public static IObject3D LoadMCX(string filename, Action progressReporter = null) + { + if (File.Exists(filename) + && Path.GetExtension(filename).ToLower() == ".mcx") + { + var stream = File.OpenRead(filename); + return LoadMCX(stream, progressReporter); + } + + return null; + } + + public static IObject3D LoadMCX(Stream stream, Action progressReporter = null) + { + return Object3D.Load(stream, ".mcx", CancellationToken.None, null /*itemCache*/, progressReporter); + } + public Task CreateItem(ILibraryItem item, Action progressReporter) { return Task.Run(async () => diff --git a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs index de7b4385c..fd64e1840 100644 --- a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs +++ b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs @@ -466,6 +466,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } #endif + public void OpenDropFile(string filePath) + { + Instance_OpenNewFile(this, filePath); + } + private async void Instance_OpenNewFile(object sender, string filePath) { if (File.Exists(filePath)) diff --git a/MatterControlLib/PartPreviewWindow/Tabs.cs b/MatterControlLib/PartPreviewWindow/Tabs.cs index 863d38faa..504d1ff16 100644 --- a/MatterControlLib/PartPreviewWindow/Tabs.cs +++ b/MatterControlLib/PartPreviewWindow/Tabs.cs @@ -29,6 +29,7 @@ either expressed or implied, of the FreeBSD Project. using System; using System.Collections.Generic; +using System.IO; using System.Linq; using MatterHackers.Agg; using MatterHackers.Agg.Image; @@ -262,6 +263,37 @@ namespace MatterHackers.MatterControl.PartPreviewWindow }; this.TabBar.ActionArea.AddChild(leadingTabAdornment); + this.TabBar.MouseMove += (s, e) => + { + if (e?.DragFiles?.Count > 0 + && e.DragFiles.Where(f => ApplicationController.ShellFileExtensions.Contains(Path.GetExtension(f).ToLower())).Any()) + { + e.AcceptDrop = true; + } + }; + + TabBar.MouseEnterBounds += (s, e) => + { + ApplicationController.Instance.UiHint = "You can drag and drop .mcx files here to open them"; + }; + + TabBar.MouseLeaveBounds += (s, e) => + { + ApplicationController.Instance.UiHint = ""; + }; + + this.TabBar.MouseUp += (s, e) => + { + if (e?.DragFiles?.Count > 0 + && e.DragFiles.Where(f => ApplicationController.ShellFileExtensions.Contains(Path.GetExtension(f).ToLower())).Any()) + { + foreach (var file in e.DragFiles) + { + ApplicationController.Instance.MainView.OpenDropFile(file); + } + } + }; + tabTrailer = new TabTrailer(this, theme) { VAnchor = VAnchor.Bottom, diff --git a/Program.cs b/Program.cs index 1928c5cf8..79f7ae881 100644 --- a/Program.cs +++ b/Program.cs @@ -178,7 +178,7 @@ namespace MatterHackers.MatterControl var proxy = new ServiceProxy(); // and at least one argument is an acceptable shell file extension - var itemsToAdd = args.Where(f => File.Exists(f) && shellFileExtensions.Contains(Path.GetExtension(f).ToLower())); + var itemsToAdd = args.Where(f => File.Exists(f) && ApplicationController.ShellFileExtensions.Contains(Path.GetExtension(f).ToLower())); if (itemsToAdd.Any()) { // notify the running instance of the event @@ -202,7 +202,7 @@ namespace MatterHackers.MatterControl #endif // If MatterControl isn't running and valid files were shelled, schedule a StartupAction to open the files after load - var shellFiles = args.Where(f => File.Exists(f) && shellFileExtensions.Contains(Path.GetExtension(f).ToLower())); + var shellFiles = args.Where(f => File.Exists(f) && ApplicationController.ShellFileExtensions.Contains(Path.GetExtension(f).ToLower())); if (shellFiles.Any()) { ApplicationController.StartupActions.Add(new ApplicationController.StartupAction() @@ -318,8 +318,6 @@ namespace MatterHackers.MatterControl rootSystemWindow.ShowAsSystemWindow(); } - private static string[] shellFileExtensions = new string[] { ".stl", ".amf", ".3mf", ".obj", ".mcx", ".png", ".jpg", ".jpeg" }; - private static readonly object locker = new object(); static void KeepAwake(bool keepAwake) @@ -341,7 +339,7 @@ namespace MatterHackers.MatterControl { // If at least one argument is an acceptable shell file extension var itemsToAdd = files.Where(f => File.Exists(f) - && shellFileExtensions.Contains(Path.GetExtension(f).ToLower())); + && ApplicationController.ShellFileExtensions.Contains(Path.GetExtension(f).ToLower())); if (itemsToAdd.Any()) { diff --git a/StaticData/Stls/sheet_border.stl b/StaticData/Stls/sheet_border.stl deleted file mode 100644 index 89bc848b1..000000000 Binary files a/StaticData/Stls/sheet_border.stl and /dev/null differ diff --git a/StaticData/Stls/sheet_boxes.stl b/StaticData/Stls/sheet_boxes.stl deleted file mode 100644 index 41c91b136..000000000 Binary files a/StaticData/Stls/sheet_boxes.stl and /dev/null differ diff --git a/StaticData/Stls/sheet_icon.mcx b/StaticData/Stls/sheet_icon.mcx new file mode 100644 index 000000000..e22b3ead0 Binary files /dev/null and b/StaticData/Stls/sheet_icon.mcx differ