diff --git a/js/menus/ImportMenuView.js b/js/menus/ImportMenuView.js index e8a6f025d4bccd1e8e25c2d077ecb2e2b4eb928f..4e188caf9da1ccfedc9a772295a6619f72fc6a88 100644 --- a/js/menus/ImportMenuView.js +++ b/js/menus/ImportMenuView.js @@ -91,6 +91,13 @@ ImportMenuView = Backbone.View.extend({ this.$el.html(this.template(this.model.attributes)); }, + destroy: function(){ + this.stopListening(); + this.model = null; + this.lattice = null; + this.appState = null; + }, + // makeDimensionString: function(){ // var bounds = this.model.get("boundingBoxHelper").box; // return (bounds.max.x - bounds.min.x).toFixed(1) + " x " + diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index 20309cebc8789cd2897387928f4e13cd5cc83401..356347bafb6df44be182ca615500c9b7a10d5c2a 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -107,6 +107,12 @@ LatticeMenuView = Backbone.View.extend({ }); }, + destroy: function(){ + this.stopListening(); + this.model = null; + this.lattice = null; + }, + template: _.template('\ Cell Type: \ <div class="btn-group">\ diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index cd6c279e90ad961ce201c0cd8ef2fe76e2cbdc22..7b26324c8667425660c5bfaf2fdca84d4df0280b 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -110,6 +110,22 @@ MenuWrapper = Backbone.View.extend({ this.model.set("menuIsVisible", true); }, + destroy: function(){ + this.stopListening(); + this.lattice = null; + this.template = null; + this._dealloc(this.latticeMenu); + this._dealloc(this.importMenu); + this._dealloc(this.sketchMenu); + this._dealloc(this.partMenu); + this._dealloc(this.scriptMenu); + }, + + _dealloc: function(object){ + object.destroy(); + object = null; + }, + template: _.template('\ <ul class="nav nav-tabs nav-justified">\ <% var dict = eval(currentNav);\ diff --git a/js/menus/PartMenuView.js b/js/menus/PartMenuView.js index e266c67183759e0d9a3578b43bd6b2e81b396d7f..eb9f52c98b8cb3785342cd8ede6bfca8479d5d31 100644 --- a/js/menus/PartMenuView.js +++ b/js/menus/PartMenuView.js @@ -34,6 +34,12 @@ PartMenuView = Backbone.View.extend({ }); }, + destroy: function(){ + this.stopListening(); + this.model = null; + this.lattice = null; + }, + template: _.template('\ Part Type: \ <div class="btn-group">\ diff --git a/js/menus/ScriptMenuView.js b/js/menus/ScriptMenuView.js index 324e4b79f64d8c2f78f4fe46a5d8f9479bf7f480..5b755e359d466b5fe210af4284aa35244e6da652 100644 --- a/js/menus/ScriptMenuView.js +++ b/js/menus/ScriptMenuView.js @@ -19,6 +19,11 @@ ScriptMenuView = Backbone.View.extend({ this.$el.html(this.template()); }, + destroy: function(){ + this.stopListening(); + this.model = null; + }, + template: _.template('\ some kind of scripting functionality?\ ') diff --git a/js/menus/SketchMenuView.js b/js/menus/SketchMenuView.js index 1aefd45cdd4982560cc84116d85474c1ca5642b9..ec1171070cf7eb4717eb9ee83de3b426efee0236 100644 --- a/js/menus/SketchMenuView.js +++ b/js/menus/SketchMenuView.js @@ -34,6 +34,12 @@ SketchMenuView = Backbone.View.extend({ }); }, + destroy: function(){ + this.stopListening(); + this.model = null; + this.appState = null; + }, + template: _.template('\ Sketch Plane Height: <input id="zHeightSlider" data-slider-id="ex1Slider" type="text" data-slider-min="0" data-slider-max="20" data-slider-step="2" data-slider-value="<%= zIndex %>"/>\ ') diff --git a/js/models/AppState.js b/js/models/AppState.js index 53e1fa123accc3788260d898c826ac52c70595bb..04d9d305110a2e239bf0a9b2fe3d9e53daf9da3c 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -64,9 +64,7 @@ AppState = Backbone.Model.extend({ this.listenTo(this, "change:cellMode", this._cellModeDidChange); this.listenTo(this, "change:cellType change:connectionType", this._buildNewLattice); - this.listenTo(this, "change:lattice", this._buildLatticeMenu); - - this.set("lattice", new OctaFaceLattice({appState:this})); + this._buildNewLattice(); this.get("lattice").addCellAtIndex({x:0,y:0,z:0}); }, @@ -108,13 +106,31 @@ AppState = Backbone.Model.extend({ this.get("lattice").cellModeDidChange(this.get("cellMode")); }, - _buildLatticeMenu: function(){ - this.set("menuWrapper", new MenuWrapper({lattice:this.get("lattice"), model:this})); - }, - _buildNewLattice: function(){ - this.get("lattice").destroy(); -// var mode = + var currentLattice = this.get("lattice"); + if (currentLattice) { + currentLattice.destroy(); + } + var type = this.get("cellType"); + var connectionType = this.get("connectionType"); + if (type == "octa"){ + if (connectionType == "face"){ + this.set("lattice", new OctaFaceLattice({appState:this})); + } else if (connectionType == "edge"){ + this.set("lattice", new OctaEdgeLattice({appState:this})); + } else if (connectionType == "edgeRot"){ + + } else if (connectionType == "vertex"){ + + } + } else if (type == "cube"){ + + } + var currentMenu = this.get("menuWrapper"); + if (currentMenu) { + currentMenu.destroy(); + } + this.set("menuWrapper", new MenuWrapper({lattice:this.get("lattice"), model:this})); }, /////////////////////////////////////////////////////////////////////////////// diff --git a/js/models/BasePlane.js b/js/models/BasePlane.js index 5593cc9e26fd2b07141c49b9b32bb95a6eb495d4..6c585365cf085f62b5d7405aaf8304a6c07bfab5 100644 --- a/js/models/BasePlane.js +++ b/js/models/BasePlane.js @@ -53,6 +53,7 @@ BasePlane = Backbone.Model.extend({ }, destroy: function(){ +// this.stopListening(); this.set("zIndex", null, {silent:true}); this._removeMesh(); this.set("mesh", null, {silent:true}); diff --git a/js/models/Lattice.js b/js/models/Lattice.js index c98268f9acaa0f7b93248732ca6ac5b0b061de87..7d50d1a82cf9c708c00d3ad30580e646adeb0ba3 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -293,9 +293,13 @@ Lattice = Backbone.Model.extend({ }, destroy: function(){ + this.stopListening(); this.set("scale", null, {silent:true}); this.set("nodes", null, {silent:true}); this.clearCells(); +// this._iterCells(this.get("cells"), function(cell){ +// if (cell) cell.destroy(); +// }); this.set("cells", null, {silent:true}); this.set("inverseCells", null, {silent:true}); this.set("cellsMin", null, {silent:true}); @@ -365,6 +369,54 @@ OctaFaceLattice = Lattice.extend({ //////////////////////////////EDGE CONN OCTA LATTICE//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// +OctaEdgeLattice = Lattice.extend({ + + _initialize: function(){ + + //bind events + this.listenTo(this, "change:columnSeparation", this._changeColSeparation); + + this.set("basePlane", new OctaBasePlane({scale:this.get("scale")})); + this.set("columnSeparation", 0.0); + }, + + _changeColSeparation: function(){ + var colSep = this.get("columnSeparation"); + var scale = this.get("scale"); + this.get("basePlane").updateColSeparation(colSep); + this._iterCells(this.get("cells"), function(cell){ + if (cell) cell.updateForScale(scale); + }); + window.three.render(); + }, + + addCellAtPosition: function(absPosition){ + + //calc indices in cell matrix + var scale = this.get("scale"); + var colSep = this.get("columnSeparation"); + var latticeScale = scale*(1+2*colSep); + var octHeight = 2*scale/Math.sqrt(6); + var triHeight = latticeScale/2*Math.sqrt(3); + var position = {}; + position.x = Math.round(absPosition.x/latticeScale); + position.y = Math.round(absPosition.y/triHeight); + position.z = Math.round(absPosition.z/octHeight); + if (position.z%2 == 1) position.y += 1; + + this.addCellAtIndex(position); + }, + + getScale: function(){ + return this.get("scale")*(1.0+2*this.get("columnSeparation")); + }, + + _makeCellForLatticeType: function(indices, scale){ + return new DMASideOctaCell(this.appState.get("cellMode"), indices, scale, this); + } + +}); + //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////VERTEX CONN OCTA LATTICE//////////////////////////////////