From ccf0274e93430d87c9fbfe360532cf7120ddeb63 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Thu, 4 Jun 2015 16:07:15 -0700
Subject: [PATCH] preparing for a big refactor or cell classes

---
 js/cells/DMACell.js                 | 14 ++++++++++++--
 js/cells/supercells/DMASuperCell.js |  5 ++---
 js/models/AppState.js               |  2 +-
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js
index 46b20385..54cede47 100644
--- a/js/cells/DMACell.js
+++ b/js/cells/DMACell.js
@@ -12,7 +12,13 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'],
     function DMACell(index, superCell){
 
         this.index = new THREE.Vector3(index.x, index.y, index.z);
-        if (superCell) this.superCell = superCell;
+
+        if (superCell) {
+            this.superCell = superCell;
+        } else if (!this.cells){
+            //lowest level child
+            this.material = lattice.get("materialType");
+        }
 
         //object 3d is parent to all 3d elements related to cell, parts, beams, nodes, etc
         this.object3D = this._buildObject3D();
@@ -120,7 +126,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'],
     };
 
     DMACell.prototype.getMaterial = function(){
-        return cellMaterial;
+        return this.superCell.getMaterial();
     };
 
     DMACell.prototype.setOpacity = function(opacity){
@@ -140,6 +146,9 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'],
         if (mode === undefined) mode = appState.get("cellMode");
 
         switch(mode) {
+            case "supercell":
+                if (!this.superCell) mode = "cell";
+                break;
             case "cell":
                 break;
             case "part":
@@ -216,6 +225,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'],
     };
 
     DMACell.prototype.destroyParts = function(){
+        if (!this.parts) return;
         _.each(this.parts, function(part){
             if (part) part.destroy();
         });
diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js
index 386d4640..62e34f99 100644
--- a/js/cells/supercells/DMASuperCell.js
+++ b/js/cells/supercells/DMASuperCell.js
@@ -9,7 +9,6 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
 
     function DMASuperCell(index, superCell){//supercells might have supercells
 
-        this.material = lattice.get("materialType");//todo move to dmacell
         var range = lattice.get("superCellRange");
         this.cells = this._makeChildCells(index, range);//todo three dimensional array?
         DMACell.call(this, index, superCell);
@@ -51,8 +50,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
             cell.setMode(mode);
         });
 
-        if (mode == "cell") mode = "supercell";
-        if (mode == "part") mode = "object3D";
+        if (mode == "cell" || mode == "supercell") mode = "supercell";
+        else mode = "object3D";
 
         _.each(this.object3D.children, function(child){
             child.visible = child.name == mode;
diff --git a/js/models/AppState.js b/js/models/AppState.js
index a1593512..14566526 100644
--- a/js/models/AppState.js
+++ b/js/models/AppState.js
@@ -33,7 +33,7 @@ define(['underscore', 'backbone'], function(_, Backbone){
             deleteMode: false,
             highlightMode: true,
             extrudeMode: false,
-            cellMode: "cell",//show cells vs part
+            cellMode: "cell",//supercell, cell, part, node, beam
             cellsVisible: true,
 
             superCellIndex: 0,//offset of superCell adds todo lattice?
-- 
GitLab