package org.reprap.machines; import java.net.URL; import java.util.Properties; import org.reprap.Printer; import org.reprap.ReprapException; import org.reprap.comms.port.Port; import org.reprap.comms.port.SerialPort; /** * * Returns an appropriate Printer object based on the current properties * */ public class MachineFactory { private static final int defaultBaudRate = 19200; ///< Default baud rate if none is specified private MachineFactory() { } static public Printer create(Properties props, Port port) throws Exception { // Currently this just always assumes we're building // a 3-axis cartesian printer. It should build an // appropriate type based on the local configuration. String geometry = props.getProperty("Geometry"); if (geometry.compareToIgnoreCase("cartesian") == 0) return new Reprap(props, port); else if (geometry.compareToIgnoreCase("nullcartesian") == 0) return new NullCartesianMachine(props); else throw new ReprapException("Invalid geometry in properties file"); } static public Printer create(Properties props) throws Exception { String commPortName = props.getProperty("Port"); String geometry = props.getProperty("Geometry"); Port port = null; // Create a port, provided this isn't a null machine if (geometry.compareToIgnoreCase("nullcartesian") != 0) { int baudRate = defaultBaudRate; if (props.containsKey("BaudRate")) baudRate = Integer.parseInt(props.getProperty("BaudRate")); port = new SerialPort(commPortName, baudRate); } return create(props, port); } static public Printer create() throws Exception { Properties props = new Properties(); URL url = ClassLoader.getSystemResource("reprap.properties"); props.load(url.openStream()); return create(props); } }