From 457e31ef10d32974819b02fca4e094010d04580e Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Mon, 4 Mar 2019 08:04:29 -0800 Subject: [PATCH] Putting in info for tool change timing refactoring extruder index to tool index --- .../GCodeRenderer/GCodeRenderer.cs | 10 +++++----- .../RenderFeatures/RenderFeatureBase.cs | 4 ++-- .../RenderFeatures/RenderFeatureExtrusion.cs | 8 ++++---- .../RenderFeatures/RenderFeatureRetract.cs | 4 ++-- .../RenderFeatures/RenderFeatureTravel.cs | 6 +++--- .../GCode/GCodeMemoryFile.cs | 11 ++++++++++- .../GCode/PrinterMachineInstruction.cs | 4 ++-- .../GCodeDetails/GCodeDebugView.cs | 18 +++++++++++++----- 8 files changed, 41 insertions(+), 24 deletions(-) diff --git a/MatterControl.OpenGL/GCodeRenderer/GCodeRenderer.cs b/MatterControl.OpenGL/GCodeRenderer/GCodeRenderer.cs index 1423f9506..1a82b41b0 100644 --- a/MatterControl.OpenGL/GCodeRenderer/GCodeRenderer.cs +++ b/MatterControl.OpenGL/GCodeRenderer/GCodeRenderer.cs @@ -128,15 +128,15 @@ namespace MatterHackers.GCodeVisualizer if (Math.Abs(eMovement) > 0) { // this is a retraction - renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, eMovement, currentInstruction.ExtruderIndex, currentInstruction.FeedRate)); + renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, eMovement, currentInstruction.ToolIndex, currentInstruction.FeedRate)); } if (currentInstruction.Line.StartsWith("G10")) { - renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, -1, currentInstruction.ExtruderIndex, currentInstruction.FeedRate)); + renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, -1, currentInstruction.ToolIndex, currentInstruction.FeedRate)); } else if (currentInstruction.Line.StartsWith("G11")) { - renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, 1, currentInstruction.ExtruderIndex, currentInstruction.FeedRate)); + renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, 1, currentInstruction.ToolIndex, currentInstruction.FeedRate)); } } else @@ -150,7 +150,7 @@ namespace MatterHackers.GCodeVisualizer new RenderFeatureExtrusion( previousInstruction.Position, currentInstruction.Position, - currentInstruction.ExtruderIndex, + currentInstruction.ToolIndex, currentInstruction.FeedRate, currentInstruction.EPosition - previousInstruction.EPosition, gCodeFileToDraw.GetFilamentDiameter(), @@ -164,7 +164,7 @@ namespace MatterHackers.GCodeVisualizer new RenderFeatureTravel( previousInstruction.Position, currentInstruction.Position, - currentInstruction.ExtruderIndex, + currentInstruction.ToolIndex, currentInstruction.FeedRate)); } } diff --git a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureBase.cs b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureBase.cs index 15e1ffd8c..763231a48 100644 --- a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureBase.cs +++ b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureBase.cs @@ -34,7 +34,7 @@ namespace MatterHackers.GCodeVisualizer { public abstract class RenderFeatureBase { - protected int extruderIndex; + protected int toolIndex; public static Color HighlightColor { get; set; } = new Color("#D0F476"); @@ -48,7 +48,7 @@ namespace MatterHackers.GCodeVisualizer public RenderFeatureBase(int extruderIndex) { - this.extruderIndex = extruderIndex; + this.toolIndex = extruderIndex; } static public void CreateCylinder(VectorPOD colorVertexData, VectorPOD indexData, Vector3 startPos, Vector3 endPos, double radius, int steps, Color color, double layerHeight) diff --git a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureExtrusion.cs b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureExtrusion.cs index 606046a05..02f5148a0 100644 --- a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureExtrusion.cs +++ b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureExtrusion.cs @@ -42,8 +42,8 @@ namespace MatterHackers.GCodeVisualizer private Color color; private Color gray; - public RenderFeatureExtrusion(Vector3 start, Vector3 end, int extruderIndex, double travelSpeed, double totalExtrusionMm, double filamentDiameterMm, double layerHeight, Color color, Color gray) - : base(start, end, extruderIndex, travelSpeed) + public RenderFeatureExtrusion(Vector3 start, Vector3 end, int toolIndex, double travelSpeed, double totalExtrusionMm, double filamentDiameterMm, double layerHeight, Color color, Color gray) + : base(start, end, toolIndex, travelSpeed) { this.color = color; this.gray = gray; @@ -101,7 +101,7 @@ namespace MatterHackers.GCodeVisualizer } else { - lineColor = renderInfo.GetMaterialColor(extruderIndex); + lineColor = renderInfo.GetMaterialColor(toolIndex); } CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, lineColor, layerHeight); @@ -130,7 +130,7 @@ namespace MatterHackers.GCodeVisualizer } else { - extrusionColor = renderInfo.GetMaterialColor(extruderIndex); + extrusionColor = renderInfo.GetMaterialColor(toolIndex); } if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion)) diff --git a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureRetract.cs b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureRetract.cs index 810bc79c8..689ec4d28 100644 --- a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureRetract.cs +++ b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureRetract.cs @@ -68,9 +68,9 @@ namespace MatterHackers.GCodeVisualizer var position = new Vector3(this.position); // retract and unretract are the extruder color - Color color = renderInfo.GetMaterialColor(extruderIndex); + Color color = renderInfo.GetMaterialColor(toolIndex); // except for extruder 0 where they are the red and blue we are familiar with - if (extruderIndex == 0) + if (toolIndex == 0) { if (extrusionAmount > 0) { diff --git a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureTravel.cs b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureTravel.cs index e4a8898a9..764f3ef67 100644 --- a/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureTravel.cs +++ b/MatterControl.OpenGL/GCodeRenderer/RenderFeatures/RenderFeatureTravel.cs @@ -45,10 +45,10 @@ namespace MatterHackers.GCodeVisualizer public Vector3Float End => end; - public RenderFeatureTravel(Vector3 start, Vector3 end, int extruderIndex, double travelSpeed) - : base(extruderIndex) + public RenderFeatureTravel(Vector3 start, Vector3 end, int toolIndex, double travelSpeed) + : base(toolIndex) { - this.extruderIndex = extruderIndex; + this.toolIndex = toolIndex; this.start = new Vector3Float(start); this.end = new Vector3Float(end); this.travelSpeed = (float)travelSpeed; diff --git a/MatterControl.Printing/GCode/GCodeMemoryFile.cs b/MatterControl.Printing/GCode/GCodeMemoryFile.cs index 732a7e48b..81e8227cb 100644 --- a/MatterControl.Printing/GCode/GCodeMemoryFile.cs +++ b/MatterControl.Printing/GCode/GCodeMemoryFile.cs @@ -47,6 +47,7 @@ namespace MatterControl.Printing private double diameterOfFilamentUsedMmCache = 0; private List layerHeights = new List(); + private List toolChanges = new List(); private List GCodeCommandQueue = new List(); private bool foundFirstLayerMarker; @@ -255,7 +256,7 @@ namespace MatterControl.Printing double extruderIndex = 0; if (GetFirstNumberAfter("T", lineString, ref extruderIndex)) { - machineInstructionForLine.ExtruderIndex = (int)extruderIndex; + machineInstructionForLine.ToolIndex = (int)extruderIndex; } break; @@ -349,6 +350,8 @@ namespace MatterControl.Printing Stopwatch maxProgressReport = new Stopwatch(); maxProgressReport.Start(); + int currentTool = 0; + for (int lineIndex = 0; lineIndex < GCodeCommandQueue.Count; lineIndex++) { PrinterMachineInstruction instruction = GCodeCommandQueue[lineIndex]; @@ -387,6 +390,12 @@ namespace MatterControl.Printing } } + if(instruction.ToolIndex != currentTool) + { + toolChanges.Add(lineIndex); + currentTool = instruction.ToolIndex; + } + if (feedRateMmPerMin > 0) { var timeForE = Estimator.GetSecondsForMovement(deltaEPositionThisLine, diff --git a/MatterControl.Printing/GCode/PrinterMachineInstruction.cs b/MatterControl.Printing/GCode/PrinterMachineInstruction.cs index bd8a78e05..6544396e3 100644 --- a/MatterControl.Printing/GCode/PrinterMachineInstruction.cs +++ b/MatterControl.Printing/GCode/PrinterMachineInstruction.cs @@ -71,14 +71,14 @@ namespace MatterControl.Printing EPosition = copy.EPosition; MovementType = copy.MovementType; SecondsToEndFromHere = copy.SecondsToEndFromHere; - ExtruderIndex = copy.ExtruderIndex; + ToolIndex = copy.ToolIndex; } public enum MovementTypes { Absolute, Relative }; public float EPosition { get; set; } - public int ExtruderIndex { get; set; } + public int ToolIndex { get; set; } public float FeedRate { get; set; } diff --git a/MatterControlLib/PartPreviewWindow/GCodeDetails/GCodeDebugView.cs b/MatterControlLib/PartPreviewWindow/GCodeDetails/GCodeDebugView.cs index f8268120a..de3429741 100644 --- a/MatterControlLib/PartPreviewWindow/GCodeDetails/GCodeDebugView.cs +++ b/MatterControlLib/PartPreviewWindow/GCodeDetails/GCodeDebugView.cs @@ -46,6 +46,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private TextWidget lengthWidget; private TextWidget yInterceptWidget; private TextWidget xInterceptWidget; + private TextWidget timeToToolChange; public GCodeDebugView(PrinterTabPage printerTabPage, GCodeFile gCodeMemoryFile, ISceneContext sceneContext, ThemeConfig theme) : base(theme) @@ -59,6 +60,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow slopeWidget = this.AddSetting("Slope".Localize(), ""); yInterceptWidget = this.AddSetting("Y Intercept".Localize(), ""); xInterceptWidget = this.AddSetting("X Intercept".Localize(), ""); + timeToToolChange = this.AddSetting("Tool Change".Localize(), ""); // Register listeners printerTabPage.LayerFeaturesScrollbar.SecondValueChanged += this.LayerFeaturesScrollbar_SecondValueChanged; @@ -79,7 +81,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow int featuresOnLayer = sceneContext.GCodeRenderer.GetNumFeatures(layerIndex); int featureIndex = (int)(featuresOnLayer * renderInfo.FeatureToEndOnRatio0To1 + .5); - int activeFeatureIndex = Math.Max(0, Math.Min(featureIndex, featuresOnLayer - 1)); + int activeFeatureIndex = Math.Max(0, Math.Min(featureIndex, featuresOnLayer - 1) - 1); if (sceneContext.GCodeRenderer[layerIndex, activeFeatureIndex] is RenderFeatureTravel line) { @@ -90,7 +92,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow endPointWidget.Text = $"{end}"; var length = new Vector2(start).Distance(new Vector2(end)); - lengthWidget.Text = $"{length}"; + lengthWidget.Text = $"{length:0.###}"; // Slope // m = (y_2 - y_1) / (x_2 - x_1) @@ -99,15 +101,21 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // n = -x_1 * (y_2 - y_1) / (x_2 - x_1) + y_1 var slope = (end.Y - start.Y) / (end.X - start.X); - slopeWidget.Text = $"{slope}"; + slopeWidget.Text = $"{slope:0.###}"; // -x_1 * (y_2 - y_1) / (x_2 - x_1) + y_1 var yIntercept = -start.X * slope + start.Y; - yInterceptWidget.Text = $"{yIntercept}"; + yInterceptWidget.Text = $"{yIntercept:0.###}"; // x_1 - y_1*(x_2-x_1)/(y_2-y_1) var xIntercept = start.X - start.Y * (end.X - start.X) / (end.Y - start.Y); - xInterceptWidget.Text = $"{xIntercept}"; + xInterceptWidget.Text = $"{xIntercept:0.###}"; + + // put in the time until the next tool change + if(timeToToolChange != null) + { + + } } } }