From b2a54fd2973093cdf8d779cc0b79c5aff58b0821 Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 9 Apr 2019 11:04:41 -0700 Subject: [PATCH] Extract StreamProcessor tool for interactive debugging --- MatterControl.Winforms/InspectForm.cs | 11 +-------- .../CustomWidgets/ExtensionMethods.cs | 23 +++++++++++++++++++ .../Io/ProcessWriteRegExStream.cs | 4 +--- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/MatterControl.Winforms/InspectForm.cs b/MatterControl.Winforms/InspectForm.cs index d7469d804..79cb4a065 100644 --- a/MatterControl.Winforms/InspectForm.cs +++ b/MatterControl.Winforms/InspectForm.cs @@ -509,16 +509,7 @@ namespace MatterHackers.MatterControl private void button1_Click(object sender, EventArgs e) { var context = ApplicationController.Instance.ActivePrinters.First().Connection.TotalGCodeStream; - - var sb = new StringBuilder(); - - while (context is GCodeStream gCodeStream) - { - sb.AppendFormat("{0} {1}\r\n", gCodeStream.GetType().Name, gCodeStream.DebugInfo); - context = gCodeStream.InternalStream; - } - - textBox1.Text = sb.ToString(); + textBox1.Text = context.GetDebugState(); } } } diff --git a/MatterControlLib/CustomWidgets/ExtensionMethods.cs b/MatterControlLib/CustomWidgets/ExtensionMethods.cs index 97306c6f7..41cc0fd71 100644 --- a/MatterControlLib/CustomWidgets/ExtensionMethods.cs +++ b/MatterControlLib/CustomWidgets/ExtensionMethods.cs @@ -28,11 +28,13 @@ either expressed or implied, of the FreeBSD Project. */ using System.Linq; +using System.Text; using MatterHackers.Agg.Image; using MatterHackers.Agg.UI; using MatterHackers.DataConverters3D; using MatterHackers.ImageProcessing; using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.PrinterCommunication.Io; namespace MatterHackers.MatterControl { @@ -61,5 +63,26 @@ namespace MatterHackers.MatterControl { return sourceImage.AnyAlphaToColor(ApplicationController.Instance.Theme.PrimaryAccentColor); } + + + public static string GetDebugState(this GCodeStream sourceStream) + { + return GetDebugState(sourceStream, ApplicationController.Instance.ActivePrinters.First()); + } + + public static string GetDebugState(this GCodeStream sourceStream, PrinterConfig printer) + { + var context = printer.Connection.TotalGCodeStream; + + var sb = new StringBuilder(); + + while (context is GCodeStream gCodeStream) + { + sb.AppendFormat("{0} {1}\r\n", gCodeStream.GetType().Name, gCodeStream.DebugInfo); + context = gCodeStream.InternalStream; + } + + return sb.ToString(); + } } } diff --git a/MatterControlLib/PrinterCommunication/Io/ProcessWriteRegExStream.cs b/MatterControlLib/PrinterCommunication/Io/ProcessWriteRegExStream.cs index 6d902776f..1c4640171 100644 --- a/MatterControlLib/PrinterCommunication/Io/ProcessWriteRegExStream.cs +++ b/MatterControlLib/PrinterCommunication/Io/ProcessWriteRegExStream.cs @@ -101,15 +101,13 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io public static List ProcessWriteRegEx(string lineToWrite, PrinterConfig printer) { - var WriteLineReplacements = printer.Settings.Helpers.WriteLineReplacements; - var linesToWrite = new List(); linesToWrite.Add(lineToWrite); var addedLines = new List(); for (int i = 0; i < linesToWrite.Count; i++) { - foreach (var item in WriteLineReplacements) + foreach (var item in printer.Settings.Helpers.WriteLineReplacements) { var splitReplacement = item.Replacement.Split(','); if (splitReplacement.Length > 0)