Updated a bunch of stuff to make it compile and run in Processing v2

This commit is contained in:
Sandy Noble 2015-04-26 12:13:35 +01:00
parent 111a9b9478
commit cb4fa89674
12 changed files with 1058 additions and 923 deletions

46
ControlFrame.pde Normal file
View File

@ -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);
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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 <http://www.gnu.org/licenses/>.
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
{

View File

@ -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
*/
/**
*

402
Misc.pde
View File

@ -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<fontNames.length;n++) System.out.println(fontNames[n]);
// // Testing part: simple an error thrown anywhere in this JVM will be printed on the Console
// // We do it with a seperate Thread becasue we don't wan't to break a Thread used by the Console.
// System.out.println("\nLets throw an error on this console");
// errorThrower=new Thread(this);
// errorThrower.setDaemon(true);
// errorThrower.start();
}
public synchronized void windowClosed(WindowEvent evt)
{
quit=true;
this.notifyAll(); // stop all threads
try {
reader.join(1000);
pin.close();
System.setOut(this.cOut);
}
catch (Exception e){
}
try {
reader2.join(1000);
pin2.close();
System.setErr(this.cErr);
}
catch (Exception e){
}
// System.exit(0);
}
public synchronized void windowClosing(WindowEvent evt)
{
frame.setVisible(false); // default behaviour of JFrame
frame.dispose();
}
public synchronized void actionPerformed(ActionEvent evt)
{
textArea.setText("");
}
public synchronized void run()
{
try
{
while (Thread.currentThread()==reader)
{
try {
this.wait(100);
}
catch(InterruptedException ie) {
}
if (pin.available()!=0)
{
String input=this.readLine(pin);
textArea.append(input);
textArea.setCaretPosition(textArea.getDocument().getLength());
}
if (quit) return;
}
while (Thread.currentThread()==reader2)
{
try {
this.wait(100);
}
catch(InterruptedException ie) {
}
if (pin2.available()!=0)
{
String input=this.readLine(pin2);
textArea.append(input);
textArea.setCaretPosition(textArea.getDocument().getLength());
}
if (quit) return;
}
}
catch (Exception e)
{
textArea.append("\nConsole reports an Internal error.");
textArea.append("The error is: "+e);
}
}
public void close()
{
this.windowClosing(null);
}
public synchronized String readLine(PipedInputStream in) throws IOException
{
String input="";
do
{
int available=in.available();
if (available==0) break;
byte b[]=new byte[available];
in.read(b);
input=input+new String(b,0,b.length);
}
while( !input.endsWith("\n") && !input.endsWith("\r\n") && !quit);
return input;
}
}
//
//
//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<fontNames.length;n++) System.out.println(fontNames[n]);
//// // Testing part: simple an error thrown anywhere in this JVM will be printed on the Console
//// // We do it with a seperate Thread becasue we don't wan't to break a Thread used by the Console.
//// System.out.println("\nLets throw an error on this console");
//// errorThrower=new Thread(this);
//// errorThrower.setDaemon(true);
//// errorThrower.start();
// }
//
// public synchronized void windowClosed(WindowEvent evt)
// {
// quit=true;
// this.notifyAll(); // stop all threads
// try {
// reader.join(1000);
// pin.close();
// System.setOut(this.cOut);
// }
// catch (Exception e){
// }
// try {
// reader2.join(1000);
// pin2.close();
// System.setErr(this.cErr);
// }
// catch (Exception e){
// }
//// System.exit(0);
// }
//
// public synchronized void windowClosing(WindowEvent evt)
// {
// frame.setVisible(false); // default behaviour of JFrame
// frame.dispose();
// }
//
// public synchronized void actionPerformed(ActionEvent evt)
// {
// textArea.setText("");
// }
//
// public synchronized void run()
// {
// try
// {
// while (Thread.currentThread()==reader)
// {
// try {
// this.wait(100);
// }
// catch(InterruptedException ie) {
// }
// if (pin.available()!=0)
// {
// String input=this.readLine(pin);
// textArea.append(input);
// textArea.setCaretPosition(textArea.getDocument().getLength());
//
// }
// if (quit) return;
// }
//
// while (Thread.currentThread()==reader2)
// {
// try {
// this.wait(100);
// }
// catch(InterruptedException ie) {
// }
// if (pin2.available()!=0)
// {
// String input=this.readLine(pin2);
// textArea.append(input);
// textArea.setCaretPosition(textArea.getDocument().getLength());
//
// }
// if (quit) return;
// }
// }
// catch (Exception e)
// {
// textArea.append("\nConsole reports an Internal error.");
// textArea.append("The error is: "+e);
// }
// }
//
// public void close()
// {
// this.windowClosing(null);
// }
//
// public synchronized String readLine(PipedInputStream in) throws IOException
// {
// String input="";
// do
// {
// int available=in.available();
// if (available==0) break;
// byte b[]=new byte[available];
// in.read(b);
// input=input+new String(b,0,b.length);
// }
// while( !input.endsWith("\n") && !input.endsWith("\r\n") && !quit);
// return input;
// }
//}

View File

@ -120,9 +120,9 @@ class Panel
public void draw()
{
// stroke(outlineColour);
// strokeWeight(2);
// rect(getOutline().getLeft(), getOutline().getTop(), getOutline().getWidth(), getOutline().getHeight());
//stroke(outlineColour);
//strokeWeight(2);
//rect(getOutline().getLeft(), getOutline().getTop(), getOutline().getWidth(), getOutline().getHeight());
drawControls();
}
@ -131,13 +131,13 @@ class Panel
{
for (Controller c : this.getControls())
{
//println("Control: " + c.name());
PVector pos = getControlPositions().get(c.name());
// println("Control: " + c.getName());
PVector pos = getControlPositions().get(c.getName());
float x = pos.x+getOutline().getLeft();
float y = pos.y+getOutline().getTop();
c.setPosition(x, y);
PVector cSize = getControlSizes().get(c.name());
PVector cSize = getControlSizes().get(c.getName());
c.setSize((int)cSize.x, (int)cSize.y);
boolean locked = false;
@ -146,32 +146,32 @@ class Panel
// any drawing / extracting controls are disabled if there is no selec
// box specified.
if (getControlsToLockIfBoxNotSpecified().contains(c.name()) && !isBoxSpecified())
if (getControlsToLockIfBoxNotSpecified().contains(c.getName()) && !isBoxSpecified())
{
locked = true;
}
// if there is no vector shape loaded then lock the "draw vector"
// control.
if (c.name().equals(MODE_RENDER_VECTORS) && getVectorShape() == null)
if (c.getName().equals(MODE_RENDER_VECTORS) && getVectorShape() == null)
{
locked = true;
}
// if there's no image loaded, then hide resizing/moving
if (getControlsToLockIfImageNotLoaded().contains(c.name()) && getDisplayMachine().getImage() == null)
if (getControlsToLockIfImageNotLoaded().contains(c.getName()) && getDisplayMachine().getImage() == null)
{
locked = true;
}
if (c.name().equals(MODE_LOAD_VECTOR_FILE))
if (c.getName().equals(MODE_LOAD_VECTOR_FILE))
{
if (getVectorShape() != null)
c.setLabel("Clear vector");
else
c.setLabel("Load vector");
}
else if (c.name().equals(MODE_LOAD_IMAGE))
else if (c.getName().equals(MODE_LOAD_IMAGE))
{
if (getDisplayMachine().getImage() != null)
c.setLabel("Clear image");
@ -231,6 +231,4 @@ class Panel
this.getOutline().setWidth(right);
}
}
}

View File

@ -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 Rectangle
{
@ -122,4 +122,8 @@ class Rectangle
return false;
}
public String toString() {
return new StringBuffer().append("Rectangle pos: ").append(this.getPosition()).append(", size: ").append(this.getSize()).append(".").toString();
}
}

View File

@ -1,6 +1,6 @@
/**
Polargraph controller
Copyright Sandy Noble 2012.
Copyright Sandy Noble 2015.
This file is part of Polargraph Controller.
@ -24,9 +24,9 @@
sandy.noble@gmail.com
http://www.polargraph.co.uk/
http://code.google.com/p/polargraph/
https://github.com/euphy/polargraphcontroller
*/
void button_mode_begin()
void button_mode_begin()
{
button_mode_clearQueue();
}
@ -719,4 +719,10 @@ void button_mode_sendButtonDeactivate()
addToCommandQueue(CMD_DEACTIVATE_MACHINE_BUTTON+",END");
}
void numberbox_mode_previewCordOffsetValue(int value)
{
previewCordOffset = value;
previewQueue();
}

File diff suppressed because it is too large Load Diff

View File

@ -1,82 +1,73 @@
/**
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 <http://www.gnu.org/licenses/>.
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<String> 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 <http://www.gnu.org/licenses/>.
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<String> getPanelNames() {
if (this.panelNames == null)
this.panelNames = buildPanelNames();
return this.panelNames;
}
List<String> getTabNames()
{
List<String> getTabNames() {
if (this.tabNames == null)
this.tabNames = buildTabNames();
return this.tabNames;
}
Set<String> getControlNames()
{
Set<String> getControlNames() {
if (this.controlNames == null)
this.controlNames = buildControlNames();
return this.controlNames;
}
Map<String, List<Controller>> getControlsForPanels()
{
Map<String, List<Controller>> getControlsForPanels() {
if (this.controlsForPanels == null)
this.controlsForPanels = buildControlsForPanels();
return this.controlsForPanels;
}
Map<String, Controller> getAllControls()
{
Map<String, Controller> getAllControls() {
if (this.allControls == null)
this.allControls = buildAllControls();
return this.allControls;
}
Map<String, String> getControlLabels()
{
Map<String, String> getControlLabels() {
if (this.controlLabels == null)
this.controlLabels = buildControlLabels();
return this.controlLabels;
}
Map<String, Set<Panel>> getPanelsForTabs()
{
Map<String, Set<Panel>> getPanelsForTabs() {
if (this.panelsForTabs == null)
this.panelsForTabs = buildPanelsForTabs();
return this.panelsForTabs;
}
Map<String, Panel> getPanels()
{
Map<String, Panel> getPanels() {
if (this.panels == null)
this.panels = buildPanels();
return this.panels;
}
Set<String> getControlsToLockIfBoxNotSpecified()
{
Set<String> getControlsToLockIfBoxNotSpecified() {
if (this.controlsToLockIfBoxNotSpecified == null)
{
this.controlsToLockIfBoxNotSpecified = buildControlsToLockIfBoxNotSpecified();
@ -84,8 +75,7 @@ Set<String> getControlsToLockIfBoxNotSpecified()
return this.controlsToLockIfBoxNotSpecified;
}
Set<String> getControlsToLockIfImageNotLoaded()
{
Set<String> getControlsToLockIfImageNotLoaded() {
if (this.controlsToLockIfImageNotLoaded == null)
{
this.controlsToLockIfImageNotLoaded = buildControlsToLockIfImageNotLoaded();
@ -93,9 +83,7 @@ Set<String> 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<String, Panel> buildPanels()
{
Map<String, Panel> buildPanels() {
Map<String, Panel> panels = new HashMap<String, Panel>();
float panelHeight = frame.getHeight() - getMainPanelPosition().y - (DEFAULT_CONTROL_SIZE.y*3);
@ -121,7 +108,7 @@ Map<String, Panel> 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<String, Panel> 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<String, Panel> 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<String, Panel> 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<String, Panel> 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<String, Controller> 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<String, Controller> 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<String, Controller> 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<String, Controller> initialiseNumberboxValues(Map<String, Controller> 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<String, Controller> initialiseToggleValues(Map<String, Controller> map)
return map;
}
String getControlLabel(String butName)
{
if (controlLabels.containsKey(butName))
@ -574,10 +564,10 @@ Map<String, PVector> 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<String, PVector> 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<String, PVector> buildControlPositionsForPanel(Panel panel)
}
}
}
return map;
}
Map<String, PVector> buildControlSizesForPanel(Panel panel)
{
//println("Building control sizes for panel " + panel.getName());
@ -609,16 +599,16 @@ Map<String, PVector> 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<String> 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<String> 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<String, String> 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<String> buildControlNames()
result.add(MODE_SEND_BUTTON_ACTIVATE);
result.add(MODE_SEND_BUTTON_DEACTIVATE);
result.add(MODE_ADJUST_PREVIEW_CORD_OFFSET);
return result;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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 <http://www.gnu.org/licenses/>.
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,";

View File

@ -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<String> controlsToLockIfImageNotLoaded = null;
public Map<String, Set<Panel>> panelsForTabs = null;
public Map<String, Panel> panels = null;
public Map<String, ControlFrame> controlFrames = new HashMap<String, ControlFrame>();
// 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<controlEvent.group().arrayValue().length; i++)
for (int i=0; i<controlEvent.group().getArrayValue().length; i++)
{
int n = (int)controlEvent.group().arrayValue()[i];
int n = (int)controlEvent.group().getArrayValue()[i];
}
println();
}
}
}
void changeTab(String from, String to)
{
// hide old panels
currentTab = to;
for (Panel panel : getPanelsForTab(currentTab))
@ -1262,7 +1263,6 @@ void changeTab(String from, String to)
c.show();
}
}
}
@ -1334,8 +1334,12 @@ boolean mouseOverPanel()
boolean result = false;
for (Panel panel : getPanelsForTab(currentTab))
{
if (panel.getOutline().surrounds(getMouseVector()))
if (panel.getOutline().surrounds(getMouseVector())) {
println("Outline: " + panel.getOutline().toString());
println("OVER PANEL!" + panel.getName());
result = true;
break;
}
}
return result;
}
@ -1745,7 +1749,7 @@ void previewQueue()
String aLenStr = splitted[1];
String bLenStr = splitted[2];
PVector endPoint = new PVector(Integer.parseInt(aLenStr), Integer.parseInt(bLenStr));
PVector endPoint = new PVector(Integer.parseInt(aLenStr)+previewCordOffset, Integer.parseInt(bLenStr)+previewCordOffset);
endPoint = getDisplayMachine().asCartesianCoords(endPoint);
endPoint = getDisplayMachine().inMM(endPoint);
@ -1834,8 +1838,8 @@ void exportQueueToFile()
{
if (!commandQueue.isEmpty() || !realtimeCommandQueue.isEmpty())
{
String savePath = selectOutput(); // Opens file chooser
if (savePath == null)
selectOutput("Enter a filename to save to:", "fileSelected"); // Opens file chooser
if (filePath == null)
{
// If a file was not selected
println("No output file was selected...");
@ -1843,29 +1847,41 @@ void exportQueueToFile()
else
{
// If a file was selected, print path to folder
println("Output file: " + savePath);
println("Output file: " + filePath);
List<String> allCommands = new ArrayList<String>(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<String> 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<String> rows = java.util.Arrays.asList(loadStrings(loadPath));
println("Input file: " + filePath);
List<String> 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

View File

@ -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<Panel> getPanelsForTab(String tabName)
@ -83,25 +83,25 @@ List<String> 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<String> buildPanelNames()