Merge pull request #4307 from jlewin/master

Prevent StringBuilder from doubling up results
This commit is contained in:
Lars Brubaker 2019-02-23 11:10:51 -08:00 committed by GitHub
commit 329f944879
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 56 deletions

View file

@ -183,7 +183,7 @@ namespace MatterHackers.GCodeVisualizer
{
try
{
return renderFeatures[layerIndex][featureIndex - 1];
return renderFeatures[layerIndex][featureIndex];
}
catch
{

View file

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

View file

@ -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<double>(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);
}
});

View file

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

View file

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