diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 3dff20a136a3341e7e12aa63c50017839f8387ab..1352ff6d64d4cda50ed25faa8eacf3ae52643b6c 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -18,6 +18,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre latticeType: "willGik", partType: null, + aspectRatio: null, + denseCellsMin: null, overlapDetected: false, @@ -32,8 +34,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre //todo change latticeType this.listenTo(this, "change:partType change:latticeType", this._updatePartType); this.listenTo(this, "change:cellType change:connectionType", function(){ - this._updateLatticeType();//pass no params + this._updateLatticeConfig();//pass no params }); + this.listenTo(this, "change:latticeType", this._updateLatticeType); this.listenTo(this, "change:cellSeparation", this._updateCellSeparation); this.listenTo(appState, "change:currentNav", this._navChanged); @@ -41,7 +44,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre this.updateThreeViewTarget(); }); - this._updateLatticeType(); + this._updateLatticeConfig(); }, @@ -73,12 +76,15 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre if (latticeData.parts) newPartType = _.keys(latticeData.parts)[0]; this.set("partType", newPartType, {silent:true}); - var newMaterialClass = (latticeData.materialClasses || plist.allMaterialClasses)[0]; - appState.set("materialClass", newMaterialClass); + this._updateLatticeType(); }, - _getLatticePlistData: function(){ - return plist.allLattices[this.get("cellType")].connection[this.get("connectionType")].type[this.get("latticeType")]; + _updateLatticeType: function(){ + var latticeData = this._getLatticePlistData(); + this.set("aspectRatio", latticeData.aspectRatio.clone(), {silent:true}); + + var newMaterialClass = (latticeData.materialClasses || _.keys(plist.allMaterialClasses))[0]; + appState.set("materialClass", newMaterialClass); }, _setDefaultCellMode: function(){//if no part associated with this lattice type @@ -244,7 +250,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre self.compositeEditor = new CompositeEditorLattice(_.extend({id:id}, _.omit(data, "sparseCells")), null, function(_self){ var cells = null; if (data) cells = data.sparseCells; - _self._updateLatticeType(cells, self._getSubclassForLatticeType()); + _self._updateLatticeConfig(cells, self._getSubclassForLatticeType()); appState.set("currentNav", "navComposite"); }); diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index c50e25750614ee7560bfc46ba335010674993246..c09bf9939a552ce36f1ef42d6c77eb7e89c74b30 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -41,7 +41,11 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre //lattice type - _updateLatticeType: function(cells, subclass){//do not clear cells if loading from file (cells array contains important metadata) + _getLatticePlistData: function(){ + return plist.allLattices[this.get("cellType")].connection[this.get("connectionType")].type[this.get("latticeType")]; + }, + + _updateLatticeConfig: function(cells, subclass){//do not clear cells if loading from file (cells array contains important metadata) if (!cells) { if (this._setToDefaultsSilently) this._setToDefaultsSilently(); diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index f4978aa26c506f82313c0c4590cb58ebb250a566..4aaa1845d6f4280b2475e3cf81515ae1b0430fe7 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -16,9 +16,7 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice', 'text!latticeM }, _makeTemplateJSON: function(){ - var aspectRatio = {aspectRatio: {x:1,y:1,z:1}}; - if (lattice.xScale) aspectRatio = {aspectRatio: {x:lattice.xScale(0), y:lattice.yScale(0), z:lattice.zScale(0)}}; - return _.extend(_.extend(lattice.toJSON(), this.model.toJSON()), plist, aspectRatio); + return _.extend(_.extend(lattice.toJSON(), this.model.toJSON()), plist); }, template: _.template(template) diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index 60d213adb1e222edb6fb9f1818aaaf015b0f244a..033ff84d269e66ff09e468a6e41800f48417c1bc 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -105,9 +105,10 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice', 'appState', 'tex _updateInt: function(e){ e.preventDefault(); var $target = $(e.target); - var newVal = parseInt($target.val()); + var val = $target.val(); + if (val == "") return; + var newVal = parseInt(val); if (isNaN(newVal)) { - if (newVal == "") return; console.warn("value is NaN"); return; } diff --git a/js/models/FileSaver.js b/js/models/FileSaver.js index 1c2af8d3926871310f83b48bc119326a6c305a8e..2902c199c4a5bf895e82564384cba205c0391c79 100644 --- a/js/models/FileSaver.js +++ b/js/models/FileSaver.js @@ -105,7 +105,7 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra lattice.clearCells(); var sparseCells = data.assembly.sparseCells; _setData(lattice, _.omit(data.assembly, "sparseCells")); - if (sparseCells) lattice._updateLatticeType(sparseCells); + if (sparseCells) lattice._updateLatticeConfig(sparseCells); ribbon.render(); menuWrapper.render(); }