From cb857ae6fe3e93966d355f83421e9517bbea16b1 Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Fri, 17 Jan 2014 16:27:15 +0100 Subject: [PATCH 1/4] Cleanup --- js_src/Keyboard.js | 42 ---------------------------------- js_src/Shape.js | 42 ---------------------------------- js_src/verticalShapes.js | 49 ---------------------------------------- 3 files changed, 133 deletions(-) delete mode 100644 js_src/Keyboard.js delete mode 100644 js_src/Shape.js delete mode 100644 js_src/verticalShapes.js diff --git a/js_src/Keyboard.js b/js_src/Keyboard.js deleted file mode 100644 index fc11aed..0000000 --- a/js_src/Keyboard.js +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of the Doodle3D project (http://doodle3d.com). - * - * Copyright (c) 2013, Doodle3D - * This software is licensed under the terms of the GNU GPL v2 or later. - * See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details. - */ - -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 'n': 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 's': saveSketch(); break; - case 'L': nextDoodle(); break; - case 'l': prevDoodle(); break; - case '[': previewTwistLeft(); break; - case ']': previewTwistRight(); break; - case '\'': resetTwist(); break; - default: console.log("Key: '" + ch + "' (" + event.which + ")"); - } - }) - -} diff --git a/js_src/Shape.js b/js_src/Shape.js deleted file mode 100644 index 5734a07..0000000 --- a/js_src/Shape.js +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of the Doodle3D project (http://doodle3d.com). - * - * Copyright (c) 2013, Doodle3D - * This software is licensed under the terms of the GNU GPL v2 or later. - * See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details. - */ - -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(); -} diff --git a/js_src/verticalShapes.js b/js_src/verticalShapes.js deleted file mode 100644 index d90ae40..0000000 --- a/js_src/verticalShapes.js +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of the Doodle3D project (http://doodle3d.com). - * - * Copyright (c) 2013, Doodle3D - * This software is licensed under the terms of the GNU GPL v2 or later. - * See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details. - */ - -var VERTICALSHAPE; -var verticalShapes = { - "NONE": 'none', - "DIVERGING": 'diverging', - "CONVERGING": 'converging', - "SINUS": 'sinus' -}; - -function initVerticalShapes() { - // TODO give these vertical shapes a better spot - VERTICALSHAPE = verticalShapes.NONE; - $(".verticalShapes, .straight").on('mouseup touchend', function(e) { - e.preventDefault(); - console.log("diverging"); - VERTICALSHAPE = verticalShapes.NONE; - redrawRenderedPreview(); - }) - $(".verticalShapes, .diverging").on('mouseup touchend', function(e) { - e.preventDefault(); - console.log("diverging"); - VERTICALSHAPE = verticalShapes.DIVERGING; - redrawRenderedPreview(); - }) - $(".verticalShapes, .converging").on('mouseup touchend', function(e) { - e.preventDefault(); - console.log("converging"); - VERTICALSHAPE = verticalShapes.CONVERGING; - redrawRenderedPreview(); - }) - $(".verticalShapes, .sinus").on('mouseup touchend', function(e) { - e.preventDefault(); - console.log("sinus"); - VERTICALSHAPE = verticalShapes.SINUS; - redrawRenderedPreview(); - }) - -} - -function resetVerticalShapes() { - VERTICALSHAPE = verticalShapes.NONE; -} From 577bc28bc9cce0a5e5f5432b0f69f24a0d347a98 Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Fri, 17 Jan 2014 16:28:48 +0100 Subject: [PATCH 2/4] Update preview bounds when move/zoom or rotate --- js/Shape.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/Shape.js b/js/Shape.js index 2c859b2..94dd115 100644 --- a/js/Shape.js +++ b/js/Shape.js @@ -124,7 +124,7 @@ function rotateShape(radians) { function updateView() { setSketchModified(true); - redrawDoodle(); + redrawDoodle(true); adjustPreviewTransformation(); renderToImageDataPreview(); From 6dafeafa37a85463f01df0d341b485b294d8aa8b Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Fri, 17 Jan 2014 16:28:56 +0100 Subject: [PATCH 3/4] less logs --- js/canvasDrawing.js | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/js/canvasDrawing.js b/js/canvasDrawing.js index 0adf13b..eabec19 100644 --- a/js/canvasDrawing.js +++ b/js/canvasDrawing.js @@ -45,7 +45,7 @@ var isModified = false; * * * * * * * * * * */ function initDoodleDrawing() { - console.log("f:initDoodleDrawing()"); + //console.log("f:initDoodleDrawing()"); $canvas = $("#mycanvas"); canvas = $canvas[0]; @@ -79,7 +79,7 @@ function initDoodleDrawing() { // drawCanvas = $(".drawareacontainer"); drawCanvas = $("#mycanvasContainer"); // $("#drawAreaContainer") - console.log("drawCanvasTopLeftCoords: " + drawCanvasTopLeftCoords); + //console.log("drawCanvasTopLeftCoords: " + drawCanvasTopLeftCoords); // drawCanvasTopLeftCoords[0] = drawCanvas.css("left").match(/[0-9]/g).join(""); // drawCanvasTopLeftCoords[1] = drawCanvas.css("top").match(/[0-9]/g).join(""); drawCanvasTopLeftCoords[0] = drawCanvas.offset().left; @@ -87,8 +87,8 @@ function initDoodleDrawing() { // drawCanvasTopLeftCoords[0] = drawCanvas[0].offsetParent.offsetLeft; // drawCanvasTopLeftCoords[1] = drawCanvas[0].offsetParent.offsetTop; - console.log("f:initDoodleDrawing() >> canvasWidth: " + canvasWidth); - console.log("f:initDoodleDrawing() >> canvasHeight: " + canvasHeight); + //console.log("f:initDoodleDrawing() >> canvasWidth: " + canvasWidth); + //console.log("f:initDoodleDrawing() >> canvasHeight: " + canvasHeight); } @@ -98,6 +98,7 @@ function initDoodleDrawing() { * * * * * * * * * * */ function draw(_x, _y, _width) { + //console.log("canvasDrawing:draw"); // console.log("f:draw() >> _width: " + _width); if (prevX == 0 && prevY ==0) { @@ -154,7 +155,7 @@ function draw(_x, _y, _width) { * * * * * * * * * * */ function clearDoodle() { - console.log("f:clearDoodle"); + //console.log("f:clearDoodle"); updatePrevNextButtonStateOnClear(); @@ -179,6 +180,7 @@ function clearDoodle() { } function redrawDoodle(recalcBoundsAndTransforms) { + //console.log("canvasDrawing:redrawDoodle"); if (recalcBoundsAndTransforms == undefined) recalcBoundsAndTransforms = false; // console.log("f:redrawDoodle() >> recalcBoundsAndTransforms = " + recalcBoundsAndTransforms); @@ -205,8 +207,9 @@ function redrawDoodle(recalcBoundsAndTransforms) { } } } - +// checks if x,y is outside doodleBounds, if so update function adjustBounds(x, y) { + //console.log("canvasDrawing:adjustBounds"); var newPointsOutsideOfCurrentBounds = false; // console.log("f:adjustBounds("+x+","+y+")"); @@ -242,7 +245,7 @@ function redrawDoodle(recalcBoundsAndTransforms) { // does what exactly? function adjustPreviewTransformation() { - // console.log("f:adjustPreviewTransformation()"); + //console.log("canvasDrawing:adjustPreviewTransformation"); doodleTransform[0] = doodleBounds[0]; doodleTransform[1] = doodleBounds[1]; @@ -272,6 +275,7 @@ function adjustPreviewTransformation() { * * * * * * * * * * */ function onCanvasMouseDown(e) { + //console.log("canvasDrawing:onCanvasMouseDown"); setSketchModified(true); // console.log("f:onCanvasMouseDown()"); @@ -301,7 +305,7 @@ function onCanvasMouseDown(e) { var prevPoint = {x:-1, y:-1}; function onCanvasMouseMove(e) { - + //console.log("canvasDrawing:onCanvasMouseMove"); // console.log("f:onCanvasMouseMove()"); if (!dragging) return; @@ -363,11 +367,11 @@ function onCanvasMouseUp(e) { // console.log("f:onCanvasMouseUp()"); // console.log("onmouseup"); dragging = false; - console.log("doodleBounds: " + doodleBounds); - console.log("doodleTransform: " + doodleTransform); + //console.log("doodleBounds: " + doodleBounds); + //console.log("doodleTransform: " + doodleTransform); // ctx.stroke(); - console.log("_points.length :" + _points.length); + //console.log("_points.length :" + _points.length); // console.log(_points); // DEBUG @@ -383,7 +387,7 @@ function onCanvasTouchDown(e) { setSketchModified(true); e.preventDefault(); - console.log("f:onCanvasTouchDown >> e: " , e); + //console.log("f:onCanvasTouchDown >> e: " , e); // var x = e.touches[0].pageX - e.touches[0].target.offsetLeft; // var y = e.touches[0].pageY - e.touches[0].target.offsetTop; var x = e.touches[0].pageX - drawCanvasTopLeftCoords[0]; @@ -404,6 +408,7 @@ function onCanvasTouchDown(e) { } function onCanvasTouchMove(e) { + //console.log("canvasDrawing:onCanvasTouchMove"); setSketchModified(true); e.preventDefault(); @@ -469,12 +474,12 @@ function onCanvasTouchMove(e) { } function onCanvasTouchEnd(e) { - console.log("f:onCanvasTouchEnd()"); - console.log("doodleBounds: " + doodleBounds); - console.log("doodleTransform: " + doodleTransform); + //console.log("f:onCanvasTouchEnd()"); + //console.log("doodleBounds: " + doodleBounds); + //console.log("doodleTransform: " + doodleTransform); // ctx.stroke(); - console.log("_points.length :" + _points.length); + //console.log("_points.length :" + _points.length); // redrawPreview(); renderToImageDataPreview(); From 679cf9b5a51d058f910c63e2f1907e870741234b Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Fri, 17 Jan 2014 16:29:34 +0100 Subject: [PATCH 4/4] Check if there is preview slice image when doing redraw --- js/previewRendering.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/js/previewRendering.js b/js/previewRendering.js index b7a9a6f..aba2d6a 100644 --- a/js/previewRendering.js +++ b/js/previewRendering.js @@ -26,7 +26,7 @@ var prevRedrawTime = new Date().getTime(); var redrawInterval = 1000 / 30; // ms function initPreviewRendering() { - console.log("f:initPreviewRendering()"); + //console.log("f:initPreviewRendering()"); $preview = $("#preview"); preview = $preview[0]; @@ -89,6 +89,7 @@ var highlight = true; //highlight bottom, middle and top layers var linesRaw = ""; var debug_redrawSimplification = 6; function redrawPreview(redrawLess) { + //console.log("PreviewRendering:redrawPreview"); if (redrawLess == undefined) redrawLess = false; if (_points.length < 2) { @@ -168,6 +169,7 @@ function redrawPreview(redrawLess) { } function renderToImageDataPreview() { + //console.log("PreviewRendering:renderToImageDataPreview"); if (_points.length < 2) return; //* @@ -236,9 +238,10 @@ function renderToImageDataPreview() { previewCtx.globalAlpha = globalAlpha; } -// called by the move up/down or twist left/right buttons +// called by the move up/down, twist left/right or new buttons // it is assumed that the preview has been rendered to an Image object, which will be used to draw the preview with (much better performance) function redrawRenderedPreview(redrawLess) { + //console.log("PreviewRendering:redrawRenderedPreview"); if (redrawLess == undefined) redrawLess = false; // console.log("f:redrawRenderedPreview()"); @@ -248,7 +251,10 @@ function redrawRenderedPreview(redrawLess) { var y = 0; var r = 0; - + + // check if there is preview image data that we can use for the layers + if(!doodleImageCapture.src || doodleImageCapture.src == "") return; + for(var i = 0; i < numLayers; i++) { var verticalScaleFactor = scaleFunction(i / maxNumLayers); @@ -271,7 +277,7 @@ function redrawRenderedPreview(redrawLess) { previewCtx.scale(verticalScaleFactor, scaleY * verticalScaleFactor); previewCtx.rotate(r); previewCtx.translate(-layerCX,-layerCY); - + previewCtx.drawImage(doodleImageCapture, 0, 0); y -= yStep; @@ -297,6 +303,7 @@ function centeredAndScaledDoodlePoint(p) { var updatePrevX = -1; var updatePrevY = -1; function updatePreview(_x, _y, redrawLess) { + //console.log("PreviewRendering:updatePreview"); if (redrawLess == undefined) redrawLess = false; redrawLess = false;