diff options
author | Nivesh Rajbhandari | 2012-04-18 11:24:18 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-04-18 11:24:18 -0700 |
commit | e2510cba3b75bba78c587d784f39c137c1618369 (patch) | |
tree | e35fccf09cd5d59c6dcc2ad48cddd94f620bb554 /js/tools/RotateObject3DTool.js | |
parent | 7372dd9aa32e404b971efb78c354a9cdfc86c212 (diff) | |
parent | d6d72e8f519f3eb69374eb233149d3dfde2e5558 (diff) | |
download | ninja-e2510cba3b75bba78c587d784f39c137c1618369.tar.gz |
Merge branch 'refs/heads/Snapping_II' into EricMerge
Diffstat (limited to 'js/tools/RotateObject3DTool.js')
-rwxr-xr-x | js/tools/RotateObject3DTool.js | 141 |
1 files changed, 140 insertions, 1 deletions
diff --git a/js/tools/RotateObject3DTool.js b/js/tools/RotateObject3DTool.js index 27352231..25de0cd1 100755 --- a/js/tools/RotateObject3DTool.js +++ b/js/tools/RotateObject3DTool.js | |||
@@ -4,7 +4,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var Montage = require("montage/core/core").Montage; | 7 | var Montage = require("montage/core/core").Montage, |
8 | viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, | ||
9 | snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; | ||
8 | 10 | ||
9 | var Rotate3DToolBase = require("js/tools/Rotate3DToolBase").Rotate3DToolBase; | 11 | var Rotate3DToolBase = require("js/tools/Rotate3DToolBase").Rotate3DToolBase; |
10 | var toolHandleModule = require("js/stage/tool-handle"); | 12 | var toolHandleModule = require("js/stage/tool-handle"); |
@@ -55,6 +57,143 @@ exports.RotateObject3DTool = Montage.create(Rotate3DToolBase, { | |||
55 | } | 57 | } |
56 | }, | 58 | }, |
57 | 59 | ||
60 | initializeSnapping : { | ||
61 | value : function(event) | ||
62 | { | ||
63 | console.log( "initializeSnapping" ); | ||
64 | |||
65 | this._mouseDownHitRec = null; | ||
66 | this._mouseUpHitRec = null; | ||
67 | |||
68 | snapManager.clearAvoidList(); | ||
69 | snapManager.clearDragPlane(); | ||
70 | |||
71 | // the translate tool does snap align to the bounds of the object only. | ||
72 | // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method | ||
73 | snapManager.enableSnapAlign( false ); | ||
74 | |||
75 | // snap to element and snap to grid are conditionally enabled based | ||
76 | // on the snap results of the mouse down. enable everything for the first snap | ||
77 | this._snapToElements = snapManager.elementSnapEnabledAppLevel(); | ||
78 | this._snapToGrid = snapManager.gridSnapEnabledAppLevel(); | ||
79 | |||
80 | this._dragPlane = null; | ||
81 | this._clickedOnStage = false; | ||
82 | var do3DSnap = true; | ||
83 | |||
84 | if(this._handleMode === null) | ||
85 | { | ||
86 | snapManager.enableElementSnap ( true ); | ||
87 | snapManager.enableGridSnap ( true ); | ||
88 | } | ||
89 | // else | ||
90 | // { | ||
91 | // this._delta = null; | ||
92 | // special case for z-translation | ||
93 | // if(this._handleMode === 0) | ||
94 | // { | ||
95 | // this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target); | ||
96 | // snapManager.setupDragPlaneFromPlane(this._dragPlane); | ||
97 | // do3DSnap = false; | ||
98 | |||
99 | // snapManager.enableElementSnap ( false ); | ||
100 | // snapManager.enableGridSnap ( false ); | ||
101 | // } | ||
102 | // } | ||
103 | |||
104 | if (this._targets) | ||
105 | { | ||
106 | var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, | ||
107 | new WebKitPoint(event.pageX, event.pageY)); | ||
108 | |||
109 | // do the snap before setting up the avoid list to allow | ||
110 | // a snap on the mouse down | ||
111 | var hitRec = snapManager.snap(point.x, point.y, do3DSnap); | ||
112 | |||
113 | // if(this._handleMode === 2) | ||
114 | // { | ||
115 | // // translate z doesn't snap to element so hitRec's element will always be different | ||
116 | // // from what the browser says we clicked on. So, skip this check. | ||
117 | // } | ||
118 | // else | ||
119 | // { | ||
120 | // // Check that hitRec's element matches element that browser says we clicked on | ||
121 | // // TODO - This is still not working when using a handle that is on top of an | ||
122 | // // element that is not currently selected | ||
123 | // var elt = this.application.ninja.stage.GetSelectableElement(event); | ||
124 | // if(elt && (elt !== hitRec.getElement())) | ||
125 | // { | ||
126 | // hitRec = snapManager.findHitRecordForElement(elt); | ||
127 | // } | ||
128 | // if(elt === this.application.ninja.currentSelectedContainer) | ||
129 | // { | ||
130 | // this._clickedOnStage = true; | ||
131 | // } | ||
132 | // } | ||
133 | |||
134 | // we don't want to snap to selected objects during the drag | ||
135 | // var len = this._targets.length; | ||
136 | // for(var i=0; i<len; i++) | ||
137 | // { | ||
138 | // snapManager.addToAvoidList( this._targets[i].elt ); | ||
139 | // } | ||
140 | if (hitRec) | ||
141 | { | ||
142 | // disable snap attributes | ||
143 | if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT) | ||
144 | { | ||
145 | this._snapToElements = false; | ||
146 | this._snapToGrid = false; | ||
147 | } | ||
148 | else if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_CENTER) | ||
149 | { | ||
150 | snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); | ||
151 | } | ||
152 | |||
153 | if(this._handleMode === 0) | ||
154 | this.clickedObject = this._target; | ||
155 | |||
156 | // parameterize the snap point on the target | ||
157 | this._snapParam = this.parameterizeSnap( hitRec ); | ||
158 | |||
159 | if(!this._dragPlane) | ||
160 | { | ||
161 | if (this._targets.length === 1) | ||
162 | { | ||
163 | this._dragPlane = viewUtils.getUnprojectedElementPlane(this._clickedObject); | ||
164 | snapManager.setupDragPlaneFromPlane(this._dragPlane); | ||
165 | } | ||
166 | else | ||
167 | { | ||
168 | this._dragPlane = snapManager.setupDragPlanes( hitRec, true ); | ||
169 | } | ||
170 | |||
171 | } | ||
172 | |||
173 | // no quadrant snapping for the rotate tool | ||
174 | this._shouldUseQuadPt = false; | ||
175 | |||
176 | var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); | ||
177 | this._mouseDownHitRec = wpHitRec; | ||
178 | this._mouseUpHitRec = null; | ||
179 | |||
180 | var pt = hitRec.getScreenPoint(); | ||
181 | this.downPoint.x = pt[0]; | ||
182 | this.downPoint.y = pt[1]; | ||
183 | this.downPoint.z = pt[2]; | ||
184 | |||
185 | // TODO - need to figure out snapManager dependency by drawUtils. | ||
186 | // For now, bypassing by calling snapManager.drawLastHit(); | ||
187 | // drawUtils.refreshDisplay(); | ||
188 | // snapManager.drawLastHit(); | ||
189 | } | ||
190 | } | ||
191 | else | ||
192 | { | ||
193 | this.target = null; | ||
194 | } | ||
195 | } | ||
196 | }, | ||
58 | _handleToolOptionsChange: { | 197 | _handleToolOptionsChange: { |
59 | value: function(event) { | 198 | value: function(event) { |
60 | this._inLocalMode = event.detail.mode; | 199 | this._inLocalMode = event.detail.mode; |