diff --git a/ControlFrame.pde b/ControlFrame.pde new file mode 100644 index 0000000..38beffb --- /dev/null +++ b/ControlFrame.pde @@ -0,0 +1,52 @@ +// the ControlFrame class extends PApplet, so we +// are creating a new processing applet inside a +// new frame with a controlP5 object loaded +public class ControlFrame extends PApplet { + public int w, h; + int abc = 100; + public ControlP5 cp5; + protected PApplet parent; + + private ControlFrame() { + } + + public ControlFrame(PApplet theParent, int theWidth, int theHeight) { + this.parent = theParent; + this.w = theWidth; + this.h = theHeight; + } + + public ControlP5 cp5() { + if (this.cp5 == null) { + this.cp5 = this.setupControlP5(); + } + return this.cp5; + } + + public PApplet getParent() { + return this.parent; + } + + public void setup() { + size(w, h); + frameRate(5); + } + + public ControlP5 setupControlP5() { + println("About to create new ControlP5"); + ControlP5 cp5 = new ControlP5(this); + println("Created: " + cp5); + while (cp5 == null) { + println("Was null: " + cp5); + } + println("Finally created: " + cp5); + return cp5; + } + + public void draw() { + background(abc); + } +} + + + diff --git a/ControlFrameSimple.pde b/ControlFrameSimple.pde new file mode 100644 index 0000000..06c2eba --- /dev/null +++ b/ControlFrameSimple.pde @@ -0,0 +1,40 @@ + +// the ControlFrame class extends PApplet, so we +// are creating a new processing applet inside a +// new frame with a controlP5 object loaded +public class ControlFrameSimple extends PApplet { + + int w, h; + + int bg; + + public void setup() { + size(w, h); + frameRate(5); + cp5 = new ControlP5( this ); + } + + public void draw() { + background( bg ); + } + + private ControlFrameSimple() { + } + + public ControlFrameSimple(Object theParent, int theWidth, int theHeight, int theColor) { + parent = theParent; + w = theWidth; + h = theHeight; + bg = theColor; + } + + + public ControlP5 cp5() { + return this.cp5; + } + + ControlP5 cp5; + + Object parent; +} + diff --git a/DisplayMachine.pde b/DisplayMachine.pde index feba66d..a0d9582 100644 --- a/DisplayMachine.pde +++ b/DisplayMachine.pde @@ -25,8 +25,8 @@ sandy.noble@gmail.com http://www.polargraph.co.uk/ https://github.com/euphy/polargraphcontroller - */ + class DisplayMachine extends Machine { private Rectangle outline = null; @@ -767,8 +767,6 @@ class DisplayMachine extends Machine void previewNativePixel(PVector pos, float size, float brightness) { float half = size / 2.0; - fill(0,0,0, 255-brightness); - beginShape(); // arcs from the left-hand corner float distFromPointA = getOutline().getTopLeft().dist(pos); @@ -776,14 +774,19 @@ class DisplayMachine extends Machine List int1 = findIntersections(getOutline().getLeft(), distFromPointA-half, getOutline().getRight(), distFromPointB-half, size); List int2 = findIntersections(getOutline().getLeft(), distFromPointA+half, getOutline().getRight(), distFromPointB-half, size); - - // plot out the vertexes - vertex(int1.get(0).x, int1.get(0).y); - vertex(int2.get(0).x, int2.get(0).y); - vertex(int2.get(1).x, int2.get(1).y); - vertex(int1.get(1).x, int1.get(1).y); - vertex(int1.get(0).x, int1.get(0).y); - endShape(); + + if (!int1.isEmpty() && !int2.isEmpty()) { + fill(0,0,0, 255-brightness); + beginShape(); + + // plot out the vertexes + vertex(int1.get(0).x, int1.get(0).y); + vertex(int2.get(0).x, int2.get(0).y); + vertex(int2.get(1).x, int2.get(1).y); + vertex(int1.get(1).x, int1.get(1).y); + vertex(int1.get(0).x, int1.get(0).y); + endShape(); + } } void previewNativeArcPixel(PVector pos, float size, float brightness) diff --git a/DrawPixelsWindow.pde b/DrawPixelsWindow.pde new file mode 100644 index 0000000..0b96807 --- /dev/null +++ b/DrawPixelsWindow.pde @@ -0,0 +1,138 @@ +///*------------------------------------------------------------------------ +// Details about the "drawing" subwindow +//------------------------------------------------------------------------*/ + +public Integer renderStartDirection = DRAW_DIR_SE; // default start drawing in SE direction (DOWN) +public Integer renderStartPosition = DRAW_DIR_NE; // default top right hand corner for start +public Integer renderStyle = PIXEL_STYLE_SQ_FREQ; // default pixel style square wave + +ControlFrameSimple addDrawPixelsControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) { + final Frame f = new Frame( theName ); + final ControlFrameSimple p = new ControlFrameSimple( this, theWidth, theHeight, theColor ); + + f.add( p ); + p.init(); + f.setTitle(theName); + f.setSize( p.w, p.h ); + f.setLocation( theX, theY ); + f.addWindowListener( new WindowAdapter() { + @Override + public void windowClosing(WindowEvent we) { + p.dispose(); + f.dispose(); + } + } + ); + f.setResizable( true ); + f.setVisible( true ); + // sleep a little bit to allow p to call setup. + // otherwise a nullpointerexception might be caused. + try { + Thread.sleep( 100 ); + } + catch(Exception e) { + } + + // set up controls + RadioButton rPos = p.cp5().addRadioButton("radio_startPosition",10,10) + .add("Top-right", DRAW_DIR_NE) + .add("Bottom-right", DRAW_DIR_SE) + .add("Bottom-left", DRAW_DIR_SW) + .add("Top-left", DRAW_DIR_NW) + .plugTo(this, "radio_startPosition"); + + RadioButton rSkip = p.cp5().addRadioButton("radio_pixelSkipStyle",10,100) + .add("Lift pen over masked pixels", 1) + .add("Draw masked pixels as blanks", 2) + .plugTo(this, "radio_pixelSkipStyle"); + + RadioButton rStyle = p.cp5().addRadioButton("radio_pixelStyle",100,10); + rStyle.add("Variable frequency square wave", PIXEL_STYLE_SQ_FREQ); + rStyle.add("Variable size square wave", PIXEL_STYLE_SQ_SIZE); + rStyle.add("Solid square wave", PIXEL_STYLE_SQ_SOLID); + rStyle.add("Scribble", PIXEL_STYLE_SCRIBBLE); + if (currentHardware >= HARDWARE_VER_MEGA) { + rStyle.add("Spiral", PIXEL_STYLE_CIRCLE); + rStyle.add("Sawtooth", PIXEL_STYLE_SAW); + } + rStyle.plugTo(this, "radio_pixelStyle"); + + + Button submitButton = p.cp5().addButton("submitDrawWindow",0,280,10,120,20) + .setLabel("Generate commands") + .plugTo(this, "submitDrawWindow"); + + return p; +} + +void radio_startPosition(int pos) { + renderStartPosition = pos; + radio_rowStartDirection(1); +} + +void radio_rowStartDirection(int dir) { + if (renderStartPosition == DRAW_DIR_NE || renderStartPosition == DRAW_DIR_SW) + renderStartDirection = (dir == 0) ? DRAW_DIR_NW : DRAW_DIR_SE; + else if (renderStartPosition == DRAW_DIR_SE || renderStartPosition == DRAW_DIR_NW) + renderStartDirection = (dir == 0) ? DRAW_DIR_NE : DRAW_DIR_SW; +} + +void radio_pixelStyle(int style) { + renderStyle = style; +} + +void radio_pixelSkipStyle(int style) { + if (style == 1) + liftPenOnMaskedPixels = true; + else if (style == 2) + liftPenOnMaskedPixels = false; +} + +void submitDrawWindow(int theValue) { + println("draw."); + println("Style: " + renderStyle); + println("Start pos: " + renderStartPosition); + println("Start dir: " + renderStartDirection); + + switch (renderStyle) { + case PIXEL_STYLE_SQ_FREQ: button_mode_renderSquarePixel(); break; + case PIXEL_STYLE_SQ_SIZE: button_mode_renderScaledSquarePixels(); break; + case PIXEL_STYLE_SQ_SOLID: button_mode_renderSolidSquarePixels(); break; + case PIXEL_STYLE_SCRIBBLE: button_mode_renderScribblePixels(); break; + case PIXEL_STYLE_CIRCLE: button_mode_renderCirclePixel(); break; + case PIXEL_STYLE_SAW: button_mode_renderSawPixel(); break; + } +} + + +class DrawPixelsWindow extends ControlFrame { + + + public DrawPixelsWindow () { + super(parentPapplet, 450, 150); + + int xPos = 100; + int yPos = 100; + String name = DRAW_PIXELS_WINDOW_NAME; + + final Frame f = new Frame(DRAW_PIXELS_WINDOW_NAME); + f.add(this); + this.init(); + f.setTitle(CHANGE_SERIAL_PORT_WINDOW_NAME); + f.setSize(super.w, super.h); + f.setLocation(xPos, yPos); + f.setResizable(false); + f.setVisible(true); + + f.addWindowListener( new WindowAdapter() { + @Override + public void windowClosing(WindowEvent we) { + f.dispose(); + } + }); + + + } + + +} diff --git a/Machine.pde b/Machine.pde index cb1ca9b..6e7b5bd 100644 --- a/Machine.pde +++ b/Machine.pde @@ -25,7 +25,11 @@ sandy.noble@gmail.com http://www.polargraph.co.uk/ https://github.com/euphy/polargraphcontroller - +*/ +/** +* +* +* */ class Machine { diff --git a/MachineExecWindow.pde b/MachineExecWindow.pde new file mode 100644 index 0000000..7589c15 --- /dev/null +++ b/MachineExecWindow.pde @@ -0,0 +1,64 @@ +ControlFrameSimple addMachineExecControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) { + final Frame f = new Frame( theName ); + final ControlFrameSimple p = new ControlFrameSimple( this, theWidth, theHeight, theColor ); + + f.add( p ); + p.init(); + f.setTitle(theName); + f.setSize( p.w, p.h ); + f.setLocation( theX, theY ); + f.addWindowListener( new WindowAdapter() { + @Override + public void windowClosing(WindowEvent we) { + p.dispose(); + f.dispose(); + } + } + ); + f.setResizable( true ); + f.setVisible( true ); + // sleep a little bit to allow p to call setup. + // otherwise a nullpointerexception might be caused. + try { + Thread.sleep( 100 ); + } + catch(Exception e) { + } + + // set up controls + Textfield filenameField = p.cp5().addTextfield("machineExec_execFilename",20,20,150,20) + .setText(getStoreFilename()) + .setLabel("Filename to execute from") + .addListener( new ControlListener() { + public void controlEvent( ControlEvent ev ) { + machineExec_execFilename(ev.getController().getStringValue()); + Textfield tf = p.cp5().get(Textfield.class, "machineExec_execFilename"); + } + }); + + + Button submitButton = p.cp5().addButton("machineExec_submitExecFilenameWindow",0,180,20,60,20) + .setLabel("Submit") + .addListener( new ControlListener() { + public void controlEvent( ControlEvent ev ) { + p.cp5().get(Textfield.class, "machineExec_execFilename").submit(); + p.cp5().get(Textfield.class, "machineExec_execFilename").setText(getStoreFilename()); + } + }); + + filenameField.setFocus(true); + + return p; +} + +void machineExec_execFilename(String filename) { + println("Filename event: "+ filename); + if (filename != null + && filename.length() <= 12 + && !"".equals(filename.trim())) { + filename = filename.trim(); + setStoreFilename(filename); + sendMachineExecMode(); + } +} + diff --git a/MachineStoreWindow.pde b/MachineStoreWindow.pde new file mode 100644 index 0000000..958ff3d --- /dev/null +++ b/MachineStoreWindow.pde @@ -0,0 +1,77 @@ +/*------------------------------------------------------------------------ + Details about the "machine store" subwindow +------------------------------------------------------------------------*/ + +ControlFrameSimple addMachineStoreControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) { + final Frame f = new Frame( theName ); + final ControlFrameSimple p = new ControlFrameSimple( this, theWidth, theHeight, theColor ); + + f.add( p ); + p.init(); + f.setTitle(theName); + f.setSize( p.w, p.h ); + f.setLocation( theX, theY ); + f.addWindowListener( new WindowAdapter() { + @Override + public void windowClosing(WindowEvent we) { + p.dispose(); + f.dispose(); + } + } + ); + f.setResizable( true ); + f.setVisible( true ); + // sleep a little bit to allow p to call setup. + // otherwise a nullpointerexception might be caused. + try { + Thread.sleep( 100 ); + } + catch(Exception e) { + } + + // set up controls + + Textfield filenameField = p.cp5().addTextfield("machineStore_storeFilename",20,20,150,20) + .setText(getStoreFilename()) + .setLabel("Filename to store to") + .addListener( new ControlListener() { + public void controlEvent( ControlEvent ev ) { + machineStore_storeFilename(ev.getController().getStringValue()); + Textfield tf = p.cp5().get(Textfield.class, "machineExec_execFilename"); + } + }); + + Button submitButton = p.cp5().addButton("machineStore_submitStoreFilenameWindow",0,180,20,60,20) + .setLabel("Submit") + .addListener( new ControlListener() { + public void controlEvent( ControlEvent ev ) { + p.cp5().get(Textfield.class, "machineStore_storeFilename").submit(); + p.cp5().get(Textfield.class, "machineStore_storeFilename").setText(getStoreFilename()); + } + }); + + Toggle overwriteToggle = p.cp5().addToggle("machineStore_toggleAppendToFile",true,180,50,20,20) + .setCaptionLabel("Overwrite existing file") + .plugTo(this, "machineStore_toggleAppendToFile"); + + + filenameField.setFocus(true); + + return p; +} + +void machineStore_toggleAppendToFile(boolean theFlag) { + setOverwriteExistingStoreFile(theFlag); +} + +void machineStore_storeFilename(String filename) { + println("Filename event: "+ filename); + if (filename != null + && filename.length() <= 12 + && !"".equals(filename.trim())) { + filename = filename.trim(); + setStoreFilename(filename); + sendMachineStoreMode(); + } +} + diff --git a/Misc.pde b/Misc.pde index 652a854..57d03e0 100644 --- a/Misc.pde +++ b/Misc.pde @@ -25,7 +25,6 @@ sandy.noble@gmail.com http://www.polargraph.co.uk/ https://github.com/euphy/polargraphcontroller - */ class Scaler @@ -53,202 +52,202 @@ class PreviewVector extends PVector { public String command; } - - -import java.awt.Toolkit; -import java.awt.BorderLayout; -import java.awt.GraphicsEnvironment; - -public class Console extends WindowAdapter implements WindowListener, ActionListener, Runnable -{ - private JFrame frame; - private JTextArea textArea; - private Thread reader; - private Thread reader2; - private boolean quit; - - private final PipedInputStream pin=new PipedInputStream(); - private final PipedInputStream pin2=new PipedInputStream(); - - private PrintStream cOut = System.out; - private PrintStream cErr = System.err; - - Thread errorThrower; // just for testing (Throws an Exception at this Console - - public Console() - { - // create all components and add them - frame=new JFrame("Java Console"); - Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize(); - Dimension frameSize=new Dimension((int)(screenSize.width/2),(int)(screenSize.height/2)); - int x=(int)(frameSize.width/2); - int y=(int)(frameSize.height/2); - frame.setBounds(x,y,frameSize.width,frameSize.height); - - textArea=new JTextArea(); - textArea.setEditable(false); - JButton button=new JButton("clear"); - - frame.getContentPane().setLayout(new BorderLayout()); - frame.getContentPane().add(new JScrollPane(textArea),BorderLayout.CENTER); - frame.getContentPane().add(button,BorderLayout.SOUTH); - frame.setVisible(true); - - frame.addWindowListener(this); - button.addActionListener(this); - - try - { - this.cOut = System.out; - PipedOutputStream pout=new PipedOutputStream(this.pin); - System.setOut(new PrintStream(pout,true)); - } - catch (java.io.IOException io) - { - textArea.append("Couldn't redirect STDOUT to this console\n"+io.getMessage()); - } - catch (SecurityException se) - { - textArea.append("Couldn't redirect STDOUT to this console\n"+se.getMessage()); - } - - try - { - this.cErr = System.err; - PipedOutputStream pout2=new PipedOutputStream(this.pin2); - System.setErr(new PrintStream(pout2,true)); - } - catch (java.io.IOException io) - { - textArea.append("Couldn't redirect STDERR to this console\n"+io.getMessage()); - } - catch (SecurityException se) - { - textArea.append("Couldn't redirect STDERR to this console\n"+se.getMessage()); - } - - quit=false; // signals the Threads that they should exit - - // Starting two seperate threads to read from the PipedInputStreams - // - reader=new Thread(this); - reader.setDaemon(true); - reader.start(); - // - reader2=new Thread(this); - reader2.setDaemon(true); - reader2.start(); - -// // testing part -// // you may omit this part for your application -// // -// System.out.println("Hello World 2"); -// System.out.println("All fonts available to Graphic2D:\n"); -// GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); -// String[] fontNames=ge.getAvailableFontFamilyNames(); -// for(int n=0;n= 0 && portNo < ports.length) + r.activate(ports[portNo]); + else + r.activate("No serial connection"); + + return p; +} + + +void radio_serialPort(int newSerialPort) +{ + println("In radio_serialPort"); + if (newSerialPort == -2) + { + } + else if (newSerialPort == -1) { + println("Disconnecting serial port."); + useSerialPortConnection = false; + if (myPort != null) + { + myPort.stop(); + myPort = null; + } + drawbotReady = false; + drawbotConnected = false; + serialPortNumber = newSerialPort; + } + else if (newSerialPort != getSerialPortNumber()) { + println("About to connect to serial port in slot " + newSerialPort); + // Print a list of the serial ports, for debugging purposes: + if (newSerialPort < Serial.list().length) { + try { + drawbotReady = false; + drawbotConnected = false; + if (myPort != null) { + myPort.stop(); + myPort = null; + } + + if (getSerialPortNumber() >= 0) + println("closing " + Serial.list()[getSerialPortNumber()]); + + serialPortNumber = newSerialPort; + String portName = Serial.list()[serialPortNumber]; + + myPort = new Serial(this, portName, getBaudRate()); + //read bytes into a buffer until you get a linefeed (ASCII 10): + myPort.bufferUntil('\n'); + useSerialPortConnection = true; + println("Successfully connected to port " + portName); + } + catch (Exception e) { + println("Attempting to connect to serial port in slot " + getSerialPortNumber() + + " caused an exception: " + e.getMessage()); + } + } else { + println("No serial ports found."); + useSerialPortConnection = false; + } + } else { + println("no serial port change."); + } +} + diff --git a/controlsActions.pde b/controlsActions.pde index df29267..63a2329 100644 --- a/controlsActions.pde +++ b/controlsActions.pde @@ -25,7 +25,6 @@ sandy.noble@gmail.com http://www.polargraph.co.uk/ https://github.com/euphy/polargraphcontroller - */ void button_mode_begin() { @@ -723,7 +722,7 @@ void button_mode_sendButtonDeactivate() void numberbox_mode_previewCordOffsetValue(int value) { previewCordOffset = value; - lastCommandQueueHash = 0; + previewQueue(true); } diff --git a/controlsActionsWindows.pde b/controlsActionsWindows.pde index 6ad6cc6..0781e86 100644 --- a/controlsActionsWindows.pde +++ b/controlsActionsWindows.pde @@ -1,569 +1,412 @@ /** - Polargraph controller - Copyright Sandy Noble 2015. + Polargraph controller + Copyright Sandy Noble 2015. + + This file is part of Polargraph Controller. + + Polargraph Controller is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Polargraph Controller 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Polargraph Controller. If not, see . + + Requires the excellent ControlP5 GUI library available from http://www.sojamo.de/libraries/controlP5/. + Requires the excellent Geomerative library available from http://www.ricardmarxer.com/geomerative/. + + This is an application for controlling a polargraph machine, communicating using ASCII command language over a serial link. + + sandy.noble@gmail.com + http://www.polargraph.co.uk/ + https://github.com/euphy/polargraphcontroller + */ - This file is part of Polargraph Controller. - - Polargraph Controller is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Polargraph Controller 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Polargraph Controller. If not, see . - - Requires the excellent ControlP5 GUI library available from http://www.sojamo.de/libraries/controlP5/. - Requires the excellent Geomerative library available from http://www.ricardmarxer.com/geomerative/. - - This is an application for controlling a polargraph machine, communicating using ASCII command language over a serial link. - - sandy.noble@gmail.com - http://www.polargraph.co.uk/ - https://github.com/euphy/polargraphcontroller - -*/ - - -/*------------------------------------------------------------------------ - Details about the "serial port" subwindow -------------------------------------------------------------------------*/ - -void button_mode_serialPortDialog() -{ - ControlWindow serialPortWindow = cp5.addControlWindow("changeSerialPortWindow",100,100,150,350); - serialPortWindow.hideCoordinates(); - - serialPortWindow.setBackground(getBackgroundColour()); - Radio r = cp5.addRadio("radio_serialPort",10,10); - r.setWindow(serialPortWindow); - - String[] ports = Serial.list(); - if (getSerialPortNumber() >= 0 && getSerialPortNumber() < ports.length) - r.setValue(getSerialPortNumber()); - - r.add("setup", -2); - r.add("No serial connection", -1); - - for (int i = 0; i < ports.length; i++) - { - r.add(ports[i], i); - } - - int portNo = getSerialPortNumber(); - if (portNo > -1 && portNo < ports.length) - r.activate(ports[portNo]); - else - r.activate("No serial connection"); - - r.removeItem("setup"); -} - -void radio_serialPort(int newSerialPort) -{ - if (newSerialPort == -2) - { - } - else if (newSerialPort == -1) - { - println("Disconnecting serial port."); - useSerialPortConnection = false; - if (myPort != null) - { - myPort.stop(); - myPort = null; - } - drawbotReady = false; - drawbotConnected = false; - serialPortNumber = newSerialPort; - } - else if (newSerialPort != getSerialPortNumber()) - { - println("About to connect to serial port in slot " + newSerialPort); - // Print a list of the serial ports, for debugging purposes: - if (newSerialPort < Serial.list().length) - { - try - { - drawbotReady = false; - drawbotConnected = false; - if (myPort != null) - { - myPort.stop(); - myPort = null; - } - if (getSerialPortNumber() >= 0) - println("closing " + Serial.list()[getSerialPortNumber()]); - - serialPortNumber = newSerialPort; - String portName = Serial.list()[serialPortNumber]; - - myPort = new Serial(this, portName, getBaudRate()); - //read bytes into a buffer until you get a linefeed (ASCII 10): - myPort.bufferUntil('\n'); - useSerialPortConnection = true; - println("Successfully connected to port " + portName); - } - catch (Exception e) - { - println("Attempting to connect to serial port in slot " + getSerialPortNumber() - + " caused an exception: " + e.getMessage()); - } - } - else - { - println("No serial ports found."); - useSerialPortConnection = false; - } - } - else - { - println("no serial port change."); - } -} - - -/*------------------------------------------------------------------------ - Details about the "machine store" subwindow -------------------------------------------------------------------------*/ - -ControlWindow dialogWindow = null; - -void button_mode_machineStoreDialog() -{ - this.dialogWindow = cp5.addControlWindow("chooseStoreFilenameWindow",100,100,450,150); - dialogWindow.hideCoordinates(); - - dialogWindow.setBackground(getBackgroundColour()); - - Textfield filenameField = cp5.addTextfield("storeFilename",20,20,150,20); - filenameField.setText(getStoreFilename()); - filenameField.setLabel("Filename to store to"); - filenameField.setWindow(dialogWindow); - - Button submitButton = cp5.addButton("submitStoreFilenameWindow",0,180,20,60,20); - submitButton.setLabel("Submit"); - submitButton.setWindow(dialogWindow); - - Toggle overwriteToggle = cp5.addToggle("toggleAppendToFile",true,180,50,20,20); - overwriteToggle.setCaptionLabel("Overwrite existing file"); - overwriteToggle.setWindow(dialogWindow); - - filenameField.setFocus(true); - -} - -void storeFilename(String filename) -{ - println("Filename event: "+ filename); - if (filename != null && filename.length() <= 12) - { - setStoreFilename(filename); - sendMachineStoreMode(); - } -} - -void toggleAppendToFile(boolean theFlag) -{ - setOverwriteExistingStoreFile(theFlag); -} - -void submitStoreFilenameWindow(int theValue) -{ - Textfield tf = (Textfield) cp5.controller("storeFilename"); - tf.submit(); -} - -void button_mode_machineExecDialog() -{ - this.dialogWindow = cp5.addControlWindow("chooseExecFilenameWindow",100,100,450,150); - dialogWindow.hideCoordinates(); - - dialogWindow.setBackground(getBackgroundColour()); - - Textfield filenameField = cp5.addTextfield("execFilename",20,20,150,20); - filenameField.setText(getStoreFilename()); - filenameField.setLabel("Filename to execute from"); - filenameField.setWindow(dialogWindow); - - Button submitButton = cp5.addButton("submitExecFilenameWindow",0,180,20,60,20); - submitButton.setLabel("Submit"); - submitButton.setWindow(dialogWindow); - - filenameField.setFocus(true); - -} - -void execFilename(String filename) -{ - println("Filename event: "+ filename); - if (filename != null && filename.length() <= 12) - { - setStoreFilename(filename); - sendMachineExecMode(); - } -} -void submitExecFilenameWindow(int theValue) -{ - Textfield tf = (Textfield) cp5.controller("execFilename"); - tf.submit(); -} - -void button_mode_sendMachineLiveMode() -{ +void button_mode_sendMachineLiveMode() { sendMachineLiveMode(); } +String CHANGE_SERIAL_PORT_WINDOW_NAME = "changeSerialPortWindow"; +String MACHINE_STORE_WINDOW_NAME = "chooseStoreFilenameWindow"; +String MACHINE_EXEC_WINDOW_NAME = "chooseExecFilenameWindow"; +String DRAW_PIXELS_WINDOW_NAME = "drawPixelsWindow"; +String DRAW_WRITING_WINDOW_NAME = "drawWritingWindow"; +void button_mode_serialPortDialog() { + ControlFrameSimple cf = addSerialPortControlFrame("Serial Port", 200, 200, 20, 240, color( 100 ) ); +} +void button_mode_machineStoreDialog() { + ControlFrameSimple cf = addMachineStoreControlFrame("Machine Store", 450, 250, 20, 240, color( 100 ) ); +} +void button_mode_machineExecDialog() { + ControlFrameSimple cf = addMachineExecControlFrame("Machine Execute", 450, 250, 20, 240, color( 100 ) ); +} -/*------------------------------------------------------------------------ - Details about the "drawing" subwindow -------------------------------------------------------------------------*/ -void button_mode_drawPixelsDialog() -{ - this.dialogWindow = cp5.addControlWindow("drawPixelsWindow",100,100,450,150); - dialogWindow.hideCoordinates(); - - dialogWindow.setBackground(getBackgroundColour()); +void button_mode_drawPixelsDialog() { + ControlFrameSimple cf = addDrawPixelsControlFrame("Render pixels", 450, 250, 20, 240, color( 100 ) ); +} - Radio rPos = cp5.addRadio("radio_startPosition",10,10); - rPos.add("Top-right", DRAW_DIR_NE); - rPos.add("Bottom-right", DRAW_DIR_SE); - rPos.add("Bottom-left", DRAW_DIR_SW); - rPos.add("Top-left", DRAW_DIR_NW); - rPos.setWindow(dialogWindow); +void button_mode_drawWritingDialog() { + ControlFrameSimple cf = addSpriteWritingControlFrame("Sprite Writing", 450, 250, 20, 240, color( 100 ) ); +} - Radio rSkip = cp5.addRadio("radio_pixelSkipStyle",10,100); - rSkip.add("Lift pen over masked pixels", 1); - rSkip.add("Draw masked pixels as blanks", 2); - rSkip.setWindow(dialogWindow); +void button_mode_RandomSpriteDialog() { + ControlFrameSimple cf = addRandomSpriteControlFrame("Random Sprite", 450, 250, 20, 240, color( 100 ) ); +} -// Radio rDir = cp5.addRadio("radio_rowStartDirection",100,10); -// rDir.add("Upwards", 0); -// rDir.add("Downwards", 1); -// rDir.setWindow(dialogWindow); +void button_mode_drawNorwegianDialog() { + ControlFrameSimple cf = addNorwegianPixelControlFrame("Norwegian Pixel", 450, 250, 20, 240, color( 100 ) ); +} - Radio rStyle = cp5.addRadio("radio_pixelStyle",100,10); - rStyle.add("Variable frequency square wave", PIXEL_STYLE_SQ_FREQ); - rStyle.add("Variable size square wave", PIXEL_STYLE_SQ_SIZE); - rStyle.add("Solid square wave", PIXEL_STYLE_SQ_SOLID); - rStyle.add("Scribble", PIXEL_STYLE_SCRIBBLE); - if (currentHardware >= HARDWARE_VER_MEGA) - { - rStyle.add("Spiral", PIXEL_STYLE_CIRCLE); - rStyle.add("Sawtooth", PIXEL_STYLE_SAW); +///*------------------------------------------------------------------------ +// Details about the "writing" subwindow +//------------------------------------------------------------------------*/ + +String spriteWriting_textToWrite = ""; +String spriteWriting_spriteFilePrefix = "sprite/let"; +String spriteWriting_spriteFileSuffix = ".txt"; + +ControlFrameSimple addSpriteWritingControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) { + final Frame f = new Frame( theName ); + final ControlFrameSimple p = new ControlFrameSimple( this, theWidth, theHeight, theColor ); + + f.add( p ); + p.init(); + f.setTitle(theName); + f.setSize( p.w, p.h ); + f.setLocation( theX, theY ); + f.addWindowListener( new WindowAdapter() { + @Override + public void windowClosing(WindowEvent we) { + p.dispose(); + f.dispose(); + cp5s.remove(DRAW_WRITING_WINDOW_NAME); + } } - rStyle.setWindow(dialogWindow); - - Button submitButton = cp5.addButton("submitDrawWindow",0,280,10,120,20); - submitButton.setLabel("Generate commands"); - submitButton.setWindow(dialogWindow); - - -} - -public Integer renderStartPosition = DRAW_DIR_NE; // default top right hand corner for start -public Integer renderStartDirection = DRAW_DIR_SE; // default start drawing in SE direction (DOWN) -public Integer renderStyle = PIXEL_STYLE_SQ_FREQ; // default pixel style square wave -void radio_startPosition(int pos) -{ - this.renderStartPosition = pos; - radio_rowStartDirection(1); -} -void radio_rowStartDirection(int dir) -{ - if (renderStartPosition == DRAW_DIR_NE || renderStartPosition == DRAW_DIR_SW) - renderStartDirection = (dir == 0) ? DRAW_DIR_NW : DRAW_DIR_SE; - else if (renderStartPosition == DRAW_DIR_SE || renderStartPosition == DRAW_DIR_NW) - renderStartDirection = (dir == 0) ? DRAW_DIR_NE : DRAW_DIR_SW; -} -void radio_pixelStyle(int style) -{ - renderStyle = style; -} -void radio_pixelSkipStyle(int style) -{ - if (style == 1) - liftPenOnMaskedPixels = true; - else if (style == 2) - liftPenOnMaskedPixels = false; -} -void submitDrawWindow(int theValue) -{ - println("draw."); - println("Style: " + renderStyle); - println("Start pos: " + renderStartPosition); - println("Start dir: " + renderStartDirection); - - switch (renderStyle) - { - case PIXEL_STYLE_SQ_FREQ: button_mode_renderSquarePixel(); break; - case PIXEL_STYLE_SQ_SIZE: button_mode_renderScaledSquarePixels(); break; - case PIXEL_STYLE_SQ_SOLID: button_mode_renderSolidSquarePixels(); break; - case PIXEL_STYLE_SCRIBBLE: button_mode_renderScribblePixels(); break; - case PIXEL_STYLE_CIRCLE: button_mode_renderCirclePixel(); break; - case PIXEL_STYLE_SAW: button_mode_renderSawPixel(); break; + ); + f.setResizable( true ); + f.setVisible( true ); + // sleep a little bit to allow p to call setup. + // otherwise a nullpointerexception might be caused. + try { + Thread.sleep( 100 ); + } + catch(Exception e) { } - -} - -/*------------------------------------------------------------------------ - Details about the "writing" subwindow -------------------------------------------------------------------------*/ -String textToWrite = ""; -String spriteFilePrefix = "sprite/let"; -String spriteFileSuffix = ".txt"; - -void button_mode_drawWritingDialog() -{ - this.dialogWindow = cp5.addControlWindow("drawWritingWindow",100,100,450,200); - dialogWindow.hideCoordinates(); + cp5s.put(DRAW_WRITING_WINDOW_NAME, p.cp5()); + println(cp5s); - dialogWindow.setBackground(getBackgroundColour()); + // set up controls + Textfield spriteFileField = p.cp5().addTextfield("spriteWriting_spriteFilePrefixField", 20, 20, 150, 20) + .setText(spriteWriting_getSpriteFilePrefix()) + .setLabel("File prefix") + .plugTo(this, "spriteWriting_spriteFilePrefixField"); - Textfield spriteFileField = cp5.addTextfield("spriteFilePrefixField",20,20,150,20); - spriteFileField.setText(getSpriteFilePrefix()); - spriteFileField.setLabel("File prefix"); - spriteFileField.setWindow(dialogWindow); + Textfield writingField = p.cp5().addTextfield("spriteWriting_textToWriteField", 20, 60, 400, 20) + .setText(spriteWriting_getTextToWrite()) + .setLabel("Text to write") + .plugTo(this, "spriteWriting_textToWriteField"); - Textfield writingField = cp5.addTextfield("textToWriteField",20,60,400,20); - writingField.setText(getTextToWrite()); - writingField.setLabel("Text to write"); - writingField.setWindow(dialogWindow); + Button importTextButton = p.cp5().addButton("spriteWriting_importTextButton", 0, 20, 100, 120, 20) + .setLabel("Load text from file") + .addListener( new ControlListener() { + public void controlEvent( ControlEvent ev ) { + spriteWriting_importTextButton(); + } + }); + + RadioButton rPos = p.cp5().addRadioButton("spriteWriting_radio_drawWritingDirection", 20, 140); + rPos.add("South-east", DRAW_DIR_SE); + rPos.activate("South-east"); + rPos.plugTo(this, "spriteWriting_radio_drawWritingDirection"); - Button importTextButton = cp5.addButton("importTextButton",0,20,100,120,20); - importTextButton.setLabel("Load text from file"); - importTextButton.setWindow(dialogWindow); - - Radio rPos = cp5.addRadio("radio_drawWritingDirection",20,140); -// rPos.add("North-east", DRAW_DIR_NE); - rPos.add("South-east", DRAW_DIR_SE); -// rPos.add("South-west", DRAW_DIR_SW); -// rPos.add("North-west", DRAW_DIR_NW); - rPos.setWindow(dialogWindow); - - - - Button submitButton = cp5.addButton("submitWritingWindow",0,300,100,120,20); - submitButton.setLabel("Generate commands"); - submitButton.setWindow(dialogWindow); -} - -void spriteFilePrefixField(String value) -{ - spriteFilePrefix = value; -} -void textToWriteField(String value) -{ - textToWrite = value; -} - -String getTextToWrite() -{ - return textToWrite; -} -String getSpriteFilePrefix() -{ - return spriteFilePrefix; -} -String getSpriteFileSuffix() -{ - return spriteFileSuffix; -} - -void importTextButton() -{ - textToWrite = importTextToWriteFromFile(); - Textfield tf = (Textfield) cp5.controller("textToWriteField"); - tf.setText(getTextToWrite()); - tf.submit(); + Button submitButton = p.cp5.addButton("spriteWriting_submitWritingWindow", 0, 300, 100, 120, 20) + .setLabel("Generate commands") + .addListener( new ControlListener() { + public void controlEvent( ControlEvent ev ) { + spriteWriting_submitWritingWindow(p.cp5()); + } + }); + + + return p; } -void submitWritingWindow(int theValue) -{ - println("Write."); - - Textfield tf = (Textfield) cp5.controller("spriteFilePrefixField"); - tf.submit(); - tf.setText(getSpriteFilePrefix()); - tf = (Textfield) cp5.controller("textToWriteField"); - tf.submit(); - tf.setText(getTextToWrite()); - - println("Start dir: " + renderStartDirection); - println("Sprite file prefix: " + spriteFilePrefix); - println("Text: " + textToWrite); - for (int i=0; i rows = java.util.Arrays.asList(loadStrings(fp)); + StringBuilder sb = new StringBuilder(200); + for (String row : rows) { + sb.append(row); + } + spriteWriting_textToWriteField(sb.toString()); + println("Completed text import, " + spriteWriting_getTextToWrite().length() + " characters found."); + + println("Text: " + spriteWriting_getTextToWrite()); + + println(cp5s); + + Textfield tf = cp5s.get(DRAW_WRITING_WINDOW_NAME).get(Textfield.class, "spriteWriting_textToWriteField"); + if (spriteWriting_getTextToWrite() != null + && !"".equals(spriteWriting_getTextToWrite().trim())) { + tf.setText(spriteWriting_getTextToWrite()); + tf.submit(); + tf.setText(spriteWriting_getTextToWrite()); + } + } + } + + void spriteWriting_submitWritingWindow(ControlP5 parent) { - String filename = getSpriteFilePrefix() + (int) getTextToWrite().charAt(i) + getSpriteFileSuffix(); - addToCommandQueue(CMD_DRAW_SPRITE + int(gridSize * pixelScalingOverGridSize) + "," + filename+",END"); - println(filename); + println("Write."); + + Textfield tf = parent.get(Textfield.class, "spriteWriting_spriteFilePrefixField"); + tf.submit(); + tf.setText(spriteWriting_getSpriteFilePrefix()); + + Textfield wf = parent.get(Textfield.class, "spriteWriting_textToWriteField"); + wf.submit(); + wf.setText(spriteWriting_getTextToWrite()); + + println("Start dir: " + renderStartDirection); + println("Sprite file prefix: " + spriteWriting_spriteFilePrefix); + println("Text: " + spriteWriting_textToWrite); + + for (int i=0; i getPanelNames() -{ +Set getPanelNames() { if (this.panelNames == null) this.panelNames = buildPanelNames(); return this.panelNames; } -List getTabNames() -{ +List getTabNames() { if (this.tabNames == null) this.tabNames = buildTabNames(); return this.tabNames; } -Set getControlNames() -{ +Set getControlNames() { if (this.controlNames == null) this.controlNames = buildControlNames(); return this.controlNames; } -Map> getControlsForPanels() -{ +Map> getControlsForPanels() { if (this.controlsForPanels == null) this.controlsForPanels = buildControlsForPanels(); return this.controlsForPanels; } -Map getAllControls() -{ +Map getAllControls() { if (this.allControls == null) this.allControls = buildAllControls(); return this.allControls; } -Map getControlLabels() -{ +Map getControlLabels() { if (this.controlLabels == null) this.controlLabels = buildControlLabels(); return this.controlLabels; } -Map> getPanelsForTabs() -{ +Map> getPanelsForTabs() { if (this.panelsForTabs == null) this.panelsForTabs = buildPanelsForTabs(); return this.panelsForTabs; } -Map getPanels() -{ +Map getPanels() { if (this.panels == null) this.panels = buildPanels(); return this.panels; } -Set getControlsToLockIfBoxNotSpecified() -{ +Set getControlsToLockIfBoxNotSpecified() { if (this.controlsToLockIfBoxNotSpecified == null) { this.controlsToLockIfBoxNotSpecified = buildControlsToLockIfBoxNotSpecified(); @@ -86,8 +75,7 @@ Set getControlsToLockIfBoxNotSpecified() return this.controlsToLockIfBoxNotSpecified; } -Set getControlsToLockIfImageNotLoaded() -{ +Set getControlsToLockIfImageNotLoaded() { if (this.controlsToLockIfImageNotLoaded == null) { this.controlsToLockIfImageNotLoaded = buildControlsToLockIfImageNotLoaded(); @@ -95,9 +83,7 @@ Set getControlsToLockIfImageNotLoaded() return this.controlsToLockIfImageNotLoaded; } - -void hideAllControls() -{ +void hideAllControls() { for (String key : allControls.keySet()) { Controller c = allControls.get(key); @@ -105,8 +91,7 @@ void hideAllControls() } } -Map buildPanels() -{ +Map buildPanels() { Map panels = new HashMap(); float panelHeight = frame.getHeight() - getMainPanelPosition().y - (DEFAULT_CONTROL_SIZE.y*3); @@ -123,7 +108,7 @@ Map buildPanels() panels.put(PANEL_NAME_INPUT, inputPanel); Panel rovingPanel = new Panel(PANEL_NAME_ROVING, panelOutline); - rovingPanel.setOutlineColour(color(200,200,200)); + rovingPanel.setOutlineColour(color(100,200,200)); // get controls rovingPanel.setResizable(true); rovingPanel.setControls(getControlsForPanels().get(PANEL_NAME_ROVING)); @@ -133,7 +118,7 @@ Map buildPanels() panels.put(PANEL_NAME_ROVING, rovingPanel); Panel tracePanel = new Panel(PANEL_NAME_TRACE, panelOutline); - tracePanel.setOutlineColour(color(200,200,200)); + tracePanel.setOutlineColour(color(200,255,200)); // get controls tracePanel.setResizable(true); tracePanel.setControls(getControlsForPanels().get(PANEL_NAME_TRACE)); @@ -143,7 +128,7 @@ Map buildPanels() panels.put(PANEL_NAME_TRACE, tracePanel); Panel detailsPanel = new Panel(PANEL_NAME_DETAILS, panelOutline); - detailsPanel.setOutlineColour(color(200, 200, 200)); + detailsPanel.setOutlineColour(color(200, 200, 255)); // get controls detailsPanel.setResizable(true); detailsPanel.setControls(getControlsForPanels().get(PANEL_NAME_DETAILS)); @@ -153,7 +138,7 @@ Map buildPanels() panels.put(PANEL_NAME_DETAILS, detailsPanel); Panel queuePanel = new Panel(PANEL_NAME_QUEUE, panelOutline); - queuePanel.setOutlineColour(color(200, 200, 200)); + queuePanel.setOutlineColour(color(200, 200, 50)); // get controls queuePanel.setResizable(true); queuePanel.setControls(getControlsForPanels().get(PANEL_NAME_QUEUE)); @@ -167,7 +152,7 @@ Map buildPanels() new PVector((DEFAULT_CONTROL_SIZE.x+CONTROL_SPACING.x)*2, (DEFAULT_CONTROL_SIZE.y+CONTROL_SPACING.y)*2)); Panel generalPanel = new Panel(PANEL_NAME_GENERAL, panelOutline); generalPanel.setResizable(false); - generalPanel.setOutlineColour(color(200, 200, 200)); + generalPanel.setOutlineColour(color(200, 50, 200)); // get controls generalPanel.setControls(getControlsForPanels().get(PANEL_NAME_GENERAL)); // get control positions @@ -243,9 +228,9 @@ Map buildAllControls() Toggle t = cp5.addToggle(controlName, false, 100, 100, 100, 100); t.setLabel(getControlLabels().get(controlName)); t.hide(); - controlP5.Label l = t.captionLabel(); - l.style().marginTop = -17; //move upwards (relative to button size) - l.style().marginLeft = 4; //move to the right + controlP5.Label l = t.getCaptionLabel(); + l.getStyle().marginTop = -17; //move upwards (relative to button size) + l.getStyle().marginLeft = 4; //move to the right map.put(controlName, t); // println("Added toggle " + controlName); } @@ -254,9 +239,9 @@ Map buildAllControls() Toggle t = cp5.addToggle(controlName, false, 100, 100, 100, 100); t.setLabel(getControlLabels().get(controlName)); t.hide(); - controlP5.Label l = t.captionLabel(); - l.style().marginTop = -17; //move upwards (relative to button size) - l.style().marginLeft = 4; //move to the right + controlP5.Label l = t.getCaptionLabel(); + l.getStyle().marginTop = -17; //move upwards (relative to button size) + l.getStyle().marginLeft = 4; //move to the right map.put(controlName, t); // println("Added minitoggle " + controlName); } @@ -266,9 +251,9 @@ Map buildAllControls() n.setLabel(getControlLabels().get(controlName)); n.hide(); n.setDecimalPrecision(0); - controlP5.Label l = n.captionLabel(); - l.style().marginTop = -17; //move upwards (relative to button size) - l.style().marginLeft = 40; //move to the right + controlP5.Label l = n.getCaptionLabel(); + l.getStyle().marginTop = -17; //move upwards (relative to button size) + l.getStyle().marginLeft = 40; //move to the right // change the control direction to left/right n.setDirection(Controller.VERTICAL); map.put(controlName, n); @@ -504,7 +489,7 @@ Map initialiseNumberboxValues(Map map) } else if (MODE_ADJUST_PREVIEW_CORD_OFFSET.equals(key)) { - n.setDecimalPrecision(1); + n.setDecimalPrecision(0); n.setValue(0); n.setMultiplier(0.5); } @@ -563,9 +548,6 @@ Map initialiseToggleValues(Map map) return map; } - - - String getControlLabel(String butName) { if (controlLabels.containsKey(butName)) @@ -582,10 +564,10 @@ Map buildControlPositionsForPanel(Panel panel) int row = 0; for (Controller controller : panel.getControls()) { - if (controller.name().startsWith("minitoggle_")) + if (controller.getName().startsWith("minitoggle_")) { PVector p = new PVector(col*(DEFAULT_CONTROL_SIZE.x+CONTROL_SPACING.x), row*(DEFAULT_CONTROL_SIZE.y+CONTROL_SPACING.y)); - map.put(controller.name(), p); + map.put(controller.getName(), p); row++; if (p.y + (DEFAULT_CONTROL_SIZE.y*2) >= panel.getOutline().getHeight()) { @@ -596,7 +578,7 @@ Map buildControlPositionsForPanel(Panel panel) else { PVector p = new PVector(col*(DEFAULT_CONTROL_SIZE.x+CONTROL_SPACING.x), row*(DEFAULT_CONTROL_SIZE.y+CONTROL_SPACING.y)); - map.put(controller.name(), p); + map.put(controller.getName(), p); row++; if (p.y + (DEFAULT_CONTROL_SIZE.y*2) >= panel.getOutline().getHeight()) { @@ -605,9 +587,9 @@ Map buildControlPositionsForPanel(Panel panel) } } } - return map; } + Map buildControlSizesForPanel(Panel panel) { //println("Building control sizes for panel " + panel.getName()); @@ -617,16 +599,16 @@ Map buildControlSizesForPanel(Panel panel) int row = 0; for (Controller controller : panel.getControls()) { - if (controller.name().startsWith("minitoggle_")) + if (controller.getName().startsWith("minitoggle_")) { PVector s = new PVector(DEFAULT_CONTROL_SIZE.y, DEFAULT_CONTROL_SIZE.y); - map.put(controller.name(), s); + map.put(controller.getName(), s); } else { PVector s = new PVector(DEFAULT_CONTROL_SIZE.x, DEFAULT_CONTROL_SIZE.y); - map.put(controller.name(), s); - //println("Added size of " + controller.name() + " to panel. " + s); + map.put(controller.getName(), s); + //println("Added size of " + controller.getName() + " to panel. " + s); } } @@ -970,7 +952,7 @@ Map buildControlLabels() result.put(MODE_SEND_BUTTON_ACTIVATE, "Activate button"); result.put(MODE_SEND_BUTTON_DEACTIVATE, "Deactivate button"); - result.put(MODE_ADJUST_PREVIEW_CORD_OFFSET, "Preview cord offset"); + result.put(MODE_ADJUST_PREVIEW_CORD_OFFSET, "Cord offset"); return result; @@ -1090,13 +1072,13 @@ Set buildControlNames() result.add(MODE_SELECT_ROVE_IMAGE_SOURCE); result.add(MODE_SEND_START_TEXT); result.add(MODE_SHOW_WRITING_DIALOG); - result.add(MODE_START_SWIRLING); - result.add(MODE_STOP_SWIRLING); - result.add(MODE_START_MARKING); - result.add(MODE_STOP_MARKING); - result.add(MODE_START_SPRITE); - result.add(MODE_START_RANDOM_SPRITES); - result.add(MODE_STOP_RANDOM_SPRITES); +// result.add(MODE_START_SWIRLING); +// result.add(MODE_STOP_SWIRLING); +// result.add(MODE_START_MARKING); +// result.add(MODE_STOP_MARKING); +// result.add(MODE_START_SPRITE); +// result.add(MODE_START_RANDOM_SPRITES); +// result.add(MODE_STOP_RANDOM_SPRITES); result.add(MODE_DRAW_NORWEGIAN_DIALOG); result.add(MODE_LIVE_BLUR_VALUE); diff --git a/drawing.pde b/drawing.pde index 16996d0..e7ce185 100644 --- a/drawing.pde +++ b/drawing.pde @@ -25,7 +25,6 @@ sandy.noble@gmail.com http://www.polargraph.co.uk/ https://github.com/euphy/polargraphcontroller - */ static final String CMD_CHANGELENGTH = "C01,"; static final String CMD_CHANGEPENWIDTH = "C02,"; @@ -945,7 +944,7 @@ void sendMachineStoreMode() } void sendMachineLiveMode() { - addToRealtimeCommandQueue(CMD_MACHINE_MODE_LIVE+"END"); + addToCommandQueue(CMD_MACHINE_MODE_LIVE+"END"); } void sendMachineExecMode() { diff --git a/gamepad.pde b/gamepad.pde deleted file mode 100644 index c288673..0000000 --- a/gamepad.pde +++ /dev/null @@ -1,234 +0,0 @@ -//ControllIO controllIO; -//ControllDevice joypad; -// -//ControllButton buttonA; -//ControllButton buttonB; -//ControllButton buttonX; -//ControllButton buttonY; -//ControllButton buttonL; -//ControllButton buttonR; -//ControllButton buttonStart; -// -//ControllCoolieHat dpad; -// -//List devices = new ArrayList( -// Arrays.asList("Controller (Xbox 360 Wireless Receiver for Windows)", -// "Controller (XBOX 360 For Windows)")); -// -//String signalFromGamepad = null; -// -//static final String BUTTON_A_RELEASED = "ButtonAReleased"; -//static final String BUTTON_B_RELEASED = "ButtonBReleased"; -//static final String BUTTON_L_RELEASED = "ButtonLReleased"; -//static final String BUTTON_R_RELEASED = "ButtonRReleased"; -//static final String BUTTON_START_RELEASED = "ButtonStartReleased"; -// -//void gamepad_init() -//{ -// controllIO = ControllIO.getInstance(this); -// -// try -// { -// controllIO.printDevices(); -// for (int i = 0; i LIVE_SIMPLIFICATION_MAX) -// liveSimplification = LIVE_SIMPLIFICATION_MAX; -// } -// if (val == 8.0) // left -// { -// pathLengthHighPassCutoff--; -// if (pathLengthHighPassCutoff < PATH_LENGTH_HIGHPASS_CUTOFF_MIN) -// pathLengthHighPassCutoff = PATH_LENGTH_HIGHPASS_CUTOFF_MIN; -// } -// else if (val == 4.0) // right -// { -// pathLengthHighPassCutoff++; -// if (pathLengthHighPassCutoff > PATH_LENGTH_HIGHPASS_CUTOFF_MAX) -// pathLengthHighPassCutoff = PATH_LENGTH_HIGHPASS_CUTOFF_MAX; -// } -// -// Numberbox n = (Numberbox) getAllControls().get(MODE_LIVE_SIMPLIFICATION_VALUE); -// n.setValue(liveSimplification); -// n.update(); -// -// n = (Numberbox) getAllControls().get(MODE_VECTOR_PATH_LENGTH_HIGHPASS_CUTOFF); -// n.setValue(pathLengthHighPassCutoff); -// n.update(); -// -//} -// -//void processGamepadInput() -//{ -// if (signalFromGamepad != null) -// { -// println("Signal from gamepad: " + signalFromGamepad); -// if (signalFromGamepad == BUTTON_A_RELEASED) -// { -// if (captureShape == null && !confirmedDraw) -// button_mode_liveCaptureFromLive(); -// else if (captureShape != null && !confirmedDraw) -// button_mode_liveClearCapture(); -// else if (captureShape != null && confirmedDraw) -// { -// button_mode_liveClearCapture(); -// button_mode_clearQueue(); -// confirmedDraw = false; -// } -// } -// else if (signalFromGamepad == BUTTON_B_RELEASED) -// { -// if (captureShape != null && !confirmedDraw) -// button_mode_liveConfirmDraw(); -// } -// else if (signalFromGamepad == BUTTON_L_RELEASED) -// { -// commandQueueRunning = !commandQueueRunning; -// } -// else if (signalFromGamepad == BUTTON_R_RELEASED) -// { -// } -// else if (signalFromGamepad == BUTTON_START_RELEASED) -// { -// preLoadCommandQueue(); -// button_mode_setPositionHome(); -// } -// -// -// // clear the signal -// signalFromGamepad = null; -// } -// -//} - -//void displayGamepadOverlay() -//{ -// textSize(40); -// fill(255); -// -// if (captureShape == null) -// { -// image(aButtonImage, width-400, height-180, 128, 128); -// text("SNAP!", width-400, height-200); -// -// textSize(30); -// image(dpadYImage, width-600, height-180, 128, 128); -// text("Simplify", width-600, height-200); -// -// image(dpadXImage, width-600, height-400, 128, 128); -// text("Filter short paths", width-600, height-420); -// } -// else -// { -// if (confirmedDraw) -// { -// image(aButtonImage, width-400, height-180, 128, 128); -// text("CANCEL!", width-385, height-200); -// } -// else -// { -// image(aButtonImage, width-400, height-180, 128, 128); -// text("BACK", width-400, height-200); -// image(bButtonImage, width-190, height-180, 128, 128); -// text("DRAW!", width-180, height-200); -// } -// } -// -// -// textSize(12); -//} diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index dacc05b..beac9d1 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -28,6 +28,7 @@ https://github.com/euphy/polargraphcontroller */ + //import processing.video.*; import diewald_CV_kit.libraryinfo.*; import diewald_CV_kit.utility.*; @@ -50,13 +51,20 @@ import processing.serial.*; import controlP5.*; import java.awt.event.KeyEvent; import java.awt.event.*; +import java.awt.Frame; +import java.awt.BorderLayout; -int majorVersionNo = 1; -int minorVersionNo = 2; -int buildNo = 2; +import java.lang.reflect.Method; + +int majorVersionNo = 2; +int minorVersionNo = 0; +int buildNo = 3; String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo; ControlP5 cp5; +Map cp5s = new HashMap(); + + boolean drawbotReady = false; boolean drawbotConnected = false; @@ -388,11 +396,11 @@ static final char BITMAP_BACKGROUND_COLOUR = 0x0F; PVector homePointCartesian = null; -public color chromaKeyColour = color(0, 255, 0); +public color chromaKeyColour = color(0,255,0); // used in the preview page public color pageColour = color(220); -public color frameColour = color(200, 0, 0); +public color frameColour = color(200,0,0); public color machineColour = color(150); public color guideColour = color(255); public color backgroundColour = color(100); @@ -438,7 +446,7 @@ public static final String PANEL_NAME_TRACE = "panel_trace"; public static final String PANEL_NAME_GENERAL = "panel_general"; public final PVector DEFAULT_CONTROL_SIZE = new PVector(100.0, 20.0); -public final PVector CONTROL_SPACING = new PVector(2.0, 2.0); +public final PVector CONTROL_SPACING = new PVector(4.0, 4.0); public PVector mainPanelPosition = new PVector(10.0, 85.0); public final Integer PANEL_MIN_HEIGHT = 400; @@ -459,13 +467,13 @@ public Map panels = null; // machine moving PVector machineDragOffset = new PVector (0.0, 0.0); PVector lastMachineDragPosition = new PVector (0.0, 0.0); -public final float MIN_SCALING = 0.1; -public final float MAX_SCALING = 15.0; +public final float MIN_SCALING = 0.01; +public final float MAX_SCALING = 30.0; RShape vectorShape = null; String vectorFilename = null; float vectorScaling = 100; -PVector vectorPosition = new PVector(0.0, 0.0); +PVector vectorPosition = new PVector(0.0,0.0); int minimumVectorLineLength = 0; public static final int VECTOR_FILTER_LOW_PASS = 0; @@ -494,8 +502,6 @@ static int pathLengthHighPassCutoff = 0; static final Integer PATH_LENGTH_HIGHPASS_CUTOFF_MAX = 10000; static final Integer PATH_LENGTH_HIGHPASS_CUTOFF_MIN = 0; -//Capture liveCamera; -//JMyron liveCamera; BlobDetector blob_detector; int liveSimplification = 5; int blurValue = 1; @@ -510,29 +516,34 @@ String shapeSavePath = "../../savedcaptures/"; String shapeSavePrefix = "shape-"; String shapeSaveExtension = ".svg"; -static Float gcodeZAxisDrawingHeight = 1.0; //-0.125000; +String filePath = null; + +static PApplet parentPapplet = null; void setup() { println("Running polargraph controller"); frame.setResizable(true); initLogging(); - - initImages(); - + parentPapplet = this; + RG.init(this); RG.setPolygonizer(RG.ADAPTATIVE); try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(); } loadFromPropertiesFile(); - + +// size(400, 400, JAVA2D ); +// surface.setResizable(true); +// surface.setSize(windowWidth, windowHeight); + size(windowWidth, windowHeight, JAVA2D); this.cp5 = new ControlP5(this); initTabs(); @@ -540,7 +551,7 @@ void setup() println("Serial ports available on your machine:"); println(serialPorts); - // println("getSerialPortNumber()"+getSerialPortNumber()); +// println("getSerialPortNumber()"+getSerialPortNumber()); if (getSerialPortNumber() >= 0) { println("About to connect to serial port in slot " + getSerialPortNumber()); @@ -561,8 +572,8 @@ void setup() catch (Exception e) { println("Attempting to connect to serial port " - + portName + " in slot " + getSerialPortNumber() - + " caused an exception: " + e.getMessage()); + + portName + " in slot " + getSerialPortNumber() + + " caused an exception: " + e.getMessage()); } } else @@ -578,34 +589,34 @@ void setup() currentMode = MODE_BEGIN; preLoadCommandQueue(); - size(windowWidth, windowHeight, JAVA2D ); changeTab(TAB_NAME_INPUT, TAB_NAME_INPUT); addEventListeners(); - //gamepad_init(); + frameRate(8); } void addEventListeners() { frame.addComponentListener(new ComponentAdapter() - { - public void componentResized(ComponentEvent event) { - if (event.getSource()==frame) + public void componentResized(ComponentEvent event) { - windowResized(); + if (event.getSource()==frame) + { + windowResized(); + } } } - } - ); - addMouseWheelListener(new java.awt.event.MouseWheelListener() - { - public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) - { - mouseWheel(evt.getWheelRotation()); - } - } ); + + addMouseWheelListener(new java.awt.event.MouseWheelListener() + { + public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) + { + mouseWheel(evt.getWheelRotation()); + } + } + ); } @@ -625,6 +636,7 @@ void windowResized() Panel p = getPanels().get(key); p.setHeight(frame.getHeight() - p.getOutline().getTop() - (DEFAULT_CONTROL_SIZE.y*2)); } + } void draw() { @@ -667,6 +679,7 @@ void draw() { dispatchCommandQueue(); } + } String getCurrentTab() @@ -687,6 +700,7 @@ boolean isShowingDialogBox() } void drawDialogBox() { + } String getVectorFilename() { @@ -744,12 +758,12 @@ void drawImagePage() getDisplayMachine().draw(); drawMoveImageOutline(); stroke(255, 0, 0); - + for (Panel panel : getPanelsForTab(TAB_NAME_INPUT)) { panel.draw(); } - stroke(200, 200); + stroke(200,200); text(propertiesFilename, getPanel(PANEL_NAME_GENERAL).getOutline().getLeft(), getPanel(PANEL_NAME_GENERAL).getOutline().getTop()-7); showGroupBox(); @@ -757,7 +771,7 @@ void drawImagePage() if (displayingQueuePreview) previewQueue(); if (displayingInfoTextOnInputPage) - showText(250, 45); + showText(250,45); drawStatusText((int)statusTextPosition.x, (int)statusTextPosition.y); showCommandQueue((int) getDisplayMachine().getOutline().getRight()+6, 20); @@ -765,7 +779,7 @@ void drawImagePage() void drawMachineOutline() { - rect(machinePosition.x, machinePosition.y, machinePosition.x+getDisplayMachine().getWidth(), machinePosition.y+getDisplayMachine().getHeight()); + rect(machinePosition.x,machinePosition.y, machinePosition.x+getDisplayMachine().getWidth(), machinePosition.y+getDisplayMachine().getHeight()); } void drawDetailsPage() { @@ -778,16 +792,16 @@ void drawDetailsPage() noFill(); getDisplayMachine().drawForSetup(); stroke(255, 0, 0); - + for (Panel panel : getPanelsForTab(TAB_NAME_DETAILS)) { panel.draw(); } text(propertiesFilename, getPanel(PANEL_NAME_GENERAL).getOutline().getLeft(), getPanel(PANEL_NAME_GENERAL).getOutline().getTop()-7); - // showCurrentMachinePosition(); +// showCurrentMachinePosition(); if (displayingInfoTextOnInputPage) - showText(250, 45); + showText(250,45); drawStatusText((int)statusTextPosition.x, (int)statusTextPosition.y); showCommandQueue((int) getDisplayMachine().getOutline().getRight()+6, 20); @@ -804,18 +818,18 @@ void drawRovingPage() noFill(); getDisplayMachine().drawForSetup(); stroke(255, 0, 0); - + for (Panel panel : getPanelsForTab(TAB_NAME_ROVING)) { panel.draw(); } text(propertiesFilename, getPanel(PANEL_NAME_GENERAL).getOutline().getLeft(), getPanel(PANEL_NAME_GENERAL).getOutline().getTop()-7); - // showCurrentMachinePosition(); +// showCurrentMachinePosition(); showGroupBox(); showCurrentMachinePosition(); if (displayingInfoTextOnInputPage) - showText(250, 45); + showText(250,45); drawStatusText((int)statusTextPosition.x, (int)statusTextPosition.y); showCommandQueue((int) getDisplayMachine().getOutline().getRight()+6, 20); @@ -840,7 +854,7 @@ void drawTracePage() } stroke(255, 0, 0); - + for (Panel panel : getPanelsForTab(TAB_NAME_TRACE)) { panel.draw(); @@ -849,15 +863,15 @@ void drawTracePage() if (displayingInfoTextOnInputPage) - showText(250, 45); + showText(250,45); drawStatusText((int)statusTextPosition.x, (int)statusTextPosition.y); showCommandQueue((int) width-200, 20); - // processGamepadInput(); - // - // if (displayGamepadOverlay) - // displayGamepadOverlay(); +// processGamepadInput(); +// +// if (displayGamepadOverlay) +// displayGamepadOverlay(); } @@ -870,9 +884,9 @@ void drawCommandQueuePage() fill(100); drawMachineOutline(); showingSummaryOverlay = false; + - - + int right = 0; for (Panel panel : getPanelsForTab(TAB_NAME_QUEUE)) { @@ -883,8 +897,9 @@ void drawCommandQueuePage() } text(propertiesFilename, getPanel(PANEL_NAME_GENERAL).getOutline().getLeft(), getPanel(PANEL_NAME_GENERAL).getOutline().getTop()-7); showCommandQueue(right, (int)mainPanelPosition.y); - + drawStatusText((int)statusTextPosition.x, (int)statusTextPosition.y); + } void drawImageLoadPage() @@ -903,15 +918,15 @@ void drawMoveImageOutline() PVector imageSizeOnScreen = getDisplayMachine().scaleToScreen(imageSize); imageSizeOnScreen.sub(getDisplayMachine().getOutline().getTopLeft()); PVector offset = new PVector(imageSizeOnScreen.x/2.0, imageSizeOnScreen.y/2.0); - + PVector mVect = getMouseVector(); PVector imagePos = new PVector(mVect.x-offset.x, mVect.y-offset.y); - fill(80, 50); + fill(80,50); noStroke(); rect(imagePos.x+imageSizeOnScreen.x, imagePos.y+4, 4, imageSizeOnScreen.y); rect(imagePos.x+4, imageSizeOnScreen.y+imagePos.y, imageSizeOnScreen.x-4, 4); - tint(255, 180); + tint(255,180); image(getDisplayMachine().getImage(), imagePos.x, imagePos.y, imageSizeOnScreen.x, imageSizeOnScreen.y); noTint(); // decorate image @@ -953,12 +968,12 @@ void drawMoveImageOutline() void showCurrentMachinePosition() { noStroke(); - fill(255, 0, 255, 150); + fill(255,0,255,150); PVector pgCoord = getDisplayMachine().scaleToScreen(currentMachinePos); ellipse(pgCoord.x, pgCoord.y, 20, 20); // also show cartesian position if reported - fill(255, 255, 0, 150); + fill(255,255,0,150); ellipse(currentCartesianMachinePos.x, currentCartesianMachinePos.y, 15, 15); noFill(); @@ -982,14 +997,14 @@ void showGroupBox() noFill(); stroke(getFrameColour()); strokeWeight(1); - + if (getBoxVector1() != null) { PVector topLeft = getDisplayMachine().scaleToScreen(boxVector1); line(topLeft.x, topLeft.y, topLeft.x-10, topLeft.y); line(topLeft.x, topLeft.y, topLeft.x, topLeft.y-10); } - + if (getBoxVector2() != null) { PVector botRight = getDisplayMachine().scaleToScreen(boxVector2); @@ -998,6 +1013,7 @@ void showGroupBox() } } } + } void loadImageWithFileChooser() @@ -1007,7 +1023,7 @@ void loadImageWithFileChooser() public void run() { JFileChooser fc = new JFileChooser(); fc.setFileFilter(new ImageFileFilter()); - + fc.setDialogTitle("Choose an image file..."); int returned = fc.showOpenDialog(frame); @@ -1027,22 +1043,21 @@ void loadImageWithFileChooser() } } } - } - ); + }); } class ImageFileFilter extends javax.swing.filechooser.FileFilter { public boolean accept(File file) { - String filename = file.getName(); - filename.toLowerCase(); - if (file.isDirectory() || filename.endsWith(".png") || filename.endsWith(".jpg") || filename.endsWith(".jpeg")) - return true; - else - return false; + String filename = file.getName(); + filename.toLowerCase(); + if (file.isDirectory() || filename.endsWith(".png") || filename.endsWith(".jpg") || filename.endsWith(".jpeg")) + return true; + else + return false; } public String getDescription() { - return "Image files (PNG or JPG)"; + return "Image files (PNG or JPG)"; } } @@ -1053,7 +1068,7 @@ void loadVectorWithFileChooser() public void run() { JFileChooser fc = new JFileChooser(); fc.setFileFilter(new VectorFileFilter()); - + fc.setDialogTitle("Choose a vector file..."); int returned = fc.showOpenDialog(frame); @@ -1062,7 +1077,7 @@ void loadVectorWithFileChooser() File file = fc.getSelectedFile(); if (file.exists()) { - RShape shape = loadShapeFromFile(file.getPath()); + RShape shape = RG.loadShape(file.getPath()); if (shape != null) { setVectorFilename(file.getPath()); @@ -1075,25 +1090,23 @@ void loadVectorWithFileChooser() } } } - } - ); + }); } class VectorFileFilter extends javax.swing.filechooser.FileFilter { public boolean accept(File file) { - String filename = file.getName(); - filename.toLowerCase(); - if (file.isDirectory() || filename.endsWith(".svg") || filename.endsWith(".gco") || filename.endsWith(".g")) - return true; - else - return false; + String filename = file.getName(); + filename.toLowerCase(); + if (file.isDirectory() || filename.endsWith(".svg")) + return true; + else + return false; } public String getDescription() { - return "Vector graphic files (SVG, GCode)"; + return "Vector graphic files (SVG)"; } } - void loadNewPropertiesFilenameWithFileChooser() { SwingUtilities.invokeLater(new Runnable() @@ -1102,7 +1115,7 @@ void loadNewPropertiesFilenameWithFileChooser() { JFileChooser fc = new JFileChooser(); fc.setFileFilter(new PropertiesFileFilter()); - + fc.setDialogTitle("Choose a config file..."); int returned = fc.showOpenDialog(frame); @@ -1118,28 +1131,27 @@ void loadNewPropertiesFilenameWithFileChooser() // clear old properties. props = null; loadFromPropertiesFile(); - + // set values of number spinners etc updateNumberboxValues(); - } + } } } - } - ); + }); } class PropertiesFileFilter extends javax.swing.filechooser.FileFilter { public boolean accept(File file) { - String filename = file.getName(); - filename.toLowerCase(); - if (file.isDirectory() || filename.endsWith(".properties.txt")) - return true; - else - return false; + String filename = file.getName(); + filename.toLowerCase(); + if (file.isDirectory() || filename.endsWith(".properties.txt")) + return true; + else + return false; } public String getDescription() { - return "Properties files (*.properties.txt)"; + return "Properties files (*.properties.txt)"; } } @@ -1151,7 +1163,7 @@ void saveNewPropertiesFileWithFileChooser() { JFileChooser fc = new JFileChooser(); fc.setFileFilter(new PropertiesFileFilter()); - + fc.setDialogTitle("Enter a config file name..."); int returned = fc.showSaveDialog(frame); @@ -1162,7 +1174,7 @@ void saveNewPropertiesFileWithFileChooser() newPropertiesFilename.toLowerCase(); if (!newPropertiesFilename.endsWith(".properties.txt")) newPropertiesFilename+=".properties.txt"; - + println("new propertiesFilename: "+ newPropertiesFilename); propertiesFilename = newPropertiesFilename; savePropertiesFile(); @@ -1171,211 +1183,18 @@ void saveNewPropertiesFileWithFileChooser() loadFromPropertiesFile(); } } - } - ); + }); } -RShape loadShapeFromFile(String filename) { - RShape sh = null; - if (filename.toLowerCase().endsWith(".svg")) { - sh = RG.loadShape(filename); - } - else if (filename.toLowerCase().endsWith(".gco") || filename.toLowerCase().endsWith(".g")) { - sh = loadShapeFromGCodeFile(filename); - } - return sh; -} - -int countLines(String filename) throws IOException { - InputStream is = new BufferedInputStream(new FileInputStream(filename)); - try { - byte[] c = new byte[1024]; - int count = 0; - int readChars = 0; - boolean empty = true; - while ((readChars = is.read(c)) != -1) { - empty = false; - for (int i = 0; i < readChars; ++i) { - if (c[i] == '\n') { - ++count; - } - } - } - return (count == 0 && !empty) ? 1 : count; - } finally { - is.close(); - } -} - -RShape loadShapeFromGCodeFile(String filename) { - noLoop(); - RShape parent = null; - BufferedReader reader = null; - long totalPoints = 0; - long time = millis(); - - try { - long countLines = countLines(filename); - println("" + countLines + " lines found."); - reader = createReader(filename); - parent = new RShape(); - String line; - boolean drawLine = false; - int gCodeZAxisChanges = 0; - - long lineNo = 0; - float lastPercent = 0.0f; - while ((line = reader.readLine ()) != null) { - lineNo++; - if (line.toUpperCase().startsWith("G")) { - if ((millis() - time) > 500) { - println(new StringBuilder().append(lineNo).append(" of ").append(countLines).append(": ").append(line).append(". Points: ").append(totalPoints).toString()); - long free = Runtime.getRuntime().freeMemory(); - long maximum = Runtime.getRuntime().maxMemory(); - println(new StringBuilder().append("Free: ").append(free).append(", max: ").append(maximum).toString()); - time = millis(); - } -// float percent = (lineNo / countLines) * 100; -// if (percent != lastPercent) { -// println("" + percent + "% of the way through."); -// lastPercent = percent; -// } - - Map ins = null; - try { - ins = unpackGCodeInstruction(line); - } - catch (Exception e) { - println("Exception while unpacking a gcode line " + line); - continue; - } - Integer code = Math.round(ins.get("G")); - if (code >= 2) { - continue; - } - - - Float z = ins.get("Z"); - if (z != null) { - gCodeZAxisChanges++; - if (gCodeZAxisChanges == 2) { - println("Assume second z axis change is to drop the pen to start drawing " + z); - gcodeZAxisDrawingHeight = z; - drawLine = true; - } - else if (gCodeZAxisChanges > 2) { - drawLine = isGCodeZAxisForDrawing(z); - } - else { - println("Assume first z axis change is to RAISE the pen " + z); - drawLine = false; - } - } - - Float x = ins.get("X"); - Float y = ins.get("Y"); - if (x != null && y == null) { - // move x axis only, use y of last - RPoint[][] points = parent.getPointsInPaths(); - RPoint rp = points[points.length-1][points[points.length-1].length-1]; - y = rp.y; - } - else if (x == null && y != null) { - // move y axis only, use x of last - RPoint[][] points = parent.getPointsInPaths(); - RPoint rp = points[points.length-1][points[points.length-1].length-1]; - x = rp.x; - } - - if (x != null && y != null) { - // move both x and y axis - if (drawLine) { - parent.addLineTo(x, y); - } - else { - parent.addMoveTo(x, y); - } - } -// RPoint[][] points = parent.getPointsInPaths(); -// totalPoints = 0; -// if (points != null) { -// for (int i = 0; i unpackGCodeInstruction(String line) throws NumberFormatException { - Map instruction = new HashMap(4); - try { - String[] splitted = line.trim().split(" "); - for (int i = 0; i < splitted.length; i++) { - String axis = splitted[i].substring(0, 1); - Float value = Float.parseFloat(splitted[i].substring(1)); - if ("X".equalsIgnoreCase(axis) || "Y".equalsIgnoreCase(axis) || "Z".equalsIgnoreCase(axis) || "G".equalsIgnoreCase(axis)) { - instruction.put(axis, value); - } - } -// println("instruction: " + instruction); - } - catch (NumberFormatException e) { - println("Exception while reading the lines from a gcode file: " + line); - throw e; - } - return instruction; -} void setPictureFrameDimensionsToBox() { - // if (getDisplayMachine().pixelsCanBeExtracted() && isBoxSpecified()) - // { - Rectangle r = new Rectangle(getDisplayMachine().inSteps(getBoxVector1()), getDisplayMachine().inSteps(getBoxVectorSize())); - getDisplayMachine().setPictureFrame(r); - // } +// if (getDisplayMachine().pixelsCanBeExtracted() && isBoxSpecified()) +// { + Rectangle r = new Rectangle(getDisplayMachine().inSteps(getBoxVector1()), getDisplayMachine().inSteps(getBoxVectorSize())); + getDisplayMachine().setPictureFrame(r); +// } } void setBoxToPictureframeDimensions() { @@ -1391,6 +1210,7 @@ void setBoxToPictureframeDimensions() t = (Toggle) getAllControls().get(MODE_SHOW_DENSITY_PREVIEW); t.setValue(1); t.update(); + } } @@ -1413,33 +1233,32 @@ void controlEvent(ControlEvent controlEvent) { if (controlEvent.isTab()) { - if (controlEvent.tab().name() == getCurrentTab()) + if (controlEvent.tab().getName() == getCurrentTab()) { // already here. println("Already here."); } else { - changeTab(currentTab, controlEvent.tab().name()); + changeTab(currentTab, controlEvent.tab().getName()); } } - else if (controlEvent.isGroup()) + else if(controlEvent.isGroup()) { - print("got an event from "+controlEvent.group().name()+"\t"); + print("got an event from "+controlEvent.group().getName()+"\t"); // checkbox uses arrayValue to store the state of // individual checkbox-items. usage: - for (int i=0; i= k) { - return keys[k]; + return keys[k]; } return false; } void keyReleased() { - keys[keyCode] = false; + keys[keyCode] = false; } void keyPressed() @@ -1574,7 +1397,7 @@ void keyPressed() //println("key: " + KeyEvent.getKeyText(keyCode)); //println("Keys: " + keys); //println("Keycode: " + keyCode); - + if (checkKey(CONTROL) && checkKey(KeyEvent.VK_PAGE_UP)) changeMachineScaling(1); else if (checkKey(CONTROL) && checkKey(KeyEvent.VK_PAGE_DOWN)) @@ -1590,8 +1413,8 @@ void keyPressed() else if (checkKey(KeyEvent.VK_ESCAPE)) key = 0; - // if (checkKey(CONTROL) && checkKey(KeyEvent.VK_G)) - // println("CTRL+G"); +// if (checkKey(CONTROL) && checkKey(KeyEvent.VK_G)) +// println("CTRL+G"); else if (checkKey(CONTROL) && checkKey(KeyEvent.VK_G)) { @@ -1614,7 +1437,7 @@ void keyPressed() setUseWindowedConsole(false); else setUseWindowedConsole(true); - + initLogging(); } else if (checkKey(CONTROL) && checkKey(KeyEvent.VK_S)) @@ -1626,60 +1449,60 @@ void keyPressed() { displayingInfoTextOnInputPage = (displayingInfoTextOnInputPage) ? false : true; } - // else if (key == '+') - // { - // currentMachineMaxSpeed = currentMachineMaxSpeed+MACHINE_MAXSPEED_INCREMENT; - // currentMachineMaxSpeed = Math.round(currentMachineMaxSpeed*100.0)/100.0; - // NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK); - // DecimalFormat df = (DecimalFormat)nf; - // df.applyPattern("###.##"); - // addToRealtimeCommandQueue(CMD_SETMOTORSPEED+df.format(currentMachineMaxSpeed)+",END"); - // } - // else if (key == '-') - // { - // currentMachineMaxSpeed = currentMachineMaxSpeed+(0.0 - MACHINE_MAXSPEED_INCREMENT); - // currentMachineMaxSpeed = Math.round(currentMachineMaxSpeed*100.0)/100.0; - // NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK); - // DecimalFormat df = (DecimalFormat)nf; - // df.applyPattern("###.##"); - // addToRealtimeCommandQueue(CMD_SETMOTORSPEED+df.format(currentMachineMaxSpeed)+",END"); - // } - // else if (key == '*') - // { - // currentMachineAccel = currentMachineAccel+MACHINE_ACCEL_INCREMENT; - // currentMachineAccel = Math.round(currentMachineAccel*100.0)/100.0; - // NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK); - // DecimalFormat df = (DecimalFormat)nf; - // df.applyPattern("###.##"); - // addToRealtimeCommandQueue(CMD_SETMOTORACCEL+df.format(currentMachineAccel)+",END"); - // } - // else if (key == '/') - // { - // currentMachineAccel = currentMachineAccel+(0.0 - MACHINE_ACCEL_INCREMENT); - // currentMachineAccel = Math.round(currentMachineAccel*100.0)/100.0; - // NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK); - // DecimalFormat df = (DecimalFormat)nf; - // df.applyPattern("###.##"); - // addToRealtimeCommandQueue(CMD_SETMOTORACCEL+df.format(currentMachineAccel)+",END"); - // } - // else if (key == ']') - // { - // currentPenWidth = currentPenWidth+penIncrement; - // currentPenWidth = Math.round(currentPenWidth*100.0)/100.0; - // NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK); - // DecimalFormat df = (DecimalFormat)nf; - // df.applyPattern("###.##"); - // addToRealtimeCommandQueue(CMD_CHANGEPENWIDTH+df.format(currentPenWidth)+",END"); - // } - // else if (key == '[') - // { - // currentPenWidth = currentPenWidth-penIncrement; - // currentPenWidth = Math.round(currentPenWidth*100.0)/100.0; - // NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK); - // DecimalFormat df = (DecimalFormat)nf; - // df.applyPattern("###.##"); - // addToRealtimeCommandQueue(CMD_CHANGEPENWIDTH+df.format(currentPenWidth)+",END"); - // } +// else if (key == '+') +// { +// currentMachineMaxSpeed = currentMachineMaxSpeed+MACHINE_MAXSPEED_INCREMENT; +// currentMachineMaxSpeed = Math.round(currentMachineMaxSpeed*100.0)/100.0; +// NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK); +// DecimalFormat df = (DecimalFormat)nf; +// df.applyPattern("###.##"); +// addToRealtimeCommandQueue(CMD_SETMOTORSPEED+df.format(currentMachineMaxSpeed)+",END"); +// } +// else if (key == '-') +// { +// currentMachineMaxSpeed = currentMachineMaxSpeed+(0.0 - MACHINE_MAXSPEED_INCREMENT); +// currentMachineMaxSpeed = Math.round(currentMachineMaxSpeed*100.0)/100.0; +// NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK); +// DecimalFormat df = (DecimalFormat)nf; +// df.applyPattern("###.##"); +// addToRealtimeCommandQueue(CMD_SETMOTORSPEED+df.format(currentMachineMaxSpeed)+",END"); +// } +// else if (key == '*') +// { +// currentMachineAccel = currentMachineAccel+MACHINE_ACCEL_INCREMENT; +// currentMachineAccel = Math.round(currentMachineAccel*100.0)/100.0; +// NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK); +// DecimalFormat df = (DecimalFormat)nf; +// df.applyPattern("###.##"); +// addToRealtimeCommandQueue(CMD_SETMOTORACCEL+df.format(currentMachineAccel)+",END"); +// } +// else if (key == '/') +// { +// currentMachineAccel = currentMachineAccel+(0.0 - MACHINE_ACCEL_INCREMENT); +// currentMachineAccel = Math.round(currentMachineAccel*100.0)/100.0; +// NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK); +// DecimalFormat df = (DecimalFormat)nf; +// df.applyPattern("###.##"); +// addToRealtimeCommandQueue(CMD_SETMOTORACCEL+df.format(currentMachineAccel)+",END"); +// } +// else if (key == ']') +// { +// currentPenWidth = currentPenWidth+penIncrement; +// currentPenWidth = Math.round(currentPenWidth*100.0)/100.0; +// NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK); +// DecimalFormat df = (DecimalFormat)nf; +// df.applyPattern("###.##"); +// addToRealtimeCommandQueue(CMD_CHANGEPENWIDTH+df.format(currentPenWidth)+",END"); +// } +// else if (key == '[') +// { +// currentPenWidth = currentPenWidth-penIncrement; +// currentPenWidth = Math.round(currentPenWidth*100.0)/100.0; +// NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK); +// DecimalFormat df = (DecimalFormat)nf; +// df.applyPattern("###.##"); +// addToRealtimeCommandQueue(CMD_CHANGEPENWIDTH+df.format(currentPenWidth)+",END"); +// } else if (key == '#' ) { addToRealtimeCommandQueue(CMD_PENUP+"END"); @@ -1697,15 +1520,15 @@ void keyPressed() { this.maxSegmentLength++; } - // else if (key == ',') - // { - // if (this.minimumVectorLineLength > 0) - // this.minimumVectorLineLength--; - // } - // else if (key == '.') - // { - // this.minimumVectorLineLength++; - // } +// else if (key == ',') +// { +// if (this.minimumVectorLineLength > 0) +// this.minimumVectorLineLength--; +// } +// else if (key == '.') +// { +// this.minimumVectorLineLength++; +// } } void mouseDragged() { @@ -1726,12 +1549,12 @@ void mouseDragged() } } } - + void mouseClicked() { if (mouseOverPanel()) { // changing mode - // panelClicked(); +// panelClicked(); } else { @@ -1741,10 +1564,10 @@ void mouseClicked() PVector mVect = getDisplayMachine().scaleToDisplayMachine(getMouseVector()); PVector offset = new PVector(imageSize.x/2.0, imageSize.y/2.0); PVector imagePos = new PVector(mVect.x-offset.x, mVect.y-offset.y); - + imagePos = getDisplayMachine().inSteps(imagePos); getDisplayMachine().getImageFrame().setPosition(imagePos.x, imagePos.y); - + if (getDisplayMachine().pixelsCanBeExtracted() && isBoxSpecified()) getDisplayMachine().extractPixelsFromArea(getBoxVector1(), getBoxVectorSize(), getGridSize(), sampleArea); } @@ -1791,9 +1614,9 @@ void machineClicked() } void mousePressed() { - // println("mouse pressed"); - // println("mouse button: "+mouseButton); - // println("Current mode: " +currentMode); +// println("mouse pressed"); +// println("mouse button: "+mouseButton); +// println("Current mode: " +currentMode); if (mouseButton == CENTER) { middleButtonMachinePress(); @@ -1810,13 +1633,13 @@ void mousePressed() if (getDisplayMachine().pixelsCanBeExtracted() && isBoxSpecified()) { getDisplayMachine().extractPixelsFromArea(getBoxVector1(), getBoxVectorSize(), getGridSize(), sampleArea); - // minitoggle_mode_showImage(false); - // minitoggle_mode_showDensityPreview(true); +// minitoggle_mode_showImage(false); +// minitoggle_mode_showDensityPreview(true); } } else { - // println("Do nothing."); +// println("Do nothing."); } } } @@ -1876,6 +1699,7 @@ void leftButtonMachineClick() setChromaKey(getMouseVector()); else if (currentMode.equals(MODE_SEND_START_TEXT)) sendStartTextAtPoint(); + } void mouseWheel(int delta) @@ -1908,14 +1732,17 @@ boolean isPreviewable(String command) } /** - This will comb the command queue and attempt to draw a picture of what it contains. - Coordinates here are in pixels. - */ -void previewQueue() + This will comb the command queue and attempt to draw a picture of what it contains. + Coordinates here are in pixels. +*/ +void previewQueue() { + previewQueue(false); +} + +void previewQueue(boolean forceRebuild) { PVector startPoint = null; - - if (commandQueue.hashCode() != lastCommandQueueHash) + if (forceRebuild || (commandQueue.hashCode() != lastCommandQueueHash)) { println("regenerating preview queue."); previewCommandList.clear(); @@ -1930,27 +1757,27 @@ void previewQueue() String aLenStr = splitted[1]; String bLenStr = splitted[2]; - + PVector endPoint = new PVector(Integer.parseInt(aLenStr)+previewCordOffset, Integer.parseInt(bLenStr)+previewCordOffset); endPoint = getDisplayMachine().asCartesianCoords(endPoint); endPoint = getDisplayMachine().inMM(endPoint); - + pv.x = endPoint.x; pv.y = endPoint.y; pv.z = -1.0; - + if (command.startsWith(CMD_DRAWPIXEL)) { String densStr = splitted[4]; pv.z = Integer.parseInt(densStr); } - + previewCommandList.add(pv); } } lastCommandQueueHash = commandQueue.hashCode(); } - + for (PreviewVector pv : previewCommandList) { PVector p = (PVector) pv; @@ -1959,35 +1786,37 @@ void previewQueue() if (startPoint == null) { noStroke(); - fill(255, 0, 255, 150); + fill(255,0,255,150); startPoint = getDisplayMachine().scaleToScreen(currentMachinePos); ellipse(p.x, p.y, 20, 20); noFill(); } - + if (pv.command.equals(CMD_CHANGELENGTHDIRECT)) stroke(0); else - stroke(200, 0, 0); + stroke(200,0,0); line(startPoint.x, startPoint.y, p.x, p.y); startPoint = p; if (pv.z >= 0.0) { noStroke(); - fill(255, pv.z, pv.z); - ellipse(p.x, p.y, 5, 5); + fill(255,pv.z,pv.z); + ellipse(p.x, p.y, 5,5); noFill(); } + } if (startPoint != null) { noStroke(); - fill(200, 0, 0, 128); - ellipse(startPoint.x, startPoint.y, 15, 15); + fill(200,0,0,128); + ellipse(startPoint.x, startPoint.y, 15,15); noFill(); } + } boolean isHiddenPixel(PVector p) @@ -1998,89 +1827,61 @@ boolean isHiddenPixel(PVector p) return false; } - - -void sizeImageToFitBox() -{ - // PVector mmBoxSize = getDisplayMachine().inSteps(getBoxSize()); - // PVector mmBoxPos = getDisplayMachine().inSteps(getBoxVector1()); - // println("mm box: " + mmBoxSize); - +void sizeImageToFitBox() { PVector boxSize = getDisplayMachine().inSteps(getBoxSize()); PVector boxPos = getDisplayMachine().inSteps(getBoxVector1()); println("image: " + boxSize); - + Rectangle r = new Rectangle(boxPos, boxSize); getDisplayMachine().setImageFrame(r); } -void exportQueueToFile() -{ - if (!commandQueue.isEmpty() || !realtimeCommandQueue.isEmpty()) - { - String savePath = selectOutput(); // Opens file chooser - if (savePath == null) - { - // If a file was not selected - println("No output file was selected..."); - } - else - { - // If a file was selected, print path to folder - println("Output file: " + savePath); - List allCommands = new ArrayList(realtimeCommandQueue); - allCommands.addAll(commandQueue); - - String[] list = (String[]) allCommands.toArray(new String[0]); - saveStrings(savePath, list); - println("Completed queue export, " + list.length + " commands exported."); - } - } -} -void importQueueFromFile() -{ - commandQueue.clear(); - String loadPath = selectInput(); - if (loadPath == null) - { - // nothing selected - println("No input file was selected."); - } - else - { - println("Input file: " + loadPath); - String commands[] = loadStrings(loadPath); - // List list = Arrays - commandQueue.addAll(Arrays.asList(commands)); - println("Completed queue import, " + commandQueue.size() + " commands found."); - } +void exportQueueToFile() { + if (!commandQueue.isEmpty() || !realtimeCommandQueue.isEmpty()) { + selectOutput("Enter a filename to save to:", "exportQueueToFile"); // Opens file chooser + } } -String importTextToWriteFromFile() -{ - String loadPath = selectInput(); - String result = ""; - if (loadPath == null) - { - // nothing selected - println("No input file was selected."); - } - else - { - println("Input file: " + loadPath); - List rows = java.util.Arrays.asList(loadStrings(loadPath)); - StringBuilder sb = new StringBuilder(200); - for (String row : rows) - { - sb.append(row); - } - result = sb.toString(); - - println("Completed text import, " + result.length() + " characters found."); - } - return result; +void exportQueueToFile(File selection) { + if (selection != null) { + filePath = selection.getAbsolutePath(); + println("User selected " + filePath); + // If a file was selected, print path to folder + println("Output file: " + filePath); + List allCommands = new ArrayList(realtimeCommandQueue); + allCommands.addAll(commandQueue); + + String[] list = (String[]) allCommands.toArray(new String[0]); + saveStrings(filePath, list); + println("Completed queue export, " + list.length + " commands exported."); + } } +void fileSelected(File selection) { + if (selection == null) { + println("Window was closed or the user hit cancel."); + filePath = null; + } else { + filePath = selection.getAbsolutePath(); + println("User selected " + filePath); + } +} + +void importQueueFromFile() { + commandQueue.clear(); + selectInput("Select file to import queue from", "fileSelected"); + if (filePath == null) { + // nothing selected + println("No input file was selected."); + } else { + println("Input file: " + filePath); + String commands[] = loadStrings(filePath); + commandQueue.addAll(Arrays.asList(commands)); + println("Completed queue import, " + commandQueue.size() + " commands found."); + } +} + + void queueClicked() @@ -2088,7 +1889,7 @@ void queueClicked() int relativeCoord = (mouseY-topEdgeOfQueue); int rowClicked = relativeCoord / queueRowHeight; int totalCommands = commandQueue.size()+realtimeCommandQueue.size(); - + if (rowClicked < 1) // its the header - start or stop queue { if (commandQueueRunning) @@ -2114,7 +1915,7 @@ void queueClicked() { cmdNumber-=(realtimeCommandQueue.size()+1); commandQueue.remove(cmdNumber); - } + } } else { @@ -2161,7 +1962,7 @@ PVector getBoxVector2() } PVector getBoxVectorSize() { - return PVector.sub(getBoxVector2(), getBoxVector1()); + return PVector.sub(getBoxVector2(),getBoxVector1()); } float getSampleArea() @@ -2182,32 +1983,32 @@ void showText(int xPosOrigin, int yPosOrigin) noStroke(); fill(0, 0, 0, 80); rect(xPosOrigin, yPosOrigin, 220, 550); - - + + textSize(12); fill(255); int tRow = 15; int textPositionX = xPosOrigin+4; int textPositionY = yPosOrigin+4; - + int tRowNo = 1; PVector screenCoordsCart = getMouseVector(); - + text(programTitle, textPositionX, textPositionY+(tRow*tRowNo++)); tRowNo++; text("Cursor position: " + mouseX + ", " + mouseY, textPositionX, textPositionY+(tRow*tRowNo++)); - + text("MM Per Step: " + getDisplayMachine().getMMPerStep(), textPositionX, textPositionY+(tRow*tRowNo++)); - text("Steps Per MM: " + getDisplayMachine().getStepsPerMM(), textPositionX, textPositionY+(tRow*tRowNo++)); + text("Steps Per MM: " + getDisplayMachine().getStepsPerMM() ,textPositionX, textPositionY+(tRow*tRowNo++)); if (getDisplayMachine().getOutline().surrounds(screenCoordsCart)) { PVector posOnMachineCartesianInMM = getDisplayMachine().scaleToDisplayMachine(screenCoordsCart); text("Machine x/y mm: " + posOnMachineCartesianInMM.x+","+posOnMachineCartesianInMM.y, textPositionX, textPositionY+(tRow*tRowNo++)); - + PVector posOnMachineNativeInMM = getDisplayMachine().convertToNative(posOnMachineCartesianInMM); text("Machine a/b mm: " + posOnMachineNativeInMM.x+","+posOnMachineNativeInMM.y, textPositionX, textPositionY+(tRow*tRowNo++)); - + PVector posOnMachineNativeInSteps = getDisplayMachine().inSteps(posOnMachineNativeInMM); text("Machine a/b steps: " + posOnMachineNativeInSteps.x+","+posOnMachineNativeInSteps.y, textPositionX, textPositionY+(tRow*tRowNo++)); } @@ -2217,24 +2018,24 @@ void showText(int xPosOrigin, int yPosOrigin) text("Machine a/b mm: --,--", textPositionX, textPositionY+(tRow*tRowNo++)); text("Machine a/b steps: --,--", textPositionX, textPositionY+(tRow*tRowNo++)); } - + drawStatusText(textPositionX, textPositionY+(tRow*tRowNo++)); - + text(commandStatus, textPositionX, textPositionY+(tRow*tRowNo++)); - + text("Mode: " + currentMode, textPositionX, textPositionY+(tRow*tRowNo++)); // middle side text("Grid size: " + getGridSize(), textPositionX, textPositionY+(tRow*tRowNo++)); - + text("Box width: " + getBoxWidth(), textPositionX, textPositionY+(tRow*tRowNo++)); text("Box height: " + getBoxHeight(), textPositionX, textPositionY+(tRow*tRowNo++)); text("Box offset left: " + getBoxPosition().x, textPositionX, textPositionY+(tRow*tRowNo++)); text("Box offset top: " + getBoxPosition().y, textPositionX, textPositionY+(tRow*tRowNo++)); - + text("Available memory: " + machineAvailMem + " (min: " + machineMinAvailMem +", used: "+ machineUsedMem+")", textPositionX, textPositionY+(tRow*tRowNo++)); text("Time cmd: " + getCurrentPixelTime() + ", total: " + getTimeSoFar(), textPositionX, textPositionY+(tRow*tRowNo++)); @@ -2266,13 +2067,13 @@ void showText(int xPosOrigin, int yPosOrigin) noFill(); noStroke(); tRowNo++; - + } void drawStatusText(int x, int y) { String drawbotStatus = null; - + if (useSerialPortConnection) { if (isDrawbotConnected()) @@ -2280,12 +2081,12 @@ void drawStatusText(int x, int y) if (drawbotReady) { fill(0, 200, 0); - if (currentHardware >= HARDWARE_VER_POLARPRO) - drawbotStatus = "Polargraph READY! (PRO)"; - else if (currentHardware >= HARDWARE_VER_MEGA_POLARSHIELD) + if (currentHardware >= HARDWARE_VER_MEGA_POLARSHIELD) drawbotStatus = "Polargraph READY! (PolargraphSD)"; else if (currentHardware >= HARDWARE_VER_MEGA) drawbotStatus = "Polargraph READY! (Mega)"; + else if (currentHardware >= HARDWARE_VER_POLARPRO) + drawbotStatus = "Polargraph READY! (PRO)"; else drawbotStatus = "Polargraph READY! (Uno)"; } @@ -2296,20 +2097,20 @@ void drawStatusText(int x, int y) if ("".equals(busyDoing)) busyDoing = commandHistory.get(commandHistory.size()-1); drawbotStatus = "BUSY: " + busyDoing; - } + } } else { fill(255, 0, 0); drawbotStatus = "Polargraph is not connected."; - } + } } else { fill(255, 0, 0); drawbotStatus = "No serial connection."; } - + text(drawbotStatus, x, y); fill(255); } @@ -2333,29 +2134,29 @@ void showCommandQueue(int xPos, int yPos) leftEdgeOfQueue = textPositionX; rightEdgeOfQueue = textPositionX+300; bottomEdgeOfQueue = height; - + drawCommandQueueStatus(textPositionX, commandQueuePos, 14); commandQueuePos+=queueRowHeight; text("Last command: " + ((commandHistory.isEmpty()) ? "-" : commandHistory.get(commandHistory.size()-1)), textPositionX, commandQueuePos); commandQueuePos+=queueRowHeight; text("Current command: " + lastCommand, textPositionX, commandQueuePos); commandQueuePos+=queueRowHeight; - - fill(128, 255, 255); + + fill(128,255,255); int queueNumber = commandQueue.size()+realtimeCommandQueue.size(); for (String s : realtimeCommandQueue) { text((queueNumber--)+". "+ s, textPositionX, commandQueuePos); commandQueuePos+=queueRowHeight; } - + fill(255); try { // Write out the commands into the window, stop when you fall off the bottom of the window // Or run out of commands int commandNo = 0; - while (commandQueuePos <= height && commandNo < commandQueue.size ()) + while (commandQueuePos <= height && commandNo < commandQueue.size()) { String s = commandQueue.get(commandNo); text((queueNumber--)+". "+ s, textPositionX, commandQueuePos); @@ -2369,6 +2170,7 @@ void showCommandQueue(int xPos, int yPos) println("Caught the pesky ConcurrentModificationException: " + cme.getMessage()); } showmachineMessageLog(rightEdgeOfQueue, 20); + } void drawCommandQueueStatus(int x, int y, int tSize) @@ -2400,7 +2202,7 @@ void showmachineMessageLog(int xPos, int yPos) int pos = textPositionY+(tRow*tRowNo++); pos+=queueRowHeight; - + fill(255); // Write out the commands into the window, stop when you fall off the bottom of the window // Or run out of commands @@ -2408,9 +2210,9 @@ void showmachineMessageLog(int xPos, int yPos) while (pos <= height && entryNo >= 0) { String s = machineMessageLog.get(entryNo); - String type = s.substring(0, 1); - if ("E".equals(type)) fill(255, 128, 128); - else if ("D".equals(type)) fill(50, 50, 50); + String type = s.substring(0,1); + if ("E".equals(type)) fill(255,128,128); + else if ("D".equals(type)) fill(50,50,50); else if ("I".equals(type)) fill(255); text(s, textPositionX, pos); pos+=queueRowHeight; @@ -2552,7 +2354,7 @@ public DisplayMachine getDisplayMachine() { if (displayMachine == null) displayMachine = new DisplayMachine(new Machine(5000, 5000, 800.0, 95.0), machinePosition, machineScaling); - + displayMachine.setOffset(machinePosition); displayMachine.setScale(machineScaling); return displayMachine; @@ -2577,12 +2379,12 @@ void changeHardwareVersionTo(int newVer) switch (newVer) { - case HARDWARE_VER_MEGA : - currentSram = HARDWARE_ATMEGA1280_SRAM; - default : - currentSram = HARDWARE_ATMEGA328_SRAM; + case HARDWARE_VER_MEGA : + currentSram = HARDWARE_ATMEGA1280_SRAM; + default : + currentSram = HARDWARE_ATMEGA328_SRAM; } - // windowResized(); +// windowResized(); } void setHardwareVersionFromIncoming(String readyString) @@ -2605,15 +2407,14 @@ void setHardwareVersionFromIncoming(String readyString) println("Bad format for hardware version - defaulting to ATMEGA328 (Uno)"); verInt = HARDWARE_VER_UNO; } - + if (HARDWARE_VER_MEGA == verInt - || HARDWARE_VER_MEGA_POLARSHIELD == verInt - || HARDWARE_VER_POLARPRO == verInt) + || HARDWARE_VER_MEGA_POLARSHIELD == verInt) newHardwareVersion = verInt; else newHardwareVersion = HARDWARE_VER_UNO; } - + // now see if it's different to last time. if (newHardwareVersion != currentHardware) { @@ -2630,7 +2431,7 @@ void serialEvent(Serial myPort) // if you got any bytes other than the linefeed: incoming = trim(incoming); println("incoming: " + incoming); - + if (incoming.startsWith("READY")) { drawbotReady = true; @@ -2656,14 +2457,14 @@ void serialEvent(Serial myPort) readPenLiftRange(incoming); else if (incoming.startsWith("PGSPEED")) readMachineSpeed(incoming); - + else if ("RESEND".equals(incoming)) resendLastCommand(); else if ("DRAWING".equals(incoming)) drawbotReady = false; else if (incoming.startsWith("MEMORY")) extractMemoryUsage(incoming); - + else if (incoming.startsWith("BUTTON")) handleMachineButton(incoming); @@ -2691,10 +2492,10 @@ void extractMemoryUsage(String mem) void readMachineMessage(String msg) { msg = msg.substring(4, msg.length()); - String type = msg.substring(0, 1); + String type = msg.substring(0,1); msg = msg.substring(2, msg.length()); String timestamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); - + msg = type + timestamp + " " + msg; machineMessageLog.add(msg); if (machineMessageLog.size() > 200) @@ -2727,7 +2528,7 @@ void readCartesianMachinePosition(String sync) Float a = Float.valueOf(currentAPos).floatValue(); Float b = Float.valueOf(currentBPos).floatValue(); currentCartesianMachinePos.x = a; - currentCartesianMachinePos.y = b; + currentCartesianMachinePos.y = b; } } @@ -2737,7 +2538,7 @@ void readMmPerRev(String in) if (splitted.length == 3) { String mmStr = splitted[1]; - + float mmPerRev = Float.parseFloat(mmStr); getDisplayMachine().setMMPerRev(mmPerRev); updateNumberboxValues(); @@ -2750,7 +2551,7 @@ void readStepsPerRev(String in) if (splitted.length == 3) { String stepsStr = splitted[1]; - + Float stepsPerRev = Float.parseFloat(stepsStr); getDisplayMachine().setStepsPerRev(stepsPerRev); updateNumberboxValues(); @@ -2763,7 +2564,7 @@ void readStepMultiplier(String in) if (splitted.length == 3) { String stepsStr = splitted[1]; - + machineStepMultiplier = Integer.parseInt(stepsStr); updateNumberboxValues(); } @@ -2777,13 +2578,13 @@ void readMachineSize(String in) { String mWidth = splitted[1]; String mHeight = splitted[2]; - + Integer intWidth = Integer.parseInt(mWidth); Integer intHeight = Integer.parseInt(mHeight); - + float fWidth = getDisplayMachine().inSteps(intWidth); float fHeight = getDisplayMachine().inSteps(intHeight); - + getDisplayMachine().setSize(int(fWidth+0.5), int(fHeight+0.5)); updateNumberboxValues(); } @@ -2795,6 +2596,7 @@ void readMachineName(String sync) if (splitted.length == 3) { String name = splitted[1]; + } } @@ -2805,10 +2607,10 @@ void readMachineSpeed(String in) { String speed = splitted[1]; String accel = splitted[2]; - + currentMachineMaxSpeed = Float.parseFloat(speed); currentMachineAccel = Float.parseFloat(accel); - + updateNumberboxValues(); } } @@ -2820,7 +2622,7 @@ void readPenLiftRange(String in) { String downPos = splitted[1]; String upPos = splitted[2]; - + penLiftDownPosition = Integer.parseInt(downPos); penLiftUpPosition = Integer.parseInt(upPos); @@ -2861,11 +2663,9 @@ void dispatchCommandQueue() commandQueue.remove(0); println("Dispatching command: " + command); } - if (useChecksum()) { - Checksum crc = new CRC32(); - crc.update(lastCommand.getBytes(), 0, lastCommand.length()); - lastCommand = lastCommand+":"+crc.getValue(); - } +// Checksum crc = new CRC32(); +// crc.update(lastCommand.getBytes(), 0, lastCommand.length()); +// lastCommand = lastCommand+":"+crc.getValue(); println("Last command:" + lastCommand); myPort.write(lastCommand); myPort.write(10); // OH *$%! of COURSE you should terminate it. @@ -2874,11 +2674,7 @@ void dispatchCommandQueue() else if (commandQueue.isEmpty()) { stopPixelTimer(); - } -} - -boolean useChecksum() { - return currentHardware == 200; + } } void addToCommandQueue(String command) @@ -2925,7 +2721,7 @@ Properties getProperties() { props = new Properties(); String fileToLoad = sketchPath(propertiesFilename); - + File propertiesFile = new File(fileToLoad); if (!propertiesFile.exists()) { @@ -2933,7 +2729,7 @@ Properties getProperties() savePropertiesFile(); println("saved."); } - + propertiesFileStream = new FileInputStream(propertiesFile); props.load(propertiesFileStream); println("Successfully loaded properties file " + fileToLoad); @@ -2962,12 +2758,12 @@ void loadFromPropertiesFile() { getDisplayMachine().loadDefinitionFromProperties(getProperties()); this.pageColour = getColourProperty("controller.page.colour", color(220)); - this.frameColour = getColourProperty("controller.frame.colour", color(200, 0, 0)); + this.frameColour = getColourProperty("controller.frame.colour", color(200,0,0)); this.machineColour = getColourProperty("controller.machine.colour", color(150)); this.guideColour = getColourProperty("controller.guide.colour", color(255)); this.backgroundColour = getColourProperty("controller.background.colour", color(100)); this.densityPreviewColour = getColourProperty("controller.densitypreview.colour", color(0)); - this.chromaKeyColour = getColourProperty("controller.pixel.mask.color", color(0, 255, 0)); + this.chromaKeyColour = getColourProperty("controller.pixel.mask.color", color(0,255,0)); // pen size this.currentPenWidth = getFloatProperty("machine.pen.size", 0.8); @@ -2976,7 +2772,7 @@ void loadFromPropertiesFile() this.currentMachineMaxSpeed = getFloatProperty("machine.motors.maxSpeed", 600.0); this.currentMachineAccel = getFloatProperty("machine.motors.accel", 400.0); this.machineStepMultiplier = getIntProperty("machine.step.multiplier", 1); - + // serial port this.serialPortNumber = getIntProperty("controller.machine.serialport", 0); this.baudRate = getIntProperty("controller.machine.baudrate", 57600); @@ -2985,49 +2781,49 @@ void loadFromPropertiesFile() this.gridSize = getFloatProperty("controller.grid.size", 100.0); this.sampleArea = getIntProperty("controller.pixel.samplearea", 2); this.pixelScalingOverGridSize = getFloatProperty("controller.pixel.scaling", 1.0); - + // pixel renderer this.densityPreviewStyle = getIntProperty("controller.density.preview.style", 1); - + // initial screen size this.windowWidth = getIntProperty("controller.window.width", 650); this.windowHeight = getIntProperty("controller.window.height", 400); - + println("windowHeight:" + this.windowHeight); this.testPenWidthStartSize = getFloatProperty("controller.testPenWidth.startSize", 0.5); this.testPenWidthEndSize = getFloatProperty("controller.testPenWidth.endSize", 2.0); this.testPenWidthIncrementSize = getFloatProperty("controller.testPenWidth.incrementSize", 0.5); - + this.maxSegmentLength = getIntProperty("controller.maxSegmentLength", 2); - + float homePointX = getFloatProperty("controller.homepoint.x", 0.0); float homePointY = getFloatProperty("controller.homepoint.y", 0.0); - + if (homePointX == 0.0) { float defaultX = getDisplayMachine().getWidth() / 2.0; // in steps float defaultY = getDisplayMachine().getPage().getTop(); // in steps - // homePointX = getDisplayMachine().inMM(defaultX); - // homePointY = getDisplayMachine().inMM(defaultY); +// homePointX = getDisplayMachine().inMM(defaultX); +// homePointY = getDisplayMachine().inMM(defaultY); println("Loading default homepoint."); } this.homePointCartesian = new PVector(getDisplayMachine().inSteps(homePointX), getDisplayMachine().inSteps(homePointY)); - // println("home point loaded: " + homePointCartesian + ", " + getHomePoint()); - +// println("home point loaded: " + homePointCartesian + ", " + getHomePoint()); + setVectorFilename(getStringProperty("controller.vector.filename", null)); if (getVectorFilename() != null) { RShape shape = null; try { - shape =loadShapeFromFile(getVectorFilename()); + shape = RG.loadShape(getVectorFilename()); } catch (Exception e) { shape = null; } - + if (shape != null) { setVectorShape(shape); @@ -3042,27 +2838,29 @@ void loadFromPropertiesFile() getVectorPosition().y = getFloatProperty("controller.vector.position.y", 0.0); this.minimumVectorLineLength = getIntProperty("controller.vector.minLineLength", 0); + + println("Finished loading configuration from properties file."); } void savePropertiesFile() { Properties props = new Properties(); - + props = getDisplayMachine().loadDefinitionIntoProperties(props); NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK); DecimalFormat df = (DecimalFormat)nf; df.applyPattern("###.##"); - + props.setProperty("controller.page.colour", hex(this.pageColour, 6)); - props.setProperty("controller.frame.colour", hex(this.frameColour, 6)); - props.setProperty("controller.machine.colour", hex(this.machineColour, 6)); - props.setProperty("controller.guide.colour", hex(this.guideColour, 6)); - props.setProperty("controller.background.colour", hex(this.backgroundColour, 6)); - props.setProperty("controller.densitypreview.colour", hex(this.densityPreviewColour, 6)); - + props.setProperty("controller.frame.colour", hex(this.frameColour,6)); + props.setProperty("controller.machine.colour", hex(this.machineColour,6)); + props.setProperty("controller.guide.colour", hex(this.guideColour,6)); + props.setProperty("controller.background.colour", hex(this.backgroundColour,6)); + props.setProperty("controller.densitypreview.colour", hex(this.densityPreviewColour,6)); + // pen size props.setProperty("machine.pen.size", df.format(currentPenWidth)); // serial port @@ -3084,15 +2882,15 @@ void savePropertiesFile() props.setProperty("controller.testPenWidth.startSize", df.format(testPenWidthStartSize)); props.setProperty("controller.testPenWidth.endSize", df.format(testPenWidthEndSize)); props.setProperty("controller.testPenWidth.incrementSize", df.format(testPenWidthIncrementSize)); - + props.setProperty("controller.maxSegmentLength", new Integer(getMaxSegmentLength()).toString()); - + props.setProperty("machine.motors.maxSpeed", df.format(currentMachineMaxSpeed)); props.setProperty("machine.motors.accel", df.format(currentMachineAccel)); props.setProperty("machine.step.multiplier", new Integer(machineStepMultiplier).toString()); - + props.setProperty("controller.pixel.mask.color", hex(this.chromaKeyColour, 6)); - + PVector hp = null; if (getHomePoint() != null) { @@ -3100,20 +2898,21 @@ void savePropertiesFile() } else hp = new PVector(2000.0, 1000.0); - + hp = getDisplayMachine().inMM(hp); - + props.setProperty("controller.homepoint.x", df.format(hp.x)); props.setProperty("controller.homepoint.y", df.format(hp.y)); - + if (getVectorFilename() != null) props.setProperty("controller.vector.filename", getVectorFilename()); - + props.setProperty("controller.vector.scaling", df.format(vectorScaling)); props.setProperty("controller.vector.position.x", df.format(getVectorPosition().x)); props.setProperty("controller.vector.position.y", df.format(getVectorPosition().y)); props.setProperty("controller.vector.minLineLength", new Integer(this.minimumVectorLineLength).toString()); + FileOutputStream propertiesOutput = null; try @@ -3127,14 +2926,14 @@ void savePropertiesFile() FileInputStream propertiesFileStream = new FileInputStream(propertiesFile); oldProps.load(propertiesFileStream); oldProps.putAll(props); - oldProps.store(propertiesOutput, " *** Polargraph properties file *** "); + oldProps.store(propertiesOutput," *** Polargraph properties file *** "); println("Saved settings."); } else { // create it propertiesFile.createNewFile(); propertiesOutput = new FileOutputStream(propertiesFile); - props.store(propertiesOutput, " *** Polargraph properties file *** "); + props.store(propertiesOutput," *** Polargraph properties file *** "); println("Created file."); } } @@ -3150,26 +2949,24 @@ void savePropertiesFile() { propertiesOutput.close(); } - catch (Exception e2) { - println("what now!"+e2.getMessage()); - } + catch (Exception e2) {println("what now!"+e2.getMessage());} } } } boolean getBooleanProperty(String id, boolean defState) { - return boolean(getProperties().getProperty(id, ""+defState)); + return boolean(getProperties().getProperty(id,""+defState)); } - + int getIntProperty(String id, int defVal) { - return int(getProperties().getProperty(id, ""+defVal)); + return int(getProperties().getProperty(id,""+defVal)); } - + float getFloatProperty(String id, float defVal) { - return float(getProperties().getProperty(id, ""+defVal)); + return float(getProperties().getProperty(id,""+defVal)); } String getStringProperty(String id, String defVal) { @@ -3183,7 +2980,7 @@ color getColourProperty(String id, color defVal) { col = defVal; } - + if (colStr.length() == 1) { // single value grey @@ -3193,25 +2990,25 @@ color getColourProperty(String id, color defVal) else if (colStr.length() == 3) { // 3 digit rgb - String d1 = colStr.substring(0, 1); - String d2 = colStr.substring(1, 2); - String d3 = colStr.substring(2, 3); + String d1 = colStr.substring(0,1); + String d2 = colStr.substring(1,2); + String d3 = colStr.substring(2,3); d1 = d1+d1; d2 = d2+d2; d3 = d3+d3; - + col = color(unhex(d1), unhex(d2), unhex(d3)); } else if (colStr.length() == 6) { // 6 digit rgb - String d1 = colStr.substring(0, 2); - String d2 = colStr.substring(2, 4); - String d3 = colStr.substring(4, 6); - + String d1 = colStr.substring(0,2); + String d2 = colStr.substring(2,4); + String d3 = colStr.substring(4,6); + col = color(unhex(d1), unhex(d2), unhex(d3)); } - + return col; } @@ -3236,7 +3033,7 @@ void setOverwriteExistingStoreFile(boolean over) { this.overwriteExistingStoreFile = over; } - + void initProperties() { getProperties(); @@ -3251,10 +3048,12 @@ float getPixelScalingOverGridSize() { return pixelScalingOverGridSize; } + void setPixelScalingOverGridSize(float scaling) { pixelScalingOverGridSize = scaling; } + int getDensityPreviewStyle() { return densityPreviewStyle; @@ -3264,65 +3063,49 @@ Integer getBaudRate() { return baudRate; } + boolean isUseWindowedConsole() { return this.useWindowedConsole; } + void setUseWindowedConsole(boolean use) { this.useWindowedConsole = use; } + void initLogging() { try { - // logger = Logger.getLogger("uk.co.polargraph.controller"); - // FileHandler fileHandler = new FileHandler("mylog.txt"); - // fileHandler.setFormatter(new SimpleFormatter()); - // logger.addHandler(fileHandler); - // logger.setLevel(Level.INFO); - // logger.info("Hello"); - if (isUseWindowedConsole()) - { - console = new Console(); - } - else - { - console.close(); - console = null; - } +// logger = Logger.getLogger("uk.co.polargraph.controller"); +// FileHandler fileHandler = new FileHandler("mylog.txt"); +// fileHandler.setFormatter(new SimpleFormatter()); +// logger.addHandler(fileHandler); +// logger.setLevel(Level.INFO); +// logger.info("Hello"); +// if (isUseWindowedConsole()) +// { +// console = new Console(); +// } +// else +// { +// console.close(); +// console = null; +// } } catch(Exception e) { println("Exception setting up logger: " + e.getMessage()); } } -void initImages() -{ - // try - // { - // yButtonImage = loadImage("y.png"); - // xButtonImage = loadImage("x.png"); - // aButtonImage = loadImage("a.png"); - // bButtonImage = loadImage("b.png"); - // dpadXImage = loadImage("dpadlr.png"); - // dpadYImage = loadImage("dpadud.png"); - // } - // catch (Exception e) - // { - // yButtonImage = makeColourImage(64,64,color(180,180,0)); - // xButtonImage = makeColourImage(64,64,color(0,0,180)); - // aButtonImage = makeColourImage(64,64,color(0,180,0)); - // bButtonImage = makeColourImage(64,64,color(180,0,0)); - // } -} + PImage makeColourImage(int w, int h, int colour) { - PImage img = createImage(w, h, RGB); - for (int i=0; i < img.pixels.length; i++) { - img.pixels[i] = colour; + PImage img = createImage(w,h,RGB); + for(int i=0; i < img.pixels.length; i++) { + img.pixels[i] = colour; } return img; } - diff --git a/tabSetup.pde b/tabSetup.pde index afb57cf..3d62dec 100644 --- a/tabSetup.pde +++ b/tabSetup.pde @@ -25,7 +25,6 @@ sandy.noble@gmail.com http://www.polargraph.co.uk/ https://github.com/euphy/polargraphcontroller - */ Set getPanelsForTab(String tabName) @@ -84,25 +83,25 @@ List buildTabNames() void initTabs() { - cp5.tab(TAB_NAME_INPUT).setLabel(TAB_LABEL_INPUT); - cp5.tab(TAB_NAME_INPUT).activateEvent(true); - cp5.tab(TAB_NAME_INPUT).setId(1); + cp5.getTab(TAB_NAME_INPUT).setLabel(TAB_LABEL_INPUT); + cp5.getTab(TAB_NAME_INPUT).activateEvent(true); + cp5.getTab(TAB_NAME_INPUT).setId(1); - cp5.tab(TAB_NAME_DETAILS).setLabel(TAB_LABEL_DETAILS); - cp5.tab(TAB_NAME_DETAILS).activateEvent(true); - cp5.tab(TAB_NAME_DETAILS).setId(2); + cp5.getTab(TAB_NAME_DETAILS).setLabel(TAB_LABEL_DETAILS); + cp5.getTab(TAB_NAME_DETAILS).activateEvent(true); + cp5.getTab(TAB_NAME_DETAILS).setId(2); - cp5.tab(TAB_NAME_ROVING).setLabel(TAB_LABEL_ROVING); - cp5.tab(TAB_NAME_ROVING).activateEvent(true); - cp5.tab(TAB_NAME_ROVING).setId(3); + cp5.getTab(TAB_NAME_ROVING).setLabel(TAB_LABEL_ROVING); + cp5.getTab(TAB_NAME_ROVING).activateEvent(true); + cp5.getTab(TAB_NAME_ROVING).setId(3); - cp5.tab(TAB_NAME_TRACE).setLabel(TAB_LABEL_TRACE); - cp5.tab(TAB_NAME_TRACE).activateEvent(true); - cp5.tab(TAB_NAME_TRACE).setId(4); + cp5.getTab(TAB_NAME_TRACE).setLabel(TAB_LABEL_TRACE); + cp5.getTab(TAB_NAME_TRACE).activateEvent(true); + cp5.getTab(TAB_NAME_TRACE).setId(4); - cp5.tab(TAB_NAME_QUEUE).setLabel(TAB_LABEL_QUEUE); - cp5.tab(TAB_NAME_QUEUE).activateEvent(true); - cp5.tab(TAB_NAME_QUEUE).setId(5); + cp5.getTab(TAB_NAME_QUEUE).setLabel(TAB_LABEL_QUEUE); + cp5.getTab(TAB_NAME_QUEUE).activateEvent(true); + cp5.getTab(TAB_NAME_QUEUE).setId(5); } public Set buildPanelNames()