From bbc910d326eae9ef176472fd460d0c3c62fbad3a Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Mon, 9 Feb 2015 10:51:12 -0500 Subject: [PATCH] eod --- js/menus/ImportMenuView.js | 7 +++++ js/menus/LatticeMenuView.js | 6 +++++ js/menus/MenuWrapperView.js | 16 ++++++++++++ js/menus/PartMenuView.js | 6 +++++ js/menus/ScriptMenuView.js | 5 ++++ js/menus/SketchMenuView.js | 6 +++++ js/models/AppState.js | 34 +++++++++++++++++------- js/models/BasePlane.js | 1 + js/models/Lattice.js | 52 +++++++++++++++++++++++++++++++++++++ 9 files changed, 124 insertions(+), 9 deletions(-) diff --git a/js/menus/ImportMenuView.js b/js/menus/ImportMenuView.js index e8a6f025..4e188caf 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 20309ceb..356347ba 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 cd6c279e..7b26324c 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 e266c671..eb9f52c9 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 324e4b79..5b755e35 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 1aefd45c..ec117107 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 53e1fa12..04d9d305 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 5593cc9e..6c585365 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 c98268f9..7d50d1a8 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////////////////////////////////// -- GitLab