0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-12-21 12:43:48 +01:00

Add checkbox for new setting 'printer.bottomEnableTraveling'.

Implement bottom layer traveling in GCode generation as well as sketch rendering.
This commit is contained in:
Wouter R 2016-01-06 19:26:07 +01:00
parent 46bcd54a1a
commit d48944e448
6 changed files with 64 additions and 46 deletions

View File

@ -25,7 +25,7 @@ function shapeMoveTo(x,y) {
_points.push([x, y, true]);
adjustBounds(x, y);
adjustPreviewTransformation();
draw(x, y, .5);
draw(x, y, -1);
}
function shapeLineTo(x,y) {

View File

@ -116,7 +116,7 @@ function loadFromSvg(svgData) {
adjustBounds(x, y);
adjustPreviewTransformation();
if (isMove) draw(x, y, .5);
if (isMove) draw(x, y, -1);
else draw(x, y);
}
p++;

View File

@ -97,52 +97,67 @@ function initDoodleDrawing() {
* CANVAS DRAWING FUNCTION
*
* * * * * * * * * */
function draw(_x, _y, _width) {
//console.log("canvasDrawing:draw");
// console.log("f:draw() >> _width: " + _width);
if (prevX == 0 && prevY ==0) {
//If _width is not specified, it is calculated from the distance between this and the previous point.
//If _width is negative, the path is 'floating', and only drawn if the setting printer.bottomEnableTraveling is true.
function draw(_x, _y, _width) {
//console.log("canvasDrawing:draw");
//console.log("f:draw() >> _width: " + _width);
if (prevX == 0 && prevY == 0) {
prevX = _x;
prevY = _y;
}
ctx.beginPath();
ctx.moveTo(prevX, prevY);
ctx.lineTo(_x, _y);
if (_width != undefined) {
ctx.lineWidth = _width;
} else {
if (drawVariableLineWeight) {
var dist = Math.sqrt(Math.pow((prevX - _x), 2) + Math.pow((prevY - _y), 2));
if (dist < 10) {
lineweight += .25;
} else if (dist < 20) {
lineweight += .5;
} else if (dist < 30) {
lineweight += .75;
} else if (dist < 50) {
lineweight += 1;
} else if (dist < 80) {
lineweight += 1.5;
} else if (dist < 120) {
lineweight += 2.25;
} else if (dist < 170) {
lineweight += 3.5;
} else {
lineweight += 2;
}
lineweight = Math.min(lineweight, 30);
lineweight *= 0.90;
lineweight = Math.max(lineweight, 1.0);
if (_width != undefined && _width < 0) {
if (settings['printer.bottomEnableTraveling']) {
ctx.moveTo(_x, _y);
} else {
lineweight = 2;
ctx.lineTo(_x, _y);
ctx.lineWidth = 0.5;
ctx.stroke();
}
} else {
ctx.lineTo(_x, _y);
ctx.lineWidth = lineweight;
if (_width != undefined) {
ctx.lineWidth = _width;
} else {
if (drawVariableLineWeight) {
var dist = Math.sqrt(Math.pow((prevX - _x), 2) + Math.pow((prevY - _y), 2));
if (dist < 10) {
lineweight += .25;
} else if (dist < 20) {
lineweight += .5;
} else if (dist < 30) {
lineweight += .75;
} else if (dist < 50) {
lineweight += 1;
} else if (dist < 80) {
lineweight += 1.5;
} else if (dist < 120) {
lineweight += 2.25;
} else if (dist < 170) {
lineweight += 3.5;
} else {
lineweight += 2;
}
lineweight = Math.min(lineweight, 30);
lineweight *= 0.90;
lineweight = Math.max(lineweight, 1.0);
} else {
lineweight = 2;
}
ctx.lineWidth = lineweight;
}
ctx.lineCap = 'round';
ctx.stroke();
}
ctx.lineCap = 'round';
ctx.stroke();
prevX = _x;
prevY = _y;
@ -202,7 +217,7 @@ function redrawDoodle(recalcBoundsAndTransforms) {
for (var i = 0; i < _points.length; i++) {
// console.log(" drawing points " + _points[i]);
if (_points[i][2] == true) {
draw(_points[i][0], _points[i][1], 0.5);
draw(_points[i][0], _points[i][1], -1);
} else {
draw(_points[i][0], _points[i][1]);
}
@ -301,7 +316,7 @@ function onCanvasMouseDown(e) {
_points.push([x, y, true]);
adjustBounds(x, y);
adjustPreviewTransformation();
draw(x, y, 0.5);
draw(x, y, -1);
}
var prevPoint = {x:-1, y:-1};
@ -401,7 +416,7 @@ function onCanvasTouchDown(e) {
_points.push([x, y, true]);
adjustBounds(x, y);
adjustPreviewTransformation();
draw(x, y, .5);
draw(x, y, -1);
movementCounter = 0;
@ -489,8 +504,3 @@ function onCanvasTouchEnd(e) {
function prevent(e) {
e.preventDefault();
}

View File

@ -20,6 +20,7 @@ function generate_gcode() {
var bottomSpeed = settings["printer.bottomLayerSpeed"];
var firstLayerSlow = settings["printer.firstLayerSlow"];
var bottomFlowRate = settings["printer.bottomFlowRate"];
var bottomEnableTraveling = settings["printer.bottomEnableTraveling"];
var travelSpeed = settings["printer.travelSpeed"]
var filamentThickness = settings["printer.filamentThickness"];
var wallThickness = settings["printer.wallThickness"];
@ -159,8 +160,10 @@ function generate_gcode() {
var isTraveling = !isLoop && i==0;
var doRetract = retractionEnabled && prev.distance(to) > retractionminDistance;
//Always travel to first point, then optionally disable traveling for first two layers and use settings for remainder of print.
var firstPointEver = (layer == 0 && i == 0 && j == 0);
if (firstPointEver || layer > 2 && enableTraveling && isTraveling) { //always travel to first point, then disable traveling for first two layers and use settings for remainder of print
var travelingAllowed = firstPointEver || bottomEnableTraveling || layer > 2;
if (travelingAllowed && enableTraveling && isTraveling) {
if (!firstPointEver && doRetract) gcode.push("G0 E" + (extruder - retractionamount).toFixed(3) + " F" + (retractionspeed * 60).toFixed(3)); //retract
gcode.push("G0 X" + to.x.toFixed(3) + " Y" + to.y.toFixed(3) + " Z" + z.toFixed(3) + " F" + (travelSpeed * 60).toFixed(3));
if (!firstPointEver && doRetract) gcode.push("G0 E" + extruder.toFixed(3) + " F" + (retractionspeed * 60).toFixed(3)); // return to normal

View File

@ -116,6 +116,10 @@ function SettingsWindow() {
settingsPopup.close();
self.signin();
}
//FIXME: instead of this rather ugly call, implement events for changes to settings so we can keep code decoupled
redrawDoodle(false);
_btnOK.removeAttr("disabled");
});
};

View File

@ -99,6 +99,7 @@
<label for="bottomLayerSpeed">Bottom layer speed:</label><input id="bottomLayerSpeed" type="number" name="printer.bottomLayerSpeed" class="small">mm/s<br>
<label for="travelSpeed">Travel speed:</label><input id="travelSpeed" type="number" name="printer.travelSpeed" class="small">mm/s<br>
<label for="enableTraveling">Enable traveling:</label><input id="enableTraveling" type="checkbox" name="printer.enableTraveling" value="enableTraveling"><br>
<label for="bottomEnableTraveling">Bottom layers traveling:</label><input id="bottomEnableTraveling" type="checkbox" name="printer.bottomEnableTraveling" value="bottomEnableTraveling"><br>
<label for="firstLayerSlow">Bottom layers slow:</label><input id="firstLayerSlow" type="checkbox" name="printer.firstLayerSlow" value="firstLayerSlow"><br>
<label for="bottomFlowRate">Bottom layers flow rate*:</label><input id="bottomFlowRate" type="number" name="printer.bottomFlowRate" class="small"><br>
<small>* Multiplier for extrusion rate in first few layers</small>