mirror of
https://github.com/euphy/polargraphcontroller
synced 2025-01-09 19:55:16 +01:00
Merge pull request #9 from jerabina/patch-1
remembering last directory, gcode file extensions, unpackGCodeInstruction repair loading Gcode the character ; at the end of the line
This commit is contained in:
commit
6b49794cc1
@ -149,6 +149,8 @@ List<String> machineMessageLog = new ArrayList<String>();
|
|||||||
List<PreviewVector> previewCommandList = new ArrayList<PreviewVector>();
|
List<PreviewVector> previewCommandList = new ArrayList<PreviewVector>();
|
||||||
long lastCommandQueueHash = 0L;
|
long lastCommandQueueHash = 0L;
|
||||||
|
|
||||||
|
File LastImageDir = null;
|
||||||
|
File LastPrefDir = null;
|
||||||
|
|
||||||
String lastCommand = "";
|
String lastCommand = "";
|
||||||
String lastDrawingCommand = "";
|
String lastDrawingCommand = "";
|
||||||
@ -1072,11 +1074,14 @@ void loadImageWithFileChooser()
|
|||||||
{
|
{
|
||||||
public void run() {
|
public void run() {
|
||||||
JFileChooser fc = new JFileChooser();
|
JFileChooser fc = new JFileChooser();
|
||||||
|
if (LastImageDir != null) fc.setCurrentDirectory(LastImageDir);
|
||||||
fc.setFileFilter(new ImageFileFilter());
|
fc.setFileFilter(new ImageFileFilter());
|
||||||
|
|
||||||
fc.setDialogTitle("Choose an image file...");
|
fc.setDialogTitle("Choose an image file...");
|
||||||
|
|
||||||
int returned = fc.showOpenDialog(frame);
|
int returned = fc.showOpenDialog(frame);
|
||||||
|
|
||||||
|
LastImageDir = fc.getCurrentDirectory();
|
||||||
|
|
||||||
if (returned == JFileChooser.APPROVE_OPTION)
|
if (returned == JFileChooser.APPROVE_OPTION)
|
||||||
{
|
{
|
||||||
File file = fc.getSelectedFile();
|
File file = fc.getSelectedFile();
|
||||||
@ -1117,11 +1122,17 @@ void loadVectorWithFileChooser()
|
|||||||
{
|
{
|
||||||
public void run() {
|
public void run() {
|
||||||
JFileChooser fc = new JFileChooser();
|
JFileChooser fc = new JFileChooser();
|
||||||
|
|
||||||
|
if (LastImageDir != null) fc.setCurrentDirectory(LastImageDir);
|
||||||
|
|
||||||
fc.setFileFilter(new VectorFileFilter());
|
fc.setFileFilter(new VectorFileFilter());
|
||||||
|
|
||||||
fc.setDialogTitle("Choose a vector file...");
|
fc.setDialogTitle("Choose a vector file...");
|
||||||
|
|
||||||
int returned = fc.showOpenDialog(frame);
|
int returned = fc.showOpenDialog(frame);
|
||||||
|
|
||||||
|
LastImageDir = fc.getCurrentDirectory();
|
||||||
|
|
||||||
if (returned == JFileChooser.APPROVE_OPTION)
|
if (returned == JFileChooser.APPROVE_OPTION)
|
||||||
{
|
{
|
||||||
File file = fc.getSelectedFile();
|
File file = fc.getSelectedFile();
|
||||||
@ -1149,7 +1160,7 @@ class VectorFileFilter extends javax.swing.filechooser.FileFilter
|
|||||||
public boolean accept(File file) {
|
public boolean accept(File file) {
|
||||||
String filename = file.getName();
|
String filename = file.getName();
|
||||||
filename.toLowerCase();
|
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;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
@ -1166,11 +1177,15 @@ void loadNewPropertiesFilenameWithFileChooser()
|
|||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
JFileChooser fc = new JFileChooser();
|
JFileChooser fc = new JFileChooser();
|
||||||
|
if (LastPrefDir != null) fc.setCurrentDirectory(LastPrefDir);
|
||||||
fc.setFileFilter(new PropertiesFileFilter());
|
fc.setFileFilter(new PropertiesFileFilter());
|
||||||
|
|
||||||
fc.setDialogTitle("Choose a config file...");
|
fc.setDialogTitle("Choose a config file...");
|
||||||
|
|
||||||
int returned = fc.showOpenDialog(frame);
|
int returned = fc.showOpenDialog(frame);
|
||||||
|
|
||||||
|
LastPrefDir = fc.getCurrentDirectory();
|
||||||
|
|
||||||
if (returned == JFileChooser.APPROVE_OPTION)
|
if (returned == JFileChooser.APPROVE_OPTION)
|
||||||
{
|
{
|
||||||
File file = fc.getSelectedFile();
|
File file = fc.getSelectedFile();
|
||||||
@ -1214,6 +1229,7 @@ void saveNewPropertiesFileWithFileChooser()
|
|||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
JFileChooser fc = new JFileChooser();
|
JFileChooser fc = new JFileChooser();
|
||||||
|
if (LastPrefDir != null) fc.setCurrentDirectory(LastPrefDir);
|
||||||
fc.setFileFilter(new PropertiesFileFilter());
|
fc.setFileFilter(new PropertiesFileFilter());
|
||||||
|
|
||||||
fc.setDialogTitle("Enter a config file name...");
|
fc.setDialogTitle("Enter a config file name...");
|
||||||
@ -1245,7 +1261,7 @@ RShape loadShapeFromFile(String filename) {
|
|||||||
if (filename.toLowerCase().endsWith(".svg")) {
|
if (filename.toLowerCase().endsWith(".svg")) {
|
||||||
sh = RG.loadShape(filename);
|
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);
|
sh = loadShapeFromGCodeFile(filename);
|
||||||
}
|
}
|
||||||
return sh;
|
return sh;
|
||||||
@ -1441,13 +1457,16 @@ Map<String, Float> unpackGCodeInstruction(String line) throws Exception {
|
|||||||
try {
|
try {
|
||||||
String[] splitted = line.trim().split(" ");
|
String[] splitted = line.trim().split(" ");
|
||||||
for (int i = 0; i < splitted.length; i++) {
|
for (int i = 0; i < splitted.length; i++) {
|
||||||
|
// remove ; character
|
||||||
|
splitted[i] = splitted[i].replace(";", "");
|
||||||
String axis = splitted[i].substring(0, 1);
|
String axis = splitted[i].substring(0, 1);
|
||||||
Float value = Float.parseFloat(splitted[i].substring(1));
|
Float value = Float.parseFloat(splitted[i].substring(1));
|
||||||
|
|
||||||
if ("X".equalsIgnoreCase(axis) || "Y".equalsIgnoreCase(axis) || "Z".equalsIgnoreCase(axis) || "G".equalsIgnoreCase(axis)) {
|
if ("X".equalsIgnoreCase(axis) || "Y".equalsIgnoreCase(axis) || "Z".equalsIgnoreCase(axis) || "G".equalsIgnoreCase(axis)) {
|
||||||
instruction.put(axis, value);
|
instruction.put(axis, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// println("instruction: " + instruction);
|
// println("instruction: " + instruction);
|
||||||
if (instruction.isEmpty()) {
|
if (instruction.isEmpty()) {
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user