From f6a9620fc42211e5fd0997d5f8401ece661017f0 Mon Sep 17 00:00:00 2001 From: Thomas Oster <thomas.oster@rwth-aachen.de> Date: Tue, 18 Sep 2012 10:24:48 +0200 Subject: [PATCH] start --- src/com/t_oster/liblasercut/LaserCutter.java | 6 + .../t_oster/liblasercut/LaserProperty.java | 119 +++------- .../PowerSpeedFocusFrequencyProperty.java | 142 ++++++++++++ .../liblasercut/PowerSpeedFocusProperty.java | 210 ++++++++++++++++++ src/com/t_oster/liblasercut/Raster3dPart.java | 10 +- src/com/t_oster/liblasercut/RasterPart.java | 12 +- .../t_oster/liblasercut/VectorCommand.java | 80 ++----- src/com/t_oster/liblasercut/VectorPart.java | 49 +--- .../liblasercut/drivers/EpilogCutter.java | 23 +- 9 files changed, 430 insertions(+), 221 deletions(-) create mode 100644 src/com/t_oster/liblasercut/PowerSpeedFocusFrequencyProperty.java create mode 100644 src/com/t_oster/liblasercut/PowerSpeedFocusProperty.java diff --git a/src/com/t_oster/liblasercut/LaserCutter.java b/src/com/t_oster/liblasercut/LaserCutter.java index 22176e7..3462a45 100644 --- a/src/com/t_oster/liblasercut/LaserCutter.java +++ b/src/com/t_oster/liblasercut/LaserCutter.java @@ -178,6 +178,12 @@ public abstract class LaserCutter implements Cloneable */ public abstract int estimateJobDuration(LaserJob job); + public abstract LaserProperty getLaserPropertyForVectorPart(); + + public abstract LaserProperty getLaserPropertyForRasterPart(); + + public abstract LaserProperty getLaserPropertyForRaster3dPart(); + public abstract String getModelName(); @Override diff --git a/src/com/t_oster/liblasercut/LaserProperty.java b/src/com/t_oster/liblasercut/LaserProperty.java index d9fc4e3..9e66248 100644 --- a/src/com/t_oster/liblasercut/LaserProperty.java +++ b/src/com/t_oster/liblasercut/LaserProperty.java @@ -18,112 +18,51 @@ **/ package com.t_oster.liblasercut; +import java.util.List; + /** * The LaserProperty holds all the parameters for parts of the LaserJob. * The Frequency value is ignored for Engraving operations * * @author oster */ -public class LaserProperty implements Cloneable +public abstract class LaserProperty implements Cloneable { - - private int power = 20; - private int speed = 100; - private int frequency = 5000; - private float focus = 0; - - public LaserProperty() - { - } - - public LaserProperty(int power, int speed) - { - this(power, speed, 5000, 0); - } - public LaserProperty(int power, int speed, int frequency) - { - this(power, speed, frequency, 0); - } - - public LaserProperty(int power, int speed, int frequency, float focus) - { - this.power = power; - this.speed = speed; - this.frequency = frequency; - this.focus = focus; - } - - /** - * Sets the Laserpower. Valid values are from 0 to 100. - * In 3d-Raster mode, the intensity is scaled to this power setting - * @param power - */ - public void setPower(int power) - { - power = power < 0 ? 0 : power; - power = power > 100 ? 100 : power; - this.power = power; - } - - public int getPower() + public LaserProperty() { - return power; } /** - * Sets the speed for the Laser. Valid values is from 0 to 100 - * @param speed + * Returns the names of possible propertys, + * e.g. for epilog-cutter this is power, speed and frequency + * @return */ - public void setSpeed(int speed) - { - speed = speed < 0 ? 0 : speed; - speed = speed > 100 ? 100 : speed; - this.speed = speed; - } - - public int getSpeed() - { - return speed; - } - - public void setFrequency(int frequency) - { - frequency = frequency < 100 ? 100 : frequency; - frequency = frequency > 5000 ? 5000 : frequency; - this.frequency = frequency; - } - - public int getFrequency() - { - return frequency; - } - + public abstract String[] getPropertyNames(); + /** - * Sets the Focus aka moves the Z axis. Values are given in mm. - * Positive values move the Z axis down aka makes the distance between - * laser and object bigger. - * The possible range depends on the LaserCutter, so wrong setting - * may result in IllegalJobExceptions - * @param focus the relative Distance from object to Laser in mm + * returns the value for this property + * May be of String, Boolean, Integer, Double or Float + * @param name + * @return */ - public void setFocus(float focus) - { - this.focus = focus; - } - + public abstract Object getProperty(String name); + + public abstract void setProperty(String name, Object value); + /** - * Returns the relative (to the distance at starting the job) distance - * between laser and object in mm/10s + * returns the minimum value of this property if it is + * of type Double, Integer or Float and a minimum value + * exists. Otherwise it returns null; + * @param name + * @return */ - public float getFocus() - { - return this.focus; - } - + public abstract Object getMinimumValue(String name); + + public abstract Object getMaximumValue(String name); + + public abstract Object[] getPossibleValues(String name); + @Override - public LaserProperty clone() - { - return new LaserProperty(power, speed, frequency, focus); - } + public abstract LaserProperty clone(); } diff --git a/src/com/t_oster/liblasercut/PowerSpeedFocusFrequencyProperty.java b/src/com/t_oster/liblasercut/PowerSpeedFocusFrequencyProperty.java new file mode 100644 index 0000000..0c379b6 --- /dev/null +++ b/src/com/t_oster/liblasercut/PowerSpeedFocusFrequencyProperty.java @@ -0,0 +1,142 @@ +/** + * This file is part of VisiCut. + * Copyright (C) 2011 Thomas Oster <thomas.oster@rwth-aachen.de> + * RWTH Aachen University - 52062 Aachen, Germany + * + * VisiCut is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VisiCut is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VisiCut. If not, see <http://www.gnu.org/licenses/>. + **/ +package com.t_oster.liblasercut; + +/** + * The LaserProperty holds all the parameters for parts of the LaserJob. + * The Frequency value is ignored for Engraving operations + * + * @author oster + */ +public class PowerSpeedFocusFrequencyProperty extends PowerSpeedFocusProperty +{ + + private int frequency = 5000; + + public PowerSpeedFocusFrequencyProperty() + { + } + + public PowerSpeedFocusFrequencyProperty(int power, int speed) + { + this(power, speed, 0, 5000); + } + + public PowerSpeedFocusFrequencyProperty(int power, int speed, float focus) + { + this(power, speed, focus, 5000); + } + + public PowerSpeedFocusFrequencyProperty(int power, int speed, float focus, int frequency) + { + super(power, speed, focus); + this.frequency = frequency; + } + + public void setFrequency(int frequency) + { + frequency = frequency < 100 ? 100 : frequency; + frequency = frequency > 5000 ? 5000 : frequency; + this.frequency = frequency; + } + + public int getFrequency() + { + return frequency; + } + + private static String[] propertyNames = new String[]{"power", "speed", "focus", "frequency"}; + + @Override + public String[] getPropertyNames() + { + return propertyNames; + } + + @Override + public Object getProperty(String name) + { + if ("frequency".equals(name)) + { + return this.getFrequency(); + } + else + { + return super.getProperty(name); + } + } + + @Override + public void setProperty(String name, Object value) + { + if ("frequency".equals(name)) + { + this.setFrequency((Integer) value); + } + else + { + super.setProperty(name, value); + } + } + + @Override + public Object getMinimumValue(String name) + { + if ("frequency".equals(name)) + { + return (Integer) 100; + } + else + { + return super.getMinimumValue(name); + } + } + + @Override + public Object getMaximumValue(String name) + { + if ("frequency".equals(name)) + { + return (Integer) 5000; + } + else + { + return super.getMaximumValue(name); + } + } + + @Override + public Object[] getPossibleValues(String name) + { + if ("frequency".equals(name)) + { + return null; + } + else + { + return super.getPossibleValues(name); + } + } + + @Override + public PowerSpeedFocusFrequencyProperty clone() + { + return new PowerSpeedFocusFrequencyProperty(this.getPower(), this.getSpeed(), this.getFocus(), frequency); + } +} diff --git a/src/com/t_oster/liblasercut/PowerSpeedFocusProperty.java b/src/com/t_oster/liblasercut/PowerSpeedFocusProperty.java new file mode 100644 index 0000000..8d6c281 --- /dev/null +++ b/src/com/t_oster/liblasercut/PowerSpeedFocusProperty.java @@ -0,0 +1,210 @@ +/** + * This file is part of VisiCut. + * Copyright (C) 2011 Thomas Oster <thomas.oster@rwth-aachen.de> + * RWTH Aachen University - 52062 Aachen, Germany + * + * VisiCut is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VisiCut is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with VisiCut. If not, see <http://www.gnu.org/licenses/>. + **/ +package com.t_oster.liblasercut; + +import java.util.List; + +/** + * The LaserProperty holds all the parameters for parts of the LaserJob. + * The Frequency value is ignored for Engraving operations + * + * @author oster + */ +public class PowerSpeedFocusProperty extends LaserProperty +{ + + private int power = 20; + private int speed = 100; + private float focus = 0; + + public PowerSpeedFocusProperty() + { + } + + public PowerSpeedFocusProperty(int power, int speed) + { + this(power, speed, 0); + } + + public PowerSpeedFocusProperty(int power, int speed, float focus) + { + this.power = power; + this.speed = speed; + this.focus = focus; + } + + /** + * Sets the Laserpower. Valid values are from 0 to 100. + * In 3d-Raster mode, the intensity is scaled to this power setting + * @param power + */ + public void setPower(int power) + { + power = power < 0 ? 0 : power; + power = power > 100 ? 100 : power; + this.power = power; + } + + public int getPower() + { + return power; + } + + /** + * Sets the speed for the Laser. Valid values is from 0 to 100 + * @param speed + */ + public void setSpeed(int speed) + { + speed = speed < 0 ? 0 : speed; + speed = speed > 100 ? 100 : speed; + this.speed = speed; + } + + public int getSpeed() + { + return speed; + } + + /** + * Sets the Focus aka moves the Z axis. Values are given in mm. + * Positive values move the Z axis down aka makes the distance between + * laser and object bigger. + * The possible range depends on the LaserCutter, so wrong setting + * may result in IllegalJobExceptions + * @param focus the relative Distance from object to Laser in mm + */ + public void setFocus(float focus) + { + this.focus = focus; + } + + /** + * Returns the relative (to the distance at starting the job) distance + * between laser and object in mm/10s + */ + public float getFocus() + { + return this.focus; + } + + @Override + public PowerSpeedFocusProperty clone() + { + return new PowerSpeedFocusProperty(power, speed, focus); + } + + private static String[] propertyNames = new String[]{"power", "speed", "focus"}; + + @Override + public String[] getPropertyNames() + { + return propertyNames; + } + + @Override + public Object getProperty(String name) + { + if ("power".equals(name)) + { + return (Integer) this.getPower(); + } + else if ("speed".equals(name)) + { + return (Integer) this.getSpeed(); + } + else if ("focus".equals(name)) + { + return (Float) this.getFocus(); + } + else + { + throw new IllegalArgumentException("Unknown setting '"+name+"'"); + } + } + + @Override + public void setProperty(String name, Object value) + { + if ("power".equals(name)) + { + this.setPower((Integer) value); + } + else if ("speed".equals(name)) + { + this.setSpeed((Integer) value); + } + else if ("focus".equals(name)) + { + this.setFocus((Float) value); + } + else + { + throw new IllegalArgumentException("Unknown setting '"+name+"'"); + } + } + + @Override + public Object getMinimumValue(String name) + { + if ("power".equals(name)) + { + return (Integer) 0; + } + else if ("speed".equals(name)) + { + return (Integer) 0; + } + else if ("focus".equals(name)) + { + return null; + } + else + { + throw new IllegalArgumentException("Unknown setting '"+name+"'"); + } + } + + @Override + public Object getMaximumValue(String name) + { + if ("power".equals(name)) + { + return (Integer) 100; + } + else if ("speed".equals(name)) + { + return (Integer) 100; + } + else if ("focus".equals(name)) + { + return null; + } + else + { + throw new IllegalArgumentException("Unknown setting '"+name+"'"); + } + } + + @Override + public Object[] getPossibleValues(String name) + { + return null; + } +} diff --git a/src/com/t_oster/liblasercut/Raster3dPart.java b/src/com/t_oster/liblasercut/Raster3dPart.java index 7b995ee..9ac3a4f 100644 --- a/src/com/t_oster/liblasercut/Raster3dPart.java +++ b/src/com/t_oster/liblasercut/Raster3dPart.java @@ -23,8 +23,8 @@ package com.t_oster.liblasercut; import com.t_oster.liblasercut.platform.Point; -import java.util.List; import java.util.LinkedList; +import java.util.List; /** * @@ -49,14 +49,6 @@ public class Raster3dPart { return this.curProp; } - public void setPower(int power) { - this.curProp.setPower(power); - } - - public void setSpeed(int speed) { - this.curProp.setSpeed(speed); - } - /** * Adds the given Image to this RasterPart * The Image must be in sRGB Format. The grey value of every pixel diff --git a/src/com/t_oster/liblasercut/RasterPart.java b/src/com/t_oster/liblasercut/RasterPart.java index f919907..08af58b 100644 --- a/src/com/t_oster/liblasercut/RasterPart.java +++ b/src/com/t_oster/liblasercut/RasterPart.java @@ -23,8 +23,8 @@ package com.t_oster.liblasercut; import com.t_oster.liblasercut.platform.Point; -import java.util.List; import java.util.LinkedList; +import java.util.List; /** * @@ -53,16 +53,6 @@ public class RasterPart return this.curProp; } - public void setPower(int power) - { - this.curProp.setPower(power); - } - - public void setSpeed(int speed) - { - this.curProp.setSpeed(speed); - } - /** * Adds the given Image to this RasterPart * The Image must be in sRGB Format. The grey value of every pixel diff --git a/src/com/t_oster/liblasercut/VectorCommand.java b/src/com/t_oster/liblasercut/VectorCommand.java index b59ed30..d1002cb 100644 --- a/src/com/t_oster/liblasercut/VectorCommand.java +++ b/src/com/t_oster/liblasercut/VectorCommand.java @@ -32,23 +32,24 @@ public class VectorCommand public static enum CmdType { - SETSPEED, - SETPOWER, - SETFREQUENCY, - SETFOCUS, + SETPROPERTY, MOVETO, LINETO } private CmdType type; private int[] operands; private float foperand; - - public VectorCommand(CmdType type, float f) + private LaserProperty property; + + public VectorCommand(CmdType type, int x, int y) { - if (type == CmdType.SETFOCUS) + if (type == CmdType.MOVETO || type == CmdType.LINETO) { this.type = type; - this.foperand = f; + this.operands = new int[] + { + x, y + }; } else { @@ -56,19 +57,15 @@ public class VectorCommand } } - public VectorCommand(CmdType type, int x, int y) + public VectorCommand(CmdType type, LaserProperty p) { - if (type == CmdType.MOVETO || type == CmdType.LINETO) + if (type == CmdType.SETPROPERTY) { - this.type = type; - this.operands = new int[] - { - x, y - }; + this.property = p; } else { - throw new IllegalArgumentException("Wrong number of Parameters for " + type.toString()); + throw new IllegalArgumentException("Only valid for SETPROPERTY"); } } @@ -94,56 +91,17 @@ public class VectorCommand } throw new UnsupportedOperationException("getX not supported for " + type.toString()); } - - public VectorCommand(CmdType type, int operand1) + + public LaserProperty getProperty() { - if (type == CmdType.SETSPEED || type == CmdType.SETPOWER || type == CmdType.SETFREQUENCY) + if (this.type == CmdType.SETPROPERTY) { - this.type = type; - operands = new int[] - { - operand1 - }; + return this.property; } else { - throw new IllegalArgumentException("Wrong number of Parameters for " + type.toString()); - } - } - - public int getPower() - { - if (type == CmdType.SETPOWER) - { - return operands[0]; - } - throw new UnsupportedOperationException("getPower is not Applicable for " + type.toString()); - } - - public int getSpeed() - { - if (type == CmdType.SETSPEED) - { - return operands[0]; + throw new UnsupportedOperationException("Only valid for PROPERTY"); } - throw new UnsupportedOperationException("getSpeed is not Applicable for " + type.toString()); - } - - public int getFrequency() - { - if (type == CmdType.SETFREQUENCY) - { - return operands[0]; - } - throw new UnsupportedOperationException("getFrequency is not Applicable for " + type.toString()); - } - - public float getFocus() - { - if (type == CmdType.SETFOCUS) - { - return foperand; - } - throw new UnsupportedOperationException("getFocus is not Applicable for " + type.toString()); } + } diff --git a/src/com/t_oster/liblasercut/VectorPart.java b/src/com/t_oster/liblasercut/VectorPart.java index 3e4fe9a..5f536dc 100644 --- a/src/com/t_oster/liblasercut/VectorPart.java +++ b/src/com/t_oster/liblasercut/VectorPart.java @@ -41,11 +41,8 @@ public class VectorPart public VectorPart(LaserProperty initialProperty) { - this.currentCuttingProperty = initialProperty.clone(); commands = new LinkedList<VectorCommand>(); - commands.add(new VectorCommand(VectorCommand.CmdType.SETPOWER, currentCuttingProperty.getPower())); - commands.add(new VectorCommand(VectorCommand.CmdType.SETSPEED, currentCuttingProperty.getSpeed())); - commands.add(new VectorCommand(VectorCommand.CmdType.SETFREQUENCY, currentCuttingProperty.getFrequency())); + this.setProperty(initialProperty); } public LaserProperty getCurrentCuttingProperty() @@ -53,12 +50,10 @@ public class VectorPart return currentCuttingProperty; } - public void setCurrentCuttingProperty(LaserProperty cp) + public void setProperty(LaserProperty cp) { - this.setFrequency(cp.getFrequency()); - this.setPower(cp.getPower()); - this.setSpeed(cp.getSpeed()); - this.setFocus(cp.getFocus()); + this.currentCuttingProperty = cp; + commands.add(new VectorCommand(VectorCommand.CmdType.SETPROPERTY, cp)); } public VectorCommand[] getCommandList() @@ -66,42 +61,6 @@ public class VectorPart return commands.toArray(new VectorCommand[0]); } - public void setSpeed(int speed) - { - if (speed != this.currentCuttingProperty.getSpeed()) - { - commands.add(new VectorCommand(VectorCommand.CmdType.SETSPEED, speed)); - this.currentCuttingProperty.setSpeed(speed); - } - } - - public void setPower(int power) - { - if (power != this.currentCuttingProperty.getPower()) - { - commands.add(new VectorCommand(VectorCommand.CmdType.SETPOWER, power)); - this.currentCuttingProperty.setPower(power); - } - } - - public void setFrequency(int frequency) - { - if (frequency != this.currentCuttingProperty.getFrequency()) - { - commands.add(new VectorCommand(VectorCommand.CmdType.SETFREQUENCY, frequency)); - this.currentCuttingProperty.setFrequency(frequency); - } - } - - public void setFocus(float focus) - { - if (focus != this.currentCuttingProperty.getFocus()) - { - commands.add(new VectorCommand(VectorCommand.CmdType.SETFOCUS, focus)); - this.currentCuttingProperty.setFocus(focus); - } - } - private void checkMin(int x, int y) { if (x < minX) diff --git a/src/com/t_oster/liblasercut/drivers/EpilogCutter.java b/src/com/t_oster/liblasercut/drivers/EpilogCutter.java index 61e4e50..8a4a763 100644 --- a/src/com/t_oster/liblasercut/drivers/EpilogCutter.java +++ b/src/com/t_oster/liblasercut/drivers/EpilogCutter.java @@ -256,9 +256,14 @@ abstract class EpilogCutter extends LaserCutter { for (VectorCommand cmd : job.getVectorPart().getCommandList()) { - if (cmd.getType() == VectorCommand.CmdType.SETFOCUS) + if (cmd.getType() == VectorCommand.CmdType.SETPROPERTY) { - if (mm2focus(cmd.getFocus()) > MAXFOCUS || (mm2focus(cmd.getFocus())) < MINFOCUS) + if (!(cmd.getProperty() instanceof PowerSpeedFocusFrequencyProperty)) + { + throw new IllegalJobException("This driver expects Power,Speed,Frequency and Focus as settings"); + } + float focus = ((PowerSpeedFocusFrequencyProperty) cmd.getProperty()).getFocus(); + if (mm2focus(focus) > MAXFOCUS || (mm2focus(focus)) < MINFOCUS) { throw new IllegalJobException("Illegal Focus value. This Lasercutter supports values between" + focus2mm(MINFOCUS) + "mm to " + focus2mm(MAXFOCUS) + "mm."); @@ -270,7 +275,11 @@ abstract class EpilogCutter extends LaserCutter { for (int i = 0; i < job.getRasterPart().getRasterCount(); i++) { - float focus = job.getRasterPart().getLaserProperty(i) == null ? 0 : job.getRasterPart().getLaserProperty(i).getFocus(); + if (job.getRasterPart().getLaserProperty(i) != null && !(job.getRasterPart().getLaserProperty(i) instanceof PowerSpeedFocusFrequencyProperty)) + { + throw new IllegalJobException("This driver expects Power,Speed and Focus as settings"); + } + float focus = job.getRasterPart().getLaserProperty(i) == null ? 0 : ((PowerSpeedFocusProperty) job.getRasterPart().getLaserProperty(i)).getFocus(); if (mm2focus(focus) > MAXFOCUS || (mm2focus(focus)) < MINFOCUS) { throw new IllegalJobException("Illegal Focus value. This Lasercutter supports values between" @@ -282,7 +291,11 @@ abstract class EpilogCutter extends LaserCutter { for (int i = 0; i < job.getRaster3dPart().getRasterCount(); i++) { - float focus = job.getRaster3dPart().getLaserProperty(i) == null ? 0 : job.getRaster3dPart().getLaserProperty(i).getFocus(); + if (job.getRaster3dPart().getLaserProperty(i) != null && !(job.getRaster3dPart().getLaserProperty(i) instanceof PowerSpeedFocusFrequencyProperty)) + { + throw new IllegalJobException("This driver expects Power,Speed and Focus as settings"); + } + float focus = job.getRasterPart().getLaserProperty(i) == null ? 0 : ((PowerSpeedFocusProperty) job.getRaster3dPart().getLaserProperty(i)).getFocus(); if (mm2focus(focus) > MAXFOCUS || (mm2focus(focus)) < MINFOCUS) { throw new IllegalJobException("Illegal Focus value. This Lasercutter supports values between" @@ -382,7 +395,7 @@ abstract class EpilogCutter extends LaserCutter { ByteArrayOutputStream result = new ByteArrayOutputStream(); PrintStream out = new PrintStream(result, true, "US-ASCII"); - LaserProperty curprop = new LaserProperty(); + PowerSpeedFoc curprop = new LaserProperty(); if (rp != null && rp.getRasterCount() > 0) { if (rp.getRasterCount() > 0) -- GitLab