From 6388f39e2173073fa02ee76e0039664e490455c0 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Sat, 31 Jan 2015 23:32:51 -0500 Subject: [PATCH] cell and connections selection --- js/menus/LatticeMenuView.js | 44 ++++++++++++++++++++++++++++++------- js/models/BasePlane.js | 7 +++--- js/models/Lattice.js | 4 +++- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index bb46a1bc..d3ca8e8a 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 11ae2f4d..3887b963 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 496d62f4..bd3d5683 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"), -- GitLab