diff --git a/SerialPortWindow.pde b/SerialPortWindow.pde index 740bff4..98f8d8d 100644 --- a/SerialPortWindow.pde +++ b/SerialPortWindow.pde @@ -1,7 +1,7 @@ /*------------------------------------------------------------------------ Class and controllers on the "serial port" subwindow ------------------------------------------------------------------------*/ - + 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 ); @@ -28,36 +28,44 @@ ControlFrameSimple addSerialPortControlFrame(String theName, int theWidth, int t } catch(Exception e) { } - - // set up controls - RadioButton r = p.cp5().addRadioButton("radio_serialPort") - .setPosition(10, 10) - .setSize(15, 15) - .setSpacingRow(5) - .plugTo(this, "radio_serialPort"); - r.addItem("No serial connection", -1); + ScrollableList sl = p.cp5().addScrollableList("dropdown_serialPort") + .setPosition(10, 10) + .setSize(150, 150) + .setBarHeight(20) + .setItemHeight(16) + .plugTo(this, "dropdown_serialPort"); + + sl.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); + sl.addItem(ports[i], i); } - + int portNo = getSerialPortNumber(); - if (portNo >= 0 && portNo < ports.length) - r.activate(ports[portNo]); - else - r.activate("No serial connection"); + println("portNo: " + portNo); + if (portNo < 0 || portNo >= ports.length) + portNo = -1; + // set the value of the actual control + sl.setValue(portNo); + + sl.setOpen(false); return p; } -void radio_serialPort(int newSerialPort) +void dropdown_serialPort(int newSerialPort) { - println("In radio_serialPort"); + println("In dropdown_serialPort, newSerialPort: " + newSerialPort); + + // No serial in list is slot 0 in code because of list index + // So shift port index by one + newSerialPort -= 1; + if (newSerialPort == -2) { } diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index b4867d7..01b8c53 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -58,7 +58,7 @@ import java.lang.reflect.Method; int majorVersionNo = 2; int minorVersionNo = 4; -int buildNo = 0; +int buildNo = 2; String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo; ControlP5 cp5; @@ -149,6 +149,8 @@ List machineMessageLog = new ArrayList(); List previewCommandList = new ArrayList(); long lastCommandQueueHash = 0L; +File lastImageDirectory = null; +File lastPropertiesDirectory = null; String lastCommand = ""; String lastDrawingCommand = ""; @@ -571,7 +573,6 @@ void setup() println("Serial ports available on your machine:"); println(serialPorts); -// println("getSerialPortNumber()"+getSerialPortNumber()); if (getSerialPortNumber() >= 0) { println("About to connect to serial port in slot " + getSerialPortNumber()); @@ -682,17 +683,28 @@ void windowResized() windowWidth = frame.getWidth(); windowHeight = frame.getHeight(); println("New window size: " + windowWidth + " x " + windowHeight); + if (frame.getExtendedState() == Frame.MAXIMIZED_BOTH) { + println("Max"); + frame.setExtendedState(0); + frame.setSize(windowWidth, windowHeight); + } for (String key : getPanels().keySet()) { Panel p = getPanels().get(key); p.setSizeByHeight(windowHeight - p.getOutline().getTop() - (DEFAULT_CONTROL_SIZE.y*2)); + if (debugPanels) { + println("Resize " + key + " to be " + p.getOutline().getWidth() + "px across, " + p.getOutline().getHeight() + "px tall"); + } } - + // Required to tell CP5 to be able to use the new sized window + // How does this work? cp5.setGraphics(this,0,0); + loop(); } + void draw() { @@ -995,7 +1007,9 @@ void drawMoveImageOutline() PVector offsetMouseVector = PVector.sub(getDisplayMachine().scaleToDisplayMachine(getMouseVector()), centroid); if (pointPaths != null) { - for (int i = 0; i unpackGCodeInstruction(String line) throws Exception { try { String[] splitted = line.trim().split(" "); for (int i = 0; i < splitted.length; i++) { + // remove ; character + splitted[i] = splitted[i].replace(";", ""); String axis = splitted[i].substring(0, 1); String sanitisedValue = splitted[i].substring(1); - println("BEfore:" + sanitisedValue); sanitisedValue = sanitisedValue.replace(",", "."); - println("After: " + sanitisedValue); - Float value = Float.parseFloat(sanitisedValue); if ("X".equalsIgnoreCase(axis) || "Y".equalsIgnoreCase(axis) || "Z".equalsIgnoreCase(axis) || "G".equalsIgnoreCase(axis)) { instruction.put(axis.toUpperCase(), value); } } -// println("instruction: " + instruction); +// println("instruction: " + instruction); if (instruction.isEmpty()) { throw new Exception("Empty instruction"); } @@ -1450,7 +1482,6 @@ Map unpackGCodeInstruction(String line) throws Exception { println("e: " + e); throw new Exception("Exception while reading the lines from a gcode file: " + line + ", " + e.getMessage()); } - println("Instruction: " + instruction); return instruction; } @@ -3058,21 +3089,19 @@ void loadFromPropertiesFile() if (getVectorFilename() != null) { RShape shape = null; - try - { + // test if file exists + File f = new File(getVectorFilename()); + if (f.isFile()) { shape = RG.loadShape(getVectorFilename()); } - catch (Exception e) - { - shape = null; + else { + println("Tried to load vector file (" + getVectorFilename() + ") but I couldn't find it."); } - if (shape != null) - { + if (shape != null) { setVectorShape(shape); } - else - { + else { println("File not found (" + getVectorFilename() + ")"); } }