Merge pull request #2660 from jlewin/design_tools

Add prototype for unwrap/edit of scene children
This commit is contained in:
johnlewin 2017-11-15 10:32:22 -08:00 committed by GitHub
commit ea92bc7316
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 93 additions and 24 deletions

View file

@ -1095,7 +1095,7 @@ namespace MatterHackers.MatterControl
private string doNotAskAgainMessage = "Don't remind me again".Localize();
public async Task PrintPart(string partFilePath, string gcodePathAndFileName, string printItemName, PrinterConfig printer, View3DWidget view3DWidget, SliceProgressReporter reporter, bool overrideAllowGCode = false)
public async Task PrintPart(string partFilePath, string gcodeFilePath, string printItemName, PrinterConfig printer, View3DWidget view3DWidget, SliceProgressReporter reporter, bool overrideAllowGCode = false)
{
// Exit if called in a non-applicable state
if (this.ActivePrinter.Connection.CommunicationState != CommunicationStates.Connected
@ -1164,7 +1164,7 @@ namespace MatterHackers.MatterControl
if (messageBoxResponse)
{
this.ActivePrinter.Connection.CommunicationState = CommunicationStates.PreparingToPrint;
partToPrint_SliceDone(partFilePath, gcodePathAndFileName);
partToPrint_SliceDone(partFilePath, gcodeFilePath);
}
},
"The file you are attempting to print is a GCode file.\n\nIt is recommended that you only print Gcode files known to match your printer's configuration.\n\nAre you sure you want to print this GCode file?".Localize(),
@ -1189,7 +1189,7 @@ namespace MatterHackers.MatterControl
view3DWidget,
reporter);
partToPrint_SliceDone(partFilePath, gcodePathAndFileName);
partToPrint_SliceDone(partFilePath, gcodeFilePath);
}
}
}
@ -1200,15 +1200,15 @@ namespace MatterHackers.MatterControl
}
}
private void partToPrint_SliceDone(string partFilePath, string gcodePathAndFileName)
private void partToPrint_SliceDone(string partFilePath, string gcodeFilePath)
{
if (!string.IsNullOrEmpty(partFilePath)
&& File.Exists(partFilePath))
{
if (gcodePathAndFileName != "")
if (gcodeFilePath != "")
{
bool originalIsGCode = Path.GetExtension(partFilePath).ToUpper() == ".GCODE";
if (File.Exists(gcodePathAndFileName))
if (File.Exists(gcodeFilePath))
{
// Create archive point for printing attempt
if (Path.GetExtension(partFilePath).ToUpper() == ".MCX")
@ -1225,20 +1225,20 @@ namespace MatterHackers.MatterControl
{
zip.CreateEntryFromFile(partFilePath, "PrinterPlate.mcx");
zip.CreateEntryFromFile(ActiveSliceSettings.Instance.DocumentPath, ActiveSliceSettings.Instance.GetValue(SettingsKey.printer_name) + ".printer");
zip.CreateEntryFromFile(gcodePathAndFileName, "sliced.gcode");
zip.CreateEntryFromFile(gcodeFilePath, "sliced.gcode");
}
}
// read the last few k of the file and see if it says "filament used". We use this marker to tell if the file finished writing
if (originalIsGCode)
{
this.ActivePrinter.Connection.StartPrint(gcodePathAndFileName);
this.ActivePrinter.Connection.StartPrint(gcodeFilePath);
return;
}
else
{
int bufferSize = 32000;
using (Stream fileStream = new FileStream(gcodePathAndFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (Stream fileStream = new FileStream(gcodeFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
byte[] buffer = new byte[bufferSize];
fileStream.Seek(Math.Max(0, fileStream.Length - bufferSize), SeekOrigin.Begin);
@ -1248,7 +1248,7 @@ namespace MatterHackers.MatterControl
string fileEnd = System.Text.Encoding.UTF8.GetString(buffer);
if (fileEnd.Contains("filament used"))
{
this.ActivePrinter.Connection.StartPrint(gcodePathAndFileName);
this.ActivePrinter.Connection.StartPrint(gcodeFilePath);
return;
}
}
@ -1260,7 +1260,7 @@ namespace MatterHackers.MatterControl
}
}
public async Task SliceFileLoadOutput(PrinterConfig printer, string partFilePath, string gcodePathAndFileName, View3DWidget view3DWidget, SliceProgressReporter reporter)
public async Task SliceFileLoadOutput(PrinterConfig printer, string partFilePath, string gcodeFilePath, View3DWidget view3DWidget, SliceProgressReporter reporter)
{
var gcodeLoadCancellationTokenSource = new CancellationTokenSource();
@ -1269,12 +1269,12 @@ namespace MatterHackers.MatterControl
// Slice
reporter?.StartReporting();
await Slicer.SliceFileAsync(partFilePath, gcodePathAndFileName, reporter);
await Slicer.SliceFileAsync(partFilePath, gcodeFilePath, reporter);
reporter?.EndReporting();
// Load
printer.Bed.LoadGCode(
gcodePathAndFileName,
gcodeFilePath,
gcodeLoadCancellationTokenSource.Token,
null);
// TODO: use not yet implemented standard processing notification system to report GCode load

View file

@ -334,7 +334,8 @@ namespace MatterHackers.MatterControl
{
private ILibraryItem _sourceItem;
public ILibraryWritableContainer LibraryContainer { get; set; }
public IContentStore ContentStore { get; set; }
public ILibraryItem SourceItem
{
get => _sourceItem;
@ -351,6 +352,7 @@ namespace MatterHackers.MatterControl
}
}
}
public IObject3D Content { get; set; }
public string GCodeFilePath => printItem.GetGCodePathAndFileName();
@ -372,7 +374,7 @@ namespace MatterHackers.MatterControl
}
// Call save on the provider
this.LibraryContainer.Save(this.SourceItem, this.Content);
this.ContentStore.Save(this.SourceItem, this.Content);
}
}

View file

@ -59,7 +59,7 @@ namespace MatterHackers.MatterControl.Library
void Load();
}
public interface ILibraryWritableContainer : ILibraryContainer
public interface ILibraryWritableContainer : ILibraryContainer, IContentStore
{
event EventHandler<ItemChangedEventArgs> ItemContentChanged;
@ -68,8 +68,6 @@ 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);
}
@ -91,4 +89,9 @@ namespace MatterHackers.MatterControl.Library
this.LibraryItem = libraryItem;
}
}
public interface IContentStore
{
void Save(ILibraryItem item, IObject3D content);
}
}

View file

@ -439,7 +439,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
bed = new BedConfig(
new EditContext()
{
LibraryContainer = writableContainer,
ContentStore = writableContainer,
SourceItem = firstItem
}),
theme);

View file

@ -66,7 +66,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
new BedConfig(
new EditContext()
{
LibraryContainer = ApplicationController.Instance.Library.PlatingHistory,
ContentStore = ApplicationController.Instance.Library.PlatingHistory,
SourceItem = BedConfig.NewPlatingItem()
}),
theme);

View file

@ -30,15 +30,18 @@ either expressed or implied, of the FreeBSD Project.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.Library;
using MatterHackers.MeshVisualizer;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class SelectedObjectPanel : FlowLayoutWidget
public class SelectedObjectPanel : FlowLayoutWidget, IContentStore
{
private IObject3D item = new Object3D();
@ -95,6 +98,27 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
behavior3DTypeButtons.AddChild(solidBehaviorButton);
var editButton = new TextButton("Edit", theme);
editButton.Click += async (s, e) =>
{
BedConfig bed;
var partPreviewContent = this.Parents<PartPreviewContent>().FirstOrDefault();
partPreviewContent.CreatePartTab(
"New Part",
bed = new BedConfig(
new EditContext()
{
ContentStore = ApplicationController.Instance.Library.PlatingHistory,
SourceItem = new InMemoryItem(this.item),
}),
theme);
await bed.LoadContent();
};
behavior3DTypeButtons.AddChild(editButton);
this.AddChild(editorPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
Name = "editorPanel",
@ -234,5 +258,45 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
activeEditorWidget = newEditor;
}
public void Save(ILibraryItem item, IObject3D content)
{
this.item.Parent.Children.Modify(children =>
{
children.Remove(this.item);
children.Add(content);
});
}
public class InMemoryItem : ILibraryContentItem
{
private IObject3D existingItem;
public InMemoryItem(IObject3D existingItem)
{
this.existingItem = existingItem;
}
public string ID => existingItem.ID;
public string Name => existingItem.Name;
public bool IsProtected => !existingItem.Persistable;
public bool IsVisible => existingItem.Visible;
public string ContentType => "stl";
public string Category => "";
public Task<IObject3D> GetContent(Action<double, string> reportProgress)
{
return Task.FromResult(existingItem);
}
public void SetContent(IObject3D item)
{
}
}
}
}

View file

@ -63,7 +63,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
new PrinterConfig(
new EditContext()
{
LibraryContainer = ApplicationController.Instance.Library.PlatingHistory,
ContentStore = ApplicationController.Instance.Library.PlatingHistory,
SourceItem = BedConfig.LoadLastPlateOrNew()
},
// Short term workaround to run sync during load
@ -151,7 +151,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
new PrinterConfig(
new EditContext()
{
LibraryContainer = ApplicationController.Instance.Library.PlatingHistory,
ContentStore = ApplicationController.Instance.Library.PlatingHistory,
SourceItem = BedConfig.LoadLastPlateOrNew()
},
await ProfileManager.LoadProfileAsync(printerID)));
@ -484,7 +484,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
var printer = new PrinterConfig(
new EditContext()
{
LibraryContainer = ApplicationController.Instance.Library.PlatingHistory,
ContentStore = ApplicationController.Instance.Library.PlatingHistory,
SourceItem = BedConfig.LoadLastPlateOrNew()
},
printerSettings);