From 0cd2ffd093468592ce1c9ca5cd6f5b08d2f231d6 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 28 Jul 2017 17:35:04 -0700 Subject: [PATCH] Restore the previous bedplate on load --- ApplicationView/ApplicationController.cs | 9 +++++---- ApplicationView/WidescreenPanel.cs | 11 ++++++++++- DataStorage/Datastore.cs | 11 +++++++++++ PartPreviewWindow/PlusTabPage.cs | 3 --- PartPreviewWindow/View3D/MeshViewerWidget.cs | 9 +++++++++ PartPreviewWindow/View3D/View3DWidget.cs | 8 ++++++++ 6 files changed, 43 insertions(+), 8 deletions(-) diff --git a/ApplicationView/ApplicationController.cs b/ApplicationView/ApplicationController.cs index 4845049ed..2c59f5cc7 100644 --- a/ApplicationView/ApplicationController.cs +++ b/ApplicationView/ApplicationController.cs @@ -278,14 +278,15 @@ namespace MatterHackers.MatterControl { string now = DateTime.Now.ToString("yyyyMMdd-HHmmss"); - string platingDirectory = Path.Combine(ApplicationDataStorage.Instance.ApplicationTempDataPath, "Plating"); - Directory.CreateDirectory(platingDirectory); - - string mcxPath = Path.Combine(platingDirectory, now + ".mcx"); + string mcxPath = Path.Combine(ApplicationDataStorage.Instance.PlatingDirectory, now + ".mcx"); ApplicationController.Instance.ActivePrintItem = new PrintItemWrapper(new PrintItem(now, mcxPath)); File.WriteAllText(mcxPath, new Object3D().ToJson()); + + ApplicationController.Instance.ActiveView3DWidget?.Scene.Load(mcxPath); + ApplicationController.Instance.ActiveView3DWidget?.PartHasBeenChanged(); + } public ThemeConfig Theme { get; set; } = new ThemeConfig(); diff --git a/ApplicationView/WidescreenPanel.cs b/ApplicationView/WidescreenPanel.cs index cff79e1cf..5a93789d8 100644 --- a/ApplicationView/WidescreenPanel.cs +++ b/ApplicationView/WidescreenPanel.cs @@ -27,10 +27,14 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ +using System.IO; +using System.Linq; using MatterHackers.Agg; using MatterHackers.Agg.UI; +using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MatterControl.PrintLibrary; +using MatterHackers.MatterControl.PrintQueue; namespace MatterHackers.MatterControl { @@ -50,7 +54,12 @@ namespace MatterHackers.MatterControl // HACK: Long term we need a better solution which does not rely on ActivePrintItem/PrintItemWrapper if (ApplicationController.Instance.ActivePrintItem == null) { - ApplicationController.Instance.ClearPlate(); + // Find the last used bed plate mcx + var directoryInfo = new DirectoryInfo(ApplicationDataStorage.Instance.PlatingDirectory); + var firstFile = directoryInfo.GetFileSystemInfos("*.mcx").OrderByDescending(fl => fl.CreationTime).FirstOrDefault(); + + // Set as the current item - should be restored as the Active scene in the MeshViewer + ApplicationController.Instance.ActivePrintItem = new PrintItemWrapper(new PrintItem(firstFile.Name, firstFile.FullName)); } var library3DViewSplitter = new Splitter() diff --git a/DataStorage/Datastore.cs b/DataStorage/Datastore.cs index 8aded8661..3af75cdc1 100644 --- a/DataStorage/Datastore.cs +++ b/DataStorage/Datastore.cs @@ -159,6 +159,17 @@ namespace MatterHackers.MatterControl.DataStorage } } + public string PlatingDirectory + { + get + { + string platingDirectory = Path.Combine(ApplicationTempDataPath, "Plating"); + Directory.CreateDirectory(platingDirectory); + + return platingDirectory; + } + } + public string DownloadsDirectory { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads"); public string CustomLibraryFoldersPath { get; } = Path.Combine(applicationUserDataPath, "LibraryFolders.conf"); diff --git a/PartPreviewWindow/PlusTabPage.cs b/PartPreviewWindow/PlusTabPage.cs index f46a7b53f..f68e4ed24 100644 --- a/PartPreviewWindow/PlusTabPage.cs +++ b/PartPreviewWindow/PlusTabPage.cs @@ -31,7 +31,6 @@ using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.Localizations; using MatterHackers.MatterControl.ActionBar; -using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.PrinterCommunication; namespace MatterHackers.MatterControl.PartPreviewWindow @@ -93,9 +92,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { UiThread.RunOnIdle(() => { - //WizardPage.WizardWindow.ChangeToSetupPrinterForm(true); WizardWindow.ShowPrinterSetup(true); - }); } }; diff --git a/PartPreviewWindow/View3D/MeshViewerWidget.cs b/PartPreviewWindow/View3D/MeshViewerWidget.cs index d4cc189f4..7ec01460e 100644 --- a/PartPreviewWindow/View3D/MeshViewerWidget.cs +++ b/PartPreviewWindow/View3D/MeshViewerWidget.cs @@ -39,6 +39,7 @@ using MatterHackers.Agg.OpenGlGui; using MatterHackers.Agg.UI; using MatterHackers.Agg.VertexSource; using MatterHackers.DataConverters3D; +using MatterHackers.MatterControl; using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.PolygonMesh; using MatterHackers.RenderOpenGl; @@ -84,6 +85,14 @@ namespace MatterHackers.MeshVisualizer { interactionLayer.Scene = Scene; + var activePrintItem = ApplicationController.Instance.ActivePrintItem; + + if (activePrintItem != null + && File.Exists(activePrintItem.FileLocation)) + { + Scene.Load(activePrintItem.FileLocation); + } + this.interactionLayer = interactionLayer; this.World = interactionLayer.World; diff --git a/PartPreviewWindow/View3D/View3DWidget.cs b/PartPreviewWindow/View3D/View3DWidget.cs index e1c807245..2e3c854ee 100644 --- a/PartPreviewWindow/View3D/View3DWidget.cs +++ b/PartPreviewWindow/View3D/View3DWidget.cs @@ -332,6 +332,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow }); }; + Button clearPlateButton = smallMarginButtonFactory.Generate("Clear Plate".Localize()); + clearPlateButton.Margin = new BorderDouble(right: 10); + clearPlateButton.Click += (sender, e) => + { + UiThread.RunOnIdle(ApplicationController.Instance.ClearPlate); + }; + doEdittingButtonsContainer.AddChild(clearPlateButton); + // put in the save button AddSaveAndSaveAs(doEdittingButtonsContainer);