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-08-16 22:28:58 +02:00
|
|
|
var debugMode = false; // debug mode
|
|
|
|
var sendPrintCommands = true; // if Doodle3d should send print commands to the 3d printer
|
|
|
|
var communicateWithWifibox = true; // if Doodle3d should try interfacing with the wifibox (in case one is not connected)
|
2013-08-20 10:55:08 +02:00
|
|
|
var wifiboxIsRemote = false; // when you want to run the client on a computer and have it remotely connect to the wifibox
|
2013-08-27 15:34:28 +02:00
|
|
|
var autoUpdate = true; // auto retrieve updates about temperature and progress from printer
|
2013-08-07 20:47:47 +02:00
|
|
|
|
2013-09-17 13:08:52 +02:00
|
|
|
var printer = new Printer();
|
2013-10-16 23:11:06 +02:00
|
|
|
var progressbar = new Progressbar();
|
2013-09-17 13:08:52 +02:00
|
|
|
var thermometer = new Thermometer();
|
2013-08-27 15:34:28 +02:00
|
|
|
var settingsWindow = new SettingsWindow();
|
2013-10-18 19:11:10 +02:00
|
|
|
var message = new Message();
|
2013-09-17 13:08:52 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
var firstTimeSettingsLoaded = true;
|
2013-09-18 22:35:38 +02:00
|
|
|
|
2013-10-16 12:31:22 +02:00
|
|
|
var wifiboxURL; // Using the uhttpd lua handler as default, because of better performance
|
|
|
|
var wifiboxCGIBinURL; // CGI-bin, for some network stuff, where it needs to restart the webserver for example
|
2013-09-18 18:56:32 +02:00
|
|
|
|
2013-09-18 10:46:36 +02:00
|
|
|
var $drawAreaContainer, $doodleCanvas, doodleCanvas, doodleCanvasContext, $previewContainer;
|
|
|
|
|
2013-10-22 12:04:46 +02:00
|
|
|
var showhideInterval;
|
|
|
|
var showOrHide = false;
|
2015-02-02 17:19:19 +01:00
|
|
|
var limitedFeatures = false;
|
2013-10-22 12:04:46 +02:00
|
|
|
|
2013-10-23 18:10:25 +02:00
|
|
|
var clientInfo = {};
|
|
|
|
|
2014-01-10 14:04:36 +01:00
|
|
|
var POPUP_SHOW_DURATION = 175;
|
2014-01-13 15:52:40 +01:00
|
|
|
var BUTTON_GROUP_SHOW_DURATION = 80;
|
2014-01-10 14:04:36 +01:00
|
|
|
|
2013-08-07 20:47:47 +02:00
|
|
|
$(function() {
|
|
|
|
console.log("ready");
|
2014-02-04 11:00:32 +01:00
|
|
|
|
2013-08-16 22:28:58 +02:00
|
|
|
if (getURLParameter("d") != "null") debugMode = (getURLParameter("d") == "1");
|
|
|
|
if (getURLParameter("p") != "null") sendPrintCommands = (getURLParameter("p") == "1");
|
|
|
|
if (getURLParameter("c") != "null") communicateWithWifibox = (getURLParameter("c") == "1");
|
|
|
|
if (getURLParameter("r") != "null") wifiboxIsRemote = (getURLParameter("r") == "1");
|
2013-08-27 15:34:28 +02:00
|
|
|
if (getURLParameter("u") != "null") autoUpdate = (getURLParameter("u") == "1");
|
2015-02-02 17:19:19 +01:00
|
|
|
if (getURLParameter("l") != "null") limitedFeatures = (getURLParameter("l") == "1");
|
2013-12-11 17:57:29 +01:00
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
var hostname;
|
|
|
|
if (wifiboxIsRemote) hostname = 'http://192.168.5.1';
|
|
|
|
if (getURLParameter("wifiboxURL") != "null") hostname = getURLParameter("wifiboxURL");
|
|
|
|
if (!hostname) hostname = "http://" + window.location.host;
|
|
|
|
|
|
|
|
wifiboxURL = hostname+"/d3dapi";
|
|
|
|
wifiboxCGIBinURL = hostname+"/cgi-bin/d3dapi";
|
|
|
|
|
|
|
|
|
|
|
|
//var api = wifiboxURL+'/d3dapi/sketch/';
|
|
|
|
|
|
|
|
// if (wifiboxIsRemote) {
|
|
|
|
// // var hostname = "http://10.0.0.45";
|
|
|
|
// var hostname = "http://192.168.5.1";
|
|
|
|
// wifiboxURL = hostname+"/d3dapi";
|
|
|
|
// wifiboxCGIBinURL = hostname+"/cgi-bin/d3dapi";
|
|
|
|
// } else {
|
|
|
|
// wifiboxURL = "http://" + window.location.host + "/d3dapi";
|
|
|
|
// wifiboxCGIBinURL = "http://" + window.location.host + "/cgi-bin/d3dapi";
|
|
|
|
// }
|
2013-09-27 16:04:56 +02:00
|
|
|
|
2013-08-19 17:55:01 +02:00
|
|
|
if (!communicateWithWifibox) {
|
2013-08-16 22:28:58 +02:00
|
|
|
sendPrintCommands = false; // 'communicateWithWifibox = false' implies this
|
|
|
|
}
|
|
|
|
console.log("debugMode: " + debugMode);
|
|
|
|
console.log("sendPrintCommands: " + sendPrintCommands);
|
|
|
|
console.log("communicateWithWifibox: " + communicateWithWifibox);
|
|
|
|
console.log("wifiboxIsRemote: " + wifiboxIsRemote);
|
2013-08-07 20:47:47 +02:00
|
|
|
console.log("wifibox URL: " + wifiboxURL);
|
2013-08-09 22:25:14 +02:00
|
|
|
|
2013-10-23 18:10:25 +02:00
|
|
|
// rudimentary client info
|
|
|
|
clientInfo.isMobileDevice = isMobileDevice();
|
|
|
|
clientInfo.isSmartphone = isSmartphone();
|
|
|
|
|
2013-08-07 20:47:47 +02:00
|
|
|
initDoodleDrawing();
|
|
|
|
initPreviewRendering();
|
2013-10-11 11:42:27 +02:00
|
|
|
initLayouting();
|
2014-01-09 17:05:03 +01:00
|
|
|
// initSidebars();
|
2013-08-07 20:47:47 +02:00
|
|
|
initButtonBehavior();
|
2013-12-05 11:14:12 +01:00
|
|
|
initKeyboard();
|
2014-01-09 17:05:03 +01:00
|
|
|
// initVerticalShapes();
|
|
|
|
initWordArt();
|
|
|
|
initShapeDialog();
|
2014-10-09 16:24:24 +02:00
|
|
|
initScanDialog();
|
2014-01-09 17:05:03 +01:00
|
|
|
|
|
|
|
disableDragging();
|
|
|
|
|
2013-10-23 18:10:25 +02:00
|
|
|
if (!clientInfo.isSmartphone) initHelp();
|
2013-08-07 20:47:47 +02:00
|
|
|
|
2013-09-18 10:57:46 +02:00
|
|
|
thermometer.init($("#thermometerCanvas"), $("#thermometerContainer"));
|
2013-10-16 23:11:06 +02:00
|
|
|
progressbar.init($("#progressbarCanvas"), $("#progressbarCanvasContainer"));
|
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
message.init($("#message"));
|
2013-12-11 17:57:29 +01:00
|
|
|
|
2013-09-17 13:08:52 +02:00
|
|
|
printer.init();
|
2013-08-27 15:34:28 +02:00
|
|
|
$(document).on(Printer.UPDATE,update);
|
2013-09-27 16:04:56 +02:00
|
|
|
|
2013-10-16 12:31:22 +02:00
|
|
|
settingsWindow.init(wifiboxURL,wifiboxCGIBinURL);
|
2013-10-11 11:42:27 +02:00
|
|
|
$(document).on(SettingsWindow.SETTINGS_LOADED, settingsLoaded);
|
2014-01-16 21:30:57 +01:00
|
|
|
|
2013-09-18 22:35:38 +02:00
|
|
|
if(debugMode) {
|
2013-08-16 22:28:58 +02:00
|
|
|
console.log("debug mode is true");
|
2013-08-07 20:47:47 +02:00
|
|
|
$("body").css("overflow", "auto");
|
|
|
|
$("#debug_textArea").css("display", "block");
|
2013-12-05 12:47:03 +01:00
|
|
|
//$("#preview_tmp").css("display", "block");
|
2013-10-11 12:39:05 +02:00
|
|
|
$("#debug_display").css("display", "block");
|
2015-02-02 17:19:19 +01:00
|
|
|
}
|
2013-10-21 10:28:04 +02:00
|
|
|
|
2015-02-02 17:19:19 +01:00
|
|
|
if (limitedFeatures) {
|
|
|
|
initLimitedInterface();
|
2013-08-07 20:47:47 +02:00
|
|
|
}
|
2013-10-16 23:11:06 +02:00
|
|
|
});
|
|
|
|
|
2014-01-09 17:05:03 +01:00
|
|
|
function disableDragging() {
|
|
|
|
$(document).bind("dragstart", function(event) {
|
|
|
|
console.log("dragstart");
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-10-16 23:32:50 +02:00
|
|
|
function showOrHideThermo() {
|
|
|
|
console.log("f:showOrHideThermo()");
|
|
|
|
if (showOrHide) {
|
|
|
|
thermometer.hide();
|
|
|
|
progressbar.hide();
|
|
|
|
} else {
|
|
|
|
thermometer.show();
|
|
|
|
progressbar.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
showOrHide = !showOrHide;
|
|
|
|
}
|
|
|
|
|
2013-08-27 15:34:28 +02:00
|
|
|
function settingsLoaded() {
|
|
|
|
console.log("settingsLoaded");
|
2014-01-27 13:19:20 +01:00
|
|
|
|
2013-12-19 16:36:15 +01:00
|
|
|
if(firstTimeSettingsLoaded) {
|
2014-01-27 13:19:20 +01:00
|
|
|
console.log(" preheat: ",settings["printer.heatup.enabled"]);
|
|
|
|
console.log(" state: ",state);
|
|
|
|
if(state == Printer.IDLE_STATE && settings["printer.heatup.enabled"]) {
|
2013-09-18 18:56:32 +02:00
|
|
|
printer.preheat();
|
|
|
|
}
|
2013-12-19 16:36:15 +01:00
|
|
|
console.log("doodle3d.tour.enabled: ",settings["doodle3d.tour.enabled"]);
|
|
|
|
if(settings["doodle3d.tour.enabled"] && !clientInfo.isSmartphone) {
|
|
|
|
console.log("show tour");
|
|
|
|
initHelp();
|
|
|
|
}
|
|
|
|
firstTimeSettingsLoaded = false;
|
2013-08-27 15:34:28 +02:00
|
|
|
}
|
2013-12-19 16:36:15 +01:00
|
|
|
|
2013-09-27 16:04:56 +02:00
|
|
|
}
|
2013-10-11 12:39:05 +02:00
|
|
|
|
|
|
|
function setDebugText(text) {
|
|
|
|
$("#debug_display").text(text);
|
2015-02-02 17:19:19 +01:00
|
|
|
|
2013-12-11 17:57:29 +01:00
|
|
|
}
|