From 2457ce656e02a632ecabe2d6687e6c9b8d7518d7 Mon Sep 17 00:00:00 2001 From: Wouter R Date: Wed, 5 Mar 2014 13:49:15 +0100 Subject: [PATCH] Code formatting. --- js/Printer.js | 328 ++++++++++++++-------------- js/buttonbehaviors.js | 493 +++++++++++++++++++++--------------------- 2 files changed, 414 insertions(+), 407 deletions(-) diff --git a/js/Printer.js b/js/Printer.js index f5f3dc5..d0c1680 100644 --- a/js/Printer.js +++ b/js/Printer.js @@ -11,51 +11,51 @@ var $printProgressContainer = $("#printProgressContainer"); var $progressbar = $("#progressbar"); var $progressAmount = $(".progressAmount"); function setPrintprogress(val) { - if (isNaN(val)) return; -// console.log("f:setPrintprogress() >> val " + val); - $progressbar.css("width", val*100 + "%"); - $progressAmount.text(Math.floor(val*100) + "%"); + if (isNaN(val)) return; +// console.log("f:setPrintprogress() >> val " + val); + $progressbar.css("width", val*100 + "%"); + $progressAmount.text(Math.floor(val*100) + "%"); } //*/ function Printer() { - Printer.WIFIBOX_DISCONNECTED_STATE = "wifibox disconnected"; - Printer.UNKNOWN_STATE = "unknown"; // happens when a printer is connection but there isn't communication yet - Printer.DISCONNECTED_STATE = "disconnected"; // printer disconnected - Printer.IDLE_STATE = "idle"; // printer found, but idle - Printer.BUFFERING_STATE = "buffering"; // printer is buffering (recieving) data, but not yet printing - Printer.PRINTING_STATE = "printing"; - Printer.STOPPING_STATE = "stopping"; // when you stop (abort) a print it prints the endcode - Printer.TOUR_STATE = "tour"; // when in joyride mode + Printer.WIFIBOX_DISCONNECTED_STATE = "wifibox disconnected"; + Printer.UNKNOWN_STATE = "unknown"; // happens when a printer is connection but there isn't communication yet + Printer.DISCONNECTED_STATE = "disconnected"; // printer disconnected + Printer.IDLE_STATE = "idle"; // printer found, but idle + Printer.BUFFERING_STATE = "buffering"; // printer is buffering (recieving) data, but not yet printing + Printer.PRINTING_STATE = "printing"; + Printer.STOPPING_STATE = "stopping"; // when you stop (abort) a print it prints the endcode + Printer.TOUR_STATE = "tour"; // when in joyride mode Printer.ON_BEFORE_UNLOAD_MESSAGE = "You're doodle is still being send to the printer, leaving will result in a incomplete 3D print"; - this.temperature = 0; + this.temperature = 0; this.targetTemperature = 0; - this.currentLine = 0; - this.totalLines = 0; - this.bufferedLines = 0; - this.state = Printer.UNKNOWN_STATE; - this.hasControl = true; // whether this client has control access + this.currentLine = 0; + this.totalLines = 0; + this.bufferedLines = 0; + this.state = Printer.UNKNOWN_STATE; + this.hasControl = true; // whether this client has control access this.wifiboxURL; - this.checkStatusInterval = 3000; + this.checkStatusInterval = 3000; this.checkStatusDelay; - this.timeoutTime = 3000; - this.sendPrintPartTimeoutTime = 5000; + this.timeoutTime = 3000; + this.sendPrintPartTimeoutTime = 5000; - this.gcode; // gcode to be printed + this.gcode; // gcode to be printed this.sendLength = 500; // max amount of gcode lines per post (limited because WiFi box can't handle to much) - this.retryDelay = 2000; // retry setTimout delay - this.retrySendPrintPartDelay; // retry setTimout instance + this.retryDelay = 2000; // retry setTimout delay + this.retrySendPrintPartDelay; // retry setTimout instance this.retryCheckStatusDelay; // retry setTimout instance - this.retryStopDelay; // retry setTimout instance - this.retryPreheatDelay; // retry setTimout instance + this.retryStopDelay; // retry setTimout instance + this.retryPreheatDelay; // retry setTimout instance - Printer.MAX_GCODE_SIZE = 10; // max size of gcode in MB's (estimation) + Printer.MAX_GCODE_SIZE = 10; // max size of gcode in MB's (estimation) this.stateOverruled = false; @@ -65,40 +65,40 @@ function Printer() { var self = this; this.init = function() { - //console.log("Printer:init"); + //console.log("Printer:init"); //this.wifiboxURL = "http://" + window.location.host + "/cgi-bin/d3dapi"; //this.wifiboxURL = "http://192.168.5.1/cgi-bin/d3dapi"; this.wifiboxURL = wifiboxURL; //this.wifiboxURL = "proxy5.php"; - //console.log(" wifiboxURL: ",this.wifiboxURL); + //console.log(" wifiboxURL: ",this.wifiboxURL); - if(autoUpdate) { - this.startStatusCheckInterval(); - } - } + if (autoUpdate) { + this.startStatusCheckInterval(); + } + } this.preheat = function() { - console.log("Printer:preheat"); + console.log("Printer:preheat"); - if( this.state == Printer.BUFFERING_STATE || - this.state == Printer.PRINTING_STATE || - this.state == Printer.STOPPING_STATE) { - return; - } + if( this.state == Printer.BUFFERING_STATE || + this.state == Printer.PRINTING_STATE || + this.state == Printer.STOPPING_STATE) { + return; + } - var self = this; - if (communicateWithWifibox) { - $.ajax({ - url: this.wifiboxURL + "/printer/heatup", - type: "POST", - dataType: 'json', - timeout: this.timeoutTime, - success: function(data){ - console.log("Printer:preheat response: ",data); - if(data.status != "success") { - clearTimeout(self.retryPreheatDelay); + var self = this; + if (communicateWithWifibox) { + $.ajax({ + url: this.wifiboxURL + "/printer/heatup", + type: "POST", + dataType: 'json', + timeout: this.timeoutTime, + success: function(data){ + console.log("Printer:preheat response: ",data); + if(data.status != "success") { + clearTimeout(self.retryPreheatDelay); self.retryPreheatDelay = setTimeout(function() { self.preheat() },self.retryDelay); // retry after delay - } + } } }).fail(function() { console.log("Printer:preheat: failed"); @@ -106,99 +106,101 @@ function Printer() { self.retryPreheatDelay = setTimeout(function() { self.preheat() },self.retryDelay); // retry after delay }); } else { - console.log ("Printer >> f:preheat() >> communicateWithWifibox is false, so not executing this function"); - } + console.log ("Printer >> f:preheat() >> communicateWithWifibox is false, so not executing this function"); + } } this.print = function(gcode) { - console.log("Printer:print"); - console.log(" gcode total # of lines: " + gcode.length); + console.log("Printer:print"); + console.log(" gcode total # of lines: " + gcode.length); - message.set("Sending doodle to printer...",Message.NOTICE); - self.addLeaveWarning(); + message.set("Sending doodle to printer...",Message.NOTICE); + self.addLeaveWarning(); - /*for (i = 0; i < gcode.length; i++) { + /*for (i = 0; i < gcode.length; i++) { gcode[i] += " (" + i + ")"; }*/ this.sendIndex = 0; - this.gcode = gcode; + this.gcode = gcode; - //console.log(" gcode[20]: ",gcode[20]); - var gcodeLineSize = this.byteSize(gcode[20]); - //console.log(" gcodeLineSize: ",gcodeLineSize); - var gcodeSize = gcodeLineSize*gcode.length/1024/1024; // estimate gcode size in MB's - console.log(" gcodeSize: ",gcodeSize); + //console.log(" gcode[20]: ",gcode[20]); + var gcodeLineSize = this.byteSize(gcode[20]); + //console.log(" gcodeLineSize: ",gcodeLineSize); + var gcodeSize = gcodeLineSize*gcode.length/1024/1024; // estimate gcode size in MB's + console.log(" gcodeSize: ",gcodeSize); - if(gcodeSize > Printer.MAX_GCODE_SIZE) { - alert("Error: Printer:print: gcode file is probably too big ("+gcodeSize+"MB) (max: "+Printer.MAX_GCODE_SIZE+"MB)"); - console.log("Error: Printer:print: gcode file is probably too big ("+gcodeSize+"MB) (max: "+Printer.MAX_GCODE_SIZE+"MB)"); + if(gcodeSize > Printer.MAX_GCODE_SIZE) { + alert("Error: Printer:print: gcode file is probably too big ("+gcodeSize+"MB) (max: "+Printer.MAX_GCODE_SIZE+"MB)"); + console.log("Error: Printer:print: gcode file is probably too big ("+gcodeSize+"MB) (max: "+Printer.MAX_GCODE_SIZE+"MB)"); - this.overruleState(Printer.IDLE_STATE); - this.startStatusCheckInterval(); - message.hide(); - self.removeLeaveWarning(); + this.overruleState(Printer.IDLE_STATE); + this.startStatusCheckInterval(); + message.hide(); + self.removeLeaveWarning(); - return; - } + return; + } - //this.targetTemperature = settings["printer.temperature"]; // slight hack + //this.targetTemperature = settings["printer.temperature"]; // slight hack this.sendPrintPart(this.sendIndex, this.sendLength); } + this.byteSize = function(s){ return~-encodeURI(s).split(/%..|./).length; } + this.sendPrintPart = function(sendIndex,sendLength) { console.log("Printer:sendPrintPart sendIndex: " + sendIndex + "/" + this.gcode.length + ", sendLength: " + sendLength); - + var sendPercentage = Math.round(sendIndex/this.gcode.length*100); message.set("Sending doodle to printer: "+sendPercentage+"%",Message.NOTICE,false,true); - - var firstOne = (sendIndex == 0)? true : false; - var start = firstOne; // start printing right away - - var completed = false; - if (this.gcode.length < (sendIndex + sendLength)) { - console.log(" sending less than max sendLength (and last)"); - sendLength = this.gcode.length - sendIndex; - //lastOne = true; - completed = true; - } - var gcodePart = this.gcode.slice(sendIndex, sendIndex+sendLength); - var postData = { gcode: gcodePart.join("\n"), first: firstOne, start: start}; - var self = this; - if (communicateWithWifibox) { - $.ajax({ - url: this.wifiboxURL + "/printer/print", - type: "POST", - data: postData, - dataType: 'json', - timeout: this.sendPrintPartTimeoutTime, - success: function(data){ - console.log("Printer:sendPrintPart response: ",data); + var firstOne = (sendIndex == 0)? true : false; + var start = firstOne; // start printing right away - if(data.status == "success") { - if (completed) { - console.log("Printer:sendPrintPart:gcode sending completed"); - this.gcode = []; - btnStop.css("display","block"); // hack - self.removeLeaveWarning(); - message.set("Doodle has been sent to printer...",Message.INFO,true); - //self.targetTemperature = settings["printer.temperature"]; // slight hack - } else { - // only if the state hasn't bin changed (by for example pressing stop) we send more gcode + var completed = false; + if (this.gcode.length < (sendIndex + sendLength)) { + console.log(" sending less than max sendLength (and last)"); + sendLength = this.gcode.length - sendIndex; + //lastOne = true; + completed = true; + } + var gcodePart = this.gcode.slice(sendIndex, sendIndex+sendLength); - //console.log("Printer:sendPrintPart:gcode part received (state: ",self.state,")"); - if(self.state == Printer.PRINTING_STATE || self.state == Printer.BUFFERING_STATE) { - //console.log("Printer:sendPrintPart:sending next part"); - self.sendPrintPart(sendIndex + sendLength, sendLength); - } - } - } - // after we know the first gcode packed has bin received or failed + var postData = { gcode: gcodePart.join("\n"), first: firstOne, start: start}; + var self = this; + if (communicateWithWifibox) { + $.ajax({ + url: this.wifiboxURL + "/printer/print", + type: "POST", + data: postData, + dataType: 'json', + timeout: this.sendPrintPartTimeoutTime, + success: function(data){ + console.log("Printer:sendPrintPart response: ",data); + + if(data.status == "success") { + if (completed) { + console.log("Printer:sendPrintPart:gcode sending completed"); + this.gcode = []; + btnStop.css("display","block"); // hack + self.removeLeaveWarning(); + message.set("Doodle has been sent to printer...",Message.INFO,true); + //self.targetTemperature = settings["printer.temperature"]; // slight hack + } else { + // only if the state hasn't bin changed (by for example pressing stop) we send more gcode + + //console.log("Printer:sendPrintPart:gcode part received (state: ",self.state,")"); + if(self.state == Printer.PRINTING_STATE || self.state == Printer.BUFFERING_STATE) { + //console.log("Printer:sendPrintPart:sending next part"); + self.sendPrintPart(sendIndex + sendLength, sendLength); + } + } + } + // after we know the first gcode packed has bin received or failed // (and the driver had time to update the printer.state) // we start checking the status again if(sendIndex == 0) { @@ -219,31 +221,31 @@ function Printer() { self.startStatusCheckInterval(); }); } else { - console.log ("Printer >> f:sendPrintPart() >> communicateWithWifibox is false, so not executing this function"); - } + console.log ("Printer >> f:sendPrintPart() >> communicateWithWifibox is false, so not executing this function"); + } } this.stop = function() { - console.log("Printer:stop"); - endCode = generateEndCode(); - console.log(" endCode: ",endCode); - var postData = { gcode: endCode.join("\n")}; + console.log("Printer:stop"); + endCode = generateEndCode(); + console.log(" endCode: ",endCode); + var postData = { gcode: endCode.join("\n")}; var self = this; if (communicateWithWifibox) { - $.ajax({ - url: this.wifiboxURL + "/printer/stop", - type: "POST", - data: postData, - dataType: 'json', - timeout: this.timeoutTime, - success: function(data){ - console.log("Printer:stop response: ", data); + $.ajax({ + url: this.wifiboxURL + "/printer/stop", + type: "POST", + data: postData, + dataType: 'json', + timeout: this.timeoutTime, + success: function(data){ + console.log("Printer:stop response: ", data); - // after we know the stop has bin received or failed + // after we know the stop has bin received or failed // (and the driver had time to update the printer.state) // we start checking the status again self.startStatusCheckInterval(); - } + } }).fail(function() { console.log("Printer:stop: failed"); clearTimeout(self.retryStopDelay); @@ -255,9 +257,10 @@ function Printer() { self.startStatusCheckInterval(); }); } else { - console.log ("Printer >> f:communicateWithWifibox() >> communicateWithWifibox is false, so not executing this function"); - } + console.log ("Printer >> f:communicateWithWifibox() >> communicateWithWifibox is false, so not executing this function"); + } } + this.startStatusCheckInterval = function() { console.log("Printer:startStatusCheckInterval"); self.checkStatus(); @@ -265,42 +268,45 @@ function Printer() { clearTimeout(self.retryCheckStatusDelay); self.checkStatusDelay = setTimeout(function() { self.checkStatus() }, self.checkStatusInterval); } + this.stopStatusCheckInterval = function() { console.log("Printer:stopStatusCheckInterval"); clearTimeout(self.checkStatusDelay); clearTimeout(self.retryCheckStatusDelay); } + this.checkStatus = function() { //console.log("Printer:checkStatus"); this.stateOverruled = false; //console.log(" stateOverruled: ",this.stateOverruled); - var self = this; - if (communicateWithWifibox) { - $.ajax({ - url: this.wifiboxURL + "/info/status", - dataType: 'json', - timeout: this.timeoutTime, - success: function(response){ - //console.log(" Printer:status: ",response.data.state); //," response: ",response); + var self = this; + if (communicateWithWifibox) { + $.ajax({ + url: this.wifiboxURL + "/info/status", + dataType: 'json', + timeout: this.timeoutTime, + success: function(response){ + //console.log(" Printer:status: ",response.data.state); //," response: ",response); - self.handleStatusUpdate(response); + self.handleStatusUpdate(response); - clearTimeout(self.checkStatusDelay); - clearTimeout(self.retryCheckStatusDelay); - self.checkStatusDelay = setTimeout(function() { self.checkStatus() }, self.checkStatusInterval); - } - }).fail(function() { - console.log("Printer:checkStatus: failed"); - self.state = Printer.WIFIBOX_DISCONNECTED_STATE; - clearTimeout(self.checkStatusDelay); - clearTimeout(self.retryCheckStatusDelay); - self.retryCheckStatusDelay = setTimeout(function() { self.checkStatus() },self.retryDelay); // retry after delay - $(document).trigger(Printer.UPDATE); - }); - } else { - console.log ("Printer >> f:checkStatus() >> communicateWithWifibox is false, so not executing this function"); - } + clearTimeout(self.checkStatusDelay); + clearTimeout(self.retryCheckStatusDelay); + self.checkStatusDelay = setTimeout(function() { self.checkStatus() }, self.checkStatusInterval); + } + }).fail(function() { + console.log("Printer:checkStatus: failed"); + self.state = Printer.WIFIBOX_DISCONNECTED_STATE; + clearTimeout(self.checkStatusDelay); + clearTimeout(self.retryCheckStatusDelay); + self.retryCheckStatusDelay = setTimeout(function() { self.checkStatus() },self.retryDelay); // retry after delay + $(document).trigger(Printer.UPDATE); + }); + } else { + console.log ("Printer >> f:checkStatus() >> communicateWithWifibox is false, so not executing this function"); + } } + this.handleStatusUpdate = function(response) { //console.log("Printer:handleStatusUpdate response: ",response); var data = response.data; @@ -332,6 +338,7 @@ function Printer() { } $(document).trigger(Printer.UPDATE); } + this.overruleState = function(newState) { this.stateOverruled = true; console.log(" stateOverruled: ",this.stateOverruled); @@ -346,10 +353,11 @@ function Printer() { this.removeLeaveWarning = function() { window.onbeforeunload = null; } + this.addLeaveWarning = function() { window.onbeforeunload = function() { - console.log("WARNING:"+Printer.ON_BEFORE_UNLOAD_MESSAGE); - return Printer.ON_BEFORE_UNLOAD_MESSAGE; + console.log("WARNING:"+Printer.ON_BEFORE_UNLOAD_MESSAGE); + return Printer.ON_BEFORE_UNLOAD_MESSAGE; }; } } diff --git a/js/buttonbehaviors.js b/js/buttonbehaviors.js index a0df642..664b099 100644 --- a/js/buttonbehaviors.js +++ b/js/buttonbehaviors.js @@ -26,117 +26,118 @@ var preheatDelay; var preheatDelayTime = 15*1000; function initButtonBehavior() { - console.log("f:initButtonBehavior"); + console.log("f:initButtonBehavior"); - 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"); - buttonGroupAdd = $("#buttonGroupAdd"); + 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"); + buttonGroupAdd = $("#buttonGroupAdd"); btnShape = new Button("#btnShape"); btnWordArt = new Button("#btnWordArt"); popupWordArt = $("#popupWordArt"); popupShape = $("#popupShape"); popupMask = $("#popupMask"); logoPanel = $("#logopanel"); - btnToggleEdit = new Button("#btnToggleEdit"); - buttonGroupEdit = $("#buttonGroupEdit"); - btnZoom = new Button("#btnZoom"); - btnMove = new Button("#btnMove"); - btnRotate = new Button("#btnRotate"); - btnToggleVerticalShapes = new Button("#btnToggleVerticalShapes"); - buttonGroupVerticalShapes = $("#buttonGroupVerticalShapes"); - 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 - - logoPanel.on("onButtonClick", onLogo); - btnNew.on("onButtonClick", onBtnNew); - btnAdd.on("onButtonClick", onBtnAdd); - btnWordArt.on("onButtonClick", onBtnWordArt); - btnShape.on("onButtonClick", onBtnShape); - btnPrint.on("onButtonClick", print); - btnStop.on("onButtonClick", stopPrint); - btnSave.on("onButtonClick", saveSketch); - btnPrevious.on("onButtonClick", prevDoodle); - btnNext.on("onButtonClick", nextDoodle); - btnOops.on("onButtonHold", onBtnOops); - // vertical shape buttons - btnToggleVerticalShapes.on("onButtonClick", onBtnToggleVerticalShapes); - btnHeight.on("onButtonHold", onBtnHeight); - btnTwist.on("onButtonHold", onBtnTwist); - btnStraight.on("onButtonClick", onBtnStraight); + btnToggleEdit = new Button("#btnToggleEdit"); + buttonGroupEdit = $("#buttonGroupEdit"); + btnZoom = new Button("#btnZoom"); + btnMove = new Button("#btnMove"); + btnRotate = new Button("#btnRotate"); + btnToggleVerticalShapes = new Button("#btnToggleVerticalShapes"); + buttonGroupVerticalShapes = $("#buttonGroupVerticalShapes"); + 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 + + logoPanel.on("onButtonClick", onLogo); + btnNew.on("onButtonClick", onBtnNew); + btnAdd.on("onButtonClick", onBtnAdd); + btnWordArt.on("onButtonClick", onBtnWordArt); + btnShape.on("onButtonClick", onBtnShape); + btnPrint.on("onButtonClick", print); + btnStop.on("onButtonClick", stopPrint); + btnSave.on("onButtonClick", saveSketch); + btnPrevious.on("onButtonClick", prevDoodle); + btnNext.on("onButtonClick", nextDoodle); + btnOops.on("onButtonHold", onBtnOops); + // vertical shape buttons + btnToggleVerticalShapes.on("onButtonClick", onBtnToggleVerticalShapes); + btnHeight.on("onButtonHold", onBtnHeight); + btnTwist.on("onButtonHold", onBtnTwist); + btnStraight.on("onButtonClick", onBtnStraight); 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); - - getSavedSketchStatus(); - setSketchModified(false); - 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); - } + btnToggleEdit.on("onButtonClick", onBtnToggleEdit); + btnMove.on("onButtonHold", onBtnMove); + btnZoom.on("onButtonHold", onBtnZoom); + btnRotate.on("onButtonHold", onBtnRotate); - function onLogo() { - location.reload(); + getSavedSketchStatus(); + setSketchModified(false); + + 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); } - function onBtnAdd() { - buttonGroupAdd.fadeToggle(BUTTON_GROUP_SHOW_DURATION); - } - function onBtnStraight() { - setVerticalShape(verticalShapes.NONE); - } - function onBtnDiv() { - setVerticalShape(verticalShapes.DIVERGING); - } - function onBtnConv() { - setVerticalShape(verticalShapes.CONVERGING); - } - function onBtnSine() { - setVerticalShape(verticalShapes.SINUS); - } + function onLogo() { + location.reload(); + } - function hitTest(cursor,button,radius) { - return distance(cursor.x,cursor.y,button.x,button.y)> sendPrintCommands = " + sendPrintCommands); - //if (!confirm("Weet je zeker dat je huidige print wilt stoppen?")) return; - if (sendPrintCommands) printer.stop(); - //setState(Printer.STOPPING_STATE,printer.hasControl); - printer.overruleState(Printer.STOPPING_STATE); + console.log("f:stopPrint() >> sendPrintCommands = " + sendPrintCommands); + //if (!confirm("Weet je zeker dat je huidige print wilt stoppen?")) return; + if (sendPrintCommands) printer.stop(); + //setState(Printer.STOPPING_STATE,printer.hasControl); + printer.overruleState(Printer.STOPPING_STATE); } function print(e) { console.log("f:print() >> sendPrintCommands = " + sendPrintCommands); - //$(".btnPrint").css("display","none"); + //$(".btnPrint").css("display","none"); - if (_points.length > 2) { + if (_points.length > 2) { - //setState(Printer.BUFFERING_STATE,printer.hasControl); - printer.overruleState(Printer.BUFFERING_STATE); + //setState(Printer.BUFFERING_STATE,printer.hasControl); + printer.overruleState(Printer.BUFFERING_STATE); - btnStop.css("display","none"); // hack + btnStop.css("display","none"); // hack - // we put the gcode generation in a little delay - // so that for example the print button is disabled right away - clearTimeout(gcodeGenerateDelayer); - gcodeGenerateDelayer = setTimeout(function() { + // we put the gcode generation in a little delay + // so that for example the print button is disabled right away + clearTimeout(gcodeGenerateDelayer); + gcodeGenerateDelayer = setTimeout(function() { - var gcode = generate_gcode(); - if (sendPrintCommands) { - if(gcode.length > 0) { - printer.print(gcode); - } else { - printer.overruleState(Printer.IDLE_STATE); - printer.startStatusCheckInterval(); - } + var gcode = generate_gcode(); + if (sendPrintCommands) { + if(gcode.length > 0) { + printer.print(gcode); + } else { + printer.overruleState(Printer.IDLE_STATE); + printer.startStatusCheckInterval(); + } } else { console.log("sendPrintCommands is false: not sending print command to 3dprinter"); } @@ -242,75 +243,75 @@ function print(e) { // $("#textdump").text(gcode.join("\n")); // } - }, gcodeGenerateDelay); - } else { - console.log("f:print >> not enough points!"); - } + }, gcodeGenerateDelay); + } else { + console.log("f:print >> not enough points!"); + } - //alert("Je tekening zal nu geprint worden"); - //$(".btnPrint").css("display","block"); + //alert("Je tekening zal nu geprint worden"); + //$(".btnPrint").css("display","block"); - // $.post("/doodle3d.of", { data:output }, function(data) { - // btnPrint.disabled = false; - // }); + // $.post("/doodle3d.of", { data:output }, function(data) { + // btnPrint.disabled = false; + // }); } function clearMainView() { - // console.log("f:clearMainView()"); - ctx.save(); - ctx.clearRect(0,0,canvas.width, canvas.height); - ctx.restore(); + // console.log("f:clearMainView()"); + ctx.save(); + ctx.clearRect(0,0,canvas.width, canvas.height); + ctx.restore(); } function resetPreview() { - // console.log("f:resetPreview()"); + // console.log("f:resetPreview()"); - // clear preview canvas - previewCtx.save(); - previewCtx.clearRect(0,0,canvas.width, canvas.height); - previewCtx.restore(); + // clear preview canvas + previewCtx.save(); + previewCtx.clearRect(0,0,canvas.width, canvas.height); + previewCtx.restore(); - // also make new Image, otherwise the previously cached preview can be redrawn with move up/down or twist left/right - doodleImageCapture = new Image(); + // also make new Image, otherwise the previously cached preview can be redrawn with move up/down or twist left/right + doodleImageCapture = new Image(); - // reset height and rotation to default values - numLayers = previewDefaults.numLayers; // current number of preview layers - rStep = previewDefaults.rotation; // Math.PI/180; //Math.PI/40; // + // reset height and rotation to default values + numLayers = previewDefaults.numLayers; // current number of preview layers + rStep = previewDefaults.rotation; // Math.PI/180; //Math.PI/40; // } function oopsUndo() { - // console.log("f:oopsUndo()"); - _points.pop(); + // console.log("f:oopsUndo()"); + _points.pop(); - 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); - } - redrawPreview(); + 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); + } + redrawPreview(); } function previewUp(redrawLess) { - // console.log("f:previewUp()"); - if (numLayers < maxNumLayers) { - numLayers++; - } - setSketchModified(true); + // console.log("f:previewUp()"); + if (numLayers < maxNumLayers) { + numLayers++; + } + setSketchModified(true); -// redrawPreview(redrawLess); - redrawRenderedPreview(redrawLess); +// redrawPreview(redrawLess); + redrawRenderedPreview(redrawLess); } function previewDown(redrawLess) { - // console.log("f:previewDown()"); - if (numLayers > minNumLayers) { - numLayers--; - } - setSketchModified(true); -// redrawPreview(redrawLess); - redrawRenderedPreview(redrawLess); + // console.log("f:previewDown()"); + if (numLayers > minNumLayers) { + numLayers--; + } + setSketchModified(true); +// redrawPreview(redrawLess); + redrawRenderedPreview(redrawLess); } function previewTwistLeft(redrawLess) { previewTwist(-twistIncrement,true) @@ -320,25 +321,23 @@ function previewTwistRight(redrawLess) { } 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; - - redrawRenderedPreview(redrawLess); - setSketchModified(true); + if (redrawLess == undefined) redrawLess = false; + + rStep += increment; + if(rStep < -previewRotationLimit) rStep = -previewRotationLimit; + else if(rStep > previewRotationLimit) rStep = previewRotationLimit; + + redrawRenderedPreview(redrawLess); + setSketchModified(true); } function resetTwist() { - rStep = 0; - redrawRenderedPreview(); - setSketchModified(true); + rStep = 0; + redrawRenderedPreview(); + setSketchModified(true); } function update() { - - setState(printer.state,printer.hasControl); thermometer.update(printer.temperature, printer.targetTemperature); @@ -371,54 +370,54 @@ function setState(newState,newHasControl) { // thermometer switch(newState) { - case Printer.IDLE_STATE: /* fall-through */ - case Printer.BUFFERING_STATE: /* fall-through */ - case Printer.PRINTING_STATE: /* fall-through */ - case Printer.STOPPING_STATE: - thermometer.show(); - break; - default: - thermometer.hide(); - break; + case Printer.IDLE_STATE: /* fall-through */ + case Printer.BUFFERING_STATE: /* fall-through */ + case Printer.PRINTING_STATE: /* fall-through */ + case Printer.STOPPING_STATE: + thermometer.show(); + break; + default: + thermometer.hide(); + break; } // progress indicator switch(newState) { - case Printer.PRINTING_STATE: - progressbar.show(); - break; - default: - progressbar.hide(); - break; + case Printer.PRINTING_STATE: + progressbar.show(); + break; + default: + progressbar.hide(); + break; } /* settings button */ switch(newState) { - case Printer.IDLE_STATE: - btnSettings.enable(); - break; - case Printer.WIFIBOX_DISCONNECTED_STATE: /* fall-through */ - case Printer.BUFFERING_STATE: /* fall-through */ - case Printer.PRINTING_STATE: /* fall-through */ - case Printer.STOPPING_STATE: - btnSettings.disable(); - break; - default: - btnSettings.enable(); - break; - } - + case Printer.IDLE_STATE: + btnSettings.enable(); + break; + case Printer.WIFIBOX_DISCONNECTED_STATE: /* fall-through */ + case Printer.BUFFERING_STATE: /* fall-through */ + case Printer.PRINTING_STATE: /* fall-through */ + case Printer.STOPPING_STATE: + btnSettings.disable(); + break; + default: + btnSettings.enable(); + break; + } + /* save, next and prev buttons */ switch(newState) { - case Printer.WIFIBOX_DISCONNECTED_STATE: - btnPrevious.disable(); - btnNext.disable() - btnSave.disable(); - break; - default: - updatePrevNextButtonState(); - if (isModified) btnSave.enable(); - break; + case Printer.WIFIBOX_DISCONNECTED_STATE: + btnPrevious.disable(); + btnNext.disable() + btnSave.disable(); + break; + default: + updatePrevNextButtonState(); + if (isModified) btnSave.enable(); + break; } if(newState == Printer.WIFIBOX_DISCONNECTED_STATE) { @@ -428,7 +427,7 @@ function setState(newState,newHasControl) { } else if(newState == Printer.DISCONNECTED_STATE) { message.set("Printer disconnected",Message.WARNING,true); } else if(prevState == Printer.DISCONNECTED_STATE && newState == Printer.IDLE_STATE || - prevState == Printer.UNKNOWN_STATE && newState == Printer.IDLE_STATE) { + prevState == Printer.UNKNOWN_STATE && newState == Printer.IDLE_STATE) { message.set("Printer connected",Message.INFO,true); console.log(" preheat: ",settings["printer.heatup.enabled"]); if(settings["printer.heatup.enabled"]) {