Added density preview cycling

This commit is contained in:
Sandy Noble 2015-10-24 22:12:44 +01:00
parent 3b5648085c
commit 4b3f7c5edd
3 changed files with 67 additions and 19 deletions

View File

@ -725,4 +725,14 @@ void numberbox_mode_previewCordOffsetValue(int value)
previewQueue(true); previewQueue(true);
} }
void button_mode_cycleDensityPreviewStyle()
{
if (densityPreviewStyle == DENSITY_PREVIEW_STYLE_COUNT) {
densityPreviewStyle = 0;
}
else {
densityPreviewStyle++;
}
}

View File

@ -493,6 +493,10 @@ Map<String, Controller> initialiseNumberboxValues(Map<String, Controller> map)
n.setValue(0); n.setValue(0);
n.setMultiplier(0.5); n.setMultiplier(0.5);
} }
else if (MODE_CYCLE_DENSITY_PREVIEW_STYLE.equals(key))
{
n.setValue(densityPreviewStyle);
}
} }
} }
return map; return map;
@ -665,7 +669,8 @@ List<String> getControlNamesForInputPanel()
controlNames.add(MODE_CHANGE_SAMPLE_AREA); controlNames.add(MODE_CHANGE_SAMPLE_AREA);
controlNames.add(MODE_CHOOSE_CHROMA_KEY_COLOUR); controlNames.add(MODE_CHOOSE_CHROMA_KEY_COLOUR);
controlNames.add(MODE_CHANGE_PIXEL_SCALING); controlNames.add(MODE_CHANGE_PIXEL_SCALING);
controlNames.add(MODE_CYCLE_DENSITY_PREVIEW_STYLE);
controlNames.add(MODE_RENDER_PIXEL_DIALOG); controlNames.add(MODE_RENDER_PIXEL_DIALOG);
// controlNames.add(MODE_DRAW_GRID); // controlNames.add(MODE_DRAW_GRID);
controlNames.add(MODE_DRAW_OUTLINE_BOX); controlNames.add(MODE_DRAW_OUTLINE_BOX);
@ -953,6 +958,8 @@ Map<String, String> buildControlLabels()
result.put(MODE_SEND_BUTTON_DEACTIVATE, "Deactivate button"); result.put(MODE_SEND_BUTTON_DEACTIVATE, "Deactivate button");
result.put(MODE_ADJUST_PREVIEW_CORD_OFFSET, "Cord offset"); result.put(MODE_ADJUST_PREVIEW_CORD_OFFSET, "Cord offset");
result.put(MODE_CYCLE_DENSITY_PREVIEW_STYLE, "Preview style");
return result; return result;
@ -1098,6 +1105,7 @@ Set<String> buildControlNames()
result.add(MODE_SEND_BUTTON_DEACTIVATE); result.add(MODE_SEND_BUTTON_DEACTIVATE);
result.add(MODE_ADJUST_PREVIEW_CORD_OFFSET); result.add(MODE_ADJUST_PREVIEW_CORD_OFFSET);
result.add(MODE_CYCLE_DENSITY_PREVIEW_STYLE);
return result; return result;
} }

View File

@ -340,6 +340,8 @@ static final String MODE_SEND_BUTTON_DEACTIVATE = "button_mode_sendButtonDeactiv
static final String MODE_ADJUST_PREVIEW_CORD_OFFSET = "numberbox_mode_previewCordOffsetValue"; static final String MODE_ADJUST_PREVIEW_CORD_OFFSET = "numberbox_mode_previewCordOffsetValue";
static final String MODE_CYCLE_DENSITY_PREVIEW_STYLE = "button_mode_cycleDensityPreviewStyle";
PVector statusTextPosition = new PVector(300.0, 12.0); PVector statusTextPosition = new PVector(300.0, 12.0);
@ -374,6 +376,8 @@ boolean displayingDensityPreview = false;
boolean displayingGuides = true; boolean displayingGuides = true;
static final int DENSITY_PREVIEW_STYLE_COUNT = 6;
static final int DENSITY_PREVIEW_ROUND = 0; static final int DENSITY_PREVIEW_ROUND = 0;
static final int DENSITY_PREVIEW_DIAMOND = 1; static final int DENSITY_PREVIEW_DIAMOND = 1;
static final int DENSITY_PREVIEW_NATIVE = 2; static final int DENSITY_PREVIEW_NATIVE = 2;
@ -1218,7 +1222,7 @@ int countLines(String filename) throws IOException {
} }
} }
} }
return (count == 0 && !empty) ? 1 : count; return (count == 0 && !empty) ? 1 : count+1;
} finally { } finally {
is.close(); is.close();
} }
@ -1230,10 +1234,14 @@ RShape loadShapeFromGCodeFile(String filename) {
BufferedReader reader = null; BufferedReader reader = null;
long totalPoints = 0; long totalPoints = 0;
long time = millis(); long time = millis();
long countLines = 0;
try { try {
long countLines = countLines(filename); countLines = countLines(filename);
println("" + countLines + " lines found."); println("" + countLines + " lines found.");
if (countLines < 1) {
throw new IOException("No lines found in GCode file.");
}
reader = createReader(filename); reader = createReader(filename);
parent = new RShape(); parent = new RShape();
String line; String line;
@ -1242,28 +1250,30 @@ RShape loadShapeFromGCodeFile(String filename) {
long lineNo = 0; long lineNo = 0;
float lastPercent = 0.0f; float lastPercent = 0.0f;
boolean reportStatus = true;
while ((line = reader.readLine ()) != null) { while ((line = reader.readLine ()) != null) {
lineNo++; lineNo++;
if (reportStatus) {
float percent = ((float)lineNo / (float)countLines) * 100.0;
println("----" + percent + "% of the way through.");
lastPercent = percent;
}
if (line.toUpperCase().startsWith("G")) { if (line.toUpperCase().startsWith("G")) {
if ((millis() - time) > 500) { if (reportStatus) {
println(new StringBuilder().append(lineNo).append(" of ").append(countLines).append(": ").append(line).append(". Points: ").append(totalPoints).toString()); println(new StringBuilder().append(lineNo).append(" of ").append(countLines).append(": ").append(line).append(". Points: ").append(totalPoints).toString());
long free = Runtime.getRuntime().freeMemory(); long free = Runtime.getRuntime().freeMemory();
long maximum = Runtime.getRuntime().maxMemory(); long maximum = Runtime.getRuntime().maxMemory();
println(new StringBuilder().append("Free: ").append(free).append(", max: ").append(maximum).toString()); println(new StringBuilder().append("Free: ").append(free).append(", max: ").append(maximum).toString());
time = millis();
} }
// float percent = (lineNo / countLines) * 100;
// if (percent != lastPercent) {
// println("" + percent + "% of the way through.");
// lastPercent = percent;
// }
Map<String, Float> ins = null; Map<String, Float> ins = null;
try { try {
ins = unpackGCodeInstruction(line); ins = unpackGCodeInstruction(line);
} }
catch (Exception e) { catch (Exception e) {
println("Exception while unpacking a gcode line " + line); println(e.toString());
continue; continue;
} }
Integer code = Math.round(ins.get("G")); Integer code = Math.round(ins.get("G"));
@ -1271,7 +1281,6 @@ RShape loadShapeFromGCodeFile(String filename) {
continue; continue;
} }
Float z = ins.get("Z"); Float z = ins.get("Z");
if (z != null) { if (z != null) {
gCodeZAxisChanges++; gCodeZAxisChanges++;
@ -1327,12 +1336,28 @@ RShape loadShapeFromGCodeFile(String filename) {
// points = null; // points = null;
// println("" + totalPoints + " points."); // println("" + totalPoints + " points.");
} }
else {
}
if ((millis() - time) > 500) {
time = millis();
reportStatus = true;
}
else {
reportStatus = false;
}
if (lineNo == (countLines-1)) {
reportStatus = true;
}
} }
} }
catch (IOException e) { catch (IOException e) {
println("Execption reading lines from the gcode file " + filename); println("Execption reading lines from the gcode file " + filename);
e.printStackTrace(); e.printStackTrace();
} }
finally { finally {
try { try {
reader.close(); reader.close();
@ -1341,7 +1366,6 @@ RShape loadShapeFromGCodeFile(String filename) {
println("Exception closing the gcode file " + filename); println("Exception closing the gcode file " + filename);
e.printStackTrace(); e.printStackTrace();
} }
loop();
} }
RPoint[][] points = parent.getPointsInPaths(); RPoint[][] points = parent.getPointsInPaths();
@ -1355,7 +1379,10 @@ RShape loadShapeFromGCodeFile(String filename) {
} }
} }
} }
println("Total points in shape: " + totalPoints);
String conclusionMessage = "Imported " + totalPoints + " points from " + countLines + " lines of code in the file.";
println(conclusionMessage);
javax.swing.JOptionPane.showMessageDialog(null, conclusionMessage);
loop(); loop();
return parent; return parent;
@ -1365,7 +1392,7 @@ Boolean isGCodeZAxisForDrawing(float z) {
return gcodeZAxisDrawingHeight.compareTo(z) == 0; return gcodeZAxisDrawingHeight.compareTo(z) == 0;
} }
Map<String, Float> unpackGCodeInstruction(String line) throws NumberFormatException { Map<String, Float> unpackGCodeInstruction(String line) throws Exception {
Map<String, Float> instruction = new HashMap<String, Float>(4); Map<String, Float> instruction = new HashMap<String, Float>(4);
try { try {
String[] splitted = line.trim().split(" "); String[] splitted = line.trim().split(" ");
@ -1377,11 +1404,14 @@ Map<String, Float> unpackGCodeInstruction(String line) throws NumberFormatExcept
} }
} }
// println("instruction: " + instruction); // println("instruction: " + instruction);
if (instruction.isEmpty()) {
throw new Exception();
}
} }
catch (NumberFormatException e) { catch (Exception e) {
println("Exception while reading the lines from a gcode file: " + line); throw new Exception("Exception while reading the lines from a gcode file: " + line + ", " + e.getMessage());
throw e;
} }
return instruction; return instruction;
} }