Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to change grid size #87

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ <h3>Running analysis....</h3>
<label for="alphaCheckbox"><input type="checkbox" id="alphaCheckbox" value="10" onclick="GCODE.ui.processOptions()" > Render lines slightly transparent</label>
<!--<label for="widthModifier">Width modifier: <input type="text" value="2" id="widthModifier" onchange="GCODE.ui.processOptions()"/></label>-->
<label for="showNextLayer"><input type="checkbox" id="showNextLayer" value="9" onclick="GCODE.ui.processOptions()" > Show +1 layer</label>
<label for="showGrid"><input type="checkbox" id="showGrid" value="1" onclick="GCODE.ui.processOptions()" checked> Show grid</label>
</div>
</div>
</div>
Expand Down Expand Up @@ -230,6 +231,8 @@ <h3>Running analysis....</h3>
<label for="volumetricE"><input type="checkbox" id="volumetricE" onclick="GCODE.ui.processOptions()"> Volumetric E</label>
<label for="hourlyCost">Printer hourly cost: <input type="text" value="1.00" id="hourlyCost" onchange="GCODE.ui.processOptions()"/></label>
<label for="filamentPrice">Filament price(per gram): <input type="text" value="0.05" id="filamentPrice" onchange="GCODE.ui.processOptions()"/></label>
<label for="bedSizeX">Bed size X <input type="text" value="200" id="bedSizeX" onchange="GCODE.ui.processOptions()"/></label>
<label for="bedSizeY">Bed size Y <input type="text" value="200" id="bedSizeY" onchange="GCODE.ui.processOptions()"/></label>
</div>
</div>
</div>
Expand Down
22 changes: 13 additions & 9 deletions js/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -41,11 +41,14 @@ GCODE.renderer = (function(){
moveModel: true,
differentiateColors: true,
showNextLayer: false,
showGrid: true,
alpha: false,
actualWidth: false,
renderErrors: false,
renderAnalysis: false,
speedDisplayType: displayType.speed
speedDisplayType: displayType.speed,
bedSizeX: 500,
bedSizeY: 500,
};

var offsetModelX=0, offsetModelY=0;
Expand Down Expand Up @@ -218,6 +221,7 @@ GCODE.renderer = (function(){
};

var drawGrid = function() {
if (!renderOptions["showGrid"]) return;
var i;
ctx.strokeStyle = renderOptions["colorGrid"];
ctx.lineWidth = 1;
Expand All @@ -228,16 +232,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();

Expand Down Expand Up @@ -447,7 +451,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){
Expand Down Expand Up @@ -517,8 +521,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);
Expand Down
7 changes: 5 additions & 2 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});

Expand All @@ -482,7 +481,11 @@ 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,
showGrid: document.getElementById('showGrid').checked,

bedSizeX: Number($('#bedSizeX').val()) || 200,
bedSizeY: Number($('#bedSizeY').val()) || 200,
});

showGCode = document.getElementById('showGCodeCheckbox').checked;
Expand Down