diff --git a/dependencies/loaders/FileSaver.min.js b/dependencies/loaders/FileSaver.min.js new file mode 100755 index 0000000000000000000000000000000000000000..682d14b3789b20d668fec7b3428b27f8ca0266b7 --- /dev/null +++ b/dependencies/loaders/FileSaver.min.js @@ -0,0 +1,2 @@ +/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */ +var saveAs=saveAs||"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob&&navigator.msSaveOrOpenBlob.bind(navigator)||function(e){"use strict";if("undefined"==typeof navigator||!/MSIE [1-9]\./.test(navigator.userAgent)){var t=e.document,n=function(){return e.URL||e.webkitURL||e},o=t.createElementNS("http://www.w3.org/1999/xhtml","a"),r="download"in o,i=function(n){var o=t.createEvent("MouseEvents");o.initMouseEvent("click",!0,!1,e,0,0,0,0,0,!1,!1,!1,!1,0,null),n.dispatchEvent(o)},a=e.webkitRequestFileSystem,c=e.requestFileSystem||a||e.mozRequestFileSystem,s=function(t){(e.setImmediate||e.setTimeout)(function(){throw t},0)},u="application/octet-stream",f=0,d=500,l=function(t){var o=function(){"string"==typeof t?n().revokeObjectURL(t):t.remove()};e.chrome?o():setTimeout(o,d)},v=function(e,t,n){t=[].concat(t);for(var o=t.length;o--;){var r=e["on"+t[o]];if("function"==typeof r)try{r.call(e,n||e)}catch(i){s(i)}}},p=function(t,s){var d,p,w,y=this,m=t.type,S=!1,h=function(){v(y,"writestart progress write writeend".split(" "))},O=function(){if((S||!d)&&(d=n().createObjectURL(t)),p)p.location.href=d;else{var o=e.open(d,"_blank");void 0==o&&"undefined"!=typeof safari&&(e.location.href=d)}y.readyState=y.DONE,h(),l(d)},b=function(e){return function(){return y.readyState!==y.DONE?e.apply(this,arguments):void 0}},g={create:!0,exclusive:!1};return y.readyState=y.INIT,s||(s="download"),r?(d=n().createObjectURL(t),o.href=d,o.download=s,i(o),y.readyState=y.DONE,h(),void l(d)):(/^\s*(?:text\/(?:plain|xml)|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(t.type)&&(t=new Blob(["",t],{type:t.type})),e.chrome&&m&&m!==u&&(w=t.slice||t.webkitSlice,t=w.call(t,0,t.size,u),S=!0),a&&"download"!==s&&(s+=".download"),(m===u||a)&&(p=e),c?(f+=t.size,void c(e.TEMPORARY,f,b(function(e){e.root.getDirectory("saved",g,b(function(e){var n=function(){e.getFile(s,g,b(function(e){e.createWriter(b(function(n){n.onwriteend=function(t){p.location.href=e.toURL(),y.readyState=y.DONE,v(y,"writeend",t),l(e)},n.onerror=function(){var e=n.error;e.code!==e.ABORT_ERR&&O()},"writestart progress write abort".split(" ").forEach(function(e){n["on"+e]=y["on"+e]}),n.write(t),y.abort=function(){n.abort(),y.readyState=y.DONE},y.readyState=y.WRITING}),O)}),O)};e.getFile(s,{create:!1},b(function(e){e.remove(),n()}),b(function(e){e.code===e.NOT_FOUND_ERR?n():O()}))}),O)}),O)):void O())},w=p.prototype,y=function(e,t){return new p(e,t)};return w.abort=function(){var e=this;e.readyState=e.DONE,v(e,"abort")},w.readyState=w.INIT=0,w.WRITING=1,w.DONE=2,w.error=w.onwritestart=w.onprogress=w.onwrite=w.onabort=w.onerror=w.onwriteend=null,y}}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content);"undefined"!=typeof module&&module.exports?module.exports.saveAs=saveAs:"undefined"!=typeof define&&null!==define&&null!=define.amd&&define([],function(){return saveAs}); \ No newline at end of file diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index 4a296de7e93ca288c42326e3a13f28cefcd2c9e8..d0061863e91ebcc7d0f3957948496407bb286cb8 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -86,7 +86,7 @@ DMACell.prototype._setCellMeshVisibility = function(visibility){ }; /////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////DELETE//////////////////////////////////////////////////////// +/////////////////////////////////META////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// DMACell.prototype.removePart = function(index){ @@ -117,6 +117,16 @@ DMACell.prototype.destroy = function(){ this.parts = null; }; +DMACell.prototype.toJSON = function(){ + if (!this.parts) this.parts = this._initParts(); + return { + indices:this.indices, + parts: this.parts, +// position: this.getPosition(), +// orientation: this.getOrientation() + }; +}; + diff --git a/js/fea/DmaPart.js b/js/fea/DmaPart.js index ec4396fddeaf808c4dfb97f56e75571efa581346..36b436533852eb7f6caf829a38ba2c3cbc4abcf2 100644 --- a/js/fea/DmaPart.js +++ b/js/fea/DmaPart.js @@ -75,6 +75,11 @@ this.type = null; }; + DMAPart.prototype.toJSON = function(){ + return { + } + }; + ////////////////////////////////////////////////////////////// /////////////////TRIANGLE PART/////////////////////////////////// diff --git a/js/menus/Navbar.js b/js/menus/Navbar.js index d312437c2f459ae424434b168daea88e1e4e69ed..e9b8103d8929b6209e65ddcb1da6729e4587975f 100644 --- a/js/menus/Navbar.js +++ b/js/menus/Navbar.js @@ -12,7 +12,8 @@ NavBar = Backbone.View.extend({ events: { "click #showHideMenu": "_setMenuVis", - "click .menuHoverControls": "_setNavSelection" + "click .menuHoverControls": "_setNavSelection", + "click #saveAs": "_saveAs" }, initialize: function(){ @@ -62,6 +63,11 @@ NavBar = Backbone.View.extend({ }); }, + _saveAs: function(e){ + e.preventDefault(); + dmaGlobals.lattice.saveAsJSON(); + }, + _uiStuff: function(){ var $logo = $("#logo"); $logo.mouseover(function(){ diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 222f47e9d39a075453d31a94d5c201a24e042393..fc13658a61b6547cadbc211d3714c97551e8ebda 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -18,7 +18,7 @@ Lattice = Backbone.Model.extend({ numInvCells: 0, basePlane: null,//plane to build from - scale: window.defaultLatticeScale, + scale: 20, highlighter: null,//highlights build-able surfaces shouldPreserveCells: true,//preserve cells when changing lattice type @@ -434,6 +434,16 @@ Lattice = Backbone.Model.extend({ } }, + saveAsJSON: function(){ + var data = JSON.stringify(_.omit(this.toJSON(), ["highlighter", "basePlane"])); + var blob = new Blob([data], {type: "text/plain;charset=utf-8"}); + saveAs(blob, "lattice.json"); + }, + + loadFromJSON: function(){ + + }, + //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////FACE CONN OCTA LATTICE//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// @@ -613,9 +623,6 @@ Lattice = Backbone.Model.extend({ addFreeFormCell: function(parentCellPos, parentCellOrient, direction){ var scale = this.get("scale"); var cells = this.get("cells"); -// console.log(parentCellPos); -// console.log(parentCellOrient); -// console.log(direction); cells[0][0].push(new DMAFreeFormOctaCell({x:0,y:0,z:cells[0][0].length}, scale, parentCellPos, parentCellOrient, direction)); this.set("numCells", this.get("numCells")+1); dmaGlobals.three.render(); @@ -862,7 +869,7 @@ Lattice = Backbone.Model.extend({ }, _inverseIndicesToAdd: function(index){ - var inverseIndicesToAdd = [ + return [ this._add(index, {x:0,y:0,z:0}), this._add(index, {x:0,y:1,z:0}), this._add(index, {x:1,y:0,z:0}), @@ -873,7 +880,6 @@ Lattice = Backbone.Model.extend({ this._add(index, {x:1,y:0,z:1}), this._add(index, {x:1,y:1,z:1}) ]; - return inverseIndicesToAdd; }, xScale: function(scale){ diff --git a/main.html b/main.html index b994f8a812788f5b03905c8cbc5f4ca3b86b9773..e5f001aed4f95b911a910a796a637880ba72eef8 100644 --- a/main.html +++ b/main.html @@ -29,6 +29,7 @@ <script src="dependencies/OrbitControls.js"></script> <!--stl import/export--> + <script src="dependencies/loaders/FileSaver.min.js"></script> <script src="dependencies/THREE2STL.js"></script> <script src="dependencies/loaders/STLLoader.js"></script> @@ -37,7 +38,7 @@ <!--global variables--> <script> - window.defaultLatticeScale = 20; + </script> <!--multi-threading--> @@ -92,11 +93,11 @@ <li><a data-menu-id="navSim" class="menuHoverControls" href="#">Simulate</a></li> <li><a data-menu-id="navAssemble" class="menuHoverControls" href="#">Assemble</a></li> <li class="dropdown navDropdown"> - <a href="#" class="dropdown-toggle" data-toggle="dropdown">Export <b class="caret"></b></a> + <a href="#" class="dropdown-toggle" data-toggle="dropdown">File <b class="caret"></b></a> <span class="dropdown-arrow"></span> <ul class="dropdown-menu"> - <li><a id="exportSTL" href="#">Export STL</a></li> - <li><a href="#">Another action</a></li> + <li><a id="exportSTL" href="#">Import Lattice</a></li> + <li><a id="saveAs" href="#">Save Lattice JSON</a></li> <li><a href="#">Something else here</a></li> <li class="divider"></li> <li><a href="#">Separated link</a></li> @@ -114,15 +115,6 @@ <div id="menuWrapper"><div id="menuHeader"></div><div id="menuContent"></div></div> -<div id="importGeometry" class="row navMenu"> -</div> -<div id="element" class="row navMenu"> - <div class="row demo-row"> - <div class="col-xs-3"> - <a id="elementCube" href="#">Cube</a> - </div> - </div> -</div> <div id="about" class="row navMenu"> <div class="row demo-row"> <div class="col-xs-3"> @@ -130,6 +122,7 @@ </div> </div> </div> + <div id="threeContainer"></div>