From fde9fce2f4ee36f059d6c5afa6875c96d94c1bce Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Fri, 12 Jun 2015 14:53:06 -0700 Subject: [PATCH] delete mode in part view --- js/cells/DMACell.js | 16 ++++++++++++---- js/cells/supercells/CompositeCell.js | 13 ++++++++----- js/cells/supercells/DMASuperCell.js | 10 +++++++--- js/cells/supercells/GIKSuperCell.js | 4 ++-- js/highlighter/Highlighter.js | 2 +- js/lattice/GIKLattice.js | 2 ++ js/parts/DMAPart.js | 6 +++++- 7 files changed, 37 insertions(+), 16 deletions(-) diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 1b4989c5..1f94204c 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -153,15 +153,23 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], }; DMACell.prototype.setDeleteMode = function(state){ - if (this.superCell) { - this.superCell.setDeleteMode(state); - return; - } + var material; if (state) material = globals.materials.deleteMaterial; else material = this.getMaterial(); if (!material) return;//cell may be deleted by now if (this.object3D.children[0].material == material) return; + + if (this.cells){ + this._loopCells(function(cell){ + if (cell) cell.setDeleteMode(state); + }); + } + if (this.parts){ + _.each(this.parts, function(part){ + if (part) part.setMaterial(material); + }); + } this.object3D.children[0].material = material; three.render(); }; diff --git a/js/cells/supercells/CompositeCell.js b/js/cells/supercells/CompositeCell.js index ab6d23af..7292d349 100644 --- a/js/cells/supercells/CompositeCell.js +++ b/js/cells/supercells/CompositeCell.js @@ -11,14 +11,17 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', }; CompositeCell.prototype = Object.create(DMASuperCell.prototype); - CompositeCell.prototype._makeSubCellForIndex = function(json){ - return null; - }; - + CompositeCell.prototype._makeSubCellForIndex = function(json, callback){ + require([], function(){ + }); + }; CompositeCell.prototype._getGeometry = function(){ - return new THREE.BoxGeometry(); + var dimensions = appState.get("superCellRange"); + var geo = new THREE.BoxGeometry(dimensions.x, dimensions.y, dimensions.z); + geo.applyMatrix(new THREE.Matrix4().makeTranslation(dimensions.x/2-0.5, dimensions.y/2-0.5, dimensions.z/2-0.5)); + return geo; }; CompositeCell.prototype._buildWireframe = function(mesh){ diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js index 0d8c7fa0..fcbc3d45 100644 --- a/js/cells/supercells/DMASuperCell.js +++ b/js/cells/supercells/DMASuperCell.js @@ -29,15 +29,19 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], cells[x].push([]); for (var z=0;z<range.z;z++){ //child cells add themselves to object3D - if (material.cells && material.cells[x][y][z]) cells[x][y].push(this._makeSubCellForIndex(new THREE.Vector3(x, y, z), this, material.cells[x][y][z].material)); - else cells[x][y].push(this._makeSubCellForIndex({index: new THREE.Vector3(x, y, z), material:this.material})); + var material = this.material; + if (material.cells && material.cells[x][y][z]) material = material.cells[x][y][z].material; + cells[x][y].push(null); + this._makeSubCellForIndex({index: new THREE.Vector3(x,y,z)}, function(cell){ + cells[x][y][z] = cell; + }); } } } return cells; }; - DMASuperCell.prototype._makeSubCellForIndex = function(json){ + DMASuperCell.prototype._makeSubCellForIndex = function(json, callback){ return null;//override in subclasses }; diff --git a/js/cells/supercells/GIKSuperCell.js b/js/cells/supercells/GIKSuperCell.js index 4d28f4b0..1f4cad71 100644 --- a/js/cells/supercells/GIKSuperCell.js +++ b/js/cells/supercells/GIKSuperCell.js @@ -21,8 +21,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', }; GIKSuperCell.prototype = Object.create(DMASuperCell.prototype); - GIKSuperCell.prototype._makeSubCellForIndex = function(json){ - return new GIKCell(json, this); + GIKSuperCell.prototype._makeSubCellForIndex = function(json, callback){ + callback(new GIKCell(json, this)); }; GIKSuperCell.prototype._rotateCell = function(object3D){ diff --git a/js/highlighter/Highlighter.js b/js/highlighter/Highlighter.js index 884b5b52..2d332e66 100644 --- a/js/highlighter/Highlighter.js +++ b/js/highlighter/Highlighter.js @@ -72,7 +72,7 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', ' setDeleteMode: function(object, state){ if (object && object.setDeleteMode) { if (state) this.hide(); - this.highlightedObject.setDeleteMode(state); + object.getParent().setDeleteMode(state); } }, diff --git a/js/lattice/GIKLattice.js b/js/lattice/GIKLattice.js index ef08736f..84465643 100644 --- a/js/lattice/GIKLattice.js +++ b/js/lattice/GIKLattice.js @@ -14,6 +14,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre require(['superCellHighlighter'], function(superCellHighlighter){ globals.highlighter = new superCellHighlighter(); }); + appState.set("superCellRange", new THREE.Vector3(4, 1, 1)); + }, getIndexForPosition: function(absPosition){ diff --git a/js/parts/DMAPart.js b/js/parts/DMAPart.js index b280b22f..7acd756b 100644 --- a/js/parts/DMAPart.js +++ b/js/parts/DMAPart.js @@ -31,8 +31,12 @@ define(['underscore', 'three'], function(_, THREE){ return this.parentCell.getMaterial(); }; + DMAPart.prototype.setMaterial = function(material){ + this.mesh.material = material; + }; + DMAPart.prototype.destroy = function(){ - if (this.mesh) { + if (this.mesh) {d this.parentCell.removeChildren(this.mesh); this.mesh = null; } -- GitLab