2013-12-20 16:31:41 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-07-26 22:39:28 +02:00
|
|
|
var twistIncrement = Math.PI/1800;
|
|
|
|
|
2014-01-13 16:38:26 +01:00
|
|
|
var btnNew, btnPrevious, btnNext, btnOops, btnStop, btnInfo;
|
|
|
|
var btnSettings, btnWordArt;
|
|
|
|
var btnToggleEdit, buttonGroupEdit, btnZoom, btnMove, btnRotate;
|
2014-01-16 16:07:40 +01:00
|
|
|
var btnToggleVerticalShapes, btnHeight, btnTwist, btnShape, btnConv, btnStraight, btnSine, btnDiv;
|
2014-01-13 16:38:26 +01:00
|
|
|
var buttonGroupAdd, popupWordArt;
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
var state;
|
|
|
|
var prevState;
|
2013-10-11 16:17:58 +02:00
|
|
|
var hasControl;
|
2013-08-09 22:25:14 +02:00
|
|
|
|
2013-10-14 18:51:37 +02:00
|
|
|
var gcodeGenerateDelayer;
|
|
|
|
var gcodeGenerateDelay = 50;
|
|
|
|
|
2014-02-12 17:27:41 +01:00
|
|
|
|
|
|
|
var preheatDelay;
|
|
|
|
var preheatDelayTime = 15*1000;
|
|
|
|
|
2013-07-26 22:39:28 +02:00
|
|
|
function initButtonBehavior() {
|
2013-10-11 11:42:27 +02:00
|
|
|
console.log("f:initButtonBehavior");
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2014-01-30 15:45:03 +01:00
|
|
|
btnOops = new Button("#btnOops");
|
|
|
|
btnInfo = new Button("#btnInfo");
|
|
|
|
btnSettings = new Button("#btnSettings");
|
|
|
|
btnNew = new Button("#btnNew");
|
|
|
|
btnPrint= new Button("#btnPrint");
|
|
|
|
btnStop = new Button("#btnStop");
|
|
|
|
btnPrevious = new Button("#btnPrevious");
|
|
|
|
btnNext = new Button("#btnNext");
|
|
|
|
btnSave = new Button("#btnSave");
|
2014-01-16 16:07:40 +01:00
|
|
|
buttonGroupAdd = $("#buttonGroupAdd");
|
2014-01-30 15:45:03 +01:00
|
|
|
btnShape = new Button("#btnShape");
|
|
|
|
btnWordArt = new Button("#btnWordArt");
|
2014-01-16 16:07:40 +01:00
|
|
|
popupWordArt = $("#popupWordArt");
|
|
|
|
popupShape = $("#popupShape");
|
|
|
|
popupMask = $("#popupMask");
|
|
|
|
logoPanel = $("#logopanel");
|
2014-01-30 15:45:03 +01:00
|
|
|
btnToggleEdit = new Button("#btnToggleEdit");
|
2014-01-16 16:07:40 +01:00
|
|
|
buttonGroupEdit = $("#buttonGroupEdit");
|
2014-01-30 15:45:03 +01:00
|
|
|
btnZoom = new Button("#btnZoom");
|
|
|
|
btnMove = new Button("#btnMove");
|
|
|
|
btnRotate = new Button("#btnRotate");
|
|
|
|
btnToggleVerticalShapes = new Button("#btnToggleVerticalShapes");
|
2014-01-16 16:07:40 +01:00
|
|
|
buttonGroupVerticalShapes = $("#buttonGroupVerticalShapes");
|
2014-01-30 15:45:03 +01:00
|
|
|
btnHeight = new Button("#btnHeight");
|
|
|
|
btnTwist = new Button("#btnTwist");
|
|
|
|
btnStraight = new Button("#btnStraight");
|
|
|
|
btnDiv = new Button("#btnDiv");
|
|
|
|
btnConv = new Button("#btnConv");
|
|
|
|
btnSine = new Button("#btnSine");
|
|
|
|
btnAdd = new Button("#btnAdd");
|
|
|
|
|
|
|
|
$(".btn").Button(); //initalize other buttons
|
2014-01-16 12:16:09 +01:00
|
|
|
|
|
|
|
logoPanel.on("onButtonClick", onLogo);
|
2014-01-09 17:05:03 +01:00
|
|
|
btnNew.on("onButtonClick", onBtnNew);
|
2014-01-13 18:04:51 +01:00
|
|
|
btnAdd.on("onButtonClick", onBtnAdd);
|
2014-01-09 17:05:03 +01:00
|
|
|
btnWordArt.on("onButtonClick", onBtnWordArt);
|
2014-01-13 18:04:51 +01:00
|
|
|
btnShape.on("onButtonClick", onBtnShape);
|
2014-01-20 13:28:33 +01:00
|
|
|
btnPrint.on("onButtonClick", print);
|
2014-01-30 17:49:15 +01:00
|
|
|
btnStop.on("onButtonClick", stopPrint);
|
|
|
|
btnSave.on("onButtonClick", saveSketch);
|
|
|
|
btnPrevious.on("onButtonClick", prevDoodle);
|
|
|
|
btnNext.on("onButtonClick", nextDoodle);
|
2014-01-09 17:05:03 +01:00
|
|
|
btnOops.on("onButtonHold", onBtnOops);
|
2014-01-13 18:04:51 +01:00
|
|
|
// vertical shape buttons
|
|
|
|
btnToggleVerticalShapes.on("onButtonClick", onBtnToggleVerticalShapes);
|
2014-01-16 16:07:40 +01:00
|
|
|
btnHeight.on("onButtonHold", onBtnHeight);
|
|
|
|
btnTwist.on("onButtonHold", onBtnTwist);
|
2014-01-09 17:05:03 +01:00
|
|
|
btnStraight.on("onButtonClick", onBtnStraight);
|
2014-01-13 18:04:51 +01:00
|
|
|
btnDiv.on("onButtonClick", onBtnDiv);
|
|
|
|
btnConv.on("onButtonClick", onBtnConv);
|
|
|
|
btnSine.on("onButtonClick", onBtnSine);
|
|
|
|
|
|
|
|
btnToggleEdit.on("onButtonClick", onBtnToggleEdit);
|
|
|
|
btnMove.on("onButtonHold", onBtnMove);
|
|
|
|
btnZoom.on("onButtonHold", onBtnZoom);
|
|
|
|
btnRotate.on("onButtonHold", onBtnRotate);
|
2014-01-09 18:10:54 +01:00
|
|
|
|
2013-10-29 23:26:09 +01:00
|
|
|
getSavedSketchStatus();
|
|
|
|
setSketchModified(false);
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2014-01-13 15:52:40 +01:00
|
|
|
function onBtnToggleVerticalShapes() {
|
|
|
|
var btnImg;
|
|
|
|
if(buttonGroupVerticalShapes.is(":hidden")) {
|
|
|
|
btnImg = "img/buttons/btnArrowClose.png";
|
|
|
|
} else {
|
|
|
|
btnImg = "img/buttons/btnArrowOpen.png";
|
|
|
|
}
|
|
|
|
btnToggleVerticalShapes.attr("src",btnImg);
|
|
|
|
|
|
|
|
buttonGroupVerticalShapes.fadeToggle(BUTTON_GROUP_SHOW_DURATION);
|
2014-01-09 18:10:54 +01:00
|
|
|
}
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2014-01-16 12:16:09 +01:00
|
|
|
function onLogo() {
|
|
|
|
location.reload();
|
|
|
|
}
|
2014-01-09 17:05:03 +01:00
|
|
|
function onBtnAdd() {
|
2014-01-13 15:52:40 +01:00
|
|
|
buttonGroupAdd.fadeToggle(BUTTON_GROUP_SHOW_DURATION);
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
2013-08-09 22:25:14 +02:00
|
|
|
|
2014-01-09 17:05:03 +01:00
|
|
|
function onBtnStraight() {
|
|
|
|
setVerticalShape(verticalShapes.NONE);
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
2014-01-09 17:05:03 +01:00
|
|
|
function onBtnDiv() {
|
|
|
|
setVerticalShape(verticalShapes.DIVERGING);
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
2014-01-09 17:05:03 +01:00
|
|
|
function onBtnConv() {
|
|
|
|
setVerticalShape(verticalShapes.CONVERGING);
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
2014-01-09 17:05:03 +01:00
|
|
|
function onBtnSine() {
|
|
|
|
setVerticalShape(verticalShapes.SINUS);
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
2014-01-09 17:05:03 +01:00
|
|
|
|
|
|
|
function hitTest(cursor,button,radius) {
|
|
|
|
return distance(cursor.x,cursor.y,button.x,button.y)<radius;
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
2014-01-13 18:04:51 +01:00
|
|
|
|
|
|
|
|
2014-01-13 16:38:26 +01:00
|
|
|
function onBtnToggleEdit() {
|
|
|
|
var btnImg;
|
|
|
|
if(buttonGroupEdit.is(":hidden")) {
|
|
|
|
btnImg = "img/buttons/btnArrowClose.png";
|
|
|
|
} else {
|
|
|
|
btnImg = "img/buttons/btnArrowOpen.png";
|
|
|
|
}
|
|
|
|
btnToggleEdit.attr("src",btnImg);
|
|
|
|
|
|
|
|
buttonGroupEdit.fadeToggle(BUTTON_GROUP_SHOW_DURATION);
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
2014-01-13 18:04:51 +01:00
|
|
|
function onBtnMove(e,cursor) {
|
|
|
|
var w = btnMove.width();
|
|
|
|
var h = btnMove.height();
|
|
|
|
var speedX = (cursor.x-w/2)*0.3;
|
|
|
|
var speedY = (cursor.y-h/2)*0.3;
|
2014-01-17 18:03:42 +01:00
|
|
|
//console.log("move speed: ",speedX,speedY);
|
2014-01-13 18:04:51 +01:00
|
|
|
moveShape(speedX,speedY);
|
|
|
|
}
|
|
|
|
function onBtnZoom(e,cursor) {
|
|
|
|
var h = btnZoom.height();
|
|
|
|
var multiplier = (h/2-cursor.y)*0.003 + 1;
|
|
|
|
zoomShape(multiplier);
|
|
|
|
}
|
|
|
|
function onBtnRotate(e,cursor) {
|
|
|
|
var h = btnZoom.height();
|
|
|
|
var multiplier = (h/2-cursor.y)*0.003;
|
2014-01-16 16:07:40 +01:00
|
|
|
rotateShape(-multiplier);
|
2014-01-13 18:04:51 +01:00
|
|
|
}
|
2014-01-16 16:07:40 +01:00
|
|
|
|
|
|
|
function onBtnHeight(e,cursor) {
|
|
|
|
var h = btnHeight.height();
|
|
|
|
if(cursor.y < h/2) {
|
|
|
|
previewUp(true);
|
|
|
|
} else {
|
|
|
|
previewDown(true);
|
|
|
|
}
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
2014-01-16 16:07:40 +01:00
|
|
|
function onBtnTwist(e,cursor) {
|
|
|
|
var h = btnTwist.height();
|
|
|
|
var multiplier = (cursor.y-h/2)*0.0005;
|
|
|
|
previewTwist(multiplier,true);
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
2014-01-09 17:05:03 +01:00
|
|
|
|
|
|
|
function onBtnOops(e) {
|
|
|
|
oopsUndo();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onBtnNew(e) {
|
|
|
|
clearDoodle();
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
2014-01-13 18:04:51 +01:00
|
|
|
|
2014-01-09 17:05:03 +01:00
|
|
|
function onBtnWordArt(e) {
|
|
|
|
showWordArtDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onBtnShape(e) {
|
|
|
|
showShapeDialog();
|
2014-01-10 17:21:43 +01:00
|
|
|
buttonGroupAdd.fadeOut();
|
2014-01-09 17:05:03 +01:00
|
|
|
}
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2014-01-30 17:49:15 +01:00
|
|
|
btnSettings.on("onButtonClick", openSettingsWindow);
|
2014-01-17 12:51:27 +01:00
|
|
|
|
2013-10-29 21:27:17 +01:00
|
|
|
// 29-okt-2013 - we're not doing help for smartphones at the moment
|
|
|
|
if (clientInfo.isSmartphone) {
|
2014-01-30 17:49:15 +01:00
|
|
|
btnInfo.disable();
|
2013-10-29 21:27:17 +01:00
|
|
|
} else {
|
2014-01-30 17:49:15 +01:00
|
|
|
btnInfo.on("onButtonClick", function(e) {
|
2014-01-17 12:51:27 +01:00
|
|
|
helpTours.startTour(helpTours.WELCOMETOUR);
|
2014-01-30 17:49:15 +01:00
|
|
|
});
|
2013-10-29 21:27:17 +01:00
|
|
|
}
|
2013-08-09 22:25:14 +02:00
|
|
|
}
|
2014-01-09 17:05:03 +01:00
|
|
|
|
2013-08-09 22:25:14 +02:00
|
|
|
function stopPrint() {
|
2013-08-16 22:27:26 +02:00
|
|
|
console.log("f:stopPrint() >> sendPrintCommands = " + sendPrintCommands);
|
2013-10-16 18:32:24 +02:00
|
|
|
//if (!confirm("Weet je zeker dat je huidige print wilt stoppen?")) return;
|
2013-08-16 22:27:26 +02:00
|
|
|
if (sendPrintCommands) printer.stop();
|
2013-10-14 17:40:56 +02:00
|
|
|
//setState(Printer.STOPPING_STATE,printer.hasControl);
|
|
|
|
printer.overruleState(Printer.STOPPING_STATE);
|
2013-07-26 22:39:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function print(e) {
|
2013-08-16 22:27:26 +02:00
|
|
|
console.log("f:print() >> sendPrintCommands = " + sendPrintCommands);
|
|
|
|
|
2013-10-14 18:51:37 +02:00
|
|
|
//$(".btnPrint").css("display","none");
|
2013-10-14 17:46:55 +02:00
|
|
|
|
2013-09-07 16:06:59 +02:00
|
|
|
if (_points.length > 2) {
|
2013-08-16 22:27:26 +02:00
|
|
|
|
2013-10-14 18:51:37 +02:00
|
|
|
//setState(Printer.BUFFERING_STATE,printer.hasControl);
|
2013-10-14 17:40:56 +02:00
|
|
|
printer.overruleState(Printer.BUFFERING_STATE);
|
2013-10-23 18:42:47 +02:00
|
|
|
|
2013-10-16 18:32:24 +02:00
|
|
|
btnStop.css("display","none"); // hack
|
2013-10-23 18:42:47 +02:00
|
|
|
|
|
|
|
// we put the gcode generation in a little delay
|
2013-10-14 18:51:37 +02:00
|
|
|
// so that for example the print button is disabled right away
|
|
|
|
clearTimeout(gcodeGenerateDelayer);
|
2013-10-23 18:42:47 +02:00
|
|
|
gcodeGenerateDelayer = setTimeout(function() {
|
|
|
|
|
2013-10-14 18:51:37 +02:00
|
|
|
var gcode = generate_gcode();
|
2013-10-16 22:25:15 +02:00
|
|
|
if (sendPrintCommands) {
|
|
|
|
if(gcode.length > 0) {
|
|
|
|
printer.print(gcode);
|
|
|
|
} else {
|
|
|
|
printer.overruleState(Printer.IDLE_STATE);
|
|
|
|
printer.startStatusCheckInterval();
|
|
|
|
}
|
2013-10-14 18:51:37 +02:00
|
|
|
} else {
|
|
|
|
console.log("sendPrintCommands is false: not sending print command to 3dprinter");
|
|
|
|
}
|
|
|
|
|
2013-12-05 11:14:12 +01:00
|
|
|
// if (debugMode) {
|
|
|
|
// $("#textdump").text("");
|
|
|
|
// $("#textdump").text(gcode.join("\n"));
|
|
|
|
// }
|
2013-10-23 18:42:47 +02:00
|
|
|
|
2013-10-14 18:51:37 +02:00
|
|
|
}, gcodeGenerateDelay);
|
2013-08-16 22:27:26 +02:00
|
|
|
} else {
|
2013-09-07 16:06:59 +02:00
|
|
|
console.log("f:print >> not enough points!");
|
2013-08-16 22:27:26 +02:00
|
|
|
}
|
2013-09-07 16:06:59 +02:00
|
|
|
|
2013-10-14 18:51:37 +02:00
|
|
|
//alert("Je tekening zal nu geprint worden");
|
|
|
|
//$(".btnPrint").css("display","block");
|
2013-10-14 17:46:55 +02:00
|
|
|
|
2013-09-07 16:06:59 +02:00
|
|
|
|
|
|
|
// $.post("/doodle3d.of", { data:output }, function(data) {
|
|
|
|
// btnPrint.disabled = false;
|
|
|
|
// });
|
2013-07-26 22:39:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function clearMainView() {
|
|
|
|
// console.log("f:clearMainView()");
|
|
|
|
ctx.save();
|
|
|
|
ctx.clearRect(0,0,canvas.width, canvas.height);
|
|
|
|
ctx.restore();
|
|
|
|
}
|
2013-09-17 13:08:52 +02:00
|
|
|
function resetPreview() {
|
|
|
|
// console.log("f:resetPreview()");
|
|
|
|
|
|
|
|
// clear preview canvas
|
2013-07-26 22:39:28 +02:00
|
|
|
previewCtx.save();
|
|
|
|
previewCtx.clearRect(0,0,canvas.width, canvas.height);
|
|
|
|
previewCtx.restore();
|
2013-09-17 13:08:52 +02:00
|
|
|
|
2013-10-29 22:08:08 +01:00
|
|
|
// also make new Image, otherwise the previously cached preview can be redrawn with move up/down or twist left/right
|
|
|
|
doodleImageCapture = new Image();
|
|
|
|
|
2013-09-17 13:08:52 +02:00
|
|
|
// reset height and rotation to default values
|
|
|
|
numLayers = previewDefaults.numLayers; // current number of preview layers
|
|
|
|
rStep = previewDefaults.rotation; // Math.PI/180; //Math.PI/40; //
|
2013-07-26 22:39:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function oopsUndo() {
|
|
|
|
// console.log("f:oopsUndo()");
|
|
|
|
_points.pop();
|
2013-10-28 19:37:33 +01:00
|
|
|
|
|
|
|
if (clientInfo.isSmartphone) {
|
|
|
|
// do not recalc the whole preview's bounds during undo if client device is a smartphone
|
|
|
|
redrawDoodle(false);
|
|
|
|
} else {
|
|
|
|
// recalc the whole preview's bounds during if client device is not a smartphone
|
|
|
|
redrawDoodle(true);
|
|
|
|
}
|
2013-07-26 22:39:28 +02:00
|
|
|
redrawPreview();
|
|
|
|
}
|
2014-01-09 17:05:03 +01:00
|
|
|
|
2013-08-16 22:27:26 +02:00
|
|
|
function previewUp(redrawLess) {
|
2013-07-26 22:39:28 +02:00
|
|
|
// console.log("f:previewUp()");
|
2013-09-07 16:06:59 +02:00
|
|
|
if (numLayers < maxNumLayers) {
|
2013-07-26 22:39:28 +02:00
|
|
|
numLayers++;
|
|
|
|
}
|
2013-10-29 23:26:09 +01:00
|
|
|
setSketchModified(true);
|
|
|
|
|
2013-08-21 17:37:20 +02:00
|
|
|
// redrawPreview(redrawLess);
|
2013-08-21 18:08:32 +02:00
|
|
|
redrawRenderedPreview(redrawLess);
|
2013-07-26 22:39:28 +02:00
|
|
|
}
|
2013-08-16 22:27:26 +02:00
|
|
|
function previewDown(redrawLess) {
|
2013-07-26 22:39:28 +02:00
|
|
|
// console.log("f:previewDown()");
|
2013-09-07 16:06:59 +02:00
|
|
|
if (numLayers > minNumLayers) {
|
2013-07-26 22:39:28 +02:00
|
|
|
numLayers--;
|
|
|
|
}
|
2013-10-29 23:26:09 +01:00
|
|
|
setSketchModified(true);
|
2013-08-21 17:37:20 +02:00
|
|
|
// redrawPreview(redrawLess);
|
2013-08-21 18:08:32 +02:00
|
|
|
redrawRenderedPreview(redrawLess);
|
2013-07-26 22:39:28 +02:00
|
|
|
}
|
2013-08-16 22:27:26 +02:00
|
|
|
function previewTwistLeft(redrawLess) {
|
2014-01-16 16:07:40 +01:00
|
|
|
previewTwist(-twistIncrement,true)
|
2013-07-26 22:39:28 +02:00
|
|
|
}
|
2013-08-16 22:27:26 +02:00
|
|
|
function previewTwistRight(redrawLess) {
|
2014-01-16 16:07:40 +01:00
|
|
|
previewTwist(twistIncrement,true)
|
|
|
|
}
|
|
|
|
function previewTwist(increment,redrawLess) {
|
|
|
|
console.log("previewTwist: ",increment);
|
|
|
|
if (redrawLess == undefined) redrawLess = false;
|
|
|
|
|
|
|
|
rStep += increment;
|
|
|
|
if(rStep < -previewRotationLimit) rStep = -previewRotationLimit;
|
|
|
|
else if(rStep > previewRotationLimit) rStep = previewRotationLimit;
|
|
|
|
|
2013-08-21 18:08:32 +02:00
|
|
|
redrawRenderedPreview(redrawLess);
|
2013-10-29 23:26:09 +01:00
|
|
|
setSketchModified(true);
|
2013-08-07 20:47:47 +02:00
|
|
|
}
|
|
|
|
|
2013-12-05 11:14:12 +01:00
|
|
|
function resetTwist() {
|
|
|
|
rStep = 0;
|
|
|
|
redrawRenderedPreview();
|
|
|
|
setSketchModified(true);
|
|
|
|
}
|
2013-08-07 20:47:47 +02:00
|
|
|
|
2013-08-09 22:25:14 +02:00
|
|
|
function update() {
|
2014-01-27 13:19:20 +01:00
|
|
|
|
|
|
|
|
2013-10-11 16:17:58 +02:00
|
|
|
setState(printer.state,printer.hasControl);
|
2013-10-14 16:40:48 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
thermometer.update(printer.temperature, printer.targetTemperature);
|
2013-10-17 14:40:33 +02:00
|
|
|
progressbar.update(printer.currentLine, printer.totalLines);
|
2013-08-09 22:25:14 +02:00
|
|
|
}
|
|
|
|
|
2013-10-23 18:42:47 +02:00
|
|
|
function setState(newState,newHasControl) {
|
2013-10-11 16:17:58 +02:00
|
|
|
if(newState == state && newHasControl == hasControl) return;
|
2013-10-14 16:40:48 +02:00
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
prevState = state;
|
2013-10-23 18:42:47 +02:00
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
console.log("setState: ",prevState," > ",newState," ( ",newHasControl,")");
|
2013-10-11 12:39:05 +02:00
|
|
|
setDebugText("State: "+newState);
|
2013-10-14 16:40:48 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
// print button
|
2013-10-11 16:17:58 +02:00
|
|
|
var printEnabled = (newState == Printer.IDLE_STATE && newHasControl);
|
|
|
|
if(printEnabled) {
|
2014-01-30 17:49:15 +01:00
|
|
|
btnPrint.enable();
|
2013-10-11 16:17:58 +02:00
|
|
|
} else {
|
2014-01-30 17:49:15 +01:00
|
|
|
btnPrint.disable();
|
2013-10-11 12:39:05 +02:00
|
|
|
}
|
2013-10-14 16:40:48 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
// stop button
|
2013-10-11 16:17:58 +02:00
|
|
|
var stopEnabled = ((newState == Printer.PRINTING_STATE || newState == Printer.BUFFERING_STATE) && newHasControl);
|
|
|
|
if(stopEnabled) {
|
2014-01-30 17:49:15 +01:00
|
|
|
btnStop.enable();
|
2013-10-11 16:17:58 +02:00
|
|
|
} else {
|
2014-01-30 17:49:15 +01:00
|
|
|
btnStop.disable();
|
2013-10-11 12:39:05 +02:00
|
|
|
}
|
2013-10-14 16:40:48 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
// thermometer
|
|
|
|
switch(newState) {
|
2013-10-23 18:42:47 +02:00
|
|
|
case Printer.IDLE_STATE: /* fall-through */
|
|
|
|
case Printer.BUFFERING_STATE: /* fall-through */
|
|
|
|
case Printer.PRINTING_STATE: /* fall-through */
|
2013-10-18 19:11:10 +02:00
|
|
|
case Printer.STOPPING_STATE:
|
2013-10-23 18:42:47 +02:00
|
|
|
thermometer.show();
|
2013-10-11 12:39:05 +02:00
|
|
|
break;
|
|
|
|
default:
|
2013-10-23 18:42:47 +02:00
|
|
|
thermometer.hide();
|
2013-10-11 12:39:05 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-10-14 16:40:48 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
// progress indicator
|
|
|
|
switch(newState) {
|
2013-10-14 16:40:48 +02:00
|
|
|
case Printer.PRINTING_STATE:
|
2013-10-23 18:42:47 +02:00
|
|
|
progressbar.show();
|
2013-10-11 12:39:05 +02:00
|
|
|
break;
|
|
|
|
default:
|
2013-10-17 14:40:33 +02:00
|
|
|
progressbar.hide();
|
2013-08-09 22:25:14 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-10-23 18:42:47 +02:00
|
|
|
|
|
|
|
/* settings button */
|
|
|
|
switch(newState) {
|
2013-10-23 23:40:26 +02:00
|
|
|
case Printer.IDLE_STATE:
|
2014-01-30 17:49:15 +01:00
|
|
|
btnSettings.enable();
|
2013-10-23 23:40:26 +02:00
|
|
|
break;
|
|
|
|
case Printer.WIFIBOX_DISCONNECTED_STATE: /* fall-through */
|
|
|
|
case Printer.BUFFERING_STATE: /* fall-through */
|
|
|
|
case Printer.PRINTING_STATE: /* fall-through */
|
|
|
|
case Printer.STOPPING_STATE:
|
2014-01-30 17:49:15 +01:00
|
|
|
btnSettings.disable();
|
2013-10-23 23:40:26 +02:00
|
|
|
break;
|
|
|
|
default:
|
2014-01-30 17:49:15 +01:00
|
|
|
btnSettings.enable();
|
2013-10-23 23:40:26 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-10-29 15:09:07 +01:00
|
|
|
|
|
|
|
/* save, next and prev buttons */
|
|
|
|
switch(newState) {
|
2013-10-29 23:26:09 +01:00
|
|
|
case Printer.WIFIBOX_DISCONNECTED_STATE:
|
2014-01-30 17:49:15 +01:00
|
|
|
btnPrevious.disable();
|
|
|
|
btnNext.disable()
|
|
|
|
btnSave.disable();
|
2013-10-29 15:09:07 +01:00
|
|
|
break;
|
|
|
|
default:
|
2013-10-29 23:26:09 +01:00
|
|
|
updatePrevNextButtonState();
|
2014-01-30 17:49:15 +01:00
|
|
|
if (isModified) btnSave.enable();
|
2013-10-29 15:09:07 +01:00
|
|
|
break;
|
|
|
|
}
|
2013-10-23 18:42:47 +02:00
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
if(newState == Printer.WIFIBOX_DISCONNECTED_STATE) {
|
|
|
|
message.set("Lost connection to WiFi box",Message.ERROR);
|
|
|
|
} else if(prevState == Printer.WIFIBOX_DISCONNECTED_STATE) {
|
|
|
|
message.set("Connected to WiFi box",Message.INFO,true);
|
|
|
|
} else if(newState == Printer.DISCONNECTED_STATE) {
|
|
|
|
message.set("Printer disconnected",Message.WARNING,true);
|
2013-10-23 18:42:47 +02:00
|
|
|
} else if(prevState == Printer.DISCONNECTED_STATE && newState == Printer.IDLE_STATE ||
|
2013-10-18 19:11:10 +02:00
|
|
|
prevState == Printer.UNKNOWN_STATE && newState == Printer.IDLE_STATE) {
|
|
|
|
message.set("Printer connected",Message.INFO,true);
|
2014-01-27 13:19:20 +01:00
|
|
|
console.log(" preheat: ",settings["printer.heatup.enabled"]);
|
|
|
|
if(settings["printer.heatup.enabled"]) {
|
2014-02-12 17:27:41 +01:00
|
|
|
// HACK: we delay the preheat because the driver needs time to connect
|
|
|
|
clearTimeout(preheatDelay);
|
|
|
|
preheatDelay = setTimeout(printer.preheat,preheatDelayTime); // retry after delay
|
2014-01-27 13:19:20 +01:00
|
|
|
}
|
2013-10-23 18:42:47 +02:00
|
|
|
} else if(prevState == Printer.PRINTING_STATE && newState == Printer.STOPPING_STATE) {
|
|
|
|
console.log("stopmsg show");
|
|
|
|
message.set("Printer stopping",Message.INFO,false);
|
|
|
|
} else if(prevState == Printer.STOPPING_STATE && newState == Printer.IDLE_STATE) {
|
|
|
|
console.log("stopmsg hide");
|
|
|
|
message.hide();
|
2013-10-18 19:11:10 +02:00
|
|
|
}
|
2013-10-23 18:42:47 +02:00
|
|
|
|
2013-08-09 22:25:14 +02:00
|
|
|
state = newState;
|
2013-10-11 16:17:58 +02:00
|
|
|
hasControl = newHasControl;
|
2013-10-14 16:40:48 +02:00
|
|
|
}
|