diff --git a/Gruntfile.js b/Gruntfile.js
index a008876..ea14fac 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -16,6 +16,9 @@ module.exports = function(grunt) {
},
js: {
src: [
+ 'js_src/Shape.js',
+ 'js_src/Svg.js',
+ 'js_src/Keyboard.js',
'js_src/SettingsWindow.js',
'js_src/UpdatePanel.js',
'js_src/PrinterPanel.js',
diff --git a/js_src/Keyboard.js b/js_src/Keyboard.js
new file mode 100644
index 0000000..67e936d
--- /dev/null
+++ b/js_src/Keyboard.js
@@ -0,0 +1,30 @@
+var keyboardShortcutsEnabled = true;
+
+function initKeyboard() {
+
+ $(document).keypress(function(event) {
+
+ if (!keyboardShortcutsEnabled) return;
+
+ var ch = String.fromCharCode(event.which);
+
+ switch (ch) {
+ case 'c': clearDoodle(); break;
+ case 'p': print(); break;
+ case 'u': oopsUndo(); break;
+ case 'e': settingsWindow.downloadGcode(); break;
+ case 'q': stopPrint(); break;
+ case ',': openSettingsWindow(); break;
+ case 'C': drawCircle(250,180,80,64); break; //x,y,r,res
+ case 'T': drawCircle(250,180,80,3); break; //triangle
+ case 'X': drawCircle(250,180,80,6); break; //hexagon
+ case 'H': previewUp(true); break;
+ case 'h': previewDown(true); break;
+ case '[': previewTwistLeft(); break;
+ case ']': previewTwistRight(); break;
+ case '\'': resetTwist(); break;
+ default: console.log("Key: '" + ch + "' (" + event.which + ")");
+ }
+ })
+
+}
\ No newline at end of file
diff --git a/js_src/SettingsWindow.js b/js_src/SettingsWindow.js
index 952d143..02f420d 100644
--- a/js_src/SettingsWindow.js
+++ b/js_src/SettingsWindow.js
@@ -159,6 +159,7 @@ function SettingsWindow() {
}
this.showSettings = function() {
+ keyboardShortcutsEnabled = false;
this.loadSettings(function() { // reload settings
$("#contentOverlay").fadeIn(375, function() {
document.body.removeEventListener('touchmove',prevent,false);
@@ -166,6 +167,7 @@ function SettingsWindow() {
});
}
this.hideSettings = function(complete) {
+ keyboardShortcutsEnabled = true;
$("#contentOverlay").fadeOut(375, function() {
document.body.addEventListener('touchmove',prevent,false);
// self.window.css("display","none");
@@ -365,6 +367,14 @@ function SettingsWindow() {
this.downloadlogs = function() {
window.location.href = self.wifiboxURL + "/info/logfiles"
}
+
+ this.downloadGcode = function() {
+ var gcode = generate_gcode();
+ if (gcode!=undefined) {
+ var blob = new Blob([gcode.join("\n")], {type: "text/plain;charset=utf-8"});
+ saveAs(blob, "doodle3d.gcode");
+ }
+ }
/*
* Networks ui
diff --git a/js_src/Shape.js b/js_src/Shape.js
new file mode 100644
index 0000000..4d3ac17
--- /dev/null
+++ b/js_src/Shape.js
@@ -0,0 +1,34 @@
+function drawCircle(x0,y0,r,res) {
+ if (res==undefined) res = 50; //circle resolution
+ beginShape();
+ var step=Math.PI * 2.0 / res;
+ for (var a=0; a<=Math.PI*2; a+=step) {
+ var x = Math.sin(a) * r + x0;
+ var y = Math.cos(a) * r + y0;
+ if (a==0) shapeMoveTo(x,y);
+ else shapeLineTo(x,y);
+ }
+ endShape();
+}
+
+function beginShape(x,y) {
+ setSketchModified(true);
+}
+
+function shapeMoveTo(x,y) {
+ _points.push([x, y, true]);
+ adjustBounds(x, y)
+ adjustPreviewTransformation();
+ draw(x, y, .5);
+}
+
+function shapeLineTo(x,y) {
+ _points.push([x, y, false]);
+ adjustBounds(x, y)
+ adjustPreviewTransformation();
+ draw(x, y);
+}
+
+function endShape() {
+ renderToImageDataPreview();
+}
\ No newline at end of file
diff --git a/js_src/Svg.js b/js_src/Svg.js
new file mode 100644
index 0000000..6451624
--- /dev/null
+++ b/js_src/Svg.js
@@ -0,0 +1,132 @@
+//SVG validator: http://validator.w3.org/
+//SVG viewer: http://svg-edit.googlecode.com/svn/branches/2.6/editor/svg-editor.html
+function saveToSvg() {
+ var lastX = 0, lastY = 0, lastIsMove;
+ var svg = '';
+
+ var boundsWidth = doodleBounds[2] - doodleBounds[0];
+ var boundsHeight = doodleBounds[3] - doodleBounds[1];
+
+ svg += '\n';
+ svg += '\n';
+ svg += '\n';
+
+ return svg;
+}
+
+
+//TODO: use local variables instead of _points,numLayers,VERTICALSHAPE and rStep so we can leave a current doodle in tact if an error occurs while parsing
+function loadFromSvg(svgData) {
+ var mode = '', x = 0, y = 0;
+
+ console.log("loading " + svgData.length + " bytes of data...");
+
+ clearDoodle();
+
+ var p = svgData.indexOf("-->", p);
+ if (endP == -1) { console.log("loadFromSvg: could not find metadata end-marker"); return false; }
+ var metaFields = JSON.parse(svgData.substr(p, endP - p));
+ //TODO: log error and return false if parsing failed
+ for (var k in metaFields) {
+ var v = metaFields[k];
+ switch (k) {
+ case "height": numLayers = v; break;
+ case "outlineShape": VERTICALSHAPE = v; break;
+ case "twist": rStep = v; break;
+ }
+ }
+
+ renderToImageDataPreview();
+
+ return true;
+}
\ No newline at end of file
diff --git a/js_src/buttonbehaviors.js b/js_src/buttonbehaviors.js
index 9cd016a..f365206 100644
--- a/js_src/buttonbehaviors.js
+++ b/js_src/buttonbehaviors.js
@@ -246,10 +246,10 @@ function print(e) {
console.log("sendPrintCommands is false: not sending print command to 3dprinter");
}
- if (debugMode) {
- $("#textdump").text("");
- $("#textdump").text(gcode.join("\n"));
- }
+ // if (debugMode) {
+ // $("#textdump").text("");
+ // $("#textdump").text(gcode.join("\n"));
+ // }
}, gcodeGenerateDelay);
} else {
@@ -336,7 +336,11 @@ function previewTwistRight(redrawLess) {
setSketchModified(true);
}
-
+function resetTwist() {
+ rStep = 0;
+ redrawRenderedPreview();
+ setSketchModified(true);
+}
function update() {
setState(printer.state,printer.hasControl);
diff --git a/js_src/canvasDrawing.js b/js_src/canvasDrawing.js
index c67a79d..582eee2 100644
--- a/js_src/canvasDrawing.js
+++ b/js_src/canvasDrawing.js
@@ -477,136 +477,6 @@ function prevent(e) {
}
-//SVG validator: http://validator.w3.org/
-//SVG viewer: http://svg-edit.googlecode.com/svn/branches/2.6/editor/svg-editor.html
-function saveToSvg() {
- var lastX = 0, lastY = 0, lastIsMove;
- var svg = '';
-
- var boundsWidth = doodleBounds[2] - doodleBounds[0];
- var boundsHeight = doodleBounds[3] - doodleBounds[1];
-
- svg += '\n';
- svg += '\n';
- svg += '\n';
-
- return svg;
-}
-//TODO: use local variables instead of _points,numLayers,VERTICALSHAPE and rStep so we can leave a current doodle in tact if an error occurs while parsing
-function loadFromSvg(svgData) {
- var mode = '', x = 0, y = 0;
-
- console.log("loading " + svgData.length + " bytes of data...");
-
- clearDoodle();
-
- var p = svgData.indexOf("-->", p);
- if (endP == -1) { console.log("loadFromSvg: could not find metadata end-marker"); return false; }
- var metaFields = JSON.parse(svgData.substr(p, endP - p));
- //TODO: log error and return false if parsing failed
- for (var k in metaFields) {
- var v = metaFields[k];
- switch (k) {
- case "height": numLayers = v; break;
- case "outlineShape": VERTICALSHAPE = v; break;
- case "twist": rStep = v; break;
- }
- }
-
- renderToImageDataPreview();
-
- return true;
-}
diff --git a/js_src/main.js b/js_src/main.js
index 0eb87d4..8b4c086 100644
--- a/js_src/main.js
+++ b/js_src/main.js
@@ -25,8 +25,6 @@ var clientInfo = {};
$(function() {
console.log("ready");
- //TODO give this a more logical place in code
-
if (getURLParameter("d") != "null") debugMode = (getURLParameter("d") == "1");
if (getURLParameter("p") != "null") sendPrintCommands = (getURLParameter("p") == "1");
if (getURLParameter("c") != "null") communicateWithWifibox = (getURLParameter("c") == "1");
@@ -59,6 +57,7 @@ $(function() {
initLayouting();
initSidebars();
initButtonBehavior();
+ initKeyboard();
initVerticalShapes();
if (!clientInfo.isSmartphone) initHelp();
diff --git a/js_src/previewRendering.js b/js_src/previewRendering.js
index 6c3c825..c28314b 100644
--- a/js_src/previewRendering.js
+++ b/js_src/previewRendering.js
@@ -7,7 +7,7 @@ var preview_tmp;
var previewCtx_tmp;
var previewDefaults = {
- rotation: Math.PI/90,
+ rotation: 0, //Math.PI/90,
numLayers: 10
}
diff --git a/www/index.html b/www/index.html
index 1c50f65..f07d33f 100644
--- a/www/index.html
+++ b/www/index.html
@@ -102,7 +102,8 @@
-
+
+
@@ -135,6 +136,7 @@
+
diff --git a/www/settings.html b/www/settings.html
index 37e38d9..d738b77 100644
--- a/www/settings.html
+++ b/www/settings.html
@@ -160,6 +160,7 @@