From 563bd1a3e757ba9a8388e3796b17c591844bde63 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Wed, 13 Feb 2019 15:45:33 -0800 Subject: [PATCH 01/13] making sure we don't re-enter this.OnInvalidate unless explicitly for properties issue: MatterHackers/MCCentral#4965 Rebuild should directly call base.OnInvalidate to prevent re-entering this.OnInvalidate --- .../DesignTools/Braille/BrailleCardObject3D.cs | 2 +- MatterControlLib/DesignTools/Braille/BrailleObject3D.cs | 2 +- MatterControlLib/DesignTools/LithophaneObject3D.cs | 8 ++++---- MatterControlLib/DesignTools/Obsolete/CombineObject3D.cs | 2 +- MatterControlLib/DesignTools/Obsolete/CurveObject3D.cs | 2 +- .../DesignTools/Obsolete/FitToBoundsObject3D.cs | 6 +++--- .../DesignTools/Obsolete/IntersectionObject3D.cs | 2 +- MatterControlLib/DesignTools/Obsolete/MirrorObject3D.cs | 8 ++++---- MatterControlLib/DesignTools/Obsolete/PinchObject3D.cs | 8 ++++---- MatterControlLib/DesignTools/Obsolete/RotateObject3D.cs | 2 +- MatterControlLib/DesignTools/Operations/AlignObject3D.cs | 2 +- .../DesignTools/Operations/ArrayAdvancedObject3D.cs | 2 +- .../DesignTools/Operations/ArrayLinearObject3D.cs | 2 +- .../DesignTools/Operations/ArrayRadialObject3D.cs | 2 +- .../DesignTools/Operations/CurveObject3D_2.cs | 2 +- .../DesignTools/Operations/FitToBoundsObject3D_2.cs | 2 +- .../DesignTools/Operations/FitToCylinderObject3D.cs | 2 +- .../Operations/Image/LinearExtrudeObject3D.cs | 2 +- .../DesignTools/Operations/MirrorObject3D_2.cs | 2 +- .../DesignTools/Operations/Path/InflatePathObject3D.cs | 9 ++++----- .../DesignTools/Operations/Path/SmoothPathObject3D.cs | 2 +- .../DesignTools/Operations/RotateObject3D_2.cs | 2 +- MatterControlLib/DesignTools/Operations/ScaleObject3D.cs | 2 +- .../DesignTools/Operations/TranslateObject3D.cs | 8 ++++---- MatterControlLib/DesignTools/Primitives/ImageObject3D.cs | 2 +- .../View3D/Actions/CombineObject3D_2.cs | 2 +- .../View3D/Actions/IntersectionObject3D_2.cs | 2 +- .../View3D/Actions/SubtractAndReplaceObject3D.cs | 2 +- .../View3D/Actions/SubtractAndReplaceObject3D_2.cs | 2 +- .../PartPreviewWindow/View3D/Actions/SubtractObject3D.cs | 2 +- .../View3D/Actions/SubtractObject3D_2.cs | 2 +- 31 files changed, 48 insertions(+), 49 deletions(-) diff --git a/MatterControlLib/DesignTools/Braille/BrailleCardObject3D.cs b/MatterControlLib/DesignTools/Braille/BrailleCardObject3D.cs index 5f39d3fde..0b1300200 100644 --- a/MatterControlLib/DesignTools/Braille/BrailleCardObject3D.cs +++ b/MatterControlLib/DesignTools/Braille/BrailleCardObject3D.cs @@ -131,7 +131,7 @@ namespace MatterHackers.MatterControl.DesignTools } } - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); } } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/Braille/BrailleObject3D.cs b/MatterControlLib/DesignTools/Braille/BrailleObject3D.cs index 87c1a7a00..51240f769 100644 --- a/MatterControlLib/DesignTools/Braille/BrailleObject3D.cs +++ b/MatterControlLib/DesignTools/Braille/BrailleObject3D.cs @@ -261,7 +261,7 @@ namespace MatterHackers.MatterControl.DesignTools } } - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; } } diff --git a/MatterControlLib/DesignTools/LithophaneObject3D.cs b/MatterControlLib/DesignTools/LithophaneObject3D.cs index 9bf088b75..8ef259acd 100644 --- a/MatterControlLib/DesignTools/LithophaneObject3D.cs +++ b/MatterControlLib/DesignTools/LithophaneObject3D.cs @@ -65,7 +65,7 @@ namespace MatterHackers.MatterControl.Plugins.Lithophane public Vector3 ImageOffset { get; private set; } = Vector3.Zero; - public override void OnInvalidate(InvalidateArgs invalidateArgs) + public override async void OnInvalidate(InvalidateArgs invalidateArgs) { var invalidateType = invalidateArgs.InvalidateType; if ((invalidateType.HasFlag(InvalidateType.Children) @@ -74,12 +74,12 @@ namespace MatterHackers.MatterControl.Plugins.Lithophane && invalidateArgs.Source != this && !RebuildLocked) { - Rebuild(); + await Rebuild(); } else if (invalidateArgs.InvalidateType.HasFlag(InvalidateType.Properties) && invalidateArgs.Source == this) { - Rebuild(); + await Rebuild(); } else { @@ -114,7 +114,7 @@ namespace MatterHackers.MatterControl.Plugins.Lithophane // Apply offset this.Matrix *= Matrix4X4.CreateTranslation(-this.ImageOffset); - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; }); diff --git a/MatterControlLib/DesignTools/Obsolete/CombineObject3D.cs b/MatterControlLib/DesignTools/Obsolete/CombineObject3D.cs index b099547f0..7c7240cf0 100644 --- a/MatterControlLib/DesignTools/Obsolete/CombineObject3D.cs +++ b/MatterControlLib/DesignTools/Obsolete/CombineObject3D.cs @@ -96,7 +96,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D } rebuildLocks.Dispose(); - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; }); } diff --git a/MatterControlLib/DesignTools/Obsolete/CurveObject3D.cs b/MatterControlLib/DesignTools/Obsolete/CurveObject3D.cs index f08d97668..fe28ae30c 100644 --- a/MatterControlLib/DesignTools/Obsolete/CurveObject3D.cs +++ b/MatterControlLib/DesignTools/Obsolete/CurveObject3D.cs @@ -274,7 +274,7 @@ namespace MatterHackers.MatterControl.DesignTools Matrix = currentMatrix; } - Invalidate(InvalidateType.Mesh); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh)); if (valuesChanged) { Invalidate(InvalidateType.DisplayValues); diff --git a/MatterControlLib/DesignTools/Obsolete/FitToBoundsObject3D.cs b/MatterControlLib/DesignTools/Obsolete/FitToBoundsObject3D.cs index 8b0a6896c..226432281 100644 --- a/MatterControlLib/DesignTools/Obsolete/FitToBoundsObject3D.cs +++ b/MatterControlLib/DesignTools/Obsolete/FitToBoundsObject3D.cs @@ -103,7 +103,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations list.AddRange(ScaleItem.Children); }); } - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); } public override void Remove(UndoBuffer undoBuffer) @@ -124,7 +124,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations }); } - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); } public override void OnInvalidate(InvalidateArgs invalidateType) @@ -178,7 +178,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations } } - Invalidate(InvalidateType.Matrix); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Matrix)); return Task.CompletedTask; } diff --git a/MatterControlLib/DesignTools/Obsolete/IntersectionObject3D.cs b/MatterControlLib/DesignTools/Obsolete/IntersectionObject3D.cs index 6e1b47196..4c99960b1 100644 --- a/MatterControlLib/DesignTools/Obsolete/IntersectionObject3D.cs +++ b/MatterControlLib/DesignTools/Obsolete/IntersectionObject3D.cs @@ -90,7 +90,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D } rebuildLocks.Dispose(); - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; }); } diff --git a/MatterControlLib/DesignTools/Obsolete/MirrorObject3D.cs b/MatterControlLib/DesignTools/Obsolete/MirrorObject3D.cs index 9b07f3beb..260d3cc9f 100644 --- a/MatterControlLib/DesignTools/Obsolete/MirrorObject3D.cs +++ b/MatterControlLib/DesignTools/Obsolete/MirrorObject3D.cs @@ -93,12 +93,12 @@ namespace MatterHackers.MatterControl.DesignTools this.Matrix = oldMatrix; } - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; } - public override void OnInvalidate(InvalidateArgs invalidateType) + public override async void OnInvalidate(InvalidateArgs invalidateType) { if ((invalidateType.InvalidateType.HasFlag(InvalidateType.Children) || invalidateType.InvalidateType.HasFlag(InvalidateType.Matrix) @@ -106,12 +106,12 @@ namespace MatterHackers.MatterControl.DesignTools && invalidateType.Source != this && !RebuildLocked) { - Rebuild(); + await Rebuild(); } else if (invalidateType.InvalidateType.HasFlag(InvalidateType.Properties) && invalidateType.Source == this) { - Rebuild(); + await Rebuild(); } else { diff --git a/MatterControlLib/DesignTools/Obsolete/PinchObject3D.cs b/MatterControlLib/DesignTools/Obsolete/PinchObject3D.cs index 0711a750c..5f3ad6dc8 100644 --- a/MatterControlLib/DesignTools/Obsolete/PinchObject3D.cs +++ b/MatterControlLib/DesignTools/Obsolete/PinchObject3D.cs @@ -56,7 +56,7 @@ namespace MatterHackers.MatterControl.DesignTools [DisplayName("Back Ratio")] public double PinchRatio { get; set; } = .5; - public override void OnInvalidate(InvalidateArgs invalidateType) + public override async void OnInvalidate(InvalidateArgs invalidateType) { if ((invalidateType.InvalidateType.HasFlag(InvalidateType.Children) || invalidateType.InvalidateType.HasFlag(InvalidateType.Matrix) @@ -64,12 +64,12 @@ namespace MatterHackers.MatterControl.DesignTools && invalidateType.Source != this && !RebuildLocked) { - Rebuild(); + await Rebuild(); } else if (invalidateType.InvalidateType.HasFlag(InvalidateType.Properties) && invalidateType.Source == this) { - Rebuild(); + await Rebuild(); } else { @@ -125,7 +125,7 @@ namespace MatterHackers.MatterControl.DesignTools Matrix = currentMatrix; } - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; } } diff --git a/MatterControlLib/DesignTools/Obsolete/RotateObject3D.cs b/MatterControlLib/DesignTools/Obsolete/RotateObject3D.cs index 2272e3ed7..9facf8ed9 100644 --- a/MatterControlLib/DesignTools/Obsolete/RotateObject3D.cs +++ b/MatterControlLib/DesignTools/Obsolete/RotateObject3D.cs @@ -93,7 +93,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations } } - Invalidate(InvalidateType.Matrix); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Matrix)); return Task.CompletedTask; } diff --git a/MatterControlLib/DesignTools/Operations/AlignObject3D.cs b/MatterControlLib/DesignTools/Operations/AlignObject3D.cs index 503845051..91f963ef7 100644 --- a/MatterControlLib/DesignTools/Operations/AlignObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/AlignObject3D.cs @@ -420,7 +420,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations })); } - Invalidate(InvalidateType.Matrix); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Matrix)); return Task.CompletedTask; } diff --git a/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs b/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs index b5350f619..0ddb45c88 100644 --- a/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs @@ -100,7 +100,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations }); SourceContainer.Visible = false; rebuildLock.Dispose(); - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; }); } diff --git a/MatterControlLib/DesignTools/Operations/ArrayLinearObject3D.cs b/MatterControlLib/DesignTools/Operations/ArrayLinearObject3D.cs index d196c00e9..b405c3977 100644 --- a/MatterControlLib/DesignTools/Operations/ArrayLinearObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ArrayLinearObject3D.cs @@ -86,7 +86,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations } SourceContainer.Visible = false; rebuildLock.Dispose(); - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; }); } diff --git a/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs b/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs index 24fe4f705..d6660cf60 100644 --- a/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs @@ -128,7 +128,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations }); SourceContainer.Visible = false; rebuildLock.Dispose(); - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; }); } diff --git a/MatterControlLib/DesignTools/Operations/CurveObject3D_2.cs b/MatterControlLib/DesignTools/Operations/CurveObject3D_2.cs index 64076f6ae..38bf0ea5d 100644 --- a/MatterControlLib/DesignTools/Operations/CurveObject3D_2.cs +++ b/MatterControlLib/DesignTools/Operations/CurveObject3D_2.cs @@ -185,7 +185,7 @@ namespace MatterHackers.MatterControl.DesignTools SourceContainer.Visible = false; rebuildLocks.Dispose(); } - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); } return Task.CompletedTask; diff --git a/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_2.cs b/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_2.cs index 1f8c63c0a..78818943a 100644 --- a/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_2.cs +++ b/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_2.cs @@ -233,7 +233,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations } } - Invalidate(InvalidateType.Matrix); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Matrix)); return Task.CompletedTask; } diff --git a/MatterControlLib/DesignTools/Operations/FitToCylinderObject3D.cs b/MatterControlLib/DesignTools/Operations/FitToCylinderObject3D.cs index 231b1f61f..35df9bd7e 100644 --- a/MatterControlLib/DesignTools/Operations/FitToCylinderObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/FitToCylinderObject3D.cs @@ -191,7 +191,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations } } - Invalidate(InvalidateType.Matrix); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Matrix)); return Task.CompletedTask; } diff --git a/MatterControlLib/DesignTools/Operations/Image/LinearExtrudeObject3D.cs b/MatterControlLib/DesignTools/Operations/Image/LinearExtrudeObject3D.cs index 1e1860070..a1eff68c3 100644 --- a/MatterControlLib/DesignTools/Operations/Image/LinearExtrudeObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/Image/LinearExtrudeObject3D.cs @@ -127,7 +127,7 @@ namespace MatterHackers.MatterControl.DesignTools } rebuildLock.Dispose(); - Invalidate(InvalidateType.Mesh); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh)); return Task.CompletedTask; }); } diff --git a/MatterControlLib/DesignTools/Operations/MirrorObject3D_2.cs b/MatterControlLib/DesignTools/Operations/MirrorObject3D_2.cs index 8f1b5d81e..d29d1078c 100644 --- a/MatterControlLib/DesignTools/Operations/MirrorObject3D_2.cs +++ b/MatterControlLib/DesignTools/Operations/MirrorObject3D_2.cs @@ -106,7 +106,7 @@ namespace MatterHackers.MatterControl.DesignTools this.Matrix = oldMatrix; SourceContainer.Visible = false; rebuildLock.Dispose(); - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; }); } diff --git a/MatterControlLib/DesignTools/Operations/Path/InflatePathObject3D.cs b/MatterControlLib/DesignTools/Operations/Path/InflatePathObject3D.cs index 1d0c03459..76e14a070 100644 --- a/MatterControlLib/DesignTools/Operations/Path/InflatePathObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/Path/InflatePathObject3D.cs @@ -32,7 +32,6 @@ using ClipperLib; using MatterHackers.Agg.UI; using MatterHackers.DataConverters3D; using MatterHackers.Localizations; -using MatterHackers.MatterControl.DesignTools.Operations; namespace MatterHackers.MatterControl.DesignTools.Operations { @@ -58,7 +57,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations [Description("Change the width of the image lines.")] public double Inflate { get; set; } - public override void OnInvalidate(InvalidateArgs invalidateType) + public override async void OnInvalidate(InvalidateArgs invalidateType) { if ((invalidateType.InvalidateType.HasFlag(InvalidateType.Children) || invalidateType.InvalidateType.HasFlag(InvalidateType.Matrix) @@ -66,12 +65,12 @@ namespace MatterHackers.MatterControl.DesignTools.Operations && invalidateType.Source != this && !RebuildLocked) { - Rebuild(); + await Rebuild(); } else if (invalidateType.InvalidateType.HasFlag(InvalidateType.Properties) && invalidateType.Source == this) { - Rebuild(); + await Rebuild(); } else { @@ -87,7 +86,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations InsetPath(); } - Invalidate(InvalidateType.Path); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Path)); return Task.CompletedTask; } diff --git a/MatterControlLib/DesignTools/Operations/Path/SmoothPathObject3D.cs b/MatterControlLib/DesignTools/Operations/Path/SmoothPathObject3D.cs index 548571f82..57e625d4b 100644 --- a/MatterControlLib/DesignTools/Operations/Path/SmoothPathObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/Path/SmoothPathObject3D.cs @@ -92,7 +92,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations DoSmoothing((long)(SmoothDistance * 1000), Iterations); rebuildLock.Dispose(); - Invalidate(InvalidateType.Path); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Path)); return Task.CompletedTask; }); } diff --git a/MatterControlLib/DesignTools/Operations/RotateObject3D_2.cs b/MatterControlLib/DesignTools/Operations/RotateObject3D_2.cs index 010934e78..8b5e7669a 100644 --- a/MatterControlLib/DesignTools/Operations/RotateObject3D_2.cs +++ b/MatterControlLib/DesignTools/Operations/RotateObject3D_2.cs @@ -137,7 +137,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations ItemWithTransform.Matrix = RotationMatrix; } - Invalidate(InvalidateType.Matrix); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Matrix)); return Task.CompletedTask; } diff --git a/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs b/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs index 459e32840..14c59bac5 100644 --- a/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs @@ -218,7 +218,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations ItemWithTransform.Matrix *= Matrix4X4.CreateTranslation(ScaleAbout); } - Invalidate(InvalidateType.Matrix); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Matrix)); return Task.CompletedTask; } diff --git a/MatterControlLib/DesignTools/Operations/TranslateObject3D.cs b/MatterControlLib/DesignTools/Operations/TranslateObject3D.cs index 57f2f8dfd..91ae3954a 100644 --- a/MatterControlLib/DesignTools/Operations/TranslateObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/TranslateObject3D.cs @@ -76,7 +76,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations #endregion // editable properties - public override void OnInvalidate(InvalidateArgs invalidateType) + public override async void OnInvalidate(InvalidateArgs invalidateType) { if ((invalidateType.InvalidateType.HasFlag(InvalidateType.Children) || invalidateType.InvalidateType.HasFlag(InvalidateType.Matrix) @@ -84,12 +84,12 @@ namespace MatterHackers.MatterControl.DesignTools.Operations && invalidateType.Source != this && !RebuildLocked) { - Rebuild(); + await Rebuild(); } else if (invalidateType.InvalidateType.HasFlag(InvalidateType.Properties) && invalidateType.Source == this) { - Rebuild(); + await Rebuild(); } else { @@ -107,7 +107,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations ItemWithTransform.Matrix = Matrix4X4.CreateTranslation(Translation); } - Invalidate(InvalidateType.Matrix); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Matrix)); return Task.CompletedTask; } } diff --git a/MatterControlLib/DesignTools/Primitives/ImageObject3D.cs b/MatterControlLib/DesignTools/Primitives/ImageObject3D.cs index 8881a90ed..0b37280cc 100644 --- a/MatterControlLib/DesignTools/Primitives/ImageObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/ImageObject3D.cs @@ -101,7 +101,7 @@ namespace MatterHackers.MatterControl.DesignTools } // send the invalidate on image change - Invalidate(InvalidateType.Image); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Image)); } return _image; diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/CombineObject3D_2.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/CombineObject3D_2.cs index cdaaf0ead..f32e7d8ff 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/CombineObject3D_2.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/CombineObject3D_2.cs @@ -69,7 +69,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D } rebuildLocks.Dispose(); - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; }); } diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/IntersectionObject3D_2.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/IntersectionObject3D_2.cs index ffadcfe6e..540837415 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/IntersectionObject3D_2.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/IntersectionObject3D_2.cs @@ -70,7 +70,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D } rebuildLocks.Dispose(); - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; }); } diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractAndReplaceObject3D.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractAndReplaceObject3D.cs index 022b561cf..013e78bb6 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractAndReplaceObject3D.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractAndReplaceObject3D.cs @@ -178,7 +178,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D } rebuildLocks.Dispose(); - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; }); } diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractAndReplaceObject3D_2.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractAndReplaceObject3D_2.cs index 60308ef85..1b64e0e78 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractAndReplaceObject3D_2.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractAndReplaceObject3D_2.cs @@ -131,7 +131,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D } rebuildLocks.Dispose(); - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; }); } diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D.cs index a07af4a2d..25feb4d2e 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D.cs @@ -99,7 +99,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D } rebuildLocks.Dispose(); - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; }); } diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D_2.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D_2.cs index 4013da36f..bae5af5dc 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D_2.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D_2.cs @@ -137,7 +137,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D } rebuildLocks.Dispose(); - Invalidate(InvalidateType.Children); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; }); } From d82efb143a84c38852e56b38d81bf9c84b4a5565 Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Thu, 14 Feb 2019 08:42:44 -0800 Subject: [PATCH 02/13] Working on new software endstops stream --- .../Io/SoftwareEndstopsStream.cs | 140 ++++++++++++++++++ .../PrinterCommunication/PrinterConnection.cs | 4 +- Submodules/MatterSlice | 2 +- Submodules/agg-sharp | 2 +- 4 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 MatterControlLib/PrinterCommunication/Io/SoftwareEndstopsStream.cs diff --git a/MatterControlLib/PrinterCommunication/Io/SoftwareEndstopsStream.cs b/MatterControlLib/PrinterCommunication/Io/SoftwareEndstopsStream.cs new file mode 100644 index 000000000..2fb5aa561 --- /dev/null +++ b/MatterControlLib/PrinterCommunication/Io/SoftwareEndstopsStream.cs @@ -0,0 +1,140 @@ +/* +Copyright (c) 2014, 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 MatterControl.Printing; +using MatterHackers.Agg; +using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.VectorMath; + +namespace MatterHackers.MatterControl.PrinterCommunication.Io +{ + public class SoftwareEndstopsStream : GCodeStreamProxy + { + private int extruderIndex = 0; + PrinterMove lastDestination = PrinterMove.Unknown; + + Vector3[] extruderOffsets = new Vector3[4]; + + public SoftwareEndstopsStream(GCodeStream internalStream, PrinterConfig printer) + : base(printer, internalStream) + { + printer.Settings.SettingChanged += Settings_SettingChanged; + + extruderIndex = printer.Connection.ActiveExtruderIndex; + + ReadExtruderOffsets(); + } + + private void Settings_SettingChanged(object sender, StringEventArgs stringEvent) + { + if (stringEvent != null) + { + // if the offsets change update them (unless we are actively printing) + if (stringEvent.Data == SettingsKey.extruder_offset + && !printer.Connection.Printing + && !printer.Connection.Paused) + { + 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) + { + this.lastDestination.CopyKnowSettings(position); + if (extruderIndex < 4) + { + lastDestination.position -= RuntimeOffsets[extruderIndex]; + lastDestination.position += extruderOffsets[extruderIndex]; + } + internalStream.SetPrinterPosition(lastDestination); + } + + public Vector3[] RuntimeOffsets { get; private set; } = new Vector3[4]; + + public override string ReadLine() + { + string lineToSend = base.ReadLine(); + + if (lineToSend != null + && lineToSend.EndsWith("; NO_PROCESSING")) + { + return lineToSend; + } + + if (lineToSend != null + && lineToSend.StartsWith("T")) + { + int extruder = 0; + if (GCodeFile.GetFirstNumberAfter("T", lineToSend, ref extruder)) + { + extruderIndex = extruder; + } + } + + if (lineToSend != null + && LineIsMovement(lineToSend)) + { + PrinterMove currentMove = GetPosition(lineToSend, lastDestination); + + PrinterMove moveToSend = currentMove; + if (extruderIndex < 4) + { + moveToSend.position += RuntimeOffsets[extruderIndex]; + moveToSend.position -= extruderOffsets[extruderIndex]; + } + + if (moveToSend.HaveAnyPosition) + { + lineToSend = CreateMovementLine(moveToSend, lastDestination); + } + lastDestination = currentMove; + + return lineToSend; + } + + return lineToSend; + } + } +} \ No newline at end of file diff --git a/MatterControlLib/PrinterCommunication/PrinterConnection.cs b/MatterControlLib/PrinterCommunication/PrinterConnection.cs index b25027e7a..b92884761 100644 --- a/MatterControlLib/PrinterCommunication/PrinterConnection.cs +++ b/MatterControlLib/PrinterCommunication/PrinterConnection.cs @@ -195,6 +195,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication private FeedRateMultiplyerStream feedrateMultiplyerStream9 = null; private RequestTemperaturesStream requestTemperaturesStream10 = null; private ProcessWriteRegexStream processWriteRegExStream11 = null; + private SoftwareEndstopsStream softwareEndstopsExStream12 = null; private GCodeStream totalGCodeStream = null; @@ -2141,7 +2142,8 @@ You will then need to logout and log back in to the computer for the changes to feedrateMultiplyerStream9 = new FeedRateMultiplyerStream(Printer, extrusionMultiplyerStream8); requestTemperaturesStream10 = new RequestTemperaturesStream(Printer, feedrateMultiplyerStream9); processWriteRegExStream11 = new ProcessWriteRegexStream(Printer, requestTemperaturesStream10, queuedCommandStream3); - totalGCodeStream = processWriteRegExStream11; + softwareEndstopsExStream12 = new SoftwareEndstopsStream(processWriteRegExStream11, Printer); + totalGCodeStream = softwareEndstopsExStream12; // Force a reset of the printer checksum state (but allow it to be write regexed) var transformedCommand = processWriteRegExStream11?.ProcessWriteRegEx("M110 N1"); diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index 2572ad0b2..d93dba440 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit 2572ad0b29d45fb647ef4d0d5d4dcc2e38e308e4 +Subproject commit d93dba440e76111af31c3c873a3d5c2bfc8c0d5a diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index d53980a7d..1e4317a90 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit d53980a7dc44efd0d3ecad0213caf78a3da5128f +Subproject commit 1e4317a904e923f338dde1600d65bce11bb46b97 From 3f0f8a2369651f1184893e249c812b996c4300e0 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Fri, 15 Feb 2019 12:55:22 -0800 Subject: [PATCH 03/13] starting work on software endstops stream --- .../Io/SoftwareEndstopsStream.cs | 102 ++++++++++-------- .../PrinterCommunication/PrinterConnection.cs | 2 +- .../MatterControl/GCodeStreamTests.cs | 68 ++++++++++++ 3 files changed, 124 insertions(+), 48 deletions(-) diff --git a/MatterControlLib/PrinterCommunication/Io/SoftwareEndstopsStream.cs b/MatterControlLib/PrinterCommunication/Io/SoftwareEndstopsStream.cs index 2fb5aa561..b2ed793a2 100644 --- a/MatterControlLib/PrinterCommunication/Io/SoftwareEndstopsStream.cs +++ b/MatterControlLib/PrinterCommunication/Io/SoftwareEndstopsStream.cs @@ -27,7 +27,6 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ -using MatterControl.Printing; using MatterHackers.Agg; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.VectorMath; @@ -36,40 +35,28 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io { public class SoftwareEndstopsStream : GCodeStreamProxy { - private int extruderIndex = 0; - PrinterMove lastDestination = PrinterMove.Unknown; + private PrinterMove lastDestination = PrinterMove.Unknown; - Vector3[] extruderOffsets = new Vector3[4]; + AxisAlignedBoundingBox[] extruderBounds = new AxisAlignedBoundingBox[4]; - public SoftwareEndstopsStream(GCodeStream internalStream, PrinterConfig printer) + public SoftwareEndstopsStream(PrinterConfig printer, GCodeStream internalStream) : base(printer, internalStream) { + CalculateBounds(); + printer.Settings.SettingChanged += Settings_SettingChanged; - extruderIndex = printer.Connection.ActiveExtruderIndex; - - ReadExtruderOffsets(); + // Register to listen for position after home and update Bounds based on the axis homed and position info. } private void Settings_SettingChanged(object sender, StringEventArgs stringEvent) { - if (stringEvent != null) + if (stringEvent.Data == SettingsKey.bed_size + || stringEvent.Data == SettingsKey.print_center + || stringEvent.Data == SettingsKey.build_height + || stringEvent.Data == SettingsKey.bed_shape) { - // if the offsets change update them (unless we are actively printing) - if (stringEvent.Data == SettingsKey.extruder_offset - && !printer.Connection.Printing - && !printer.Connection.Paused) - { - ReadExtruderOffsets(); - } - } - } - - private void ReadExtruderOffsets() - { - for (int i = 0; i < 4; i++) - { - extruderOffsets[i] = printer.Settings.Helpers.ExtruderOffset(i); + this.CalculateBounds(); } } @@ -80,18 +67,36 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io base.Dispose(); } - public override void SetPrinterPosition(PrinterMove position) + private void CalculateBounds() { - this.lastDestination.CopyKnowSettings(position); - if (extruderIndex < 4) + var bedSize = printer.Settings.GetValue(SettingsKey.bed_size); + var printCenter = printer.Settings.GetValue(SettingsKey.print_center); + var buildHeight = printer.Settings.GetValue(SettingsKey.build_height); + if (buildHeight == 0) { - lastDestination.position -= RuntimeOffsets[extruderIndex]; - lastDestination.position += extruderOffsets[extruderIndex]; + buildHeight = double.PositiveInfinity; } - internalStream.SetPrinterPosition(lastDestination); - } - public Vector3[] RuntimeOffsets { get; private set; } = new Vector3[4]; + // first set all the extruders to the bounds defined by the settings file + for (int i = 0; i < extruderBounds.Length; i++) + { + extruderBounds[i] = new AxisAlignedBoundingBox( + printCenter.X - bedSize.X / 2, // min x + printCenter.Y - bedSize.Y / 2, // min y + 0, // min z + printCenter.X + bedSize.X / 2, // max x + printCenter.Y + bedSize.Y / 2, // max y + buildHeight); // max z + + } + + // if we have more constrained info for extruders, add that it + + // If we know something about the homing positions, add them in. + // Specifically never go above a z homes max endstop. + // We may also want to add in all other know (measured) endstop postions. + + } public override string ReadLine() { @@ -103,30 +108,16 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io return lineToSend; } - if (lineToSend != null - && lineToSend.StartsWith("T")) - { - int extruder = 0; - if (GCodeFile.GetFirstNumberAfter("T", lineToSend, ref extruder)) - { - extruderIndex = extruder; - } - } - if (lineToSend != null && LineIsMovement(lineToSend)) { PrinterMove currentMove = GetPosition(lineToSend, lastDestination); PrinterMove moveToSend = currentMove; - if (extruderIndex < 4) - { - moveToSend.position += RuntimeOffsets[extruderIndex]; - moveToSend.position -= extruderOffsets[extruderIndex]; - } if (moveToSend.HaveAnyPosition) { + ClampToPrinter(ref moveToSend); lineToSend = CreateMovementLine(moveToSend, lastDestination); } lastDestination = currentMove; @@ -136,5 +127,22 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io return lineToSend; } + + public override void SetPrinterPosition(PrinterMove position) + { + this.lastDestination.CopyKnowSettings(position); + internalStream.SetPrinterPosition(lastDestination); + } + + private void ClampToPrinter(ref PrinterMove moveToSend) + { + var bounds = extruderBounds[printer.Connection.ActiveExtruderIndex]; + if (moveToSend.position.X < bounds.MinXYZ.X) + { + moveToSend.position.X = bounds.MinXYZ.X; + // If we clamp, than do not do any extrusion at all + moveToSend.extrusion = 0; + } + } } } \ No newline at end of file diff --git a/MatterControlLib/PrinterCommunication/PrinterConnection.cs b/MatterControlLib/PrinterCommunication/PrinterConnection.cs index b92884761..e3ebc564b 100644 --- a/MatterControlLib/PrinterCommunication/PrinterConnection.cs +++ b/MatterControlLib/PrinterCommunication/PrinterConnection.cs @@ -2142,7 +2142,7 @@ You will then need to logout and log back in to the computer for the changes to feedrateMultiplyerStream9 = new FeedRateMultiplyerStream(Printer, extrusionMultiplyerStream8); requestTemperaturesStream10 = new RequestTemperaturesStream(Printer, feedrateMultiplyerStream9); processWriteRegExStream11 = new ProcessWriteRegexStream(Printer, requestTemperaturesStream10, queuedCommandStream3); - softwareEndstopsExStream12 = new SoftwareEndstopsStream(processWriteRegExStream11, Printer); + softwareEndstopsExStream12 = new SoftwareEndstopsStream(Printer, processWriteRegExStream11); totalGCodeStream = softwareEndstopsExStream12; // Force a reset of the printer checksum state (but allow it to be write regexed) diff --git a/Tests/MatterControl.Tests/MatterControl/GCodeStreamTests.cs b/Tests/MatterControl.Tests/MatterControl/GCodeStreamTests.cs index 576393a51..bf1a03dc6 100644 --- a/Tests/MatterControl.Tests/MatterControl/GCodeStreamTests.cs +++ b/Tests/MatterControl.Tests/MatterControl/GCodeStreamTests.cs @@ -559,6 +559,74 @@ namespace MatterControl.Tests.MatterControl } } + [Test, Category("GCodeStream")] + public void SoftwareEndstopstreamTests() + { + string[] inputLines = new string[] + { + // test x min + // move without extrusion + "G1 X100Y100Z0E0", // start at the bed center + "G1 X-100", // move left off the bed + "G1 Y110", // move while outside bounds + "G1 X100", // move back on + + // move with extrusion + "G1 X100Y100Z0E0", // start at the bed center + "G1 X-100E10", // move left off the bed + "G1 Y110E20", // move while outside bounds + "G1 X100E30", // move back on + + // test x max + // test y min + // test y max + // test z min + // test z max + + null, + }; + + // We should go back to the above code when possible. It requires making pause part and move while paused part of the stream. + // All communication should go through stream to minimize the difference between printing and controlling while not printing (all printing in essence). + string[] expected = new string[] + { + // move without extrusion + "G1 X100 Y100 Z0 E0", // strat position + "G1 X0", // clamped x + "", // move while outside + "G1 Y110", // first position back in bounds + "G1 X100", // move to requested x + + // move with extrusion + "G1 X100Y100Z0E0", // start at the bed center + "G1 X-100E10", // move left off the bed + "G1 Y110E20", // move while outside bounds + "G1 X100E30", // move back on + + null, + }; + + AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); + MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); + + var printer = new PrinterConfig(new PrinterSettings()); + var pauseHandlingStream = new SoftwareEndstopsStream(printer, new TestGCodeStream(printer, inputLines)); + + int expectedIndex = 0; + string actualLine = pauseHandlingStream.ReadLine(); + string expectedLine = expected[expectedIndex++]; + + Assert.AreEqual(expectedLine, actualLine, "Unexpected response from PauseHandlingStream"); + + while (actualLine != null) + { + expectedLine = expected[expectedIndex++]; + actualLine = pauseHandlingStream.ReadLine(); + + Assert.AreEqual(expectedLine, actualLine, "Unexpected response from PauseHandlingStream"); + } + } + [Test, Category("GCodeStream")] public void MorePauseHandlingStreamTests() { From 64131e6e0144f2911f3da8de88883d24fb9c134c Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Tue, 19 Feb 2019 11:58:18 -0800 Subject: [PATCH 04/13] Always do T0 T1 change in streams --- .../PrinterCommunication/Io/QueuedCommandsStream.cs | 4 +--- .../SlicerConfiguration/EngineMappingMatterSlice.cs | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/MatterControlLib/PrinterCommunication/Io/QueuedCommandsStream.cs b/MatterControlLib/PrinterCommunication/Io/QueuedCommandsStream.cs index 58314bfaf..6dbf219d6 100644 --- a/MatterControlLib/PrinterCommunication/Io/QueuedCommandsStream.cs +++ b/MatterControlLib/PrinterCommunication/Io/QueuedCommandsStream.cs @@ -70,9 +70,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io } else { - // If we are not printing, check if we need to switch extruders - if (extruderCount > 1 - && !printer.Connection.Printing) + if (extruderCount > 1) { CheckIfNeedToSwitchExtruders(line); } diff --git a/MatterControlLib/SlicerConfiguration/EngineMappingMatterSlice.cs b/MatterControlLib/SlicerConfiguration/EngineMappingMatterSlice.cs index 9a362bfbe..e94a8da54 100644 --- a/MatterControlLib/SlicerConfiguration/EngineMappingMatterSlice.cs +++ b/MatterControlLib/SlicerConfiguration/EngineMappingMatterSlice.cs @@ -159,9 +159,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration new AsPercentOfReferenceOrDirect(printer, SettingsKey.first_layer_extrusion_width, "firstLayerExtrusionWidth", SettingsKey.nozzle_diameter), new AsPercentOfReferenceOrDirect(printer, SettingsKey.first_layer_height, "firstLayerThickness", SettingsKey.layer_height), new GCodeForSlicer(printer, SettingsKey.end_gcode, "endCode"), - new GCodeForSlicer(printer, SettingsKey.before_toolchange_gcode, "beforeToolchangeCode"), new GCodeForSlicer(printer, SettingsKey.toolchange_gcode, "toolChangeCode"), - new GCodeForSlicer(printer, SettingsKey.before_toolchange_gcode_1, "beforeToolchangeCode1"), new GCodeForSlicer(printer, SettingsKey.toolchange_gcode_1, "toolChangeCode1"), new MapFirstValue(printer, SettingsKey.retract_before_travel, "minimumTravelToCauseRetraction"), new RetractionLength(printer, SettingsKey.retract_length, "retractionOnTravel"), From 9d7357bc6da43dfaebba59c4ce719b872f78338d Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Tue, 19 Feb 2019 14:28:24 -0800 Subject: [PATCH 05/13] Don't enable software endstop stream yet --- MatterControlLib/PrinterCommunication/PrinterConnection.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MatterControlLib/PrinterCommunication/PrinterConnection.cs b/MatterControlLib/PrinterCommunication/PrinterConnection.cs index e3ebc564b..6971040f7 100644 --- a/MatterControlLib/PrinterCommunication/PrinterConnection.cs +++ b/MatterControlLib/PrinterCommunication/PrinterConnection.cs @@ -195,7 +195,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication private FeedRateMultiplyerStream feedrateMultiplyerStream9 = null; private RequestTemperaturesStream requestTemperaturesStream10 = null; private ProcessWriteRegexStream processWriteRegExStream11 = null; - private SoftwareEndstopsStream softwareEndstopsExStream12 = null; + //private SoftwareEndstopsStream softwareEndstopsExStream12 = null; private GCodeStream totalGCodeStream = null; @@ -2142,8 +2142,13 @@ You will then need to logout and log back in to the computer for the changes to feedrateMultiplyerStream9 = new FeedRateMultiplyerStream(Printer, extrusionMultiplyerStream8); requestTemperaturesStream10 = new RequestTemperaturesStream(Printer, feedrateMultiplyerStream9); processWriteRegExStream11 = new ProcessWriteRegexStream(Printer, requestTemperaturesStream10, queuedCommandStream3); + +#if true + totalGCodeStream = processWriteRegExStream11; +#else softwareEndstopsExStream12 = new SoftwareEndstopsStream(Printer, processWriteRegExStream11); totalGCodeStream = softwareEndstopsExStream12; +#endif // Force a reset of the printer checksum state (but allow it to be write regexed) var transformedCommand = processWriteRegExStream11?.ProcessWriteRegEx("M110 N1"); From 0897d4dc08d8ba195e5d5884f775e84155f857f7 Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 19 Feb 2019 14:39:22 -0800 Subject: [PATCH 06/13] Restore behavior from old UltraFineBed step conclusion - Issue MatterHackers/MCCentral#5075 Restore deleted code, move into OnClosed rather than OnLoad --- .../WizardPages/CalibrateProbeLastPageInstructions.cs | 6 ++++++ .../PrintLeveling/WizardPages/LastPageInstructions.cs | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/CalibrateProbeLastPageInstructions.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/CalibrateProbeLastPageInstructions.cs index b60c75f0f..728e81156 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/CalibrateProbeLastPageInstructions.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/CalibrateProbeLastPageInstructions.cs @@ -66,10 +66,16 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { printer.Connection.QueueLine("T0"); printer.Connection.MoveRelative(PrinterConnection.Axis.X, .1, printer.Connection.CurrentFeedRate); + if (printer.Settings.GetValue(SettingsKey.z_homes_to_max)) { printer.Connection.HomeAxis(PrinterConnection.Axis.XYZ); } + else if (!printer.Settings.GetValue(SettingsKey.has_z_probe)) + { + // Lift the hotend off the bed - at the conclusion of the wizard, make sure we lift the heated nozzle off the bed + printer.Connection.MoveRelative(PrinterConnection.Axis.Z, 2, printer.Settings.Helpers.ManualMovementSpeeds().Z); + } pageWasActive = true; diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/LastPageInstructions.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/LastPageInstructions.cs index 81936cc2f..79b323cef 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/LastPageInstructions.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/LastPageInstructions.cs @@ -97,6 +97,11 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { printer.Connection.HomeAxis(PrinterConnection.Axis.XYZ); } + else if (!printer.Settings.GetValue(SettingsKey.has_z_probe)) + { + // Lift the hotend off the bed - at the conclusion of the wizard, make sure we lift the heated nozzle off the bed + printer.Connection.MoveRelative(PrinterConnection.Axis.Z, 2, printer.Settings.Helpers.ManualMovementSpeeds().Z); + } Closed += (s, e) => { From 53e09aa4bc7992277cb763e45e80064ae868af9d Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 19 Feb 2019 14:42:15 -0800 Subject: [PATCH 07/13] Use OnClosed instead of Closed event, remove redundant guard --- .../CalibrateProbeLastPageInstructions.cs | 11 ++--------- .../WizardPages/LastPageInstructions.cs | 14 ++++++++------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/CalibrateProbeLastPageInstructions.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/CalibrateProbeLastPageInstructions.cs index 728e81156..9d6a870cc 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/CalibrateProbeLastPageInstructions.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/CalibrateProbeLastPageInstructions.cs @@ -39,8 +39,6 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { public class CalibrateProbeLastPageInstructions : WizardPage { - private bool pageWasActive = false; - public CalibrateProbeLastPageInstructions(ISetupWizard setupWizard, string headerText) : base(setupWizard, headerText, "") { @@ -77,18 +75,13 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling printer.Connection.MoveRelative(PrinterConnection.Axis.Z, 2, printer.Settings.Helpers.ManualMovementSpeeds().Z); } - pageWasActive = true; - base.OnLoad(args); } public override void OnClosed(EventArgs e) { - if (pageWasActive) - { - // move from this wizard to the print leveling wizard if needed - ApplicationController.Instance.RunAnyRequiredPrinterSetup(printer, theme); - } + // move from this wizard to the print leveling wizard if needed + ApplicationController.Instance.RunAnyRequiredPrinterSetup(printer, theme); } } } \ No newline at end of file diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/LastPageInstructions.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/LastPageInstructions.cs index 79b323cef..cf08f16d0 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/LastPageInstructions.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/LastPageInstructions.cs @@ -103,13 +103,15 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling printer.Connection.MoveRelative(PrinterConnection.Axis.Z, 2, printer.Settings.Helpers.ManualMovementSpeeds().Z); } - Closed += (s, e) => - { - // give instruction about how to load filament if the user has not gotten them - ApplicationController.Instance.RunAnyRequiredPrinterSetup(printer, theme); - }; - base.OnLoad(args); } + + public override void OnClosed(EventArgs e) + { + // give instruction about how to load filament if the user has not gotten them + ApplicationController.Instance.RunAnyRequiredPrinterSetup(printer, theme); + + base.OnClosed(e); + } } } \ No newline at end of file From acc10125c8a1c9a0e5203717f7b275c48c961920 Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 19 Feb 2019 15:26:09 -0800 Subject: [PATCH 08/13] Extract extruder switching behavior to new stream processor --- .../Io/QueuedCommandsStream.cs | 88 ---------- .../Io/SwitchExtruderStream.cs | 157 ++++++++++++++++++ .../PrinterCommunication/PrinterConnection.cs | 10 +- 3 files changed, 166 insertions(+), 89 deletions(-) create mode 100644 MatterControlLib/PrinterCommunication/Io/SwitchExtruderStream.cs diff --git a/MatterControlLib/PrinterCommunication/Io/QueuedCommandsStream.cs b/MatterControlLib/PrinterCommunication/Io/QueuedCommandsStream.cs index 6dbf219d6..ea44e8503 100644 --- a/MatterControlLib/PrinterCommunication/Io/QueuedCommandsStream.cs +++ b/MatterControlLib/PrinterCommunication/Io/QueuedCommandsStream.cs @@ -27,18 +27,10 @@ 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.Diagnostics; using System.IO; -using System.Text.RegularExpressions; -using System.Threading; -using MatterControl.Printing; using MatterHackers.Agg.Image; using MatterHackers.Agg.Platform; -using MatterHackers.Agg.UI; -using MatterHackers.MatterControl.PrinterControls; -using MatterHackers.MatterControl.SlicerConfiguration; namespace MatterHackers.MatterControl.PrinterCommunication.Io { @@ -46,15 +38,11 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io { private List commandQueue = new List(); private object locker = new object(); - private int requestedExtruder; - private int extruderLastSwitchedTo; PrinterMove lastDestination = PrinterMove.Unknown; - int extruderCount = 0; public QueuedCommandsStream(PrinterConfig printer, GCodeStream internalStream) : base(printer, internalStream) { - extruderCount = printer.Settings.GetValue(SettingsKey.extruder_count); } public int Count => commandQueue.Count; @@ -70,66 +58,11 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io } else { - if (extruderCount > 1) - { - CheckIfNeedToSwitchExtruders(line); - } - commandQueue.Add(line); } } } - private void CheckIfNeedToSwitchExtruders(string lineIn) - { - if(lineIn == null) - { - return; - } - - var lineNoComment = lineIn.Split(';')[0]; - - TrackExtruderState(lineNoComment); - - if ((lineNoComment.StartsWith("G0 ") || lineNoComment.StartsWith("G1 ")) // is a G1 or G0 - && (lineNoComment.Contains("X") || lineNoComment.Contains("Y") || lineNoComment.Contains("Z")) // hase a move axis in it - && extruderLastSwitchedTo != requestedExtruder) // is different than the last extruder set - { - string gcodeToQueue = ""; - switch (requestedExtruder) - { - case 0: - gcodeToQueue = printer.Settings.GetValue(SettingsKey.before_toolchange_gcode).Replace("\\n", "\n"); - break; - case 1: - gcodeToQueue = printer.Settings.GetValue(SettingsKey.before_toolchange_gcode_1).Replace("\\n", "\n"); - break; - } - - if (gcodeToQueue.Trim().Length > 0) - { - if (gcodeToQueue.Contains("\n")) - { - string[] linesToWrite = gcodeToQueue.Split(new string[] { "\n" }, StringSplitOptions.None); - for (int i = 0; i < linesToWrite.Length; i++) - { - string gcodeLine = linesToWrite[i].Trim(); - if (gcodeLine.Length > 0) - { - commandQueue.Add(gcodeLine); - } - } - } - else - { - commandQueue.Add(gcodeToQueue); - } - } - - extruderLastSwitchedTo = requestedExtruder; - } - } - public void Cancel() { Reset(); @@ -185,30 +118,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io lineToSend = base.ReadLine(); } - TrackExtruderState(lineToSend); - return lineToSend; } - private void TrackExtruderState(string line) - { - if (line == null) - { - return; - } - - if (line.StartsWith("G28)")) - { - extruderLastSwitchedTo = 0; - requestedExtruder = 0; - } - - if (line.StartsWith("T")) - { - GCodeFile.GetFirstNumberAfter("T", line, ref requestedExtruder); - } - } - public void Reset() { lock (locker) diff --git a/MatterControlLib/PrinterCommunication/Io/SwitchExtruderStream.cs b/MatterControlLib/PrinterCommunication/Io/SwitchExtruderStream.cs new file mode 100644 index 000000000..42422430c --- /dev/null +++ b/MatterControlLib/PrinterCommunication/Io/SwitchExtruderStream.cs @@ -0,0 +1,157 @@ +/* +Copyright (c) 2015, 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; +using System.Collections.Generic; +using MatterControl.Printing; +using MatterHackers.MatterControl.SlicerConfiguration; + +namespace MatterHackers.MatterControl.PrinterCommunication.Io +{ + public class SwitchExtruderStream : GCodeStreamProxy + { + private List commandQueue = new List(); + private object locker = new object(); + private int requestedExtruder; + private int extruderLastSwitchedTo; + PrinterMove lastDestination = PrinterMove.Unknown; + int extruderCount = 0; + + public SwitchExtruderStream(PrinterConfig printer, GCodeStream internalStream) + : base(printer, internalStream) + { + extruderCount = printer.Settings.GetValue(SettingsKey.extruder_count); + } + + private bool CheckIfNeedToSwitchExtruders(string lineIn) + { + bool queuedSwitch = false; + if (lineIn == null) + { + return queuedSwitch; + } + + var lineNoComment = lineIn.Split(';')[0]; + + TrackExtruderState(lineNoComment); + + if ((lineNoComment.StartsWith("G0 ") || lineNoComment.StartsWith("G1 ")) // is a G1 or G0 + && (lineNoComment.Contains("X") || lineNoComment.Contains("Y") || lineNoComment.Contains("Z")) // hase a move axis in it + && extruderLastSwitchedTo != requestedExtruder) // is different than the last extruder set + { + string gcodeToQueue = ""; + switch (requestedExtruder) + { + case 0: + gcodeToQueue = printer.Settings.GetValue(SettingsKey.before_toolchange_gcode).Replace("\\n", "\n"); + break; + case 1: + gcodeToQueue = printer.Settings.GetValue(SettingsKey.before_toolchange_gcode_1).Replace("\\n", "\n"); + break; + } + + if (gcodeToQueue.Trim().Length > 0) + { + if (gcodeToQueue.Contains("\n")) + { + string[] linesToWrite = gcodeToQueue.Split(new string[] { "\n" }, StringSplitOptions.None); + for (int i = 0; i < linesToWrite.Length; i++) + { + string gcodeLine = linesToWrite[i].Trim(); + if (gcodeLine.Length > 0) + { + commandQueue.Add(gcodeLine); + } + } + } + else + { + commandQueue.Add(gcodeToQueue); + } + + commandQueue.Add(lineIn); + queuedSwitch = true; + } + + extruderLastSwitchedTo = requestedExtruder; + } + + return queuedSwitch; + } + + public override string ReadLine() + { + string lineToSend = null; + + // lock queue + lock (locker) + { + if (commandQueue.Count > 0) + { + lineToSend = commandQueue[0]; + lineToSend = printer.ReplaceMacroValues(lineToSend); + commandQueue.RemoveAt(0); + } + } + + if (lineToSend == null) + { + lineToSend = base.ReadLine(); + } + + if(CheckIfNeedToSwitchExtruders(lineToSend)) + { + return ""; + } + + TrackExtruderState(lineToSend); + + return lineToSend; + } + + private void TrackExtruderState(string line) + { + if (line == null) + { + return; + } + + if (line.StartsWith("G28)")) + { + extruderLastSwitchedTo = 0; + requestedExtruder = 0; + } + + if (line.StartsWith("T")) + { + GCodeFile.GetFirstNumberAfter("T", line, ref requestedExtruder); + } + } + } +} \ No newline at end of file diff --git a/MatterControlLib/PrinterCommunication/PrinterConnection.cs b/MatterControlLib/PrinterCommunication/PrinterConnection.cs index 6971040f7..e66b082cc 100644 --- a/MatterControlLib/PrinterCommunication/PrinterConnection.cs +++ b/MatterControlLib/PrinterCommunication/PrinterConnection.cs @@ -2133,7 +2133,15 @@ You will then need to logout and log back in to the computer for the changes to } queuedCommandStream3 = new QueuedCommandsStream(Printer, firstStreamToRead); - relativeToAbsoluteStream4 = new RelativeToAbsoluteStream(Printer, queuedCommandStream3); + if (ExtruderCount > 1) + { + var switchExtruderStream = new SwitchExtruderStream(Printer, queuedCommandStream3); + relativeToAbsoluteStream4 = new RelativeToAbsoluteStream(Printer, switchExtruderStream); + } + else + { + relativeToAbsoluteStream4 = new RelativeToAbsoluteStream(Printer, queuedCommandStream3); + } bool enableLineSpliting = gcodeFilename != null && Printer.Settings.GetValue(SettingsKey.enable_line_splitting); babyStepsStream5 = new BabyStepsStream(Printer, relativeToAbsoluteStream4, enableLineSpliting ? 1 : 2000); printLevelingStream6 = new PrintLevelingStream(Printer, babyStepsStream5, true); From a10e7f5413deb998d898a8d061985c4636bed988 Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 19 Feb 2019 15:31:11 -0800 Subject: [PATCH 09/13] Use Queue type --- .../PrinterCommunication/Io/SwitchExtruderStream.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/MatterControlLib/PrinterCommunication/Io/SwitchExtruderStream.cs b/MatterControlLib/PrinterCommunication/Io/SwitchExtruderStream.cs index 42422430c..a09c1f158 100644 --- a/MatterControlLib/PrinterCommunication/Io/SwitchExtruderStream.cs +++ b/MatterControlLib/PrinterCommunication/Io/SwitchExtruderStream.cs @@ -36,7 +36,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io { public class SwitchExtruderStream : GCodeStreamProxy { - private List commandQueue = new List(); + private Queue commandQueue = new Queue(); private object locker = new object(); private int requestedExtruder; private int extruderLastSwitchedTo; @@ -86,16 +86,16 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io string gcodeLine = linesToWrite[i].Trim(); if (gcodeLine.Length > 0) { - commandQueue.Add(gcodeLine); + commandQueue.Enqueue(gcodeLine); } } } else { - commandQueue.Add(gcodeToQueue); + commandQueue.Enqueue(gcodeToQueue); } - commandQueue.Add(lineIn); + commandQueue.Enqueue(lineIn); queuedSwitch = true; } @@ -114,9 +114,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io { if (commandQueue.Count > 0) { - lineToSend = commandQueue[0]; + lineToSend = commandQueue.Dequeue(); lineToSend = printer.ReplaceMacroValues(lineToSend); - commandQueue.RemoveAt(0); } } From ef94c9e7f62c8fdd61f4bf4e4d362a393fa2cde4 Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 19 Feb 2019 15:36:30 -0800 Subject: [PATCH 10/13] Add SwitchExtruderStream to GCode export --- MatterControlLib/Library/Export/GCodeExport.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MatterControlLib/Library/Export/GCodeExport.cs b/MatterControlLib/Library/Export/GCodeExport.cs index 476ae6c21..497809e8c 100644 --- a/MatterControlLib/Library/Export/GCodeExport.cs +++ b/MatterControlLib/Library/Export/GCodeExport.cs @@ -287,6 +287,11 @@ namespace MatterHackers.MatterControl.Library.Export var queueStream = new QueuedCommandsStream(printer, gCodeBaseStream); GCodeStream accumulatedStream = queueStream; + if (printer.Settings.GetValue(SettingsKey.extruder_count) > 1) + { + accumulatedStream = new SwitchExtruderStream(printer, accumulatedStream); + } + accumulatedStream = new RelativeToAbsoluteStream(printer, accumulatedStream); bool levelingEnabled = printer.Settings.GetValue(SettingsKey.print_leveling_enabled) && applyLeveling; From 26b22980d15d33c6ac7eca0103d8f353159b59c3 Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 19 Feb 2019 15:39:02 -0800 Subject: [PATCH 11/13] Rename type --- MatterControlLib/Library/Export/GCodeExport.cs | 2 +- .../Io/{SwitchExtruderStream.cs => ToolChangeStream.cs} | 6 +++--- MatterControlLib/PrinterCommunication/PrinterConnection.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename MatterControlLib/PrinterCommunication/Io/{SwitchExtruderStream.cs => ToolChangeStream.cs} (96%) diff --git a/MatterControlLib/Library/Export/GCodeExport.cs b/MatterControlLib/Library/Export/GCodeExport.cs index 497809e8c..94a33381a 100644 --- a/MatterControlLib/Library/Export/GCodeExport.cs +++ b/MatterControlLib/Library/Export/GCodeExport.cs @@ -289,7 +289,7 @@ namespace MatterHackers.MatterControl.Library.Export if (printer.Settings.GetValue(SettingsKey.extruder_count) > 1) { - accumulatedStream = new SwitchExtruderStream(printer, accumulatedStream); + accumulatedStream = new ToolChangeStream(printer, accumulatedStream); } accumulatedStream = new RelativeToAbsoluteStream(printer, accumulatedStream); diff --git a/MatterControlLib/PrinterCommunication/Io/SwitchExtruderStream.cs b/MatterControlLib/PrinterCommunication/Io/ToolChangeStream.cs similarity index 96% rename from MatterControlLib/PrinterCommunication/Io/SwitchExtruderStream.cs rename to MatterControlLib/PrinterCommunication/Io/ToolChangeStream.cs index a09c1f158..9eb22c638 100644 --- a/MatterControlLib/PrinterCommunication/Io/SwitchExtruderStream.cs +++ b/MatterControlLib/PrinterCommunication/Io/ToolChangeStream.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2015, Lars Brubaker +Copyright (c) 2019, Lars Brubaker, John Lewin All rights reserved. Redistribution and use in source and binary forms, with or without @@ -34,7 +34,7 @@ using MatterHackers.MatterControl.SlicerConfiguration; namespace MatterHackers.MatterControl.PrinterCommunication.Io { - public class SwitchExtruderStream : GCodeStreamProxy + public class ToolChangeStream : GCodeStreamProxy { private Queue commandQueue = new Queue(); private object locker = new object(); @@ -43,7 +43,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io PrinterMove lastDestination = PrinterMove.Unknown; int extruderCount = 0; - public SwitchExtruderStream(PrinterConfig printer, GCodeStream internalStream) + public ToolChangeStream(PrinterConfig printer, GCodeStream internalStream) : base(printer, internalStream) { extruderCount = printer.Settings.GetValue(SettingsKey.extruder_count); diff --git a/MatterControlLib/PrinterCommunication/PrinterConnection.cs b/MatterControlLib/PrinterCommunication/PrinterConnection.cs index e66b082cc..9ce2571e7 100644 --- a/MatterControlLib/PrinterCommunication/PrinterConnection.cs +++ b/MatterControlLib/PrinterCommunication/PrinterConnection.cs @@ -2135,7 +2135,7 @@ You will then need to logout and log back in to the computer for the changes to queuedCommandStream3 = new QueuedCommandsStream(Printer, firstStreamToRead); if (ExtruderCount > 1) { - var switchExtruderStream = new SwitchExtruderStream(Printer, queuedCommandStream3); + var switchExtruderStream = new ToolChangeStream(Printer, queuedCommandStream3); relativeToAbsoluteStream4 = new RelativeToAbsoluteStream(Printer, switchExtruderStream); } else From d26b786b1e0817b18dfb35f8e79994116f4802ba Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 19 Feb 2019 16:01:08 -0800 Subject: [PATCH 12/13] Remove Trim and StringBuilder reassignment --- .../PrintLeveling/LevelingFunctions.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/LevelingFunctions.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/LevelingFunctions.cs index a104318ce..47c96135a 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/LevelingFunctions.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/LevelingFunctions.cs @@ -128,7 +128,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling double feedRate = 0; GCodeFile.GetFirstNumberAfter("F", lineBeingSent, ref feedRate); - StringBuilder newLine = new StringBuilder("G1 "); + var newLine = new StringBuilder("G1"); if (lineBeingSent.Contains("X") || lineBeingSent.Contains("Y") || lineBeingSent.Contains("Z")) { @@ -136,20 +136,20 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling lastDestinationWithLevelingApplied = outPosition; - newLine = newLine.Append($"X{outPosition.X:0.##} Y{outPosition.Y:0.##} Z{outPosition.Z:0.##} "); + newLine.Append($" X{outPosition.X:0.##} Y{outPosition.Y:0.##} Z{outPosition.Z:0.##}"); } if (lineBeingSent.Contains("E")) { - newLine = newLine.Append($"E{extruderDelta:0.###} "); + newLine.Append($" E{extruderDelta:0.###}"); } if (lineBeingSent.Contains("F")) { - newLine = newLine.Append($"F{feedRate:0.##}"); + newLine.Append($" F{feedRate:0.##}"); } - return newLine.ToString().Trim(); + return newLine.ToString(); } public Vector3 GetPositionWithZOffset(Vector3 currentDestination) From 1ca0151eb6313b095ad12e27a62efe9256468a17 Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 19 Feb 2019 16:02:36 -0800 Subject: [PATCH 13/13] Ignore WIP test --- Tests/MatterControl.Tests/MatterControl/GCodeStreamTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/MatterControl.Tests/MatterControl/GCodeStreamTests.cs b/Tests/MatterControl.Tests/MatterControl/GCodeStreamTests.cs index bf1a03dc6..5d01fa2ce 100644 --- a/Tests/MatterControl.Tests/MatterControl/GCodeStreamTests.cs +++ b/Tests/MatterControl.Tests/MatterControl/GCodeStreamTests.cs @@ -559,7 +559,7 @@ namespace MatterControl.Tests.MatterControl } } - [Test, Category("GCodeStream")] + [Test, Category("GCodeStream"), Ignore("WIP")] public void SoftwareEndstopstreamTests() { string[] inputLines = new string[]