From c38219c8fd96c564453cdc9cdc3850bf427fd5f8 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Tue, 23 Jun 2015 11:09:59 -0700
Subject: [PATCH] moving lattice methods around

---
 js/lattice/Lattice.js                         | 139 ------------------
 js/lattice/LatticeCAM.js                      |  90 ++++++++++++
 js/lattice/LatticeImportGeo.js                |  63 ++++++++
 .../{ => latticeSubclasses}/CubeLattice.js    |   0
 .../{ => latticeSubclasses}/GIKLattice.js     |   0
 .../{ => latticeSubclasses}/KelvinLattice.js  |   0
 .../OctaEdgeLattice.js                        |   0
 .../OctaFaceLattice.js                        |   0
 .../OctaRotEdgeLattice.js                     |   0
 .../OctaVertexLattice.js                      |   0
 .../TetraStackedLattice.js                    |   0
 .../TetraVertexLattice.js                     |   0
 .../TruncatedCubeLattice.js                   |   0
 js/main.js                                    |  26 ++--
 14 files changed, 168 insertions(+), 150 deletions(-)
 create mode 100644 js/lattice/LatticeCAM.js
 create mode 100644 js/lattice/LatticeImportGeo.js
 rename js/lattice/{ => latticeSubclasses}/CubeLattice.js (100%)
 rename js/lattice/{ => latticeSubclasses}/GIKLattice.js (100%)
 rename js/lattice/{ => latticeSubclasses}/KelvinLattice.js (100%)
 rename js/lattice/{ => latticeSubclasses}/OctaEdgeLattice.js (100%)
 rename js/lattice/{ => latticeSubclasses}/OctaFaceLattice.js (100%)
 rename js/lattice/{ => latticeSubclasses}/OctaRotEdgeLattice.js (100%)
 rename js/lattice/{ => latticeSubclasses}/OctaVertexLattice.js (100%)
 rename js/lattice/{ => latticeSubclasses}/TetraStackedLattice.js (100%)
 rename js/lattice/{ => latticeSubclasses}/TetraVertexLattice.js (100%)
 rename js/lattice/{ => latticeSubclasses}/TruncatedCubeLattice.js (100%)

diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js
index d54511f9..2441a73f 100644
--- a/js/lattice/Lattice.js
+++ b/js/lattice/Lattice.js
@@ -103,13 +103,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
 
         //events
 
-        showCellAtIndex: function(index){
-            var latticeIndex = (new THREE.Vector3()).subVectors(index, this.get("cellsMin"));//index is probably a json object from gcode comment
-            var cell = this.cells[latticeIndex.x][latticeIndex.y][latticeIndex.z];
-            if (cell) cell.show();
-            else console.warn("placing a cell that does not exist");
-        },
-
         _updateCellSeparation: function(){
             var cellSep = this.get("cellSeparation");
             globals.basePlane.updateXYSeparation(cellSep.xy);
@@ -153,61 +146,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
 
 
 
-        //fill geometry
-
-        subtractMesh: function(mesh){
-            //todo this is specific to octa face
-
-            var xScale = this.xScale();
-            var yScale = this.yScale();
-            var zScale = this.zScale();
-
-            var cells = this.cells;
-            var cellsMin = this.get("cellsMin");
-
-            var allVertexPos = mesh.geometry.attributes.position.array;
-
-            var zHeight = 0;
-            for (var x=0;x<cells.length;x++){
-                for (var y=0;y<cells[0].length;y++){
-                    var firstCell = null;
-                    for (var z=0;z<cells[0][0].length;z++){
-                        firstCell = cells[x][y][z];
-                        if (firstCell) break;
-                    }
-                    if (!firstCell) continue;//nothing in col
-
-                    var origin = this._positionForIndex(firstCell.indices);
-    //                    firstCell._calcPosition(0, this._add({x:x,y:y,z:z}, cellsMin));
-                    zHeight = this._findIntersectionsInWindow(xScale/2, yScale/2, origin, allVertexPos) || zHeight;
-
-                    zHeight = Math.floor(zHeight/zScale);
-                    for (var z=0;z<zHeight;z++){
-                        var cell = cells[x][y][z];
-                        if (cell) cell.destroy();
-                        cells[x][y][z] = null;
-                    }
-                }
-
-            }
-            three.render();
-        },
-
-        _findIntersectionsInWindow: function(windowX, windowY, origin, allVertexPos){
-            for (var i=0;i<allVertexPos.length;i+=3){
-                if (allVertexPos[i] > origin.x-windowX && allVertexPos[i] < origin.x+windowX
-                    && allVertexPos[i+1] > origin.y-windowY && allVertexPos[i+1] < origin.y+windowY){
-                    return allVertexPos[i+2];
-                }
-            }
-            return null
-        },
-
-
-
-
-
-
 
         //composite Cells
 
@@ -261,83 +199,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
         getUItarget: function(){
             if (this.inCompositeMode()) return this.compositeEditor;
             return this;
-        },
-
-
-
-
-
-
-
-        //utils
-
-        rasterCells: function(order, callback, var1, var2, var3, cells){//used for CAM raster x/y/z in any order permutation
-            //order is of form 'XYZ'
-            var firstLetter = order.charAt(0);
-            order = order.substr(1);
-            var isNeg = false;
-            if (firstLetter == "-") {
-                isNeg = true;
-                firstLetter = order.charAt(0);
-                order = order.substr(1);
-            }
-            if (!cells) cells = this.cells;//grab cells once at beginning and hold onto it in case changes are made while looping
-            var newVarOrder;
-            var newVarDim;
-            if (firstLetter == 'X'){
-                newVarOrder = 0;
-                newVarDim = cells.length;
-            } else if (firstLetter == 'Y'){
-                newVarOrder = 1;
-                newVarDim = cells[0].length;
-            } else if (firstLetter == 'Z'){
-                newVarOrder = 2;
-                newVarDim = cells[0][0].length;
-            } else if (firstLetter == ""){
-                this._rasterCells(order, callback, var1, var2, var3, cells);
-                return;
-            }
-            if (var3 == null) var3 = {order: newVarOrder, dim: newVarDim, neg:isNeg};
-            else if (var2  == null) var2 = {order: newVarOrder, dim: newVarDim, neg:isNeg};
-            else var1 = {order: newVarOrder, dim: newVarDim, neg:isNeg};
-            this.rasterCells(order, callback, var1, var2, var3, cells);
-        },
-
-        _rasterCells: function(order, callback, var1, var2, var3, cells){
-            for (var i=this._getRasterLoopInit(var1);this._getRasterLoopCondition(i,var1);i+=this._getRasterLoopIterator(var1)){
-                for (var j=this._getRasterLoopInit(var2);this._getRasterLoopCondition(j,var2);j+=this._getRasterLoopIterator(var2)){
-                    for (var k=this._getRasterLoopInit(var3);this._getRasterLoopCondition(k,var3);k+=this._getRasterLoopIterator(var3)){
-                        if (var1.order == 0){
-                            if (var2.order == 1) callback(cells[i][j][k], i, j, k);
-                            else if (var2.order == 2) callback(cells[i][k][j], i, k, j);
-                        } else if (var1.order == 1){
-                            if (var2.order == 0) callback(cells[j][i][k], j, i, k);
-                            else if (var2.order == 2) callback(cells[k][i][j], k, i, j);
-                        } else {
-                            if (var2.order == 0) callback(cells[j][k][i], j, k, i);
-                            else if (var2.order == 1) {
-                                callback(cells[k][j][i], k, j, i);
-                            }
-                        }
-
-                    }
-                }
-            }
-        },
-
-        _getRasterLoopInit: function(variable){
-            if (variable.neg) return variable.dim-1;
-            return 0;
-        },
-
-        _getRasterLoopCondition: function(iter, variable){
-            if (variable.neg) return iter>=0;
-            return iter<variable.dim;
-        },
-
-        _getRasterLoopIterator: function(variable){
-            if (variable.neg) return -1;
-            return 1;
         }
     });
 
diff --git a/js/lattice/LatticeCAM.js b/js/lattice/LatticeCAM.js
new file mode 100644
index 00000000..bc7a87f8
--- /dev/null
+++ b/js/lattice/LatticeCAM.js
@@ -0,0 +1,90 @@
+/**
+ * Created by aghassaei on 6/23/15.
+ */
+
+
+define(['lattice', 'three'], function(lattice, THREE){
+
+    var camMethods = {
+
+        showCellAtIndex: function(index){
+            var latticeIndex = (new THREE.Vector3()).subVectors(index, this.get("cellsMin"));//index is probably a json object from gcode comment
+            var cell = this.cells[latticeIndex.x][latticeIndex.y][latticeIndex.z];
+            if (cell) cell.show();
+            else console.warn("placing a cell that does not exist");
+        },
+
+        rasterCells: function(order, callback, var1, var2, var3, cells){//used for CAM raster x/y/z in any order permutation
+            //order is of form 'XYZ'
+            var firstLetter = order.charAt(0);
+            order = order.substr(1);
+            var isNeg = false;
+            if (firstLetter == "-") {
+                isNeg = true;
+                firstLetter = order.charAt(0);
+                order = order.substr(1);
+            }
+            if (!cells) cells = this.cells;//grab cells once at beginning and hold onto it in case changes are made while looping
+            var newVarOrder;
+            var newVarDim;
+            if (firstLetter == 'X'){
+                newVarOrder = 0;
+                newVarDim = cells.length;
+            } else if (firstLetter == 'Y'){
+                newVarOrder = 1;
+                newVarDim = cells[0].length;
+            } else if (firstLetter == 'Z'){
+                newVarOrder = 2;
+                newVarDim = cells[0][0].length;
+            } else if (firstLetter == ""){
+                this._rasterCells(order, callback, var1, var2, var3, cells);
+                return;
+            }
+            if (var3 == null) var3 = {order: newVarOrder, dim: newVarDim, neg:isNeg};
+            else if (var2  == null) var2 = {order: newVarOrder, dim: newVarDim, neg:isNeg};
+            else var1 = {order: newVarOrder, dim: newVarDim, neg:isNeg};
+            this.rasterCells(order, callback, var1, var2, var3, cells);
+        },
+
+        _rasterCells: function(order, callback, var1, var2, var3, cells){
+            for (var i=this._getRasterLoopInit(var1);this._getRasterLoopCondition(i,var1);i+=this._getRasterLoopIterator(var1)){
+                for (var j=this._getRasterLoopInit(var2);this._getRasterLoopCondition(j,var2);j+=this._getRasterLoopIterator(var2)){
+                    for (var k=this._getRasterLoopInit(var3);this._getRasterLoopCondition(k,var3);k+=this._getRasterLoopIterator(var3)){
+                        if (var1.order == 0){
+                            if (var2.order == 1) callback(cells[i][j][k], i, j, k);
+                            else if (var2.order == 2) callback(cells[i][k][j], i, k, j);
+                        } else if (var1.order == 1){
+                            if (var2.order == 0) callback(cells[j][i][k], j, i, k);
+                            else if (var2.order == 2) callback(cells[k][i][j], k, i, j);
+                        } else {
+                            if (var2.order == 0) callback(cells[j][k][i], j, k, i);
+                            else if (var2.order == 1) {
+                                callback(cells[k][j][i], k, j, i);
+                            }
+                        }
+
+                    }
+                }
+            }
+        },
+
+        _getRasterLoopInit: function(variable){
+            if (variable.neg) return variable.dim-1;
+            return 0;
+        },
+
+        _getRasterLoopCondition: function(iter, variable){
+            if (variable.neg) return iter>=0;
+            return iter<variable.dim;
+        },
+
+        _getRasterLoopIterator: function(variable){
+            if (variable.neg) return -1;
+            return 1;
+        }
+    };
+
+    _.extend(lattice, camMethods);
+
+    return lattice;
+});
\ No newline at end of file
diff --git a/js/lattice/LatticeImportGeo.js b/js/lattice/LatticeImportGeo.js
new file mode 100644
index 00000000..c11f9d10
--- /dev/null
+++ b/js/lattice/LatticeImportGeo.js
@@ -0,0 +1,63 @@
+/**
+ * Created by aghassaei on 6/23/15.
+ */
+
+define(['lattice', 'threeModel'], function(lattice, three){
+
+    var importGeometryMethods = {
+
+        //fill geometry
+
+        subtractMesh: function(mesh){
+            //todo this is specific to octa face
+
+            var xScale = this.xScale();
+            var yScale = this.yScale();
+            var zScale = this.zScale();
+
+            var cells = this.cells;
+            var cellsMin = this.get("cellsMin");
+
+            var allVertexPos = mesh.geometry.attributes.position.array;
+
+            var zHeight = 0;
+            for (var x=0;x<cells.length;x++){
+                for (var y=0;y<cells[0].length;y++){
+                    var firstCell = null;
+                    for (var z=0;z<cells[0][0].length;z++){
+                        firstCell = cells[x][y][z];
+                        if (firstCell) break;
+                    }
+                    if (!firstCell) continue;//nothing in col
+
+                    var origin = this._positionForIndex(firstCell.indices);
+    //                    firstCell._calcPosition(0, this._add({x:x,y:y,z:z}, cellsMin));
+                    zHeight = this._findIntersectionsInWindow(xScale/2, yScale/2, origin, allVertexPos) || zHeight;
+
+                    zHeight = Math.floor(zHeight/zScale);
+                    for (var z=0;z<zHeight;z++){
+                        var cell = cells[x][y][z];
+                        if (cell) cell.destroy();
+                        cells[x][y][z] = null;
+                    }
+                }
+
+            }
+            three.render();
+        },
+
+        _findIntersectionsInWindow: function(windowX, windowY, origin, allVertexPos){
+            for (var i=0;i<allVertexPos.length;i+=3){
+                if (allVertexPos[i] > origin.x-windowX && allVertexPos[i] < origin.x+windowX
+                    && allVertexPos[i+1] > origin.y-windowY && allVertexPos[i+1] < origin.y+windowY){
+                    return allVertexPos[i+2];
+                }
+            }
+            return null
+        }
+    };
+
+    _.extend(lattice, importGeometryMethods);
+
+    return lattice;
+});
\ No newline at end of file
diff --git a/js/lattice/CubeLattice.js b/js/lattice/latticeSubclasses/CubeLattice.js
similarity index 100%
rename from js/lattice/CubeLattice.js
rename to js/lattice/latticeSubclasses/CubeLattice.js
diff --git a/js/lattice/GIKLattice.js b/js/lattice/latticeSubclasses/GIKLattice.js
similarity index 100%
rename from js/lattice/GIKLattice.js
rename to js/lattice/latticeSubclasses/GIKLattice.js
diff --git a/js/lattice/KelvinLattice.js b/js/lattice/latticeSubclasses/KelvinLattice.js
similarity index 100%
rename from js/lattice/KelvinLattice.js
rename to js/lattice/latticeSubclasses/KelvinLattice.js
diff --git a/js/lattice/OctaEdgeLattice.js b/js/lattice/latticeSubclasses/OctaEdgeLattice.js
similarity index 100%
rename from js/lattice/OctaEdgeLattice.js
rename to js/lattice/latticeSubclasses/OctaEdgeLattice.js
diff --git a/js/lattice/OctaFaceLattice.js b/js/lattice/latticeSubclasses/OctaFaceLattice.js
similarity index 100%
rename from js/lattice/OctaFaceLattice.js
rename to js/lattice/latticeSubclasses/OctaFaceLattice.js
diff --git a/js/lattice/OctaRotEdgeLattice.js b/js/lattice/latticeSubclasses/OctaRotEdgeLattice.js
similarity index 100%
rename from js/lattice/OctaRotEdgeLattice.js
rename to js/lattice/latticeSubclasses/OctaRotEdgeLattice.js
diff --git a/js/lattice/OctaVertexLattice.js b/js/lattice/latticeSubclasses/OctaVertexLattice.js
similarity index 100%
rename from js/lattice/OctaVertexLattice.js
rename to js/lattice/latticeSubclasses/OctaVertexLattice.js
diff --git a/js/lattice/TetraStackedLattice.js b/js/lattice/latticeSubclasses/TetraStackedLattice.js
similarity index 100%
rename from js/lattice/TetraStackedLattice.js
rename to js/lattice/latticeSubclasses/TetraStackedLattice.js
diff --git a/js/lattice/TetraVertexLattice.js b/js/lattice/latticeSubclasses/TetraVertexLattice.js
similarity index 100%
rename from js/lattice/TetraVertexLattice.js
rename to js/lattice/latticeSubclasses/TetraVertexLattice.js
diff --git a/js/lattice/TruncatedCubeLattice.js b/js/lattice/latticeSubclasses/TruncatedCubeLattice.js
similarity index 100%
rename from js/lattice/TruncatedCubeLattice.js
rename to js/lattice/latticeSubclasses/TruncatedCubeLattice.js
diff --git a/js/main.js b/js/main.js
index 72d3e5f5..422badae 100644
--- a/js/main.js
+++ b/js/main.js
@@ -31,20 +31,24 @@ require.config({
         socketio: '../dependencies/socket.io-1.3.5',
         serialComm: 'models/SerialComm',
 
-        //lattice
+        //lattice classes and extra methods
         latticeBase: 'lattice/LatticeBase',
         lattice: 'lattice/Lattice',
-        cubeLattice: 'lattice/CubeLattice',
-        gikLattice: 'lattice/GIKLattice',
-        kelvinLattice: 'lattice/KelvinLattice',
-        octaEdgeLattice: 'lattice/OctaEdgeLattice',
-        octaFaceLattice: 'lattice/OctaFaceLattice',
-        octaRotEdgeLattice: 'lattice/OctaRotEdgeLattice',
-        octaVertexLattice: 'lattice/OctaVertexLattice',
-        truncatedCubeLattice: 'lattice/TruncatedCubeLattice',
-        tetraStackedLattice: 'lattice/TetraStackedLattice',
-        tetraVertexLattice: 'lattice/TetraVertexLattice',
         compositeEditorLattice: 'lattice/CompositeEditorLattice',
+        latticeImportGeo: 'lattice/ImportGeo',
+        latticeCAM: 'lattice/latticeCAM',
+
+        //lattice "subclasses"
+        cubeLattice: 'lattice/latticeSubclasses/CubeLattice',
+        gikLattice: 'lattice/latticeSubclasses/GIKLattice',
+        kelvinLattice: 'lattice/latticeSubclasses/KelvinLattice',
+        octaEdgeLattice: 'lattice/latticeSubclasses/OctaEdgeLattice',
+        octaFaceLattice: 'lattice/latticeSubclasses/OctaFaceLattice',
+        octaRotEdgeLattice: 'lattice/latticeSubclasses/OctaRotEdgeLattice',
+        octaVertexLattice: 'lattice/latticeSubclasses/OctaVertexLattice',
+        truncatedCubeLattice: 'lattice/latticeSubclasses/TruncatedCubeLattice',
+        tetraStackedLattice: 'lattice/latticeSubclasses/TetraStackedLattice',
+        tetraVertexLattice: 'lattice/latticeSubclasses/TetraVertexLattice',
 
         //baseplane
         baseplane: 'baseplane/BasePlane',
-- 
GitLab