Merge pull request #2659 from jlewin/design_tools
Reduce Print/Slice helper method couplings to PrintItemWrapper
This commit is contained in:
commit
118a000b76
13 changed files with 83 additions and 59 deletions
|
|
@ -1095,7 +1095,7 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
private string doNotAskAgainMessage = "Don't remind me again".Localize();
|
||||
|
||||
public async Task PrintPart(PrintItemWrapper printItem, PrinterConfig printer, View3DWidget view3DWidget, SliceProgressReporter reporter, bool overrideAllowGCode = false)
|
||||
public async Task PrintPart(string partFilePath, string gcodePathAndFileName, 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
|
||||
|
|
@ -1121,21 +1121,20 @@ namespace MatterHackers.MatterControl
|
|||
// Save any pending changes before starting the print
|
||||
await ApplicationController.Instance.ActiveView3DWidget.PersistPlateIfNeeded();
|
||||
|
||||
if (printItem != null)
|
||||
if (!string.IsNullOrEmpty(partFilePath)
|
||||
&& File.Exists(partFilePath))
|
||||
{
|
||||
this.PrintingItemName = printItem.Name;
|
||||
string pathAndFile = printItem.FileLocation;
|
||||
this.PrintingItemName = printItemName;
|
||||
|
||||
if (ActiveSliceSettings.Instance.IsValid())
|
||||
{
|
||||
if (File.Exists(pathAndFile))
|
||||
{
|
||||
// clear the output cache prior to starting a print
|
||||
this.ActivePrinter.Connection.TerminalLog.Clear();
|
||||
|
||||
string hideGCodeWarning = ApplicationSettings.Instance.get(ApplicationSettingsKey.HideGCodeWarning);
|
||||
|
||||
if (Path.GetExtension(pathAndFile).ToUpper() == ".GCODE"
|
||||
if (Path.GetExtension(partFilePath).ToUpper() == ".GCODE"
|
||||
&& hideGCodeWarning == null
|
||||
&& !overrideAllowGCode)
|
||||
{
|
||||
|
|
@ -1165,7 +1164,7 @@ namespace MatterHackers.MatterControl
|
|||
if (messageBoxResponse)
|
||||
{
|
||||
this.ActivePrinter.Connection.CommunicationState = CommunicationStates.PreparingToPrint;
|
||||
partToPrint_SliceDone(printItem);
|
||||
partToPrint_SliceDone(partFilePath, gcodePathAndFileName);
|
||||
}
|
||||
},
|
||||
"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(),
|
||||
|
|
@ -1185,11 +1184,12 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
await ApplicationController.Instance.SliceFileLoadOutput(
|
||||
printer,
|
||||
printItem,
|
||||
printer.Bed.EditContext.PartFilePath,
|
||||
printer.Bed.EditContext.GCodeFilePath,
|
||||
view3DWidget,
|
||||
reporter);
|
||||
|
||||
partToPrint_SliceDone(printItem);
|
||||
partToPrint_SliceDone(partFilePath, gcodePathAndFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1200,18 +1200,18 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
}
|
||||
|
||||
private void partToPrint_SliceDone(PrintItemWrapper partToPrint)
|
||||
private void partToPrint_SliceDone(string partFilePath, string gcodePathAndFileName)
|
||||
{
|
||||
if (partToPrint != null)
|
||||
if (!string.IsNullOrEmpty(partFilePath)
|
||||
&& File.Exists(partFilePath))
|
||||
{
|
||||
string gcodePathAndFileName = partToPrint.GetGCodePathAndFileName();
|
||||
if (gcodePathAndFileName != "")
|
||||
{
|
||||
bool originalIsGCode = Path.GetExtension(partToPrint.FileLocation).ToUpper() == ".GCODE";
|
||||
bool originalIsGCode = Path.GetExtension(partFilePath).ToUpper() == ".GCODE";
|
||||
if (File.Exists(gcodePathAndFileName))
|
||||
{
|
||||
// Create archive point for printing attempt
|
||||
if (Path.GetExtension(partToPrint.FileLocation).ToUpper() == ".MCX")
|
||||
if (Path.GetExtension(partFilePath).ToUpper() == ".MCX")
|
||||
{
|
||||
// TODO: We should zip mcx and settings when starting a print
|
||||
string platingDirectory = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, "PrintHistory");
|
||||
|
|
@ -1223,7 +1223,7 @@ namespace MatterHackers.MatterControl
|
|||
using (var file = File.OpenWrite(archivePath))
|
||||
using (var zip = new ZipArchive(file, ZipArchiveMode.Create))
|
||||
{
|
||||
zip.CreateEntryFromFile(partToPrint.FileLocation, "PrinterPlate.mcx");
|
||||
zip.CreateEntryFromFile(partFilePath, "PrinterPlate.mcx");
|
||||
zip.CreateEntryFromFile(ActiveSliceSettings.Instance.DocumentPath, ActiveSliceSettings.Instance.GetValue(SettingsKey.printer_name) + ".printer");
|
||||
zip.CreateEntryFromFile(gcodePathAndFileName, "sliced.gcode");
|
||||
}
|
||||
|
|
@ -1260,7 +1260,7 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
}
|
||||
|
||||
public async Task SliceFileLoadOutput(PrinterConfig printer, PrintItemWrapper printItem, View3DWidget view3DWidget, SliceProgressReporter reporter)
|
||||
public async Task SliceFileLoadOutput(PrinterConfig printer, string partFilePath, string gcodePathAndFileName, View3DWidget view3DWidget, SliceProgressReporter reporter)
|
||||
{
|
||||
var gcodeLoadCancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
|
|
@ -1269,18 +1269,17 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
// Slice
|
||||
reporter?.StartReporting();
|
||||
await Slicer.SliceFileAsync(printItem, reporter);
|
||||
await Slicer.SliceFileAsync(partFilePath, gcodePathAndFileName, reporter);
|
||||
reporter?.EndReporting();
|
||||
|
||||
// Load
|
||||
printer.Bed.LoadGCode(
|
||||
printItem.GetGCodePathAndFileName(),
|
||||
gcodePathAndFileName,
|
||||
gcodeLoadCancellationTokenSource.Token,
|
||||
null);
|
||||
// TODO: use not yet implemented standard processing notification system to report GCode load
|
||||
//view3DWidget.gcodeViewer.LoadProgress_Changed);
|
||||
//SetProcessingMessage(string.Format("{0} {1:0}%...", "Loading G-Code".Localize(), progress0To1 * 100));
|
||||
|
||||
}
|
||||
|
||||
public class CloudSyncEventArgs : EventArgs
|
||||
|
|
|
|||
|
|
@ -58,8 +58,6 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
public View3DConfig RendererOptions { get; } = new View3DConfig();
|
||||
|
||||
public PrintItemWrapper printItem = null;
|
||||
|
||||
public PrinterConfig Printer { get; set; }
|
||||
|
||||
public EditContext EditContext { get; private set; }
|
||||
|
|
@ -99,8 +97,6 @@ namespace MatterHackers.MatterControl
|
|||
this.LoadedGCode = null;
|
||||
this.GCodeRenderer = null;
|
||||
|
||||
this.printItem = new PrintItemWrapper(new PrintItem(now, mcxPath));
|
||||
|
||||
var content = new Object3D();
|
||||
|
||||
this.Scene.Load(content);
|
||||
|
|
@ -197,15 +193,6 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
public GCodeRenderInfo RenderInfo { get; set; }
|
||||
|
||||
public string GCodePath
|
||||
{
|
||||
get
|
||||
{
|
||||
bool isGCode = Path.GetExtension(printItem.FileLocation).ToUpper() == ".GCODE";
|
||||
return isGCode ? printItem.FileLocation : printItem.GetGCodePathAndFileName();
|
||||
}
|
||||
}
|
||||
|
||||
BedMeshGenerator bedGenerator;
|
||||
|
||||
private Mesh _bedMesh;
|
||||
|
|
@ -345,10 +332,37 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
public class EditContext
|
||||
{
|
||||
private ILibraryItem _sourceItem;
|
||||
|
||||
public ILibraryWritableContainer LibraryContainer { get; set; }
|
||||
public ILibraryItem SourceItem { get; set; }
|
||||
public ILibraryItem SourceItem
|
||||
{
|
||||
get => _sourceItem;
|
||||
set
|
||||
{
|
||||
if (_sourceItem != value)
|
||||
{
|
||||
_sourceItem = value;
|
||||
|
||||
if (_sourceItem is FileSystemFileItem fileItem)
|
||||
{
|
||||
printItem = new PrintItemWrapper(new PrintItem(fileItem.FileName, fileItem.Path));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public IObject3D Content { get; set; }
|
||||
|
||||
public string GCodeFilePath => printItem.GetGCodePathAndFileName();
|
||||
|
||||
public string PartFilePath => printItem.FileLocation;
|
||||
|
||||
/// <summary>
|
||||
/// Short term stop gap that should only be used until GCode path helpers, hash code and print recovery components can be extracted
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
internal PrintItemWrapper printItem { get; set; }
|
||||
|
||||
internal void Save()
|
||||
{
|
||||
var thumbnailPath = ApplicationController.Instance.ThumbnailCachePath(this.SourceItem);
|
||||
|
|
|
|||
|
|
@ -125,13 +125,13 @@ namespace MatterHackers.MatterControl.Library.Export
|
|||
// - If bedplate, save any pending changes before starting the print
|
||||
await ApplicationController.Instance.ActiveView3DWidget.PersistPlateIfNeeded();
|
||||
|
||||
var printItem = ApplicationController.Instance.ActivePrinter.Bed.printItem;
|
||||
var context = ApplicationController.Instance.ActivePrinter.Bed.EditContext;
|
||||
|
||||
// - Slice
|
||||
await Slicer.SliceFileAsync(printItem, null);
|
||||
await Slicer.SliceFileAsync(context.PartFilePath, context.GCodeFilePath, null);
|
||||
|
||||
// - Return
|
||||
fileToProcess = printItem.GetGCodePathAndFileName();
|
||||
fileToProcess = context.GCodeFilePath;
|
||||
}
|
||||
|
||||
return fileToProcess;
|
||||
|
|
|
|||
|
|
@ -390,8 +390,12 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
|
||||
AddToPlate(selectedLibraryItems);
|
||||
|
||||
var context = printer.Bed.EditContext;
|
||||
|
||||
await ApplicationController.Instance.PrintPart(
|
||||
printer.Bed.printItem,
|
||||
context.PartFilePath,
|
||||
context.GCodeFilePath,
|
||||
context.SourceItem.Name,
|
||||
printer,
|
||||
activeContext.View3DWidget,
|
||||
null);
|
||||
|
|
|
|||
|
|
@ -280,8 +280,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
UiThread.RunOnIdle(async () =>
|
||||
{
|
||||
var context = printer.Bed.EditContext;
|
||||
await ApplicationController.Instance.PrintPart(
|
||||
printer.Bed.printItem,
|
||||
context.PartFilePath,
|
||||
context.GCodeFilePath,
|
||||
context.SourceItem.Name,
|
||||
printer,
|
||||
printerTabPage.view3DWidget,
|
||||
null);
|
||||
|
|
@ -298,8 +301,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
UiThread.RunOnIdle(async () =>
|
||||
{
|
||||
var context = printer.Bed.EditContext;
|
||||
await ApplicationController.Instance.PrintPart(
|
||||
printer.Bed.printItem,
|
||||
context.PartFilePath,
|
||||
context.GCodeFilePath,
|
||||
context.SourceItem.Name,
|
||||
printer,
|
||||
printerTabPage.view3DWidget,
|
||||
null);
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
if (printer.Settings.PrinterSelected)
|
||||
{
|
||||
if (printer.Settings.IsValid() && printer.Bed.printItem != null)
|
||||
if (printer.Settings.IsValid() && printer.Bed.EditContext.SourceItem != null)
|
||||
{
|
||||
activelySlicing = true;
|
||||
|
||||
|
|
@ -124,7 +124,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
await ApplicationController.Instance.SliceFileLoadOutput(
|
||||
printer,
|
||||
printer.Bed.printItem,
|
||||
printer.Bed.EditContext.PartFilePath,
|
||||
printer.Bed.EditContext.GCodeFilePath,
|
||||
printerTabPage.view3DWidget,
|
||||
new SliceProgressReporter(this.PopupContent, printer));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -353,7 +353,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
},
|
||||
new NamedAction()
|
||||
{
|
||||
Title = "Export".Localize() + "...",
|
||||
Title = "Export".Localize(),
|
||||
Action = () =>
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
|
|
@ -361,14 +361,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
DialogWindow.Show(
|
||||
new ExportPrintItemPage(new[]
|
||||
{
|
||||
new FileSystemFileItem(sceneContext.printItem.FileLocation)
|
||||
new FileSystemFileItem(sceneContext.EditContext.PartFilePath)
|
||||
}));
|
||||
});
|
||||
}
|
||||
},
|
||||
new NamedAction()
|
||||
{
|
||||
Title = "Publish".Localize() + "...",
|
||||
Title = "Publish".Localize(),
|
||||
Action = () =>
|
||||
{
|
||||
UiThread.RunOnIdle(() => DialogWindow.Show<PublishPartToMatterHackers>());
|
||||
|
|
@ -2068,7 +2068,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
writableContainer.Add(new[]
|
||||
{
|
||||
new FileSystemFileItem(sceneContext.printItem.FileLocation)
|
||||
new FileSystemFileItem(sceneContext.EditContext.PartFilePath)
|
||||
{
|
||||
Name = returnInfo.ItemName
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2331,7 +2331,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
|
|||
|
||||
case CommunicationStates.PreparingToPrint:
|
||||
{
|
||||
var activePrintItem = printer.Bed.printItem;
|
||||
var activePrintItem = printer.Bed.EditContext.printItem;
|
||||
if (activePrintItem.PrintItem.Id == 0)
|
||||
{
|
||||
activePrintItem.PrintItem.Commit();
|
||||
|
|
|
|||
|
|
@ -360,7 +360,10 @@ namespace MatterHackers.PrinterEmulator
|
|||
{
|
||||
// M104 S210 or M109 S[temp]
|
||||
var sIndex = command.IndexOf('S') + 1;
|
||||
Hotend.TargetTemperature = int.Parse(command.Substring(sIndex));
|
||||
var spaceIndex = command.IndexOf(" ", sIndex);
|
||||
var temp = (spaceIndex < 0) ? command.Substring(sIndex) : command.Substring(sIndex, spaceIndex - sIndex);
|
||||
|
||||
Hotend.TargetTemperature = int.Parse(temp);
|
||||
ExtruderTemperatureChanged?.Invoke(this, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
|||
|
|
@ -99,11 +99,11 @@ namespace MatterHackers.MatterControl.PrintQueue
|
|||
savedGCodeFileNames = new List<string>();
|
||||
foreach (PrintItem part in allFilesToExport)
|
||||
{
|
||||
PrintItemWrapper printItemWrapper = new PrintItemWrapper(part);
|
||||
var printItemWrapper = new PrintItemWrapper(part);
|
||||
string extension = Path.GetExtension(printItemWrapper.FileLocation).ToUpper();
|
||||
if ((extension != "" && MeshFileIo.ValidFileExtensions().Contains(extension)))
|
||||
if (extension != "" && MeshFileIo.ValidFileExtensions().Contains(extension))
|
||||
{
|
||||
Slicer.SliceFileAsync(printItemWrapper, null).ContinueWith((task) =>
|
||||
Slicer.SliceFileAsync(printItemWrapper.FileLocation, printItemWrapper.GetGCodePathAndFileName(), null).ContinueWith((task) =>
|
||||
{
|
||||
Console.WriteLine("Part Slicing Completed");
|
||||
});
|
||||
|
|
@ -183,7 +183,7 @@ namespace MatterHackers.MatterControl.PrintQueue
|
|||
#if DEBUG
|
||||
if (instruction.movementType != PrinterMachineInstruction.MovementTypes.Absolute)
|
||||
{
|
||||
throw new Exception("radial funcitons can only execute absolute moves.");
|
||||
throw new Exception("Radial functions can only execute absolute moves.");
|
||||
}
|
||||
#endif
|
||||
Vector3 currentDestination = instruction.Position;
|
||||
|
|
|
|||
|
|
@ -259,8 +259,7 @@ namespace MatterHackers.MatterControl.PrintQueue
|
|||
string engineString = (0).ToString();
|
||||
|
||||
string gcodeFileName = this.FileHashCode.ToString() + "_" + engineString + "_" + ActiveSliceSettings.Instance.GetLongHashCode().ToString();
|
||||
string gcodePathAndFileName = Path.Combine(ApplicationDataStorage.Instance.GCodeOutputPath, gcodeFileName + ".gcode");
|
||||
return gcodePathAndFileName;
|
||||
return Path.Combine(ApplicationDataStorage.Instance.GCodeOutputPath, gcodeFileName + ".gcode");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -226,13 +226,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
return filePath;
|
||||
}
|
||||
|
||||
public static async Task SliceFileAsync(PrintItemWrapper printItem, IProgress<string> progressReporter)
|
||||
public static async Task SliceFileAsync(string partFilePath, string gcodeFilePath, IProgress<string> progressReporter)
|
||||
{
|
||||
string gcodeFilePath = printItem.GetGCodePathAndFileName();
|
||||
|
||||
await Task.Run(() => SliceFile(
|
||||
printItem.FileLocation,
|
||||
gcodeFilePath,
|
||||
partFilePath,
|
||||
gcodeFilePath,
|
||||
progressReporter));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 80de803ed4923a7c6aae1bc121f6ad3b72687060
|
||||
Subproject commit a28848a2104dd5534a36ec1598adb0c25789e2b8
|
||||
Loading…
Add table
Add a link
Reference in a new issue