From 232da6e43f8113bafb0ce035c4d4f94c9f6d5caf Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Thu, 5 Feb 2015 16:12:32 -0500
Subject: [PATCH] wall building

---
 js/menus/ImportMenuView.js  | 12 ++++++++--
 js/menus/LatticeMenuView.js | 21 ++++++++---------
 js/models/Lattice.js        | 45 ++++++++++++++++++++++++++++---------
 main.html                   |  2 +-
 4 files changed, 56 insertions(+), 24 deletions(-)

diff --git a/js/menus/ImportMenuView.js b/js/menus/ImportMenuView.js
index 70e3c29e..33cd6fc0 100644
--- a/js/menus/ImportMenuView.js
+++ b/js/menus/ImportMenuView.js
@@ -12,7 +12,8 @@ ImportMenuView = Backbone.View.extend({
         "change #uploadMesh":               "_uploadMesh",
         "click .selectMesh":                "_selectMesh",
         "fileselect .btn-file :file":       "_readDataURL",
-        "click #removeFillGeo":             "_removeMesh"
+        "click #removeFillGeo":             "_removeMesh",
+        "click #selectWall":                "_buildWall"
     },
 
     initialize: function(options){
@@ -31,6 +32,11 @@ ImportMenuView = Backbone.View.extend({
         this.model.set("filename", filename);
     },
 
+    _buildWall: function(e){
+        e.preventDefault();
+        this.lattice.addCellsInRange({min:{x:-50,y:-2,z:0}, max:{x:50,y:2,z:15}});
+    },
+
     _uploadMesh: function(e){//select a mesh to upload
         e.preventDefault();
         var input = $(e.target),
@@ -120,7 +126,9 @@ ImportMenuView = Backbone.View.extend({
         <div class="btn-group fullWidth">\
             <button data-toggle="dropdown" class="btn btn-default dropdown-toggle fullWidth" type="button">Select Model <span class="caret"></span></button>\
             <ul role="menu" class="dropdown-menu">\
-              <li><a class="selectMesh" data-file="Airbus_A300-600.stl" href="#">Plane</a></li>\
+              <!--<li><a class="selectMesh fillGeo" data-file="Airbus_A300-600.stl" href="#">Plane</a></li>-->\
+              <li><a id="selectWall" href="#">Wall</a></li>\
+              <li><a class="selectMesh cutTerrain" data-file="Airbus_A300-600.stl" href="#">Landscape</a></li>\
             </ul>\
         </div><!-- /btn-group -->')
 
diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js
index 495d51f2..f319c579 100644
--- a/js/menus/LatticeMenuView.js
+++ b/js/menus/LatticeMenuView.js
@@ -13,7 +13,7 @@ LatticeMenuView = Backbone.View.extend({
         "click .cellType":                              "_changeCellType",
         "click .connectionType":                        "_changeConnectionType",
         "slide #scaleSlider":                           "_sliderDidSlide",
-//        "slideStop #scaleSlider":                       "_changeScaleSlider"
+        "slideStop #scaleSlider":                       "_changeScaleSlider"
     },
 
 
@@ -44,15 +44,15 @@ LatticeMenuView = Backbone.View.extend({
 
     _sliderDidSlide: function(e){
         var scale = $(e.target)[0].value;
-        this.model.set("scale", $(e.target)[0].value);
-//        this.model.previewScaleChange(scale);//does not trigger lattice change event - no rerendering of ui
+//        this.model.set("scale", $(e.target)[0].value);
+        this.model.previewScaleChange(scale);//does not trigger lattice change event - no rerendering of ui
         $("#latticeScale").val(scale);
         window.three.render();
     },
 
-//    _changeScaleSlider: function(e){
-//        this.model.set("scale", $(e.target)[0].value);
-//    },
+    _changeScaleSlider: function(e){
+        this.model.set("scale", $(e.target)[0].value);
+    },
 
     _changeCellType: function(e){
         e.preventDefault();
@@ -132,13 +132,14 @@ LatticeMenuView = Backbone.View.extend({
             </div><br/><br/>\
         Scale:&nbsp;&nbsp;<input id="scaleSlider" data-slider-id="ex1Slider" type="text" data-slider-min="1" data-slider-max="100" data-slider-step="0.1" data-slider-value="<%= scale %>"/>\
         <br/><input id="latticeScale" value="<%= scale %>" placeholder="enter scale" class="form-control" type="text"><br/>\
-        <label class="checkbox" for="invertGeo">\
-            <input type="checkbox" checked="checked" value="" id="invertGeo" data-toggle="checkbox" class="custom-checkbox"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>\
-            Show Inverse Geometry\
-        </label>\
         Num Cells:&nbsp;&nbsp;<%= numCells %><br/>\
         <br/>\
         <a href="#" id="latticeMenuClearCells" class=" btn btn-block btn-lg btn-default">Clear All Cells</a><br/>\
         ')
 
+//    <label class="checkbox" for="invertGeo">\
+//            <input type="checkbox" checked="checked" value="" id="invertGeo" data-toggle="checkbox" class="custom-checkbox"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>\
+//            Show Inverse Geometry\
+//        </label>\
+
 });
\ No newline at end of file
diff --git a/js/models/Lattice.js b/js/models/Lattice.js
index a6c5b211..7a0680c0 100644
--- a/js/models/Lattice.js
+++ b/js/models/Lattice.js
@@ -51,17 +51,40 @@ Lattice = Backbone.Model.extend({
     ///////////////////////////////ADD/REMOVE CELLS/////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////////
 
+    addCellsInRange: function(range){//add a block of cells
+        var scale = this.get("scale");
+        var cells = this.get("cells");
+        this._checkForMatrixExpansion(cells, range.max, range.min);
+
+        var relativeMin = this._subtract(range.min, this.get("cellsMin"));
+        var relativeMax = this._subtract(range.max, this.get("cellsMin"));
+
+        for (var x=relativeMin.x;x<relativeMax.x;x++){
+            for (var y=relativeMin.y;y<relativeMax.y;y++){
+                for (var z=relativeMin.z;z<relativeMax.z;z++){
+                    if (!cells[x][y][z]) {
+                        cells[x][y][z] = this._makeCellForLatticeType(this._add({x:x, y:y, z:z}, range.min), scale);
+                        this.set("numCells", this.get("numCells")+1);
+                    } else console.warn("already a cell there");
+                }
+            }
+        }
+        window.three.render();
+    },
+
     addCellAtIndex: function(indices){
 
         var scale = this.get("scale");
         var cells = this.get("cells");
-        this._checkForMatrixExpansion(cells, indices);
+        this._checkForMatrixExpansion(cells, indices, indices);
 
         var index = this._subtract(indices, this.get("cellsMin"));
-        if (!cells[index.x][index.y][index.z]) cells[index.x][index.y][index.z] = this._makeCellForLatticeType(indices, scale);
-        else console.warn("already a cell there");
-        this.set("numCells", this.get("numCells")+1);
-        window.three.render();
+        if (!cells[index.x][index.y][index.z]) {
+            cells[index.x][index.y][index.z] = this._makeCellForLatticeType(indices, scale);
+            this.set("numCells", this.get("numCells")+1);
+            window.three.render();
+        } else console.warn("already a cell there");
+
     },
 
     removeCell: function(cell){
@@ -94,12 +117,12 @@ Lattice = Backbone.Model.extend({
     ///////////////////////////////CELLS ARRAY//////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////////
 
-    _checkForMatrixExpansion: function(cells, indices){
+    _checkForMatrixExpansion: function(cells, indicesMax, indicesMin){
 
         var lastMax = this.get("cellsMax");
         var lastMin = this.get("cellsMin");
-        var newMax = this._updateCellsMax(indices, lastMax);
-        var newMin = this._updateCellsMin(indices, lastMin);
+        var newMax = this._updateCellsMax(indicesMax, lastMax);
+        var newMin = this._updateCellsMin(indicesMin, lastMin);
         if (newMax) {
             this._expandCellsArray(cells, this._subtract(newMax, lastMax), false);
             this.set("cellsMax", newMax);
@@ -215,9 +238,9 @@ Lattice = Backbone.Model.extend({
         window.three.render();
     },
 
-//    previewScaleChange: function(scale){
-//        this.get("basePlane").updateScale(scale);
-//    },
+    previewScaleChange: function(scale){
+        this.get("basePlane").updateScale(scale);
+    },
 
     _changeLatticeStructure: function(){
         this.clearCells();
diff --git a/main.html b/main.html
index 932cce6d..6a015925 100644
--- a/main.html
+++ b/main.html
@@ -37,7 +37,7 @@
 
     <!--global variables-->
     <script>
-        window.defaultLatticeScale = 20;
+        window.defaultLatticeScale = 1;
     </script>
 
     <!--multi-threading-->
-- 
GitLab