Skip to content
Closed
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 @@ -529,9 +529,15 @@ protected void setFocus(PrintStream out, double focus) throws IOException {
}
}

// Mirror pivot for a flipped axis: bedWidth/bedHeight when the job is referenced to the machine's
// homed origin, but 0 once applyStartPoint() has re-referenced it to a manually-jogged start point
// (there's no bed-width-away home corner to mirror around anymore). Set per job in sendJob().
protected transient double flipPivotX = 0;
protected transient double flipPivotY = 0;

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);
x = isFlipXaxis() ? flipPivotX - Util.px2mm(x, resolution) : Util.px2mm(x, resolution);
y = isFlipYaxis() ? flipPivotY - Util.px2mm(y, resolution) : Util.px2mm(y, resolution);
currentSpeed = getTravel_speed();

if (blankLaserDuringRapids)
Expand All @@ -546,8 +552,8 @@ 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);
x = isFlipXaxis() ? flipPivotX - Util.px2mm(x, resolution) : Util.px2mm(x, resolution);
y = isFlipYaxis() ? flipPivotY - Util.px2mm(y, resolution) : Util.px2mm(y, resolution);
String append = "";

if (nextPower != currentPower)
Expand Down Expand Up @@ -965,6 +971,8 @@ public void sendJob(LaserJob job, ProgressListener pl, List<String> warnings) th
this.jobName = job.getName() + ".gcode";
}
job.applyStartPoint();
flipPivotX = job.getTransformedOriginX() == 0 ? getBedWidth() : 0;
flipPivotY = job.getTransformedOriginY() == 0 ? getBedHeight() : 0;
pl.taskChanged(this, "connecting...");
connect(pl);
pl.taskChanged(this, "sending");
Expand Down
38 changes: 28 additions & 10 deletions src/main/java/de/thomas_oster/liblasercut/drivers/Ruida.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ public double getRasterPadding() {
return 0;
}

// Mirror pivot for a flipped axis: bedWidth/bedHeight when the job is referenced to the machine's
// homed origin, but 0 once applyStartPoint() has re-referenced it to a manually-jogged start point
// (there's no bed-width-away home corner to mirror around anymore). Set per job in writeJobCode().
private transient double flipPivotX = 0;
private transient double flipPivotY = 0;

private void find_and_write_bounding_box(LaserJob job) throws IOException
{
double minX = 0.0;
Expand All @@ -223,10 +229,15 @@ private void find_and_write_bounding_box(LaserJob job) throws IOException
/* compute bounding box */
for (JobPart p : job.getParts())
{
double min_x = isFlipXaxis() ? getBedWidth() - Util.px2mm(p.getMinX(), p.getDPI()) : Util.px2mm(p.getMinX(), p.getDPI());
double min_y = isFlipYaxis() ? getBedHeight() - Util.px2mm(p.getMinY(), p.getDPI()) : Util.px2mm(p.getMinY(), p.getDPI());
double max_x = isFlipXaxis() ? getBedWidth() - Util.px2mm(p.getMaxX(), p.getDPI()) : Util.px2mm(p.getMaxX(), p.getDPI());
double max_y = isFlipYaxis() ? getBedHeight() - Util.px2mm(p.getMaxY(), p.getDPI()) : Util.px2mm(p.getMaxY(), p.getDPI());
// flipping reverses min/max order, so re-sort instead of flipping each bound independently
double x1 = isFlipXaxis() ? flipPivotX - Util.px2mm(p.getMinX(), p.getDPI()) : Util.px2mm(p.getMinX(), p.getDPI());
double x2 = isFlipXaxis() ? flipPivotX - Util.px2mm(p.getMaxX(), p.getDPI()) : Util.px2mm(p.getMaxX(), p.getDPI());
double y1 = isFlipYaxis() ? flipPivotY - Util.px2mm(p.getMinY(), p.getDPI()) : Util.px2mm(p.getMinY(), p.getDPI());
double y2 = isFlipYaxis() ? flipPivotY - Util.px2mm(p.getMaxY(), p.getDPI()) : Util.px2mm(p.getMaxY(), p.getDPI());
double min_x = Math.min(x1, x2);
double max_x = Math.max(x1, x2);
double min_y = Math.min(y1, y2);
double max_y = Math.max(y1, y2);
if (first) {
minX = min_x;
maxX = max_x;
Expand Down Expand Up @@ -259,8 +270,8 @@ private void find_and_write_bounding_box(LaserJob job) throws IOException

private void vector(double x, double y, double dpi, boolean as_cut, boolean force_abs) throws IOException
{
double x_mm = isFlipXaxis() ? getBedWidth() - Util.px2mm(x, dpi) : Util.px2mm(x, dpi);
double y_mm = isFlipYaxis() ? getBedHeight() - Util.px2mm(y, dpi) : Util.px2mm(y, dpi);
double x_mm = isFlipXaxis() ? flipPivotX - Util.px2mm(x, dpi) : Util.px2mm(x, dpi);
double y_mm = isFlipYaxis() ? flipPivotY - Util.px2mm(y, dpi) : Util.px2mm(y, dpi);
boolean as_absolute;

/* compute distance to last known position */
Expand Down Expand Up @@ -543,6 +554,8 @@ public void writeJobCode(LaserJob job, ProgressListener pl) throws IOException {
last_y = Double.NaN;
vector_count = 0;
travel_distance = 0;
flipPivotX = job.getTransformedOriginX() == 0 ? getBedWidth() : 0;
flipPivotY = job.getTransformedOriginY() == 0 ? getBedHeight() : 0;

try {
stream = new ByteStream(out, (byte)0x88); // 0x11, 0x38
Expand Down Expand Up @@ -593,10 +606,15 @@ public void writeJobCode(LaserJob job, ProgressListener pl) throws IOException {
/* FALLTHRU */
if (p instanceof VectorPart)
{
double top_left_x = Util.px2mm(p.getMinX(), p.getDPI());
double top_left_y = Util.px2mm(p.getMinY(), p.getDPI());
double bottom_right_x = Util.px2mm(p.getMaxX(), p.getDPI());
double bottom_right_y = Util.px2mm(p.getMaxY(), p.getDPI());
// must match the flip applied to the actual move commands in vector()
double lx1 = isFlipXaxis() ? flipPivotX - Util.px2mm(p.getMinX(), p.getDPI()) : Util.px2mm(p.getMinX(), p.getDPI());
double lx2 = isFlipXaxis() ? flipPivotX - Util.px2mm(p.getMaxX(), p.getDPI()) : Util.px2mm(p.getMaxX(), p.getDPI());
double ly1 = isFlipYaxis() ? flipPivotY - Util.px2mm(p.getMinY(), p.getDPI()) : Util.px2mm(p.getMinY(), p.getDPI());
double ly2 = isFlipYaxis() ? flipPivotY - Util.px2mm(p.getMaxY(), p.getDPI()) : Util.px2mm(p.getMaxY(), p.getDPI());
double top_left_x = Math.min(lx1, lx2);
double top_left_y = Math.min(ly1, ly2);
double bottom_right_x = Math.max(lx1, lx2);
double bottom_right_y = Math.max(ly1, ly2);
/* write dimensions */
stream.hex("E752").byteint(part_number).absoluteMM(top_left_x).absoluteMM(top_left_y);
stream.hex("E753").byteint(part_number).absoluteMM(bottom_right_x).absoluteMM(bottom_right_y);
Expand Down