Moved extruder offsets from passing to MS to being part of stream processing

Made '; NO_PROCESSING' track printer position correctly
issue: MatterHackers/MCCentral#4658
Create setting for ZOffset for extruder 2
This commit is contained in:
Lars Brubaker 2018-12-04 13:28:38 -08:00
parent 8b6ea26d35
commit 1a434b6388
17 changed files with 68 additions and 205 deletions

View file

@ -36,19 +36,6 @@ namespace MatterHackers.GCodeVisualizer
{
public class GCodeRenderInfo
{
public Vector3[] extruderOffsets;
public Vector3 GetExtruderOffset(int index)
{
if (extruderOffsets != null
&& extruderOffsets.Length > index)
{
return extruderOffsets[index];
}
return Vector3.Zero;
}
public Func<int, Color> GetMaterialColor { get; }
public int StartLayerIndex { get; set; }
@ -74,7 +61,6 @@ namespace MatterHackers.GCodeVisualizer
public GCodeRenderInfo(int startLayerIndex, int endLayerIndex,
Affine transform, double layerScale,
double featureToStartOnRatio0To1, double featureToEndOnRatio0To1,
Vector3[] extruderOffsets,
Func<RenderType> getRenderType,
Func<int, Color> getMaterialColor)
{
@ -92,7 +78,6 @@ namespace MatterHackers.GCodeVisualizer
this.FeatureToStartOnRatio0To1 = featureToStartOnRatio0To1;
this.FeatureToEndOnRatio0To1 = featureToEndOnRatio0To1;
this.extruderOffsets = extruderOffsets;
}
public void RefreshRenderType()

View file

@ -46,7 +46,6 @@ namespace MatterHackers.GCodeVisualizer
Retractions = 4,
SpeedColors = 8,
SimulateExtrusion = 16,
HideExtruderOffsets = 32,
TransparentExtrusion = 64,
GrayColors = 128
};

View file

@ -68,12 +68,6 @@ namespace MatterHackers.GCodeVisualizer
{
Vector3 position = new Vector3(this.position);
if (renderInfo.CurrentRenderType.HasFlag(RenderType.HideExtruderOffsets))
{
Vector3 offset = renderInfo.GetExtruderOffset(extruderIndex);
position = position + offset;
}
// retract and unretract are the extruder color
Color color = renderInfo.GetMaterialColor(extruderIndex);
// except for extruder 0 where they are the red and blue we are familiar with
@ -108,12 +102,6 @@ namespace MatterHackers.GCodeVisualizer
double radius = Radius(renderInfo.LayerScale);
Vector2 position = new Vector2(this.position.x, this.position.y);
if (renderInfo.CurrentRenderType.HasFlag(RenderType.HideExtruderOffsets))
{
Vector3 offset = renderInfo.GetExtruderOffset(extruderIndex);
position = position + new Vector2(offset);
}
renderInfo.Transform.transform(ref position);
Color retractionColor = new Color(Color.Red, 200);

View file

@ -42,31 +42,11 @@ namespace MatterHackers.GCodeVisualizer
protected Vector3Float GetStart(GCodeRenderInfo renderInfo)
{
if (renderInfo.CurrentRenderType.HasFlag(RenderType.HideExtruderOffsets))
{
Vector3Float start = this.start;
Vector3 offset = renderInfo.GetExtruderOffset(extruderIndex);
start.x += (float)offset.X;
start.y += (float)offset.Y;
start.z += (float)offset.Z;
return start;
}
return this.start;
}
protected Vector3Float GetEnd(GCodeRenderInfo renderInfo)
{
if (renderInfo.CurrentRenderType.HasFlag(RenderType.HideExtruderOffsets))
{
Vector3Float end = this.end;
Vector3 offset = renderInfo.GetExtruderOffset(extruderIndex);
end.x += (float)offset.X;
end.y += (float)offset.Y;
end.z += (float)offset.Z;
return end;
}
return this.end;
}

View file

@ -481,10 +481,6 @@ namespace MatterHackers.MatterControl
{
renderType |= RenderType.TransparentExtrusion;
}
if (options.HideExtruderOffsets)
{
renderType |= RenderType.HideExtruderOffsets;
}
return renderType;
}
@ -517,11 +513,6 @@ namespace MatterHackers.MatterControl
1,
0,
1,
new Vector3[]
{
settings.Helpers.ExtruderOffset(0),
settings.Helpers.ExtruderOffset(1)
},
this.GetRenderType,
MeshViewerWidget.GetExtruderColor);

View file

@ -144,28 +144,6 @@ namespace MatterHackers.MatterControl
}
}
public bool HideExtruderOffsets
{
get
{
string value = UserSettings.Instance.get(UserSettingsKey.GcodeViewerHideExtruderOffsets);
if (value == null)
{
return true;
}
return (value == "True");
}
set
{
if (this.HideExtruderOffsets != value)
{
UserSettings.Instance.set(UserSettingsKey.GcodeViewerHideExtruderOffsets, value.ToString());
this.IsDirty = true;
this.OnPropertyChanged(nameof(HideExtruderOffsets));
}
}
}
public bool SyncToPrint
{
get => UserSettings.Instance.get(UserSettingsKey.LayerViewSyncToPrint) == "True";

View file

@ -251,13 +251,17 @@ namespace MatterHackers.MatterControl.Library.Export
var queueStream = new QueuedCommandsStream(printer, gCodeFileStream);
GCodeStream accumulatedStream = queueStream;
if(printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled) && this.ApplyLeveling)
if (printer.Settings.GetValue<bool>(SettingsKey.enable_line_splitting))
{
if (printer.Settings.GetValue<bool>(SettingsKey.enable_line_splitting))
{
accumulatedStream = new BabyStepsStream(printer, accumulatedStream, 1);
}
accumulatedStream = new BabyStepsStream(printer, accumulatedStream, 1);
}
else
{
accumulatedStream = new BabyStepsStream(printer, accumulatedStream, 1000);
}
if (printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled) && this.ApplyLeveling)
{
accumulatedStream = new PrintLevelingStream(printer, accumulatedStream, false);
}

View file

@ -161,7 +161,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
layerScale,
options.FeatureToStartOnRatio0To1,
options.FeatureToEndOnRatio0To1,
options.extruderOffsets,
options.GetRenderType,
options.GetMaterialColor);

View file

@ -95,22 +95,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
firstSection.BorderColor = Color.Transparent; // Disable top border on first item to produce a more flat, dark top edge
// Register listeners
printer.Settings.SettingChanged += Printer_SettingChanged;
printer.Bed.LoadedGCodeChanged += Bed_LoadedGCodeChanged;
printer.Bed.RendererOptions.PropertyChanged += RendererOptions_PropertyChanged;
}
private void Printer_SettingChanged(object s, EventArgs e)
{
if (e is StringEventArgs stringEvent)
{
if (stringEvent.Data == SettingsKey.extruder_offset)
{
printer.Bed.GCodeRenderer?.Clear3DGCode();
}
}
}
private void RefreshGCodeDetails(PrinterConfig printer)
{
loadedGCodeSection.CloseAllChildren();
@ -215,7 +203,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public override void OnClosed(EventArgs e)
{
// Unregister listeners
printer.Settings.SettingChanged -= Printer_SettingChanged;
printer.Bed.RendererOptions.PropertyChanged -= RendererOptions_PropertyChanged;
printer.Bed.LoadedGCodeChanged -= Bed_LoadedGCodeChanged;

View file

@ -132,11 +132,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
"Transparent".Localize(),
() => gcodeOptions.TransparentExtrusion,
(value) => gcodeOptions.TransparentExtrusion = value),
new BoolOption(
"Hide Offsets".Localize(),
() => gcodeOptions.HideExtruderOffsets,
(value) => gcodeOptions.HideExtruderOffsets = value,
() => printer.Settings.GetValue<int>(SettingsKey.extruder_count) > 1),
new BoolOption(
"Sync To Print".Localize(),
() => gcodeOptions.SyncToPrint,

View file

@ -28,8 +28,10 @@ either expressed or implied, of the FreeBSD Project.
*/
using MatterControl.Printing;
using MatterHackers.Agg;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.VectorMath;
using System;
namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
@ -38,20 +40,56 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private int extruderIndex = 0;
private PrinterMove lastDestination = new PrinterMove();
Vector3[] extruderOffsets = new Vector3[4];
public OffsetStream(GCodeStream internalStream, PrinterConfig printer, Vector3 offset)
: base(printer, internalStream)
{
this.Offset = offset;
printer.Settings.SettingChanged += Settings_SettingChanged;
extruderIndex = printer.Connection.ActiveExtruderIndex;
ReadExtruderOffsets();
}
private void Settings_SettingChanged(object sender, EventArgs e)
{
if (e is StringEventArgs stringEvent)
{
// if the offsets change update them (unless we are actively printing)
if (stringEvent.Data == SettingsKey.extruder_offset
&& !printer.Connection.PrinterIsPrinting
&& !printer.Connection.PrinterIsPaused)
{
ReadExtruderOffsets();
}
}
}
private void ReadExtruderOffsets()
{
for (int i = 0; i < 4; i++)
{
extruderOffsets[i] = printer.Settings.Helpers.ExtruderOffset(i);
}
}
public override void Dispose()
{
printer.Settings.SettingChanged -= Settings_SettingChanged;
base.Dispose();
}
public override void SetPrinterPosition(PrinterMove position)
{
lastDestination = position;
lastDestination.position -= Offset;
if(extruderIndex == 1)
if (extruderIndex < 4)
{
var offset = printer.Settings.Helpers.ExtruderOffset(1);
lastDestination.position.Z -= offset.Z;
lastDestination.position += extruderOffsets[extruderIndex];
}
internalStream.SetPrinterPosition(lastDestination);
}
@ -72,10 +110,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
&& lineToSend.StartsWith("T"))
{
int extruder = 0;
if(GCodeFile.GetFirstNumberAfter("T", lineToSend, ref extruder))
if (GCodeFile.GetFirstNumberAfter("T", lineToSend, ref extruder))
{
extruderIndex = extruder;
// correct where we think the extruder is
}
}
@ -86,10 +123,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
PrinterMove moveToSend = currentMove;
moveToSend.position += Offset;
if (extruderIndex == 1)
if (extruderIndex < 4)
{
var offset = printer.Settings.Helpers.ExtruderOffset(1);
moveToSend.position.Z += offset.Z;
moveToSend.position -= extruderOffsets[extruderIndex];
}
lineToSend = CreateMovementLine(moveToSend, lastDestination);

View file

@ -154,7 +154,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
private double actualBedTemperature;
private int currentlyActiveExtruderIndex = 0;
public int ActiveExtruderIndex { get; private set; }
private double[] actualHotendTemperature = new double[MAX_EXTRUDERS];
@ -323,7 +323,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
double extruderBeingSet = 0;
if (GCodeFile.GetFirstNumberAfter("T", line, ref extruderBeingSet))
{
currentlyActiveExtruderIndex = (int)extruderBeingSet;
ActiveExtruderIndex = (int)extruderBeingSet;
}
}
@ -1081,7 +1081,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
else
{
// we set the private variable so that we don't get the callbacks called and get in a loop of setting the temp
targetHotendTemperature[currentlyActiveExtruderIndex] = tempBeingSet;
targetHotendTemperature[ActiveExtruderIndex] = tempBeingSet;
}
}
}
@ -2339,6 +2339,12 @@ namespace MatterHackers.MatterControl.PrinterCommunication
if (currentSentLine != null)
{
if (currentSentLine.EndsWith("; NO_PROCESSING"))
{
// make sure our processing pipe knows the translated position after a NO_PROCESSING
ReadPosition(true);
}
if (currentSentLine.Contains("M114")
&& this.IsConnected)
{

View file

@ -30,7 +30,6 @@ namespace MatterHackers.MatterControl
public const string FavoritesBarExpansion= nameof(FavoritesBarExpansion);
public const string GCodeLineColorStyle = nameof(GCodeLineColorStyle);
public const string GcodeModelView = nameof(GcodeModelView);
public const string GcodeViewerHideExtruderOffsets = nameof(GcodeViewerHideExtruderOffsets);
public const string GcodeViewerRenderGrid = nameof(GcodeViewerRenderGrid);
public const string GcodeViewerRenderMoves = nameof(GcodeViewerRenderMoves);
public const string GcodeViewerRenderRetractions = nameof(GcodeViewerRenderRetractions);

View file

@ -96,6 +96,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
SettingsKey.make,
SettingsKey.model,
SettingsKey.number_of_first_layers,
SettingsKey.extruder_offset,
SettingsKey.pause_gcode,
SettingsKey.print_center,
SettingsKey.print_leveling_probe_start,
@ -149,7 +150,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
new OverrideSpeedOnSlaPrinters(printer, SettingsKey.top_solid_infill_speed, "topInfillSpeed", "infill_speed"),
new AsPercentOfReferenceOrDirect(printer, SettingsKey.first_layer_extrusion_width, "firstLayerExtrusionWidth", SettingsKey.nozzle_diameter),
new AsPercentOfReferenceOrDirect(printer, SettingsKey.first_layer_height, "firstLayerThickness", SettingsKey.layer_height),
new ExtruderOffsets(printer, SettingsKey.extruder_offset, "extruderOffsets"),
new GCodeForSlicer(printer, SettingsKey.end_gcode, "endCode"),
new GCodeForSlicer(printer, "before_toolchange_gcode", "beforeToolchangeCode"),
new GCodeForSlicer(printer, "toolchange_gcode", "toolChangeCode"),

View file

@ -1,84 +0,0 @@
/*
Copyright (c) 2016, Lars Brubaker
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.Text;
namespace MatterHackers.MatterControl.SlicerConfiguration.MappingClasses
{
public class ExtruderOffsets : MappedSetting
{
public ExtruderOffsets(PrinterConfig printer, string canonicalSettingsName, string exportedName)
: base(printer, canonicalSettingsName, exportedName)
{
}
public override string Value
{
get
{
// map from 0x0,0x0,0x0
// to [[0,0],[0,0]]
StringBuilder final = new StringBuilder("[");
string[] offsets = base.Value.Split(',');
bool first = true;
int count = 0;
foreach (string offset in offsets)
{
if (!first)
{
final.Append(",");
}
string[] xy = offset.Split('x');
if (xy.Length == 2 || xy.Length == 3)
{
double x = 0;
double.TryParse(xy[0], out x);
double y = 0;
double.TryParse(xy[1], out y);
final.Append($"[{x},{y}]");
first = false;
count++;
}
else
{
final.Append("[0,0]");
}
}
while (count < 16)
{
final.Append(",[0,0]");
count++;
}
final.Append("]");
return final.ToString();
}
}
}
}

View file

@ -1670,7 +1670,7 @@
{
"SlicerConfigName": "before_toolchange_gcode",
"PresentationName": "Before Tool Change G-Code",
"HelpText": "G-Code to be run before every tool change. You can use [wipe_tower_x] [wipe_tower_y] & [wipe_tower_z] to set the extruder position if needed.",
"HelpText": "G-Code to be run before every tool change. You can use [wipe_tower_x] [wipe_tower_y] & [wipe_tower_z] to set the extruder position if needed. You can also use '; WRITE_RAW' to skip checksums or '; NO_PROCESSING' to skip position offseting.",
"DataEditType": "MULTI_LINE_TEXT",
"ShowIfSet": "!sla_printer&extruder_count>1",
"DefaultValue": ""
@ -1678,7 +1678,7 @@
{
"SlicerConfigName": "toolchange_gcode",
"PresentationName": "After Tool Change G-Code",
"HelpText": "G-Code to be run after every tool change. You can use [wipe_tower_x] [wipe_tower_y] & [wipe_tower_z] to set the extruder position if needed.",
"HelpText": "G-Code to be run after every tool change. You can use [wipe_tower_x] [wipe_tower_y] & [wipe_tower_z] to set the extruder position if needed. You can also use '; WRITE_RAW' to skip checksums or '; NO_PROCESSING' to skip position offseting.",
"ShowIfSet": "!sla_printer&extruder_count>1",
"DataEditType": "MULTI_LINE_TEXT",
"DefaultValue": ""
@ -1686,7 +1686,7 @@
{
"SlicerConfigName": "before_toolchange_gcode_1",
"PresentationName": "Before Tool Change G-Code 2",
"HelpText": "G-Code to be run before switching to extruder 2. Will use standard before G-Code if not set. You can use [wipe_tower_x] [wipe_tower_y] & [wipe_tower_z] to set the extruder position if needed.",
"HelpText": "G-Code to be run before switching to extruder 2. Will use standard before G-Code if not set. You can use [wipe_tower_x] [wipe_tower_y] & [wipe_tower_z] to set the extruder position if needed. You can also use '; WRITE_RAW' to skip checksums or '; NO_PROCESSING' to skip position offseting.",
"DataEditType": "MULTI_LINE_TEXT",
"ShowIfSet": "!sla_printer&extruder_count>1",
"DefaultValue": ""
@ -1694,7 +1694,7 @@
{
"SlicerConfigName": "toolchange_gcode_1",
"PresentationName": "After Tool Change G-Code 2",
"HelpText": "G-Code to be run after switching to extruder 2. Will use standard after G-Code if not set. You can use [wipe_tower_x] [wipe_tower_y] & [wipe_tower_z] to set the extruder position if needed.",
"HelpText": "G-Code to be run after switching to extruder 2. Will use standard after G-Code if not set. You can use [wipe_tower_x] [wipe_tower_y] & [wipe_tower_z] to set the extruder position if needed. You can also use '; WRITE_RAW' to skip checksums or '; NO_PROCESSING' to skip position offseting.",
"ShowIfSet": "!sla_printer&extruder_count>1",
"DataEditType": "MULTI_LINE_TEXT",
"DefaultValue": ""

@ -1 +1 @@
Subproject commit d622147cca7e624c572d80750ea59809c95e1496
Subproject commit 3b0f4710bf8f500d8bc803b2d4bea6c84a3dcd7a