From 8f870d6e44d368b7887c464d53686226e1ea2747 Mon Sep 17 00:00:00 2001 From: amandaghassaei <amandaghassaei@gmail.com> Date: Sat, 14 Mar 2015 01:20:29 -0400 Subject: [PATCH] cell separation edge connected --- css/main.css | 2 +- js/fea/DmaCellOcta.js | 12 +++++++++- js/main.js | 2 -- js/menus/LatticeMenuView.js | 18 ++++++++++++++ js/models/BasePlane.js | 3 +-- js/models/Lattice.js | 4 +--- js/models/LatticeOcta.js | 47 ++++--------------------------------- 7 files changed, 36 insertions(+), 52 deletions(-) diff --git a/css/main.css b/css/main.css index 38b44a5f..3820bace 100644 --- a/css/main.css +++ b/css/main.css @@ -80,7 +80,7 @@ nav .btn { #menuWrapper { width: 400px; height: 100%; - z-index: 2; + z-index: 1; position: absolute; display: block; background-color: rgba(255,255,255,0.8); diff --git a/js/fea/DmaCellOcta.js b/js/fea/DmaCellOcta.js index e2cb273c..9424aed0 100644 --- a/js/fea/DmaCellOcta.js +++ b/js/fea/DmaCellOcta.js @@ -187,8 +187,18 @@ DMARotatedEdgeCell.prototype.calcHighlighterPosition = function(face, point){ return {index: _.clone(this.indices), direction:direction, position:position}; }; +DMARotatedEdgeCell.prototype.xScale = function(scale){ + if (!scale) scale = dmaGlobals.lattice.get("scale"); + return scale; +}; + +DMARotatedEdgeCell.prototype.yScale = function(scale){ + return this.xScale(scale); +}; + DMARotatedEdgeCell.prototype.zScale = function(scale){ - return this.xScale(scale)*Math.sqrt(2); + if (!scale) scale = dmaGlobals.lattice.get("scale"); + return Math.sqrt(2)/2*scale; }; DMARotatedEdgeCell.prototype._getGeometry = function(){ diff --git a/js/main.js b/js/main.js index 2be1014f..8288646a 100644 --- a/js/main.js +++ b/js/main.js @@ -2,8 +2,6 @@ * Created by aghassaei on 1/7/15. */ -//test - //setup persistent global variables if (typeof dmaGlobals === "undefined") dmaGlobals = {}; diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index e13b6436..0ec1ea48 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -26,9 +26,25 @@ LatticeMenuView = Backbone.View.extend({ this.lattice = options.lattice; _.bindAll(this, "render"); + _.bindAll(this, "_onKeyup"); + //bind events this.listenTo(this.lattice, "change", this.render); this.listenTo(this.model, "change:units", this.render); + $(document).bind('keyup', {state:false}, this._onKeyup); + }, + + _onKeyup: function(e){ + if ($(".cellSeparation").is(":focus")) this._updateNumber(e, "cellSeparation"); + }, + + _updateNumber: function(e, property){ + e.preventDefault(); + var newVal = parseFloat($(e.target).val()); + if (isNaN(newVal)) return; + var object = this.lattice.get(property); + object[$(e.target).data("type")] = newVal; + this.lattice.trigger("change:"+property); }, _clearCells: function(e){ @@ -159,6 +175,8 @@ LatticeMenuView = Backbone.View.extend({ <% }); %>\ </ul>\ </div><br/><br/>\ + Cell Separation (xy, z): <input data-type="xy" value="<%= cellSeparation.xy %>" placeholder="XY" class="form-control numberInput cellSeparation" type="text">\ + <input data-type="z" value="<%= cellSeparation.z %>" placeholder="Z" class="form-control numberInput cellSeparation" type="text">\ Num Cells: <%= numCells %><br/>\ <br/>\ <a href="#" id="latticeMenuClearCells" class=" btn btn-block btn-lg btn-default">Clear All Cells</a><br/>\ diff --git a/js/models/BasePlane.js b/js/models/BasePlane.js index e62e4415..f95c8151 100644 --- a/js/models/BasePlane.js +++ b/js/models/BasePlane.js @@ -161,8 +161,7 @@ OctaBasePlane = BasePlane.extend({ for (var i=-dimY;i<=dimY;i++){ var xOffset = 0; - if (Math.abs(j)%2==0) { - } else { + if (Math.abs(j)%2!=0) { xOffset = 1/2*xScale; } diff --git a/js/models/Lattice.js b/js/models/Lattice.js index bb89b505..05c94aee 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -20,9 +20,7 @@ Lattice = Backbone.Model.extend({ //spacing for connectors/joints columnSeparation: 0.0,//todo get rid of this - xSeparation: 0.0, - ySeparation: 0.0, - zSeparation: 0.0, + cellSeparation: {xy:0.1, z:0}, cellMode: "cell",//show cells vs parts cellType: "octa", diff --git a/js/models/LatticeOcta.js b/js/models/LatticeOcta.js index 9697ce9d..4cea50a5 100644 --- a/js/models/LatticeOcta.js +++ b/js/models/LatticeOcta.js @@ -223,48 +223,6 @@ OctaLatticeSubclasses = { return new DMAEdgeOctaCell(indices, scale); }, -// getInvCellPositionForIndex: function(index){ -// -// var scale = this.get("scale"); -// var position = _.clone(index); -// -// var oddZ = position.z%2 != 0; -// position.z = Math.floor(position.z/2); -// var yScale = scale/Math.sqrt(3); -// -// if (oddZ){ -// position.x = (position.x)*this.xScale(scale); -// position.y = position.y*this.yScale(scale); -// } else { -// position.x = (position.x+0.5)*this.xScale(scale); -// position.y = (position.y)*this.yScale(scale)-yScale/2; -// } -// -// if (oddZ){ -// position.z = (position.z + 1)*this.zScale(scale); -// } else { -// position.z = (position.z)*this.zScale(scale); -// } -// -// if ((index.y%2) != 0) { -// if (oddZ){ -// position.x += this.xScale(scale)/2; -// } else { -// position.x -= this.xScale(scale)/2; -// } -// } -// -// var zLayer = Math.floor(index.z/2)%3; -// if (zLayer == 1) { -// position.x += this.xScale(scale)/2; -// position.y -= yScale/2; -// } else if (zLayer == 2){ -// position.y -= yScale; -// } -// -// return position; -// }, - _undo: function(){//remove all the mixins, this will help with debugging later var self = this; _.each(_.keys(this.OctaEdgeLattice), function(key){ @@ -310,6 +268,7 @@ OctaLatticeSubclasses = { xScale: function(scale){ if (!scale) scale = this.get("scale"); + scale *= 1 + 2*this.get("cellSeparation").xy; return scale; }, @@ -318,7 +277,9 @@ OctaLatticeSubclasses = { }, zScale: function(scale){ - return this.xScale(scale)*Math.sqrt(2)/2; + if (!scale) scale = this.get("scale"); + scale *= Math.sqrt(2)/2 + 2*this.get("cellSeparation").z; + return scale; }, makeCellForLatticeType: function(indices, scale){ -- GitLab