Merge pull request #2658 from jlewin/design_tools
Revise scene load/save
This commit is contained in:
commit
1baad0b596
21 changed files with 323 additions and 100 deletions
|
|
@ -41,6 +41,7 @@ using MatterHackers.MatterControl.PrinterCommunication;
|
|||
using MatterHackers.MatterControl.PrintQueue;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
using Newtonsoft.Json;
|
||||
using MatterHackers.MatterControl.Library;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
|
|
@ -72,7 +73,9 @@ namespace MatterHackers.MatterControl
|
|||
// A list of printers which are open (i.e. displaying a tab) on this instance of MatterControl
|
||||
public IEnumerable<PrinterConfig> ActivePrinters { get; } = new List<PrinterConfig>();
|
||||
|
||||
private static PrinterConfig emptyPrinter = new PrinterConfig(false, PrinterSettings.Empty);
|
||||
private static PrinterConfig emptyPrinter = new PrinterConfig(null, PrinterSettings.Empty);
|
||||
|
||||
private static string cacheDirectory = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "temp", "cache");
|
||||
|
||||
// TODO: Any references to this property almost certainly need to be reconsidered. ActiveSliceSettings static references that assume a single printer
|
||||
// selection are being redirected here. This allows us to break the dependency to the original statics and consolidates
|
||||
|
|
@ -112,11 +115,17 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
private Queue<Func<Task>> queuedThumbCallbacks = new Queue<Func<Task>>();
|
||||
|
||||
public void SetActivePrinter(PrinterConfig printer, bool allowChangedEvent = true)
|
||||
public async Task SetActivePrinter(PrinterConfig printer, bool allowChangedEvent = true)
|
||||
{
|
||||
var initialPrinter = this.ActivePrinter;
|
||||
if (initialPrinter?.Settings.ID != printer.Settings.ID)
|
||||
{
|
||||
// TODO: Consider if autosave is appropriate
|
||||
if (initialPrinter != emptyPrinter)
|
||||
{
|
||||
initialPrinter.Bed.Save();
|
||||
}
|
||||
|
||||
// If we have an active printer, run Disable
|
||||
if (initialPrinter.Settings != PrinterSettings.Empty)
|
||||
{
|
||||
|
|
@ -127,6 +136,11 @@ namespace MatterHackers.MatterControl
|
|||
(this.ActivePrinters as List<PrinterConfig>).Add(printer);
|
||||
this.ActivePrinter = printer;
|
||||
|
||||
if (printer != emptyPrinter)
|
||||
{
|
||||
await printer.Bed.LoadContent();
|
||||
}
|
||||
|
||||
// TODO: Decide if non-printer contexts should prompt for a printer, if we should have a default printer, or get "ActiveTab printer" working
|
||||
// HACK: short term solution to resolve printer reference for non-printer related contexts
|
||||
DragDropData.Printer = printer;
|
||||
|
|
@ -160,9 +174,9 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
}
|
||||
|
||||
internal void ClearActivePrinter()
|
||||
internal async Task ClearActivePrinter()
|
||||
{
|
||||
this.SetActivePrinter(emptyPrinter);
|
||||
await this.SetActivePrinter(emptyPrinter);
|
||||
}
|
||||
|
||||
public void RefreshActiveInstance(PrinterSettings updatedPrinterSettings)
|
||||
|
|
@ -409,6 +423,7 @@ namespace MatterHackers.MatterControl
|
|||
() => new SqliteLibraryContainer(rootLibraryCollection.Id)));
|
||||
}
|
||||
|
||||
|
||||
this.Library.RegisterRootProvider(
|
||||
new DynamicContainerLink(
|
||||
"Print History".Localize(),
|
||||
|
|
@ -451,6 +466,13 @@ namespace MatterHackers.MatterControl
|
|||
IsReadOnly = true
|
||||
});
|
||||
|
||||
this.Library.PlatingHistory = new PlatingHistoryContainer();
|
||||
|
||||
this.Library.RegisterRootProvider(
|
||||
new DynamicContainerLink(
|
||||
"Plating History".Localize(),
|
||||
LibraryProviderHelpers.LoadInvertIcon("FileDialog", "folder.png"),
|
||||
() => ApplicationController.Instance.Library.PlatingHistory));
|
||||
}
|
||||
|
||||
public ApplicationController()
|
||||
|
|
@ -632,8 +654,6 @@ namespace MatterHackers.MatterControl
|
|||
return await LoadCacheableAsync<T>(cacheKey, cacheScope, staticDataFallbackPath);
|
||||
}
|
||||
|
||||
private static string cacheDirectory = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "temp", "cache");
|
||||
|
||||
public static string CacheablePath(string cacheScope, string cacheKey)
|
||||
{
|
||||
string scopeDirectory = Path.Combine(cacheDirectory, cacheScope);
|
||||
|
|
@ -700,6 +720,13 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
public void OnApplicationClosed()
|
||||
{
|
||||
// Save changes before close
|
||||
if (this.ActivePrinter != null
|
||||
&& this.ActivePrinter != emptyPrinter)
|
||||
{
|
||||
this.ActivePrinter.Bed.Save();
|
||||
}
|
||||
|
||||
ApplicationClosed?.Invoke(null, null);
|
||||
}
|
||||
|
||||
|
|
@ -968,6 +995,7 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
AggContext.StaticData.LoadImageData(stream, imageToLoadInto);
|
||||
}
|
||||
|
||||
imageToLoadInto.MarkImageChanged();
|
||||
}
|
||||
catch
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ namespace MatterHackers.MatterControl
|
|||
using MatterHackers.Agg;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.GCodeVisualizer;
|
||||
using MatterHackers.MatterControl.Library;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
using MatterHackers.MeshVisualizer;
|
||||
using MatterHackers.PolygonMesh;
|
||||
|
|
@ -61,40 +62,31 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
public PrinterConfig Printer { get; set; }
|
||||
|
||||
public EditContext EditContext { get; private set; }
|
||||
|
||||
public Mesh PrinterShape { get; private set; }
|
||||
|
||||
public BedConfig(PrinterConfig printer = null, bool loadLastBedplate = false)
|
||||
public BedConfig(EditContext editContext, PrinterConfig printer = null)
|
||||
{
|
||||
this.EditContext = editContext;
|
||||
this.Printer = printer;
|
||||
}
|
||||
|
||||
if (loadLastBedplate)
|
||||
{
|
||||
// Find the last used bed plate mcx
|
||||
var directoryInfo = new DirectoryInfo(ApplicationDataStorage.Instance.PlatingDirectory);
|
||||
var firstFile = directoryInfo.GetFileSystemInfos("*.mcx").OrderByDescending(fl => fl.CreationTime).FirstOrDefault();
|
||||
public async Task LoadContent()
|
||||
{
|
||||
// View or caller should invoke LoadContent
|
||||
this.EditContext.Content = await EditContext.SourceItem.CreateContent(null);
|
||||
this.Scene.Load(this.EditContext.Content);
|
||||
}
|
||||
|
||||
// Set as the current item - should be restored as the Active scene in the MeshViewer
|
||||
if (firstFile != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var loadedItem = new PrintItemWrapper(new PrintItem(firstFile.Name, firstFile.FullName));
|
||||
if (loadedItem != null)
|
||||
{
|
||||
this.printItem = loadedItem;
|
||||
}
|
||||
internal static ILibraryItem NewPlatingItem()
|
||||
{
|
||||
string now = DateTime.Now.ToString("yyyyMMdd-HHmmss");
|
||||
string mcxPath = Path.Combine(ApplicationDataStorage.Instance.PlatingDirectory, now + ".mcx");
|
||||
|
||||
this.Scene.Load(firstFile.FullName);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
File.WriteAllText(mcxPath, new Object3D().ToJson());
|
||||
|
||||
// Clear if not assigned above
|
||||
if (this.printItem == null)
|
||||
{
|
||||
this.ClearPlate();
|
||||
}
|
||||
return new FileSystemFileItem(mcxPath);
|
||||
}
|
||||
|
||||
internal void ClearPlate()
|
||||
|
|
@ -109,9 +101,13 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
this.printItem = new PrintItemWrapper(new PrintItem(now, mcxPath));
|
||||
|
||||
File.WriteAllText(mcxPath, new Object3D().ToJson());
|
||||
var content = new Object3D();
|
||||
|
||||
this.Scene.Load(mcxPath);
|
||||
this.Scene.Load(content);
|
||||
|
||||
//this.Scene.Save()
|
||||
|
||||
File.WriteAllText(mcxPath, content.ToJson());
|
||||
|
||||
// TODO: Define and fire event and eliminate ActiveView3DWidget - model objects need to be dependency free. For the time being prevent application spin up in ClearPlate due to the call below - if MC isn't loaded, don't notify
|
||||
if (!MatterControlApplication.IsLoading)
|
||||
|
|
@ -120,6 +116,22 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
}
|
||||
|
||||
internal static ILibraryItem LoadLastPlateOrNew()
|
||||
{
|
||||
// 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
|
||||
if (firstFile != null)
|
||||
{
|
||||
return new FileSystemFileItem(firstFile.FullName);
|
||||
}
|
||||
|
||||
// Otherwise generate a new plating item
|
||||
return NewPlatingItem();
|
||||
}
|
||||
|
||||
private GCodeFile loadedGCode;
|
||||
public GCodeFile LoadedGCode
|
||||
{
|
||||
|
|
@ -320,6 +332,34 @@ namespace MatterHackers.MatterControl
|
|||
// Invalidate bed mesh cache
|
||||
_bedMesh = null;
|
||||
}
|
||||
|
||||
internal void Save()
|
||||
{
|
||||
if (this.Scene.Persistable)
|
||||
{
|
||||
this.Scene.PersistAssets(ApplicationDataStorage.Instance.ApplicationLibraryDataPath);
|
||||
this.EditContext.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class EditContext
|
||||
{
|
||||
public ILibraryWritableContainer LibraryContainer { get; set; }
|
||||
public ILibraryItem SourceItem { get; set; }
|
||||
public IObject3D Content { get; set; }
|
||||
|
||||
internal void Save()
|
||||
{
|
||||
var thumbnailPath = ApplicationController.Instance.ThumbnailCachePath(this.SourceItem);
|
||||
if (File.Exists(thumbnailPath))
|
||||
{
|
||||
File.Delete(thumbnailPath);
|
||||
}
|
||||
|
||||
// Call save on the provider
|
||||
this.LibraryContainer.Save(this.SourceItem, this.Content);
|
||||
}
|
||||
}
|
||||
|
||||
public class PrinterViewState
|
||||
|
|
@ -386,9 +426,9 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
private EventHandler unregisterEvents;
|
||||
|
||||
public PrinterConfig(bool loadLastBedplate, PrinterSettings settings)
|
||||
public PrinterConfig(EditContext editContext, PrinterSettings settings)
|
||||
{
|
||||
this.Bed = new BedConfig(this, loadLastBedplate);
|
||||
this.Bed = new BedConfig(editContext, this);
|
||||
|
||||
this.Connection = new PrinterConnection(printer: this);
|
||||
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
|
||||
progressContainer.AddChild(printerName);
|
||||
|
||||
partName = new TextWidget(printer.Bed.printItem.GetFriendlyName(), pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
|
||||
partName = new TextWidget(printer.Bed.EditContext.SourceItem.Name, pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
|
||||
{
|
||||
HAnchor = HAnchor.Center,
|
||||
MinimumSize = new Vector2(maxTextWidth, MinimumSize.Y),
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.DataConverters3D;
|
||||
|
||||
namespace MatterHackers.MatterControl.Library
|
||||
{
|
||||
|
|
@ -67,6 +68,8 @@ namespace MatterHackers.MatterControl.Library
|
|||
void Rename(ILibraryItem item, string revisedName);
|
||||
void Move(IEnumerable<ILibraryItem> items, ILibraryContainer targetContainer);
|
||||
|
||||
void Save(ILibraryItem item, IObject3D content);
|
||||
|
||||
void SetThumbnail(ILibraryItem item, int width, int height, ImageBuffer imageBuffer);
|
||||
bool AllowAction(ContainerActions containerActions);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ using System.Text.RegularExpressions;
|
|||
using System.Threading.Tasks;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.DataConverters3D;
|
||||
|
||||
namespace MatterHackers.MatterControl.Library
|
||||
{
|
||||
|
|
|
|||
|
|
@ -124,6 +124,8 @@ namespace MatterHackers.MatterControl.Library
|
|||
}
|
||||
}
|
||||
|
||||
public PlatingHistoryContainer PlatingHistory { get; internal set; }
|
||||
|
||||
public IContentProvider GetContentProvider(ILibraryItem item)
|
||||
{
|
||||
string contentType = (item as ILibraryContentStream)?.ContentType ?? (item as ILibraryContentItem)?.ContentType;
|
||||
|
|
|
|||
108
Library/Providers/MatterControl/PlatingHistoryContainer.cs
Normal file
108
Library/Providers/MatterControl/PlatingHistoryContainer.cs
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
Copyright (c) 2017, 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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
|
||||
namespace MatterHackers.MatterControl.Library
|
||||
{
|
||||
public class PlatingHistoryContainer : LibraryContainer, ILibraryWritableContainer
|
||||
{
|
||||
public PlatingHistoryContainer()
|
||||
{
|
||||
this.ChildContainers = new List<ILibraryContainerLink>();
|
||||
this.Items = new List<ILibraryItem>();
|
||||
this.Name = "Plating History".Localize();
|
||||
}
|
||||
|
||||
public event EventHandler<ItemChangedEventArgs> ItemContentChanged;
|
||||
|
||||
public void Add(IEnumerable<ILibraryItem> items)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool AllowAction(ContainerActions containerActions)
|
||||
{
|
||||
switch(containerActions)
|
||||
{
|
||||
case ContainerActions.AddItems:
|
||||
case ContainerActions.AddContainers:
|
||||
case ContainerActions.RemoveItems:
|
||||
case ContainerActions.RenameItems:
|
||||
return false;
|
||||
|
||||
default:
|
||||
System.Diagnostics.Debugger.Break();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
// PrintItems projected onto FileSystemFileItem
|
||||
Items = new DirectoryInfo(ApplicationDataStorage.Instance.PlatingDirectory).GetFiles("*.mcx").OrderByDescending(f => f.CreationTime).Take(25).Select(f => new FileSystemFileItem(f.FullName)).ToList<ILibraryItem>();
|
||||
}
|
||||
|
||||
public void Move(IEnumerable<ILibraryItem> items, ILibraryContainer targetContainer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Remove(IEnumerable<ILibraryItem> items)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Rename(ILibraryItem item, string revisedName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Save(ILibraryItem item, IObject3D content)
|
||||
{
|
||||
if (item is FileSystemFileItem fileItem)
|
||||
{
|
||||
// Serialize the scene to disk using a modified Json.net pipeline with custom ContractResolvers and JsonConverters
|
||||
File.WriteAllText(fileItem.Path, content.ToJson());
|
||||
this.ItemContentChanged?.Invoke(this, new ItemChangedEventArgs(fileItem));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetThumbnail(ILibraryItem item, int width, int height, ImageBuffer imageBuffer)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -29,7 +29,9 @@ either expressed or implied, of the FreeBSD Project.
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.DataConverters3D;
|
||||
|
||||
namespace MatterHackers.MatterControl.Library
|
||||
{
|
||||
|
|
@ -39,7 +41,7 @@ namespace MatterHackers.MatterControl.Library
|
|||
|
||||
public virtual void OnItemContentChanged(ItemChangedEventArgs args)
|
||||
{
|
||||
ItemContentChanged?.Invoke(this, args);
|
||||
this.ItemContentChanged?.Invoke(this, args);
|
||||
}
|
||||
|
||||
public virtual void Add(IEnumerable<ILibraryItem> items)
|
||||
|
|
@ -54,6 +56,17 @@ namespace MatterHackers.MatterControl.Library
|
|||
{
|
||||
}
|
||||
|
||||
public virtual void Save(ILibraryItem item, IObject3D content)
|
||||
{
|
||||
if (item is FileSystemFileItem fileItem)
|
||||
{
|
||||
// Serialize the scene to disk using a modified Json.net pipeline with custom ContractResolvers and JsonConverters
|
||||
File.WriteAllText(fileItem.Path, content.ToJson());
|
||||
|
||||
this.OnItemContentChanged(new ItemChangedEventArgs(fileItem));
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Move(IEnumerable<ILibraryItem> items, ILibraryContainer targetContainer)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -423,26 +423,29 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
AllowMultiple = false,
|
||||
AllowProtected = false,
|
||||
AllowContainers = false,
|
||||
Action = (selectedLibraryItems, listView) =>
|
||||
Action = async (selectedLibraryItems, listView) =>
|
||||
{
|
||||
var firstItem = selectedLibraryItems.FirstOrDefault();
|
||||
if (firstItem != null)
|
||||
if (selectedLibraryItems.FirstOrDefault() is ILibraryItem firstItem
|
||||
&& ApplicationController.Instance.Library.ActiveContainer is ILibraryWritableContainer writableContainer)
|
||||
{
|
||||
var bedConfig = new BedConfig();
|
||||
BedConfig bed;
|
||||
|
||||
var newTab = partPreviewContent.CreatePartTab(firstItem.Name, bedConfig, theme);
|
||||
if (newTab.TabContent is PartTabPage printerTab)
|
||||
var newTab = partPreviewContent.CreatePartTab(
|
||||
firstItem.Name,
|
||||
bed = new BedConfig(
|
||||
new EditContext()
|
||||
{
|
||||
LibraryContainer = writableContainer,
|
||||
SourceItem = firstItem
|
||||
}),
|
||||
theme);
|
||||
|
||||
// Load content after UI widgets to support progress notification during acquire/load
|
||||
await bed.LoadContent();
|
||||
|
||||
if (newTab.TabContent is PartTabPage partTab)
|
||||
{
|
||||
bedConfig.Scene.Children.Modify(list =>
|
||||
{
|
||||
list.Add(
|
||||
new InsertionGroup(
|
||||
selectedLibraryItems.Take(1),
|
||||
printerTab.view3DWidget,
|
||||
bedConfig.Scene,
|
||||
bedConfig.BedCenter,
|
||||
() => false));
|
||||
});
|
||||
// TODO: Restore ability to render progress loading
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@
|
|||
<Compile Include="CustomWidgets\DisableablePanel.cs" />
|
||||
<Compile Include="Library\Interfaces\LibraryExtensionMethods.cs" />
|
||||
<Compile Include="Library\Providers\CreateFolderItem.cs" />
|
||||
<Compile Include="Library\Providers\MatterControl\PlatingHistoryContainer.cs" />
|
||||
<Compile Include="Library\Providers\MatterControl\PrintHistoryContainer.cs" />
|
||||
<Compile Include="Library\Providers\MatterControl\PrintHistoryItem.cs" />
|
||||
<Compile Include="Library\Providers\WritableContainer.cs" />
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
this.parentTabControl.RemoveTab(this);
|
||||
this.CloseClicked?.Invoke(this, null);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -61,7 +61,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
simpleTabs.RemoveTab(simpleTabs.ActiveTab);
|
||||
partPreviewContent.CreatePartTab("New Part", new BedConfig(), theme);
|
||||
partPreviewContent.CreatePartTab(
|
||||
"New Part",
|
||||
new BedConfig(
|
||||
new EditContext()
|
||||
{
|
||||
LibraryContainer = ApplicationController.Instance.Library.PlatingHistory,
|
||||
SourceItem = BedConfig.NewPlatingItem()
|
||||
}),
|
||||
theme);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -244,12 +244,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
}
|
||||
}
|
||||
|
||||
private void MainTab_CloseClicked(object sender, EventArgs e)
|
||||
private async void MainTab_CloseClicked(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is ITab tab)
|
||||
if (sender is ITab tab
|
||||
&& tab.TabContent is PrinterTabPage)
|
||||
{
|
||||
this.RemoveTab(sender as ITab);
|
||||
ApplicationController.Instance.ClearActivePrinter();
|
||||
await ApplicationController.Instance.ClearActivePrinter();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -567,6 +567,13 @@ namespace MatterHackers.MeshVisualizer
|
|||
private void Draw_GlOpaqueContent(object sender, DrawEventArgs e)
|
||||
{
|
||||
List<IObject3D> transparentMeshes = new List<IObject3D>();
|
||||
|
||||
// TODO: Adding in to test out how editing InteractiveScene roots might work. Remove/adjust after discussing
|
||||
if (scene.Mesh != null)
|
||||
{
|
||||
GLHelper.Render(scene.Mesh, scene.WorldColor(), scene.Matrix, RenderTypes.Shaded);
|
||||
}
|
||||
|
||||
foreach (var object3D in scene.Children)
|
||||
{
|
||||
DrawObject(object3D, transparentMeshes, false, e);
|
||||
|
|
|
|||
|
|
@ -343,14 +343,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
Title = "Save".Localize(),
|
||||
Action = async () =>
|
||||
{
|
||||
if (sceneContext.printItem == null)
|
||||
{
|
||||
UiThread.RunOnIdle(OpenSaveAsWindow);
|
||||
}
|
||||
else
|
||||
{
|
||||
await this.SaveChanges();
|
||||
}
|
||||
await this.SaveChanges();
|
||||
}
|
||||
},
|
||||
new NamedAction()
|
||||
|
|
@ -2017,16 +2010,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
try
|
||||
{
|
||||
// Force to .mcx
|
||||
if (Path.GetExtension(sceneContext.printItem.FileLocation) != ".mcx")
|
||||
{
|
||||
sceneContext.printItem.FileLocation = Path.ChangeExtension(sceneContext.printItem.FileLocation, ".mcx");
|
||||
}
|
||||
|
||||
// TODO: Hook up progress reporting
|
||||
Scene.Save(sceneContext.printItem.FileLocation, ApplicationDataStorage.Instance.ApplicationLibraryDataPath);
|
||||
|
||||
sceneContext.printItem.PrintItem.Commit();
|
||||
sceneContext.Save();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -105,12 +105,12 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
|
||||
case PauseReason.PauseLayerReached:
|
||||
case PauseReason.GCodeRequest:
|
||||
printer.Connection.PauseOnLayer.CallEvents(printer.Connection, new PrintItemWrapperEventArgs(printer.Bed.printItem));
|
||||
printer.Connection.PauseOnLayer.CallEvents(printer.Connection, new NamedItemEventArgs(printer.Bed.EditContext?.SourceItem?.Name ?? "Unknown"));
|
||||
UiThread.RunOnIdle(() => StyledMessageBox.ShowMessageBox(ResumePrint, layerPauseMessage.FormatWith(layerNumber), pauseCaption, StyledMessageBox.MessageType.YES_NO, "Ok".Localize(), "Resume".Localize()));
|
||||
break;
|
||||
|
||||
case PauseReason.FilamentRunout:
|
||||
printer.Connection.FilamentRunout.CallEvents(printer.Connection, new PrintItemWrapperEventArgs(printer.Bed.printItem));
|
||||
printer.Connection.FilamentRunout.CallEvents(printer.Connection, new NamedItemEventArgs(printer.Bed.EditContext?.SourceItem?.Name ?? "Unknown"));
|
||||
UiThread.RunOnIdle(() => StyledMessageBox.ShowMessageBox(ResumePrint, filamentPauseMessage, pauseCaption, StyledMessageBox.MessageType.YES_NO, "Ok".Localize(), "Resume".Localize()));
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -473,7 +473,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
|
|||
// Set this early as we always want our functions to know the state we are in.
|
||||
communicationState = value;
|
||||
timeSinceStartedPrint.Stop();
|
||||
PrintFinished.CallEvents(this, new PrintItemWrapperEventArgs(printer.Bed.printItem));
|
||||
PrintFinished.CallEvents(this, new NamedItemEventArgs(printer.Bed.EditContext.SourceItem.Name));
|
||||
|
||||
// clear single use setting on print completion
|
||||
foreach (var keyValue in printer.Settings.BaseLayer)
|
||||
|
|
@ -2846,14 +2846,14 @@ namespace MatterHackers.MatterControl.PrinterCommunication
|
|||
}
|
||||
}
|
||||
|
||||
public class PrintItemWrapperEventArgs : EventArgs
|
||||
public class NamedItemEventArgs : EventArgs
|
||||
{
|
||||
public PrintItemWrapperEventArgs(PrintItemWrapper printItemWrapper)
|
||||
public NamedItemEventArgs(string name)
|
||||
{
|
||||
this.PrintItemWrapper = printItemWrapper;
|
||||
this.ItemName = name;
|
||||
}
|
||||
|
||||
public PrintItemWrapper PrintItemWrapper { get; }
|
||||
public string ItemName { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -61,8 +61,13 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
// Load or download on a background thread the last loaded settings
|
||||
ApplicationController.Instance.SetActivePrinter(
|
||||
new PrinterConfig(
|
||||
true,
|
||||
LoadProfileAsync(activeInstance.LastProfileID).Result));
|
||||
new EditContext()
|
||||
{
|
||||
LibraryContainer = ApplicationController.Instance.Library.PlatingHistory,
|
||||
SourceItem = BedConfig.LoadLastPlateOrNew()
|
||||
},
|
||||
// Short term workaround to run sync during load
|
||||
LoadProfileAsync(activeInstance.LastProfileID).Result)).Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -142,9 +147,13 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
{
|
||||
ProfileManager.Instance.LastProfileID = printerID;
|
||||
|
||||
ApplicationController.Instance.SetActivePrinter(
|
||||
await ApplicationController.Instance.SetActivePrinter(
|
||||
new PrinterConfig(
|
||||
false,
|
||||
new EditContext()
|
||||
{
|
||||
LibraryContainer = ApplicationController.Instance.Library.PlatingHistory,
|
||||
SourceItem = BedConfig.LoadLastPlateOrNew()
|
||||
},
|
||||
await ProfileManager.LoadProfileAsync(printerID)));
|
||||
}
|
||||
|
||||
|
|
@ -472,9 +481,15 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
// Set as active profile
|
||||
ProfileManager.Instance.LastProfileID = guid;
|
||||
|
||||
var printer = new PrinterConfig(false, printerSettings);
|
||||
var printer = new PrinterConfig(
|
||||
new EditContext()
|
||||
{
|
||||
LibraryContainer = ApplicationController.Instance.Library.PlatingHistory,
|
||||
SourceItem = BedConfig.LoadLastPlateOrNew()
|
||||
},
|
||||
printerSettings);
|
||||
|
||||
ApplicationController.Instance.SetActivePrinter(printer);
|
||||
await ApplicationController.Instance.SetActivePrinter(printer);
|
||||
|
||||
return printer;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 157ae3944409f34e7381ef0c72d8022a34914111
|
||||
Subproject commit 80de803ed4923a7c6aae1bc121f6ad3b72687060
|
||||
|
|
@ -277,7 +277,7 @@ namespace MatterControl.Tests.MatterControl
|
|||
AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
|
||||
MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
|
||||
|
||||
var field = new ComPortField(new PrinterConfig(false, PrinterSettings.Empty));
|
||||
var field = new ComPortField(new PrinterConfig(null, PrinterSettings.Empty));
|
||||
|
||||
await ValidateAgainstValueMap(
|
||||
field,
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ using MatterHackers.Agg;
|
|||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.MatterControl;
|
||||
using MatterHackers.MatterControl.Library;
|
||||
using MatterHackers.MatterControl.Tests.Automation;
|
||||
using MatterHackers.MeshVisualizer;
|
||||
using Newtonsoft.Json;
|
||||
|
|
@ -101,7 +102,7 @@ namespace MatterHackers.PolygonMesh.UnitTests
|
|||
MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
|
||||
#endif
|
||||
|
||||
var sceneContext = new BedConfig();
|
||||
var sceneContext = new BedConfig(null);
|
||||
|
||||
var scene = sceneContext.Scene;
|
||||
scene.Children.Add(new Object3D
|
||||
|
|
@ -126,25 +127,33 @@ namespace MatterHackers.PolygonMesh.UnitTests
|
|||
Assert.AreEqual(1, Directory.GetFiles(tempPath).Length, "Only .mcx file should exists");
|
||||
Assert.AreEqual(1, Directory.GetFiles(Path.Combine(tempPath, "Assets")).Length, "Only 1 asset should exist");
|
||||
|
||||
var originalFiles = Directory.GetFiles(tempPath).ToArray(); ;
|
||||
var originalFiles = Directory.GetFiles(tempPath).ToArray();
|
||||
|
||||
// Load the file from disk
|
||||
IObject3D loadedItem = Object3D.Load(filePath, CancellationToken.None);
|
||||
Assert.IsTrue(loadedItem.Children.Count == 1);
|
||||
Assert.AreEqual(1, loadedItem.Children.Count);
|
||||
|
||||
// Ensure the UI scene is cleared
|
||||
scene.Children.Modify(list => list.Clear());
|
||||
|
||||
// Reload the model
|
||||
await Task.Run(() => sceneContext.Scene.Load(filePath));
|
||||
await Task.Run(() =>
|
||||
{
|
||||
sceneContext.Scene.Load(Object3D.Load(filePath, CancellationToken.None));
|
||||
});
|
||||
|
||||
// Serialize and compare the two trees
|
||||
string onDiskData = JsonConvert.SerializeObject(loadedItem, Formatting.Indented);
|
||||
string inMemoryData = JsonConvert.SerializeObject(scene, Formatting.Indented);
|
||||
Assert.IsTrue(inMemoryData == onDiskData);
|
||||
string onDiskData = loadedItem.ToJson();
|
||||
string inMemoryData = scene.ToJson();
|
||||
|
||||
//File.WriteAllText(@"c:\temp\file-a.txt", onDiskData);
|
||||
//File.WriteAllText(@"c:\temp\file-b.txt", inMemoryData);
|
||||
|
||||
Assert.AreEqual(inMemoryData, onDiskData, "Serialized content should match");
|
||||
|
||||
// Save the scene a second time, validate that things remain the same
|
||||
scene.Save(filePath, tempPath);
|
||||
onDiskData = JsonConvert.SerializeObject(loadedItem, Formatting.Indented);
|
||||
onDiskData = loadedItem.ToJson();
|
||||
|
||||
Assert.IsTrue(inMemoryData == onDiskData);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue