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