diff --git a/index.html b/index.html index 9187d7e3d359d285bec50dacb2063477634302fe..2490d6e1397dfe805035c3365c0130b8672c58af 100644 --- a/index.html +++ b/index.html @@ -39,9 +39,9 @@ <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 class="saveJSON" href="#">Save JSON     (CTRL/⌘ + S)</a></li> - <li><a data-toggle="modal" data-target="#saveAsModel" href="#">Save JSON As...     (CTRL/⌘ + Shift + S)</a></li> - <li><a class="importJSON" href="#">Open JSON...     (CTRL/⌘ + O)</a></li> + <li><a class="saveJSON" href="#">Save Assembly     (CTRL/⌘ + S)</a></li> + <li><a data-toggle="modal" data-target="#saveAsModel" href="#">Save Assembly As...     (CTRL/⌘ + Shift + S)</a></li> + <li><a class="importJSON" href="#">Open Assembly...     (CTRL/⌘ + O)</a></li> <li class="dropdown-submenu"> <a tabindex="-1">Demo Files<span class="pull-right fui-arrow-right"></span></a> <ul class="dropdown-menu"> diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index fcd6e4cb9747309c5c8a4ddb7c340da36560e241..68a2561c15fa7e03606b33b387d7f5a3abb691c6 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -29,7 +29,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre this.listenTo(this, "change:partType", this._updatePartType); this.listenTo(this, "change:cellType change:connectionType", function(){ - this._updateLatticeType(false); + this._updateLatticeType(); }); this.listenTo(this, "change:cellSeparation", this._updateCellSeparation); @@ -39,7 +39,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre }, __initialize: function(){ - this._updateLatticeType(false); + this._updateLatticeType(); }, @@ -50,19 +50,31 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre //lattice type - _updateLatticeType: function(){//do not clear cells if loading from file (cells array contains important metadata) + _updateLatticeType: function(cells){//do not clear cells if loading from file (cells array contains important metadata) + + if (!cells) { + this._setToDefaultsSilently(); + cells = JSON.parse(JSON.stringify(this.sparseCells)); + } - this._setToDefaultsSilently(); this._setDefaultCellMode(); this._loadMaterialClass(); + var cellsMin = this.get("cellsMin"); + var cellsMax = this.get("cellsMax"); this.clearCells(); if (this._undo) this._undo(); if (globals.basePlane) globals.basePlane.destroy(); if (globals.highlighter) globals.highlighter.destroy(); - this._initLatticeSubclass(this._getSubclassForLatticeType()); + if (cellsMax && cellsMin) this.checkForMatrixExpansion(this.sparseCells, cellsMax, cellsMin); + var self = this; + require([this._getSubclassForLatticeType()], function(subclassObject){ + _.extend(self, subclassObject); + self._initLatticeType(); + if (self.get("cellsMin")) self.parseCellsJSON(cells); + }); }, _setToDefaultsSilently: function(){ @@ -83,28 +95,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre } }, - _initLatticeSubclass: function(subclass){ - var self = this; - require([subclass], function(subclassObject){ - - _.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:index}, function(newCell){ - cells[x][y][z] = newCell; - }); - }); - three.render(); - }); - }, - _getSubclassForLatticeType: function(){ var cellType = this.get("cellType"); var connectionType = this.get("connectionType"); @@ -161,11 +151,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre else console.warn("placing a cell that does not exist"); }, - _navChanged: function(){ - var currentNav = appState.get("currentNav"); - if (currentNav != "navComposite" && this.compositeEditor && this.exitCompositeEditing) this.exitCompositeEditing(); - }, - _updateCellSeparation: function(){ var cellSep = this.get("cellSeparation"); globals.basePlane.updateXYSeparation(cellSep.xy); @@ -265,6 +250,11 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre //composite Cells + _navChanged: function(){ + var currentNav = appState.get("currentNav"); + if (currentNav != "navComposite" && this.compositeEditor && this.exitCompositeEditing) this.exitCompositeEditing(); + }, + setToCompositeMode: function(id, data){ var self = this; require(['compositeEditorLattice'], function(CompositeEditorLattice){ diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index d2cf38c91f1a8e5465f02c651fc40a908aeeb386..09014bd85279c034dbc9236ac37173f6be6d4e1c 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -339,12 +339,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre 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){ diff --git a/js/models/FileSaver.js b/js/models/FileSaver.js index dac9a3123fd91aa59ae43332a237d4d273e2652f..a4d0ff2a6fb7ffefade083c0a53315c8173a66cd 100644 --- a/js/models/FileSaver.js +++ b/js/models/FileSaver.js @@ -60,7 +60,7 @@ define(['underscore', 'fileSaverLib', 'lattice'], function(_, saveAs, lattice){ lattice.clearCells(); var sparseCells = data.assembly.sparseCells; lattice.parseJSON(_.omit(data.assembly, sparseCells), false); - if (sparseCells) lattice.parseCellsJSON(sparseCells); + if (sparseCells) lattice._updateLatticeType(sparseCells); } function loadUser(data){