From 5572070ed1910979c1ce975d8860120dd627edbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= Date: Wed, 27 Dec 2023 19:15:27 +0100 Subject: [PATCH 1/2] Support X and Y axis flip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Klaus Kämpf --- .../liblasercut/drivers/Ruida.java | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/thomas_oster/liblasercut/drivers/Ruida.java b/src/main/java/de/thomas_oster/liblasercut/drivers/Ruida.java index 18be6c40..a9df2a60 100644 --- a/src/main/java/de/thomas_oster/liblasercut/drivers/Ruida.java +++ b/src/main/java/de/thomas_oster/liblasercut/drivers/Ruida.java @@ -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}; @@ -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() @@ -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 */ @@ -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 @@ -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; } @@ -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); } } From c425533a6c08b43df7418cd45b94cccf29d78acb Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Mon, 15 Apr 2024 16:56:48 +0200 Subject: [PATCH 2/2] Fix bounding box calculation Fixes oversight in previous commit. --- .../java/de/thomas_oster/liblasercut/drivers/Ruida.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/thomas_oster/liblasercut/drivers/Ruida.java b/src/main/java/de/thomas_oster/liblasercut/drivers/Ruida.java index a9df2a60..d6f90d52 100644 --- a/src/main/java/de/thomas_oster/liblasercut/drivers/Ruida.java +++ b/src/main/java/de/thomas_oster/liblasercut/drivers/Ruida.java @@ -257,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;