diff --git a/index.html b/index.html index 197c6d816506cecfc61e63ad72b5393cc4f240f0..9187d7e3d359d285bec50dacb2063477634302fe 100644 --- a/index.html +++ b/index.html @@ -87,7 +87,7 @@ <p class="modal-title" >Enter File Name</p> </div> <div class="modal-body"> - <input id="saveAsFileName" type="text" value="file" placeholder="Enter file name" class="form-control filename"> + <input id="saveAsFileName" type="text" value="DM Assembly" placeholder="Enter file name" class="form-control filename"> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> @@ -105,7 +105,7 @@ <p class="modal-title" >Save User Settings</p> </div> <div class="modal-body"> - <input id="saveUserFileName" type="text" value="user" placeholder="Enter file name" class="form-control filename"> + <input id="saveUserFileName" type="text" value="User" placeholder="Enter file name" class="form-control filename"> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> diff --git a/js/cam/Machine.js b/js/cam/Machine.js index d5a098d63371ec539a72c8f33cf98650f0189083..09587679725c31a72fb4bebae2419b73d2966c31 100644 --- a/js/cam/Machine.js +++ b/js/cam/Machine.js @@ -70,7 +70,7 @@ Machine.prototype.setScale = function(scale){ Machine.prototype._makeStockCell = function(){ if (globals.lattice.makeSuperCell) return globals.lattice.makeSuperCell(); - return globals.lattice.makeCellForLatticeType(null, globals.lattice.get("scale")); + return globals.lattice.makeCellForLatticeType({}, globals.lattice.get("scale")); }; Machine.prototype.updateCellType = function(){ diff --git a/js/cam/assemblers/Assembler.js b/js/cam/assemblers/Assembler.js index 232478be8fd93aed33798239ddfef4f81af849d7..46bfb07c19ca9c9e8f299c010f1fdc40d0084b9c 100644 --- a/js/cam/assemblers/Assembler.js +++ b/js/cam/assemblers/Assembler.js @@ -22,7 +22,7 @@ function Assembler(){ Assembler.prototype._buildStock = function(){ if (globals.lattice.makeSuperCell) return globals.lattice.makeSuperCell(); - return globals.lattice.makeCellForLatticeType(null); + return globals.lattice.makeCellForLatticeType({}); }; Assembler.prototype._positionStockRelativeToEndEffector = function(){ diff --git a/js/cells/CubeCell.js b/js/cells/CubeCell.js index ff808f388f58590c312b7cc98f56d23908f035c7..81d38571cc8bf9e05eb2bde3bcf6e5184e391db0 100644 --- a/js/cells/CubeCell.js +++ b/js/cells/CubeCell.js @@ -8,8 +8,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], var unitCellGeo = new THREE.BoxGeometry(1,1,1); - function CubeCell(index, superCell){ - DMACell.call(this, index, superCell); + function CubeCell(json, superCell){ + DMACell.call(this, json, superCell); } CubeCell.prototype = Object.create(DMACell.prototype); diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 812b88cddc4a9c1d8a8667c1f3c4a2bb2ea1711e..1cc4227f456ce46f6206d6530a8f9a023b48033c 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -8,12 +8,12 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], var wireframeMaterial = new THREE.MeshBasicMaterial({color:0x000000, wireframe:true}); - function DMACell(index, superCell, material, stopSetMode){ + function DMACell(json, superCell){ - if (index) this.index = new THREE.Vector3(index.x, index.y, index.z); + if (json.index) this.index = new THREE.Vector3(json.index.x, json.index.y, json.index.z); if (superCell) this.superCell = superCell; - this.material = material || lattice.get("materialType"); + this.material = json.material || lattice.get("materialType"); //object 3d is parent to all 3d elements owned by cell: cell mesh and wireframe, parts, beams, nodes, etc this.object3D = this._buildObject3D(); @@ -354,9 +354,10 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], DMACell.prototype.toJSON = function(){ var data = { - index:this.index//todo get rid of this and calculate from min and max + material: this.material }; - if (this.parts) data.parts = this.parts; + if (globals.materials.compositeMaterials[this.material]) return data;//material definition in material composites + if (this.cells) data.cells = this.cells; return data; }; diff --git a/js/cells/GIKCell.js b/js/cells/GIKCell.js index 7a35dc59e5c5640c1bdf16b0b43b61bf90fd0db1..f17442b07d4174ffc7e7d07b5d103f51ee2265d9 100644 --- a/js/cells/GIKCell.js +++ b/js/cells/GIKCell.js @@ -6,8 +6,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cubeCell'], function(_, THREE, three, lattice, appState, CubeCell){ - function GIKCell(index, superCell){ - CubeCell.call(this, index, superCell); + function GIKCell(json, superCell){ + CubeCell.call(this, json, superCell); } GIKCell.prototype = Object.create(CubeCell.prototype); diff --git a/js/cells/KelvinCell.js b/js/cells/KelvinCell.js index 911043bf14775ae7b8355c2ea4cc975de38fac69..e21d9ba87e2a4371ef3105e55a0e694d581228f5 100644 --- a/js/cells/KelvinCell.js +++ b/js/cells/KelvinCell.js @@ -97,8 +97,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'truncatedCu ]; unitGeo.computeFaceNormals(); - function KelvinCell(index, superCell){ - TruncatedCubeCell.call(this, index, superCell); + function KelvinCell(json, superCell){ + TruncatedCubeCell.call(this, json, superCell); } KelvinCell.prototype = Object.create(TruncatedCubeCell.prototype); diff --git a/js/cells/OctaEdgeCell.js b/js/cells/OctaEdgeCell.js index 689efe73106cceefaecaaa343cb51e7ba01d3678..9cc1a98af1fb70ae18dbedfaad4d286244606a26 100644 --- a/js/cells/OctaEdgeCell.js +++ b/js/cells/OctaEdgeCell.js @@ -6,8 +6,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'octaFaceCell'], function(_, THREE, three, lattice, appState, OctaFaceCell){ - function OctaEdgeCell(index, superCell){ - OctaFaceCell.call(this, index, superCell); + function OctaEdgeCell(json, superCell){ + OctaFaceCell.call(this, json, superCell); } OctaEdgeCell.prototype = Object.create(OctaFaceCell.prototype); diff --git a/js/cells/OctaFaceCell.js b/js/cells/OctaFaceCell.js index b1b021661bbf0ed9a7aeaf091af309436fb5e6da..2de0d9d7c9845344ddbe507cd2fb55d3c27e230a 100644 --- a/js/cells/OctaFaceCell.js +++ b/js/cells/OctaFaceCell.js @@ -10,8 +10,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], unitGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(-3*Math.PI/12)); unitGeo.applyMatrix(new THREE.Matrix4().makeRotationX(Math.asin(2/Math.sqrt(2)/Math.sqrt(3)))); - function OctaFaceCell(index, superCell){ - DMACell.call(this, index, superCell); + function OctaFaceCell(json, superCell){ + DMACell.call(this, json, superCell); } OctaFaceCell.prototype = Object.create(DMACell.prototype); diff --git a/js/cells/OctaRotEdgeCell.js b/js/cells/OctaRotEdgeCell.js index c41c0a5626714a449cdd35b7f6705fdff62c32cc..378eecfa29aab61dfb02c2771c9f653844deb232 100644 --- a/js/cells/OctaRotEdgeCell.js +++ b/js/cells/OctaRotEdgeCell.js @@ -9,8 +9,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], var unitGeo = new THREE.OctahedronGeometry(1/Math.sqrt(2)); unitGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI/4)); - function OctaRotEdgeCell(index, superCell){ - DMACell.call(this, index, superCell); + function OctaRotEdgeCell(json, superCell){ + DMACell.call(this, json, superCell); } OctaRotEdgeCell.prototype = Object.create(DMACell.prototype); diff --git a/js/cells/OctaVertexCell.js b/js/cells/OctaVertexCell.js index e60050e9d92c64120bfc37de86ef8ce629b1ffd3..4390c9045d01d077e6c9ee68e11eb24959a7597d 100644 --- a/js/cells/OctaVertexCell.js +++ b/js/cells/OctaVertexCell.js @@ -8,8 +8,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], var unitGeo = new THREE.OctahedronGeometry(1/Math.sqrt(2)); - function OctaVertexCell(index, superCell){ - DMACell.call(this, index, superCell); + function OctaVertexCell(json, superCell){ + DMACell.call(this, json, superCell); } OctaVertexCell.prototype = Object.create(DMACell.prototype); diff --git a/js/cells/TetraStackedCell.js b/js/cells/TetraStackedCell.js index 29be42c53f2365b6f029e2b94a0854430e50a882..2e477b290d4011b7c79a6a8420054d669849b567 100644 --- a/js/cells/TetraStackedCell.js +++ b/js/cells/TetraStackedCell.js @@ -12,8 +12,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], unitGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,Math.sqrt(3/8)-2/Math.sqrt(6))); unitGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); - function TetraStackedCell(index, superCell){ - DMACell.call(this, index, superCell); + function TetraStackedCell(json, superCell){ + DMACell.call(this, json, superCell); } TetraStackedCell.prototype = Object.create(DMACell.prototype); diff --git a/js/cells/TetraVertexCell.js b/js/cells/TetraVertexCell.js index 8a9c392c5ab66fb397250c20bb3818eaeb37a0b4..57bdda5ef00209ade5524d436b3f8b5d64eb79ae 100644 --- a/js/cells/TetraVertexCell.js +++ b/js/cells/TetraVertexCell.js @@ -12,8 +12,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], unitGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,Math.sqrt(3/8)-2/Math.sqrt(6))); unitGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); - function TetraStackedCell(index, superCell){ - DMACell.call(this, index, superCell); + function TetraStackedCell(json, superCell){ + DMACell.call(this, json, superCell); } TetraStackedCell.prototype = Object.create(DMACell.prototype); diff --git a/js/cells/TruncatedCubeCell.js b/js/cells/TruncatedCubeCell.js index ee4addcf51d5cd3aa523e5530d5892c569be8784..ceac765804a3f6ba4f124ca68632b860faf708d3 100644 --- a/js/cells/TruncatedCubeCell.js +++ b/js/cells/TruncatedCubeCell.js @@ -50,8 +50,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], ]; unitGeo.computeFaceNormals(); - function TruncatedCubeCell(index, superCell){ - DMACell.call(this, index, superCell); + function TruncatedCubeCell(json, superCell){ + DMACell.call(this, json, superCell); } TruncatedCubeCell.prototype = Object.create(DMACell.prototype); diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js index 6c8b8cb4e546303873b7f5705ff3b5993f6a7804..fc4dba853d6af99486d2f9947a823e4ea68db6ce 100644 --- a/js/cells/supercells/DMASuperCell.js +++ b/js/cells/supercells/DMASuperCell.js @@ -7,11 +7,11 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], function(_, THREE, three, lattice, appState, DMACell){ - function DMASuperCell(index, superCell){//supercells might have supercells + function DMASuperCell(json, superCell){//supercells might have supercells this.cells = true;//flag for now - DMACell.call(this, index, superCell); + DMACell.call(this, json, superCell); var material = this.getMaterial(); var range = material.dimensions || appState.get("superCellRange"); diff --git a/js/cells/supercells/GIKSuperCell.js b/js/cells/supercells/GIKSuperCell.js index 1b7ca98276b5ea718d74d0c3e2e4b733b7fcb8d8..1b69218b2e2d03d1d2792e61b46b1618b8e9dbe2 100644 --- a/js/cells/supercells/GIKSuperCell.js +++ b/js/cells/supercells/GIKSuperCell.js @@ -16,8 +16,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', return geo; } - GIKSuperCell = function(index, superCell){ - DMASuperCell.call(this, index, superCell); + GIKSuperCell = function(json, superCell){ + DMASuperCell.call(this, json, superCell); }; GIKSuperCell.prototype = Object.create(DMASuperCell.prototype); diff --git a/js/lattice/CompositeEditorLattice.js b/js/lattice/CompositeEditorLattice.js index 247377af172c5237fcf9d49df9b654c8d5da6c94..344a416a9bda7591b50853ff704e04fa3b958a18 100644 --- a/js/lattice/CompositeEditorLattice.js +++ b/js/lattice/CompositeEditorLattice.js @@ -20,7 +20,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre }), __initialize: function(options, callback){ - if (!options.id || options.id == "") this.set("id", this.cid); + if (!options.id || options.id == "") this.set("id", "super" + this.cid); if (!options.color || options.color == "") this.set("color", makeRandomColor(), {silent:true}); if (callback) callback(this); }, @@ -29,18 +29,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre var self = this; require([subclass], function(subclassObject){ _.extend(self, subclassObject); - -// //copy over cells to new lattice type -// var cells = self.cells; -// self._loopCells(cells, function(cell, x, y, z){ -// if (!cell) return; -// var index = _.clone(cell.index); -// if (cell.destroy) cell.destroy(); -// self.makeCellForLatticeType(index, function(newCell){ -// cells[x][y][z] = newCell; -// }); -// }); -// three.render(); }); }, diff --git a/js/lattice/CubeLattice.js b/js/lattice/CubeLattice.js index 492fddc8e02bb17b6363ba5e68b4fdb23e237ed3..cd9dc04f189289a6a26c18787f3e3271b9839149 100644 --- a/js/lattice/CubeLattice.js +++ b/js/lattice/CubeLattice.js @@ -38,9 +38,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre return 1+2*cellSeparation; }, - makeCellForLatticeType: function(indices, callback){ + makeCellForLatticeType: function(json, callback){ require(['cubeCell'], function(CubeCell){ - var cell = new CubeCell(indices); + var cell = new CubeCell(json); if (callback) callback(cell); }); }, diff --git a/js/lattice/GIKLattice.js b/js/lattice/GIKLattice.js index 25e65679fe5af5c72c1612ccb0a419b3da37acad..ef08736fe53ab33e6fe7b6734bb8088fa669ba78 100644 --- a/js/lattice/GIKLattice.js +++ b/js/lattice/GIKLattice.js @@ -38,9 +38,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre return 1.28*(1+2*cellSeparation); }, - makeCellForLatticeType: function(indices, callback){ + makeCellForLatticeType: function(json, callback){ require(['gikSuperCell'], function(GIKSuperCell){ - var cell = new GIKSuperCell(indices); + var cell = new GIKSuperCell(json); if (callback) callback(cell); }); }, diff --git a/js/lattice/KelvinLattice.js b/js/lattice/KelvinLattice.js index 231de87ab506a8eef4d944d930de0a0bbea595e8..f3b712df847054ad78c0306c712060763529f01b 100644 --- a/js/lattice/KelvinLattice.js +++ b/js/lattice/KelvinLattice.js @@ -39,9 +39,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre return 2*Math.sqrt(2)+2*cellSeparation; }, - makeCellForLatticeType: function(indices, callback){ + makeCellForLatticeType: function(json, callback){ require(['kelvinCell'], function(KelvinCell){ - var cell = new KelvinCell(indices); + var cell = new KelvinCell(json); if (callback) callback(cell); }); }, diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 0c4c5c245d7c5e70b3b85ed678bfcb1a7fbb6573..fcd6e4cb9747309c5c8a4ddb7c340da36560e241 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -50,14 +50,12 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre //lattice type - _updateLatticeType: function(loadingFromFile){//do not clear cells if loading from file (cells array contains important metadata) + _updateLatticeType: function(){//do not clear cells if loading from file (cells array contains important metadata) this._setToDefaultsSilently(); this._setDefaultCellMode(); this._loadMaterialClass(); - if (loadingFromFile === undefined) loadingFromFile = false; - if (loadingFromFile) console.warn('loading from file'); this.clearCells(); if (this._undo) this._undo(); @@ -92,13 +90,14 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre _.extend(self, subclassObject); self._initLatticeType(); + //todo parse cells? //copy over cells to new lattice type var cells = self.cells; self._loopCells(cells, function(cell, x, y, z){ if (!cell) return; var index = _.clone(cell.index); if (cell.destroy) cell.destroy(); - self.makeCellForLatticeType(index, function(newCell){ + self.makeCellForLatticeType({index:index}, function(newCell){ cells[x][y][z] = newCell; }); }); diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index 8e7137d032e85bab5d966c617ab746b72be5ab02..d2cf38c91f1a8e5465f02c651fc40a908aeeb386 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -53,7 +53,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre for (var z=relativeMin.z;z<=relativeMax.z;z++){ if (!this.sparseCells[x][y][z]) { var self = this; - this.makeCellForLatticeType((new THREE.Vector3(x, y, z)).add(cellsMin), function(cell){ + this.makeCellForLatticeType({index: (new THREE.Vector3(x, y, z)).add(cellsMin)}, function(cell){ self.sparseCells[x][y][z] = cell; self.set("numCells", self.get("numCells")+1); }); @@ -64,16 +64,16 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre three.render(); }, - addCellAtIndex: function(indices, noRender, noCheck){//no render no check from fill + addCellAtIndex: function(index, noRender, noCheck, material){//no render no check from fill/load - if (!noCheck || noCheck === undefined) this.checkForMatrixExpansion(this.sparseCells, indices, indices); + if (!noCheck || noCheck === undefined) this.checkForMatrixExpansion(this.sparseCells, index, index); - var index = (new THREE.Vector3()).subVectors(indices, this.get("cellsMin") || indices); - if (!this.sparseCells[index.x][index.y][index.z]) { + var relIndex = (new THREE.Vector3()).subVectors(index, this.get("cellsMin") || index); + if (!this.sparseCells[relIndex.x][relIndex.y][relIndex.z]) { var self = this; if (!noRender || noRender === undefined) three.setRenderFlag(); - this.makeCellForLatticeType(indices, function(cell){ - self.sparseCells[index.x][index.y][index.z] = cell; + this.makeCellForLatticeType({index:index, material:material}, function(cell){ + self.sparseCells[relIndex.x][relIndex.y][relIndex.z] = cell; self.set("numCells", self.get("numCells")+1); }); } else console.warn("already a cell there"); @@ -336,6 +336,31 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre //save/load + parseJSON: function(json){ + var self = this; + _.each(_.keys(json), function(key){ + if (key == "cellsMin" || key == "cellsMax" || key == "numCells") return; + self.set(key, json[key], {silent:true}); + }); + this.checkForMatrixExpansion(this.sparseCells, new THREE.Vector3(json.cellsMax.x, json.cellsMax.y, json.cellsMax.z), + new THREE.Vector3(json.cellsMin.x, json.cellsMin.y, json.cellsMin.z)); + this.trigger("change"); + }, + + parseCellsJSON: function(sparseCells){ + var cellsMin = this.get("cellsMin"); + this._loopCells(sparseCells, function(cell, x, y, z, self){ + if (cell) self.addCellAtIndex((new THREE.Vector3(x, y, z)).add(cellsMin), true, true, cell.material); + }); + three.render();//todo in callback + }, + + getSaveJSON: function(){ + var data = this.toJSON(); + data.sparseCells = this.sparseCells; + return data; + }, + toJSON: function(){//a minimal toJSON for ui stuff - no need to parse all cells return _.omit(this.attributes, ["nodes"]);//omit makes a copy }//todo something weird here diff --git a/js/lattice/OctaEdgeLattice.js b/js/lattice/OctaEdgeLattice.js index 6d95089e8caf3cd98d817828a743d0e19fcad53f..8db77437b8bafa8a063ac511b0ec38221e491671 100644 --- a/js/lattice/OctaEdgeLattice.js +++ b/js/lattice/OctaEdgeLattice.js @@ -76,9 +76,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre return 2/Math.sqrt(6)+2*cellSeparation; }, - makeCellForLatticeType: function(indices, callback){ + makeCellForLatticeType: function(json, callback){ require(['octaEdgeCell'], function(OctaEdgeCell){ - var cell = new OctaEdgeCell(indices); + var cell = new OctaEdgeCell(json); if (callback) callback(cell); }); }, diff --git a/js/lattice/OctaFaceLattice.js b/js/lattice/OctaFaceLattice.js index e4b4250fb270fd63adfa1c2df481b98cf9e05d82..a01225eeb8010f6b113d0a8ff5b349fd44722416 100644 --- a/js/lattice/OctaFaceLattice.js +++ b/js/lattice/OctaFaceLattice.js @@ -45,9 +45,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre return 2/Math.sqrt(6)+2*cellSeparation; }, - makeCellForLatticeType: function(indices, callback){ + makeCellForLatticeType: function(json, callback){ require(['octaFaceCell'], function(OctaFaceCell){ - var cell = new OctaFaceCell(indices); + var cell = new OctaFaceCell(json); if (callback) callback(cell); }); }, diff --git a/js/lattice/OctaRotEdgeLattice.js b/js/lattice/OctaRotEdgeLattice.js index b189274e507f876606459e497b3b1e1d15920e9c..2d8b52bf09af59834a8ad2107cf3148260d73751 100644 --- a/js/lattice/OctaRotEdgeLattice.js +++ b/js/lattice/OctaRotEdgeLattice.js @@ -43,9 +43,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre return Math.sqrt(2)/2 + 2*cellSeparation; }, - makeCellForLatticeType: function(indices, callback){ + makeCellForLatticeType: function(json, callback){ require(['octaRotEdgeCell'], function(OctaRotEdgeCell){ - var cell = new OctaRotEdgeCell(indices); + var cell = new OctaRotEdgeCell(json); if (callback) callback(cell); }); }, diff --git a/js/lattice/OctaVertexLattice.js b/js/lattice/OctaVertexLattice.js index 0e2af7538c08fc9c404da51c47c8a7db0fb902a4..ea9acd5835d7dca02439c135cd7a12ba5bb6675c 100644 --- a/js/lattice/OctaVertexLattice.js +++ b/js/lattice/OctaVertexLattice.js @@ -38,9 +38,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre return Math.sqrt(2)+2*cellSeparation; }, - makeCellForLatticeType: function(indices, callback){ + makeCellForLatticeType: function(json, callback){ require(['octaVertexCell'], function(OctaVertexCell){ - var cell = new OctaVertexCell(indices); + var cell = new OctaVertexCell(json); if (callback) callback(cell); }); }, diff --git a/js/lattice/TetraStackedLattice.js b/js/lattice/TetraStackedLattice.js index 5be5601b4b2d3f0fe624dd971a356174e2c6c194..ce40d53047834c6368bdc724a96b500e7d803ed7 100644 --- a/js/lattice/TetraStackedLattice.js +++ b/js/lattice/TetraStackedLattice.js @@ -45,9 +45,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre return 2/Math.sqrt(6)+2*cellSeparation; }, - makeCellForLatticeType: function(indices, callback){ + makeCellForLatticeType: function(json, callback){ require(['tetraStackedCell'], function(TetraStackedCell){ - var cell = new TetraStackedCell(indices); + var cell = new TetraStackedCell(json); if (callback) callback(cell); }); }, diff --git a/js/lattice/TetraVertexLattice.js b/js/lattice/TetraVertexLattice.js index 47dd4fd0374bed389dc5c61710bc95364d766ead..337e434dc4df8d9977c0e75adebc8ef7303ffecc 100644 --- a/js/lattice/TetraVertexLattice.js +++ b/js/lattice/TetraVertexLattice.js @@ -47,9 +47,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre return 2/Math.sqrt(6)+2*cellSeparation; }, - makeCellForLatticeType: function(indices, callback){ + makeCellForLatticeType: function(json, callback){ require(['tetraVertexCell'], function(TetraVertexCell){ - var cell = new TetraVertexCell(indices); + var cell = new TetraVertexCell(json); if (callback) callback(cell); }); }, diff --git a/js/lattice/TruncatedCubeLattice.js b/js/lattice/TruncatedCubeLattice.js index 8df8ebabf1a91a03dd8981676d5bce35bff18aa5..e5c34b67f8fd637c06f8ebcaaa4c7cd26c5c8209 100644 --- a/js/lattice/TruncatedCubeLattice.js +++ b/js/lattice/TruncatedCubeLattice.js @@ -39,9 +39,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre return Math.sqrt(2)+2*cellSeparation; }, - makeCellForLatticeType: function(indices, callback){ + makeCellForLatticeType: function(json, callback){ require(['truncatedCubeCell'], function(TruncatedCubeCell){ - var cell = new TruncatedCubeCell(indices); + var cell = new TruncatedCubeCell(json); if (callback) callback(cell); }); }, diff --git a/js/models/FileSaver.js b/js/models/FileSaver.js index be441f13343914335ca6a3da4f688f7345ffcf9f..dac9a3123fd91aa59ae43332a237d4d273e2652f 100644 --- a/js/models/FileSaver.js +++ b/js/models/FileSaver.js @@ -3,26 +3,26 @@ */ -define(['underscore', 'fileSaverLib'], function(_, saveAs){ +define(['underscore', 'fileSaverLib', 'lattice'], function(_, saveAs, lattice){ function _saveFile(data, name, extension){ var blob = new Blob([data], {type: "text/plain;charset=utf-8"}); saveAs(blob, name + extension); } - function save(name){ - if (!name || name == "" || name == undefined) name = "file"; - var data = JSON.stringify({ - lattice:_getLatticeDataToSave(), - assembler:_getAssemblerDataToSave() - }); - _saveFile(data, name, ".json"); - } +// function save(name){ +// if (!name || name == "" || name == undefined) name = "file"; +// var data = JSON.stringify({ +// lattice:_getLatticeDataToSave(), +//// assembler:_getAssemblerDataToSave() +// }); +// _saveFile(data, name, ".json"); +// } - function saveLattice(name){ - if (!name || name == "" || name == undefined) name = "lattice"; + function save(name){ + if (!name || name == "" || name == undefined) name = "DM Assembly"; var data = JSON.stringify({ - lattice:_getLatticeDataToSave() + assembly:_getLatticeDataToSave() }); _saveFile(data, name, ".json"); } @@ -49,14 +49,18 @@ define(['underscore', 'fileSaverLib'], function(_, saveAs){ } function _getLatticeDataToSave(){ - return globals.lattice.attributes; + return lattice.getSaveJSON(); } - function loadFile(data){//todo make this better - globals.lattice.getUItarget().clearCells(); - _setData(data, false); - globals.lattice._updateLatticeType(true); - globals.lattice.trigger("change:scale"); + function loadFile(data){//parsed json todo make this better - load composite + if (!data.assembly){ + console.warn("no assembly in this file"); + return; + } + lattice.clearCells(); + var sparseCells = data.assembly.sparseCells; + lattice.parseJSON(_.omit(data.assembly, sparseCells), false); + if (sparseCells) lattice.parseCellsJSON(sparseCells); } function loadUser(data){ @@ -64,20 +68,21 @@ define(['underscore', 'fileSaverLib'], function(_, saveAs){ } function _setData(data, silent){ - _.each(_.keys(data.lattice), function(key){ - globals.lattice.set(key, data.lattice[key], {silent:silent}); + if (silent === undefined) silent = false; + _.each(_.keys(data.assembly), function(key){ + lattice.set(key, data.assembly[key], {silent:silent}); }); - _.each(_.keys(data.assembler), function(key){ - globals.cam.set(key, data.assembler[key]); + _.each(_.keys(data.cam), function(key){ + cam.set(key, data.assembler[key]); }); } return {//return public methods +// save: save, save: save, - saveLattice: saveLattice, // saveAssembler: saveAssembler, - saveUser: saveUser, - loadFile: loadFile, - loadUser: loadUser +// saveUser: saveUser, + loadFile: loadFile +// loadUser: loadUser } }); \ No newline at end of file