From 20bbc6bb871fccca12886b9dbfdcf360304c7caa Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Wed, 28 Jan 2015 14:07:48 -0500 Subject: [PATCH] added cell iterator --- js/fea/dmaCell.js | 3 +-- js/models/lattice.js | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/js/fea/dmaCell.js b/js/fea/dmaCell.js index 96ad164f..7eb85b92 100644 --- a/js/fea/dmaCell.js +++ b/js/fea/dmaCell.js @@ -91,11 +91,10 @@ }; DMACell.prototype.drawForMode = function(mode){ - position = this.position; if (mode == "cell"){ if (this.cellMesh) this._setCellMeshVisibility(true); else { - this.cellMesh = this._buildCellMesh(position); + this.cellMesh = this._buildCellMesh(this.position); window.three.sceneAdd(this.cellMesh); } } else if (mode == "parts"){ diff --git a/js/models/lattice.js b/js/models/lattice.js index 0b9c35a6..db09d1cd 100644 --- a/js/models/lattice.js +++ b/js/models/lattice.js @@ -159,15 +159,8 @@ Lattice = Backbone.Model.extend({ }, clearCells: function(){ - _.each(this.get("cells"), function(cellLayer){ - _.each(cellLayer, function(cellCol){ - _.each(cellCol, function(cell){ - if (cell) { - cell.remove(); - } - }); - }); - + this._iterCells(this.get("cells"), function(cell){ + if (cell) cell.remove(); }); this.set("cells", this.defaults.cells); this.set("numCells", 0); @@ -176,10 +169,21 @@ Lattice = Backbone.Model.extend({ _cellModeDidChange: function(){ var mode = this.get("cellMode"); - _.each(this.get("cells"), function(cell){ - if (cell.drawForMode) cell.drawForMode(mode); + this._iterCells(this.get("cells"), function(cell){ + if (cell && cell.drawForMode) cell.drawForMode(mode); }); window.three.render(); + }, + + _iterCells: function(cells, callback, vars){ + _.each(cells, function(cellLayer){ + _.each(cellLayer, function(cellColumn){ + _.each(cellColumn, function(cell){ + callback(cell); + }); + }); + + }); } }); \ No newline at end of file -- GitLab