adding the ability to copy paths to make debugging easier

This commit is contained in:
LarsBrubaker 2020-08-22 08:12:34 -07:00
parent 42b337ce10
commit 8ab0d4d03a
4 changed files with 88 additions and 10 deletions

View file

@ -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));

View file

@ -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<List<Vector2>> GetExtrusionsForLayer(this GCodeFile gcode, int layerIndex)
{
var extrusions = new List<List<Vector2>>();
bool addingExtrudePath = false;
List<Vector2> 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<Vector2>();
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 = ", ";
}
}

View file

@ -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,

@ -1 +1 @@
Subproject commit 389ba8e0b825410e527738dec8861c6003120bdf
Subproject commit fde99f581b0fad6943a680495a8b7970f50dd792