From 8f469f6fd6b4724bdc03100053df5b21efe49afd Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Fri, 15 May 2015 19:13:32 -0400
Subject: [PATCH] supercells coming in gik

---
 index.html                   |  1 +
 js/fea/DMASuperCell.js       | 40 ++++++++++++++++++++++++++++++++++++
 js/fea/DmaCellOther.js       | 26 +++++++++++++++++++++++
 js/models/Lattice.js         |  1 +
 js/models/LatticeOther.js    | 12 ++++++++++-
 js/threeViews/Highlighter.js |  2 +-
 6 files changed, 80 insertions(+), 2 deletions(-)
 create mode 100644 js/fea/DMASuperCell.js

diff --git a/index.html b/index.html
index 328b67d4..63cc8af5 100644
--- a/index.html
+++ b/index.html
@@ -44,6 +44,7 @@
     <script src="js/fea/DmaNode.js"></script>
     <script src="js/fea/DmaBeam.js"></script>
     <script src="js/fea/DmaCell.js"></script>
+    <script src="js/fea/DMASuperCell.js"></script>
     <script src="js/fea/DMACellFreeform.js"></script>
     <script src="js/fea/DmaCellOcta.js"></script>
     <script src="js/fea/DmaCellTetra.js"></script>
diff --git a/js/fea/DMASuperCell.js b/js/fea/DMASuperCell.js
new file mode 100644
index 00000000..a2d2ab5c
--- /dev/null
+++ b/js/fea/DMASuperCell.js
@@ -0,0 +1,40 @@
+/**
+ * Created by aghassaei on 5/15/15.
+ */
+
+
+var cellMaterials = [new THREE.MeshNormalMaterial()];
+
+DMASuperCell = function(length, index){
+    this.mesh = this._buildSuperCellMesh(length);
+    this.index = _.clone(index);
+    this.setScale();
+    dmaGlobals.three.sceneAdd(this.mesh);
+};
+
+DMASuperCell.prototype._buildSuperCellMesh = function(length){
+    var superCellGeo = new THREE.BoxGeometry(1,1,1);
+    superCellGeo.applyMatrix(new THREE.Matrix4().makeScale(length, 1, 1));
+    var mesh = THREE.SceneUtils.createMultiMaterialObject(superCellGeo, cellMaterials);
+    var wireframe = new THREE.BoxHelper(mesh.children[0]);
+    wireframe.material.color.set(0x000000);
+    mesh.children.push(wireframe);
+    return mesh;
+};
+
+DMASuperCell.prototype._setPosition = function(index){
+    var position = dmaGlobals.lattice.getPositionForIndex(index);
+    this.mesh.position.set(position.x, position.y, position.z);
+};
+
+DMASuperCell.prototype.setScale = function(scale){
+    if (!scale) scale = dmaGlobals.lattice.get("scale");
+    this.mesh.scale.set(scale, scale, scale);
+    this._setPosition(this.index);
+};
+
+DMASuperCell.prototype.destroy = function(){
+    dmaGlobals.three.sceneRemove(this.mesh);
+    this.mesh = null;
+    this.index = null;
+}
\ No newline at end of file
diff --git a/js/fea/DmaCellOther.js b/js/fea/DmaCellOther.js
index 9f31426f..adcd7cae 100644
--- a/js/fea/DmaCellOther.js
+++ b/js/fea/DmaCellOther.js
@@ -60,6 +60,32 @@ var cellMaterial = [new THREE.MeshNormalMaterial()];
 
 })();
 
+(function () {
+
+    var unitCellGeo = new THREE.BoxGeometry(1,1,1);
+
+    function DMAGIKCell(indices, scale, cellMode, partType){
+        DMACubeCell.call(this, indices, scale, cellMode, partType);
+    }
+    DMAGIKCell.prototype = Object.create(DMACubeCell.prototype);
+
+    DMAGIKCell.prototype._buildCellMesh = function(){
+        return DMACell.prototype._buildCellMesh.call(this, cellMaterial);
+    };
+
+    DMAGIKCell.prototype._setCellMeshVisibility = function(visible){
+        this.cellMesh.visible = false;
+    };
+
+    DMAGIKCell.prototype.setSuperCell = function(superCell, index, length){
+        this.superCellIndex = index;
+        this.superCellLength = length;
+    };
+
+    self.DMAGIKCell = DMAGIKCell;
+
+})();
+
 
 ///////////////////////////////////////////////////////////////////////////////////////////////
 ////////////////////////TRUNCATED CUBE CLASS///////////////////////////////////////////////////
diff --git a/js/models/Lattice.js b/js/models/Lattice.js
index 3acecb4b..32e8c3cd 100644
--- a/js/models/Lattice.js
+++ b/js/models/Lattice.js
@@ -448,6 +448,7 @@ Lattice = Backbone.Model.extend({
             if (connectionType == "face"){
                 _.extend(this, this.CubeLattice);
             } else if (connectionType == "gik"){
+                if (!loadingFromFile) this.clearCells();
                 _.extend(this, this.GIKLattice);
             }
         } else if (cellType == "truncatedCube"){
diff --git a/js/models/LatticeOther.js b/js/models/LatticeOther.js
index fd8610f2..a165f4a9 100644
--- a/js/models/LatticeOther.js
+++ b/js/models/LatticeOther.js
@@ -84,7 +84,17 @@ OtherLatticeSubclasses = {
         },
 
         makeCellForLatticeType: function(indices, scale){
-            return new DMACubeCell(indices, scale);
+            return new DMAGIKCell(indices, scale);
+        },
+
+        addSuperCell: function(range){
+
+            var length = this.get("gikLength");
+            var superCell = new DMASuperCell(length, range.max);
+            var cells = this.addCellsInRange(range);
+            _.each(cells, function(cell, index){
+                cell.setSuperCell(superCell, index, length);
+            });
         },
 
         _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 7e13ea62..bb8fa30b 100644
--- a/js/threeViews/Highlighter.js
+++ b/js/threeViews/Highlighter.js
@@ -250,7 +250,7 @@ GIKHighlighter = Highlighter.extend({
             if (this.mesh.rotation.z == 0) min = {x:position.x-(dmaGlobals.lattice.get("gikLength")-1), y:position.y, z:position.z};
             else min = {x:position.x, y:position.y-(dmaGlobals.lattice.get("gikLength")-1), z:position.z};
             var range = {min:min, max:position};
-            dmaGlobals.lattice.addCellsInRange(range);
+            dmaGlobals.lattice.addSuperCell(range);
         } else {
             if (!this.highlightedObject) return;
             if (!(this.highlightedObject instanceof DMACell)) return;
-- 
GitLab