diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index 16dfd171822a620bb9651c9ed657b36d257cc744..fee678377a975c8d542392c1af5d24369b9f83e0 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -15,7 +15,7 @@ function DMACell(indices, scale, lattice, inverse) { this.parts = this._initParts(indices.z); this.updateForScale(scale); - this.drawForMode(dmaGlobals.appState.get("cellMode")); + this.drawForMode(dmaGlobals.appState.get("cellMode"), dmaGlobals.appState.get("inverseMode")); } DMACell.prototype.removePart = function(index){ @@ -35,33 +35,13 @@ DMACell.prototype._setMeshPosition = function(mesh, position){ return mesh; }; -DMACell.prototype.drawForMode = function(mode){ - if (mode == "cell"){ - this._setCellMeshVisibility(true); - _.each(this.parts, function(part){ - if (part) part.hide(); - }); - } else if (mode == "part"){ - this._setCellMeshVisibility(false); - _.each(this.parts, function(part){ - if (part) part.show(); - }); - } else { - console.warn("unrecognized draw mode for cell"); - } -}; - -DMACell.prototype.hide = function(){ - this._setCellMeshVisibility(false); +DMACell.prototype.drawForMode = function(cellMode, inverseMode){ + this._setCellMeshVisibility(cellMode == "cell" && inverseMode==this.isInverse);//only show if in the correct inverseMode _.each(this.parts, function(part){ - if (part) part.hide(); + if (part) part.setVisibility(cellMode == "part"); }); }; -DMACell.prototype.show = function(){ - this._setCellMeshVisibility(true); -}; - DMACell.prototype._setCellMeshVisibility = function(visibility){ if (!this.cellMesh) return; this.cellMesh.visible = visibility; diff --git a/js/fea/DmaPart.js b/js/fea/DmaPart.js index aa09216c52127106e05286c22dc16d5db22cfb7a..ec4396fddeaf808c4dfb97f56e75571efa581346 100644 --- a/js/fea/DmaPart.js +++ b/js/fea/DmaPart.js @@ -32,12 +32,17 @@ mesh.position.z = position.z; }; - DMAPart.prototype.show = function(){ + DMAPart.prototype.setVisibility = function(visibility){ + if (visibility) this._show(); + else this._hide(); + }; + + DMAPart.prototype._show = function(){ if (!this.mesh) this._draw(); this.mesh.visible = true; }; - DMAPart.prototype.hide = function(){ + DMAPart.prototype._hide = function(){ if (this.mesh) this.mesh.visible = false; }; diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 983e88134a52e57881e797866c5f8853211e87db..ba855ae138a23783b2b96993c9d7dcc193aee0f4 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -36,8 +36,7 @@ Lattice = Backbone.Model.extend({ //bind events this.listenTo(this, "change:scale", this._scaleDidChange); - this.listenTo(this, "change:inverseMode", this._showInverseCells); - this.listenTo(this, "change:cellMode", this._cellModeDidChange); + this.listenTo(this, "change:inverseMode change:cellMode", this._updateForMode); this.listenTo(this, "change:cellType change:connectionType", this._updateLatticeType); }, @@ -299,35 +298,14 @@ Lattice = Backbone.Model.extend({ ////////////////////////////////////EVENTS////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// - _cellModeDidChange: function(){ - var mode = this.get("cellMode"); - var inverseMode = this.get("inverseMode"); - if (mode == "part" || !inverseMode){ - this._iterCells(this.get("cells"), function(cell){ - if (cell && cell.drawForMode) cell.drawForMode(mode); - }); - this._iterCells(this.get("inverseCells"), function(cell){ - if (cell) cell.hide(); - }); - } else { - this._showInverseCells(); - } - dmaGlobals.three.render(); - }, - - _showInverseCells: function(){ + _updateForMode: function(){ + var cellMode = this.get("cellMode"); var inverseMode = this.get("inverseMode"); this._iterCells(this.get("cells"), function(cell){ - if (cell) { - if (inverseMode) cell.hide(); - else cell.show(); - } + if (cell) cell.drawForMode(cellMode, inverseMode); }); this._iterCells(this.get("inverseCells"), function(cell){ - if (cell) { - if (inverseMode) cell.show(); - else cell.hide(); - } + if (cell) cell.drawForMode(cellMode, inverseMode); }); dmaGlobals.three.render(); }, @@ -336,6 +314,8 @@ Lattice = Backbone.Model.extend({ var scale = this.get("scale"); this.get("basePlane").updateScale(scale); this.get("highlighter").updateScale(scale); + + //only update visible cells this._iterCells(this.get("cells"), function(cell){ if (cell) cell.updateForScale(scale); }); @@ -570,7 +550,6 @@ Lattice = Backbone.Model.extend({ var indexRel = self._subtract(invIndex, self.get("inverseCellsMin")); if (!invCells[indexRel.x][indexRel.y][indexRel.z]) { var cell = self._makeInvCellForLatticeType(invIndex, scale); - cell.hide(); invCells[indexRel.x][indexRel.y][indexRel.z] = cell; self.set("numInvCells", self.get("numInvCells")+1); }