From c2fe273ef2fa57a056a22e92009a04adc6bfd146 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Tue, 30 Jun 2015 19:37:50 -0700
Subject: [PATCH] only check from brass conductors

---
 js/cells/DMACell.js                    |  4 ++++
 js/lattice/Lattice.js                  |  3 +++
 js/lattice/LatticeEsim.js              | 10 +++++-----
 js/menus/templates/ESetupMenuView.html |  6 +++++-
 js/simulation/electronics/eSimCell.js  | 14 ++++++++------
 5 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js
index e5ebfb45..14eecd55 100644
--- a/js/cells/DMACell.js
+++ b/js/cells/DMACell.js
@@ -218,6 +218,10 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
         this.setMode(mode);
     };
 
+    DMACell.prototype.getMaterialName = function(){
+        return this.materialName;
+    };
+
     DMACell.prototype.getMaterial = function(returnTHREEObject){
         if (!this.materialName) {
             console.warn("no material type set for cell");
diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js
index a8daf390..958e984c 100644
--- a/js/lattice/Lattice.js
+++ b/js/lattice/Lattice.js
@@ -16,6 +16,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             connectionType: "face",
             partType: null,
 
+            denseCellsMin: null,
+
             nodes: [],
 
             cellSeparation: {xy:0, z:0}//spacing for connectors/joints
@@ -140,6 +142,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             }
 
             var bounds = this.calculateBoundingBox();
+            this.set("denseCellsMin", bounds.min.clone().add(this.get("cellsMin")));
             var size = bounds.max.sub(bounds.min);
 
             //create array of nulls
diff --git a/js/lattice/LatticeEsim.js b/js/lattice/LatticeEsim.js
index 66ed1caa..04e21b59 100644
--- a/js/lattice/LatticeEsim.js
+++ b/js/lattice/LatticeEsim.js
@@ -9,7 +9,7 @@ define(['lattice', 'eSim', 'eSimCell'], function(lattice, eSim){
         calculateConnectivity: function(){
             var num = 1;
             this._loopCells(this.cells, function(cell){
-                if (cell) cell.setConnectivityGroupNum(num++, true);
+                if (cell) cell.setConnectivityGroupNum(num++);
             });
             this._loopCells(this.cells, function(cell){
                 if (cell) cell.propagateConnectivityGroupNum();
@@ -18,16 +18,16 @@ define(['lattice', 'eSim', 'eSimCell'], function(lattice, eSim){
         },
 
         _calcNumberConnectedComponents: function(){
-            var groups = [];
+            var groups = {};
             this._loopCells(this.cells, function(cell){
                 if (!cell) return;
-                if (groups.indexOf(cell.getConnectivityGroupNum())<0) groups.push(cell.getConnectivityGroupNum());
+                if (!groups[cell.getConnectivityGroupNum()] && cell.getMaterialName() == "brass") groups[cell.getConnectivityGroupNum()] = cell.getMaterialName();
             });
-            eSim.set("numConnectedComponents", groups.length);
+            eSim.set("numConnectedComponents", _.keys(groups).length);
         },
 
         propagateToNeighbors: function(index, callback){
-            index.sub(this.get("cellsMin"));//todo wrong
+            index.sub(this.get("denseCellsMin"));
             var xLength = this.cells.length;
             var yLength = this.cells[0].length;
             var zLength = this.cells[0][0].length;
diff --git a/js/menus/templates/ESetupMenuView.html b/js/menus/templates/ESetupMenuView.html
index a6bd5cb1..e1607e72 100644
--- a/js/menus/templates/ESetupMenuView.html
+++ b/js/menus/templates/ESetupMenuView.html
@@ -8,4 +8,8 @@ Simulation Type: &nbsp;&nbsp;
         </ul>
     </div><br/><br/>
 <a href="#" id="calcConnectivity" class="btn btn-block btn-lg btn-default">Calculate Connectivity</a><br/>
-<% if(numConnectedComponents){ %>Num Connected Components: &nbsp;&nbsp<%= numConnectedComponents %> <% } %>
\ No newline at end of file
+<% if(numConnectedComponents){ %>Num Connected Conductors: &nbsp;&nbsp<%= numConnectedComponents %><br/><br/>
+Show Conductors:
+
+
+<% } %>
\ No newline at end of file
diff --git a/js/simulation/electronics/eSimCell.js b/js/simulation/electronics/eSimCell.js
index 58527050..90fb49e2 100644
--- a/js/simulation/electronics/eSimCell.js
+++ b/js/simulation/electronics/eSimCell.js
@@ -5,11 +5,11 @@
 //assume latticeESim has loaded?
 define(['cell', 'lattice'], function(DMACell, lattice){
 
-    DMACell.prototype.setConnectivityGroupNum = function(num, force){
-        if (force) this._eSimConnectivityGroup = num;
+    DMACell.prototype.setConnectivityGroupNum = function(num, materialName){
+        if (!materialName) this._eSimConnectivityGroup = num;
         else if (this._eSimConnectivityGroup>num){
             this._eSimConnectivityGroup = num;
-            this.propagateConnectivityGroupNum(num);
+            this.propagateConnectivityGroupNum(num, materialName);
         }
     };
 
@@ -17,10 +17,12 @@ define(['cell', 'lattice'], function(DMACell, lattice){
         return this._eSimConnectivityGroup;
     };
 
-    DMACell.prototype.propagateConnectivityGroupNum = function(num){
-        if (num===undefined) num = this._eSimConnectivityGroup;
+    DMACell.prototype.propagateConnectivityGroupNum = function(num, materialName){
+        if (materialName === undefined) materialName = this.materialName;
+        if (materialName != "brass") return;
+        if (num === undefined) num = this._eSimConnectivityGroup;
         lattice.propagateToNeighbors(this.getAbsoluteIndex(), function(neighbor){
-            if (neighbor) neighbor.setConnectivityGroupNum(num);
+            if (neighbor) neighbor.setConnectivityGroupNum(num, materialName);
         });
     };
 
-- 
GitLab