diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index 67c36d6..3109b8d 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 = ""; @@ -1072,11 +1074,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(); @@ -1117,11 +1122,17 @@ 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(); @@ -1149,7 +1160,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; @@ -1166,11 +1177,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(); @@ -1214,6 +1229,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..."); @@ -1245,7 +1261,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; @@ -1441,17 +1457,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) { throw new Exception("Exception while reading the lines from a gcode file: " + line + ", " + e.getMessage()); }