From 8ab0d4d03a8064ff1b99fd19fe838764eae7705f Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Sat, 22 Aug 2020 08:12:34 -0700 Subject: [PATCH] adding the ability to copy paths to make debugging easier --- .../GCodeRenderer/GCodeRenderer.cs | 1 + .../GCodeDetails/GCodeDetails.cs | 55 ++++++++++++++++++- .../PartPreviewWindow/GCodePanel.cs | 40 ++++++++++++-- Submodules/MatterSlice | 2 +- 4 files changed, 88 insertions(+), 10 deletions(-) diff --git a/MatterControl.OpenGL/GCodeRenderer/GCodeRenderer.cs b/MatterControl.OpenGL/GCodeRenderer/GCodeRenderer.cs index d08fe0d59..a05844ae9 100644 --- a/MatterControl.OpenGL/GCodeRenderer/GCodeRenderer.cs +++ b/MatterControl.OpenGL/GCodeRenderer/GCodeRenderer.cs @@ -130,6 +130,7 @@ namespace MatterHackers.GCodeVisualizer // this is a retraction renderFeaturesForLayer.Add(new RenderFeatureRetract(instructionIndex, currentInstruction.Position, eMovement, currentInstruction.ToolIndex, currentInstruction.FeedRate)); } + if (currentInstruction.Line.StartsWith("G10")) { renderFeaturesForLayer.Add(new RenderFeatureRetract(instructionIndex, currentInstruction.Position, -1, currentInstruction.ToolIndex, currentInstruction.FeedRate)); diff --git a/MatterControlLib/PartPreviewWindow/GCodeDetails/GCodeDetails.cs b/MatterControlLib/PartPreviewWindow/GCodeDetails/GCodeDetails.cs index 3c584d1e6..242a94e5c 100644 --- a/MatterControlLib/PartPreviewWindow/GCodeDetails/GCodeDetails.cs +++ b/MatterControlLib/PartPreviewWindow/GCodeDetails/GCodeDetails.cs @@ -28,8 +28,10 @@ either expressed or implied, of the FreeBSD Project. */ using System; +using System.Collections.Generic; using MatterControl.Printing; using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.PartPreviewWindow { @@ -156,6 +158,52 @@ namespace MatterHackers.MatterControl.PartPreviewWindow return loadedGCode.GetLayerTop(layerIndex); } + public static List> GetExtrusionsForLayer(this GCodeFile gcode, int layerIndex) + { + var extrusions = new List>(); + + bool addingExtrudePath = false; + List currentExtrudePath = null; + + int startRenderIndex = gcode.GetFirstLayerInstruction(layerIndex); + int endRenderIndex = gcode.LineCount - 1; + if (layerIndex < gcode.LayerCount - 1) + { + endRenderIndex = gcode.GetFirstLayerInstruction(layerIndex + 1); + } + + for (int instructionIndex = startRenderIndex; instructionIndex < endRenderIndex; instructionIndex++) + { + PrinterMachineInstruction currentInstruction = gcode.Instruction(instructionIndex); + PrinterMachineInstruction previousInstruction = currentInstruction; + if (instructionIndex > 0) + { + previousInstruction = gcode.Instruction(instructionIndex - 1); + } + + if (currentInstruction.Position != previousInstruction.Position) + { + if (gcode.IsExtruding(instructionIndex)) + { + if (addingExtrudePath) + { + currentExtrudePath = new List(); + extrusions.Add(currentExtrudePath); + addingExtrudePath = true; + } + + currentExtrudePath.Add(new Vector2(currentInstruction.Position.X, currentInstruction.Position.Y)); + } + else + { + addingExtrudePath = false; + } + } + } + + return extrusions; + } + public static string GetLayerFanSpeeds(this GCodeFile loadedGCode, int activeLayerIndex) { if (loadedGCode == null || loadedGCode.LayerCount == 0) @@ -164,10 +212,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } int startInstruction = loadedGCode.GetFirstLayerInstruction(activeLayerIndex); - if(activeLayerIndex == 0) + if (activeLayerIndex == 0) { startInstruction = 0; } + int endInstruction = loadedGCode.GetFirstLayerInstruction(activeLayerIndex + 1); string separator = ""; @@ -180,12 +229,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow fanSpeeds += separator + "Off"; separator = ", "; } - else if(line.StartsWith("M106")) // fan on + else if (line.StartsWith("M106")) // fan on { double speed = 0; if (GCodeFile.GetFirstNumberAfter("M106", line, ref speed, 0, "")) { - fanSpeeds += separator + $"{speed/255*100:0}%"; + fanSpeeds += separator + $"{speed / 255 * 100:0}%"; separator = ", "; } } diff --git a/MatterControlLib/PartPreviewWindow/GCodePanel.cs b/MatterControlLib/PartPreviewWindow/GCodePanel.cs index 2794d3121..7abef0143 100644 --- a/MatterControlLib/PartPreviewWindow/GCodePanel.cs +++ b/MatterControlLib/PartPreviewWindow/GCodePanel.cs @@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project. using System; using System.Collections.Generic; using System.Linq; +using System.Text; using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.Localizations; @@ -40,15 +41,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { public class GCodePanel : FlowLayoutWidget { - private ISceneContext sceneContext; - private ThemeConfig theme; - private PrinterConfig printer; - private PrinterTabPage printerTabPage; + private readonly ISceneContext sceneContext; + private readonly ThemeConfig theme; + private readonly PrinterConfig printer; + private readonly PrinterTabPage printerTabPage; private SectionWidget speedsWidget; - private GuiWidget loadedGCodeSection; + private readonly GuiWidget loadedGCodeSection; public GCodePanel(PrinterTabPage printerTabPage, PrinterConfig printer, ISceneContext sceneContext, ThemeConfig theme) - : base (FlowDirection.TopToBottom) + : base(FlowDirection.TopToBottom) { this.sceneContext = sceneContext; this.theme = theme; @@ -143,6 +144,32 @@ namespace MatterHackers.MatterControl.PartPreviewWindow VAnchor = VAnchor.Fit }); + var copyButton = new TextButton("copy", theme, 8) + { + Padding = 5, + Margin = new BorderDouble(0, 0, 15, 0), + VAnchor = VAnchor.Center | VAnchor.Fit, + ToolTipText = "Copy extrusions data".Localize() + }; + + copyButton.Click += (s, e) => + { + var output = new StringBuilder(); + // copy all the extrusions to the clipboard as paths + var extrusions = printer.Bed.LoadedGCode.GetExtrusionsForLayer(sceneContext.ActiveLayerIndex); + foreach (var extrusion in extrusions) + { + foreach (var position in extrusion) + { + output.Append($"x:{position.X:0.##}, y:{position.Y:0.##},"); + } + + output.Append("|"); + } + + Clipboard.Instance.SetText(output.ToString()); + }; + loadedGCodeSection.AddChild( new SectionWidget( "Layer".Localize(), @@ -154,6 +181,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow }, theme, serializationKey: "gcode_panel_layer_details", + rightAlignedContent: copyButton, expanded: true) { HAnchor = HAnchor.Stretch, diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index 389ba8e0b..fde99f581 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit 389ba8e0b825410e527738dec8861c6003120bdf +Subproject commit fde99f581b0fad6943a680495a8b7970f50dd792