2017-08-11 23:13:19 -07:00
|
|
|
|
/*
|
2018-12-05 13:25:28 -08:00
|
|
|
|
Copyright (c) 2018, Lars Brubaker, John Lewin
|
2017-08-11 23:13:19 -07:00
|
|
|
|
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 System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2018-01-05 12:44:57 -08:00
|
|
|
|
using MatterControl.Printing;
|
2018-02-13 16:02:18 -08:00
|
|
|
|
using MatterHackers.Agg;
|
2017-08-18 18:13:15 -07:00
|
|
|
|
using MatterHackers.Agg.Image;
|
2017-08-20 02:34:39 -07:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2017-08-11 23:13:19 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2018-02-12 14:52:47 -08:00
|
|
|
|
using MatterHackers.DataConverters3D;
|
2017-08-11 23:13:19 -07:00
|
|
|
|
using MatterHackers.Localizations;
|
2019-04-25 15:45:03 -07:00
|
|
|
|
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
|
2017-08-11 23:13:19 -07:00
|
|
|
|
using MatterHackers.MatterControl.PrinterCommunication.Io;
|
|
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2018-01-17 14:03:56 -08:00
|
|
|
|
using MatterHackers.VectorMath;
|
2017-08-11 23:13:19 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.Library.Export
|
|
|
|
|
|
{
|
2018-02-13 16:58:14 -08:00
|
|
|
|
public class GCodeExport : IExportPlugin, IExportWithOptions
|
2017-08-11 23:13:19 -07:00
|
|
|
|
{
|
2019-05-16 15:34:52 -07:00
|
|
|
|
private bool forceSpiralVase;
|
2018-12-05 13:21:09 -08:00
|
|
|
|
protected PrinterConfig printer;
|
2019-05-16 15:34:34 -07:00
|
|
|
|
private bool printerSetupRequired;
|
2018-02-13 18:11:01 -08:00
|
|
|
|
|
2018-12-05 13:21:09 -08:00
|
|
|
|
public virtual string ButtonText => "Machine File (G-Code)".Localize();
|
2017-08-11 23:13:19 -07:00
|
|
|
|
|
2018-12-05 13:21:09 -08:00
|
|
|
|
public virtual string FileExtension => ".gcode";
|
2017-08-11 23:13:19 -07:00
|
|
|
|
|
2018-12-05 13:21:09 -08:00
|
|
|
|
public virtual string ExtensionFilter => "Export GCode|*.gcode";
|
2017-08-11 23:13:19 -07:00
|
|
|
|
|
2018-12-05 13:21:09 -08:00
|
|
|
|
public virtual ImageBuffer Icon { get; } = AggContext.StaticData.LoadIcon(Path.Combine("filetypes", "gcode.png"));
|
2017-08-18 18:13:15 -07:00
|
|
|
|
|
2018-02-13 18:11:01 -08:00
|
|
|
|
public void Initialize(PrinterConfig printer)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.printer = printer;
|
2019-05-16 16:00:46 -07:00
|
|
|
|
printerSetupRequired = PrinterCalibrationWizard.SetupRequired(printer, requiresLoadedFilament: false);
|
2018-02-13 18:11:01 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-05 13:21:09 -08:00
|
|
|
|
public virtual bool Enabled
|
2017-08-11 23:13:19 -07:00
|
|
|
|
{
|
2018-12-05 17:48:32 -08:00
|
|
|
|
get => printer != null
|
|
|
|
|
|
&& printer.Settings.PrinterSelected
|
2018-11-29 17:35:08 -08:00
|
|
|
|
&& !printer.Settings.GetValue<bool>("enable_sailfish_communication")
|
2019-05-16 15:34:34 -07:00
|
|
|
|
&& !printerSetupRequired;
|
2018-11-29 17:35:08 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-05 13:25:09 -08:00
|
|
|
|
public virtual string DisabledReason
|
2018-11-29 17:35:08 -08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2019-05-14 18:20:02 -07:00
|
|
|
|
if (printer == null)
|
2018-12-05 17:48:32 -08:00
|
|
|
|
{
|
|
|
|
|
|
return "Create a printer to export G-Code".Localize();
|
|
|
|
|
|
}
|
2019-05-14 18:20:02 -07:00
|
|
|
|
else if (!printer.Settings.PrinterSelected)
|
2018-11-29 17:35:08 -08:00
|
|
|
|
{
|
|
|
|
|
|
return "No Printer Selected".Localize();
|
|
|
|
|
|
}
|
2019-05-16 15:34:34 -07:00
|
|
|
|
else if (printerSetupRequired)
|
2018-11-29 17:35:08 -08:00
|
|
|
|
{
|
|
|
|
|
|
return "Setup Needs to be Run".Localize();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
2017-08-11 23:13:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-05 13:21:09 -08:00
|
|
|
|
public virtual bool ExportPossible(ILibraryAsset libraryItem) => true;
|
2018-02-13 18:30:17 -08:00
|
|
|
|
|
2017-08-11 23:13:19 -07:00
|
|
|
|
public GuiWidget GetOptionsPanel()
|
|
|
|
|
|
{
|
2018-02-13 18:11:01 -08:00
|
|
|
|
var container = new FlowLayoutWidget()
|
2017-08-11 23:13:19 -07:00
|
|
|
|
{
|
2018-02-13 18:11:01 -08:00
|
|
|
|
Margin = new BorderDouble(left: 40, bottom: 10),
|
|
|
|
|
|
};
|
2017-08-11 23:13:19 -07:00
|
|
|
|
|
2018-11-03 09:13:07 -07:00
|
|
|
|
var theme = AppContext.Theme;
|
|
|
|
|
|
|
|
|
|
|
|
var spiralVaseCheckbox = new CheckBox("Spiral Vase".Localize(), theme.TextColor, 10)
|
2018-02-13 18:11:01 -08:00
|
|
|
|
{
|
|
|
|
|
|
Checked = false,
|
|
|
|
|
|
Cursor = Cursors.Hand,
|
|
|
|
|
|
};
|
|
|
|
|
|
spiralVaseCheckbox.CheckedStateChanged += (s, e) =>
|
|
|
|
|
|
{
|
2019-05-16 16:00:46 -07:00
|
|
|
|
forceSpiralVase = spiralVaseCheckbox.Checked;
|
2018-02-13 18:11:01 -08:00
|
|
|
|
};
|
|
|
|
|
|
container.AddChild(spiralVaseCheckbox);
|
|
|
|
|
|
|
|
|
|
|
|
// If print leveling is enabled then add in a check box 'Apply Leveling During Export' and default checked.
|
|
|
|
|
|
if (printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled))
|
|
|
|
|
|
{
|
2018-11-03 09:13:07 -07:00
|
|
|
|
var levelingCheckbox = new CheckBox("Apply leveling to G-Code during export".Localize(), theme.TextColor, 10)
|
2017-08-11 23:13:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
Checked = true,
|
|
|
|
|
|
Cursor = Cursors.Hand,
|
2018-02-13 18:11:01 -08:00
|
|
|
|
Margin = new BorderDouble(left: 10)
|
2017-08-11 23:13:19 -07:00
|
|
|
|
};
|
2018-02-13 18:11:01 -08:00
|
|
|
|
levelingCheckbox.CheckedStateChanged += (s, e) =>
|
2017-08-11 23:13:19 -07:00
|
|
|
|
{
|
2018-02-13 18:11:01 -08:00
|
|
|
|
this.ApplyLeveling = levelingCheckbox.Checked;
|
2017-08-11 23:13:19 -07:00
|
|
|
|
};
|
2018-02-13 18:11:01 -08:00
|
|
|
|
container.AddChild(levelingCheckbox);
|
2017-08-11 23:13:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-13 18:11:01 -08:00
|
|
|
|
return container;
|
2017-08-11 23:13:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-04 17:09:42 -08:00
|
|
|
|
public virtual async Task<List<ValidationError>> Generate(IEnumerable<ILibraryItem> libraryItems, string outputPath, IProgress<ProgressStatus> progress, CancellationToken cancellationToken)
|
2017-08-11 23:13:19 -07:00
|
|
|
|
{
|
2018-02-12 14:52:47 -08:00
|
|
|
|
var firstItem = libraryItems.OfType<ILibraryAsset>().FirstOrDefault();
|
|
|
|
|
|
if (firstItem != null)
|
2017-08-11 23:13:19 -07:00
|
|
|
|
{
|
2018-02-12 14:52:47 -08:00
|
|
|
|
IObject3D loadedItem = null;
|
2017-11-16 22:01:24 -08:00
|
|
|
|
|
2018-07-19 15:34:26 -07:00
|
|
|
|
var assetStream = firstItem as ILibraryAssetStream;
|
|
|
|
|
|
if (assetStream?.ContentType == "gcode")
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var gcodeStream = await assetStream.GetStream(progress: null))
|
|
|
|
|
|
{
|
|
|
|
|
|
this.ApplyStreamPipelineAndExport(
|
2018-11-12 15:02:47 -08:00
|
|
|
|
new GCodeFileStream(new GCodeFileStreamed(gcodeStream.Stream), printer),
|
2018-07-19 15:34:26 -07:00
|
|
|
|
outputPath);
|
|
|
|
|
|
|
2019-01-03 16:58:05 -08:00
|
|
|
|
return null;
|
2018-07-19 15:34:26 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (firstItem.AssetPath == printer.Bed.EditContext.SourceFilePath)
|
2017-08-11 23:13:19 -07:00
|
|
|
|
{
|
2018-02-12 14:52:47 -08:00
|
|
|
|
// If item is bedplate, save any pending changes before starting the print
|
2018-12-05 13:48:25 -08:00
|
|
|
|
await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer, printer.Bed.SaveChanges);
|
2018-02-12 14:52:47 -08:00
|
|
|
|
loadedItem = printer.Bed.Scene;
|
2018-09-07 10:25:29 -07:00
|
|
|
|
CenterOnBed = false;
|
2017-08-11 23:13:19 -07:00
|
|
|
|
}
|
2018-02-12 14:52:47 -08:00
|
|
|
|
else if (firstItem is ILibraryObject3D object3DItem)
|
2017-08-11 23:13:19 -07:00
|
|
|
|
{
|
2018-08-17 17:49:41 -07:00
|
|
|
|
var status = new ProgressStatus()
|
|
|
|
|
|
{
|
|
|
|
|
|
Status = "Saving Asset".Localize()
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-02-12 14:52:47 -08:00
|
|
|
|
loadedItem = await object3DItem.CreateContent(null);
|
2018-08-17 17:49:41 -07:00
|
|
|
|
await loadedItem.PersistAssets((percentComplete, text) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
status.Progress0To1 = percentComplete;
|
|
|
|
|
|
progress.Report(status);
|
|
|
|
|
|
}, publishAssets: false);
|
2017-08-11 23:13:19 -07:00
|
|
|
|
}
|
2018-07-19 15:34:26 -07:00
|
|
|
|
else if (assetStream != null)
|
2018-02-09 18:11:55 -08:00
|
|
|
|
{
|
2018-02-12 14:52:47 -08:00
|
|
|
|
loadedItem = await assetStream.CreateContent(null);
|
|
|
|
|
|
}
|
2017-08-11 23:13:19 -07:00
|
|
|
|
|
2018-02-12 14:52:47 -08:00
|
|
|
|
if (loadedItem != null)
|
2017-12-11 14:15:50 -08:00
|
|
|
|
{
|
2018-11-25 07:13:22 -08:00
|
|
|
|
// Ensure content is on disk before slicing
|
|
|
|
|
|
await loadedItem.PersistAssets(null);
|
2018-02-13 12:40:25 -08:00
|
|
|
|
|
2019-05-19 16:42:44 -07:00
|
|
|
|
string gcodePath = null;
|
|
|
|
|
|
|
2018-02-12 14:52:47 -08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
string sourceExtension = $".{firstItem.ContentType}";
|
2018-03-10 16:25:55 -08:00
|
|
|
|
string assetPath = await AssetObject3D.AssetManager.StoreMcx(loadedItem, false);
|
2018-02-12 14:52:47 -08:00
|
|
|
|
|
2019-01-24 08:24:18 -08:00
|
|
|
|
var errors = new List<ValidationError>();
|
2019-01-18 18:16:21 -08:00
|
|
|
|
|
2018-02-13 12:41:15 -08:00
|
|
|
|
if (ApplicationSettings.ValidFileExtensions.IndexOf(sourceExtension, StringComparison.OrdinalIgnoreCase) >= 0
|
2018-02-12 14:52:47 -08:00
|
|
|
|
|| string.Equals(sourceExtension, ".mcx", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
{
|
2018-09-07 10:25:29 -07:00
|
|
|
|
if (CenterOnBed)
|
2018-02-13 12:42:08 -08:00
|
|
|
|
{
|
|
|
|
|
|
// Get Bounds
|
|
|
|
|
|
var aabb = loadedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity);
|
|
|
|
|
|
|
|
|
|
|
|
// Move to bed center
|
|
|
|
|
|
var bedCenter = printer.Bed.BedCenter;
|
2019-05-16 16:00:46 -07:00
|
|
|
|
loadedItem.Matrix *= Matrix4X4.CreateTranslation(-aabb.Center.X, -aabb.Center.Y, -aabb.MinXYZ.Z) * Matrix4X4.CreateTranslation(bedCenter.X, bedCenter.Y, 0);
|
2018-02-13 12:42:08 -08:00
|
|
|
|
}
|
2018-02-12 14:52:47 -08:00
|
|
|
|
|
2018-02-13 18:11:01 -08:00
|
|
|
|
string originalSpiralVase = printer.Settings.GetValue(SettingsKey.spiral_vase);
|
|
|
|
|
|
|
2018-02-12 14:52:47 -08:00
|
|
|
|
// Slice
|
2018-02-13 18:11:01 -08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2019-05-16 16:00:46 -07:00
|
|
|
|
if (forceSpiralVase)
|
2018-02-13 18:11:01 -08:00
|
|
|
|
{
|
|
|
|
|
|
printer.Settings.SetValue(SettingsKey.spiral_vase, "1");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-30 08:19:29 -07:00
|
|
|
|
errors = printer.ValidateSettings(validatePrintBed: false);
|
2019-01-03 16:58:05 -08:00
|
|
|
|
|
2019-05-16 16:00:46 -07:00
|
|
|
|
if (errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Error))
|
2019-01-03 16:05:02 -08:00
|
|
|
|
{
|
2019-01-03 16:58:05 -08:00
|
|
|
|
return errors;
|
2019-01-03 16:05:02 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-19 16:42:44 -07:00
|
|
|
|
// This mush be calculated after the settings have been set (spiral vase)
|
|
|
|
|
|
// or it uses the wrong slice settings.
|
|
|
|
|
|
// TODO: Prior code bypassed GCodeOverridePath mechanisms in EditContext. Consolidating into a single pathway
|
|
|
|
|
|
gcodePath = printer.Bed.EditContext.GCodeFilePath(printer);
|
|
|
|
|
|
|
2018-08-17 17:49:41 -07:00
|
|
|
|
await ApplicationController.Instance.Tasks.Execute(
|
|
|
|
|
|
"Slicing Item".Localize() + " " + loadedItem.Name,
|
2018-12-05 13:48:25 -08:00
|
|
|
|
printer,
|
2018-08-17 17:49:41 -07:00
|
|
|
|
(reporter, cancellationToken2) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
return Slicer.SliceItem(loadedItem, gcodePath, printer, reporter, cancellationToken2);
|
|
|
|
|
|
});
|
2018-02-13 18:11:01 -08:00
|
|
|
|
}
|
|
|
|
|
|
finally
|
2018-02-12 14:52:47 -08:00
|
|
|
|
{
|
2019-05-16 16:00:46 -07:00
|
|
|
|
if (forceSpiralVase)
|
2018-02-13 18:11:01 -08:00
|
|
|
|
{
|
|
|
|
|
|
printer.Settings.SetValue(SettingsKey.spiral_vase, originalSpiralVase);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-02-12 14:52:47 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (File.Exists(gcodePath))
|
|
|
|
|
|
{
|
2018-07-19 13:25:34 -07:00
|
|
|
|
ApplyStreamPipelineAndExport(gcodePath, outputPath);
|
2019-01-18 18:16:21 -08:00
|
|
|
|
return errors;
|
2018-02-12 14:52:47 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2019-03-18 16:31:41 -07:00
|
|
|
|
|
|
|
|
|
|
return new List<ValidationError>();
|
2018-02-12 14:52:47 -08:00
|
|
|
|
}
|
2017-08-11 23:13:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-04 17:09:42 -08:00
|
|
|
|
return new List<ValidationError>
|
|
|
|
|
|
{
|
2019-03-08 16:43:25 -08:00
|
|
|
|
new ValidationError("ItemCannotBeExported")
|
2019-01-04 17:09:42 -08:00
|
|
|
|
{
|
|
|
|
|
|
Error = "Item cannot be exported".Localize(),
|
|
|
|
|
|
Details = firstItem?.ToString() ?? ""
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2017-08-11 23:13:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-11 08:58:43 -08:00
|
|
|
|
public bool ApplyLeveling { get; set; } = true;
|
2018-12-05 13:25:28 -08:00
|
|
|
|
|
2018-09-07 10:25:29 -07:00
|
|
|
|
public bool CenterOnBed { get; set; }
|
2017-08-11 23:13:19 -07:00
|
|
|
|
|
2018-12-20 16:00:27 -08:00
|
|
|
|
public static GCodeStream GetExportStream(PrinterConfig printer, GCodeStream gCodeBaseStream, bool applyLeveling)
|
2017-08-11 23:13:19 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
var queuedCommandStream = new QueuedCommandsStream(printer, gCodeBaseStream);
|
|
|
|
|
|
GCodeStream accumulatedStream = queuedCommandStream;
|
2018-12-20 16:00:27 -08:00
|
|
|
|
|
2019-03-31 10:01:52 -07:00
|
|
|
|
accumulatedStream = new RelativeToAbsoluteStream(printer, accumulatedStream);
|
|
|
|
|
|
|
2019-02-19 15:36:30 -08:00
|
|
|
|
if (printer.Settings.GetValue<int>(SettingsKey.extruder_count) > 1)
|
|
|
|
|
|
{
|
2019-04-26 11:52:05 -07:00
|
|
|
|
var gCodeFileStream = gCodeBaseStream as GCodeFileStream;
|
|
|
|
|
|
accumulatedStream = new ToolChangeStream(printer, accumulatedStream, queuedCommandStream, gCodeFileStream);
|
2019-04-09 13:34:16 -07:00
|
|
|
|
accumulatedStream = new ToolSpeedMultiplierStream(printer, accumulatedStream);
|
2019-02-19 15:36:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-14 15:35:21 -08:00
|
|
|
|
bool levelingEnabled = printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled) && applyLeveling;
|
|
|
|
|
|
|
2019-03-01 19:38:59 -08:00
|
|
|
|
accumulatedStream = new BabyStepsStream(printer, accumulatedStream);
|
|
|
|
|
|
|
2019-01-14 15:35:21 -08:00
|
|
|
|
if (levelingEnabled
|
|
|
|
|
|
&& printer.Settings.GetValue<bool>(SettingsKey.enable_line_splitting))
|
2018-12-20 16:00:27 -08:00
|
|
|
|
{
|
2019-03-01 19:38:59 -08:00
|
|
|
|
accumulatedStream = new MaxLengthStream(printer, accumulatedStream, 1);
|
2018-12-20 16:00:27 -08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2017-08-11 23:13:19 -07:00
|
|
|
|
{
|
2019-03-01 19:38:59 -08:00
|
|
|
|
accumulatedStream = new MaxLengthStream(printer, accumulatedStream, 1000);
|
2018-12-20 16:00:27 -08:00
|
|
|
|
}
|
2018-10-29 11:39:41 -07:00
|
|
|
|
|
2019-04-25 15:45:03 -07:00
|
|
|
|
if (levelingEnabled
|
|
|
|
|
|
&& !LevelingValidation.NeedsToBeRun(printer))
|
2018-12-20 16:00:27 -08:00
|
|
|
|
{
|
|
|
|
|
|
accumulatedStream = new PrintLevelingStream(printer, accumulatedStream, false);
|
|
|
|
|
|
}
|
2018-12-07 16:50:22 -08:00
|
|
|
|
|
2019-03-18 15:57:17 -07:00
|
|
|
|
if (printer.Settings.GetValue<bool>(SettingsKey.emulate_endstops))
|
|
|
|
|
|
{
|
|
|
|
|
|
var softwareEndstopsExStream12 = new SoftwareEndstopsStream(printer, accumulatedStream);
|
|
|
|
|
|
accumulatedStream = softwareEndstopsExStream12;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-31 10:01:52 -07:00
|
|
|
|
accumulatedStream = new RemoveNOPsStream(printer, accumulatedStream);
|
2018-10-29 11:39:41 -07:00
|
|
|
|
|
2019-04-09 11:02:34 -07:00
|
|
|
|
accumulatedStream = new ProcessWriteRegexStream(printer, accumulatedStream, queuedCommandStream);
|
|
|
|
|
|
|
2018-12-20 16:00:27 -08:00
|
|
|
|
return accumulatedStream;
|
|
|
|
|
|
}
|
2017-08-11 23:13:19 -07:00
|
|
|
|
|
2018-12-20 16:00:27 -08:00
|
|
|
|
private void ApplyStreamPipelineAndExport(GCodeFileStream gCodeFileStream, string outputPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var finalStream = GetExportStream(printer, gCodeFileStream, this.ApplyLeveling);
|
2018-11-16 14:22:53 -08:00
|
|
|
|
|
2018-07-19 13:25:34 -07:00
|
|
|
|
// Run each line from the source gcode through the loaded pipeline and dump to the output location
|
2018-02-13 16:15:58 -08:00
|
|
|
|
using (var file = new StreamWriter(outputPath))
|
2017-08-11 23:13:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
string nextLine = finalStream.ReadLine();
|
|
|
|
|
|
while (nextLine != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (nextLine.Trim().Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
file.WriteLine(nextLine);
|
|
|
|
|
|
}
|
2018-07-19 13:22:37 -07:00
|
|
|
|
|
2017-08-11 23:13:19 -07:00
|
|
|
|
nextLine = finalStream.ReadLine();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
2017-10-18 19:54:06 -07:00
|
|
|
|
StyledMessageBox.ShowMessageBox(e.Message, "Couldn't save file".Localize());
|
2017-08-11 23:13:19 -07:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-07-19 15:29:16 -07:00
|
|
|
|
|
|
|
|
|
|
private void ApplyStreamPipelineAndExport(string gcodeFilename, string outputPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2019-05-16 16:00:46 -07:00
|
|
|
|
var settings = printer.Settings;
|
2019-03-06 13:44:33 -08:00
|
|
|
|
var maxAcceleration = settings.GetValue<double>(SettingsKey.max_acceleration);
|
|
|
|
|
|
var maxVelocity = settings.GetValue<double>(SettingsKey.max_velocity);
|
|
|
|
|
|
var jerkVelocity = settings.GetValue<double>(SettingsKey.jerk_velocity);
|
|
|
|
|
|
var multiplier = settings.GetValue<double>(SettingsKey.print_time_estimate_multiplier) / 100.0;
|
|
|
|
|
|
|
2018-07-19 15:29:16 -07:00
|
|
|
|
this.ApplyStreamPipelineAndExport(
|
|
|
|
|
|
new GCodeFileStream(
|
|
|
|
|
|
GCodeFile.Load(
|
2019-03-23 18:37:53 -07:00
|
|
|
|
new StreamReader(gcodeFilename).BaseStream,
|
2019-03-06 13:44:33 -08:00
|
|
|
|
new Vector4(maxAcceleration, maxAcceleration, maxAcceleration, maxAcceleration),
|
|
|
|
|
|
new Vector4(maxVelocity, maxVelocity, maxVelocity, maxVelocity),
|
|
|
|
|
|
new Vector4(jerkVelocity, jerkVelocity, jerkVelocity, jerkVelocity),
|
|
|
|
|
|
new Vector4(multiplier, multiplier, multiplier, multiplier),
|
|
|
|
|
|
CancellationToken.None),
|
|
|
|
|
|
printer),
|
2018-07-19 15:29:16 -07:00
|
|
|
|
outputPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
StyledMessageBox.ShowMessageBox(e.Message, "Couldn't load file".Localize());
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-08-11 23:13:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|