/* Copyright (c) 2012, Motorola Mobility LLC. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Motorola Mobility LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Base class for the 3D rotation tools Subclass RotateObject3DTool will rotate the object that was clicked. Subclass RotateStage3DTool will rotate the stage. */ var Montage = require("montage/core/core").Montage, ModifierToolBase = require("js/tools/modifier-tool-base").ModifierToolBase, snapManager = require("js/helper-classes/3D/snap-manager").SnapManager, viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, ElementsMediator = require("js/mediators/element-mediator").ElementMediator; exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { _canSnap: { value: false }, _inLocalMode: { value: true, enumerable: true }, rotateStage: { value: false }, initializeSnapping : { value : function(event) { // console.log( "initializeSnapping" ); var selectedElements = this.application.ninja.selectedElements; if(this.rotateStage) { selectedElements = [this.application.ninja.currentDocument.model.documentRoot]; } this._mouseDownHitRec = null; this._mouseUpHitRec = null; snapManager.clearAvoidList(); snapManager.clearDragPlane(); // the translate tool does snap align to the bounds of the object only. // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method snapManager.enableSnapAlign( false ); // snap to element and snap to grid are conditionally enabled based // on the snap results of the mouse down. enable everything for the first snap this._snapToElements = snapManager.elementSnapEnabledAppLevel(); this._snapToGrid = snapManager.gridSnapEnabledAppLevel(); this._dragPlane = null; this._clickedOnStage = false; var do3DSnap = true; if(this._handleMode === null) { snapManager.enableElementSnap ( true ); snapManager.enableGridSnap ( true ); } // else // { // this._delta = null; // special case for z-translation // if(this._handleMode === 0) // { // this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target); // snapManager.setupDragPlaneFromPlane(this._dragPlane); // do3DSnap = false; // snapManager.enableElementSnap ( false ); // snapManager.enableGridSnap ( false ); // } // } if (selectedElements.length) { var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); // do the snap before setting up the avoid list to allow // a snap on the mouse down var hitRec = snapManager.snap(point.x, point.y, do3DSnap); // if(this._handleMode === 2) // { // // translate z doesn't snap to element so hitRec's element will always be different // // from what the browser says we clicked on. So, skip this check. // } // else // { // // Check that hitRec's element matches element that browser says we clicked on // // TODO - This is still not working when using a handle that is on top of an // // element that is not currently selected // var elt = this.application.ninja.stage.GetSelectableElement(event); // if(elt && (elt !== hitRec.getElement())) // { // hitRec = snapManager.findHitRecordForElement(elt); // } // if(elt === this.application.ninja.currentDocument.model.domContainer) // { // this._clickedOnStage = true; // } // } // we don't want to snap to selected objects during the drag // var len = this._targets.length; // for(var i=0; i