From ba8edd5104f10b5c91830895296d4d3f44041efd Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Fri, 19 Jun 2015 17:45:37 -0700
Subject: [PATCH] taking a break

---
 js/cells/DMACell.js                 |  2 +-
 js/cells/supercells/DMASuperCell.js | 17 +++++++++++------
 js/cells/supercells/GIKSuperCell.js | 24 ++++++++++++++++--------
 js/lattice/LatticeBase.js           |  3 ---
 4 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js
index 2f0d6f2a..e33f40b5 100644
--- a/js/cells/DMACell.js
+++ b/js/cells/DMACell.js
@@ -373,7 +373,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
 
     DMACell.prototype.toJSON = function(){
         var data = {
-            material: this.materialName
+            materialName: this.materialName
         };
         if (materials[this.materialName].cells) return data;//material definition in material composites
         if (this.cells) data.cells = this.cells;
diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js
index 1dfaade0..ce374dfe 100644
--- a/js/cells/supercells/DMASuperCell.js
+++ b/js/cells/supercells/DMASuperCell.js
@@ -27,7 +27,6 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
     DMASuperCell.prototype = Object.create(DMACell.prototype);
 
     DMASuperCell.prototype._makeChildCells = function(range, material){
-        console.log(range);
         var cells = [];
         for (var x=0;x<range.x;x++){
             cells.push([]);
@@ -36,21 +35,21 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
                 for (var z=0;z<range.z;z++){
                     //child cells add themselves to object3D
 
-                    var cellMaterial = this.materialName;
+                    var cellMaterialName = this.materialName;
                     cells[x][y].push(null);
 
                     if (material.sparseCells){
                         if (material.sparseCells[x][y][z]){
-                            if (material.sparseCells[x][y][z].material) {
-                                cellMaterial = material.sparseCells[x][y][z].material;
-                                this._makeSubCellForIndex({index: new THREE.Vector3(x,y,z), material:cellMaterial}, function(cell){
+                            if (material.sparseCells[x][y][z].materialName) {
+                                cellMaterialName = material.sparseCells[x][y][z].materialName;
+                                this._makeSubCellForIndex({index: new THREE.Vector3(x,y,z), materialName:cellMaterialName}, function(cell){
                                     var index = cell.getIndex();
                                     cells[index.x][index.y][index.z] = cell;
                                 });
                             } else console.warn("no material for composite cell definition subcell");
                         }//else no cell in this spot
                     } else {//if not from composite definition, add subcell at all possible indices in supercell range
-                        this._makeSubCellForIndex({index: new THREE.Vector3(x,y,z), material:cellMaterial}, function(cell){
+                        this._makeSubCellForIndex({index: new THREE.Vector3(x,y,z), materialName:cellMaterialName}, function(cell){
                             cells[x][y][z] = cell;
                         });
                     }
@@ -142,5 +141,11 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
         });
     };
 
+    DMASuperCell.prototype.toJSON = function(){
+        var data = DMACell.prototype.toJSON.call(this);
+        if (this.cells) data.cells = this.cells;
+        return data;
+    };
+
     return DMASuperCell;
 });
\ No newline at end of file
diff --git a/js/cells/supercells/GIKSuperCell.js b/js/cells/supercells/GIKSuperCell.js
index dd6d54f4..c4520d2c 100644
--- a/js/cells/supercells/GIKSuperCell.js
+++ b/js/cells/supercells/GIKSuperCell.js
@@ -41,18 +41,22 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell',
 
     GIKSuperCell.prototype.getMaterial = function(returnTHREEObject){
         if (returnTHREEObject){
-            return DMASuperCell.prototype.getMaterial.call(this, returnTHREEObject);
+            return materials[this.materialName].threeMaterial
         }
-        var length = this.getLength();
-        var name = this.materialName + "length" + (length+1);
-        if (!gikMaterials[name]) {
-            gikMaterials[name] = {
+        var name = this._makeMaterialKey();
+        if (!gikMaterials[this.materialName]) gikMaterials[this.materialName] = {};
+        if (!gikMaterials[this.materialName][name]) {
+            gikMaterials[this.materialName][name] = {
                 materialName: this.materialName,
-                dimensions: new THREE.Vector3(length+1, 1, 1),
-                threeMaterial: materials[this.materialName].threeMaterial
+                dimensions: new THREE.Vector3(length+1, 1, 1)
             };
         }
-        return gikMaterials[name];
+        return gikMaterials[this.materialName][name];
+    };
+
+    GIKSuperCell.prototype._makeMaterialKey = function(){
+        var length = this.getLength();
+        return "length" + (length+1);
     };
 
     GIKSuperCell.prototype._buildWireframe = function(mesh){
@@ -67,5 +71,9 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell',
         return "cell";
     };
 
+    GIKSuperCell.prototype.toJSON = function(){
+        return gikMaterials[this.materialName][this._makeMaterialKey()];
+    };
+
     return GIKSuperCell;
 });
\ No newline at end of file
diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js
index f4d40a86..9879f6bb 100644
--- a/js/lattice/LatticeBase.js
+++ b/js/lattice/LatticeBase.js
@@ -199,9 +199,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
                     if (material.dimensions){
                         var subCellMax = (new THREE.Vector3(x, y, z)).add(material.dimensions);
                         dimVector.max(subCellMax);
-                    } else if (cell.getLength){
-                        var subCellMax = (new THREE.Vector3(x, y, z)).add(new THREE.Vector3(cell.getLength()+1, 1, 1));
-                        dimVector.max(subCellMax);
                     }
                 }
             });
-- 
GitLab