From fae7ba558fed742ddba2212cf64ba7a8d5846849 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Mon, 8 Jun 2015 14:22:54 -0700
Subject: [PATCH] clear cells working, cells array expansion working

---
 js/cells/DMACell.js                |  1 -
 js/cells/OctaEdgeCell.js           |  4 ++++
 js/lattice/CubeLattice.js          |  1 -
 js/lattice/GIKLattice.js           |  1 -
 js/lattice/KelvinLattice.js        |  1 -
 js/lattice/Lattice.js              | 34 +++++++++++++++++++++---------
 js/lattice/OctaEdgeLattice.js      |  1 -
 js/lattice/OctaFaceLattice.js      |  1 -
 js/lattice/OctaRotEdgeLattice.js   |  1 -
 js/lattice/OctaVertexLattice.js    |  1 -
 js/lattice/TetraStackedLattice.js  |  1 -
 js/lattice/TetraVertexLattice.js   |  1 -
 js/lattice/TruncatedCubeLattice.js |  1 -
 js/models/PList.js                 |  2 +-
 14 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js
index 96ce95e9..c2d63513 100644
--- a/js/cells/DMACell.js
+++ b/js/cells/DMACell.js
@@ -217,7 +217,6 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'],
             console.warn("no material "+ this.material + " found for class "+ materialClass);
             return null;
         }
-        console.log(material.shading);
         return material;
     };
 
diff --git a/js/cells/OctaEdgeCell.js b/js/cells/OctaEdgeCell.js
index a81b11b7..689efe73 100644
--- a/js/cells/OctaEdgeCell.js
+++ b/js/cells/OctaEdgeCell.js
@@ -11,6 +11,10 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'octaFaceCel
     }
     OctaEdgeCell.prototype = Object.create(OctaFaceCell.prototype);
 
+    OctaFaceCell.prototype._rotateCell = function(object3D){
+        return object3D;
+    };
+
     OctaEdgeCell.prototype.calcHighlighterParams = function(face, point){
         var direction = face.normal.clone().applyQuaternion(this.getAbsoluteOrientation());
         var position = this.getAbsolutePosition();
diff --git a/js/lattice/CubeLattice.js b/js/lattice/CubeLattice.js
index 1fae3a4a..2853e6c4 100644
--- a/js/lattice/CubeLattice.js
+++ b/js/lattice/CubeLattice.js
@@ -42,7 +42,6 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
             require(['cubeCell'], function(CubeCell){
                 var cell = new CubeCell(indices);
                 if (callback) callback(cell);
-                return cell;
             });
         },
 
diff --git a/js/lattice/GIKLattice.js b/js/lattice/GIKLattice.js
index be5d8ff0..066c0375 100644
--- a/js/lattice/GIKLattice.js
+++ b/js/lattice/GIKLattice.js
@@ -43,7 +43,6 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
             require(['gikSuperCell'], function(GIKSuperCell){
                 var cell = new GIKSuperCell(indices);
                 if (callback) callback(cell);
-                return cell;
             });
         },
 
diff --git a/js/lattice/KelvinLattice.js b/js/lattice/KelvinLattice.js
index c67998c2..f84156ff 100644
--- a/js/lattice/KelvinLattice.js
+++ b/js/lattice/KelvinLattice.js
@@ -43,7 +43,6 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
             require(['kelvinCell'], function(KelvinCell){
                 var cell = new KelvinCell(indices);
                 if (callback) callback(cell);
-                return cell;
             });
         },
 
diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js
index b5cfd0f8..5728d63f 100644
--- a/js/lattice/Lattice.js
+++ b/js/lattice/Lattice.js
@@ -22,8 +22,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             //spacing for connectors/joints
             cellSeparation: {xy:0, z:0},
 
-            cellType: "tetra",
-            connectionType: "stacked",
+            cellType: "cube",
+            connectionType: "face",
             partType: null,
             materialType: null,
             materialClass: "mechanical",
@@ -68,7 +68,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
                     for (var z=relativeMin.z;z<=relativeMax.z;z++){
                         if (!this.sparseCells[x][y][z]) {
                             var self = this;
-                            this.sparseCells[x][y][z] = this.makeCellForLatticeType((new THREE.Vector3(x, y, z)).add(cellsMin), function(){
+                             this.makeCellForLatticeType((new THREE.Vector3(x, y, z)).add(cellsMin), function(cell){
+                                self.sparseCells[x][y][z] = cell;
                                 self.set("numCells", self.get("numCells")+1);
                             });
                         } else console.warn("already a cell there");
@@ -79,17 +80,21 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
         },
 
         addCellAtIndex: function(indices, noRender, noCheck){//no render no check from fill
+            console.log(indices);
 
+            console.log(this.get("cellsMin"));
+            console.log(this.get("cellsMax"));
             if (!noCheck || noCheck === undefined) this.checkForMatrixExpansion(this.sparseCells, indices, indices);
+            console.log(this.sparseCells);
 
             var index = (new THREE.Vector3()).subVectors(indices, this.get("cellsMin") || indices);
             if (!this.sparseCells[index.x][index.y][index.z]) {
                 var self = this;
-                var callback = function(){
+                this.makeCellForLatticeType(indices, function(cell){
+                    self.sparseCells[index.x][index.y][index.z] = cell;
                     self.set("numCells", self.get("numCells")+1);
                     if (!noRender || noRender === undefined) three.render();
-                };
-                this.sparseCells[index.x][index.y][index.z] = this.makeCellForLatticeType(indices, callback);
+                });
             } else console.warn("already a cell there");
 
         },
@@ -131,7 +136,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
         },
 
         clearCells: function(){
-            this._iterCells(this.sparseCells, function(cell){//send destroy to top level
+            this._loopCells(this.sparseCells, function(cell){//send destroy to top level
                 if (cell) cell.destroy();
             });
             three.removeAllCells();//todo add flag in cell destroy to avoid redundancy here
@@ -224,8 +229,15 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
                 return;
             }
 
-            var lastMax = this.get("cellsMax") || indicesMax;
-            var lastMin = this.get("cellsMin") || indicesMin;
+            if (!this.get("cellsMax") || !this.get("cellsMin")){
+                this.set("cellsMax", indicesMax);
+                this.set("cellsMin", indicesMin);
+                this._expandCellsArray(cells, (new THREE.Vector3()).subVectors(indicesMax, indicesMin), false);
+                return;
+            }
+
+            var lastMax = this.get("cellsMax");
+            var lastMin = this.get("cellsMin");
             var newMax = this._updateCellsMax(indicesMax, lastMax);
             var newMin = this._updateCellsMin(indicesMin, lastMin);
             if (newMax) {
@@ -417,7 +429,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
                     if (!cell) return;
                     var index = _.clone(cell.index);
                     if (cell.destroy) cell.destroy();
-                    cells[x][y][z] = self.makeCellForLatticeType(index);// parentPos, parentOrientation, direction, parentType, type)
+                    self.makeCellForLatticeType(index, function(newCell){
+                        cells[x][y][z] = newCell;
+                    });
                 });
                 three.render();
             });
diff --git a/js/lattice/OctaEdgeLattice.js b/js/lattice/OctaEdgeLattice.js
index 1a6f3d33..517ff6aa 100644
--- a/js/lattice/OctaEdgeLattice.js
+++ b/js/lattice/OctaEdgeLattice.js
@@ -65,7 +65,6 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
             require(['octaEdgeCell'], function(OctaEdgeCell){
                 var cell = new OctaEdgeCell(indices);
                 if (callback) callback(cell);
-                return cell;
             });
         },
 
diff --git a/js/lattice/OctaFaceLattice.js b/js/lattice/OctaFaceLattice.js
index 0927d3e6..2aa1d1fe 100644
--- a/js/lattice/OctaFaceLattice.js
+++ b/js/lattice/OctaFaceLattice.js
@@ -51,7 +51,6 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
             require(['octaFaceCell'], function(OctaFaceCell){
                 var cell = new OctaFaceCell(indices);
                 if (callback) callback(cell);
-                return cell;
             });
         },
 
diff --git a/js/lattice/OctaRotEdgeLattice.js b/js/lattice/OctaRotEdgeLattice.js
index 88ab171e..8fc717cb 100644
--- a/js/lattice/OctaRotEdgeLattice.js
+++ b/js/lattice/OctaRotEdgeLattice.js
@@ -53,7 +53,6 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
             require(['octaRotEdgeCell'], function(OctaRotEdgeCell){
                 var cell = new OctaRotEdgeCell(indices);
                 if (callback) callback(cell);
-                return cell;
             });
         },
 
diff --git a/js/lattice/OctaVertexLattice.js b/js/lattice/OctaVertexLattice.js
index 76764cb9..508c40e2 100644
--- a/js/lattice/OctaVertexLattice.js
+++ b/js/lattice/OctaVertexLattice.js
@@ -49,7 +49,6 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
             require(['octaVertexCell'], function(OctaVertexCell){
                 var cell = new OctaVertexCell(indices);
                 if (callback) callback(cell);
-                return cell;
             });
         },
 
diff --git a/js/lattice/TetraStackedLattice.js b/js/lattice/TetraStackedLattice.js
index 1bc435a0..4bea1a01 100644
--- a/js/lattice/TetraStackedLattice.js
+++ b/js/lattice/TetraStackedLattice.js
@@ -51,7 +51,6 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
             require(['tetraStackedCell'], function(TetraStackedCell){
                 var cell = new TetraStackedCell(indices);
                 if (callback) callback(cell);
-                return cell;
             });
         },
 
diff --git a/js/lattice/TetraVertexLattice.js b/js/lattice/TetraVertexLattice.js
index e04a7a83..09537f95 100644
--- a/js/lattice/TetraVertexLattice.js
+++ b/js/lattice/TetraVertexLattice.js
@@ -51,7 +51,6 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
             require(['tetraVertexCell'], function(TetraVertexCell){
                 var cell = new TetraVertexCell(indices);
                 if (callback) callback(cell);
-                return cell;
             });
         },
 
diff --git a/js/lattice/TruncatedCubeLattice.js b/js/lattice/TruncatedCubeLattice.js
index 7ba455af..2c8eaf4d 100644
--- a/js/lattice/TruncatedCubeLattice.js
+++ b/js/lattice/TruncatedCubeLattice.js
@@ -43,7 +43,6 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
             require(['truncatedCubeCell'], function(TruncatedCubeCell){
                 var cell = new TruncatedCubeCell(indices);
                 if (callback) callback(cell);
-                return cell;
             });
         },
 
diff --git a/js/models/PList.js b/js/models/PList.js
index 7a25f4d6..3323f103 100644
--- a/js/models/PList.js
+++ b/js/models/PList.js
@@ -36,7 +36,7 @@ define(['three'], function(THREE){
         },
         allConnectionTypes: {
             octa: {face:"Face", edge:"Edge", edgeRot:"Edge (Rotated)", vertex:"Vertex"},// freeformFace:"Freeform Face"
-            tetra: {stacked: "Stacked", vertex: "Vertex"},
+            tetra: {stacked: "Stacked"},//vertex: "Vertex"
             cube: {face:"Face", gik: "GIK"},
             truncatedCube: {face:"Face"},
             kelvin: {face: "Face"}
-- 
GitLab