From cb4fa896743537b55a20764d66adee24ca767f83 Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Sun, 26 Apr 2015 12:13:35 +0100 Subject: [PATCH 01/13] Updated a bunch of stuff to make it compile and run in Processing v2 --- ControlFrame.pde | 46 ++ DisplayMachine.pde | 54 +- Machine.pde | 4 +- Misc.pde | 402 +++++++------- Panel.pde | 24 +- Rectangle.pde | 8 +- controlsActions.pde | 12 +- controlsActionsWindows.pde | 1066 +++++++++++++++++++----------------- controlsSetup.pde | 151 +++-- drawing.pde | 54 +- polargraphcontroller.pde | 126 +++-- tabSetup.pde | 34 +- 12 files changed, 1058 insertions(+), 923 deletions(-) create mode 100644 ControlFrame.pde diff --git a/ControlFrame.pde b/ControlFrame.pde new file mode 100644 index 0000000..a2eba2f --- /dev/null +++ b/ControlFrame.pde @@ -0,0 +1,46 @@ +// 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 Object parent; + + private ControlFrame() { + } + + public ControlFrame(Object 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 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); + } + +} \ No newline at end of file diff --git a/DisplayMachine.pde b/DisplayMachine.pde index 56090c6..6e7019c 100644 --- a/DisplayMachine.pde +++ b/DisplayMachine.pde @@ -1,31 +1,31 @@ /** - Polargraph controller - Copyright Sandy Noble 2012. - - 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/ - http://code.google.com/p/polargraph/ - */ + 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 +*/ class DisplayMachine extends Machine { diff --git a/Machine.pde b/Machine.pde index 1a0f008..6e7b5bd 100644 --- a/Machine.pde +++ b/Machine.pde @@ -1,6 +1,6 @@ /** Polargraph controller - Copyright Sandy Noble 2012. + Copyright Sandy Noble 2015. This file is part of Polargraph Controller. @@ -24,7 +24,7 @@ sandy.noble@gmail.com http://www.polargraph.co.uk/ - http://code.google.com/p/polargraph/ + https://github.com/euphy/polargraphcontroller */ /** * diff --git a/Misc.pde b/Misc.pde index c415e60..57d03e0 100644 --- a/Misc.pde +++ b/Misc.pde @@ -1,6 +1,6 @@ /** Polargraph controller - Copyright Sandy Noble 2012. + Copyright Sandy Noble 2015. This file is part of Polargraph Controller. @@ -24,7 +24,7 @@ sandy.noble@gmail.com http://www.polargraph.co.uk/ - http://code.google.com/p/polargraph/ + https://github.com/euphy/polargraphcontroller */ class Scaler @@ -52,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 && getSerialPortNumber() < ports.length) - r.setValue(getSerialPortNumber()); - - r.add("setup", -2); - r.add("No serial connection", -1); +void button_mode_serialPortDialog() { + if (controlFrames.containsKey(CHANGE_SERIAL_PORT_WINDOW_NAME)) { + println("NOT OPENING ANOTHER ONE!"); + } + else { + final SerialPortWindow serialPortWindow = new SerialPortWindow(); + controlFrames.put(CHANGE_SERIAL_PORT_WINDOW_NAME, serialPortWindow); + } +} + +class SerialPortWindow extends ControlFrame { + + @Override + public ControlP5 cp5() { + return super.cp5(); + } + public SerialPortWindow() { + super(parentPapplet, 150, 350); + + int xPos = 100; + int yPos = 100; + + final Frame f = new Frame(CHANGE_SERIAL_PORT_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(); + } + }); + + RadioButton r = cp5().addRadioButton("radio_serialPort") + .setPosition(10, 10) + .setSize(15,15) + .setSpacingRow(5) + .plugTo(parentPapplet, "radio_serialPort"); - 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"); + String[] ports = Serial.list(); + + for (int i = 0; i < ports.length; i++) { + println("Adding " + ports[i]); + r.addItem(ports[i], i); + } + + int portNo = getSerialPortNumber(); + if (portNo >= 0 && portNo < ports.length) + r.activate(ports[portNo]); + else + r.activate("No serial connection"); + + } + + } 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; + 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]; + 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; - } + 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."); + println("no serial port change."); } } +/* +ControlFrame newControlFrame(String name, int xPos, int yPos, int width, int height) { + final Frame f = new Frame(name); + final ControlFrame p = new ControlFrame(this, width, height); + f.add(p); + p.init(); + f.setTitle(name); + f.setSize(p.w, p.h); + f.setLocation(xPos, yPos); + f.setResizable(false); + f.setVisible(true); + + f.addWindowListener( new WindowAdapter() { + @Override + public void windowClosing(WindowEvent we) { + p.dispose(); + f.dispose(); + if (controlFrames.containsKey(f.getName())) { + controlFrames.remove(f.getName()); + } + + } + }); + + return p; +} + +*/ /*------------------------------------------------------------------------ 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() -{ - sendMachineLiveMode(); -} - - - - - -/*------------------------------------------------------------------------ - Details about the "drawing" subwindow -------------------------------------------------------------------------*/ -void button_mode_drawPixelsDialog() -{ - this.dialogWindow = cp5.addControlWindow("drawPixelsWindow",100,100,450,150); - dialogWindow.hideCoordinates(); - - dialogWindow.setBackground(getBackgroundColour()); - - 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); - - 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); - -// Radio rDir = cp5.addRadio("radio_rowStartDirection",100,10); -// rDir.add("Upwards", 0); -// rDir.add("Downwards", 1); -// rDir.setWindow(dialogWindow); - - 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); - } - rStyle.setWindow(dialogWindow); - - Button submitButton = cp5.addButton("submitDrawWindow",0,280,10,120,20); - submitButton.setLabel("Generate commands"); - submitButton.setWindow(dialogWindow); - - -} - +// +//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() +//{ +// sendMachineLiveMode(); +//} +// +// +// +// +// +///*------------------------------------------------------------------------ +// Details about the "drawing" subwindow +//------------------------------------------------------------------------*/ +//void button_mode_drawPixelsDialog() +//{ +// this.dialogWindow = cp5.addControlWindow("drawPixelsWindow",100,100,450,150); +// dialogWindow.hideCoordinates(); +// +// dialogWindow.setBackground(getBackgroundColour()); +// +// 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); +// +// 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); +// +//// Radio rDir = cp5.addRadio("radio_rowStartDirection",100,10); +//// rDir.add("Upwards", 0); +//// rDir.add("Downwards", 1); +//// rDir.setWindow(dialogWindow); +// +// 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); +// } +// 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; - } - - -} - -/*------------------------------------------------------------------------ - Details about the "writing" subwindow -------------------------------------------------------------------------*/ +//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; +// } +// +// +//} +// +///*------------------------------------------------------------------------ +// 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(); - - dialogWindow.setBackground(getBackgroundColour()); - - Textfield spriteFileField = cp5.addTextfield("spriteFilePrefixField",20,20,150,20); - spriteFileField.setText(getSpriteFilePrefix()); - spriteFileField.setLabel("File prefix"); - spriteFileField.setWindow(dialogWindow); - - Textfield writingField = cp5.addTextfield("textToWriteField",20,60,400,20); - writingField.setText(getTextToWrite()); - writingField.setLabel("Text to write"); - writingField.setWindow(dialogWindow); - - 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); +// +//void button_mode_drawWritingDialog() +//{ +// this.dialogWindow = cp5.addControlWindow("drawWritingWindow",100,100,450,200); +// dialogWindow.hideCoordinates(); +// +// dialogWindow.setBackground(getBackgroundColour()); +// +// Textfield spriteFileField = cp5.addTextfield("spriteFilePrefixField",20,20,150,20); +// spriteFileField.setText(getSpriteFilePrefix()); +// spriteFileField.setLabel("File prefix"); +// spriteFileField.setWindow(dialogWindow); +// +// Textfield writingField = cp5.addTextfield("textToWriteField",20,60,400,20); +// writingField.setText(getTextToWrite()); +// writingField.setLabel("Text to write"); +// writingField.setWindow(dialogWindow); +// +// 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(); +//} +// +// +//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. - - 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/ - http://code.google.com/p/polargraph/ - */ -Set getPanelNames() -{ + 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 +*/ +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(); @@ -84,8 +75,7 @@ Set getControlsToLockIfBoxNotSpecified() return this.controlsToLockIfBoxNotSpecified; } -Set getControlsToLockIfImageNotLoaded() -{ +Set getControlsToLockIfImageNotLoaded() { if (this.controlsToLockIfImageNotLoaded == null) { this.controlsToLockIfImageNotLoaded = buildControlsToLockIfImageNotLoaded(); @@ -93,9 +83,7 @@ Set getControlsToLockIfImageNotLoaded() return this.controlsToLockIfImageNotLoaded; } - -void hideAllControls() -{ +void hideAllControls() { for (String key : allControls.keySet()) { Controller c = allControls.get(key); @@ -103,8 +91,7 @@ void hideAllControls() } } -Map buildPanels() -{ +Map buildPanels() { Map panels = new HashMap(); float panelHeight = frame.getHeight() - getMainPanelPosition().y - (DEFAULT_CONTROL_SIZE.y*3); @@ -121,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)); @@ -131,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)); @@ -141,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)); @@ -151,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)); @@ -165,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 @@ -241,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); } @@ -252,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); } @@ -264,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); @@ -500,6 +487,12 @@ Map initialiseNumberboxValues(Map map) n.setMax(PATH_LENGTH_HIGHPASS_CUTOFF_MAX); n.setMultiplier(0.5); } + else if (MODE_ADJUST_PREVIEW_CORD_OFFSET.equals(key)) + { + n.setDecimalPrecision(0); + n.setValue(0); + n.setMultiplier(0.5); + } } } return map; @@ -555,9 +548,6 @@ Map initialiseToggleValues(Map map) return map; } - - - String getControlLabel(String butName) { if (controlLabels.containsKey(butName)) @@ -574,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()) { @@ -588,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()) { @@ -597,9 +587,9 @@ Map buildControlPositionsForPanel(Panel panel) } } } - return map; } + Map buildControlSizesForPanel(Panel panel) { //println("Building control sizes for panel " + panel.getName()); @@ -609,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); } } @@ -688,6 +678,8 @@ List getControlNamesForInputPanel() controlNames.add(MODE_CHANGE_MIN_VECTOR_LINE_LENGTH); //controlNames.add(MODE_VECTOR_PATH_LENGTH_HIGHPASS_CUTOFF); controlNames.add(MODE_RENDER_VECTORS); + + controlNames.add(MODE_ADJUST_PREVIEW_CORD_OFFSET); controlNames.add(MODE_SHOW_IMAGE); controlNames.add(MODE_SHOW_VECTOR); @@ -784,7 +776,7 @@ List getControlNamesForDetailPanel() controlNames.add(MODE_SEND_BUTTON_ACTIVATE); controlNames.add(MODE_SEND_BUTTON_DEACTIVATE); - + controlNames.add(MODE_CHANGE_SERIAL_PORT); return controlNames; @@ -960,6 +952,8 @@ 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, "Cord offset"); + return result; } @@ -1103,6 +1097,7 @@ Set buildControlNames() result.add(MODE_SEND_BUTTON_ACTIVATE); result.add(MODE_SEND_BUTTON_DEACTIVATE); + result.add(MODE_ADJUST_PREVIEW_CORD_OFFSET); return result; } diff --git a/drawing.pde b/drawing.pde index 4952b13..7ba69fa 100644 --- a/drawing.pde +++ b/drawing.pde @@ -1,31 +1,31 @@ /** - Polargraph controller - Copyright Sandy Noble 2012. - - 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/ - http://code.google.com/p/polargraph/ - */ + 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 +*/ static final String CMD_CHANGELENGTH = "C01,"; static final String CMD_CHANGEPENWIDTH = "C02,"; static final String CMD_CHANGEMOTORSPEED = "C03,"; diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index 7688662..1b430fa 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -1,6 +1,6 @@ /** Polargraph controller - Copyright Sandy Noble 2014. + Copyright Sandy Noble 2015. This file is part of Polargraph Controller. @@ -24,8 +24,7 @@ sandy.noble@gmail.com http://www.polargraph.co.uk/ - http://code.google.com/p/polargraph/ - + https://github.com/euphy/polargraphcontroller */ //import processing.video.*; import diewald_CV_kit.libraryinfo.*; @@ -49,10 +48,14 @@ 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 = 10; -int buildNo = 2; +import java.lang.reflect.Method; + +int majorVersionNo = 2; +int minorVersionNo = 0; +int buildNo = 0; String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo; ControlP5 cp5; @@ -329,6 +332,8 @@ static final String MODE_ROTATE_WEBCAM_INPUT = "toggle_mode_rotateWebcam"; static final String MODE_SEND_BUTTON_ACTIVATE = "button_mode_sendButtonActivate"; static final String MODE_SEND_BUTTON_DEACTIVATE = "button_mode_sendButtonDeactivate"; +static final String MODE_ADJUST_PREVIEW_CORD_OFFSET = "numberbox_mode_previewCordOffsetValue"; + PVector statusTextPosition = new PVector(300.0, 12.0); @@ -395,6 +400,8 @@ public color guideColour = color(255); public color backgroundColour = color(100); public color densityPreviewColour = color(0); +public Integer previewCordOffset = 0; + public boolean showingSummaryOverlay = true; public boolean showingDialogBox = false; @@ -433,7 +440,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; @@ -451,11 +458,13 @@ public Set controlsToLockIfImageNotLoaded = null; public Map> panelsForTabs = null; public Map panels = null; +public Map controlFrames = new HashMap(); + // 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; @@ -489,8 +498,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; @@ -505,20 +512,16 @@ String shapeSavePath = "../../savedcaptures/"; String shapeSavePrefix = "shape-"; String shapeSaveExtension = ".svg"; -//boolean displayGamepadOverlay = false; -//PImage yButtonImage = null; -//PImage xButtonImage = null; -//PImage aButtonImage = null; -//PImage bButtonImage = null; -// -//PImage dpadXImage = null; -//PImage dpadYImage = null; +String filePath = null; + +static PApplet parentPapplet = null; void setup() { println("Running polargraph controller"); frame.setResizable(true); initLogging(); + parentPapplet = this; initImages(); @@ -535,6 +538,7 @@ void setup() } loadFromPropertiesFile(); + size(windowWidth, windowHeight, JAVA2D ); this.cp5 = new ControlP5(this); initTabs(); @@ -580,7 +584,6 @@ void setup() currentMode = MODE_BEGIN; preLoadCommandQueue(); - size(windowWidth, windowHeight, JAVA2D ); changeTab(TAB_NAME_INPUT, TAB_NAME_INPUT); addEventListeners(); @@ -1224,34 +1227,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()) { - 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 allCommands = new ArrayList(realtimeCommandQueue); allCommands.addAll(commandQueue); String[] list = (String[]) allCommands.toArray(new String[0]); - saveStrings(savePath, list); + 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 { + println("User selected " + selection.getAbsolutePath()); + filePath = selection.getAbsolutePath(); + } +} + + void importQueueFromFile() { commandQueue.clear(); - String loadPath = selectInput(); - if (loadPath == null) + selectInput("Select file to import queue from", "fileSelected"); + if (filePath == null) { // nothing selected println("No input file was selected."); } else { - println("Input file: " + loadPath); - String commands[] = loadStrings(loadPath); + println("Input file: " + filePath); + String commands[] = loadStrings(filePath); // List list = Arrays commandQueue.addAll(Arrays.asList(commands)); println("Completed queue import, " + commandQueue.size() + " commands found."); @@ -1874,17 +1890,17 @@ void importQueueFromFile() String importTextToWriteFromFile() { - String loadPath = selectInput(); + selectInput("Select the text file to load the text from:", "fileSelected"); String result = ""; - if (loadPath == null) + if (filePath == null) { // nothing selected println("No input file was selected."); } else { - println("Input file: " + loadPath); - List rows = java.util.Arrays.asList(loadStrings(loadPath)); + println("Input file: " + filePath); + List rows = java.util.Arrays.asList(loadStrings(filePath)); StringBuilder sb = new StringBuilder(200); for (String row : rows) { @@ -3063,10 +3079,12 @@ float getPixelScalingOverGridSize() { return pixelScalingOverGridSize; } + void setPixelScalingOverGridSize(float scaling) { pixelScalingOverGridSize = scaling; } + int getDensityPreviewStyle() { return densityPreviewStyle; @@ -3076,14 +3094,17 @@ Integer getBaudRate() { return baudRate; } + boolean isUseWindowedConsole() { return this.useWindowedConsole; } + void setUseWindowedConsole(boolean use) { this.useWindowedConsole = use; } + void initLogging() { try @@ -3094,21 +3115,22 @@ void initLogging() // logger.addHandler(fileHandler); // logger.setLevel(Level.INFO); // logger.info("Hello"); - if (isUseWindowedConsole()) - { - console = new Console(); - } - else - { - console.close(); - console = null; - } +// if (isUseWindowedConsole()) +// { +// console = new Console(); +// } +// else +// { +// console.close(); +// console = null; +// } } catch(Exception e) { println("Exception setting up logger: " + e.getMessage()); } } + void initImages() { // try diff --git a/tabSetup.pde b/tabSetup.pde index 67f6ac6..3d62dec 100644 --- a/tabSetup.pde +++ b/tabSetup.pde @@ -1,6 +1,6 @@ /** Polargraph controller - Copyright Sandy Noble 2012. + Copyright Sandy Noble 2015. This file is part of Polargraph Controller. @@ -24,7 +24,7 @@ sandy.noble@gmail.com http://www.polargraph.co.uk/ - http://code.google.com/p/polargraph/ + https://github.com/euphy/polargraphcontroller */ Set getPanelsForTab(String tabName) @@ -83,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() From fdf2bca1c035352c8eec7248a850cc6c6856b6c0 Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Sun, 26 Apr 2015 20:58:07 +0100 Subject: [PATCH 02/13] Added MAchineExecWindow class --- MachineExecWindow.pde | 48 +++++++ MachineStoreWindow.pde | 59 +++++++++ SerialPortWindow.pde | 111 ++++++++++++++++ controlsActionsWindows.pde | 253 +++---------------------------------- polargraphcontroller.pde | 2 - 5 files changed, 239 insertions(+), 234 deletions(-) create mode 100644 MachineExecWindow.pde create mode 100644 MachineStoreWindow.pde create mode 100644 SerialPortWindow.pde diff --git a/MachineExecWindow.pde b/MachineExecWindow.pde new file mode 100644 index 0000000..42e1413 --- /dev/null +++ b/MachineExecWindow.pde @@ -0,0 +1,48 @@ +class MachineExecWindow extends ControlFrame { + + void execFilename(String filename) { + println("Filename event: "+ filename); + if (filename != null && filename.length() <= 12) { + setStoreFilename(filename); + sendMachineExecMode(); + } + } + + void submitExecFilenameWindow(int theValue) { + cp5().get(Textfield.class, "execFilename").submit(); + } + + public MachineExecWindow() { + super(parentPapplet, 450, 150); + int xPos = 100; + int yPos = 100; + String name = MACHINE_EXEC_WINDOW_NAME; + + final Frame f = new Frame(name); + f.add(this); + this.init(); + f.setTitle(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(); + } + }); + + Textfield filenameField = cp5().addTextfield("execFilename",20,20,150,20) + .setText(getStoreFilename()) + .setLabel("Filename to execute from") + .plugTo("execFilename"); + + Button submitButton = cp5().addButton("submitExecFilenameWindow",0,180,20,60,20) + .setLabel("Submit") + .plugTo("submitExecFilenameWindow"); + + filenameField.setFocus(true); + } +} diff --git a/MachineStoreWindow.pde b/MachineStoreWindow.pde new file mode 100644 index 0000000..f35af62 --- /dev/null +++ b/MachineStoreWindow.pde @@ -0,0 +1,59 @@ +/*------------------------------------------------------------------------ + Details about the "machine store" subwindow +------------------------------------------------------------------------*/ +class MachineStoreWindow extends ControlFrame { + + 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) { + cp5().get(Textfield.class, "storeFilename").submit(); + } + + public MachineStoreWindow() { + super(parentPapplet, 450, 150); + int xPos = 100; + int yPos = 100; + String name = MACHINE_STORE_WINDOW_NAME; + + final Frame f = new Frame(name); + f.add(this); + this.init(); + f.setTitle(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(); + } + }); + + Textfield filenameField = cp5().addTextfield("storeFilename",20,20,150,20) + .setText(getStoreFilename()) + .setLabel("Filename to store to") + .plugTo("storeFilename"); + + Button submitButton = cp5().addButton("submitStoreFilenameWindow",0,180,20,60,20) + .setLabel("Submit") + .plugTo("submitStoreFilenameWindow"); + + Toggle overwriteToggle = cp5().addToggle("toggleAppendToFile",true,180,50,20,20) + .setCaptionLabel("Overwrite existing file") + .plugTo("toggleAppendToFile"); + + filenameField.setFocus(true); + } +} \ No newline at end of file diff --git a/SerialPortWindow.pde b/SerialPortWindow.pde new file mode 100644 index 0000000..057a861 --- /dev/null +++ b/SerialPortWindow.pde @@ -0,0 +1,111 @@ +/*------------------------------------------------------------------------ + Class and controllers on the "serial port" subwindow +------------------------------------------------------------------------*/ + +class SerialPortWindow extends ControlFrame { + public SerialPortWindow() { + super(parentPapplet, 150, 350); + + int xPos = 100; + int yPos = 100; + + final Frame f = new Frame(CHANGE_SERIAL_PORT_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(); + } + }); + + RadioButton r = cp5().addRadioButton("radio_serialPort") + .setPosition(10, 10) + .setSize(15,15) + .setSpacingRow(5) + .plugTo(parentPapplet, "radio_serialPort"); + + String[] ports = Serial.list(); + + for (int i = 0; i < ports.length; i++) { + println("Adding " + ports[i]); + r.addItem(ports[i], i); + } + + int portNo = getSerialPortNumber(); + if (portNo >= 0 && portNo < ports.length) + r.activate(ports[portNo]); + else + r.activate("No serial connection"); + } +} + +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."); + } +} \ No newline at end of file diff --git a/controlsActionsWindows.pde b/controlsActionsWindows.pde index 2442702..7555356 100644 --- a/controlsActionsWindows.pde +++ b/controlsActionsWindows.pde @@ -27,30 +27,32 @@ https://github.com/euphy/polargraphcontroller */ - -/*------------------------------------------------------------------------ - Details about the "serial port" subwindow -------------------------------------------------------------------------*/ - +void button_mode_sendMachineLiveMode() { + sendMachineLiveMode(); +} + String CHANGE_SERIAL_PORT_WINDOW_NAME = "changeSerialPortWindow"; +String MACHINE_STORE_WINDOW_NAME = "chooseStoreFilenameWindow"; +String MACHINE_EXEC_WINDOW_NAME = "chooseExecFilenameWindow"; void button_mode_serialPortDialog() { - if (controlFrames.containsKey(CHANGE_SERIAL_PORT_WINDOW_NAME)) { - println("NOT OPENING ANOTHER ONE!"); - } - else { - final SerialPortWindow serialPortWindow = new SerialPortWindow(); - controlFrames.put(CHANGE_SERIAL_PORT_WINDOW_NAME, serialPortWindow); - } + final SerialPortWindow serialPortWindow = new SerialPortWindow(); } -class SerialPortWindow extends ControlFrame { - - @Override - public ControlP5 cp5() { - return super.cp5(); - } - public SerialPortWindow() { +void button_mode_machineStoreDialog() { + final MachineStoreWindow machineStoreWindow = new MachineStoreWindow(); +} + +void button_mode_machineExecDialog() { + final MachineExecWindow machineExecWindow = new MachineExecWindow(); +} + +void button_mode_drawPixelsDialog() { + final DrawPixelsWindow drawPixelsWindow = new DrawPixelsWindow(); +} + +class DrawPixelsWindow extends ControlFrame { + public DrawPixelsWindow() { super(parentPapplet, 150, 350); int xPos = 100; @@ -68,223 +70,10 @@ class SerialPortWindow extends ControlFrame { f.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { - f.dispose(); } }); - - RadioButton r = cp5().addRadioButton("radio_serialPort") - .setPosition(10, 10) - .setSize(15,15) - .setSpacingRow(5) - .plugTo(parentPapplet, "radio_serialPort"); - - String[] ports = Serial.list(); - - for (int i = 0; i < ports.length; i++) { - println("Adding " + ports[i]); - r.addItem(ports[i], i); - } - - int portNo = getSerialPortNumber(); - if (portNo >= 0 && portNo < ports.length) - r.activate(ports[portNo]); - else - r.activate("No serial connection"); - - } - - } - -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."); - } -} -/* -ControlFrame newControlFrame(String name, int xPos, int yPos, int width, int height) { - final Frame f = new Frame(name); - final ControlFrame p = new ControlFrame(this, width, height); - f.add(p); - p.init(); - f.setTitle(name); - f.setSize(p.w, p.h); - f.setLocation(xPos, yPos); - f.setResizable(false); - f.setVisible(true); - - f.addWindowListener( new WindowAdapter() { - @Override - public void windowClosing(WindowEvent we) { - p.dispose(); - f.dispose(); - if (controlFrames.containsKey(f.getName())) { - controlFrames.remove(f.getName()); - } - - } - }); - - return p; -} - -*/ - - -/*------------------------------------------------------------------------ - 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() -//{ -// sendMachineLiveMode(); -//} -// -// -// -// -// ///*------------------------------------------------------------------------ // Details about the "drawing" subwindow //------------------------------------------------------------------------*/ diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index 1b430fa..bbd62a0 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -458,8 +458,6 @@ public Set controlsToLockIfImageNotLoaded = null; public Map> panelsForTabs = null; public Map panels = null; -public Map controlFrames = new HashMap(); - // machine moving PVector machineDragOffset = new PVector (0.0, 0.0); PVector lastMachineDragPosition = new PVector (0.0, 0.0); From 1abe63bba62a23b2b6a7004284b8b5e43a49bb13 Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Sun, 26 Apr 2015 23:00:04 +0100 Subject: [PATCH 03/13] Split Draw pixels window out, started on draw writing --- DrawPixelsWindow.pde | 102 +++++++++++++ controlsActionsWindows.pde | 289 +++++++++++++------------------------ polargraphcontroller.pde | 2 +- 3 files changed, 206 insertions(+), 187 deletions(-) create mode 100644 DrawPixelsWindow.pde diff --git a/DrawPixelsWindow.pde b/DrawPixelsWindow.pde new file mode 100644 index 0000000..2695aea --- /dev/null +++ b/DrawPixelsWindow.pde @@ -0,0 +1,102 @@ +///*------------------------------------------------------------------------ +// 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 + +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(); + } + }); + + RadioButton rPos = 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("radio_startPosition"); + + RadioButton rSkip = cp5().addRadioButton("radio_pixelSkipStyle",10,100) + .add("Lift pen over masked pixels", 1) + .add("Draw masked pixels as blanks", 2) + .plugTo("radio_pixelSkipStyle"); + + RadioButton rStyle = 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("radio_pixelStyle"); + + + Button submitButton = cp5().addButton("submitDrawWindow",0,280,10,120,20) + .setLabel("Generate commands") + .plugTo("submitDrawWindow"); + } + + 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; + } + } +} \ No newline at end of file diff --git a/controlsActionsWindows.pde b/controlsActionsWindows.pde index 7555356..3551b5f 100644 --- a/controlsActionsWindows.pde +++ b/controlsActionsWindows.pde @@ -34,6 +34,8 @@ void button_mode_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() { final SerialPortWindow serialPortWindow = new SerialPortWindow(); @@ -51,17 +53,27 @@ void button_mode_drawPixelsDialog() { final DrawPixelsWindow drawPixelsWindow = new DrawPixelsWindow(); } -class DrawPixelsWindow extends ControlFrame { - public DrawPixelsWindow() { - super(parentPapplet, 150, 350); - +void button_mode_drawWritingDialog() { + final DrawWritingWindow drawWritingWindow = new DrawWritingWindow(); +} + +///*------------------------------------------------------------------------ +// Details about the "writing" subwindow +//------------------------------------------------------------------------*/ +String textToWrite = ""; +String spriteFilePrefix = "sprite/let"; +String spriteFileSuffix = ".txt"; +class DrawWritingWindow extends ControlFrame { + public DrawWritingWindow() { + super(parentPapplet, 450, 250); int xPos = 100; int yPos = 100; + String name = DRAW_WRITING_WINDOW_NAME; - final Frame f = new Frame(CHANGE_SERIAL_PORT_WINDOW_NAME); + final Frame f = new Frame(name); f.add(this); this.init(); - f.setTitle(CHANGE_SERIAL_PORT_WINDOW_NAME); + f.setTitle(name); f.setSize(super.w, super.h); f.setLocation(xPos, yPos); f.setResizable(false); @@ -73,105 +85,92 @@ class DrawPixelsWindow extends ControlFrame { f.dispose(); } }); + Textfield spriteFileField = cp5().addTextfield("spriteFilePrefixField",20,20,150,20) + .setText(getSpriteFilePrefix()) + .setLabel("File prefix") + .plugTo("spriteFilePrefixField"); + + Textfield writingField = cp5().addTextfield("textToWriteField",20,60,400,20) + .setText(getTextToWrite()) + .setLabel("Text to write") + .plugTo("textToWriteField"); + + Button importTextButton = cp5().addButton("importTextButton",0,20,100,120,20) + .setLabel("Load text from file") + .plugTo("importTextButton"); + + RadioButton rPos = cp5().addRadioButton("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.plugTo("radio_drawWritingDirection"); + + Button submitButton = cp5.addButton("submitWritingWindow",0,300,100,120,20) + .setLabel("Generate commands") + .plugTo("submitWritingWindow"); + } + + + 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() + { + println("Text!"); + textToWrite = importTextToWriteFromFile(); + println(textToWrite); + Textfield tf = cp5().get(Textfield.class, "textToWriteField"); + tf.setText(getTextToWrite()); + tf.submit(); + } + + + void submitWritingWindow(int theValue) + { + println("Write."); + + Textfield tf = cp5().get(Textfield.class, "spriteFilePrefixField"); + tf.submit(); + tf.setText(getSpriteFilePrefix()); + + Textfield wf = cp5.get(Textfield.class, "textToWriteField"); + wf.submit(); + wf.setText(getTextToWrite()); + + println("Start dir: " + renderStartDirection); + println("Sprite file prefix: " + spriteFilePrefix); + println("Text: " + textToWrite); + + for (int i=0; i= HARDWARE_VER_MEGA) -// { -// rStyle.add("Spiral", PIXEL_STYLE_CIRCLE); -// rStyle.add("Sawtooth", PIXEL_STYLE_SAW); -// } -// 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; -// } -// -// -//} -// -///*------------------------------------------------------------------------ -// Details about the "writing" subwindow -//------------------------------------------------------------------------*/ -String textToWrite = ""; -String spriteFilePrefix = "sprite/let"; -String spriteFileSuffix = ".txt"; // //void button_mode_drawWritingDialog() //{ @@ -180,88 +179,6 @@ String spriteFileSuffix = ".txt"; // // dialogWindow.setBackground(getBackgroundColour()); // -// Textfield spriteFileField = cp5.addTextfield("spriteFilePrefixField",20,20,150,20); -// spriteFileField.setText(getSpriteFilePrefix()); -// spriteFileField.setLabel("File prefix"); -// spriteFileField.setWindow(dialogWindow); -// -// Textfield writingField = cp5.addTextfield("textToWriteField",20,60,400,20); -// writingField.setText(getTextToWrite()); -// writingField.setLabel("Text to write"); -// writingField.setWindow(dialogWindow); -// -// 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(); -//} -// -// -//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 Date: Sun, 26 Apr 2015 23:08:15 +0100 Subject: [PATCH 04/13] Update README.md --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5839566..f4eace0 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,19 @@ polargraphcontroller ==================== Polargraph controller -Copyright Sandy Noble 2014. +Copyright Sandy Noble 2015. -- Requires v0.5.4 of the excellent ControlP5 GUI library available from http://www.sojamo.de/libraries/controlP5/ - - (http://code.google.com/p/controlp5/downloads/detail?name=controlP5_0.5.4.zip&can=2&q=). +*** THIS VERSION IS UNDER DEVELOPMENT! *** +========================================== + +This branch is being migrated to v2x of Processing, and modern versions of the libraries. + +- Requires the excellent ControlP5 GUI library available from https://github.com/sojamo/controlp5. - Requires the excellent Geomerative library available from http://www.ricardmarxer.com/geomerative/. -- Currently only runs on Processing v1.5 +- Somewhat running on Processing v2.2.1. This is a desktop application for controlling a polargraph machine, communicating using ASCII command language over a serial link. -Very sorry that this doesn't work with newest versions of the libraries and Processing. - The [latest releases bundle] (https://github.com/euphy/polargraphcontroller/releases/latest) contains copies of all the libraries that I use, as well as all the source, and compiled versions of the code where sensible. From d075117fbfccd685790f662fb39f8fcafb6af5a6 Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Wed, 15 Jul 2015 21:21:37 +0100 Subject: [PATCH 05/13] Added star.gco example --- data/star.gco | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 data/star.gco diff --git a/data/star.gco b/data/star.gco new file mode 100644 index 0000000..ef28d94 --- /dev/null +++ b/data/star.gco @@ -0,0 +1,37 @@ +% +(Header) +(Generated by gcodetools from Inkscape.) +(Using default header. To add your own header create file "header" in the output dir.) +M3 +(Header end.) +G21 (All units in mm) + +(Start cutting path id: path3336) +(Change tool to Default tool) + +G00 Z5.000000 +G00 X145.949208 Y119.339675 + +G01 Z-0.125000 F100.0(Penetrate) +G01 X99.103415 Y136.824796 Z-0.125000 F400.000000 +G01 X58.142003 Y108.146925 Z-0.125000 +G01 X60.295192 Y158.103121 Z-0.125000 +G01 X20.363145 Y188.197789 Z-0.125000 +G01 X68.539682 Y201.587300 Z-0.125000 +G01 X84.821731 Y248.864696 Z-0.125000 +G01 X112.443280 Y207.183671 Z-0.125000 +G01 X162.438188 Y206.308042 Z-0.125000 +G01 X131.332705 Y167.158243 Z-0.125000 +G01 X145.949208 Y119.339675 Z-0.125000 +G00 Z5.000000 + +(End cutting path id: path3336) + + +(Footer) +M5 +G00 X0.0000 Y0.0000 +M2 +(Using default footer. To add your own footer create file "footer" in the output dir.) +(end) +% \ No newline at end of file From cc7774edc2fbb16acd7574256ef45920606be303 Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Sat, 18 Jul 2015 10:01:02 +0100 Subject: [PATCH 06/13] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5839566..4ca1c73 100644 --- a/README.md +++ b/README.md @@ -16,5 +16,7 @@ Very sorry that this doesn't work with newest versions of the libraries and Proc The [latest releases bundle] (https://github.com/euphy/polargraphcontroller/releases/latest) contains copies of all the libraries that I use, as well as all the source, and compiled versions of the code where sensible. +This project (polargraphcontroller) is the "owner" of the bundle, in that bundle releases show up as events against this project. But not every bundle release actually includes an update from polargraphcontroller, but still requires one to keep the release sequence in order. So there's some fake changes. Just be chill. + sandy.noble@gmail.com http://www.polargraph.co.uk/ From cbb2678aefd9223f09dab6999767900bc281cfea Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Sun, 16 Aug 2015 12:19:19 +0100 Subject: [PATCH 07/13] Quite a few things working. The window focus is still a bit weird. --- ControlFrame.pde | 8 ++- DisplayMachine.pde | 23 ++++---- SerialPortWindow.pde | 6 +- controlsActionsWindows.pde | 97 +++++++++++++++--------------- polargraphcontroller.pde | 118 ++++++++++++------------------------- 5 files changed, 113 insertions(+), 139 deletions(-) diff --git a/ControlFrame.pde b/ControlFrame.pde index a2eba2f..d124589 100644 --- a/ControlFrame.pde +++ b/ControlFrame.pde @@ -5,12 +5,12 @@ public class ControlFrame extends PApplet { public int w, h; int abc = 100; public ControlP5 cp5; - protected Object parent; + protected PApplet parent; private ControlFrame() { } - public ControlFrame(Object theParent, int theWidth, int theHeight) { + public ControlFrame(PApplet theParent, int theWidth, int theHeight) { this.parent = theParent; this.w = theWidth; this.h = theHeight; @@ -23,6 +23,10 @@ public class ControlFrame extends PApplet { return this.cp5; } + public PApplet getParent() { + return this.parent; + } + public void setup() { size(w, h); frameRate(5); diff --git a/DisplayMachine.pde b/DisplayMachine.pde index 6e7019c..a0d9582 100644 --- a/DisplayMachine.pde +++ b/DisplayMachine.pde @@ -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/SerialPortWindow.pde b/SerialPortWindow.pde index 057a861..086b073 100644 --- a/SerialPortWindow.pde +++ b/SerialPortWindow.pde @@ -15,7 +15,7 @@ class SerialPortWindow extends ControlFrame { f.setTitle(CHANGE_SERIAL_PORT_WINDOW_NAME); f.setSize(super.w, super.h); f.setLocation(xPos, yPos); - f.setResizable(false); + f.setResizable(true); f.setVisible(true); f.addWindowListener( new WindowAdapter() { @@ -31,6 +31,8 @@ class SerialPortWindow extends ControlFrame { .setSpacingRow(5) .plugTo(parentPapplet, "radio_serialPort"); + r.addItem("No serial connection", -1); + String[] ports = Serial.list(); for (int i = 0; i < ports.length; i++) { @@ -108,4 +110,4 @@ void radio_serialPort(int newSerialPort) { println("no serial port change."); } -} \ No newline at end of file +} diff --git a/controlsActionsWindows.pde b/controlsActionsWindows.pde index 3551b5f..75df251 100644 --- a/controlsActionsWindows.pde +++ b/controlsActionsWindows.pde @@ -63,7 +63,7 @@ void button_mode_drawWritingDialog() { String textToWrite = ""; String spriteFilePrefix = "sprite/let"; String spriteFileSuffix = ".txt"; -class DrawWritingWindow extends ControlFrame { +public class DrawWritingWindow extends ControlFrame { public DrawWritingWindow() { super(parentPapplet, 450, 250); int xPos = 100; @@ -110,66 +110,71 @@ class DrawWritingWindow extends ControlFrame { .setLabel("Generate commands") .plugTo("submitWritingWindow"); } - - void spriteFilePrefixField(String value) - { - spriteFilePrefix = value; + void spriteFilePrefixField(String value) { + spriteFilePrefix = value; } - void textToWriteField(String value) - { - textToWrite = value; + void textToWriteField(String value) { + textToWrite = value; } - String getTextToWrite() - { - return textToWrite; + String getTextToWrite() { + return textToWrite; } - String getSpriteFilePrefix() - { - return spriteFilePrefix; + String getSpriteFilePrefix() { + return spriteFilePrefix; } - String getSpriteFileSuffix() - { - return spriteFileSuffix; + String getSpriteFileSuffix() { + return spriteFileSuffix; } - void importTextButton() - { + void importTextButton() { println("Text!"); - textToWrite = importTextToWriteFromFile(); - println(textToWrite); - Textfield tf = cp5().get(Textfield.class, "textToWriteField"); - tf.setText(getTextToWrite()); - tf.submit(); + selectInput("Select the text file to load the text from:", "importTextToWriteFromFile", null, this); + } + + public void importTextToWriteFromFile(File selection) { + if (selection != null) { + String fp = selection.getAbsolutePath(); + println("Input file: " + fp); + List rows = java.util.Arrays.asList(loadStrings(fp)); + StringBuilder sb = new StringBuilder(200); + for (String row : rows) { + sb.append(row); + } + textToWriteField(sb.toString()); + println("Completed text import, " + getTextToWrite().length() + " characters found."); + + println("Text: " + getTextToWrite()); + + Textfield tf = cp5().get(Textfield.class, "textToWriteField"); + tf.setText(getTextToWrite()); + tf.submit(); + } } - void submitWritingWindow(int theValue) { - println("Write."); - - Textfield tf = cp5().get(Textfield.class, "spriteFilePrefixField"); - tf.submit(); - tf.setText(getSpriteFilePrefix()); - - Textfield wf = cp5.get(Textfield.class, "textToWriteField"); - wf.submit(); - wf.setText(getTextToWrite()); - - println("Start dir: " + renderStartDirection); - println("Sprite file prefix: " + spriteFilePrefix); - println("Text: " + textToWrite); + println("Write."); + + Textfield tf = cp5().get(Textfield.class, "spriteFilePrefixField"); + tf.submit(); + tf.setText(getSpriteFilePrefix()); + + Textfield wf = cp5.get(Textfield.class, "textToWriteField"); + wf.submit(); + wf.setText(getTextToWrite()); + + println("Start dir: " + renderStartDirection); + println("Sprite file prefix: " + spriteFilePrefix); + println("Text: " + textToWrite); - for (int i=0; i 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 exportQueueToFile() { + if (!commandQueue.isEmpty() || !realtimeCommandQueue.isEmpty()) { + selectOutput("Enter a filename to save to:", "exportQueueToFile"); // Opens file chooser + } +} + +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); - } + 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); -// List list = Arrays - commandQueue.addAll(Arrays.asList(commands)); - println("Completed queue import, " + commandQueue.size() + " commands found."); - } +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."); + } } -String importTextToWriteFromFile() -{ - selectInput("Select the text file to load the text from:", "fileSelected"); - String result = ""; - if (filePath == null) - { - // nothing selected - println("No input file was selected."); - } - else - { - println("Input file: " + filePath); - List rows = java.util.Arrays.asList(loadStrings(filePath)); - 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; -} From d005b1bb0c6b93afc1a7addb92d5e2357916fdb1 Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Sat, 5 Sep 2015 16:00:22 +0100 Subject: [PATCH 08/13] Most control frames now working. --- ControlFrame.pde | 40 +++--- DrawPixelsWindow.pde | 164 +++++++++++++--------- MachineExecWindow.pde | 106 +++++++++------ MachineStoreWindow.pde | 81 ++++++++++- SerialPortWindow.pde | 197 +++++++++++++-------------- controlsActionsWindows.pde | 272 +++++++++++++++++++------------------ drawing.pde | 2 +- 7 files changed, 496 insertions(+), 366 deletions(-) diff --git a/ControlFrame.pde b/ControlFrame.pde index d124589..38beffb 100644 --- a/ControlFrame.pde +++ b/ControlFrame.pde @@ -17,34 +17,36 @@ public class ControlFrame extends PApplet { } public ControlP5 cp5() { - if (this.cp5 == null) { - this.cp5 = this.setupControlP5(); - } - return this.cp5; + if (this.cp5 == null) { + this.cp5 = this.setupControlP5(); + } + return this.cp5; } - - public PApplet getParent() { - return this.parent; - } - + + public PApplet getParent() { + return this.parent; + } + public void setup() { size(w, h); frameRate(5); } - + public ControlP5 setupControlP5() { - println("About to create new ControlP5"); + println("About to create new ControlP5"); ControlP5 cp5 = new ControlP5(this); - println("Created: " + cp5); - while (cp5 == null) { + println("Created: " + cp5); + while (cp5 == null) { println("Was null: " + cp5); - } - println("Finally created: " + cp5); - return cp5; + } + println("Finally created: " + cp5); + return cp5; } public void draw() { - background(abc); + background(abc); } - -} \ No newline at end of file +} + + + diff --git a/DrawPixelsWindow.pde b/DrawPixelsWindow.pde index 2695aea..0b96807 100644 --- a/DrawPixelsWindow.pde +++ b/DrawPixelsWindow.pde @@ -6,6 +6,105 @@ public Integer renderStartDirection = DRAW_DIR_SE; // default start drawing in S 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 { @@ -32,71 +131,8 @@ class DrawPixelsWindow extends ControlFrame { } }); - RadioButton rPos = 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("radio_startPosition"); - RadioButton rSkip = cp5().addRadioButton("radio_pixelSkipStyle",10,100) - .add("Lift pen over masked pixels", 1) - .add("Draw masked pixels as blanks", 2) - .plugTo("radio_pixelSkipStyle"); - - RadioButton rStyle = 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("radio_pixelStyle"); - - - Button submitButton = cp5().addButton("submitDrawWindow",0,280,10,120,20) - .setLabel("Generate commands") - .plugTo("submitDrawWindow"); } - 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; - } - } -} \ No newline at end of file +} diff --git a/MachineExecWindow.pde b/MachineExecWindow.pde index 42e1413..7589c15 100644 --- a/MachineExecWindow.pde +++ b/MachineExecWindow.pde @@ -1,48 +1,64 @@ -class MachineExecWindow extends ControlFrame { +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 ); - void execFilename(String filename) { - println("Filename event: "+ filename); - if (filename != null && filename.length() <= 12) { - setStoreFilename(filename); - sendMachineExecMode(); - } - } - - void submitExecFilenameWindow(int theValue) { - cp5().get(Textfield.class, "execFilename").submit(); - } + 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"); + } + }); + - public MachineExecWindow() { - super(parentPapplet, 450, 150); - int xPos = 100; - int yPos = 100; - String name = MACHINE_EXEC_WINDOW_NAME; - - final Frame f = new Frame(name); - f.add(this); - this.init(); - f.setTitle(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(); - } - }); - - Textfield filenameField = cp5().addTextfield("execFilename",20,20,150,20) - .setText(getStoreFilename()) - .setLabel("Filename to execute from") - .plugTo("execFilename"); - - Button submitButton = cp5().addButton("submitExecFilenameWindow",0,180,20,60,20) - .setLabel("Submit") - .plugTo("submitExecFilenameWindow"); - - filenameField.setFocus(true); - } + 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 index f35af62..960c966 100644 --- a/MachineStoreWindow.pde +++ b/MachineStoreWindow.pde @@ -11,9 +11,7 @@ class MachineStoreWindow extends ControlFrame { } } - void toggleAppendToFile(boolean theFlag) { - setOverwriteExistingStoreFile(theFlag); - } + void submitStoreFilenameWindow(int theValue) { cp5().get(Textfield.class, "storeFilename").submit(); @@ -56,4 +54,79 @@ class MachineStoreWindow extends ControlFrame { filenameField.setFocus(true); } -} \ No newline at end of file +} + + +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/SerialPortWindow.pde b/SerialPortWindow.pde index 086b073..740bff4 100644 --- a/SerialPortWindow.pde +++ b/SerialPortWindow.pde @@ -1,113 +1,112 @@ /*------------------------------------------------------------------------ - Class and controllers on the "serial port" subwindow -------------------------------------------------------------------------*/ + Class and controllers on the "serial port" subwindow + ------------------------------------------------------------------------*/ -class SerialPortWindow extends ControlFrame { - public SerialPortWindow() { - super(parentPapplet, 150, 350); - - int xPos = 100; - int yPos = 100; +ControlFrameSimple addSerialPortControlFrame(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 ); - final Frame f = new Frame(CHANGE_SERIAL_PORT_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(true); - f.setVisible(true); - - f.addWindowListener( new WindowAdapter() { - @Override - public void windowClosing(WindowEvent we) { - f.dispose(); - } - }); - - RadioButton r = cp5().addRadioButton("radio_serialPort") - .setPosition(10, 10) - .setSize(15,15) - .setSpacingRow(5) - .plugTo(parentPapplet, "radio_serialPort"); + 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) { + } - r.addItem("No serial connection", -1); - - String[] ports = Serial.list(); - - for (int i = 0; i < ports.length; i++) { - println("Adding " + ports[i]); - r.addItem(ports[i], i); - } + // set up controls + RadioButton r = p.cp5().addRadioButton("radio_serialPort") + .setPosition(10, 10) + .setSize(15, 15) + .setSpacingRow(5) + .plugTo(this, "radio_serialPort"); - int portNo = getSerialPortNumber(); - if (portNo >= 0 && portNo < ports.length) - r.activate(ports[portNo]); - else - r.activate("No serial connection"); - } + r.addItem("No serial connection", -1); + + String[] ports = Serial.list(); + + for (int i = 0; i < ports.length; i++) { + println("Adding " + ports[i]); + r.addItem(ports[i], i); + } + + int portNo = getSerialPortNumber(); + if (portNo >= 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."); + } + 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/controlsActionsWindows.pde b/controlsActionsWindows.pde index 75df251..877bb9f 100644 --- a/controlsActionsWindows.pde +++ b/controlsActionsWindows.pde @@ -1,36 +1,36 @@ /** - 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 -*/ + 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 + */ void button_mode_sendMachineLiveMode() { - sendMachineLiveMode(); + sendMachineLiveMode(); } - + String CHANGE_SERIAL_PORT_WINDOW_NAME = "changeSerialPortWindow"; String MACHINE_STORE_WINDOW_NAME = "chooseStoreFilenameWindow"; String MACHINE_EXEC_WINDOW_NAME = "chooseExecFilenameWindow"; @@ -38,23 +38,26 @@ String DRAW_PIXELS_WINDOW_NAME = "drawPixelsWindow"; String DRAW_WRITING_WINDOW_NAME = "drawWritingWindow"; void button_mode_serialPortDialog() { - final SerialPortWindow serialPortWindow = new SerialPortWindow(); + ControlFrameSimple cf = addSerialPortControlFrame("Serial Port", 200, 200, 20, 240, color( 100 ) ); } void button_mode_machineStoreDialog() { - final MachineStoreWindow machineStoreWindow = new MachineStoreWindow(); + ControlFrameSimple cf = addMachineStoreControlFrame("Machine Store", 450, 250, 20, 240, color( 100 ) ); +// final MachineStoreWindow machineStoreWindow = new MachineStoreWindow(); } void button_mode_machineExecDialog() { - final MachineExecWindow machineExecWindow = new MachineExecWindow(); + ControlFrameSimple cf = addMachineExecControlFrame("Machine Execute", 450, 250, 20, 240, color( 100 ) ); +// final MachineExecWindow machineExecWindow = new MachineExecWindow(); } void button_mode_drawPixelsDialog() { - final DrawPixelsWindow drawPixelsWindow = new DrawPixelsWindow(); + ControlFrameSimple cf = addDrawPixelsControlFrame("Render pixels", 450, 250, 20, 240, color( 100 ) ); +// final DrawPixelsWindow drawPixelsWindow = new DrawPixelsWindow(); } void button_mode_drawWritingDialog() { - final DrawWritingWindow drawWritingWindow = new DrawWritingWindow(); + final DrawWritingWindow drawWritingWindow = new DrawWritingWindow(); } ///*------------------------------------------------------------------------ @@ -64,117 +67,118 @@ String textToWrite = ""; String spriteFilePrefix = "sprite/let"; String spriteFileSuffix = ".txt"; public class DrawWritingWindow extends ControlFrame { - public DrawWritingWindow() { - super(parentPapplet, 450, 250); - int xPos = 100; - int yPos = 100; - String name = DRAW_WRITING_WINDOW_NAME; + public DrawWritingWindow() { + super(parentPapplet, 450, 250); + int xPos = 100; + int yPos = 100; + String name = DRAW_WRITING_WINDOW_NAME; - final Frame f = new Frame(name); - f.add(this); - this.init(); - f.setTitle(name); - f.setSize(super.w, super.h); - f.setLocation(xPos, yPos); - f.setResizable(false); - f.setVisible(true); + final Frame f = new Frame(name); + f.add(this); + this.init(); + f.setTitle(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(); - } - }); - Textfield spriteFileField = cp5().addTextfield("spriteFilePrefixField",20,20,150,20) - .setText(getSpriteFilePrefix()) - .setLabel("File prefix") - .plugTo("spriteFilePrefixField"); + f.addWindowListener( new WindowAdapter() { + @Override + public void windowClosing(WindowEvent we) { + f.dispose(); + } + } + ); + Textfield spriteFileField = cp5().addTextfield("spriteFilePrefixField", 20, 20, 150, 20) + .setText(getSpriteFilePrefix()) + .setLabel("File prefix") + .plugTo("spriteFilePrefixField"); - Textfield writingField = cp5().addTextfield("textToWriteField",20,60,400,20) - .setText(getTextToWrite()) - .setLabel("Text to write") - .plugTo("textToWriteField"); + Textfield writingField = cp5().addTextfield("textToWriteField", 20, 60, 400, 20) + .setText(getTextToWrite()) + .setLabel("Text to write") + .plugTo("textToWriteField"); - Button importTextButton = cp5().addButton("importTextButton",0,20,100,120,20) - .setLabel("Load text from file") - .plugTo("importTextButton"); + Button importTextButton = cp5().addButton("importTextButton", 0, 20, 100, 120, 20) + .setLabel("Load text from file") + .plugTo("importTextButton"); - RadioButton rPos = cp5().addRadioButton("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.plugTo("radio_drawWritingDirection"); + RadioButton rPos = cp5().addRadioButton("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.plugTo("radio_drawWritingDirection"); - Button submitButton = cp5.addButton("submitWritingWindow",0,300,100,120,20) - .setLabel("Generate commands") - .plugTo("submitWritingWindow"); - } + Button submitButton = cp5.addButton("submitWritingWindow", 0, 300, 100, 120, 20) + .setLabel("Generate commands") + .plugTo("submitWritingWindow"); + } - void spriteFilePrefixField(String value) { - spriteFilePrefix = value; - } - void textToWriteField(String value) { - textToWrite = value; - } + void spriteFilePrefixField(String value) { + spriteFilePrefix = value; + } + void textToWriteField(String value) { + textToWrite = value; + } - String getTextToWrite() { - return textToWrite; - } - String getSpriteFilePrefix() { - return spriteFilePrefix; - } - String getSpriteFileSuffix() { - return spriteFileSuffix; - } + String getTextToWrite() { + return textToWrite; + } + String getSpriteFilePrefix() { + return spriteFilePrefix; + } + String getSpriteFileSuffix() { + return spriteFileSuffix; + } - void importTextButton() { - println("Text!"); - selectInput("Select the text file to load the text from:", "importTextToWriteFromFile", null, this); - } - - public void importTextToWriteFromFile(File selection) { - if (selection != null) { - String fp = selection.getAbsolutePath(); - println("Input file: " + fp); - List rows = java.util.Arrays.asList(loadStrings(fp)); - StringBuilder sb = new StringBuilder(200); - for (String row : rows) { - sb.append(row); - } - textToWriteField(sb.toString()); - println("Completed text import, " + getTextToWrite().length() + " characters found."); - - println("Text: " + getTextToWrite()); - - Textfield tf = cp5().get(Textfield.class, "textToWriteField"); - tf.setText(getTextToWrite()); - tf.submit(); - } - } + void importTextButton() { + println("Text!"); + selectInput("Select the text file to load the text from:", "importTextToWriteFromFile", null, this); + } - void submitWritingWindow(int theValue) - { - println("Write."); - - Textfield tf = cp5().get(Textfield.class, "spriteFilePrefixField"); - tf.submit(); - tf.setText(getSpriteFilePrefix()); - - Textfield wf = cp5.get(Textfield.class, "textToWriteField"); - wf.submit(); - wf.setText(getTextToWrite()); - - println("Start dir: " + renderStartDirection); - println("Sprite file prefix: " + spriteFilePrefix); - println("Text: " + textToWrite); + public void importTextToWriteFromFile(File selection) { + if (selection != null) { + String fp = selection.getAbsolutePath(); + println("Input file: " + fp); + List rows = java.util.Arrays.asList(loadStrings(fp)); + StringBuilder sb = new StringBuilder(200); + for (String row : rows) { + sb.append(row); + } + textToWriteField(sb.toString()); + println("Completed text import, " + getTextToWrite().length() + " characters found."); - for (int i=0; i Date: Sat, 5 Sep 2015 18:33:45 +0100 Subject: [PATCH 09/13] Norwegian pixel dialog working. --- controlsActionsWindows.pde | 366 +++++++++++++++++++++---------------- controlsSetup.pde | 8 +- polargraphcontroller.pde | 3 + 3 files changed, 216 insertions(+), 161 deletions(-) diff --git a/controlsActionsWindows.pde b/controlsActionsWindows.pde index 877bb9f..169081b 100644 --- a/controlsActionsWindows.pde +++ b/controlsActionsWindows.pde @@ -43,101 +43,124 @@ void button_mode_serialPortDialog() { void button_mode_machineStoreDialog() { ControlFrameSimple cf = addMachineStoreControlFrame("Machine Store", 450, 250, 20, 240, color( 100 ) ); -// final MachineStoreWindow machineStoreWindow = new MachineStoreWindow(); } void button_mode_machineExecDialog() { ControlFrameSimple cf = addMachineExecControlFrame("Machine Execute", 450, 250, 20, 240, color( 100 ) ); -// final MachineExecWindow machineExecWindow = new MachineExecWindow(); } void button_mode_drawPixelsDialog() { ControlFrameSimple cf = addDrawPixelsControlFrame("Render pixels", 450, 250, 20, 240, color( 100 ) ); -// final DrawPixelsWindow drawPixelsWindow = new DrawPixelsWindow(); } void button_mode_drawWritingDialog() { - final DrawWritingWindow drawWritingWindow = new DrawWritingWindow(); + ControlFrameSimple cf = addSpriteWritingControlFrame("Sprite Writing", 450, 250, 20, 240, color( 100 ) ); +} + +void button_mode_drawNorwegianDialog() { + ControlFrameSimple cf = addNorwegianPixelControlFrame("Norwegian Pixel", 450, 250, 20, 240, color( 100 ) ); } ///*------------------------------------------------------------------------ // Details about the "writing" subwindow //------------------------------------------------------------------------*/ -String textToWrite = ""; -String spriteFilePrefix = "sprite/let"; -String spriteFileSuffix = ".txt"; -public class DrawWritingWindow extends ControlFrame { - public DrawWritingWindow() { - super(parentPapplet, 450, 250); - int xPos = 100; - int yPos = 100; - String name = DRAW_WRITING_WINDOW_NAME; - final Frame f = new Frame(name); - f.add(this); - this.init(); - f.setTitle(name); - f.setSize(super.w, super.h); - f.setLocation(xPos, yPos); - f.setResizable(false); - f.setVisible(true); +String spriteWriting_textToWrite = ""; +String spriteWriting_spriteFilePrefix = "sprite/let"; +String spriteWriting_spriteFileSuffix = ".txt"; - f.addWindowListener( new WindowAdapter() { - @Override - public void windowClosing(WindowEvent we) { - f.dispose(); - } +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); } - ); - Textfield spriteFileField = cp5().addTextfield("spriteFilePrefixField", 20, 20, 150, 20) - .setText(getSpriteFilePrefix()) + } + ); + 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) { + } + + cp5s.put(DRAW_WRITING_WINDOW_NAME, p.cp5()); + println(cp5s); + + // set up controls + Textfield spriteFileField = p.cp5().addTextfield("spriteWriting_spriteFilePrefixField", 20, 20, 150, 20) + .setText(spriteWriting_getSpriteFilePrefix()) .setLabel("File prefix") - .plugTo("spriteFilePrefixField"); + .plugTo(this, "spriteWriting_spriteFilePrefixField"); - Textfield writingField = cp5().addTextfield("textToWriteField", 20, 60, 400, 20) - .setText(getTextToWrite()) + Textfield writingField = p.cp5().addTextfield("spriteWriting_textToWriteField", 20, 60, 400, 20) + .setText(spriteWriting_getTextToWrite()) .setLabel("Text to write") - .plugTo("textToWriteField"); + .plugTo(this, "spriteWriting_textToWriteField"); - Button importTextButton = cp5().addButton("importTextButton", 0, 20, 100, 120, 20) + Button importTextButton = p.cp5().addButton("spriteWriting_importTextButton", 0, 20, 100, 120, 20) .setLabel("Load text from file") - .plugTo("importTextButton"); - - RadioButton rPos = cp5().addRadioButton("radio_drawWritingDirection", 20, 140); - // rPos.add("North-east", DRAW_DIR_NE); + .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.add("South-west", DRAW_DIR_SW); - // rPos.add("North-west", DRAW_DIR_NW); - rPos.plugTo("radio_drawWritingDirection"); + rPos.activate("South-east"); + rPos.plugTo(this, "spriteWriting_radio_drawWritingDirection"); - Button submitButton = cp5.addButton("submitWritingWindow", 0, 300, 100, 120, 20) + Button submitButton = p.cp5.addButton("spriteWriting_submitWritingWindow", 0, 300, 100, 120, 20) .setLabel("Generate commands") - .plugTo("submitWritingWindow"); + .addListener( new ControlListener() { + public void controlEvent( ControlEvent ev ) { + spriteWriting_submitWritingWindow(p.cp5()); + } + }); + + + return p; +} + + + + void spriteWriting_spriteFilePrefixField(String value) { + spriteWriting_spriteFilePrefix = value; + } + void spriteWriting_textToWriteField(String value) { + spriteWriting_textToWrite = value; + } + String spriteWriting_getTextToWrite() { + return spriteWriting_textToWrite; + } + String spriteWriting_getSpriteFilePrefix() { + return spriteWriting_spriteFilePrefix; + } + String spriteWriting_getSpriteFileSuffix() { + return spriteWriting_spriteFileSuffix; } - void spriteFilePrefixField(String value) { - spriteFilePrefix = value; - } - void textToWriteField(String value) { - textToWrite = value; + void spriteWriting_importTextButton() { + println("Text being imported!"); + selectInput("Select the text file to load the text from:", + "spriteWriting_importTextToWriteFromFile"); } - String getTextToWrite() { - return textToWrite; - } - String getSpriteFilePrefix() { - return spriteFilePrefix; - } - String getSpriteFileSuffix() { - return spriteFileSuffix; - } - - void importTextButton() { - println("Text!"); - selectInput("Select the text file to load the text from:", "importTextToWriteFromFile", null, this); - } - - public void importTextToWriteFromFile(File selection) { + public void spriteWriting_importTextToWriteFromFile(File selection) { if (selection != null) { String fp = selection.getAbsolutePath(); println("Input file: " + fp); @@ -146,50 +169,47 @@ public class DrawWritingWindow extends ControlFrame { for (String row : rows) { sb.append(row); } - textToWriteField(sb.toString()); - println("Completed text import, " + getTextToWrite().length() + " characters found."); + spriteWriting_textToWriteField(sb.toString()); + println("Completed text import, " + spriteWriting_getTextToWrite().length() + " characters found."); - println("Text: " + getTextToWrite()); + println("Text: " + spriteWriting_getTextToWrite()); + + println(cp5s); - Textfield tf = cp5().get(Textfield.class, "textToWriteField"); - tf.setText(getTextToWrite()); - tf.submit(); + 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 submitWritingWindow(int theValue) + void spriteWriting_submitWritingWindow(ControlP5 parent) { println("Write."); - Textfield tf = cp5().get(Textfield.class, "spriteFilePrefixField"); + Textfield tf = parent.get(Textfield.class, "spriteWriting_spriteFilePrefixField"); tf.submit(); - tf.setText(getSpriteFilePrefix()); + tf.setText(spriteWriting_getSpriteFilePrefix()); - Textfield wf = cp5.get(Textfield.class, "textToWriteField"); + Textfield wf = parent.get(Textfield.class, "spriteWriting_textToWriteField"); wf.submit(); - wf.setText(getTextToWrite()); + wf.setText(spriteWriting_getTextToWrite()); println("Start dir: " + renderStartDirection); - println("Sprite file prefix: " + spriteFilePrefix); - println("Text: " + textToWrite); + println("Sprite file prefix: " + spriteWriting_spriteFilePrefix); + println("Text: " + spriteWriting_textToWrite); - for (int i=0; i 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_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); diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index aa9f171..4d81a6a 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -59,6 +59,9 @@ int buildNo = 0; String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo; ControlP5 cp5; +Map cp5s = new HashMap(); + + boolean drawbotReady = false; boolean drawbotConnected = false; From 6510da9a45bdb09582c3054eb3a60896529b5318 Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Sat, 5 Sep 2015 22:02:43 +0100 Subject: [PATCH 10/13] All done for processing v2 --- ControlFrameSimple.pde | 40 ++++++++ MachineStoreWindow.pde | 55 ----------- controlsActions.pde | 2 +- controlsActionsWindows.pde | 183 ++++++++++++++++++++----------------- polargraphcontroller.pde | 10 +- 5 files changed, 146 insertions(+), 144 deletions(-) create mode 100644 ControlFrameSimple.pde 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/MachineStoreWindow.pde b/MachineStoreWindow.pde index 960c966..958ff3d 100644 --- a/MachineStoreWindow.pde +++ b/MachineStoreWindow.pde @@ -1,61 +1,6 @@ /*------------------------------------------------------------------------ Details about the "machine store" subwindow ------------------------------------------------------------------------*/ -class MachineStoreWindow extends ControlFrame { - - void storeFilename(String filename) { - println("Filename event: "+ filename); - if (filename != null && filename.length() <= 12) { - setStoreFilename(filename); - sendMachineStoreMode(); - } - } - - - - void submitStoreFilenameWindow(int theValue) { - cp5().get(Textfield.class, "storeFilename").submit(); - } - - public MachineStoreWindow() { - super(parentPapplet, 450, 150); - int xPos = 100; - int yPos = 100; - String name = MACHINE_STORE_WINDOW_NAME; - - final Frame f = new Frame(name); - f.add(this); - this.init(); - f.setTitle(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(); - } - }); - - Textfield filenameField = cp5().addTextfield("storeFilename",20,20,150,20) - .setText(getStoreFilename()) - .setLabel("Filename to store to") - .plugTo("storeFilename"); - - Button submitButton = cp5().addButton("submitStoreFilenameWindow",0,180,20,60,20) - .setLabel("Submit") - .plugTo("submitStoreFilenameWindow"); - - Toggle overwriteToggle = cp5().addToggle("toggleAppendToFile",true,180,50,20,20) - .setCaptionLabel("Overwrite existing file") - .plugTo("toggleAppendToFile"); - - filenameField.setFocus(true); - } -} - ControlFrameSimple addMachineStoreControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) { final Frame f = new Frame( theName ); diff --git a/controlsActions.pde b/controlsActions.pde index 49234c0..63a2329 100644 --- a/controlsActions.pde +++ b/controlsActions.pde @@ -722,7 +722,7 @@ void button_mode_sendButtonDeactivate() void numberbox_mode_previewCordOffsetValue(int value) { previewCordOffset = value; - previewQueue(); + previewQueue(true); } diff --git a/controlsActionsWindows.pde b/controlsActionsWindows.pde index 169081b..0781e86 100644 --- a/controlsActionsWindows.pde +++ b/controlsActionsWindows.pde @@ -57,6 +57,10 @@ void button_mode_drawWritingDialog() { ControlFrameSimple cf = addSpriteWritingControlFrame("Sprite Writing", 450, 250, 20, 240, color( 100 ) ); } +void button_mode_RandomSpriteDialog() { + ControlFrameSimple cf = addRandomSpriteControlFrame("Random Sprite", 450, 250, 20, 240, color( 100 ) ); +} + void button_mode_drawNorwegianDialog() { ControlFrameSimple cf = addNorwegianPixelControlFrame("Norwegian Pixel", 450, 250, 20, 240, color( 100 ) ); } @@ -213,87 +217,100 @@ ControlFrameSimple addSpriteWritingControlFrame(String theName, int theWidth, in ///*------------------------------------------------------------------------ // Details about the "sprite" subwindow //------------------------------------------------------------------------*/ -//String spriteFilename; -//int minSpriteSize = 100; -//int maxSpriteSize = 500; -// -//void button_mode_drawSpriteDialog() -//{ -// this.dialogWindow = cp5.addControlWindow("drawSpriteWindow",100,100,450,200); -// dialogWindow.hideCoordinates(); -// -// dialogWindow.setBackground(getBackgroundColour()); -// -// delay(200); -// Textfield spriteFilenameField = cp5.addTextfield("spriteFilenameField",20,20,400,20); -// spriteFilenameField.setText("filename.txt"); -// spriteFilenameField.setLabel("Sprite filename"); -// spriteFilenameField.setWindow(dialogWindow); -// -// Numberbox minSizeField = cp5.addNumberbox("minimumSpriteSize",20,60,100,20); -// minSizeField.setValue(getMinimumSpriteSize()); -// minSizeField.setMin(10); -// minSizeField.setMax(getMaximumSpriteSize()); -// minSizeField.setMultiplier(0.5); -// minSizeField.setLabel("Minimum size"); -// minSizeField.setWindow(dialogWindow); -// -// Numberbox maxSizeField = cp5.addNumberbox("maximumSpriteSize",20,100,100,20); -// maxSizeField.setValue(getMaximumSpriteSize()); -// maxSizeField.setMin(getMinimumSpriteSize()); -// maxSizeField.setMultiplier(0.5); -// maxSizeField.setLabel("Maximum size"); -// maxSizeField.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("submitSpriteWindow",0,300,100,120,20); -// submitButton.setLabel("Draw sprite"); -// submitButton.setWindow(dialogWindow); -//} -// -//void radio_drawWritingDirection(int dir) -//{ -// renderStartDirection = dir; -//} -// -//String getSpriteFilename() -//{ -// return spriteFilename; -//} -//int getMinimumSpriteSize() -//{ -// return minSpriteSize; -//} -//int getMaximumSpriteSize() -//{ -// return maxSpriteSize; -//} -// -//void submitSpriteWindow(int theValue) -//{ -// println("Sprite."); -// -// Textfield tf = (Textfield) cp5.controller("spriteFilenameField"); -// tf.submit(); -// tf.setText(getSpriteFilename()); -// -// println("Start dir: " + renderStartDirection); -// println("Filename: " + spriteFilename); -// -// addToCommandQueue(CMD_DRAW_SPRITE + "," + spriteFilename + "," -// + getMinimumSpriteSize() + "," + getMaximumSpriteSize() + "," + renderStartDirection + ",END"); -// -//} -// -// +String sprite_spriteFilename; +int sprite_minSpriteSize = 100; +int sprite_maxSpriteSize = 500; + +ControlFrameSimple addRandomSpriteControlFrame(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 spriteFilenameField = p.cp5().addTextfield("sprite_spriteFilenameField",20,20,400,20) + .setText("filename.txt") + .setLabel("Sprite filename") + .plugTo(this, "sprite_spriteFilenameField"); + + Numberbox minSizeField = p.cp5().addNumberbox("sprite_minimumSpriteSize",20,60,100,20) + .setValue(sprite_getMinimumSpriteSize()) + .setMin(10) + .setMax(sprite_getMaximumSpriteSize()) + .setMultiplier(0.5) + .setLabel("Minimum size") + .plugTo(this, "sprite_minimumSpriteSize"); + + Numberbox maxSizeField = p.cp5().addNumberbox("sprite_maximumSpriteSize",20,100,100,20) + .setValue(sprite_getMaximumSpriteSize()) + .setMin(sprite_getMinimumSpriteSize()) + .setMultiplier(0.5) + .setLabel("Maximum size") + .plugTo(this, "sprite_maximumSpriteSize"); + + Button submitButton = p.cp5().addButton("sprite_submitSpriteWindow",0,300,100,120,20) + .setLabel("Draw sprite") + .addListener( new ControlListener() { + public void controlEvent( ControlEvent ev ) { + spriteWriting_submitWritingWindow(p.cp5()); + } + }); + + spriteFilenameField.setFocus(true); + + return p; +} + +String sprite_getSpriteFilename() +{ + return sprite_spriteFilename; +} +int sprite_getMinimumSpriteSize() +{ + return sprite_minSpriteSize; +} +int sprite_getMaximumSpriteSize() +{ + return sprite_maxSpriteSize; +} + +void sprite_submitSpriteWindow(Textfield tf) +{ + println("Sprite."); + + tf.submit(); + tf.setText(sprite_getSpriteFilename()); + + println("Filename: " + sprite_getSpriteFilename()); + + addToCommandQueue(CMD_DRAW_SPRITE + "," + sprite_getSpriteFilename() + "," + + sprite_getMinimumSpriteSize() + "," + sprite_getMaximumSpriteSize() + "," + DRAW_DIR_NE + ",END"); + +} + + ///*------------------------------------------------------------------------ // Details about the "norwegian draw" subwindow //------------------------------------------------------------------------*/ @@ -315,7 +332,6 @@ ControlFrameSimple addNorwegianPixelControlFrame(String theName, int theWidth, i public void windowClosing(WindowEvent we) { p.dispose(); f.dispose(); - cp5s.remove(DRAW_WRITING_WINDOW_NAME); } } ); @@ -329,9 +345,6 @@ ControlFrameSimple addNorwegianPixelControlFrame(String theName, int theWidth, i catch(Exception e) { } - cp5s.put(DRAW_WRITING_WINDOW_NAME, p.cp5()); - println(cp5s); - // set up controls Textfield filenameField = p.cp5().addTextfield("norwegian_execFilename",20,20,150,20) .setText(norwegian_execFilename) diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index 4d81a6a..cca1874 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -590,6 +590,7 @@ void setup() addEventListeners(); //gamepad_init(); + frameRate(8); } void addEventListeners() { @@ -1730,11 +1731,14 @@ 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() +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(); From f27d625cc2681ecdd7f1bb567e7b3d75c7be1192 Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Sun, 13 Sep 2015 18:07:56 +0100 Subject: [PATCH 11/13] Cleaned up a little. --- controlsSetup.pde | 6 +- gamepad.pde | 234 --------------------------------------- polargraphcontroller.pde | 30 ++--- 3 files changed, 10 insertions(+), 260 deletions(-) delete mode 100644 gamepad.pde diff --git a/controlsSetup.pde b/controlsSetup.pde index 8295b5e..0e77554 100644 --- a/controlsSetup.pde +++ b/controlsSetup.pde @@ -1076,9 +1076,9 @@ Set buildControlNames() // 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_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/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 cca1874..a7aeeb2 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -55,7 +55,7 @@ import java.lang.reflect.Method; int majorVersionNo = 2; int minorVersionNo = 0; -int buildNo = 0; +int buildNo = 3; String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo; ControlP5 cp5; @@ -539,7 +539,10 @@ void setup() } loadFromPropertiesFile(); - size(windowWidth, windowHeight, JAVA2D ); +// size(400, 400, JAVA2D ); +// surface.setResizable(true); +// surface.setSize(windowWidth, windowHeight); + size(windowWidth, windowHeight, JAVA2D); this.cp5 = new ControlP5(this); initTabs(); @@ -589,7 +592,6 @@ void setup() addEventListeners(); - //gamepad_init(); frameRate(8); } void addEventListeners() @@ -604,7 +606,8 @@ void addEventListeners() } } } - ); + ); + addMouseWheelListener(new java.awt.event.MouseWheelListener() { public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) @@ -3096,25 +3099,6 @@ void initLogging() } } -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) { From 7f2421f0d869050174ac00d94b2b97f2d339a788 Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Sun, 13 Sep 2015 18:39:52 +0100 Subject: [PATCH 12/13] Update README.md --- README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index f4eace0..eb8137d 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,9 @@ polargraphcontroller Polargraph controller Copyright Sandy Noble 2015. -*** THIS VERSION IS UNDER DEVELOPMENT! *** -========================================== - -This branch is being migrated to v2x of Processing, and modern versions of the libraries. - - Requires the excellent ControlP5 GUI library available from https://github.com/sojamo/controlp5. - Requires the excellent Geomerative library available from http://www.ricardmarxer.com/geomerative/. -- Somewhat running on Processing v2.2.1. +- Running on Processing v2.2.1. This is a desktop application for controlling a polargraph machine, communicating using ASCII command language over a serial link. From 87e11f6b93d9f455fb0f91345d350a886ce34181 Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Sat, 10 Oct 2015 10:31:40 +0100 Subject: [PATCH 13/13] Removing initImages() from setup(), duh --- polargraphcontroller.pde | 2 -- 1 file changed, 2 deletions(-) diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index a7aeeb2..f7f6db0 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -524,8 +524,6 @@ void setup() initLogging(); parentPapplet = this; - initImages(); - RG.init(this); RG.setPolygonizer(RG.ADAPTATIVE);