diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index 30ee34679ccff300fbd1d7791e66b73ade07dc13..61fd323b40e0a1edd5be90f11b830f8bbe0fe829 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -8,6 +8,8 @@ LatticeMenuView = Backbone.View.extend({ el: "#menuContent", events: { + "click #latticeMenuClearCells": "_clearCells" + }, initialize: function(){ @@ -16,6 +18,11 @@ LatticeMenuView = Backbone.View.extend({ this.listenTo(this.model, "change", this.render); }, + _clearCells: function(e){ + e.preventDefault(); + this.model.clearCells(); + }, + _formatData: function(){ var formattedCellType = "Octagon"; var formattedConnectionType = "Face-Connected"; @@ -32,7 +39,7 @@ LatticeMenuView = Backbone.View.extend({ Scale: <%= scale %><br/>\ Column Separation:<br/>\ NumCells: <%= numCells %><br/><br/>\ - <a href="#" class=" btn btn-block btn-lg btn-default">Clear All Cells</a><br/>\ + <a href="#" id="latticeMenuClearCells" class=" btn btn-block btn-lg btn-default">Clear All Cells</a><br/>\ ') }); \ No newline at end of file diff --git a/js/models/lattice.js b/js/models/lattice.js index fef1ebfde42258bd94da20439a3c4be6b2c64f12..8466fd0f16b45ce926e84b6b15e14107c7fea454 100644 --- a/js/models/lattice.js +++ b/js/models/lattice.js @@ -22,14 +22,16 @@ Lattice = Backbone.Model.extend({ }, addCell: function(position){ - new Cell(position); + this.get("cells").push(new Cell(position)); this.set("numCells", this.get("numCells")+1); window.three.render(); }, removeCell: function(object){ - window.three.sceneRemove(object); + var cells = this.get("cells"); + cells.splice(cells.indexOf(object), 1); this.set("numCells", this.get("numCells")-1); + window.three.sceneRemove(object); window.three.render(); }, @@ -38,7 +40,8 @@ Lattice = Backbone.Model.extend({ cell.remove(); }); this.set("cells", []); - this.set("numCells, 0"); + this.set("numCells", 0); + window.three.render(); } }); \ No newline at end of file diff --git a/js/models/threeModel.js b/js/models/threeModel.js index ff5a5e8d5d3f00a68f03aee448d9fbc67c4f016a..a4ccba9c30446563934db5a39d276fe233795286 100644 --- a/js/models/threeModel.js +++ b/js/models/threeModel.js @@ -54,7 +54,7 @@ function ThreeModel(){ function sceneRemove(object){ var objectToRemove = object; - if (object.parent !== THREE.Scene) { + if (object.parent.type != "Scene") { objectToRemove = object.parent; } scene.remove(objectToRemove); @@ -66,15 +66,16 @@ function ThreeModel(){ renderer.render(scene, camera); } - function clearAll(){x - var children = scene.children; - for (var i=children.length;i>=0;i--){ - var object = children[i]; - if (object instanceof THREE.Mesh){// && object != this.fillGeometry.get("mesh") - scene.remove(object); - } - } - render(); + function clearAll(){ +// var children = objects.slice(0); +// for (var i=children.length;i>=0;i--){ +// var object = children[i]; +// if (!(object instanceof THREE.Mesh)){// && object != this.fillGeometry.get("mesh") +// scene.remove(object); +// objects.splice(objects.indexOf(object), 1); +// } +// } +// render(); } return {//return public properties/methods diff --git a/js/threeViews/threeView.js b/js/threeViews/threeView.js index 1d9673cc2a70925d5443da96712f16deb099bb4b..f9cc4b4f5b8f3a84edf11b767da366894c026b63 100644 --- a/js/threeViews/threeView.js +++ b/js/threeViews/threeView.js @@ -75,6 +75,7 @@ ThreeView = Backbone.View.extend({ this.controls.enabled = !state; break; case 32://space bar + e.preventDefault(); this.deleteMode = state; this.controls.enabled = !state; break;