From 1eae86637ec7fef82140e6d806d90fe1f188d7cf Mon Sep 17 00:00:00 2001 From: Shaun Barratt Date: Mon, 12 Oct 2020 12:11:18 +0100 Subject: [PATCH 1/2] Added ability to change grid size --- index.html | 2 ++ js/renderer.js | 20 +++++++++++--------- js/ui.js | 6 ++++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index cd44dc0..3f0fa34 100644 --- a/index.html +++ b/index.html @@ -230,6 +230,8 @@

Running analysis....

+ + diff --git a/js/renderer.js b/js/renderer.js index b22913b..5e6eb0f 100644 --- a/js/renderer.js +++ b/js/renderer.js @@ -11,7 +11,7 @@ GCODE.renderer = (function(){ var canvas; var ctx; var zoomFactor= 3, zoomFactorDelta = 0.4; - var gridSizeX=200,gridSizeY=200,gridStep=10; + var gridStep=10; var ctxHeight, ctxWidth; var prevX=0, prevY=0; @@ -45,7 +45,9 @@ GCODE.renderer = (function(){ actualWidth: false, renderErrors: false, renderAnalysis: false, - speedDisplayType: displayType.speed + speedDisplayType: displayType.speed, + bedSizeX: 500, + bedSizeY: 500, }; var offsetModelX=0, offsetModelY=0; @@ -228,16 +230,16 @@ GCODE.renderer = (function(){ } ctx.beginPath(); - for(i=0;i<=gridSizeX;i+=gridStep){ + for(i=0;i<=renderOptions["bedSizeX"];i+=gridStep){ ctx.moveTo(i*zoomFactor-offsetX, 0-offsetY); - ctx.lineTo(i*zoomFactor-offsetX, -gridSizeY*zoomFactor-offsetY); + ctx.lineTo(i*zoomFactor-offsetX, -renderOptions["bedSizeY"]*zoomFactor-offsetY); } ctx.stroke(); ctx.beginPath(); - for(i=0;i<=gridSizeY;i+=gridStep){ + for(i=0;i<=renderOptions["bedSizeY"];i+=gridStep){ ctx.moveTo(0-offsetX, -i*zoomFactor-offsetY); - ctx.lineTo(gridSizeX*zoomFactor-offsetX, -i*zoomFactor-offsetY); + ctx.lineTo(renderOptions["bedSizeX"]*zoomFactor-offsetX, -i*zoomFactor-offsetY); } ctx.stroke(); @@ -447,7 +449,7 @@ GCODE.renderer = (function(){ init: function(){ startCanvas(); initialized = true; - ctx.translate((canvas.width - gridSizeX*zoomFactor)/2,gridSizeY*zoomFactor+(canvas.height - gridSizeY*zoomFactor)/2); + ctx.translate((canvas.width - renderOptions["bedSizeX"]*zoomFactor)/2,renderOptions["bedSizeY"]*zoomFactor+(canvas.height - renderOptions["bedSizeY"]*zoomFactor)/2); }, setOption: function(options){ for(var opt in options){ @@ -517,8 +519,8 @@ GCODE.renderer = (function(){ min = mdlInfo.min; // console.log(speeds); // console.log(mdlInfo.min.x + ' ' + mdlInfo.modelSize.x); - offsetModelX = (gridSizeX/2-(mdlInfo.min.x+mdlInfo.modelSize.x/2))*zoomFactor; - offsetModelY = (mdlInfo.min.y+mdlInfo.modelSize.y/2)*zoomFactor-gridSizeY/2*zoomFactor; + offsetModelX = (renderOptions["bedSizeX"]/2-(mdlInfo.min.x+mdlInfo.modelSize.x/2))*zoomFactor; + offsetModelY = (mdlInfo.min.y+mdlInfo.modelSize.y/2)*zoomFactor-renderOptions["bedSizeY"]/2*zoomFactor; if(ctx)ctx.translate(offsetModelX, offsetModelY); var scaleF = mdlInfo.modelSize.x>mdlInfo.modelSize.y?(canvas.width)/mdlInfo.modelSize.x/zoomFactor:(canvas.height)/mdlInfo.modelSize.y/zoomFactor; var pt = ctx.transformedPoint(canvas.width/2,canvas.height/2); diff --git a/js/ui.js b/js/ui.js index 641521f..99d5ce3 100644 --- a/js/ui.js +++ b/js/ui.js @@ -471,7 +471,6 @@ GCODE.ui = (function(){ nozzleDia: Number($('#nozzleDia').val()) || 0.4, hourlyCost: Number($('#hourlyCost').val()) || 1.0, filamentPrice: Number($('#filamentPrice').val()) || 0.05, - filamentType: document.getElementById('plasticABS').checked ? 'ABS' : 'PLA', }); @@ -482,7 +481,10 @@ GCODE.ui = (function(){ differentiateColors: document.getElementById('differentiateColorsCheckbox').checked, actualWidth: document.getElementById('thickExtrusionCheckbox').checked, alpha: document.getElementById('alphaCheckbox').checked, - showNextLayer: document.getElementById('showNextLayer').checked, + showNextLayer: document.getElementById('showNextLayer').checked, + + bedSizeX: Number($('#bedSizeX').val()) || 200, + bedSizeY: Number($('#bedSizeY').val()) || 200, }); showGCode = document.getElementById('showGCodeCheckbox').checked; From 120365629799d110dcea0aa863590d52181cc91e Mon Sep 17 00:00:00 2001 From: Shaun Barratt Date: Mon, 12 Oct 2020 12:18:16 +0100 Subject: [PATCH 2/2] Added option to toggle the grid on and off --- index.html | 1 + js/renderer.js | 2 ++ js/ui.js | 1 + 3 files changed, 4 insertions(+) diff --git a/index.html b/index.html index 3f0fa34..306ea5d 100644 --- a/index.html +++ b/index.html @@ -194,6 +194,7 @@

Running analysis....

+ diff --git a/js/renderer.js b/js/renderer.js index 5e6eb0f..8c72f81 100644 --- a/js/renderer.js +++ b/js/renderer.js @@ -41,6 +41,7 @@ GCODE.renderer = (function(){ moveModel: true, differentiateColors: true, showNextLayer: false, + showGrid: true, alpha: false, actualWidth: false, renderErrors: false, @@ -220,6 +221,7 @@ GCODE.renderer = (function(){ }; var drawGrid = function() { + if (!renderOptions["showGrid"]) return; var i; ctx.strokeStyle = renderOptions["colorGrid"]; ctx.lineWidth = 1; diff --git a/js/ui.js b/js/ui.js index 99d5ce3..b5e356f 100644 --- a/js/ui.js +++ b/js/ui.js @@ -482,6 +482,7 @@ GCODE.ui = (function(){ actualWidth: document.getElementById('thickExtrusionCheckbox').checked, alpha: document.getElementById('alphaCheckbox').checked, showNextLayer: document.getElementById('showNextLayer').checked, + showGrid: document.getElementById('showGrid').checked, bedSizeX: Number($('#bedSizeX').val()) || 200, bedSizeY: Number($('#bedSizeY').val()) || 200,