diff --git a/MatterControl.OpenGL/GCodeRenderer/GCodeRenderer.cs b/MatterControl.OpenGL/GCodeRenderer/GCodeRenderer.cs index bb1a7f43c..1423f9506 100644 --- a/MatterControl.OpenGL/GCodeRenderer/GCodeRenderer.cs +++ b/MatterControl.OpenGL/GCodeRenderer/GCodeRenderer.cs @@ -183,7 +183,7 @@ namespace MatterHackers.GCodeVisualizer { try { - return renderFeatures[layerIndex][featureIndex - 1]; + return renderFeatures[layerIndex][featureIndex]; } catch { diff --git a/MatterControlLib/CustomWidgets/GCodeSketch.cs b/MatterControlLib/CustomWidgets/GCodeSketch.cs index cc8f653de..cb27ac6c5 100644 --- a/MatterControlLib/CustomWidgets/GCodeSketch.cs +++ b/MatterControlLib/CustomWidgets/GCodeSketch.cs @@ -70,6 +70,12 @@ namespace MatterHackers.MatterControl } } + public void SetTool(string toolChange) + { + this.WriteRaw(toolChange); + this.ResetE(); + } + public void MoveTo(double x, double y, bool retract = false) { this.MoveTo(new Vector2(x, y), retract); diff --git a/MatterControlLib/CustomWidgets/NozzleOffsetCalibrationPage.cs b/MatterControlLib/CustomWidgets/NozzleOffsetCalibrationPage.cs index a8d0d2a5c..d6cc84903 100644 --- a/MatterControlLib/CustomWidgets/NozzleOffsetCalibrationPage.cs +++ b/MatterControlLib/CustomWidgets/NozzleOffsetCalibrationPage.cs @@ -58,8 +58,6 @@ namespace MatterHackers.MatterControl templatePrinter = new NozzleOffsetTemplatePrinter(printer); - contentRow.AddChild(new TextWidget("Printing Calibration Guide".Localize(), pointSize: theme.DefaultFontSize, textColor: theme.TextColor)); - contentRow.AddChild(xOffsetWidget = new NozzleOffsetTemplateWidget(templatePrinter.ActiveOffsets, FlowDirection.LeftToRight, theme) { Padding = new BorderDouble(left: 4) @@ -85,18 +83,27 @@ namespace MatterHackers.MatterControl { Margin = new BorderDouble(top: 15), Padding = new BorderDouble(top: 4), - Width = 300 + Width = 110 }); var verticalColumn = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.Stretch, - VAnchor = VAnchor.Stretch + VAnchor = VAnchor.Stretch, + Margin = 40 }; container.AddChild(verticalColumn); - verticalColumn.AddChild(xOffsetText = new TextWidget("".Localize(), pointSize: theme.DefaultFontSize, textColor: theme.TextColor)); - verticalColumn.AddChild(yOffsetText = new TextWidget("".Localize(), pointSize: theme.DefaultFontSize, textColor: theme.TextColor)); + verticalColumn.AddChild(xOffsetText = new TextWidget("".Localize(), pointSize: theme.DefaultFontSize, textColor: theme.TextColor) + { + Width = 200, + Margin = new BorderDouble(bottom: 10) + }); + + verticalColumn.AddChild(yOffsetText = new TextWidget("".Localize(), pointSize: theme.DefaultFontSize, textColor: theme.TextColor) + { + Width = 200 + }); yOffsetWidget.OffsetChanged += (s, e) => { @@ -128,14 +135,23 @@ namespace MatterHackers.MatterControl Task.Run(async () => { - string gcode1 = templatePrinter.BuildTemplate(verticalLayout: true); - string gcode2 = templatePrinter.BuildTemplate(verticalLayout: false); + var gcodeSketch = new GCodeSketch() + { + Speed = (int)(printer.Settings.GetValue(SettingsKey.first_layer_speed) * 60) + }; + + //gcodeSketch.WriteRaw("G92 E0"); + gcodeSketch.WriteRaw("; LAYER: 0"); + gcodeSketch.WriteRaw("; LAYER_HEIGHT: 0.2"); + + templatePrinter.BuildTemplate(gcodeSketch, verticalLayout: true); + templatePrinter.BuildTemplate(gcodeSketch, verticalLayout: false); string outputPath = Path.Combine( ApplicationDataStorage.Instance.GCodeOutputPath, $"nozzle-offset-template-combined.gcode"); - File.WriteAllText(outputPath, gcode1 + "\n" + gcode2); + File.WriteAllText(outputPath, gcodeSketch.ToGCode()); // HACK: update state needed to be set before calling StartPrint printer.Connection.CommunicationState = CommunicationStates.PreparingToPrint; @@ -162,8 +178,8 @@ namespace MatterHackers.MatterControl { printer.Connection.MoveRelative(PrinterConnection.Axis.Z, 20, printer.Settings.Helpers.ManualMovementSpeeds().Z); - printer.Connection.MoveAbsolute(PrinterConnection.Axis.Y, - printer.Bed.Bounds.Top, + printer.Connection.MoveAbsolute(PrinterConnection.Axis.Y, + printer.Bed.Bounds.Top, printer.Settings.Helpers.ManualMovementSpeeds().Y); } }); diff --git a/MatterControlLib/CustomWidgets/NozzleOffsetTemplatePrinter.cs b/MatterControlLib/CustomWidgets/NozzleOffsetTemplatePrinter.cs index 92a299dc9..e2cafefb1 100644 --- a/MatterControlLib/CustomWidgets/NozzleOffsetTemplatePrinter.cs +++ b/MatterControlLib/CustomWidgets/NozzleOffsetTemplatePrinter.cs @@ -74,46 +74,10 @@ namespace MatterHackers.MatterControl public bool DebugMode { get; private set; } = false; - public Task PrintTemplate(bool verticalLayout) + + public void BuildTemplate(GCodeSketch gcodeSketch, bool verticalLayout) { - return Task.Run(async ()=> - { - string gcode = this.BuildTemplate(verticalLayout); - - string outputPath = Path.Combine( - ApplicationDataStorage.Instance.GCodeOutputPath, - $"nozzle-offset-template{ (verticalLayout ? 1 : 2) }.gcode"); - - File.WriteAllText(outputPath, gcode); - - // HACK: update state needed to be set before calling StartPrint - printer.Connection.CommunicationState = CommunicationStates.PreparingToPrint; - - await printer.Connection.StartPrint(outputPath); - - // Wait for print start - while (!printer.Connection.PrintIsActive) - { - Thread.Sleep(500); - } - - // Wait for print finished - while (printer.Connection.PrintIsActive) - { - Thread.Sleep(500); - } - }); - } - - public string BuildTemplate(bool verticalLayout) - { - var gcodeSketch = new GCodeSketch() - { - Speed = firstLayerSpeed - }; - - //gcodeSketch.WriteRaw("G92 E0"); - gcodeSketch.WriteRaw("T0"); + gcodeSketch.SetTool("T0"); gcodeSketch.WriteRaw($"G1 Z0.2 F{firstLayerSpeed}"); if (verticalLayout) @@ -203,8 +167,7 @@ namespace MatterHackers.MatterControl y1 = rect.Top + (nozzleWidth * .5); y2 = y1 - sectionHeight + (nozzleWidth * .5); - gcodeSketch.WriteRaw("T1"); - gcodeSketch.ResetE(); + gcodeSketch.SetTool("T1"); gcodeSketch.MoveTo(rect.Left, rect.Top); @@ -238,8 +201,6 @@ namespace MatterHackers.MatterControl } gcodeSketch.PenUp(); - - return gcodeSketch.ToGCode(); } private RectangleDouble CreatePerimeters(GCodeSketch gcodeSketch, RectangleDouble rect) diff --git a/MatterControlLib/PartPreviewWindow/GCodeDetails/GCodeDebugView.cs b/MatterControlLib/PartPreviewWindow/GCodeDetails/GCodeDebugView.cs index 467994188..f8268120a 100644 --- a/MatterControlLib/PartPreviewWindow/GCodeDetails/GCodeDebugView.cs +++ b/MatterControlLib/PartPreviewWindow/GCodeDetails/GCodeDebugView.cs @@ -79,7 +79,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)); + int activeFeatureIndex = Math.Max(0, Math.Min(featureIndex, featuresOnLayer - 1)); if (sceneContext.GCodeRenderer[layerIndex, activeFeatureIndex] is RenderFeatureTravel line) {