Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support X and Y axis flip, mk. 2 #223

Merged
merged 2 commits into from
Apr 19, 2024
Merged
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
48 changes: 42 additions & 6 deletions src/main/java/de/thomas_oster/liblasercut/drivers/Ruida.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public class Ruida extends LaserCutter
protected static final String SETTING_MAX_POWER = "Max laser power (%)";
protected static final String SETTING_BED_WIDTH = "Bed width (mm)";
protected static final String SETTING_BED_HEIGHT = "Bed height (mm)";
protected static final String SETTING_FLIP_X = "Flip X Axis";
protected static final String SETTING_FLIP_Y = "Flip Y Axis";
protected static final Locale FORMAT_LOCALE = Locale.US;

protected static final String[] uploadMethodList = {UPLOAD_METHOD_FILE, UPLOAD_METHOD_IP, UPLOAD_METHOD_SERIAL};
Expand Down Expand Up @@ -138,6 +140,30 @@ public void setComport(String comport)
this.comport = comport;
}

protected boolean flipXaxis = false;

public boolean isFlipXaxis()
{
return flipXaxis;
}

public void setFlipXaxis(boolean flipXaxis)
{
this.flipXaxis = flipXaxis;
}

protected boolean flipYaxis = false;

public boolean isFlipYaxis()
{
return flipYaxis;
}

public void setFlipYaxis(boolean flipYaxis)
{
this.flipYaxis = flipYaxis;
}

/* -----------------------------------------------------------------------*/

public Ruida()
Expand Down Expand Up @@ -231,10 +257,10 @@ private void find_and_write_bounding_box(LaserJob job) throws IOException
/* compute bounding box */
for (JobPart p : job.getParts())
{
double min_x = Util.px2mm(p.getMinX(), p.getDPI());
double min_y = Util.px2mm(p.getMinY(), p.getDPI());
double max_x = Util.px2mm(p.getMaxX(), p.getDPI());
double max_y = Util.px2mm(p.getMaxY(), p.getDPI());
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());
if (first) {
minX = min_x;
maxX = max_x;
Expand Down Expand Up @@ -267,8 +293,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 = Util.px2mm(x, dpi);
double y_mm = Util.px2mm(y, dpi);
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);
boolean as_absolute;

/* compute distance to last known position */
Expand Down Expand Up @@ -935,6 +961,8 @@ else if (getExportPath() != null && getExportPath().length() > 0)
SETTING_MAX_POWER,
SETTING_BED_WIDTH,
SETTING_BED_HEIGHT,
SETTING_FLIP_X,
SETTING_FLIP_Y,
};

@Override
Expand All @@ -961,6 +989,10 @@ public Object getProperty(String attribute) {
return this.getBedWidth();
} else if (SETTING_BED_HEIGHT.equals(attribute)) {
return this.getBedHeight();
} else if (SETTING_FLIP_X.equals(attribute)) {
return this.isFlipXaxis();
} else if (SETTING_FLIP_Y.equals(attribute)) {
return this.isFlipYaxis();
}
return null;
}
Expand Down Expand Up @@ -994,6 +1026,10 @@ public void setProperty(String attribute, Object value) {
this.setBedHeigth((Double)value);
} else if (SETTING_BED_WIDTH.equals(attribute)) {
this.setBedWidth((Double)value);
} else if (SETTING_FLIP_X.equals(attribute)) {
this.setFlipXaxis((Boolean) value);
} else if (SETTING_FLIP_Y.equals(attribute)) {
this.setFlipYaxis((Boolean) value);
}
}

Expand Down
Loading