From 8d8b4d41fd4b772cabc6d66e2f946480ecf97848 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Tue, 8 Sep 2015 21:00:02 -0400 Subject: [PATCH] focus on lattice toggle --- js/lattice/Lattice.js | 11 +++++++++-- js/menus/templates/NavViewMenu.html | 1 + js/models/AppState.js | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 8ae26fc7..410ce53f 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -35,7 +35,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre this.listenTo(this, "change:cellSeparation", this._updateCellSeparation); this.listenTo(appState, "change:currentNav", this._navChanged); - this.listenTo(this, "change:cellsMin change:cellsMax", this._updateThreeViewControls); + this.listenTo(this, "change:cellsMin change:cellsMax", function(){ + this.updateThreeViewTarget(); + }); this._updateLatticeType(); }, @@ -105,7 +107,12 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre if (globals.basePlane) globals.basePlane.set("zIndex", 0, {silent:silent}); }, - _updateThreeViewControls: function(){ + updateThreeViewTarget: function(target){ + if (target) { + globals.threeView.setOrbitControlsFor(target); + return; + } + if (!appState.get("focusOnLattice")) return; var cellsMin = this.get("cellsMin"); var cellsMax = this.get("cellsMax"); if (cellsMax === null || cellsMin === null) return; diff --git a/js/menus/templates/NavViewMenu.html b/js/menus/templates/NavViewMenu.html index d90881c8..49ca72b5 100644 --- a/js/menus/templates/NavViewMenu.html +++ b/js/menus/templates/NavViewMenu.html @@ -13,6 +13,7 @@ <li><a class="appState boolProperty" data-property="basePlaneIsVisible" href="#">Sketch Plane</a></li> <li><a class="appState boolProperty" data-property="highlighterIsVisible" href="#">Hover Tool</a></li> <li><a class="appState boolProperty" data-property="axesAreVisible" href="#">Axes</a></li> + <li><a class="appState boolProperty" data-property="focusOnLattice" href="#">Center on Lattice</a></li> <li><a id="reset3DView" href="#">Reset 3D Navigation</a></li> </ul> </li> diff --git a/js/models/AppState.js b/js/models/AppState.js index 42790d02..a55d2494 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -25,6 +25,7 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'], fu basePlaneIsVisible:true, highlighterIsVisible:true, axesAreVisible: false, + focusOnLattice: true, //key bindings shift: false, @@ -63,6 +64,7 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'], fu this.listenTo(this, "change:gikLength", this._gikLengthChanged); this.listenTo(this, "change:turnOffRendering", this._renderingOnOff); this.listenTo(this, "change:axesAreVisible", this._showAxes); + this.listenTo(this, "change:focusOnLattice", this._focusOnLattice); this.downKeys = {};//track keypresses to prevent repeat keystrokes on hold this.lastCellMode = this.get("cellMode");//store this to toggle on/off hide mode @@ -163,6 +165,14 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'], fu }) }, + _focusOnLattice: function(){ + if (this.get("focusOnLattice")) this.lattice.updateThreeViewTarget(); + else { + this.lattice.updateThreeViewTarget(new THREE.Vector3(0,0,0)); + this.reset3DNavigation(); + } + }, + reset3DNavigation: function(){ three.resetCameraPosition(); }, -- GitLab