From bd1d19018e82f26b839165870dfd9d9b350a80ae Mon Sep 17 00:00:00 2001 From: jerabina Date: Thu, 17 Mar 2016 21:42:01 +0100 Subject: [PATCH 1/9] I joined remembering directory with pictures, curves (LastImageDir) and setting (LastPrefDir) --- polargraphcontroller.pde | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index 80f6f5a..c8e09e9 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -149,6 +149,8 @@ List machineMessageLog = new ArrayList(); List previewCommandList = new ArrayList(); long lastCommandQueueHash = 0L; +File LastImageDir = null; +File LastPrefDir = null; String lastCommand = ""; String lastDrawingCommand = ""; @@ -1061,11 +1063,14 @@ void loadImageWithFileChooser() { public void run() { JFileChooser fc = new JFileChooser(); + if (LastImageDir != null) fc.setCurrentDirectory(LastImageDir); fc.setFileFilter(new ImageFileFilter()); - fc.setDialogTitle("Choose an image file..."); int returned = fc.showOpenDialog(frame); + + LastImageDir = fc.getCurrentDirectory(); + if (returned == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); @@ -1106,17 +1111,24 @@ void loadVectorWithFileChooser() { public void run() { JFileChooser fc = new JFileChooser(); + + if (LastImageDir != null) fc.setCurrentDirectory(LastImageDir); + fc.setFileFilter(new VectorFileFilter()); fc.setDialogTitle("Choose a vector file..."); int returned = fc.showOpenDialog(frame); + + LastImageDir = fc.getCurrentDirectory(); + if (returned == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); if (file.exists()) { RShape shape = loadShapeFromFile(file.getPath()); + println(shape); if (shape != null) { setVectorFilename(file.getPath()); @@ -1138,7 +1150,7 @@ class VectorFileFilter extends javax.swing.filechooser.FileFilter public boolean accept(File file) { String filename = file.getName(); filename.toLowerCase(); - if (file.isDirectory() || filename.endsWith(".svg") || filename.endsWith(".gco") || filename.endsWith(".g") || filename.endsWith(".txt")) + if (file.isDirectory() || filename.endsWith(".svg") || filename.endsWith(".gcode") || filename.endsWith(".g") || filename.endsWith(".ngc") || filename.endsWith(".txt")) return true; else return false; @@ -1155,11 +1167,15 @@ void loadNewPropertiesFilenameWithFileChooser() public void run() { JFileChooser fc = new JFileChooser(); + if (LastPrefDir != null) fc.setCurrentDirectory(LastPrefDir); fc.setFileFilter(new PropertiesFileFilter()); fc.setDialogTitle("Choose a config file..."); int returned = fc.showOpenDialog(frame); + + LastPrefDir = fc.getCurrentDirectory(); + if (returned == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); @@ -1203,6 +1219,7 @@ void saveNewPropertiesFileWithFileChooser() public void run() { JFileChooser fc = new JFileChooser(); + if (LastPrefDir != null) fc.setCurrentDirectory(LastPrefDir); fc.setFileFilter(new PropertiesFileFilter()); fc.setDialogTitle("Enter a config file name..."); @@ -1234,7 +1251,7 @@ RShape loadShapeFromFile(String filename) { if (filename.toLowerCase().endsWith(".svg")) { sh = RG.loadShape(filename); } - else if (filename.toLowerCase().endsWith(".gco") || filename.toLowerCase().endsWith(".g") || filename.toLowerCase().endsWith(".txt")) { + else if (filename.toLowerCase().endsWith(".gcode") || filename.toLowerCase().endsWith(".g") || filename.toLowerCase().endsWith(".ngc") || filename.toLowerCase().endsWith(".txt")) { sh = loadShapeFromGCodeFile(filename); } return sh; @@ -1333,6 +1350,9 @@ RShape loadShapeFromGCodeFile(String filename) { Float x = ins.get("X"); Float y = ins.get("Y"); + + println("X: " + x + " Y: "+ y); + if (x != null && y == null) { // move x axis only, use y of last RPoint[][] points = parent.getPointsInPaths(); @@ -1430,18 +1450,20 @@ Map 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); Float value = Float.parseFloat(splitted[i].substring(1)); + if ("X".equalsIgnoreCase(axis) || "Y".equalsIgnoreCase(axis) || "Z".equalsIgnoreCase(axis) || "G".equalsIgnoreCase(axis)) { instruction.put(axis, value); } } -// println("instruction: " + instruction); + println("instruction: " + instruction); if (instruction.isEmpty()) { throw new Exception(); } - } - catch (Exception e) { + } catch (Exception e) { throw new Exception("Exception while reading the lines from a gcode file: " + line + ", " + e.getMessage()); } From bbcae8b07917e883b6cb3c1521997a97c251e921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Je=C5=99=C3=A1bek?= Date: Tue, 29 Mar 2016 13:49:39 +0200 Subject: [PATCH 2/9] Update polargraphcontroller.pde Change wrong case variablles, remove debugging code --- polargraphcontroller.pde | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index c8e09e9..e8122d2 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -149,8 +149,8 @@ List machineMessageLog = new ArrayList(); List previewCommandList = new ArrayList(); long lastCommandQueueHash = 0L; -File LastImageDir = null; -File LastPrefDir = null; +File lastImageDir = null; +File lastPrefDir = null; String lastCommand = ""; String lastDrawingCommand = ""; @@ -1063,13 +1063,13 @@ void loadImageWithFileChooser() { public void run() { JFileChooser fc = new JFileChooser(); - if (LastImageDir != null) fc.setCurrentDirectory(LastImageDir); + if (lastImageDir != null) fc.setCurrentDirectory(LastImageDir); fc.setFileFilter(new ImageFileFilter()); fc.setDialogTitle("Choose an image file..."); int returned = fc.showOpenDialog(frame); - LastImageDir = fc.getCurrentDirectory(); + lastImageDir = fc.getCurrentDirectory(); if (returned == JFileChooser.APPROVE_OPTION) { @@ -1112,7 +1112,7 @@ void loadVectorWithFileChooser() public void run() { JFileChooser fc = new JFileChooser(); - if (LastImageDir != null) fc.setCurrentDirectory(LastImageDir); + if (lastImageDir != null) fc.setCurrentDirectory(LastImageDir); fc.setFileFilter(new VectorFileFilter()); @@ -1120,7 +1120,7 @@ void loadVectorWithFileChooser() int returned = fc.showOpenDialog(frame); - LastImageDir = fc.getCurrentDirectory(); + lastImageDir = fc.getCurrentDirectory(); if (returned == JFileChooser.APPROVE_OPTION) { @@ -1128,7 +1128,6 @@ void loadVectorWithFileChooser() if (file.exists()) { RShape shape = loadShapeFromFile(file.getPath()); - println(shape); if (shape != null) { setVectorFilename(file.getPath()); @@ -1167,14 +1166,14 @@ void loadNewPropertiesFilenameWithFileChooser() public void run() { JFileChooser fc = new JFileChooser(); - if (LastPrefDir != null) fc.setCurrentDirectory(LastPrefDir); + if (lastPrefDir != null) fc.setCurrentDirectory(lastPrefDir); fc.setFileFilter(new PropertiesFileFilter()); fc.setDialogTitle("Choose a config file..."); int returned = fc.showOpenDialog(frame); - LastPrefDir = fc.getCurrentDirectory(); + lastPrefDir = fc.getCurrentDirectory(); if (returned == JFileChooser.APPROVE_OPTION) { @@ -1219,7 +1218,7 @@ void saveNewPropertiesFileWithFileChooser() public void run() { JFileChooser fc = new JFileChooser(); - if (LastPrefDir != null) fc.setCurrentDirectory(LastPrefDir); + if (lastPrefDir != null) fc.setCurrentDirectory(lastPrefDir); fc.setFileFilter(new PropertiesFileFilter()); fc.setDialogTitle("Enter a config file name..."); From 3909dee0a7ac2e352dbb0a1892bc44fa85b35d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Je=C5=99=C3=A1bek?= Date: Tue, 29 Mar 2016 13:55:09 +0200 Subject: [PATCH 3/9] Update polargraphcontroller.pde sorry I was distracted --- polargraphcontroller.pde | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index e8122d2..a4947da 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -1063,7 +1063,7 @@ void loadImageWithFileChooser() { public void run() { JFileChooser fc = new JFileChooser(); - if (lastImageDir != null) fc.setCurrentDirectory(LastImageDir); + if (lastImageDir != null) fc.setCurrentDirectory(lastImageDir); fc.setFileFilter(new ImageFileFilter()); fc.setDialogTitle("Choose an image file..."); @@ -1112,7 +1112,7 @@ void loadVectorWithFileChooser() public void run() { JFileChooser fc = new JFileChooser(); - if (lastImageDir != null) fc.setCurrentDirectory(LastImageDir); + if (lastImageDir != null) fc.setCurrentDirectory(lastImageDir); fc.setFileFilter(new VectorFileFilter()); From 3bf418fa930241b4ce8fbf9368b718157e1f4516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Je=C5=99=C3=A1bek?= Date: Tue, 29 Mar 2016 14:44:35 +0200 Subject: [PATCH 4/9] And next remove debugging code remove debugging code --- polargraphcontroller.pde | 487 +++++++++++++++++++-------------------- 1 file changed, 242 insertions(+), 245 deletions(-) diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index a4947da..bed3b87 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -1,32 +1,32 @@ /** 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 - + */ //import processing.video.*; @@ -540,25 +540,25 @@ void setup() frame.setResizable(true); initLogging(); parentPapplet = this; - + RG.init(this); RG.setPolygonizer(RG.UNIFORMLENGTH); // RG.setPolygonizer(RG.ADAPTATIVE); - try - { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } - catch (Exception e) - { - e.printStackTrace(); + try + { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } + catch (Exception e) + { + e.printStackTrace(); } loadFromPropertiesFile(); size(windowWidth, windowHeight); this.cp5 = new ControlP5(this); initTabs(); - + String[] serialPorts = Serial.list(); println("Serial ports available on your machine:"); println(serialPorts); @@ -571,7 +571,7 @@ void setup() if (serialPorts.length > 0) { String portName = null; - try + try { println("Get serial port no: "+getSerialPortNumber()); portName = serialPorts[getSerialPortNumber()]; @@ -583,8 +583,8 @@ void setup() } catch (Exception e) { - println("Attempting to connect to serial port " - + portName + " in slot " + getSerialPortNumber() + println("Attempting to connect to serial port " + + portName + " in slot " + getSerialPortNumber() + " caused an exception: " + e.getMessage()); } } @@ -610,54 +610,54 @@ void setup() } void fitDisplayMachineToWindow() { - + Rectangle gr = panels.get(PANEL_NAME_GENERAL).getOutline(); println(gr); - + Rectangle ir = panels.get(PANEL_NAME_INPUT).getOutline(); println(ir); - + float targetHeight = ir.getBottom() - gr.getTop() - CONTROL_SPACING.y; println("Target height is " + targetHeight + " pixels"); - + float machineHeight = getDisplayMachine().getOutline().getHeight(); println(machineHeight); - + machineScaling = (targetHeight / machineHeight); println(machineScaling); - + if (machineScaling < 0) { machineScaling = 1.0; } - + getDisplayMachine().getOffset().x = ((gr.getRight() > ir.getRight()) ? gr.getRight() : ir.getRight()) + CONTROL_SPACING.x; getDisplayMachine().getOffset().y = gr.getTop(); - + } void addEventListeners() { - frame.addComponentListener(new ComponentAdapter() + frame.addComponentListener(new ComponentAdapter() { - public void componentResized(ComponentEvent event) + public void componentResized(ComponentEvent event) { - if (event.getSource()==frame) + if (event.getSource()==frame) { windowResized(); } } } ); - - addMouseWheelListener(new java.awt.event.MouseWheelListener() - { - public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) - { + + addMouseWheelListener(new java.awt.event.MouseWheelListener() + { + public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) + { mouseWheel(evt.getWheelRotation()); } } - ); -} + ); +} void preLoadCommandQueue() @@ -673,13 +673,13 @@ void windowResized() windowWidth = frame.getWidth(); windowHeight = frame.getHeight(); println("New window size: " + windowWidth + " x " + windowHeight); - + for (String key : getPanels().keySet()) { Panel p = getPanels().get(key); p.setSizeByHeight(windowHeight - p.getOutline().getTop() - (DEFAULT_CONTROL_SIZE.y*2)); } - + // Required to tell CP5 to be able to use the new sized window cp5.setGraphics(this,0,0); loop(); @@ -709,7 +709,7 @@ void draw() if (isShowingSummaryOverlay()) { drawSummaryOverlay(); } - + if (isShowingDialogBox()) { drawDialogBox(); } @@ -737,7 +737,7 @@ boolean isShowingDialogBox() } void drawDialogBox() { - + } String getVectorFilename() { @@ -799,7 +799,7 @@ void drawImagePage() getDisplayMachine().draw(); drawMoveImageOutline(); stroke(255, 0, 0); - + for (Panel panel : getPanelsForTab(TAB_NAME_INPUT)) { panel.draw(); @@ -833,7 +833,7 @@ void drawDetailsPage() noFill(); getDisplayMachine().drawForSetup(); stroke(255, 0, 0); - + for (Panel panel : getPanelsForTab(TAB_NAME_DETAILS)) { panel.draw(); @@ -859,7 +859,7 @@ void drawRovingPage() noFill(); getDisplayMachine().drawForSetup(); stroke(255, 0, 0); - + for (Panel panel : getPanelsForTab(TAB_NAME_ROVING)) { panel.draw(); @@ -895,7 +895,7 @@ void drawTracePage() } stroke(255, 0, 0); - + for (Panel panel : getPanelsForTab(TAB_NAME_TRACE)) { panel.draw(); @@ -925,9 +925,9 @@ void drawCommandQueuePage() fill(100); drawMachineOutline(); showingSummaryOverlay = false; - - + + int right = 0; for (Panel panel : getPanelsForTab(TAB_NAME_QUEUE)) { @@ -938,9 +938,9 @@ void drawCommandQueuePage() } text(propertiesFilename, getPanel(PANEL_NAME_GENERAL).getOutline().getLeft(), getPanel(PANEL_NAME_GENERAL).getOutline().getTop()-7); showCommandQueue(right, (int)mainPanelPosition.y); - + drawStatusText((int)statusTextPosition.x, (int)statusTextPosition.y); - + } void drawImageLoadPage() @@ -959,7 +959,7 @@ void drawMoveImageOutline() PVector imageSizeOnScreen = getDisplayMachine().scaleToScreen(imageSize); imageSizeOnScreen.sub(getDisplayMachine().getOutline().getTopLeft()); PVector offset = new PVector(imageSizeOnScreen.x/2.0, imageSizeOnScreen.y/2.0); - + PVector mVect = getMouseVector(); PVector imagePos = new PVector(mVect.x-offset.x, mVect.y-offset.y); @@ -988,7 +988,7 @@ void drawMoveImageOutline() { for (int i = 0; i ins = null; try { ins = unpackGCodeInstruction(line); @@ -1329,7 +1329,7 @@ RShape loadShapeFromGCodeFile(String filename) { if (code >= 2) { continue; } - + Float z = ins.get("Z"); if (z != null) { gCodeZAxisChanges++; @@ -1346,12 +1346,9 @@ RShape loadShapeFromGCodeFile(String filename) { drawLine = false; } } - + Float x = ins.get("X"); Float y = ins.get("Y"); - - println("X: " + x + " Y: "+ y); - if (x != null && y == null) { // move x axis only, use y of last RPoint[][] points = parent.getPointsInPaths(); @@ -1364,7 +1361,7 @@ RShape loadShapeFromGCodeFile(String filename) { RPoint rp = points[points.length-1][points[points.length-1].length-1]; x = rp.x; } - + if (x != null && y != null) { // move both x and y axis if (drawLine) { @@ -1389,9 +1386,9 @@ RShape loadShapeFromGCodeFile(String filename) { // println("" + totalPoints + " points."); } else { - + } - + if ((millis() - time) > 500) { time = millis(); reportStatus = true; @@ -1399,11 +1396,11 @@ RShape loadShapeFromGCodeFile(String filename) { else { reportStatus = false; } - + if (lineNo == (countLines-1)) { reportStatus = true; } - + } } catch (IOException e) { @@ -1413,13 +1410,13 @@ RShape loadShapeFromGCodeFile(String filename) { finally { try { reader.close(); - } + } catch (IOException e) { println("Exception closing the gcode file " + filename); e.printStackTrace(); } } - + RPoint[][] points = parent.getPointsInPaths(); totalPoints = 0; if (points != null) { @@ -1453,19 +1450,19 @@ Map unpackGCodeInstruction(String line) throws Exception { splitted[i] = splitted[i].replace(";", ""); String axis = splitted[i].substring(0, 1); Float value = Float.parseFloat(splitted[i].substring(1)); - if ("X".equalsIgnoreCase(axis) || "Y".equalsIgnoreCase(axis) || "Z".equalsIgnoreCase(axis) || "G".equalsIgnoreCase(axis)) { instruction.put(axis, value); } } - println("instruction: " + instruction); +// println("instruction: " + instruction); if (instruction.isEmpty()) { throw new Exception(); } - } catch (Exception e) { + } + catch (Exception e) { throw new Exception("Exception while reading the lines from a gcode file: " + line + ", " + e.getMessage()); } - + return instruction; } @@ -1492,7 +1489,7 @@ void setBoxToPictureframeDimensions() t = (Toggle) getAllControls().get(MODE_SHOW_DENSITY_PREVIEW); t.setValue(1); t.update(); - + } } @@ -1511,9 +1508,9 @@ void setSampleArea(float v) this.sampleArea = v; } -void controlEvent(ControlEvent controlEvent) +void controlEvent(ControlEvent controlEvent) { - if (controlEvent.isTab()) + if (controlEvent.isTab()) { if (controlEvent.tab().getName() == getCurrentTab()) { @@ -1525,18 +1522,18 @@ void controlEvent(ControlEvent controlEvent) changeTab(currentTab, controlEvent.tab().getName()); } } - else if(controlEvent.isGroup()) + else if(controlEvent.isGroup()) { print("got an event from "+controlEvent.group().getName()+"\t"); - // checkbox uses arrayValue to store the state of + // checkbox uses arrayValue to store the state of // individual checkbox-items. usage: - for (int i=0; i= k) { - return keys[k]; + return keys[k]; } return false; } void keyReleased() -{ - keys[keyCode] = false; +{ + keys[keyCode] = false; } void keyPressed() @@ -1679,18 +1676,18 @@ void keyPressed() //println("key: " + KeyEvent.getKeyText(keyCode)); //println("Keys: " + keys); //println("Keycode: " + keyCode); - - if (checkKey(CONTROL) && checkKey(KeyEvent.VK_PAGE_UP)) + + if (checkKey(CONTROL) && checkKey(KeyEvent.VK_PAGE_UP)) changeMachineScaling(1); - else if (checkKey(CONTROL) && checkKey(KeyEvent.VK_PAGE_DOWN)) + else if (checkKey(CONTROL) && checkKey(KeyEvent.VK_PAGE_DOWN)) changeMachineScaling(-1); else if (checkKey(CONTROL) && checkKey(DOWN)) getDisplayMachine().getOffset().y = getDisplayMachine().getOffset().y + 10; - else if (checkKey(CONTROL) && checkKey(UP)) + else if (checkKey(CONTROL) && checkKey(UP)) getDisplayMachine().getOffset().y = getDisplayMachine().getOffset().y - 10; - else if (checkKey(CONTROL) && checkKey(RIGHT)) + else if (checkKey(CONTROL) && checkKey(RIGHT)) getDisplayMachine().getOffset().x = getDisplayMachine().getOffset().x + 10; - else if (checkKey(CONTROL) && checkKey(LEFT)) + else if (checkKey(CONTROL) && checkKey(LEFT)) getDisplayMachine().getOffset().x = getDisplayMachine().getOffset().x - 10; else if (checkKey(KeyEvent.VK_ESCAPE)) key = 0; @@ -1759,12 +1756,12 @@ void mouseDragged() } } } - + void mouseClicked() { if (mouseOverPanel()) { // changing mode - + } else { @@ -1774,10 +1771,10 @@ void mouseClicked() PVector mVect = getDisplayMachine().scaleToDisplayMachine(getMouseVector()); PVector offset = new PVector(imageSize.x/2.0, imageSize.y/2.0); PVector imagePos = new PVector(mVect.x-offset.x, mVect.y-offset.y); - + imagePos = getDisplayMachine().inSteps(imagePos); getDisplayMachine().getImageFrame().setPosition(imagePos.x, imagePos.y); - + if (getDisplayMachine().pixelsCanBeExtracted() && isBoxSpecified()) getDisplayMachine().extractPixelsFromArea(getBoxVector1(), getBoxVectorSize(), getGridSize(), sampleArea); } @@ -1791,12 +1788,12 @@ void mouseClicked() } else if (mouseOverQueue()) { - // stopping or starting + // stopping or starting println("queue clicked."); queueClicked(); } else if (mouseOverMachine()) - { + { // picking coords machineClicked(); } @@ -1909,17 +1906,17 @@ void leftButtonMachineClick() setChromaKey(getMouseVector()); else if (currentMode.equals(MODE_SEND_START_TEXT)) sendStartTextAtPoint(); - + } -void mouseWheel(int delta) +void mouseWheel(int delta) { changeMachineScaling(delta); -} +} void setChromaKey(PVector p) { - color col = getDisplayMachine().getPixelAtScreenCoords(p); + color col = getDisplayMachine().getPixelAtScreenCoords(p); chromaKeyColour = col; if (getDisplayMachine().pixelsCanBeExtracted() && isBoxSpecified()) { @@ -1929,7 +1926,7 @@ void setChromaKey(PVector p) boolean isPreviewable(String command) { - if (command.startsWith(CMD_CHANGELENGTHDIRECT) + if (command.startsWith(CMD_CHANGELENGTHDIRECT) || command.startsWith(CMD_CHANGELENGTH) || command.startsWith(CMD_DRAWPIXEL)) { @@ -1955,9 +1952,9 @@ boolean toggleShowConsole() { console = null; System.setOut(savedOut); } - + println("Ow"); - + return console == null; } @@ -1976,8 +1973,8 @@ void previewQueue(boolean forceRebuild) { println("regenerating preview queue."); previewCommandList.clear(); - - + + for (String command : commandQueue) { if (command.startsWith(CMD_CHANGELENGTHDIRECT) || command.startsWith(CMD_CHANGELENGTH) || command.startsWith(CMD_DRAWPIXEL)) @@ -1989,27 +1986,27 @@ void previewQueue(boolean forceRebuild) String aLenStr = splitted[1]; String bLenStr = splitted[2]; - + PVector endPoint = new PVector(Integer.parseInt(aLenStr)+previewCordOffset, Integer.parseInt(bLenStr)+previewCordOffset); endPoint = getDisplayMachine().asCartesianCoords(endPoint); endPoint = getDisplayMachine().inMM(endPoint); - + pv.x = endPoint.x; pv.y = endPoint.y; pv.z = -1.0; - + if (command.startsWith(CMD_DRAWPIXEL)) { String densStr = splitted[4]; pv.z = Integer.parseInt(densStr); } - + previewCommandList.add(pv); } } lastCommandQueueHash = commandQueue.hashCode(); } - + for (PreviewVector pv : previewCommandList) { PVector p = (PVector) pv; @@ -2023,10 +2020,10 @@ void previewQueue(boolean forceRebuild) ellipse(p.x, p.y, 20, 20); noFill(); } - + if (pv.command.equals(CMD_CHANGELENGTHDIRECT)) stroke(0); - else + else stroke(200,0,0); line(startPoint.x, startPoint.y, p.x, p.y); startPoint = p; @@ -2048,7 +2045,7 @@ void previewQueue(boolean forceRebuild) ellipse(startPoint.x, startPoint.y, 15,15); noFill(); } - + } boolean isHiddenPixel(PVector p) @@ -2063,7 +2060,7 @@ void sizeImageToFitBox() { PVector boxSize = getDisplayMachine().inSteps(getBoxSize()); PVector boxPos = getDisplayMachine().inSteps(getBoxVector1()); println("image: " + boxSize); - + Rectangle r = new Rectangle(boxPos, boxSize); getDisplayMachine().setImageFrame(r); } @@ -2082,11 +2079,11 @@ void exportQueueToFile(File selection) { 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) { @@ -2121,7 +2118,7 @@ void queueClicked() int relativeCoord = (mouseY-topEdgeOfQueue); int rowClicked = relativeCoord / queueRowHeight; int totalCommands = commandQueue.size()+realtimeCommandQueue.size(); - + if (rowClicked < 1) // its the header - start or stop queue { if (commandQueueRunning) @@ -2143,11 +2140,11 @@ void queueClicked() { if (cmdNumber <= realtimeCommandQueue.size()) realtimeCommandQueue.remove(cmdNumber-1); - else + else { cmdNumber-=(realtimeCommandQueue.size()+1); commandQueue.remove(cmdNumber); - } + } } else { @@ -2215,21 +2212,21 @@ void showText(int xPosOrigin, int yPosOrigin) noStroke(); fill(0, 0, 0, 80); rect(xPosOrigin, yPosOrigin, 220, 550); - - + + textSize(12); fill(255); int tRow = 15; int textPositionX = xPosOrigin+4; int textPositionY = yPosOrigin+4; - + int tRowNo = 1; PVector screenCoordsCart = getMouseVector(); - + text(programTitle, textPositionX, textPositionY+(tRow*tRowNo++)); tRowNo++; text("Cursor position: " + mouseX + ", " + mouseY, textPositionX, textPositionY+(tRow*tRowNo++)); - + text("MM Per Step: " + getDisplayMachine().getMMPerStep(), textPositionX, textPositionY+(tRow*tRowNo++)); text("Steps Per MM: " + getDisplayMachine().getStepsPerMM() ,textPositionX, textPositionY+(tRow*tRowNo++)); @@ -2237,10 +2234,10 @@ void showText(int xPosOrigin, int yPosOrigin) { PVector posOnMachineCartesianInMM = getDisplayMachine().scaleToDisplayMachine(screenCoordsCart); text("Machine x/y mm: " + posOnMachineCartesianInMM.x+","+posOnMachineCartesianInMM.y, textPositionX, textPositionY+(tRow*tRowNo++)); - + PVector posOnMachineNativeInMM = getDisplayMachine().convertToNative(posOnMachineCartesianInMM); text("Machine a/b mm: " + posOnMachineNativeInMM.x+","+posOnMachineNativeInMM.y, textPositionX, textPositionY+(tRow*tRowNo++)); - + PVector posOnMachineNativeInSteps = getDisplayMachine().inSteps(posOnMachineNativeInMM); text("Machine a/b steps: " + posOnMachineNativeInSteps.x+","+posOnMachineNativeInSteps.y, textPositionX, textPositionY+(tRow*tRowNo++)); } @@ -2250,24 +2247,24 @@ void showText(int xPosOrigin, int yPosOrigin) text("Machine a/b mm: --,--", textPositionX, textPositionY+(tRow*tRowNo++)); text("Machine a/b steps: --,--", textPositionX, textPositionY+(tRow*tRowNo++)); } - - drawStatusText(textPositionX, textPositionY+(tRow*tRowNo++)); - + + drawStatusText(textPositionX, textPositionY+(tRow*tRowNo++)); + text(commandStatus, textPositionX, textPositionY+(tRow*tRowNo++)); - + text("Mode: " + currentMode, textPositionX, textPositionY+(tRow*tRowNo++)); // middle side text("Grid size: " + getGridSize(), textPositionX, textPositionY+(tRow*tRowNo++)); - + text("Box width: " + getBoxWidth(), textPositionX, textPositionY+(tRow*tRowNo++)); text("Box height: " + getBoxHeight(), textPositionX, textPositionY+(tRow*tRowNo++)); text("Box offset left: " + getBoxPosition().x, textPositionX, textPositionY+(tRow*tRowNo++)); text("Box offset top: " + getBoxPosition().y, textPositionX, textPositionY+(tRow*tRowNo++)); - + text("Available memory: " + machineAvailMem + " (min: " + machineMinAvailMem +", used: "+ machineUsedMem+")", textPositionX, textPositionY+(tRow*tRowNo++)); text("Time cmd: " + getCurrentPixelTime() + ", total: " + getTimeSoFar(), textPositionX, textPositionY+(tRow*tRowNo++)); @@ -2305,7 +2302,7 @@ void showText(int xPosOrigin, int yPosOrigin) void drawStatusText(int x, int y) { String drawbotStatus = null; - + if (useSerialPortConnection) { if (isDrawbotConnected()) @@ -2329,20 +2326,20 @@ void drawStatusText(int x, int y) if ("".equals(busyDoing)) busyDoing = commandHistory.get(commandHistory.size()-1); drawbotStatus = "BUSY: " + busyDoing; - } + } } else { fill(255, 0, 0); drawbotStatus = "Polargraph is not connected."; - } + } } else { fill(255, 0, 0); drawbotStatus = "No serial connection."; } - + text(drawbotStatus, x, y); fill(255); } @@ -2351,7 +2348,7 @@ void setCommandQueueFont() { textSize(12); fill(255); -} +} void showCommandQueue(int xPos, int yPos) { setCommandQueueFont(); @@ -2366,14 +2363,14 @@ void showCommandQueue(int xPos, int yPos) leftEdgeOfQueue = textPositionX; rightEdgeOfQueue = textPositionX+300; bottomEdgeOfQueue = height; - + drawCommandQueueStatus(textPositionX, commandQueuePos, 14); commandQueuePos+=queueRowHeight; text("Last command: " + ((commandHistory.isEmpty()) ? "-" : commandHistory.get(commandHistory.size()-1)), textPositionX, commandQueuePos); commandQueuePos+=queueRowHeight; text("Current command: " + lastCommand, textPositionX, commandQueuePos); commandQueuePos+=queueRowHeight; - + fill(128,255,255); int queueNumber = commandQueue.size()+realtimeCommandQueue.size(); for (String s : realtimeCommandQueue) @@ -2381,7 +2378,7 @@ void showCommandQueue(int xPos, int yPos) text((queueNumber--)+". "+ s, textPositionX, commandQueuePos); commandQueuePos+=queueRowHeight; } - + fill(255); try { @@ -2402,7 +2399,7 @@ void showCommandQueue(int xPos, int yPos) println("Caught the pesky ConcurrentModificationException: " + cme.getMessage()); } showmachineMessageLog(rightEdgeOfQueue, 20); - + } void drawCommandQueueStatus(int x, int y, int tSize) @@ -2434,7 +2431,7 @@ void showmachineMessageLog(int xPos, int yPos) int pos = textPositionY+(tRow*tRowNo++); pos+=queueRowHeight; - + fill(255); // Write out the commands into the window, stop when you fall off the bottom of the window // Or run out of commands @@ -2586,7 +2583,7 @@ public DisplayMachine getDisplayMachine() { if (displayMachine == null) displayMachine = new DisplayMachine(new Machine(5000, 5000, 200.0, 95.0), machinePosition, machineScaling); - + displayMachine.setOffset(machinePosition); displayMachine.setScale(machineScaling); return displayMachine; @@ -2613,7 +2610,7 @@ void changeHardwareVersionTo(int newVer) { case HARDWARE_VER_MEGA : currentSram = HARDWARE_ATMEGA1280_SRAM; - default : + default : currentSram = HARDWARE_ATMEGA328_SRAM; } // windowResized(); @@ -2639,14 +2636,14 @@ void setHardwareVersionFromIncoming(String readyString) println("Bad format for hardware version - defaulting to ATMEGA328 (Uno)"); verInt = HARDWARE_VER_UNO; } - - if (HARDWARE_VER_MEGA == verInt + + if (HARDWARE_VER_MEGA == verInt || HARDWARE_VER_MEGA_POLARSHIELD == verInt) newHardwareVersion = verInt; else newHardwareVersion = HARDWARE_VER_UNO; } - + // now see if it's different to last time. if (newHardwareVersion != currentHardware) { @@ -2655,15 +2652,15 @@ void setHardwareVersionFromIncoming(String readyString) } } -void serialEvent(Serial myPort) -{ +void serialEvent(Serial myPort) +{ // read the serial buffer: String incoming = myPort.readStringUntil('\n'); myPort.clear(); // if you got any bytes other than the linefeed: incoming = trim(incoming); println("incoming: " + incoming); - + if (incoming.startsWith("READY")) { drawbotReady = true; @@ -2689,14 +2686,14 @@ void serialEvent(Serial myPort) readPenLiftRange(incoming); else if (incoming.startsWith("PGSPEED")) readMachineSpeed(incoming); - + else if ("RESEND".equals(incoming)) resendLastCommand(); else if ("DRAWING".equals(incoming)) drawbotReady = false; else if (incoming.startsWith("MEMORY")) extractMemoryUsage(incoming); - + else if (incoming.startsWith("BUTTON")) handleMachineButton(incoming); @@ -2727,10 +2724,10 @@ void readMachineMessage(String msg) String type = msg.substring(0,1); msg = msg.substring(2, msg.length()); String timestamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); - + msg = type + timestamp + " " + msg; machineMessageLog.add(msg); - if (machineMessageLog.size() > 200) + if (machineMessageLog.size() > 200) { machineMessageLog.remove(0); } @@ -2746,7 +2743,7 @@ void readMachinePosition(String sync) Float a = Float.valueOf(currentAPos).floatValue(); Float b = Float.valueOf(currentBPos).floatValue(); currentMachinePos.x = a; - currentMachinePos.y = b; + currentMachinePos.y = b; currentMachinePos = getDisplayMachine().inMM(getDisplayMachine().asCartesianCoords(currentMachinePos)); } } @@ -2760,7 +2757,7 @@ void readCartesianMachinePosition(String sync) Float a = Float.valueOf(currentAPos).floatValue(); Float b = Float.valueOf(currentBPos).floatValue(); currentCartesianMachinePos.x = a; - currentCartesianMachinePos.y = b; + currentCartesianMachinePos.y = b; } } @@ -2770,7 +2767,7 @@ void readMmPerRev(String in) if (splitted.length == 3) { String mmStr = splitted[1]; - + float mmPerRev = Float.parseFloat(mmStr); getDisplayMachine().setMMPerRev(mmPerRev); updateNumberboxValues(); @@ -2783,7 +2780,7 @@ void readStepsPerRev(String in) if (splitted.length == 3) { String stepsStr = splitted[1]; - + Float stepsPerRev = Float.parseFloat(stepsStr); getDisplayMachine().setStepsPerRev(stepsPerRev); updateNumberboxValues(); @@ -2796,7 +2793,7 @@ void readStepMultiplier(String in) if (splitted.length == 3) { String stepsStr = splitted[1]; - + machineStepMultiplier = Integer.parseInt(stepsStr); updateNumberboxValues(); } @@ -2810,13 +2807,13 @@ void readMachineSize(String in) { String mWidth = splitted[1]; String mHeight = splitted[2]; - + Integer intWidth = Integer.parseInt(mWidth); Integer intHeight = Integer.parseInt(mHeight); - + float fWidth = getDisplayMachine().inSteps(intWidth); float fHeight = getDisplayMachine().inSteps(intHeight); - + getDisplayMachine().setSize(int(fWidth+0.5), int(fHeight+0.5)); updateNumberboxValues(); } @@ -2828,7 +2825,7 @@ void readMachineName(String sync) if (splitted.length == 3) { String name = splitted[1]; - + } } @@ -2839,10 +2836,10 @@ void readMachineSpeed(String in) { String speed = splitted[1]; String accel = splitted[2]; - + currentMachineMaxSpeed = Float.parseFloat(speed); currentMachineAccel = Float.parseFloat(accel); - + updateNumberboxValues(); } } @@ -2854,7 +2851,7 @@ void readPenLiftRange(String in) { String downPos = splitted[1]; String upPos = splitted[2]; - + penLiftDownPosition = Integer.parseInt(downPos); penLiftUpPosition = Integer.parseInt(upPos); @@ -2871,7 +2868,7 @@ void resendLastCommand() void dispatchCommandQueue() { - if (isDrawbotReady() + if (isDrawbotReady() && (!commandQueue.isEmpty() || !realtimeCommandQueue.isEmpty()) && commandQueueRunning) { @@ -2906,7 +2903,7 @@ void dispatchCommandQueue() else if (commandQueue.isEmpty()) { stopPixelTimer(); - } + } } void addToCommandQueue(String command) @@ -2953,7 +2950,7 @@ Properties getProperties() { props = new Properties(); String fileToLoad = sketchPath(propertiesFilename); - + File propertiesFile = new File(fileToLoad); if (!propertiesFile.exists()) { @@ -2961,7 +2958,7 @@ Properties getProperties() savePropertiesFile(); println("saved."); } - + propertiesFileStream = new FileInputStream(propertiesFile); props.load(propertiesFileStream); println("Successfully loaded properties file " + fileToLoad); @@ -2973,11 +2970,11 @@ Properties getProperties() } finally { - try - { + try + { propertiesFileStream.close(); } - catch (Exception e) + catch (Exception e) { println("Exception: "+e.getMessage()); }; @@ -3004,7 +3001,7 @@ void loadFromPropertiesFile() this.currentMachineMaxSpeed = getFloatProperty("machine.motors.maxSpeed", 2000.0); this.currentMachineAccel = getFloatProperty("machine.motors.accel", 2000.0); this.machineStepMultiplier = getIntProperty("machine.step.multiplier", 8); - + // serial port this.serialPortNumber = getIntProperty("controller.machine.serialport", 0); this.baudRate = getIntProperty("controller.machine.baudrate", 57600); @@ -3013,25 +3010,25 @@ void loadFromPropertiesFile() this.gridSize = getFloatProperty("controller.grid.size", 100.0); this.sampleArea = getIntProperty("controller.pixel.samplearea", 2); this.pixelScalingOverGridSize = getFloatProperty("controller.pixel.scaling", 1.0); - + // pixel renderer this.densityPreviewStyle = getIntProperty("controller.density.preview.style", 1); - + // initial screen size this.windowWidth = getIntProperty("controller.window.width", 650); this.windowHeight = getIntProperty("controller.window.height", 400); - + println("windowHeight:" + this.windowHeight); this.testPenWidthStartSize = getFloatProperty("controller.testPenWidth.startSize", 0.5); this.testPenWidthEndSize = getFloatProperty("controller.testPenWidth.endSize", 2.0); this.testPenWidthIncrementSize = getFloatProperty("controller.testPenWidth.incrementSize", 0.5); - + this.maxSegmentLength = getIntProperty("controller.maxSegmentLength", 2); - + float homePointX = getFloatProperty("controller.homepoint.x", 0.0); float homePointY = getFloatProperty("controller.homepoint.y", 0.0); - + if (homePointX == 0.0) { float defaultX = getDisplayMachine().getWidth() / 2.0; // in steps @@ -3042,7 +3039,7 @@ void loadFromPropertiesFile() } this.homePointCartesian = new PVector(getDisplayMachine().inSteps(homePointX), getDisplayMachine().inSteps(homePointY)); // println("home point loaded: " + homePointCartesian + ", " + getHomePoint()); - + setVectorFilename(getStringProperty("controller.vector.filename", null)); if (getVectorFilename() != null) { @@ -3055,12 +3052,12 @@ void loadFromPropertiesFile() { shape = null; } - - if (shape != null) + + if (shape != null) { setVectorShape(shape); } - else + else { println("File not found (" + getVectorFilename() + ")"); } @@ -3071,20 +3068,20 @@ void loadFromPropertiesFile() this.minimumVectorLineLength = getIntProperty("controller.vector.minLineLength", 0); - + println("Finished loading configuration from properties file."); } void savePropertiesFile() { Properties props = new Properties(); - + props = getDisplayMachine().loadDefinitionIntoProperties(props); NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK); - DecimalFormat df = (DecimalFormat)nf; + DecimalFormat df = (DecimalFormat)nf; df.applyPattern("###.##"); - + props.setProperty("controller.page.colour", hex(this.pageColour, 6)); props.setProperty("controller.frame.colour", hex(this.frameColour,6)); props.setProperty("controller.machine.colour", hex(this.machineColour,6)); @@ -3092,7 +3089,7 @@ void savePropertiesFile() props.setProperty("controller.background.colour", hex(this.backgroundColour,6)); props.setProperty("controller.densitypreview.colour", hex(this.densityPreviewColour,6)); - + // pen size props.setProperty("machine.pen.size", df.format(currentPenWidth)); // serial port @@ -3114,37 +3111,37 @@ void savePropertiesFile() props.setProperty("controller.testPenWidth.startSize", df.format(testPenWidthStartSize)); props.setProperty("controller.testPenWidth.endSize", df.format(testPenWidthEndSize)); props.setProperty("controller.testPenWidth.incrementSize", df.format(testPenWidthIncrementSize)); - + props.setProperty("controller.maxSegmentLength", new Integer(getMaxSegmentLength()).toString()); - + props.setProperty("machine.motors.maxSpeed", df.format(currentMachineMaxSpeed)); props.setProperty("machine.motors.accel", df.format(currentMachineAccel)); props.setProperty("machine.step.multiplier", new Integer(machineStepMultiplier).toString()); - + props.setProperty("controller.pixel.mask.color", hex(this.chromaKeyColour, 6)); - - PVector hp = null; + + PVector hp = null; if (getHomePoint() != null) { hp = getHomePoint(); } else hp = new PVector(2000.0, 1000.0); - + hp = getDisplayMachine().inMM(hp); - + props.setProperty("controller.homepoint.x", df.format(hp.x)); props.setProperty("controller.homepoint.y", df.format(hp.y)); - + if (getVectorFilename() != null) props.setProperty("controller.vector.filename", getVectorFilename()); - + props.setProperty("controller.vector.scaling", df.format(vectorScaling)); props.setProperty("controller.vector.position.x", df.format(getVectorPosition().x)); props.setProperty("controller.vector.position.y", df.format(getVectorPosition().y)); props.setProperty("controller.vector.minLineLength", new Integer(this.minimumVectorLineLength).toString()); - + FileOutputStream propertiesOutput = null; try @@ -3186,19 +3183,19 @@ void savePropertiesFile() } } -boolean getBooleanProperty(String id, boolean defState) +boolean getBooleanProperty(String id, boolean defState) { return boolean(getProperties().getProperty(id,""+defState)); } - -int getIntProperty(String id, int defVal) + +int getIntProperty(String id, int defVal) { - return int(getProperties().getProperty(id,""+defVal)); + return int(getProperties().getProperty(id,""+defVal)); } - -float getFloatProperty(String id, float defVal) + +float getFloatProperty(String id, float defVal) { - return float(getProperties().getProperty(id,""+defVal)); + return float(getProperties().getProperty(id,""+defVal)); } String getStringProperty(String id, String defVal) { @@ -3212,7 +3209,7 @@ color getColourProperty(String id, color defVal) { col = defVal; } - + if (colStr.length() == 1) { // single value grey @@ -3228,7 +3225,7 @@ color getColourProperty(String id, color defVal) d1 = d1+d1; d2 = d2+d2; d3 = d3+d3; - + col = color(unhex(d1), unhex(d2), unhex(d3)); } else if (colStr.length() == 6) @@ -3237,10 +3234,10 @@ color getColourProperty(String id, color defVal) String d1 = colStr.substring(0,2); String d2 = colStr.substring(2,4); String d3 = colStr.substring(4,6); - + col = color(unhex(d1), unhex(d2), unhex(d3)); } - + return col; } @@ -3265,7 +3262,7 @@ void setOverwriteExistingStoreFile(boolean over) { this.overwriteExistingStoreFile = over; } - + void initProperties() { getProperties(); @@ -3327,7 +3324,7 @@ PImage makeColourImage(int w, int h, int colour) { PImage img = createImage(w,h,RGB); for(int i=0; i < img.pixels.length; i++) { - img.pixels[i] = colour; + img.pixels[i] = colour; } return img; } From eddaf3661aad200825f79bdce2aa31236bddf635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Je=C5=99=C3=A1bek?= Date: Tue, 29 Mar 2016 16:21:25 +0200 Subject: [PATCH 5/9] Update polargraphcontroller.pde --- polargraphcontroller.pde | 501 ++++++++++++++++++++------------------- 1 file changed, 251 insertions(+), 250 deletions(-) diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index bed3b87..6ee2491 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -1,32 +1,32 @@ /** 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 - + */ //import processing.video.*; @@ -149,8 +149,8 @@ List machineMessageLog = new ArrayList(); List previewCommandList = new ArrayList(); long lastCommandQueueHash = 0L; -File lastImageDir = null; -File lastPrefDir = null; +File LastImageDir = null; +File LastPrefDir = null; String lastCommand = ""; String lastDrawingCommand = ""; @@ -540,25 +540,25 @@ void setup() frame.setResizable(true); initLogging(); parentPapplet = this; - + RG.init(this); RG.setPolygonizer(RG.UNIFORMLENGTH); // RG.setPolygonizer(RG.ADAPTATIVE); - try - { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } - catch (Exception e) - { - e.printStackTrace(); + try + { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } + catch (Exception e) + { + e.printStackTrace(); } loadFromPropertiesFile(); size(windowWidth, windowHeight); this.cp5 = new ControlP5(this); initTabs(); - + String[] serialPorts = Serial.list(); println("Serial ports available on your machine:"); println(serialPorts); @@ -571,7 +571,7 @@ void setup() if (serialPorts.length > 0) { String portName = null; - try + try { println("Get serial port no: "+getSerialPortNumber()); portName = serialPorts[getSerialPortNumber()]; @@ -583,8 +583,8 @@ void setup() } catch (Exception e) { - println("Attempting to connect to serial port " - + portName + " in slot " + getSerialPortNumber() + println("Attempting to connect to serial port " + + portName + " in slot " + getSerialPortNumber() + " caused an exception: " + e.getMessage()); } } @@ -610,54 +610,54 @@ void setup() } void fitDisplayMachineToWindow() { - + Rectangle gr = panels.get(PANEL_NAME_GENERAL).getOutline(); println(gr); - + Rectangle ir = panels.get(PANEL_NAME_INPUT).getOutline(); println(ir); - + float targetHeight = ir.getBottom() - gr.getTop() - CONTROL_SPACING.y; println("Target height is " + targetHeight + " pixels"); - + float machineHeight = getDisplayMachine().getOutline().getHeight(); println(machineHeight); - + machineScaling = (targetHeight / machineHeight); println(machineScaling); - + if (machineScaling < 0) { machineScaling = 1.0; } - + getDisplayMachine().getOffset().x = ((gr.getRight() > ir.getRight()) ? gr.getRight() : ir.getRight()) + CONTROL_SPACING.x; getDisplayMachine().getOffset().y = gr.getTop(); - + } void addEventListeners() { - frame.addComponentListener(new ComponentAdapter() + frame.addComponentListener(new ComponentAdapter() { - public void componentResized(ComponentEvent event) + public void componentResized(ComponentEvent event) { - if (event.getSource()==frame) + if (event.getSource()==frame) { windowResized(); } } } ); - - addMouseWheelListener(new java.awt.event.MouseWheelListener() - { - public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) - { + + addMouseWheelListener(new java.awt.event.MouseWheelListener() + { + public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) + { mouseWheel(evt.getWheelRotation()); } } - ); -} + ); +} void preLoadCommandQueue() @@ -673,13 +673,13 @@ void windowResized() windowWidth = frame.getWidth(); windowHeight = frame.getHeight(); println("New window size: " + windowWidth + " x " + windowHeight); - + for (String key : getPanels().keySet()) { Panel p = getPanels().get(key); p.setSizeByHeight(windowHeight - p.getOutline().getTop() - (DEFAULT_CONTROL_SIZE.y*2)); } - + // Required to tell CP5 to be able to use the new sized window cp5.setGraphics(this,0,0); loop(); @@ -709,7 +709,7 @@ void draw() if (isShowingSummaryOverlay()) { drawSummaryOverlay(); } - + if (isShowingDialogBox()) { drawDialogBox(); } @@ -737,7 +737,7 @@ boolean isShowingDialogBox() } void drawDialogBox() { - + } String getVectorFilename() { @@ -799,7 +799,7 @@ void drawImagePage() getDisplayMachine().draw(); drawMoveImageOutline(); stroke(255, 0, 0); - + for (Panel panel : getPanelsForTab(TAB_NAME_INPUT)) { panel.draw(); @@ -833,7 +833,7 @@ void drawDetailsPage() noFill(); getDisplayMachine().drawForSetup(); stroke(255, 0, 0); - + for (Panel panel : getPanelsForTab(TAB_NAME_DETAILS)) { panel.draw(); @@ -859,7 +859,7 @@ void drawRovingPage() noFill(); getDisplayMachine().drawForSetup(); stroke(255, 0, 0); - + for (Panel panel : getPanelsForTab(TAB_NAME_ROVING)) { panel.draw(); @@ -895,7 +895,7 @@ void drawTracePage() } stroke(255, 0, 0); - + for (Panel panel : getPanelsForTab(TAB_NAME_TRACE)) { panel.draw(); @@ -925,9 +925,9 @@ void drawCommandQueuePage() fill(100); drawMachineOutline(); showingSummaryOverlay = false; + - - + int right = 0; for (Panel panel : getPanelsForTab(TAB_NAME_QUEUE)) { @@ -938,9 +938,9 @@ void drawCommandQueuePage() } text(propertiesFilename, getPanel(PANEL_NAME_GENERAL).getOutline().getLeft(), getPanel(PANEL_NAME_GENERAL).getOutline().getTop()-7); showCommandQueue(right, (int)mainPanelPosition.y); - + drawStatusText((int)statusTextPosition.x, (int)statusTextPosition.y); - + } void drawImageLoadPage() @@ -959,7 +959,7 @@ void drawMoveImageOutline() PVector imageSizeOnScreen = getDisplayMachine().scaleToScreen(imageSize); imageSizeOnScreen.sub(getDisplayMachine().getOutline().getTopLeft()); PVector offset = new PVector(imageSizeOnScreen.x/2.0, imageSizeOnScreen.y/2.0); - + PVector mVect = getMouseVector(); PVector imagePos = new PVector(mVect.x-offset.x, mVect.y-offset.y); @@ -988,7 +988,7 @@ void drawMoveImageOutline() { for (int i = 0; i ins = null; try { ins = unpackGCodeInstruction(line); @@ -1329,7 +1329,7 @@ RShape loadShapeFromGCodeFile(String filename) { if (code >= 2) { continue; } - + Float z = ins.get("Z"); if (z != null) { gCodeZAxisChanges++; @@ -1346,7 +1346,7 @@ RShape loadShapeFromGCodeFile(String filename) { drawLine = false; } } - + Float x = ins.get("X"); Float y = ins.get("Y"); if (x != null && y == null) { @@ -1361,7 +1361,7 @@ RShape loadShapeFromGCodeFile(String filename) { RPoint rp = points[points.length-1][points[points.length-1].length-1]; x = rp.x; } - + if (x != null && y != null) { // move both x and y axis if (drawLine) { @@ -1386,9 +1386,9 @@ RShape loadShapeFromGCodeFile(String filename) { // println("" + totalPoints + " points."); } else { - + } - + if ((millis() - time) > 500) { time = millis(); reportStatus = true; @@ -1396,11 +1396,11 @@ RShape loadShapeFromGCodeFile(String filename) { else { reportStatus = false; } - + if (lineNo == (countLines-1)) { reportStatus = true; } - + } } catch (IOException e) { @@ -1410,13 +1410,13 @@ RShape loadShapeFromGCodeFile(String filename) { finally { try { reader.close(); - } + } catch (IOException e) { println("Exception closing the gcode file " + filename); e.printStackTrace(); } } - + RPoint[][] points = parent.getPointsInPaths(); totalPoints = 0; if (points != null) { @@ -1450,6 +1450,7 @@ Map unpackGCodeInstruction(String line) throws Exception { splitted[i] = splitted[i].replace(";", ""); String axis = splitted[i].substring(0, 1); Float value = Float.parseFloat(splitted[i].substring(1)); + if ("X".equalsIgnoreCase(axis) || "Y".equalsIgnoreCase(axis) || "Z".equalsIgnoreCase(axis) || "G".equalsIgnoreCase(axis)) { instruction.put(axis, value); } @@ -1458,11 +1459,11 @@ Map unpackGCodeInstruction(String line) throws Exception { if (instruction.isEmpty()) { throw new Exception(); } - } - catch (Exception e) { + } + catch (Exception e) { throw new Exception("Exception while reading the lines from a gcode file: " + line + ", " + e.getMessage()); } - + return instruction; } @@ -1489,7 +1490,7 @@ void setBoxToPictureframeDimensions() t = (Toggle) getAllControls().get(MODE_SHOW_DENSITY_PREVIEW); t.setValue(1); t.update(); - + } } @@ -1508,9 +1509,9 @@ void setSampleArea(float v) this.sampleArea = v; } -void controlEvent(ControlEvent controlEvent) +void controlEvent(ControlEvent controlEvent) { - if (controlEvent.isTab()) + if (controlEvent.isTab()) { if (controlEvent.tab().getName() == getCurrentTab()) { @@ -1522,18 +1523,18 @@ void controlEvent(ControlEvent controlEvent) changeTab(currentTab, controlEvent.tab().getName()); } } - else if(controlEvent.isGroup()) + else if(controlEvent.isGroup()) { print("got an event from "+controlEvent.group().getName()+"\t"); - // checkbox uses arrayValue to store the state of + // checkbox uses arrayValue to store the state of // individual checkbox-items. usage: - for (int i=0; i= k) { - return keys[k]; + return keys[k]; } return false; } void keyReleased() -{ - keys[keyCode] = false; +{ + keys[keyCode] = false; } void keyPressed() @@ -1676,18 +1677,18 @@ void keyPressed() //println("key: " + KeyEvent.getKeyText(keyCode)); //println("Keys: " + keys); //println("Keycode: " + keyCode); - - if (checkKey(CONTROL) && checkKey(KeyEvent.VK_PAGE_UP)) + + if (checkKey(CONTROL) && checkKey(KeyEvent.VK_PAGE_UP)) changeMachineScaling(1); - else if (checkKey(CONTROL) && checkKey(KeyEvent.VK_PAGE_DOWN)) + else if (checkKey(CONTROL) && checkKey(KeyEvent.VK_PAGE_DOWN)) changeMachineScaling(-1); else if (checkKey(CONTROL) && checkKey(DOWN)) getDisplayMachine().getOffset().y = getDisplayMachine().getOffset().y + 10; - else if (checkKey(CONTROL) && checkKey(UP)) + else if (checkKey(CONTROL) && checkKey(UP)) getDisplayMachine().getOffset().y = getDisplayMachine().getOffset().y - 10; - else if (checkKey(CONTROL) && checkKey(RIGHT)) + else if (checkKey(CONTROL) && checkKey(RIGHT)) getDisplayMachine().getOffset().x = getDisplayMachine().getOffset().x + 10; - else if (checkKey(CONTROL) && checkKey(LEFT)) + else if (checkKey(CONTROL) && checkKey(LEFT)) getDisplayMachine().getOffset().x = getDisplayMachine().getOffset().x - 10; else if (checkKey(KeyEvent.VK_ESCAPE)) key = 0; @@ -1756,12 +1757,12 @@ void mouseDragged() } } } - + void mouseClicked() { if (mouseOverPanel()) { // changing mode - + } else { @@ -1771,10 +1772,10 @@ void mouseClicked() PVector mVect = getDisplayMachine().scaleToDisplayMachine(getMouseVector()); PVector offset = new PVector(imageSize.x/2.0, imageSize.y/2.0); PVector imagePos = new PVector(mVect.x-offset.x, mVect.y-offset.y); - + imagePos = getDisplayMachine().inSteps(imagePos); getDisplayMachine().getImageFrame().setPosition(imagePos.x, imagePos.y); - + if (getDisplayMachine().pixelsCanBeExtracted() && isBoxSpecified()) getDisplayMachine().extractPixelsFromArea(getBoxVector1(), getBoxVectorSize(), getGridSize(), sampleArea); } @@ -1788,12 +1789,12 @@ void mouseClicked() } else if (mouseOverQueue()) { - // stopping or starting + // stopping or starting println("queue clicked."); queueClicked(); } else if (mouseOverMachine()) - { + { // picking coords machineClicked(); } @@ -1906,17 +1907,17 @@ void leftButtonMachineClick() setChromaKey(getMouseVector()); else if (currentMode.equals(MODE_SEND_START_TEXT)) sendStartTextAtPoint(); - + } -void mouseWheel(int delta) +void mouseWheel(int delta) { changeMachineScaling(delta); -} +} void setChromaKey(PVector p) { - color col = getDisplayMachine().getPixelAtScreenCoords(p); + color col = getDisplayMachine().getPixelAtScreenCoords(p); chromaKeyColour = col; if (getDisplayMachine().pixelsCanBeExtracted() && isBoxSpecified()) { @@ -1926,7 +1927,7 @@ void setChromaKey(PVector p) boolean isPreviewable(String command) { - if (command.startsWith(CMD_CHANGELENGTHDIRECT) + if (command.startsWith(CMD_CHANGELENGTHDIRECT) || command.startsWith(CMD_CHANGELENGTH) || command.startsWith(CMD_DRAWPIXEL)) { @@ -1952,9 +1953,9 @@ boolean toggleShowConsole() { console = null; System.setOut(savedOut); } - + println("Ow"); - + return console == null; } @@ -1973,8 +1974,8 @@ void previewQueue(boolean forceRebuild) { println("regenerating preview queue."); previewCommandList.clear(); - - + + for (String command : commandQueue) { if (command.startsWith(CMD_CHANGELENGTHDIRECT) || command.startsWith(CMD_CHANGELENGTH) || command.startsWith(CMD_DRAWPIXEL)) @@ -1986,27 +1987,27 @@ void previewQueue(boolean forceRebuild) String aLenStr = splitted[1]; String bLenStr = splitted[2]; - + PVector endPoint = new PVector(Integer.parseInt(aLenStr)+previewCordOffset, Integer.parseInt(bLenStr)+previewCordOffset); endPoint = getDisplayMachine().asCartesianCoords(endPoint); endPoint = getDisplayMachine().inMM(endPoint); - + pv.x = endPoint.x; pv.y = endPoint.y; pv.z = -1.0; - + if (command.startsWith(CMD_DRAWPIXEL)) { String densStr = splitted[4]; pv.z = Integer.parseInt(densStr); } - + previewCommandList.add(pv); } } lastCommandQueueHash = commandQueue.hashCode(); } - + for (PreviewVector pv : previewCommandList) { PVector p = (PVector) pv; @@ -2020,10 +2021,10 @@ void previewQueue(boolean forceRebuild) ellipse(p.x, p.y, 20, 20); noFill(); } - + if (pv.command.equals(CMD_CHANGELENGTHDIRECT)) stroke(0); - else + else stroke(200,0,0); line(startPoint.x, startPoint.y, p.x, p.y); startPoint = p; @@ -2045,7 +2046,7 @@ void previewQueue(boolean forceRebuild) ellipse(startPoint.x, startPoint.y, 15,15); noFill(); } - + } boolean isHiddenPixel(PVector p) @@ -2060,7 +2061,7 @@ void sizeImageToFitBox() { PVector boxSize = getDisplayMachine().inSteps(getBoxSize()); PVector boxPos = getDisplayMachine().inSteps(getBoxVector1()); println("image: " + boxSize); - + Rectangle r = new Rectangle(boxPos, boxSize); getDisplayMachine().setImageFrame(r); } @@ -2079,11 +2080,11 @@ void exportQueueToFile(File selection) { 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) { @@ -2118,7 +2119,7 @@ void queueClicked() int relativeCoord = (mouseY-topEdgeOfQueue); int rowClicked = relativeCoord / queueRowHeight; int totalCommands = commandQueue.size()+realtimeCommandQueue.size(); - + if (rowClicked < 1) // its the header - start or stop queue { if (commandQueueRunning) @@ -2140,11 +2141,11 @@ void queueClicked() { if (cmdNumber <= realtimeCommandQueue.size()) realtimeCommandQueue.remove(cmdNumber-1); - else + else { cmdNumber-=(realtimeCommandQueue.size()+1); commandQueue.remove(cmdNumber); - } + } } else { @@ -2212,21 +2213,21 @@ void showText(int xPosOrigin, int yPosOrigin) noStroke(); fill(0, 0, 0, 80); rect(xPosOrigin, yPosOrigin, 220, 550); - - + + textSize(12); fill(255); int tRow = 15; int textPositionX = xPosOrigin+4; int textPositionY = yPosOrigin+4; - + int tRowNo = 1; PVector screenCoordsCart = getMouseVector(); - + text(programTitle, textPositionX, textPositionY+(tRow*tRowNo++)); tRowNo++; text("Cursor position: " + mouseX + ", " + mouseY, textPositionX, textPositionY+(tRow*tRowNo++)); - + text("MM Per Step: " + getDisplayMachine().getMMPerStep(), textPositionX, textPositionY+(tRow*tRowNo++)); text("Steps Per MM: " + getDisplayMachine().getStepsPerMM() ,textPositionX, textPositionY+(tRow*tRowNo++)); @@ -2234,10 +2235,10 @@ void showText(int xPosOrigin, int yPosOrigin) { PVector posOnMachineCartesianInMM = getDisplayMachine().scaleToDisplayMachine(screenCoordsCart); text("Machine x/y mm: " + posOnMachineCartesianInMM.x+","+posOnMachineCartesianInMM.y, textPositionX, textPositionY+(tRow*tRowNo++)); - + PVector posOnMachineNativeInMM = getDisplayMachine().convertToNative(posOnMachineCartesianInMM); text("Machine a/b mm: " + posOnMachineNativeInMM.x+","+posOnMachineNativeInMM.y, textPositionX, textPositionY+(tRow*tRowNo++)); - + PVector posOnMachineNativeInSteps = getDisplayMachine().inSteps(posOnMachineNativeInMM); text("Machine a/b steps: " + posOnMachineNativeInSteps.x+","+posOnMachineNativeInSteps.y, textPositionX, textPositionY+(tRow*tRowNo++)); } @@ -2247,24 +2248,24 @@ void showText(int xPosOrigin, int yPosOrigin) text("Machine a/b mm: --,--", textPositionX, textPositionY+(tRow*tRowNo++)); text("Machine a/b steps: --,--", textPositionX, textPositionY+(tRow*tRowNo++)); } + - - drawStatusText(textPositionX, textPositionY+(tRow*tRowNo++)); - + drawStatusText(textPositionX, textPositionY+(tRow*tRowNo++)); + text(commandStatus, textPositionX, textPositionY+(tRow*tRowNo++)); - + text("Mode: " + currentMode, textPositionX, textPositionY+(tRow*tRowNo++)); // middle side text("Grid size: " + getGridSize(), textPositionX, textPositionY+(tRow*tRowNo++)); - + text("Box width: " + getBoxWidth(), textPositionX, textPositionY+(tRow*tRowNo++)); text("Box height: " + getBoxHeight(), textPositionX, textPositionY+(tRow*tRowNo++)); text("Box offset left: " + getBoxPosition().x, textPositionX, textPositionY+(tRow*tRowNo++)); text("Box offset top: " + getBoxPosition().y, textPositionX, textPositionY+(tRow*tRowNo++)); - + text("Available memory: " + machineAvailMem + " (min: " + machineMinAvailMem +", used: "+ machineUsedMem+")", textPositionX, textPositionY+(tRow*tRowNo++)); text("Time cmd: " + getCurrentPixelTime() + ", total: " + getTimeSoFar(), textPositionX, textPositionY+(tRow*tRowNo++)); @@ -2302,7 +2303,7 @@ void showText(int xPosOrigin, int yPosOrigin) void drawStatusText(int x, int y) { String drawbotStatus = null; - + if (useSerialPortConnection) { if (isDrawbotConnected()) @@ -2326,20 +2327,20 @@ void drawStatusText(int x, int y) if ("".equals(busyDoing)) busyDoing = commandHistory.get(commandHistory.size()-1); drawbotStatus = "BUSY: " + busyDoing; - } + } } else { fill(255, 0, 0); drawbotStatus = "Polargraph is not connected."; - } + } } else { fill(255, 0, 0); drawbotStatus = "No serial connection."; } - + text(drawbotStatus, x, y); fill(255); } @@ -2348,7 +2349,7 @@ void setCommandQueueFont() { textSize(12); fill(255); -} +} void showCommandQueue(int xPos, int yPos) { setCommandQueueFont(); @@ -2363,14 +2364,14 @@ void showCommandQueue(int xPos, int yPos) leftEdgeOfQueue = textPositionX; rightEdgeOfQueue = textPositionX+300; bottomEdgeOfQueue = height; - + drawCommandQueueStatus(textPositionX, commandQueuePos, 14); commandQueuePos+=queueRowHeight; text("Last command: " + ((commandHistory.isEmpty()) ? "-" : commandHistory.get(commandHistory.size()-1)), textPositionX, commandQueuePos); commandQueuePos+=queueRowHeight; text("Current command: " + lastCommand, textPositionX, commandQueuePos); commandQueuePos+=queueRowHeight; - + fill(128,255,255); int queueNumber = commandQueue.size()+realtimeCommandQueue.size(); for (String s : realtimeCommandQueue) @@ -2378,7 +2379,7 @@ void showCommandQueue(int xPos, int yPos) text((queueNumber--)+". "+ s, textPositionX, commandQueuePos); commandQueuePos+=queueRowHeight; } - + fill(255); try { @@ -2399,7 +2400,7 @@ void showCommandQueue(int xPos, int yPos) println("Caught the pesky ConcurrentModificationException: " + cme.getMessage()); } showmachineMessageLog(rightEdgeOfQueue, 20); - + } void drawCommandQueueStatus(int x, int y, int tSize) @@ -2431,7 +2432,7 @@ void showmachineMessageLog(int xPos, int yPos) int pos = textPositionY+(tRow*tRowNo++); pos+=queueRowHeight; - + fill(255); // Write out the commands into the window, stop when you fall off the bottom of the window // Or run out of commands @@ -2583,7 +2584,7 @@ public DisplayMachine getDisplayMachine() { if (displayMachine == null) displayMachine = new DisplayMachine(new Machine(5000, 5000, 200.0, 95.0), machinePosition, machineScaling); - + displayMachine.setOffset(machinePosition); displayMachine.setScale(machineScaling); return displayMachine; @@ -2610,7 +2611,7 @@ void changeHardwareVersionTo(int newVer) { case HARDWARE_VER_MEGA : currentSram = HARDWARE_ATMEGA1280_SRAM; - default : + default : currentSram = HARDWARE_ATMEGA328_SRAM; } // windowResized(); @@ -2636,14 +2637,14 @@ void setHardwareVersionFromIncoming(String readyString) println("Bad format for hardware version - defaulting to ATMEGA328 (Uno)"); verInt = HARDWARE_VER_UNO; } - - if (HARDWARE_VER_MEGA == verInt + + if (HARDWARE_VER_MEGA == verInt || HARDWARE_VER_MEGA_POLARSHIELD == verInt) newHardwareVersion = verInt; else newHardwareVersion = HARDWARE_VER_UNO; } - + // now see if it's different to last time. if (newHardwareVersion != currentHardware) { @@ -2652,15 +2653,15 @@ void setHardwareVersionFromIncoming(String readyString) } } -void serialEvent(Serial myPort) -{ +void serialEvent(Serial myPort) +{ // read the serial buffer: String incoming = myPort.readStringUntil('\n'); myPort.clear(); // if you got any bytes other than the linefeed: incoming = trim(incoming); println("incoming: " + incoming); - + if (incoming.startsWith("READY")) { drawbotReady = true; @@ -2686,14 +2687,14 @@ void serialEvent(Serial myPort) readPenLiftRange(incoming); else if (incoming.startsWith("PGSPEED")) readMachineSpeed(incoming); - + else if ("RESEND".equals(incoming)) resendLastCommand(); else if ("DRAWING".equals(incoming)) drawbotReady = false; else if (incoming.startsWith("MEMORY")) extractMemoryUsage(incoming); - + else if (incoming.startsWith("BUTTON")) handleMachineButton(incoming); @@ -2724,10 +2725,10 @@ void readMachineMessage(String msg) String type = msg.substring(0,1); msg = msg.substring(2, msg.length()); String timestamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); - + msg = type + timestamp + " " + msg; machineMessageLog.add(msg); - if (machineMessageLog.size() > 200) + if (machineMessageLog.size() > 200) { machineMessageLog.remove(0); } @@ -2743,7 +2744,7 @@ void readMachinePosition(String sync) Float a = Float.valueOf(currentAPos).floatValue(); Float b = Float.valueOf(currentBPos).floatValue(); currentMachinePos.x = a; - currentMachinePos.y = b; + currentMachinePos.y = b; currentMachinePos = getDisplayMachine().inMM(getDisplayMachine().asCartesianCoords(currentMachinePos)); } } @@ -2757,7 +2758,7 @@ void readCartesianMachinePosition(String sync) Float a = Float.valueOf(currentAPos).floatValue(); Float b = Float.valueOf(currentBPos).floatValue(); currentCartesianMachinePos.x = a; - currentCartesianMachinePos.y = b; + currentCartesianMachinePos.y = b; } } @@ -2767,7 +2768,7 @@ void readMmPerRev(String in) if (splitted.length == 3) { String mmStr = splitted[1]; - + float mmPerRev = Float.parseFloat(mmStr); getDisplayMachine().setMMPerRev(mmPerRev); updateNumberboxValues(); @@ -2780,7 +2781,7 @@ void readStepsPerRev(String in) if (splitted.length == 3) { String stepsStr = splitted[1]; - + Float stepsPerRev = Float.parseFloat(stepsStr); getDisplayMachine().setStepsPerRev(stepsPerRev); updateNumberboxValues(); @@ -2793,7 +2794,7 @@ void readStepMultiplier(String in) if (splitted.length == 3) { String stepsStr = splitted[1]; - + machineStepMultiplier = Integer.parseInt(stepsStr); updateNumberboxValues(); } @@ -2807,13 +2808,13 @@ void readMachineSize(String in) { String mWidth = splitted[1]; String mHeight = splitted[2]; - + Integer intWidth = Integer.parseInt(mWidth); Integer intHeight = Integer.parseInt(mHeight); - + float fWidth = getDisplayMachine().inSteps(intWidth); float fHeight = getDisplayMachine().inSteps(intHeight); - + getDisplayMachine().setSize(int(fWidth+0.5), int(fHeight+0.5)); updateNumberboxValues(); } @@ -2825,7 +2826,7 @@ void readMachineName(String sync) if (splitted.length == 3) { String name = splitted[1]; - + } } @@ -2836,10 +2837,10 @@ void readMachineSpeed(String in) { String speed = splitted[1]; String accel = splitted[2]; - + currentMachineMaxSpeed = Float.parseFloat(speed); currentMachineAccel = Float.parseFloat(accel); - + updateNumberboxValues(); } } @@ -2851,7 +2852,7 @@ void readPenLiftRange(String in) { String downPos = splitted[1]; String upPos = splitted[2]; - + penLiftDownPosition = Integer.parseInt(downPos); penLiftUpPosition = Integer.parseInt(upPos); @@ -2868,7 +2869,7 @@ void resendLastCommand() void dispatchCommandQueue() { - if (isDrawbotReady() + if (isDrawbotReady() && (!commandQueue.isEmpty() || !realtimeCommandQueue.isEmpty()) && commandQueueRunning) { @@ -2903,7 +2904,7 @@ void dispatchCommandQueue() else if (commandQueue.isEmpty()) { stopPixelTimer(); - } + } } void addToCommandQueue(String command) @@ -2950,7 +2951,7 @@ Properties getProperties() { props = new Properties(); String fileToLoad = sketchPath(propertiesFilename); - + File propertiesFile = new File(fileToLoad); if (!propertiesFile.exists()) { @@ -2958,7 +2959,7 @@ Properties getProperties() savePropertiesFile(); println("saved."); } - + propertiesFileStream = new FileInputStream(propertiesFile); props.load(propertiesFileStream); println("Successfully loaded properties file " + fileToLoad); @@ -2970,11 +2971,11 @@ Properties getProperties() } finally { - try - { + try + { propertiesFileStream.close(); } - catch (Exception e) + catch (Exception e) { println("Exception: "+e.getMessage()); }; @@ -3001,7 +3002,7 @@ void loadFromPropertiesFile() this.currentMachineMaxSpeed = getFloatProperty("machine.motors.maxSpeed", 2000.0); this.currentMachineAccel = getFloatProperty("machine.motors.accel", 2000.0); this.machineStepMultiplier = getIntProperty("machine.step.multiplier", 8); - + // serial port this.serialPortNumber = getIntProperty("controller.machine.serialport", 0); this.baudRate = getIntProperty("controller.machine.baudrate", 57600); @@ -3010,25 +3011,25 @@ void loadFromPropertiesFile() this.gridSize = getFloatProperty("controller.grid.size", 100.0); this.sampleArea = getIntProperty("controller.pixel.samplearea", 2); this.pixelScalingOverGridSize = getFloatProperty("controller.pixel.scaling", 1.0); - + // pixel renderer this.densityPreviewStyle = getIntProperty("controller.density.preview.style", 1); - + // initial screen size this.windowWidth = getIntProperty("controller.window.width", 650); this.windowHeight = getIntProperty("controller.window.height", 400); - + println("windowHeight:" + this.windowHeight); this.testPenWidthStartSize = getFloatProperty("controller.testPenWidth.startSize", 0.5); this.testPenWidthEndSize = getFloatProperty("controller.testPenWidth.endSize", 2.0); this.testPenWidthIncrementSize = getFloatProperty("controller.testPenWidth.incrementSize", 0.5); - + this.maxSegmentLength = getIntProperty("controller.maxSegmentLength", 2); - + float homePointX = getFloatProperty("controller.homepoint.x", 0.0); float homePointY = getFloatProperty("controller.homepoint.y", 0.0); - + if (homePointX == 0.0) { float defaultX = getDisplayMachine().getWidth() / 2.0; // in steps @@ -3039,7 +3040,7 @@ void loadFromPropertiesFile() } this.homePointCartesian = new PVector(getDisplayMachine().inSteps(homePointX), getDisplayMachine().inSteps(homePointY)); // println("home point loaded: " + homePointCartesian + ", " + getHomePoint()); - + setVectorFilename(getStringProperty("controller.vector.filename", null)); if (getVectorFilename() != null) { @@ -3052,12 +3053,12 @@ void loadFromPropertiesFile() { shape = null; } - - if (shape != null) + + if (shape != null) { setVectorShape(shape); } - else + else { println("File not found (" + getVectorFilename() + ")"); } @@ -3068,20 +3069,20 @@ void loadFromPropertiesFile() this.minimumVectorLineLength = getIntProperty("controller.vector.minLineLength", 0); - + println("Finished loading configuration from properties file."); } void savePropertiesFile() { Properties props = new Properties(); - + props = getDisplayMachine().loadDefinitionIntoProperties(props); NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK); - DecimalFormat df = (DecimalFormat)nf; + DecimalFormat df = (DecimalFormat)nf; df.applyPattern("###.##"); - + props.setProperty("controller.page.colour", hex(this.pageColour, 6)); props.setProperty("controller.frame.colour", hex(this.frameColour,6)); props.setProperty("controller.machine.colour", hex(this.machineColour,6)); @@ -3089,7 +3090,7 @@ void savePropertiesFile() props.setProperty("controller.background.colour", hex(this.backgroundColour,6)); props.setProperty("controller.densitypreview.colour", hex(this.densityPreviewColour,6)); - + // pen size props.setProperty("machine.pen.size", df.format(currentPenWidth)); // serial port @@ -3111,37 +3112,37 @@ void savePropertiesFile() props.setProperty("controller.testPenWidth.startSize", df.format(testPenWidthStartSize)); props.setProperty("controller.testPenWidth.endSize", df.format(testPenWidthEndSize)); props.setProperty("controller.testPenWidth.incrementSize", df.format(testPenWidthIncrementSize)); - + props.setProperty("controller.maxSegmentLength", new Integer(getMaxSegmentLength()).toString()); - + props.setProperty("machine.motors.maxSpeed", df.format(currentMachineMaxSpeed)); props.setProperty("machine.motors.accel", df.format(currentMachineAccel)); props.setProperty("machine.step.multiplier", new Integer(machineStepMultiplier).toString()); - + props.setProperty("controller.pixel.mask.color", hex(this.chromaKeyColour, 6)); - - PVector hp = null; + + PVector hp = null; if (getHomePoint() != null) { hp = getHomePoint(); } else hp = new PVector(2000.0, 1000.0); - + hp = getDisplayMachine().inMM(hp); - + props.setProperty("controller.homepoint.x", df.format(hp.x)); props.setProperty("controller.homepoint.y", df.format(hp.y)); - + if (getVectorFilename() != null) props.setProperty("controller.vector.filename", getVectorFilename()); - + props.setProperty("controller.vector.scaling", df.format(vectorScaling)); props.setProperty("controller.vector.position.x", df.format(getVectorPosition().x)); props.setProperty("controller.vector.position.y", df.format(getVectorPosition().y)); props.setProperty("controller.vector.minLineLength", new Integer(this.minimumVectorLineLength).toString()); - + FileOutputStream propertiesOutput = null; try @@ -3183,19 +3184,19 @@ void savePropertiesFile() } } -boolean getBooleanProperty(String id, boolean defState) +boolean getBooleanProperty(String id, boolean defState) { return boolean(getProperties().getProperty(id,""+defState)); } - -int getIntProperty(String id, int defVal) + +int getIntProperty(String id, int defVal) { - return int(getProperties().getProperty(id,""+defVal)); + return int(getProperties().getProperty(id,""+defVal)); } - -float getFloatProperty(String id, float defVal) + +float getFloatProperty(String id, float defVal) { - return float(getProperties().getProperty(id,""+defVal)); + return float(getProperties().getProperty(id,""+defVal)); } String getStringProperty(String id, String defVal) { @@ -3209,7 +3210,7 @@ color getColourProperty(String id, color defVal) { col = defVal; } - + if (colStr.length() == 1) { // single value grey @@ -3225,7 +3226,7 @@ color getColourProperty(String id, color defVal) d1 = d1+d1; d2 = d2+d2; d3 = d3+d3; - + col = color(unhex(d1), unhex(d2), unhex(d3)); } else if (colStr.length() == 6) @@ -3234,10 +3235,10 @@ color getColourProperty(String id, color defVal) String d1 = colStr.substring(0,2); String d2 = colStr.substring(2,4); String d3 = colStr.substring(4,6); - + col = color(unhex(d1), unhex(d2), unhex(d3)); } - + return col; } @@ -3262,7 +3263,7 @@ void setOverwriteExistingStoreFile(boolean over) { this.overwriteExistingStoreFile = over; } - + void initProperties() { getProperties(); @@ -3324,7 +3325,7 @@ PImage makeColourImage(int w, int h, int colour) { PImage img = createImage(w,h,RGB); for(int i=0; i < img.pixels.length; i++) { - img.pixels[i] = colour; + img.pixels[i] = colour; } return img; } From a7f37d85530434fb4650e9060d62326129ee0ee7 Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Wed, 30 Mar 2016 12:45:40 +0100 Subject: [PATCH 6/9] Updated a couple of bits in @jerabina 's pull request --- polargraphcontroller.pde | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index 3109b8d..efac169 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 = 1; String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo; ControlP5 cp5; @@ -149,8 +149,8 @@ List machineMessageLog = new ArrayList(); List previewCommandList = new ArrayList(); long lastCommandQueueHash = 0L; -File LastImageDir = null; -File LastPrefDir = null; +File lastImageDirectory = null; +File lastPropertiesDirectory = null; String lastCommand = ""; String lastDrawingCommand = ""; @@ -1074,13 +1074,13 @@ void loadImageWithFileChooser() { public void run() { JFileChooser fc = new JFileChooser(); - if (LastImageDir != null) fc.setCurrentDirectory(LastImageDir); + if (lastImageDirectory != null) fc.setCurrentDirectory(lastImageDirectory); fc.setFileFilter(new ImageFileFilter()); fc.setDialogTitle("Choose an image file..."); int returned = fc.showOpenDialog(frame); - LastImageDir = fc.getCurrentDirectory(); + lastImageDirectory = fc.getCurrentDirectory(); if (returned == JFileChooser.APPROVE_OPTION) { @@ -1122,16 +1122,15 @@ void loadVectorWithFileChooser() { public void run() { JFileChooser fc = new JFileChooser(); - - if (LastImageDir != null) fc.setCurrentDirectory(LastImageDir); + if (lastImageDirectory != null) + { + fc.setCurrentDirectory(lastImageDirectory); + } fc.setFileFilter(new VectorFileFilter()); - fc.setDialogTitle("Choose a vector file..."); - int returned = fc.showOpenDialog(frame); - - LastImageDir = fc.getCurrentDirectory(); + lastImageDirectory = fc.getCurrentDirectory(); if (returned == JFileChooser.APPROVE_OPTION) { @@ -1160,7 +1159,7 @@ class VectorFileFilter extends javax.swing.filechooser.FileFilter public boolean accept(File file) { String filename = file.getName(); filename.toLowerCase(); - if (file.isDirectory() || filename.endsWith(".svg") || filename.endsWith(".gcode") || filename.endsWith(".g") || filename.endsWith(".ngc") || filename.endsWith(".txt")) + if (file.isDirectory() || filename.endsWith(".svg") || isGCodeExtension(filename)) return true; else return false; @@ -1177,14 +1176,14 @@ void loadNewPropertiesFilenameWithFileChooser() public void run() { JFileChooser fc = new JFileChooser(); - if (LastPrefDir != null) fc.setCurrentDirectory(LastPrefDir); + if (lastPropertiesDirectory != null) fc.setCurrentDirectory(lastPropertiesDirectory); fc.setFileFilter(new PropertiesFileFilter()); fc.setDialogTitle("Choose a config file..."); int returned = fc.showOpenDialog(frame); - LastPrefDir = fc.getCurrentDirectory(); + lastPropertiesDirectory = fc.getCurrentDirectory(); if (returned == JFileChooser.APPROVE_OPTION) { @@ -1229,7 +1228,7 @@ void saveNewPropertiesFileWithFileChooser() public void run() { JFileChooser fc = new JFileChooser(); - if (LastPrefDir != null) fc.setCurrentDirectory(LastPrefDir); + if (lastPropertiesDirectory != null) fc.setCurrentDirectory(lastPropertiesDirectory); fc.setFileFilter(new PropertiesFileFilter()); fc.setDialogTitle("Enter a config file name..."); @@ -1261,12 +1260,18 @@ RShape loadShapeFromFile(String filename) { if (filename.toLowerCase().endsWith(".svg")) { sh = RG.loadShape(filename); } - else if (filename.toLowerCase().endsWith(".gcode") || filename.toLowerCase().endsWith(".g") || filename.toLowerCase().endsWith(".ngc") || filename.toLowerCase().endsWith(".txt")) { + else if (isGCodeExtension(filename)) { sh = loadShapeFromGCodeFile(filename); } return sh; } + +boolean isGCodeExtension(String filename) { + return (filename.toLowerCase().endsWith(".gcode") || filename.toLowerCase().endsWith(".g") || filename.toLowerCase().endsWith(".ngc") || filename.toLowerCase().endsWith(".txt")); +} + + int countLines(String filename) throws IOException { InputStream is = new BufferedInputStream(new FileInputStream(filename)); try { From 7da0e7e378a9e7bfca1665b03fc673d814dc95ba Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Mon, 17 Apr 2017 22:33:57 +0100 Subject: [PATCH 7/9] #14 converted serial port radio button to dropdown control - still has debug code in place because I don't have multiple serial ports to test with on home pc. --- SerialPortWindow.pde | 43 +++++++++++++++++++++++----------------- polargraphcontroller.pde | 36 +++++++++++++++++++++------------ 2 files changed, 48 insertions(+), 31 deletions(-) diff --git a/SerialPortWindow.pde b/SerialPortWindow.pde index 740bff4..1203514 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,43 @@ ControlFrameSimple addSerialPortControlFrame(String theName, int theWidth, int t } catch(Exception e) { } - - // set up controls - RadioButton r = p.cp5().addRadioButton("radio_serialPort") + + ScrollableList sl = p.cp5().addScrollableList("dropdown_serialPort") .setPosition(10, 10) - .setSize(15, 15) - .setSpacingRow(5) - .plugTo(this, "radio_serialPort"); + .setSize(150, 100) + .setBarHeight(20) + .setItemHeight(20) + .plugTo(this, "dropdown_serialPort"); - r.addItem("No serial connection", -1); - - String[] ports = Serial.list(); + sl.addItem("No serial connection", -1); + String[] ports = {"a", "b", "c", "d", "e", "f", "g", "h"}; + //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"); + + + if (newSerialPort == -2) { } diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index efac169..3be66f8 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -58,7 +58,7 @@ import java.lang.reflect.Method; int majorVersionNo = 2; int minorVersionNo = 4; -int buildNo = 1; +int buildNo = 2; String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo; ControlP5 cp5; @@ -573,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()); @@ -684,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() { @@ -997,7 +1007,9 @@ void drawMoveImageOutline() PVector offsetMouseVector = PVector.sub(getDisplayMachine().scaleToDisplayMachine(getMouseVector()), centroid); if (pointPaths != null) { - for (int i = 0; i Date: Thu, 20 Apr 2017 23:30:31 +0100 Subject: [PATCH 8/9] #14 Serial port now choosable --- SerialPortWindow.pde | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/SerialPortWindow.pde b/SerialPortWindow.pde index 1203514..09b02a8 100644 --- a/SerialPortWindow.pde +++ b/SerialPortWindow.pde @@ -38,8 +38,7 @@ ControlFrameSimple addSerialPortControlFrame(String theName, int theWidth, int t sl.addItem("No serial connection", -1); - String[] ports = {"a", "b", "c", "d", "e", "f", "g", "h"}; - //Serial.list(); + String[] ports = Serial.list(); for (int i = 0; i < ports.length; i++) { println("Adding " + ports[i]); @@ -61,8 +60,8 @@ ControlFrameSimple addSerialPortControlFrame(String theName, int theWidth, int t void dropdown_serialPort(int newSerialPort) { - println("In dropdown_serialPort"); - + println("In dropdown_serialPort, newSerialPort: " + newSerialPort); + newSerialPort -= 1; if (newSerialPort == -2) From 936d918402d764d692e85e7d9cfaba4778eb49b9 Mon Sep 17 00:00:00 2001 From: MurKit Date: Fri, 21 Apr 2017 01:35:17 +0300 Subject: [PATCH 9/9] Dropdown selects the actual selected port (#15) Also mentioned against issue #14. --- SerialPortWindow.pde | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/SerialPortWindow.pde b/SerialPortWindow.pde index 09b02a8..98f8d8d 100644 --- a/SerialPortWindow.pde +++ b/SerialPortWindow.pde @@ -31,9 +31,9 @@ ControlFrameSimple addSerialPortControlFrame(String theName, int theWidth, int t ScrollableList sl = p.cp5().addScrollableList("dropdown_serialPort") .setPosition(10, 10) - .setSize(150, 100) + .setSize(150, 150) .setBarHeight(20) - .setItemHeight(20) + .setItemHeight(16) .plugTo(this, "dropdown_serialPort"); sl.addItem("No serial connection", -1); @@ -61,9 +61,11 @@ ControlFrameSimple addSerialPortControlFrame(String theName, int theWidth, int t void dropdown_serialPort(int newSerialPort) { 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) { }