From 5e43789f82815e32d1a95daf2a7fe7c5b443e2ea Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Thu, 7 May 2015 14:09:36 +0200 Subject: [PATCH] clean up code --- build/d3d.js | 239 +++++++++++++++++++++++++++++++++-------------- build/d3d.min.js | 2 +- src/box.js | 196 ++++++++++++++++++++++++++++---------- src/printer.js | 7 ++ src/slicer.js | 14 ++- src/utils.js | 22 ++--- 6 files changed, 341 insertions(+), 139 deletions(-) diff --git a/build/d3d.js b/build/d3d.js index 71553b1..34c41cf 100644 --- a/build/d3d.js +++ b/build/d3d.js @@ -6,8 +6,8 @@ ******************************************************/ var D3D = { - "version": "0.1", - "website": "http://www.doodle3d.com/", + "version": "0.1", + "website": "http://www.doodle3d.com/", "contact": "develop@doodle3d.com" }; @@ -25,11 +25,11 @@ function sendAPI (url, data, callback) { "use strict"; $.ajax({ - url: url, - type: "POST", - data: data, - dataType: "json", - timeout: 10000, + url: url, + type: "POST", + data: data, + dataType: "json", + timeout: 10000, success: function (response) { if (response.status === "success") { if (callback !== undefined) { @@ -50,9 +50,9 @@ function getAPI (url, callback) { "use strict"; $.ajax({ - url: url, - dataType: "json", - timeout: 5000, + url: url, + dataType: "json", + timeout: 5000, success: function (response) { if (response.status === "success") { if (callback !== undefined) { @@ -73,7 +73,7 @@ function downloadFile (file, data) { "use strict"; $(document.createElement("a")).attr({ - download: file, + download: file, href: "data:text/plain," + data })[0].click(); } @@ -172,14 +172,9 @@ D3D.Box = function (localIp) { this.currentBatch = 0; this.loaded = false; - this.onload; - getAPI(self.api + "config/all", function (data) { - for (var i in data) { - if (i.indexOf("doodle3d") === 0) { - self.config[i] = data[i]; - } - } + this.getConfigAll(function (data) { + self.updateConfig(data); self.printer = new D3D.Printer(data); self.update(); @@ -190,6 +185,17 @@ D3D.Box = function (localIp) { } }); }; +D3D.Box.prototype.updateConfig = function (config) { + "use strict"; + + for (var i in config) { + if (i.indexOf("doodle3d") === 0) { + this.config[i] = config[i]; + } + } + + return this; +}; D3D.Box.prototype.update = function () { "use strict"; //TODO @@ -206,13 +212,17 @@ D3D.Box.prototype.update = function () { } }; D3D.Box.prototype.updateState = function () { + //que api calls so they don't overload the d3d box "use strict"; var self = this; - //que api calls so they don't overload the d3d box - getAPI(this.api + "info/status", function (data) { + this.getInfoStatus(function (data) { self.printer.status = data; + if (self.onupdate !== undefined) { + self.onupdate(data); + } + self.update(); }); }; @@ -238,9 +248,9 @@ D3D.Box.prototype.printBatch = function () { var gcode = this.printBatches.shift(); - sendAPI(this.api + "printer/print", { - "start": ((this.currentBatch === 0) ? true : false), - "first": ((this.currentBatch === 0) ? true : false), + this.setPrinterPrint({ + "start": ((this.currentBatch === 0) ? true : false), + "first": ((this.currentBatch === 0) ? true : false), "gcode": gcode.join("\n") }, function (data) { console.log("batch sent: " + self.currentBatch, data); @@ -250,7 +260,7 @@ D3D.Box.prototype.printBatch = function () { self.currentBatch ++; } else { - //finish printing + //finish sending } self.updateState(); @@ -275,7 +285,7 @@ D3D.Box.prototype.stopPrint = function () { "M117 Done ;display message (20 characters to clear whole screen)" ]; - sendAPI(this.api + "printer/stop", { + this.setPrinterStop({ "gcode": finishMove.join("\n") }, function (data) { console.log("Printer stop command sent"); @@ -283,11 +293,39 @@ D3D.Box.prototype.stopPrint = function () { return this; }; -D3D.Box.prototype.setConfig = function (data, callback) { + +//COMMUNICATION SHELL +//see http://www.doodle3d.com/help/api-documentation +D3D.Box.prototype.getConfig = function (keys, callback) { //works "use strict"; - sendAPI(this.api + "config", data, callback); + getAPI(this.api + "config/?" + keys.join("=&") + "=", callback); +}; +D3D.Box.prototype.getConfigAll = function (callback) { + //works + "use strict"; + + getAPI(this.api + "config/all", callback); +}; +D3D.Box.prototype.setConfig = function (data, callback) { + //works + "use strict"; + var self = this; + + sendAPI(this.api + "config", data, function (response) { + for (var i in response.validation) { + if (response.validation[i] !== "ok") { + delete data[i]; + } + } + self.updateConfig(data); + self.printer.updateConfig(data); + + if (callback !== undefined) { + callback(response); + } + }); return this; }; @@ -297,7 +335,15 @@ D3D.Box.prototype.getInfo = function (callback) { getAPI(this.api + "info", callback); }; -D3D.Box.prototype.downloadInfoLog = function (callback) { +D3D.Box.prototype.getInfoStatus = function (callback) { + //works + "use strict"; + + getAPI(this.api + "info/status", callback); + + return this; +}; +D3D.Box.prototype.downloadInfoLogFiles = function () { //works in google chrome... not tested in other browsers //some browsers may redirect using this code "use strict"; @@ -370,6 +416,14 @@ D3D.Box.prototype.setNetworkRemove = function (ssid, callback) { return this; }; +D3D.Box.prototype.getNetworkSignin = function (callback) { + //works + "use strict"; + + getAPI(this.api + "network/signin", callback); + + return this; +}; D3D.Box.prototype.getNetworkAlive = function (callback) { //works but returns empty array "use strict"; @@ -378,6 +432,30 @@ D3D.Box.prototype.getNetworkAlive = function (callback) { return this; }; +D3D.Box.prototype.getPrinterTemperature = function (callback) { + //works + "use strict"; + + getAPI(this.api + "printer/temperature", callback); + + return this; +}; +D3D.Box.prototype.getPrinterProgress = function (callback) { + //works + "use strict"; + + getAPI(this.api + "printer/progress", callback); + + return this; +}; +D3D.Box.prototype.getPrinterState = function (callback) { + //works + "use strict"; + + getAPI(this.api + "printer/state", callback); + + return this; +}; D3D.Box.prototype.getPrinterListAll = function (callback) { //works "use strict"; @@ -394,6 +472,56 @@ D3D.Box.prototype.setPrinterHeatup = function (callback) { return this; }; +D3D.Box.prototype.setPrinterPrint = function (data, callback) { + //works + "use strict"; + + sendAPI(this.api + "printer/print", data, callback); + + return this; +}; +D3D.Box.prototype.setPrinterStop = function (data, callback) { + //works + "use strict"; + + sendAPI(this.api + "printer/stop", data, callback); + + return this; +}; +D3D.Box.prototype.getSketch = function (id, callback) { + //works + "use strict"; + + getAPI(this.api + "sketch/?id=" + id, callback); + + return this; +}; +D3D.Box.prototype.setSketch = function (data, callback) { + //works + "use strict"; + + sendAPI(this.api + "sketch", { + "data": data + }, callback); + + return this; +}; +D3D.Box.prototype.getSketchStatus = function (callback) { + //works + "use strict"; + + getAPI(this.api + "sketch/status", callback); + + return this; +}; +D3D.Box.prototype.setSketchClear = function (callback) { + //works + "use strict"; + + sendAPI(this.api + "sketch/clear", callback); + + return this; +}; D3D.Box.prototype.getSystemVersions = function (callback) { //works "use strict"; @@ -402,46 +530,14 @@ D3D.Box.prototype.getSystemVersions = function (callback) { return this; }; -D3D.Box.prototype.getSketch = function (id, callback) { - //not tested - "use strict"; - - getAPI(this.api + "sketch/status/?id=" + id, callback); - - return this; -}; -D3D.Box.prototype.getSketchStatus = function (callback) { - //not tested - "use strict"; - - getAPI(this.api + "sketch/status", callback); - - return this; -}; D3D.Box.prototype.getUpdateStatus = function (callback) { - //not tested + //works "use strict"; getAPI(this.api + "update/status", callback); return this; }; -D3D.Box.prototype.setSketch = function (data, callback) { - //not tested - "use strict"; - - sendAPI(this.api + "sketch", data, callback); - - return this; -}; -D3D.Box.prototype.setSketchClear = function (callback) { - //not tested - "use strict"; - - sendAPI(this.api + "sketch/clear", callback); - - return this; -}; D3D.Box.prototype.setUpdateDownload = function (callback) { //not tested "use strict"; @@ -479,11 +575,18 @@ D3D.Printer = function (config) { this.status = {}; this.config = {}; + this.updateConfig(config); +}; +D3D.Printer.prototype.updateConfig = function (config) { + "use strict"; + for (var i in config) { if (i.indexOf("printer") === 0) { this.config[i] = config[i]; } } + + return this; }; D3D.Printer.prototype.getStartCode = function () { "use strict"; @@ -546,8 +649,6 @@ D3D.Printer.prototype.subsituteVariables = function (gcode) { D3D.Slicer = function () { "use strict"; - this.geometry; - this.lines = []; }; D3D.Slicer.prototype.setGeometry = function (geometry) { @@ -581,8 +682,8 @@ D3D.Slicer.prototype.createLines = function () { lineLookup[a + "_" + b] = index; self.lines.push({ - line: new THREE.Line3(self.geometry.vertices[a], self.geometry.vertices[b]), - connects: [], + line: new THREE.Line3(self.geometry.vertices[a], self.geometry.vertices[b]), + connects: [], normals: [] }); } @@ -842,8 +943,8 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) { ClipperLib.JS.ScaleDownPaths(fill, scale); data.push({ - outerLayer: outerLayer, - innerLayer: innerLayer, + outerLayer: outerLayer, + innerLayer: innerLayer, fill: fill }); } @@ -884,7 +985,7 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) { if (extruder > retractionMinDistance && retractionEnabled) { gcode.push([ "G0", - "E" + (extruder - retractionAmount).toFixed(3), + "E" + (extruder - retractionAmount).toFixed(3), "F" + (retractionSpeed * 60).toFixed(3) ].join(" ")); } @@ -898,7 +999,7 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) { if (extruder > retractionMinDistance && retractionEnabled) { gcode.push([ "G0", - "E" + extruder.toFixed(3), + "E" + extruder.toFixed(3), "F" + (retractionSpeed * 60).toFixed(3) ].join(" ")); } diff --git a/build/d3d.min.js b/build/d3d.min.js index 7de3164..3650831 100644 --- a/build/d3d.min.js +++ b/build/d3d.min.js @@ -1 +1 @@ -function sendAPI(t,e,i){"use strict";$.ajax({url:t,type:"POST",data:e,dataType:"json",timeout:1e4,success:function(t){"success"===t.status?void 0!==i&&i(t.data):console.warn(t.msg)}}).fail(function(){console.warn("failed connecting to "+t),sendAPI(t,e,i)})}function getAPI(t,e){"use strict";$.ajax({url:t,dataType:"json",timeout:5e3,success:function(t){"success"===t.status?void 0!==e&&e(t.data):console.warn(t.msg)}}).fail(function(){console.warn("failed connecting to "+t),getAPI(t,e)})}function downloadFile(t,e){"use strict";$(document.createElement("a")).attr({download:t,href:"data:text/plain,"+e})[0].click()}function applyMouseControls(t,e,i){"use strict";function r(){e.position.x=Math.cos(s)*Math.sin(o)*n,e.position.y=Math.sin(s)*n,e.position.z=Math.cos(s)*Math.cos(o)*n,e.lookAt(new THREE.Vector3(0,0,0))}var n=20,o=0,s=0,a=!1;$(t.domElement).on("mousedown",function(t){a=!0}).on("wheel",function(t){var e=t.originalEvent;e.preventDefault(),n=THREE.Math.clamp(n-e.wheelDelta,1,i),r()}),$(window).on("mouseup",function(t){a=!1}).on("mousemove",function(t){var e=t.originalEvent;a===!0&&(o=(o-e.webkitMovementX/100)%(2*Math.PI),s=THREE.Math.clamp(s+e.webkitMovementY/100,-Math.PI/2,Math.PI/2),r())}),r()}var D3D={version:"0.1",website:"http://www.doodle3d.com/",contact:"develop@doodle3d.com"};THREE.Vector2.prototype.normal=function(){"use strict";var t=this.y,e=-this.x;return this.set(t,e)},Array.prototype.clone=function(){"use strict";for(var t=[],e=0;e0?this.printBatch():this.updateState()},D3D.Box.prototype.updateState=function(){"use strict";var t=this;getAPI(this.api+"info/status",function(e){t.printer.status=e,t.update()})},D3D.Box.prototype.print=function(t){"use strict";for(this.currentBatch=0,t=t.clone();t.length>0;){var e=t.splice(0,Math.min(this.batchSize,t.length));this.printBatches.push(e)}return this},D3D.Box.prototype.printBatch=function(){"use strict";var t=this,e=this.printBatches.shift();sendAPI(this.api+"printer/print",{start:0===this.currentBatch?!0:!1,first:0===this.currentBatch?!0:!1,gcode:e.join("\n")},function(e){console.log("batch sent: "+t.currentBatch,e),t.printBatches.length>0&&t.currentBatch++,t.updateState()})},D3D.Box.prototype.stopPrint=function(){"use strict";this.printBatches=[],this.currentBatch=0;var t=["M107 ;fan off","G91 ;relative positioning","G1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure","G1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more","G28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way","M84 ;disable axes / steppers","G90 ;absolute positioning","M104 S180",";M140 S70","M117 Done ;display message (20 characters to clear whole screen)"];return sendAPI(this.api+"printer/stop",{gcode:t.join("\n")},function(t){console.log("Printer stop command sent")}),this},D3D.Box.prototype.setConfig=function(t,e){"use strict";return sendAPI(this.api+"config",t,e),this},D3D.Box.prototype.getInfo=function(t){"use strict";getAPI(this.api+"info",t)},D3D.Box.prototype.downloadInfoLog=function(t){"use strict";window.location=this.api+"info/logfiles"},D3D.Box.prototype.getInfoAcces=function(t){"use strict";return getAPI(this.api+"info/access",t),this},D3D.Box.prototype.getNetworkScan=function(t){"use strict";return getAPI(this.api+"network/scan",t),this},D3D.Box.prototype.getNetworkKnown=function(t){"use strict";return getAPI(this.api+"network/known",t),this},D3D.Box.prototype.getNetworkStatus=function(t){"use strict";return getAPI(this.api+"network/status",t),this},D3D.Box.prototype.setNetworkAssosiate=function(t,e){"use strict";return sendAPI(this.api+"network/associate",t,e),this},D3D.Box.prototype.setNetworkDisassosiate=function(t){"use strict";return sendAPI(this.api+"network/disassociate",{},t),this},D3D.Box.prototype.setNetworkOpenAP=function(t){"use strict";return sendAPI(this.api+"network/openap",{},t),this},D3D.Box.prototype.setNetworkRemove=function(t,e){"use strict";return sendAPI(this.api+"network/remove",{ssid:t},e),this},D3D.Box.prototype.getNetworkAlive=function(t){"use strict";return getAPI(this.api+"network/alive",t),this},D3D.Box.prototype.getPrinterListAll=function(t){"use strict";return getAPI(this.api+"printer/listall",t),this},D3D.Box.prototype.setPrinterHeatup=function(t){"use strict";return sendAPI(this.api+"printer/heatup",{},t),this},D3D.Box.prototype.getSystemVersions=function(t){"use strict";return getAPI(this.api+"system/fwversions",t),this},D3D.Box.prototype.getSketch=function(t,e){"use strict";return getAPI(this.api+"sketch/status/?id="+t,e),this},D3D.Box.prototype.getSketchStatus=function(t){"use strict";return getAPI(this.api+"sketch/status",t),this},D3D.Box.prototype.getUpdateStatus=function(t){"use strict";return getAPI(this.api+"update/status",t),this},D3D.Box.prototype.setSketch=function(t,e){"use strict";return sendAPI(this.api+"sketch",t,e),this},D3D.Box.prototype.setSketchClear=function(t){"use strict";return sendAPI(this.api+"sketch/clear",t),this},D3D.Box.prototype.setUpdateDownload=function(t){"use strict";return sendAPI(this.api+"update/download",{},t),this},D3D.Box.prototype.setUpdateInstall=function(t){"use strict";return sendAPI(this.api+"update/install",{},t),this},D3D.Box.prototype.setUpdateClear=function(t){"use strict";return sendAPI(this.api+"update/clear",{},t),this},D3D.Printer=function(t){"use strict";this.status={},this.config={};for(var e in t)0===e.indexOf("printer")&&(this.config[e]=t[e])},D3D.Printer.prototype.getStartCode=function(){"use strict";var t=this.config["printer.startcode"];return t=this.subsituteVariables(t),t.split("\n")},D3D.Printer.prototype.getEndCode=function(){"use strict";var t=this.config["printer.endcode"];return t=this.subsituteVariables(t),t.split("\n")},D3D.Printer.prototype.subsituteVariables=function(t){"use strict";var e=this.config["printer.temperature"],i=this.config["printer.bed.temperature"],r=this.config["printer.heatup.temperature"],n=this.config["printer.heatup.bed.temperature"],o=this.config["printer.type"],s=this.config["printer.heatedbed"];switch(o){case"makerbot_replicator2":o="r2";break;case"makerbot_replicator2x":o="r2x";break;case"makerbot_thingomatic":o="t6";break;case"makerbot_generic":o="r2";break;case"_3Dison_plus":o="r2"}var a=s?"":";";return t=t.replace(/{printingTemp}/gi,e),t=t.replace(/{printingBedTemp}/gi,i),t=t.replace(/{preheatTemp}/gi,r),t=t.replace(/{preheatBedTemp}/gi,n),t=t.replace(/{printerType}/gi,o),t=t.replace(/{if heatedBed}/gi,a)},D3D.Slicer=function(){"use strict";this.geometry,this.lines=[]},D3D.Slicer.prototype.setGeometry=function(t){"use strict";return t instanceof THREE.BufferGeometry&&(t=(new THREE.Geometry).fromBufferGeometry(t)),this.geometry=t.clone(),this.geometry.mergeVertices(),this.createLines(),this},D3D.Slicer.prototype.createLines=function(){"use strict";function t(t,r){var n=e[t+"_"+r]||e[r+"_"+t];return void 0===n&&(n=i.lines.length,e[t+"_"+r]=n,i.lines.push({line:new THREE.Line3(i.geometry.vertices[t],i.geometry.vertices[r]),connects:[],normals:[]})),n}this.lines=[];for(var e={},i=this,r=0;rn;n+=e){r.set(new THREE.Vector3(0,-1,0),n);for(var o=[],s=[],a=0;a0)break;h=-1}else h=-1}f.length>0&&(f.push({X:f[0].X,Y:f[0].Y}),o.push(f))}if(!(o.length>0))break;i.push(o)}return i},D3D.Slicer.prototype.getInset=function(t,e){"use strict";var i=new ClipperLib.Paths,r=new ClipperLib.ClipperOffset(1,1);return r.AddPaths(t,ClipperLib.JoinType.jtRound,ClipperLib.EndType.etClosedPolygon),r.Execute(i,-e),i},D3D.Slicer.prototype.getFillTemplate=function(t,e,i,r){"use strict";var n=new ClipperLib.Paths;if(i)for(var o=0;t>=o;o+=e)n.push([{X:o,Y:0},{X:o,Y:t}]);if(r)for(var o=0;t>=o;o+=e)n.push([{X:0,Y:o},{X:t,Y:o}]);return n},D3D.Slicer.prototype.slicesToData=function(t,e){"use strict";for(var i=100,r=e.config["printer.layerHeight"]*i,n=e.config["printer.dimensions.z"]*i,o=e.config["printer.wallThickness"]*i,s=e.config["printer.shellThickness"]*i,a=e.config["printer.fillSize"]*i,p=(e.config["printer.brimOffset"]*i,[]),c=this.getFillTemplate(n,a,!0,!0),l=0;ld;d+=o){var g=this.getInset(h,d);f=f.concat(g)}for(var y=g||h,D=!1,d=1;s/r>d;d++){var m=ClipperLib.JS.Clone(t[l+d]);if(ClipperLib.JS.ScaleUpPaths(m,i),0===m.length||D&&0===D.length){D=[];break}if(D===!1)D=m;else{var v=new ClipperLib.Clipper,b=new ClipperLib.Paths;v.AddPaths(m,ClipperLib.PolyType.ptSubject,!0),v.AddPaths(D,ClipperLib.PolyType.ptClip,!0),v.Execute(ClipperLib.ClipType.ctIntersection,b),D=b}}var P=new ClipperLib.Clipper,w=new ClipperLib.Paths;P.AddPaths(y,ClipperLib.PolyType.ptSubject,!0),P.AddPaths(D,ClipperLib.PolyType.ptClip,!0),P.Execute(ClipperLib.ClipType.ctDifference,w);var P=new ClipperLib.Clipper,x=new ClipperLib.Paths;P.AddPaths(y,ClipperLib.PolyType.ptSubject,!0),P.AddPaths(w,ClipperLib.PolyType.ptClip,!0),P.Execute(ClipperLib.ClipType.ctDifference,x);var C=[],P=new ClipperLib.Clipper,T=new ClipperLib.Paths;P.AddPaths(c,ClipperLib.PolyType.ptSubject,!1),P.AddPaths(x,ClipperLib.PolyType.ptClip,!0),P.Execute(ClipperLib.ClipType.ctIntersection,T),C=C.concat(T);var A=this.getFillTemplate(n,o,l%2===0,l%2===1),P=new ClipperLib.Clipper,L=new ClipperLib.Paths;P.AddPaths(A,ClipperLib.PolyType.ptSubject,!1),P.AddPaths(w,ClipperLib.PolyType.ptClip,!0),P.Execute(ClipperLib.ClipType.ctIntersection,L),C=C.concat(L),ClipperLib.JS.ScaleDownPaths(h,i),ClipperLib.JS.ScaleDownPaths(f,i),ClipperLib.JS.ScaleDownPaths(C,i),p.push({outerLayer:h,innerLayer:f,fill:C})}return p},D3D.Slicer.prototype.dataToGcode=function(t,e){"use strict";function i(t){for(var e=[],i=0;if&&u&&e.push(["G0","E"+(y-d).toFixed(3),"F"+(60*h).toFixed(3)].join(" ")),e.push(["G0","X"+a.X.toFixed(3)+" Y"+a.Y.toFixed(3)+" Z"+w,"F"+60*p].join(" ")),y>f&&u&&e.push(["G0","E"+y.toFixed(3),"F"+(60*h).toFixed(3)].join(" "));else{var c=(new THREE.Vector2).set(a.X,a.Y),g=(new THREE.Vector2).set(n.X,n.Y),b=c.distanceTo(g);y+=b*l*r/m*v,e.push(["G1","X"+a.X.toFixed(3)+" Y"+a.Y.toFixed(3)+" Z"+w,"F"+D,"E"+y.toFixed(3)].join(" "))}n=a}return e}for(var r=e.config["printer.layerHeight"],n=e.config["printer.speed"],o=e.config["printer.bottomLayerSpeed"],s=e.config["printer.firstLayerSlow"],a=e.config["printer.bottomFlowRate"],p=e.config["printer.travelSpeed"],c=e.config["printer.filamentThickness"],l=e.config["printer.wallThickness"],u=(e.config["printer.enableTraveling"],e.config["printer.retraction.enabled"]),h=e.config["printer.retraction.speed"],f=e.config["printer.retraction.minDistance"],d=e.config["printer.retraction.amount"],g=e.getStartCode(),y=0,D=s?(60*o).toFixed(3):(60*n).toFixed(3),m=Math.pow(c/2,2)*Math.PI,v=a,b=0;bl;l++){var u=a[l%a.length];r(u.outerLayer,"red"),r(u.innerLayer,"green"),r(u.fill,"blue")}return p},D3D.Slicer.prototype.getGcode=function(t){"use strict";var e=t.config["printer.layerHeight"],i=t.config["printer.dimensions.z"],r=this.slice(i,e);r.shift();var n=this.slicesToData(r,t),o=this.dataToGcode(n,t);return o}; \ No newline at end of file +function sendAPI(t,e,i){"use strict";$.ajax({url:t,type:"POST",data:e,dataType:"json",timeout:1e4,success:function(t){"success"===t.status?void 0!==i&&i(t.data):console.warn(t.msg)}}).fail(function(){console.warn("failed connecting to "+t),sendAPI(t,e,i)})}function getAPI(t,e){"use strict";$.ajax({url:t,dataType:"json",timeout:5e3,success:function(t){"success"===t.status?void 0!==e&&e(t.data):console.warn(t.msg)}}).fail(function(){console.warn("failed connecting to "+t),getAPI(t,e)})}function downloadFile(t,e){"use strict";$(document.createElement("a")).attr({download:t,href:"data:text/plain,"+e})[0].click()}function applyMouseControls(t,e,i){"use strict";function r(){e.position.x=Math.cos(s)*Math.sin(o)*n,e.position.y=Math.sin(s)*n,e.position.z=Math.cos(s)*Math.cos(o)*n,e.lookAt(new THREE.Vector3(0,0,0))}var n=20,o=0,s=0,p=!1;$(t.domElement).on("mousedown",function(t){p=!0}).on("wheel",function(t){var e=t.originalEvent;e.preventDefault(),n=THREE.Math.clamp(n-e.wheelDelta,1,i),r()}),$(window).on("mouseup",function(t){p=!1}).on("mousemove",function(t){var e=t.originalEvent;p===!0&&(o=(o-e.webkitMovementX/100)%(2*Math.PI),s=THREE.Math.clamp(s+e.webkitMovementY/100,-Math.PI/2,Math.PI/2),r())}),r()}var D3D={version:"0.1",website:"http://www.doodle3d.com/",contact:"develop@doodle3d.com"};THREE.Vector2.prototype.normal=function(){"use strict";var t=this.y,e=-this.x;return this.set(t,e)},Array.prototype.clone=function(){"use strict";for(var t=[],e=0;e0?this.printBatch():this.updateState()},D3D.Box.prototype.updateState=function(){"use strict";var t=this;this.getInfoStatus(function(e){t.printer.status=e,void 0!==t.onupdate&&t.onupdate(e),t.update()})},D3D.Box.prototype.print=function(t){"use strict";for(this.currentBatch=0,t=t.clone();t.length>0;){var e=t.splice(0,Math.min(this.batchSize,t.length));this.printBatches.push(e)}return this},D3D.Box.prototype.printBatch=function(){"use strict";var t=this,e=this.printBatches.shift();this.setPrinterPrint({start:0===this.currentBatch?!0:!1,first:0===this.currentBatch?!0:!1,gcode:e.join("\n")},function(e){console.log("batch sent: "+t.currentBatch,e),t.printBatches.length>0&&t.currentBatch++,t.updateState()})},D3D.Box.prototype.stopPrint=function(){"use strict";this.printBatches=[],this.currentBatch=0;var t=["M107 ;fan off","G91 ;relative positioning","G1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure","G1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more","G28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way","M84 ;disable axes / steppers","G90 ;absolute positioning","M104 S180",";M140 S70","M117 Done ;display message (20 characters to clear whole screen)"];return this.setPrinterStop({gcode:t.join("\n")},function(t){console.log("Printer stop command sent")}),this},D3D.Box.prototype.getConfig=function(t,e){"use strict";getAPI(this.api+"config/?"+t.join("=&")+"=",e)},D3D.Box.prototype.getConfigAll=function(t){"use strict";getAPI(this.api+"config/all",t)},D3D.Box.prototype.setConfig=function(t,e){"use strict";var i=this;return sendAPI(this.api+"config",t,function(r){for(var n in r.validation)"ok"!==r.validation[n]&&delete t[n];i.updateConfig(t),i.printer.updateConfig(t),void 0!==e&&e(r)}),this},D3D.Box.prototype.getInfo=function(t){"use strict";getAPI(this.api+"info",t)},D3D.Box.prototype.getInfoStatus=function(t){"use strict";return getAPI(this.api+"info/status",t),this},D3D.Box.prototype.downloadInfoLogFiles=function(){"use strict";window.location=this.api+"info/logfiles"},D3D.Box.prototype.getInfoAcces=function(t){"use strict";return getAPI(this.api+"info/access",t),this},D3D.Box.prototype.getNetworkScan=function(t){"use strict";return getAPI(this.api+"network/scan",t),this},D3D.Box.prototype.getNetworkKnown=function(t){"use strict";return getAPI(this.api+"network/known",t),this},D3D.Box.prototype.getNetworkStatus=function(t){"use strict";return getAPI(this.api+"network/status",t),this},D3D.Box.prototype.setNetworkAssosiate=function(t,e){"use strict";return sendAPI(this.api+"network/associate",t,e),this},D3D.Box.prototype.setNetworkDisassosiate=function(t){"use strict";return sendAPI(this.api+"network/disassociate",{},t),this},D3D.Box.prototype.setNetworkOpenAP=function(t){"use strict";return sendAPI(this.api+"network/openap",{},t),this},D3D.Box.prototype.setNetworkRemove=function(t,e){"use strict";return sendAPI(this.api+"network/remove",{ssid:t},e),this},D3D.Box.prototype.getNetworkSignin=function(t){"use strict";return getAPI(this.api+"network/signin",t),this},D3D.Box.prototype.getNetworkAlive=function(t){"use strict";return getAPI(this.api+"network/alive",t),this},D3D.Box.prototype.getPrinterTemperature=function(t){"use strict";return getAPI(this.api+"printer/temperature",t),this},D3D.Box.prototype.getPrinterProgress=function(t){"use strict";return getAPI(this.api+"printer/progress",t),this},D3D.Box.prototype.getPrinterState=function(t){"use strict";return getAPI(this.api+"printer/state",t),this},D3D.Box.prototype.getPrinterListAll=function(t){"use strict";return getAPI(this.api+"printer/listall",t),this},D3D.Box.prototype.setPrinterHeatup=function(t){"use strict";return sendAPI(this.api+"printer/heatup",{},t),this},D3D.Box.prototype.setPrinterPrint=function(t,e){"use strict";return sendAPI(this.api+"printer/print",t,e),this},D3D.Box.prototype.setPrinterStop=function(t,e){"use strict";return sendAPI(this.api+"printer/stop",t,e),this},D3D.Box.prototype.getSketch=function(t,e){"use strict";return getAPI(this.api+"sketch/?id="+t,e),this},D3D.Box.prototype.setSketch=function(t,e){"use strict";return sendAPI(this.api+"sketch",{data:t},e),this},D3D.Box.prototype.getSketchStatus=function(t){"use strict";return getAPI(this.api+"sketch/status",t),this},D3D.Box.prototype.setSketchClear=function(t){"use strict";return sendAPI(this.api+"sketch/clear",t),this},D3D.Box.prototype.getSystemVersions=function(t){"use strict";return getAPI(this.api+"system/fwversions",t),this},D3D.Box.prototype.getUpdateStatus=function(t){"use strict";return getAPI(this.api+"update/status",t),this},D3D.Box.prototype.setUpdateDownload=function(t){"use strict";return sendAPI(this.api+"update/download",{},t),this},D3D.Box.prototype.setUpdateInstall=function(t){"use strict";return sendAPI(this.api+"update/install",{},t),this},D3D.Box.prototype.setUpdateClear=function(t){"use strict";return sendAPI(this.api+"update/clear",{},t),this},D3D.Printer=function(t){"use strict";this.status={},this.config={},this.updateConfig(t)},D3D.Printer.prototype.updateConfig=function(t){"use strict";for(var e in t)0===e.indexOf("printer")&&(this.config[e]=t[e]);return this},D3D.Printer.prototype.getStartCode=function(){"use strict";var t=this.config["printer.startcode"];return t=this.subsituteVariables(t),t.split("\n")},D3D.Printer.prototype.getEndCode=function(){"use strict";var t=this.config["printer.endcode"];return t=this.subsituteVariables(t),t.split("\n")},D3D.Printer.prototype.subsituteVariables=function(t){"use strict";var e=this.config["printer.temperature"],i=this.config["printer.bed.temperature"],r=this.config["printer.heatup.temperature"],n=this.config["printer.heatup.bed.temperature"],o=this.config["printer.type"],s=this.config["printer.heatedbed"];switch(o){case"makerbot_replicator2":o="r2";break;case"makerbot_replicator2x":o="r2x";break;case"makerbot_thingomatic":o="t6";break;case"makerbot_generic":o="r2";break;case"_3Dison_plus":o="r2"}var p=s?"":";";return t=t.replace(/{printingTemp}/gi,e),t=t.replace(/{printingBedTemp}/gi,i),t=t.replace(/{preheatTemp}/gi,r),t=t.replace(/{preheatBedTemp}/gi,n),t=t.replace(/{printerType}/gi,o),t=t.replace(/{if heatedBed}/gi,p)},D3D.Slicer=function(){"use strict";this.lines=[]},D3D.Slicer.prototype.setGeometry=function(t){"use strict";return t instanceof THREE.BufferGeometry&&(t=(new THREE.Geometry).fromBufferGeometry(t)),this.geometry=t.clone(),this.geometry.mergeVertices(),this.createLines(),this},D3D.Slicer.prototype.createLines=function(){"use strict";function t(t,r){var n=e[t+"_"+r]||e[r+"_"+t];return void 0===n&&(n=i.lines.length,e[t+"_"+r]=n,i.lines.push({line:new THREE.Line3(i.geometry.vertices[t],i.geometry.vertices[r]),connects:[],normals:[]})),n}this.lines=[];for(var e={},i=this,r=0;rn;n+=e){r.set(new THREE.Vector3(0,-1,0),n);for(var o=[],s=[],p=0;p0)break;l=-1}else l=-1}f.length>0&&(f.push({X:f[0].X,Y:f[0].Y}),o.push(f))}if(!(o.length>0))break;i.push(o)}return i},D3D.Slicer.prototype.getInset=function(t,e){"use strict";var i=new ClipperLib.Paths,r=new ClipperLib.ClipperOffset(1,1);return r.AddPaths(t,ClipperLib.JoinType.jtRound,ClipperLib.EndType.etClosedPolygon),r.Execute(i,-e),i},D3D.Slicer.prototype.getFillTemplate=function(t,e,i,r){"use strict";var n=new ClipperLib.Paths;if(i)for(var o=0;t>=o;o+=e)n.push([{X:o,Y:0},{X:o,Y:t}]);if(r)for(var o=0;t>=o;o+=e)n.push([{X:0,Y:o},{X:t,Y:o}]);return n},D3D.Slicer.prototype.slicesToData=function(t,e){"use strict";for(var i=100,r=e.config["printer.layerHeight"]*i,n=e.config["printer.dimensions.z"]*i,o=e.config["printer.wallThickness"]*i,s=e.config["printer.shellThickness"]*i,p=e.config["printer.fillSize"]*i,a=(e.config["printer.brimOffset"]*i,[]),c=this.getFillTemplate(n,p,!0,!0),u=0;ud;d+=o){var g=this.getInset(l,d);f=f.concat(g)}for(var D=g||l,y=!1,d=1;s/r>d;d++){var P=ClipperLib.JS.Clone(t[u+d]);if(ClipperLib.JS.ScaleUpPaths(P,i),0===P.length||y&&0===y.length){y=[];break}if(y===!1)y=P;else{var m=new ClipperLib.Clipper,v=new ClipperLib.Paths;m.AddPaths(P,ClipperLib.PolyType.ptSubject,!0),m.AddPaths(y,ClipperLib.PolyType.ptClip,!0),m.Execute(ClipperLib.ClipType.ctIntersection,v),y=v}}var b=new ClipperLib.Clipper,w=new ClipperLib.Paths;b.AddPaths(D,ClipperLib.PolyType.ptSubject,!0),b.AddPaths(y,ClipperLib.PolyType.ptClip,!0),b.Execute(ClipperLib.ClipType.ctDifference,w);var b=new ClipperLib.Clipper,x=new ClipperLib.Paths;b.AddPaths(D,ClipperLib.PolyType.ptSubject,!0),b.AddPaths(w,ClipperLib.PolyType.ptClip,!0),b.Execute(ClipperLib.ClipType.ctDifference,x);var C=[],b=new ClipperLib.Clipper,B=new ClipperLib.Paths;b.AddPaths(c,ClipperLib.PolyType.ptSubject,!1),b.AddPaths(x,ClipperLib.PolyType.ptClip,!0),b.Execute(ClipperLib.ClipType.ctIntersection,B),C=C.concat(B);var A=this.getFillTemplate(n,o,u%2===0,u%2===1),b=new ClipperLib.Clipper,S=new ClipperLib.Paths;b.AddPaths(A,ClipperLib.PolyType.ptSubject,!1),b.AddPaths(w,ClipperLib.PolyType.ptClip,!0),b.Execute(ClipperLib.ClipType.ctIntersection,S),C=C.concat(S),ClipperLib.JS.ScaleDownPaths(l,i),ClipperLib.JS.ScaleDownPaths(f,i),ClipperLib.JS.ScaleDownPaths(C,i),a.push({outerLayer:l,innerLayer:f,fill:C})}return a},D3D.Slicer.prototype.dataToGcode=function(t,e){"use strict";function i(t){for(var e=[],i=0;if&&h&&e.push(["G0","E"+(D-d).toFixed(3),"F"+(60*l).toFixed(3)].join(" ")),e.push(["G0","X"+p.X.toFixed(3)+" Y"+p.Y.toFixed(3)+" Z"+w,"F"+60*a].join(" ")),D>f&&h&&e.push(["G0","E"+D.toFixed(3),"F"+(60*l).toFixed(3)].join(" "));else{var c=(new THREE.Vector2).set(p.X,p.Y),g=(new THREE.Vector2).set(n.X,n.Y),v=c.distanceTo(g);D+=v*u*r/P*m,e.push(["G1","X"+p.X.toFixed(3)+" Y"+p.Y.toFixed(3)+" Z"+w,"F"+y,"E"+D.toFixed(3)].join(" "))}n=p}return e}for(var r=e.config["printer.layerHeight"],n=e.config["printer.speed"],o=e.config["printer.bottomLayerSpeed"],s=e.config["printer.firstLayerSlow"],p=e.config["printer.bottomFlowRate"],a=e.config["printer.travelSpeed"],c=e.config["printer.filamentThickness"],u=e.config["printer.wallThickness"],h=(e.config["printer.enableTraveling"],e.config["printer.retraction.enabled"]),l=e.config["printer.retraction.speed"],f=e.config["printer.retraction.minDistance"],d=e.config["printer.retraction.amount"],g=e.getStartCode(),D=0,y=s?(60*o).toFixed(3):(60*n).toFixed(3),P=Math.pow(c/2,2)*Math.PI,m=p,v=0;vu;u++){var h=p[u%p.length];r(h.outerLayer,"red"),r(h.innerLayer,"green"),r(h.fill,"blue")}return a},D3D.Slicer.prototype.getGcode=function(t){"use strict";var e=t.config["printer.layerHeight"],i=t.config["printer.dimensions.z"],r=this.slice(i,e);r.shift();var n=this.slicesToData(r,t),o=this.dataToGcode(n,t);return o}; \ No newline at end of file diff --git a/src/box.js b/src/box.js index b0c57d1..66341a1 100644 --- a/src/box.js +++ b/src/box.js @@ -28,14 +28,9 @@ D3D.Box = function (localIp) { this.currentBatch = 0; this.loaded = false; - this.onload; - getAPI(self.api + "config/all", function (data) { - for (var i in data) { - if (i.indexOf("doodle3d") === 0) { - self.config[i] = data[i]; - } - } + this.getConfigAll(function (data) { + self.updateConfig(data); self.printer = new D3D.Printer(data); self.update(); @@ -46,6 +41,17 @@ D3D.Box = function (localIp) { } }); }; +D3D.Box.prototype.updateConfig = function (config) { + "use strict"; + + for (var i in config) { + if (i.indexOf("doodle3d") === 0) { + this.config[i] = config[i]; + } + } + + return this; +}; D3D.Box.prototype.update = function () { "use strict"; //TODO @@ -62,13 +68,17 @@ D3D.Box.prototype.update = function () { } }; D3D.Box.prototype.updateState = function () { + //que api calls so they don't overload the d3d box "use strict"; var self = this; - //que api calls so they don't overload the d3d box - getAPI(this.api + "info/status", function (data) { + this.getInfoStatus(function (data) { self.printer.status = data; + if (self.onupdate !== undefined) { + self.onupdate(data); + } + self.update(); }); }; @@ -94,9 +104,9 @@ D3D.Box.prototype.printBatch = function () { var gcode = this.printBatches.shift(); - sendAPI(this.api + "printer/print", { - "start": ((this.currentBatch === 0) ? true : false), - "first": ((this.currentBatch === 0) ? true : false), + this.setPrinterPrint({ + "start": ((this.currentBatch === 0) ? true : false), + "first": ((this.currentBatch === 0) ? true : false), "gcode": gcode.join("\n") }, function (data) { console.log("batch sent: " + self.currentBatch, data); @@ -106,7 +116,7 @@ D3D.Box.prototype.printBatch = function () { self.currentBatch ++; } else { - //finish printing + //finish sending } self.updateState(); @@ -131,7 +141,7 @@ D3D.Box.prototype.stopPrint = function () { "M117 Done ;display message (20 characters to clear whole screen)" ]; - sendAPI(this.api + "printer/stop", { + this.setPrinterStop({ "gcode": finishMove.join("\n") }, function (data) { console.log("Printer stop command sent"); @@ -139,11 +149,39 @@ D3D.Box.prototype.stopPrint = function () { return this; }; -D3D.Box.prototype.setConfig = function (data, callback) { + +//COMMUNICATION SHELL +//see http://www.doodle3d.com/help/api-documentation +D3D.Box.prototype.getConfig = function (keys, callback) { //works "use strict"; - sendAPI(this.api + "config", data, callback); + getAPI(this.api + "config/?" + keys.join("=&") + "=", callback); +}; +D3D.Box.prototype.getConfigAll = function (callback) { + //works + "use strict"; + + getAPI(this.api + "config/all", callback); +}; +D3D.Box.prototype.setConfig = function (data, callback) { + //works + "use strict"; + var self = this; + + sendAPI(this.api + "config", data, function (response) { + for (var i in response.validation) { + if (response.validation[i] !== "ok") { + delete data[i]; + } + } + self.updateConfig(data); + self.printer.updateConfig(data); + + if (callback !== undefined) { + callback(response); + } + }); return this; }; @@ -153,7 +191,15 @@ D3D.Box.prototype.getInfo = function (callback) { getAPI(this.api + "info", callback); }; -D3D.Box.prototype.downloadInfoLog = function (callback) { +D3D.Box.prototype.getInfoStatus = function (callback) { + //works + "use strict"; + + getAPI(this.api + "info/status", callback); + + return this; +}; +D3D.Box.prototype.downloadInfoLogFiles = function () { //works in google chrome... not tested in other browsers //some browsers may redirect using this code "use strict"; @@ -226,6 +272,14 @@ D3D.Box.prototype.setNetworkRemove = function (ssid, callback) { return this; }; +D3D.Box.prototype.getNetworkSignin = function (callback) { + //works + "use strict"; + + getAPI(this.api + "network/signin", callback); + + return this; +}; D3D.Box.prototype.getNetworkAlive = function (callback) { //works but returns empty array "use strict"; @@ -234,6 +288,30 @@ D3D.Box.prototype.getNetworkAlive = function (callback) { return this; }; +D3D.Box.prototype.getPrinterTemperature = function (callback) { + //works + "use strict"; + + getAPI(this.api + "printer/temperature", callback); + + return this; +}; +D3D.Box.prototype.getPrinterProgress = function (callback) { + //works + "use strict"; + + getAPI(this.api + "printer/progress", callback); + + return this; +}; +D3D.Box.prototype.getPrinterState = function (callback) { + //works + "use strict"; + + getAPI(this.api + "printer/state", callback); + + return this; +}; D3D.Box.prototype.getPrinterListAll = function (callback) { //works "use strict"; @@ -250,6 +328,56 @@ D3D.Box.prototype.setPrinterHeatup = function (callback) { return this; }; +D3D.Box.prototype.setPrinterPrint = function (data, callback) { + //works + "use strict"; + + sendAPI(this.api + "printer/print", data, callback); + + return this; +}; +D3D.Box.prototype.setPrinterStop = function (data, callback) { + //works + "use strict"; + + sendAPI(this.api + "printer/stop", data, callback); + + return this; +}; +D3D.Box.prototype.getSketch = function (id, callback) { + //works + "use strict"; + + getAPI(this.api + "sketch/?id=" + id, callback); + + return this; +}; +D3D.Box.prototype.setSketch = function (data, callback) { + //works + "use strict"; + + sendAPI(this.api + "sketch", { + "data": data + }, callback); + + return this; +}; +D3D.Box.prototype.getSketchStatus = function (callback) { + //works + "use strict"; + + getAPI(this.api + "sketch/status", callback); + + return this; +}; +D3D.Box.prototype.setSketchClear = function (callback) { + //works + "use strict"; + + sendAPI(this.api + "sketch/clear", callback); + + return this; +}; D3D.Box.prototype.getSystemVersions = function (callback) { //works "use strict"; @@ -258,46 +386,14 @@ D3D.Box.prototype.getSystemVersions = function (callback) { return this; }; -D3D.Box.prototype.getSketch = function (id, callback) { - //not tested - "use strict"; - - getAPI(this.api + "sketch/status/?id=" + id, callback); - - return this; -}; -D3D.Box.prototype.getSketchStatus = function (callback) { - //not tested - "use strict"; - - getAPI(this.api + "sketch/status", callback); - - return this; -}; D3D.Box.prototype.getUpdateStatus = function (callback) { - //not tested + //works "use strict"; getAPI(this.api + "update/status", callback); return this; }; -D3D.Box.prototype.setSketch = function (data, callback) { - //not tested - "use strict"; - - sendAPI(this.api + "sketch", data, callback); - - return this; -}; -D3D.Box.prototype.setSketchClear = function (callback) { - //not tested - "use strict"; - - sendAPI(this.api + "sketch/clear", callback); - - return this; -}; D3D.Box.prototype.setUpdateDownload = function (callback) { //not tested "use strict"; diff --git a/src/printer.js b/src/printer.js index 882c240..f69293f 100644 --- a/src/printer.js +++ b/src/printer.js @@ -11,11 +11,18 @@ D3D.Printer = function (config) { this.status = {}; this.config = {}; + this.updateConfig(config); +}; +D3D.Printer.prototype.updateConfig = function (config) { + "use strict"; + for (var i in config) { if (i.indexOf("printer") === 0) { this.config[i] = config[i]; } } + + return this; }; D3D.Printer.prototype.getStartCode = function () { "use strict"; diff --git a/src/slicer.js b/src/slicer.js index 0f0d82c..7ff8950 100644 --- a/src/slicer.js +++ b/src/slicer.js @@ -15,8 +15,6 @@ D3D.Slicer = function () { "use strict"; - this.geometry; - this.lines = []; }; D3D.Slicer.prototype.setGeometry = function (geometry) { @@ -50,8 +48,8 @@ D3D.Slicer.prototype.createLines = function () { lineLookup[a + "_" + b] = index; self.lines.push({ - line: new THREE.Line3(self.geometry.vertices[a], self.geometry.vertices[b]), - connects: [], + line: new THREE.Line3(self.geometry.vertices[a], self.geometry.vertices[b]), + connects: [], normals: [] }); } @@ -311,8 +309,8 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) { ClipperLib.JS.ScaleDownPaths(fill, scale); data.push({ - outerLayer: outerLayer, - innerLayer: innerLayer, + outerLayer: outerLayer, + innerLayer: innerLayer, fill: fill }); } @@ -353,7 +351,7 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) { if (extruder > retractionMinDistance && retractionEnabled) { gcode.push([ "G0", - "E" + (extruder - retractionAmount).toFixed(3), + "E" + (extruder - retractionAmount).toFixed(3), "F" + (retractionSpeed * 60).toFixed(3) ].join(" ")); } @@ -367,7 +365,7 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) { if (extruder > retractionMinDistance && retractionEnabled) { gcode.push([ "G0", - "E" + extruder.toFixed(3), + "E" + extruder.toFixed(3), "F" + (retractionSpeed * 60).toFixed(3) ].join(" ")); } diff --git a/src/utils.js b/src/utils.js index cbe6bb3..2b677f9 100644 --- a/src/utils.js +++ b/src/utils.js @@ -6,8 +6,8 @@ ******************************************************/ var D3D = { - "version": "0.1", - "website": "http://www.doodle3d.com/", + "version": "0.1", + "website": "http://www.doodle3d.com/", "contact": "develop@doodle3d.com" }; @@ -25,11 +25,11 @@ function sendAPI (url, data, callback) { "use strict"; $.ajax({ - url: url, - type: "POST", - data: data, - dataType: "json", - timeout: 10000, + url: url, + type: "POST", + data: data, + dataType: "json", + timeout: 10000, success: function (response) { if (response.status === "success") { if (callback !== undefined) { @@ -50,9 +50,9 @@ function getAPI (url, callback) { "use strict"; $.ajax({ - url: url, - dataType: "json", - timeout: 5000, + url: url, + dataType: "json", + timeout: 5000, success: function (response) { if (response.status === "success") { if (callback !== undefined) { @@ -73,7 +73,7 @@ function downloadFile (file, data) { "use strict"; $(document.createElement("a")).attr({ - download: file, + download: file, href: "data:text/plain," + data })[0].click(); }