From 5f405bbac23bd642d1d44936d9cfd9ad45b2bc0f Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Fri, 12 Jun 2015 15:46:09 -0700
Subject: [PATCH] composite highlighter working

---
 js/highlighter/Highlighter.js        |  2 +-
 js/lattice/CompositeEditorLattice.js |  2 +-
 js/lattice/CubeLattice.js            |  6 ++++-
 js/lattice/GIKLattice.js             |  6 ++++-
 js/lattice/KelvinLattice.js          |  6 ++++-
 js/lattice/Lattice.js                | 35 +++++++++++++++-------------
 js/lattice/OctaEdgeLattice.js        |  6 ++++-
 js/lattice/OctaFaceLattice.js        |  6 ++++-
 js/lattice/OctaRotEdgeLattice.js     |  6 ++++-
 js/lattice/OctaVertexLattice.js      |  6 ++++-
 js/lattice/TetraStackedLattice.js    |  6 ++++-
 js/lattice/TetraVertexLattice.js     |  6 ++++-
 js/lattice/TruncatedCubeLattice.js   |  6 ++++-
 13 files changed, 71 insertions(+), 28 deletions(-)

diff --git a/js/highlighter/Highlighter.js b/js/highlighter/Highlighter.js
index 2d332e66..69e39162 100644
--- a/js/highlighter/Highlighter.js
+++ b/js/highlighter/Highlighter.js
@@ -23,6 +23,7 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', '
                 }));
 
             three.sceneAdd(this.mesh);
+            this._setScale();
             this.hide();
 
             //bind events
@@ -105,7 +106,6 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', '
             }
             this.position = params.position;
             this.direction = params.direction;
-            this._setScale();
             this._setPosition(params.position, params.direction);//position of center point
             this._setRotation(params.direction);
 
diff --git a/js/lattice/CompositeEditorLattice.js b/js/lattice/CompositeEditorLattice.js
index 4d07850a..15b794af 100644
--- a/js/lattice/CompositeEditorLattice.js
+++ b/js/lattice/CompositeEditorLattice.js
@@ -76,7 +76,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
                 sparseCells: JSON.parse(JSON.stringify(this.sparseCells)),
                 cellsMin: this.get("cellsMin").clone(),
                 cellsMax: this.get("cellsMax").clone(),
-                dimensions: new THREE.Vector3().subVectors(this.get("cellsMax"), this.get("cellsMin"))
+                dimensions: this.calculateBoundingBox()
             };
             globals.materials.compositeMaterials[id] = data;//todo trigger change on all instances
         },
diff --git a/js/lattice/CubeLattice.js b/js/lattice/CubeLattice.js
index cd9dc04f..de8c82b3 100644
--- a/js/lattice/CubeLattice.js
+++ b/js/lattice/CubeLattice.js
@@ -11,11 +11,15 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             require(['squareBaseplane'], function(SquareBasePlane){
                 globals.basePlane = new SquareBasePlane();
             });
-            require(['cubeHighlighter'], function(CubeHighlighter){
+            require([this.getHighlighterFile()], function(CubeHighlighter){
                 globals.highlighter = new CubeHighlighter();
             });
         },
 
+        getHighlighterFile: function(){
+            return "cubeHighlighter";
+        },
+
         getIndexForPosition: function(absPosition){
             return this._indexForPosition(absPosition);
         },
diff --git a/js/lattice/GIKLattice.js b/js/lattice/GIKLattice.js
index 84465643..89a86daf 100644
--- a/js/lattice/GIKLattice.js
+++ b/js/lattice/GIKLattice.js
@@ -11,13 +11,17 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             require(['squareBaseplane'], function(SquareBasePlane){
                 globals.basePlane = new SquareBasePlane();
             });
-            require(['superCellHighlighter'], function(superCellHighlighter){
+            require([this.getHighlighterFile()], function(superCellHighlighter){
                 globals.highlighter = new superCellHighlighter();
             });
             appState.set("superCellRange", new THREE.Vector3(4, 1, 1));
 
         },
 
+        getHighlighterFile: function(){
+            return "superCellHighlighter";
+        },
+
         getIndexForPosition: function(absPosition){
             return this._indexForPosition(absPosition);
         },
diff --git a/js/lattice/KelvinLattice.js b/js/lattice/KelvinLattice.js
index f3b712df..763a8585 100644
--- a/js/lattice/KelvinLattice.js
+++ b/js/lattice/KelvinLattice.js
@@ -12,11 +12,15 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             require(['squareBaseplane'], function(SquareBasePlane){
                 globals.basePlane = new SquareBasePlane();
             });
-            require(['truncatedCubeHighlighter'], function(TruncatedCubeHighlighter){
+            require([this.getHighlighterFile()], function(TruncatedCubeHighlighter){
                 globals.highlighter = new TruncatedCubeHighlighter();
             });
         },
 
+        getHighlighterFile: function(){
+            return "truncatedCubeHighlighter";
+        },
+
         getIndexForPosition: function(absPosition){
             return this._indexForPosition(absPosition);
         },
diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js
index 279d0cdf..f9df850c 100644
--- a/js/lattice/Lattice.js
+++ b/js/lattice/Lattice.js
@@ -33,6 +33,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             });
             this.listenTo(this, "change:cellSeparation", this._updateCellSeparation);
 
+            this.listenTo(this, "change:materialType", this._materialTypeChanged);
             this.listenTo(this, "change:materialClass", this._loadMaterialClass);
 
             this.listenTo(appState, "change:currentNav", this._navChanged);
@@ -108,22 +109,24 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
 
         //events
 
-//        _materialTypeChanged: function(){
-//            var materialType = this.get("materialType");
-//            //verify that correct class is in sync
-//            if (materialType.substr(0,5) == "super"){
-//                this.set("materialClass", "compositeMaterials");
-//                return;
-//            } else {
-//                var materialClass = null;
-//                _.each(_.keys(plist.allMaterials), function(key){
-//                    if (_.keys(plist.allMaterials[key]).indexOf(materialType) > -1) materialClass = key;
-//                });
-//            }
-//            console.log(materialClass);
-//            if (!materialClass) console.warn("material class not found for material " + materialType);
-//            else this.set("materialClass", materialClass);
-//        },
+        _materialTypeChanged: function(){
+            var materialType = this.get("materialType");
+            //verify that correct class is in sync
+            if (materialType.substr(0,5) != "super") {
+                if (this.previous("materialType").substr(0,5) != "super") return;
+                //re init highlighter
+                require([this.getHighlighterFile()], function(HighlighterClass){
+                    globals.highlighter = new HighlighterClass();
+                });
+                return;
+            }
+
+            appState.set("superCellRange", globals.materials.compositeMaterials[materialType].dimensions.clone());
+            appState.set("superCellIndex", new THREE.Vector3(0,0,0));
+            require(['superCellHighlighter'], function(SuperCellHighlighter){
+                globals.highlighter = new SuperCellHighlighter();
+            });
+        },
 
         _loadMaterialClass: function(){
             var materialClass = this.get("materialClass");
diff --git a/js/lattice/OctaEdgeLattice.js b/js/lattice/OctaEdgeLattice.js
index 8db77437..46c8e5b6 100644
--- a/js/lattice/OctaEdgeLattice.js
+++ b/js/lattice/OctaEdgeLattice.js
@@ -11,11 +11,15 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             require(['octaBaseplane'], function(OctaBasePlane){
                 globals.basePlane = new OctaBasePlane();
             });
-            require(['defaultHighlighter'], function(DefaultHighlighter){
+            require([this.getHighlighterFile()], function(DefaultHighlighter){
                 globals.highlighter = new DefaultHighlighter();
             });
         },
 
+        getHighlighterFile: function(){
+            return "defaultHighlighter";
+        },
+
         getIndexForPosition: function(absPosition){
             var index = this._indexForPosition(absPosition);
             if (index.y%2 != 0) {
diff --git a/js/lattice/OctaFaceLattice.js b/js/lattice/OctaFaceLattice.js
index a01225ee..7313dc02 100644
--- a/js/lattice/OctaFaceLattice.js
+++ b/js/lattice/OctaFaceLattice.js
@@ -11,11 +11,15 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             require(['octaBaseplane'], function(OctaBasePlane){
                 globals.basePlane = new OctaBasePlane();
             });
-            require(['octaFaceHighlighter'], function(OctaFaceHighlighter){
+            require([this.getHighlighterFile()], function(OctaFaceHighlighter){
                 globals.highlighter = new OctaFaceHighlighter();
             });
         },
 
+        getHighlighterFile: function(){
+            return "octaFaceHighlighter";
+        },
+
         getIndexForPosition: function(absPosition){
             var index = this._indexForPosition(absPosition);
             if (index.y%2 != 0) {
diff --git a/js/lattice/OctaRotEdgeLattice.js b/js/lattice/OctaRotEdgeLattice.js
index 2d8b52bf..3e37f740 100644
--- a/js/lattice/OctaRotEdgeLattice.js
+++ b/js/lattice/OctaRotEdgeLattice.js
@@ -11,11 +11,15 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             require(['rotEdgeOctaBaseplane'], function(RotEdgeOctaBasePlane){
                 globals.basePlane = new RotEdgeOctaBasePlane();
             });
-            require(['defaultHighlighter'], function(DefaultHighlighter){
+            require([this.getHighlighterFile()], function(DefaultHighlighter){
                 globals.highlighter = new DefaultHighlighter();
             });
         },
 
+        getHighlighterFile: function(){
+            return "defaultHighlighter";
+        },
+
         getIndexForPosition: function(absPosition){
             return this._indexForPosition(absPosition);
         },
diff --git a/js/lattice/OctaVertexLattice.js b/js/lattice/OctaVertexLattice.js
index ea9acd58..242c8b6f 100644
--- a/js/lattice/OctaVertexLattice.js
+++ b/js/lattice/OctaVertexLattice.js
@@ -11,11 +11,15 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             require(['squareBaseplane'], function(SquareBasePlane){
                 globals.basePlane = new SquareBasePlane();
             });
-            require(['defaultHighlighter'], function(DefaultHighlighter){
+            require([this.getHighlighterFile()], function(DefaultHighlighter){
                 globals.highlighter = new DefaultHighlighter();
             });
         },
 
+        getHighlighterFile: function(){
+            return "defaultHighlighter";
+        },
+
         getIndexForPosition: function(absPosition){
             return this._indexForPosition(absPosition);
         },
diff --git a/js/lattice/TetraStackedLattice.js b/js/lattice/TetraStackedLattice.js
index ce40d530..5e602500 100644
--- a/js/lattice/TetraStackedLattice.js
+++ b/js/lattice/TetraStackedLattice.js
@@ -11,11 +11,15 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             require(['octaBaseplane'], function(OctaBasePlane){
                 globals.basePlane = new OctaBasePlane();
             });
-            require(['defaultHighlighter'], function(DefaultHighlighter){
+            require([this.getHighlighterFile()], function(DefaultHighlighter){
                 globals.highlighter = new DefaultHighlighter();
             });
         },
 
+        getHighlighterFile: function(){
+            return "defaultHighlighter";
+        },
+
         getIndexForPosition: function(absPosition){
             var index = this._indexForPosition(absPosition);
             if (index.y%2 != 0) {
diff --git a/js/lattice/TetraVertexLattice.js b/js/lattice/TetraVertexLattice.js
index 337e434d..c5a466dc 100644
--- a/js/lattice/TetraVertexLattice.js
+++ b/js/lattice/TetraVertexLattice.js
@@ -11,11 +11,15 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             require(['octaBaseplane'], function(OctaBasePlane){
                 globals.basePlane = new OctaBasePlane();
             });
-            require(['defaultHighlighter'], function(DefaultHighlighter){
+            require([this.getHighlighterFile()], function(DefaultHighlighter){
                 globals.highlighter = new DefaultHighlighter();
             });
         },
 
+        getHighlighterFile: function(){
+            return "defaultHighlighter";
+        },
+
         getIndexForPosition: function(absPosition){
             var yIndex = Math.floor(absPosition.y/this.yScale());
             if (yIndex%2 != 0) absPosition.x += this.xScale()/2;
diff --git a/js/lattice/TruncatedCubeLattice.js b/js/lattice/TruncatedCubeLattice.js
index e5c34b67..c24d05b8 100644
--- a/js/lattice/TruncatedCubeLattice.js
+++ b/js/lattice/TruncatedCubeLattice.js
@@ -12,11 +12,15 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             require(['squareBaseplane'], function(SquareBasePlane){
                 globals.basePlane = new SquareBasePlane();
             });
-            require(['truncatedCubeHighlighter'], function(TruncatedCubeHighlighter){
+            require([this.getHighlighterFile()], function(TruncatedCubeHighlighter){
                 globals.highlighter = new TruncatedCubeHighlighter();
             });
         },
 
+        getHighlighterFile: function(){
+            return "truncatedCubeHighlighter";
+        },
+
         getIndexForPosition: function(absPosition){
             return this._indexForPosition(absPosition);
         },
-- 
GitLab