Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

/**
* This class implements a driver for a generic GRBL GCode Lasercutter.
Expand Down Expand Up @@ -479,19 +477,19 @@ protected String formatDouble(double value, int decimalPlaces)
return coordinateFormat.format(value);
}

protected void writeVectorGCode(VectorPart vp, double resolution) throws UnsupportedEncodingException, IOException {
protected void writeVectorGCode(VectorPart vp, double resolution, boolean flipShouldAlsoTranslate) throws UnsupportedEncodingException, IOException {
for (VectorCommand cmd : vp.getCommandList()) {
switch (cmd.getType()) {
// TODO: x,y should be changed to double because GCode has infinite vector resolution anyway
case MOVETO:
int x = (int) cmd.getX();
int y = (int) cmd.getY();
move(out, x, y, resolution);
move(out, x, y, resolution, flipShouldAlsoTranslate);
break;
case LINETO:
x = (int) cmd.getX();
y = (int) cmd.getY();
line(out, x, y, resolution);
line(out, x, y, resolution, flipShouldAlsoTranslate);
break;
case SETPROPERTY:
FloatPowerSpeedFocusProperty p = (FloatPowerSpeedFocusProperty) cmd.getProperty();
Expand Down Expand Up @@ -529,9 +527,9 @@ protected void setFocus(PrintStream out, double focus) throws IOException {
}
}

protected void move(PrintStream out, double x, double y, double resolution) throws IOException {
x = isFlipXaxis() ? getBedWidth() - Util.px2mm(x, resolution) : Util.px2mm(x, resolution);
y = isFlipYaxis() ? getBedHeight() - Util.px2mm(y, resolution) : Util.px2mm(y, resolution);
protected void move(PrintStream out, double x, double y, double resolution, boolean flipShouldAlsoTranslate) throws IOException {
x = isFlipXaxis() ? (flipShouldAlsoTranslate ? getBedWidth() : 0) - Util.px2mm(x, resolution) : Util.px2mm(x, resolution);
y = isFlipYaxis() ? (flipShouldAlsoTranslate ? getBedHeight() : 0) - Util.px2mm(y, resolution) : Util.px2mm(y, resolution);
currentSpeed = getTravel_speed();

if (blankLaserDuringRapids)
Expand All @@ -545,9 +543,9 @@ protected void move(PrintStream out, double x, double y, double resolution) thro
}
}

protected void line(PrintStream out, double x, double y, double resolution) throws IOException {
x = isFlipXaxis() ? getBedWidth() - Util.px2mm(x, resolution) : Util.px2mm(x, resolution);
y = isFlipYaxis() ? getBedHeight() - Util.px2mm(y, resolution) : Util.px2mm(y, resolution);
protected void line(PrintStream out, double x, double y, double resolution, boolean flipShouldAlsoTranslate) throws IOException {
x = isFlipXaxis() ? (flipShouldAlsoTranslate ? getBedWidth() : 0) - Util.px2mm(x, resolution) : Util.px2mm(x, resolution);
y = isFlipYaxis() ? (flipShouldAlsoTranslate ? getBedHeight() : 0) - Util.px2mm(y, resolution) : Util.px2mm(y, resolution);
String append = "";

if (nextPower != currentPower)
Expand Down Expand Up @@ -982,6 +980,12 @@ public void sendJob(LaserJob job, ProgressListener pl, List<String> warnings) th
}

public void writeJobCode(LaserJob job, ProgressListener pl) throws IOException {

boolean flipShouldAlsoTranslate = true;
if (job.getTransformedOriginX() != 0 || job.getTransformedOriginY() != 0) {
flipShouldAlsoTranslate = false;
}

writeInitializationCode();
pl.progressChanged(this, 20);
int i = 0;
Expand All @@ -1000,7 +1004,7 @@ public void writeJobCode(LaserJob job, ProgressListener pl) throws IOException {
{
//TODO: in direct mode use progress listener to indicate progress
//of individual job
writeVectorGCode((VectorPart) p, p.getDPI());
writeVectorGCode((VectorPart) p, p.getDPI(), flipShouldAlsoTranslate);
}
i++;
pl.progressChanged(this, 20 + (int) (i*(double) 60/max));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/de/thomas_oster/liblasercut/drivers/Grbl.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ protected String waitForIdentificationLine(ProgressListener pl) throws IOExcepti
* Doesn't include travel speed since grbl ignores that anyway.
*/
@Override
protected void move(PrintStream out, double x, double y, double resolution) throws IOException {
x = isFlipXaxis() ? getBedWidth() - Util.px2mm(x, resolution) : Util.px2mm(x, resolution);
y = isFlipYaxis() ? getBedHeight() - Util.px2mm(y, resolution) : Util.px2mm(y, resolution);
protected void move(PrintStream out, double x, double y, double resolution, boolean flipShouldAlsoTranslate) throws IOException {
x = isFlipXaxis() ? (flipShouldAlsoTranslate ? getBedWidth() : 0) - Util.px2mm(x, resolution) : Util.px2mm(x, resolution);
y = isFlipYaxis() ? (flipShouldAlsoTranslate ? getBedHeight() : 0) - Util.px2mm(y, resolution) : Util.px2mm(y, resolution);
currentSpeed = getTravel_speed();
if (blankLaserDuringRapids)
{
Expand Down