diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index bb46a1bc8d58fb955f6a81880bf6bc3a950cc2e8..d3ca8e8afa682d693cec32056956067b5b9b901e 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -9,7 +9,9 @@ LatticeMenuView = Backbone.View.extend({ events: { "click #latticeMenuClearCells": "_clearCells", - "change #latticeScale": "_changeScale" + "change #latticeScale": "_changeScale", + "click .cellType": "_changeCellType", + "click .connectionType": "_changeConnectionType" }, @@ -37,20 +39,46 @@ LatticeMenuView = Backbone.View.extend({ this.model.set("scale", val); }, - _formatData: function(){ - var formattedCellType = "Octahedral"; - var formattedConnectionType = "Face-Connected"; - return {formattedCellType:formattedCellType, formattedConnectionType:formattedConnectionType}; + _changeCellType: function(e){ + e.preventDefault(); + var cellType = $(e.target).data("type"); + var currentCellType = this.model.get("cellType"); + this.model.set("cellType", cellType, {silent:true}); + if (currentCellType == cellType) return; + if (currentCellType == "cube") this.model.set("connectionType", "face"); + else if (currentCellType == "octa") this.model.set("connectionType", "face"); + }, + + _changeConnectionType: function(e){ + e.preventDefault(); + var connectionType = $(e.target).data("type"); + this.model.set("connectionType", connectionType); }, render: function(){ if (this.appState.get("currentTab") != "lattice") return; - this.$el.html(this.template(_.extend(this.model.attributes, this._formatData()))); + this.$el.html(this.template(this.model.attributes)); }, template: _.template('\ - Cell Type: <%= formattedCellType %><br/>\ - Cell Connection: <%= formattedConnectionType %><br/>\ + Cell Type: \ + <div class="btn-group">\ + <button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= allCellTypes[cellType] %><span class="caret"></span></button>\ + <ul role="menu" class="dropdown-menu">\ + <% _.each(_.keys(allCellTypes), function(key){ %>\ + <li><a class="cellType" data-type="<%= key %>" href="#"><%= allCellTypes[key] %></a></li>\ + <% }); %>\ + </ul>\ + </div><br/><br/>\ + Cell Connection: \ + <div class="btn-group">\ + <button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= allConnectionTypes[cellType][connectionType] %>-Connected<span class="caret"></span></button>\ + <ul role="menu" class="dropdown-menu">\ + <% _.each(_.keys(allConnectionTypes[cellType]), function(key){ %>\ + <li><a class="connectionType" data-type="<%= key %>" href="#"><%= allConnectionTypes[cellType][key] %></a></li>\ + <% }); %>\ + </ul>\ + </div><br/>\ Scale: <input id="latticeScale" value="<%= scale %>" placeholder="enter scale" class="form-control" type="text"><br/>\ NumCells: <%= numCells %><br/>\ <br/>\ diff --git a/js/models/BasePlane.js b/js/models/BasePlane.js index 11ae2f4dc220d794ce47e10fb591e9318c128951..3887b9638d1492c53a094f34d55207af9087049b 100644 --- a/js/models/BasePlane.js +++ b/js/models/BasePlane.js @@ -45,10 +45,9 @@ BasePlane = Backbone.Model.extend({ if (connectionType == "face"){ return this._createOctaFaceMesh(); } else if (connectionType == "edge"){ - if (this.get("zIndex")%2 == 0) return this._createOctaFaceMesh(); - + return this._createOctaFaceMesh(); } else if (connectionType == "vertex"){ - + return this._createOctaFaceMesh(); } } }, @@ -94,7 +93,7 @@ BasePlane = Backbone.Model.extend({ }, _createGridMesh: function(){ - + return this._createOctaFaceMesh(); }, _showMesh: function(){ diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 496d62f404b761638f352dc95e400c96665ecbd8..bd3d56832aab34d67f7c2b4dd9f355b8abbe5ada 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -8,7 +8,9 @@ Lattice = Backbone.Model.extend({ defaults: { scale: window.defaultLatticeScale, cellType: "octa", + allCellTypes: {octa:"Octahedron", cube:"Cube"}, connectionType: "face", + allConnectionTypes: {octa:{face:"Face", edge:"Edge", vertex:"Vertex"}, cube:{face:"Face"}}, nodes: [], cells: [[[null]]],//3D matrix containing all cells and null, dynamic size cellsMin: {x:0, y:0, z:0},//min position of cells matrix @@ -26,7 +28,7 @@ Lattice = Backbone.Model.extend({ //bind events this.listenTo(this, "change:cellMode", this._cellModeDidChange); this.listenTo(this, "change:scale", this._scaleDidChange); - this.listenTo(this, "change:cellType, change:connectionType", this._changeLatticeStructure); + this.listenTo(this, "change:cellType change:connectionType", this._changeLatticeStructure); this.set("basePlane", new BasePlane({cellType:this.get("cellType"), connectionType:this.get("connectionType"),