From f5b9cd26483952d06069518afef68cc46a21e466 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Mon, 18 May 2015 21:58:45 -0400
Subject: [PATCH] working on gik hand of god

---
 js/cam/Machine.js            |  3 ++-
 js/fea/DMASuperCell.js       | 43 +++++++++++++++++++++++++++++++++---
 js/fea/DmaCell.js            |  1 +
 js/fea/DmaCellOther.js       |  8 ++++---
 js/models/AppState.js        |  9 ++++----
 js/models/LatticeOther.js    | 15 ++++++++++---
 js/threeViews/Highlighter.js |  2 +-
 7 files changed, 65 insertions(+), 16 deletions(-)

diff --git a/js/cam/Machine.js b/js/cam/Machine.js
index aa82f302..78bc3df9 100644
--- a/js/cam/Machine.js
+++ b/js/cam/Machine.js
@@ -68,6 +68,7 @@ Machine.prototype.setScale = function(scale){
 }
 
 Machine.prototype._makeStockCell = function(){
+    if (dmaGlobals.lattice.makeSuperCell) return dmaGlobals.lattice.makeSuperCell();
     return dmaGlobals.lattice.makeCellForLatticeType(null, dmaGlobals.lattice.get("scale"));
 };
 
@@ -172,7 +173,7 @@ Machine.prototype._incrementalMove = function(objects, axis, increment, currentP
 
 Machine.prototype._setPosition = function(objects, nextPos, axis){
     _.each(objects, function(object){
-        if (object instanceof DMACell) object.moveTo(nextPos, axis);
+        if (object instanceof DMACell || object instanceof  DMASuperCell) object.moveTo(nextPos, axis);
         else object.position[axis] = nextPos;
     });
 };
diff --git a/js/fea/DMASuperCell.js b/js/fea/DMASuperCell.js
index d0b5d630..8db6afc2 100644
--- a/js/fea/DMASuperCell.js
+++ b/js/fea/DMASuperCell.js
@@ -7,11 +7,16 @@ var cellBrassMaterial = new THREE.MeshLambertMaterial({color:"#b5a642"});
 var cellFiberGlassMaterial = new THREE.MeshLambertMaterial({color:"#fff68f"});
 
 DMASuperCell = function(length, range, cells){
-    var shouldRotate = range.max.x == range.min.x;
+    if (range) var shouldRotate = range.max.x == range.min.x;
     this.material = dmaGlobals.lattice.get("materialType");
     this.mesh = this._buildSuperCellMesh(length, shouldRotate);
     this.setVisibility(dmaGlobals.appState.get("cellMode")=="cell");
-    this.index = _.clone(range.max);
+    if (range) {
+        this.index = _.clone(range.max);
+        if (this.index.z %2 == 0) this.index.x -= cells.length/2.0-0.5;
+        else this.index.y -= cells.length/2.0-0.5;
+    }
+
     this.cells = cells;
     this.setScale();
     dmaGlobals.three.sceneAdd(this.mesh);
@@ -20,7 +25,6 @@ DMASuperCell = function(length, range, cells){
 DMASuperCell.prototype._buildSuperCellMesh = function(length, shouldRotate){
     var superCellGeo = new THREE.BoxGeometry(1,1,1);
     superCellGeo.applyMatrix(new THREE.Matrix4().makeScale(length, 1, 1));
-    superCellGeo.applyMatrix(new THREE.Matrix4().makeTranslation(-(length/2-1/2), 0, 0));
     if (shouldRotate) superCellGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI/2));
     var mesh = THREE.SceneUtils.createMultiMaterialObject(superCellGeo, [this.getMaterialType()]);
     var wireframe = new THREE.BoxHelper(mesh.children[0]);
@@ -36,6 +40,7 @@ DMASuperCell.prototype.getMaterialType = function(){
 };
 
 DMASuperCell.prototype._setPosition = function(index){
+    if (!index) return;
     var position = dmaGlobals.lattice.getPositionForIndex(index);
     this.mesh.position.set(position.x, position.y, position.z);
 };
@@ -54,6 +59,38 @@ DMASuperCell.prototype.getLength = function(){
     return this.cells.length-1;
 };
 
+DMASuperCell.prototype.hide = function(){//only used in the context of stock simulation
+    this.setVisibility(false);
+    _.each(this.cells, function(cell){
+        if (cell) cell.hide();
+    });
+};
+
+DMASuperCell.prototype.draw = function(scale, cellMode, partType){
+    if (this.hideForStockSimulation) return;
+    if (!scale) scale = dmaGlobals.lattice.get("scale");
+    var partMode = cellMode == "part";
+
+//    this.updateForScale(scale, cellMode, partType);
+
+    //set visibility
+    this.setVisibility(!partMode);
+    _.each(this.cells, function(cell){
+        if (cell) cell.draw(scale, cellMode, partType);
+    });
+};
+
+DMASuperCell.prototype.getPosition = function(){
+    return this.mesh.position.clone();
+};
+
+DMASuperCell.prototype.moveTo = function(position, axis){//used for stock simulations
+    this.mesh.position[axis] = position;
+    _.each(this.cells, function(cell){
+        if (cell) cell.moveTo(position, axis);
+    });
+};
+
 DMASuperCell.prototype.destroy = function(){
     if (this.destroyStarted) return;//prevents loop destroy from cells
     this.destroyStarted = true;
diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js
index 897c0c42..201af406 100644
--- a/js/fea/DmaCell.js
+++ b/js/fea/DmaCell.js
@@ -163,6 +163,7 @@ DMACell.prototype._buildCellMesh = function(material){//called from every subcla
     return mesh;
 };
 
+
 DMACell.prototype._doMeshTransformations = function(mesh){};//by default, no mesh transformations
 
 DMACell.prototype._initParts = function(){
diff --git a/js/fea/DmaCellOther.js b/js/fea/DmaCellOther.js
index 5fbc4252..d543b09a 100644
--- a/js/fea/DmaCellOther.js
+++ b/js/fea/DmaCellOther.js
@@ -70,9 +70,11 @@ var cellMaterial = [new THREE.MeshNormalMaterial()];
     DMAGIKCell.prototype = Object.create(DMACubeCell.prototype);
 
     DMAGIKCell.prototype._buildCellMesh = function(){
-        var mesh = DMACell.prototype._buildCellMesh.call(this, cellMaterial);
-        if (this.indices.z%2 != 0) mesh.rotateZ(Math.PI/2);
-        return mesh;
+        return DMACubeCell.prototype._buildCellMesh.call(this, cellMaterial);
+    };
+
+    DMAGIKCell.prototype._doMeshTransformations = function(mesh){
+        if (this.indices && this.indices.z%2 != 0) mesh.rotateZ(Math.PI/2);
     };
 
     DMAGIKCell.prototype._setCellMeshVisibility = function(visible){
diff --git a/js/models/AppState.js b/js/models/AppState.js
index 07253784..1bcc364a 100644
--- a/js/models/AppState.js
+++ b/js/models/AppState.js
@@ -69,8 +69,8 @@ AppState = Backbone.Model.extend({
                 },
                 edge: null,
                 edgeRot: {
-                    voxLowPoly: "Snap Voxel (low res)",
-                    vox: "Snap Voxel (high res)"
+                    vox: "Snap Voxel (high res)",
+                    voxLowPoly: "Snap Voxel (low res)"
                     //beam:"Beam"
                 },
                 vertex: null//{
@@ -135,7 +135,8 @@ AppState = Backbone.Model.extend({
                 vertex:{handOfGod: "Hand of God"}
             },
             cube:{
-                face:{handOfGod: "Hand of God"}
+                face:{handOfGod: "Hand of God"},
+                gik: {handOfGod: "Hand of God"}
             },
             truncatedCube:{
                 face:{handOfGod: "Hand of God"}
@@ -143,7 +144,6 @@ AppState = Backbone.Model.extend({
             kelvin:{
                 face:{handOfGod: "Hand of God"}
             }
-//            will: "Electronics Assembler"
         },
         allAssemblyStrategies: {
             raster: "Raster"
@@ -249,7 +249,6 @@ AppState = Backbone.Model.extend({
             this.get("lastSimulationTab"));
         else if (navSelection == "navAssemble") this.set("currentTab",
             this.get("lastAssembleTab"));
-        //todo make it so animation looks good again
     },
 
     ///////////////////////////////////////////////////////////////////////////////
diff --git a/js/models/LatticeOther.js b/js/models/LatticeOther.js
index 96f775ef..5a7d99f1 100644
--- a/js/models/LatticeOther.js
+++ b/js/models/LatticeOther.js
@@ -87,14 +87,23 @@ OtherLatticeSubclasses = {
             return new DMAGIKCell(indices, scale);
         },
 
-        addSuperCell: function(range){
+        makeSuperCell: function(range){
             var length = this.get("gikLength");
-            var cells = this.addCellsInRange(range);
-            if (cells.length < 1) return;
+            var cells;
+            if (range) cells = this.addCellsInRange(range);
+            else {
+                cells = [];
+                var scale = this.get("scale");
+                for (var i=0;i<length;i++){
+                    cells.push(this.makeCellForLatticeType(null, scale));
+                }
+            }
+            if (cells.length < 1) return null;
             var superCell = new DMASuperCell(length, range, cells);
             _.each(cells, function(cell, index){
                 cell.setSuperCell(superCell, index);
             });
+            return superCell;
         },
 
         _undo: function(){//remove all the mixins, this will help with debugging later
diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js
index 944505e9..b22a35d6 100644
--- a/js/threeViews/Highlighter.js
+++ b/js/threeViews/Highlighter.js
@@ -255,7 +255,7 @@ GIKHighlighter = Highlighter.extend({
                 max = {x:position.x, y:position.y+index, z:position.z};
             }
             var range = {min:min, max:max};
-            dmaGlobals.lattice.addSuperCell(range);
+            dmaGlobals.lattice.makeSuperCell(range);
         } else {
             if (!this.highlightedObject) return;
             if (!(this.highlightedObject instanceof DMACell)) return;
-- 
GitLab