From 3701619d2558b97c6b36091f3ce08a6b81a78c20 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Wed, 1 Jul 2015 09:19:58 -0700
Subject: [PATCH] show conductors

---
 js/cells/DMACell.js                 | 16 +++++++++++++++-
 js/cells/supercells/DMASuperCell.js |  7 +++++++
 js/lattice/LatticeBase.js           |  9 +++++++++
 js/lattice/LatticeEsim.js           | 29 +++++++++++++++++++++++++++--
 js/materials/DMAMaterials.js        |  7 +++++--
 5 files changed, 63 insertions(+), 5 deletions(-)

diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js
index 44d2d8c8..9412ea32 100644
--- a/js/cells/DMACell.js
+++ b/js/cells/DMACell.js
@@ -245,10 +245,16 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
         this.object3D.children[0].material = material;
     };
 
-    DMACell.prototype.setTransparent = function(transparent){
+    DMACell.prototype.setWireframeVisibility = function(visible){
+        this.object3D.children[1].visible = visible;
+    };
+
+    DMACell.prototype.setTransparent = function(evalFunction){
+        var transparent = evalFunction(this);
         if (transparent == this.isTransparent) return;
         this.isTransparent = transparent;
         this.setMaterial(this.getMaterial(true));
+        this.setWireframeVisibility(!this.isTransparent);
     };
 
     DMACell.prototype.setMode = function(mode, callback){
@@ -293,6 +299,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
             var visible = true;
             if (mode == "supercell") visible = !self._isMiddleLayer();//middle layers are always hidden in supercell mode
 
+            self.setWireframeVisibility(!self.isTransparent);
+
             _.each(self.object3D.children, function(child){
                 if (child.name == "object3D") return;
                 child.visible = visible && (child.name == mode);
@@ -400,6 +408,12 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
         cellsArray[index.x][index.y][index.z] = this;
     };
 
+    DMACell.prototype.removeFromDenseArray = function(cellsArray, min){
+        var index = this.getAbsoluteIndex().sub(min);
+        cellsArray[index.x][index.y][index.z] = null;
+    };
+
+
 
 
 
diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js
index 72af56be..c8c96f9e 100644
--- a/js/cells/supercells/DMASuperCell.js
+++ b/js/cells/supercells/DMASuperCell.js
@@ -105,6 +105,13 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
         return false;
     };
 
+    DMASuperCell.prototype.setTransparent = function(evalFunction){
+        DMACell.prototype.setTransparent.call(this, evalFunction);
+        this._loopCells(function(cell){
+            if (cell) cell.setTransparent(evalFunction);
+        })
+    };
+
 
 
 
diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js
index c0976ea0..6f8d43dd 100644
--- a/js/lattice/LatticeBase.js
+++ b/js/lattice/LatticeBase.js
@@ -461,6 +461,15 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             three.render();
         },
 
+        setOpaque: function(){
+            this._loopCells(this.sparseCells, function(cell){
+                if (cell) cell.setTransparent(function(){
+                    return false;
+                });
+            });
+            three.render();
+        },
+
 
 
 
diff --git a/js/lattice/LatticeEsim.js b/js/lattice/LatticeEsim.js
index 438e4042..08a6ebef 100644
--- a/js/lattice/LatticeEsim.js
+++ b/js/lattice/LatticeEsim.js
@@ -2,10 +2,31 @@
  * Created by aghassaei on 6/30/15.
  */
 
-define(['lattice', 'eSim', 'eSimCell'], function(lattice, eSim){
+define(['lattice', 'appState', 'threeModel', 'eSim', 'eSimCell'], function(lattice, appState, three, eSim){
+
+
 
     var eSimMethods = {
 
+        _eSimTabChanged: function(){
+            var currentTab = appState.get("currentTab");
+            if (currentTab == "eSetup") this._showConductors();
+            else this.setOpaque();
+        },
+
+        _showConductors: function(){
+            var groupNum = eSim.get("visibleConductorGroup");
+            console.log(eSim.get("conductorGroups"));
+            console.log(groupNum);
+            var allVisible = groupNum < 0;
+            this._loopCells(this.sparseCells, function(cell){
+                if (cell) cell.setTransparent(function(evalCell){
+                    return !evalCell.isConductive() || (!allVisible && groupNum != evalCell.getConductorGroupNum())
+                });
+            });
+            three.render();
+        },
+
         calculateConductorConnectivity: function(){
             var num = 1;
             this._loopCells(this.cells, function(cell){
@@ -23,7 +44,7 @@ define(['lattice', 'eSim', 'eSimCell'], function(lattice, eSim){
                 if (!cell) return;
                 if (groups.indexOf(cell.getConductorGroupNum()) < 0 && cell.isConductive()) groups.push(cell.getConductorGroupNum());
             });
-            eSim.set("conductorGroups", _.keys(groups));
+            eSim.set("conductorGroups", groups);
         },
 
         propagateToNeighbors: function(index, callback){
@@ -42,5 +63,9 @@ define(['lattice', 'eSim', 'eSimCell'], function(lattice, eSim){
     };
 
     _.extend(lattice, eSimMethods);
+    lattice.listenTo(appState, "change:currentTab", lattice._eSimTabChanged);
+    lattice.listenTo(eSim, "change:visibleConductorGroup", lattice._showConductors);
+
+
     return lattice;
 });
diff --git a/js/materials/DMAMaterials.js b/js/materials/DMAMaterials.js
index 71fd2f01..f075689b 100644
--- a/js/materials/DMAMaterials.js
+++ b/js/materials/DMAMaterials.js
@@ -8,7 +8,7 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu
     var materialsList = {
         deleteMaterial: {
             color: "#ff0000",
-            threeMaterial:new THREE.MeshLambertMaterial({color:"#ff0000", shading:THREE.FlatShading})
+            threeMaterial: makeMaterialObject("#ff0000")
         }
     };
 
@@ -155,6 +155,7 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu
             newMaterials[key] = definitions[key];
             var color = getMaterialColorForState(state, definitions[key], key);
             newMaterials[key].threeMaterial = makeMaterialObject(color);
+            newMaterials[key].transparentMaterial = makeMaterialObject(color, true);
             newMaterials[key].noDelete = true;//don't delete the predefined materials
         });
         return newMaterials;
@@ -181,8 +182,10 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu
         if (!state) state = appState.get("realisticColorScheme");
         var materialInfo = materialsList[name];
         var color = getMaterialColorForState(state, materialInfo, name);
+
         if (materialInfo.threeMaterial) materialInfo.threeMaterial.color = new THREE.Color(color);
         else materialInfo.threeMaterial = makeMaterialObject(color);
+
         if (materialInfo.transparentMaterial) materialInfo.transparentMaterial.color = new THREE.Color(color);
         else materialInfo.transparentMaterial = makeMaterialObject(color, true);
     }
@@ -195,7 +198,7 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu
     }
 
     function makeMaterialObject(color, transparent){
-        if (transparent) return new THREE.MeshLambertMaterial({color:color, shading:THREE.FlatShading, transparent: true, opacity:0.4});
+        if (transparent) return new THREE.MeshLambertMaterial({color:color, shading:THREE.FlatShading, transparent: true, opacity:0.1});
         return new THREE.MeshLambertMaterial({color:color, shading:THREE.FlatShading});
     }
 
-- 
GitLab