From a2b76e3885ec3deb0393d7aca47dac4a0a7a00cf Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Fri, 30 Jan 2015 18:42:36 -0500
Subject: [PATCH] bugfix

---
 js/fea/dmaCell.js          | 6 ++++++
 js/main.js                 | 8 ++++----
 js/models/lattice.js       | 8 ++++++--
 js/threeViews/threeView.js | 2 +-
 4 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/js/fea/dmaCell.js b/js/fea/dmaCell.js
index 8acd45aa..cd477996 100644
--- a/js/fea/dmaCell.js
+++ b/js/fea/dmaCell.js
@@ -73,6 +73,12 @@
     DMACell.prototype.removePart = function(index){
         this.parts[index].destroy();
         this.parts[index] = null;
+        var hasAnyParts = false;
+        _.each(this.parts, function(part){
+            if (part) hasAnyParts = true;
+        });
+        console.log("amanda");
+        if (!hasAnyParts) window.lattice.removeCell(this);
     };
 
     DMACell.prototype._buildCellMesh = function(position, zIndex){//abstract mesh representation of cell
diff --git a/js/main.js b/js/main.js
index b5183a15..3c6162c2 100644
--- a/js/main.js
+++ b/js/main.js
@@ -10,15 +10,15 @@ $(function(){
 
     //init threeJS and geometry models
     window.three = new ThreeModel();
-    var lattice = new Lattice();
+    window.lattice = new Lattice();
 
     //setup ui
-    var appState = new AppState({lattice:lattice});
-    new MenuWrapper({lattice:lattice, model:appState});
+    var appState = new AppState({lattice:window.lattice});
+    new MenuWrapper({lattice:window.lattice, model:appState});
     new NavBar({model:appState});
 
     //threeJS View
-    new ThreeView({model:window.three, lattice:lattice, appState:appState});
+    new ThreeView({model:window.three, lattice:window.lattice, appState:appState});
 
     lattice.addCell(new THREE.Vector3(0,0,0));
 });
diff --git a/js/models/lattice.js b/js/models/lattice.js
index 707f00d9..bbb3a233 100644
--- a/js/models/lattice.js
+++ b/js/models/lattice.js
@@ -150,10 +150,14 @@ Lattice = Backbone.Model.extend({
         return {x:pos1.x+pos2.x, y:pos1.y+pos2.y, z:pos1.z+pos2.z};
     },
 
-    removeCell: function(object){
+    removeCellFromMesh: function(object){
 
         if (!object) return;
-        var cell = object.parent.myCell;
+        this.removeCell(object.parent.myCell);
+
+    },
+
+    removeCell: function(cell){
         var index = this._subtract(cell.indices, this.get("cellsMin"));
         var cells = this.get("cells");
         cell.destroy();
diff --git a/js/threeViews/threeView.js b/js/threeViews/threeView.js
index 8146283b..2a2c35d7 100644
--- a/js/threeViews/threeView.js
+++ b/js/threeViews/threeView.js
@@ -212,7 +212,7 @@ ThreeView = Backbone.View.extend({
             this.lattice.addCell(this.highlighter.geometry.vertices[0]);
         } else {
             if (this.currentIntersectedCell === this.basePlane) return;
-            this.lattice.removeCell(this.currentIntersectedCell);
+            this.lattice.removeCellFromMesh(this.currentIntersectedCell);
         }
         this._hideHighlighter();
     },
-- 
GitLab