Merge pull request #3992 from larsbrubaker/master

remove active printer from PrintItemWrapper
This commit is contained in:
Lars Brubaker 2018-11-14 14:43:37 -08:00 committed by GitHub
commit 7bcbc53227
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 61 additions and 41 deletions

View file

@ -65,7 +65,6 @@ namespace MatterHackers.MatterControl
// Add in all the stl and amf files referenced in the library.
foreach (PrintItem printItem in allPrintItems)
{
var printItemWrapper = new PrintItemWrapper(printItem);
if (!filesToKeep.Contains(printItem.FileLocation))
{
filesToKeep.Add(printItem.FileLocation);

View file

@ -2035,7 +2035,7 @@ namespace MatterHackers.MatterControl
public async Task PrintPart(EditContext editContext, PrinterConfig printer, IProgress<ProgressStatus> reporter, CancellationToken cancellationToken, bool overrideAllowGCode = false)
{
var partFilePath = editContext.SourceFilePath;
var gcodeFilePath = editContext.GCodeFilePath;
var gcodeFilePath = editContext.GCodeFilePath(printer);
var printItemName = editContext.SourceItem.Name;
// Exit if called in a non-applicable state

View file

@ -286,11 +286,11 @@ namespace MatterHackers.MatterControl
internal void EnsureGCodeLoaded()
{
if (this.LoadedGCode == null
&& File.Exists(this.EditContext?.GCodeFilePath))
&& File.Exists(this.EditContext?.GCodeFilePath(this.Printer)))
{
UiThread.RunOnIdle(async () =>
{
using (var stream = File.OpenRead(this.EditContext.GCodeFilePath))
using (var stream = File.OpenRead(this.EditContext.GCodeFilePath(this.Printer)))
{
await LoadGCodeContent(stream);
}

View file

@ -62,13 +62,31 @@ namespace MatterHackers.MatterControl
}
// Natural path
private string gcodePath => printItem?.GetGCodePathAndFileName();
private string GCodePath(PrinterConfig printer)
{
if (printItem != null)
{
return printer.GetGCodePathAndFileName(printItem.FileLocation);
}
return null;
}
// Override path
public string GCodeOverridePath => Path.ChangeExtension(gcodePath, GCodeFile.PostProcessedExtension);
public string GCodeOverridePath(PrinterConfig printer)
{
return Path.ChangeExtension(GCodePath(printer), GCodeFile.PostProcessedExtension);
}
// Override or natural path
public string GCodeFilePath => (File.Exists(this.GCodeOverridePath)) ? this.GCodeOverridePath : gcodePath;
public string GCodeFilePath(PrinterConfig printer)
{
if (File.Exists(this.GCodeOverridePath(printer)))
{
return this.GCodeOverridePath(printer);
}
return GCodePath(printer);
}
public string SourceFilePath => printItem?.FileLocation;

View file

@ -34,9 +34,11 @@ using MatterHackers.MatterControl.SlicerConfiguration;
namespace MatterHackers.MatterControl
{
using System.IO;
using System.Threading;
using MatterHackers.Agg;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.SlicerConfiguration.MappingClasses;
using MatterHackers.MeshVisualizer;
@ -127,7 +129,6 @@ namespace MatterHackers.MatterControl
this.Connection.PrintFinished += PrintFinished;
this.Disposed += (s, e) => this.Connection.PrintFinished -= PrintFinished;
if (!string.IsNullOrEmpty(this.Settings.GetValue(SettingsKey.baud_rate)))
{
this.Connection.BaudRate = this.Settings.GetValue<int>(SettingsKey.baud_rate);
@ -142,6 +143,32 @@ namespace MatterHackers.MatterControl
this.Connection.ReadLineReplacementString = this.Settings.GetValue(SettingsKey.read_regex);
}
public string GetGCodePathAndFileName(string fileLocation)
{
if (fileLocation.Trim() != "")
{
if (Path.GetExtension(fileLocation).ToUpper() == ".GCODE")
{
return fileLocation;
}
return GCodePath(fileLocation);
}
else
{
return null;
}
}
public string GCodePath(string fileHashCode)
{
long settingsHashCode = this.Settings.GetLongHashCode();
return Path.Combine(
ApplicationDataStorage.Instance.GCodeOutputPath,
$"{fileHashCode}_{ settingsHashCode}.gcode");
}
public string ReplaceMacroValues(string gcodeWithMacros)
{
foreach (MappedSetting mappedSetting in replaceWithSettingsStrings)
@ -278,7 +305,6 @@ namespace MatterHackers.MatterControl
this.Connection.CommunicationStateChanged += CommunicationStateChanged;
this.Disposed += (s, e) => this.Connection.CommunicationStateChanged -= CommunicationStateChanged;
void Printer_SettingChanged(object s, EventArgs e)
{
if (e is StringEventArgs stringArg

View file

@ -173,7 +173,7 @@ namespace MatterHackers.MatterControl.Library.Export
string fileHashCode = Path.GetFileNameWithoutExtension(assetPath);
string gcodePath = PrintItemWrapper.GCodePath(fileHashCode);
string gcodePath = printer.GCodePath(fileHashCode);
if (ApplicationSettings.ValidFileExtensions.IndexOf(sourceExtension, StringComparison.OrdinalIgnoreCase) >= 0
|| string.Equals(sourceExtension, ".mcx", StringComparison.OrdinalIgnoreCase))

View file

@ -536,7 +536,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
activelySlicing = true;
if (bottomRow.Name == null)
{
bottomRow.Name = printer.Bed.EditContext.GCodeFilePath;
bottomRow.Name = printer.Bed.EditContext.GCodeFilePath(printer);
}
await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer.Bed.SaveChanges);
@ -545,7 +545,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
await ApplicationController.Instance.SliceItemLoadOutput(
printer,
printer.Bed.Scene,
printer.Bed.EditContext.GCodeFilePath);
printer.Bed.EditContext.GCodeFilePath(printer));
// Switch to the 3D layer view if on Model view
if (printer.ViewState.ViewMode == PartViewMode.Model)
@ -563,8 +563,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
if (printer.Connection != null
&& (printer.Connection.PrinterIsPrinting || printer.Connection.PrinterIsPaused))
{
printer.Connection.SwitchToGCode(printer.Bed.EditContext.GCodeFilePath);
bottomRow.Name = printer.Bed.EditContext.GCodeFilePath;
printer.Connection.SwitchToGCode(printer.Bed.EditContext.GCodeFilePath(printer));
bottomRow.Name = printer.Bed.EditContext.GCodeFilePath(printer);
}
}
else

View file

@ -110,7 +110,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
await ApplicationController.Instance.SliceItemLoadOutput(
printer,
printer.Bed.Scene,
printer.Bed.EditContext.GCodeFilePath);
printer.Bed.EditContext.GCodeFilePath(printer));
}
catch (Exception ex)
{

View file

@ -69,9 +69,11 @@ namespace MatterHackers.MatterControl.PrintQueue
public class PrintItemWrapper
{
private string fileType;
PrinterConfig printer;
public PrintItemWrapper(PrintItem printItem, ILibraryContainer sourceLibraryProviderLocator = null)
{
this.printer = printer;
this.PrintItem = printItem;
if (FileLocation != null)
@ -84,6 +86,7 @@ namespace MatterHackers.MatterControl.PrintQueue
public PrintItemWrapper(int printItemId)
{
this.printer = printer;
this.PrintItem = Datastore.Instance.dbSQLite.Table<PrintItem>().Where(v => v.Id == printItemId).Take(1).FirstOrDefault();
try
{
@ -138,31 +141,5 @@ namespace MatterHackers.MatterControl.PrintQueue
// result in inserts rather than update statements on a missing row
this.PrintItem.Id = 0;
}
public string GetGCodePathAndFileName()
{
if (FileLocation.Trim() != "")
{
if (Path.GetExtension(FileLocation).ToUpper() == ".GCODE")
{
return FileLocation;
}
return GCodePath(this.FileHashCode);
}
else
{
return null;
}
}
public static string GCodePath(string fileHashCode)
{
long settingsHashCode = ApplicationController.Instance.ActivePrinter.Settings.GetLongHashCode();
return Path.Combine(
ApplicationDataStorage.Instance.GCodeOutputPath,
$"{fileHashCode}_{ settingsHashCode}.gcode");
}
}
}