aboutsummaryrefslogtreecommitdiff
path: root/js/tools/modifier-tool-base.js
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/tools/modifier-tool-base.js
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/tools/modifier-tool-base.js')
-rw-r--r--js/tools/modifier-tool-base.js1007
1 files changed, 1007 insertions, 0 deletions
diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js
new file mode 100644
index 00000000..f78e99c8
--- /dev/null
+++ b/js/tools/modifier-tool-base.js
@@ -0,0 +1,1007 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7var Montage = require("montage/core/core").Montage,
8 DrawingTool = require("js/tools/drawing-tool").DrawingTool,
9 snapManager = require("js/helper-classes/3D/snap-manager").SnapManager,
10 viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils,
11 vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils,
12 drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils,
13 Properties3D = ("js/models/properties-3d").Properties3D;
14
15exports.ModifierToolBase = Montage.create(DrawingTool, {
16
17 //-------------------------------------------------------------------------
18 // Drawing Mode Info
19 drawingFeedback: { value: { mode: "Draw3D", type: "rectangle" } },
20
21 //-------------------------------------------------------------------------
22 // Snapping-specific properties
23 _canSnap: { value: true },
24 _dragPlane: { value: null },
25 _snapParam: { value: null },
26 _snapIndex: { value: -1 },
27 _useQuadPt: { value: false },
28
29 // we set snapping capabilities depending on the tool.
30 // The following variables are set in a tool's initializeSnapping method called on mouse down.
31 _snapToElements: { value: true },
32 _snapToGrid: { value: true },
33
34 _clickedObject : {value : null },
35 clickedObject:
36 {
37 get: function () {
38 return this._clickedObject;
39 },
40 set: function (value) {
41 if(value === this.application.ninja.currentDocument.documentRoot)
42 {
43 this._clickedObject = this._target;
44 }
45 else
46 {
47 this._clickedObject = value;
48 }
49
50 if(value)
51 {
52 this._startMat = viewUtils.getMatrixFromElement(this._clickedObject);
53 }
54 else
55 {
56 this._startMat = null;
57 }
58 }
59 },
60
61 _getObjectBeingTracked :
62 {
63 value: function(hitRec)
64 {
65 var elt = hitRec.getElt();
66 if(elt === this.application.ninja.currentDocument.documentRoot)
67 {
68 elt = this._target;
69 }
70
71 return elt;
72 }
73 },
74
75 drawWithoutSnapping:
76 {
77 value: function(event)
78 {
79 // override in subclasses
80 }
81 },
82
83 initializeSnapping:
84 {
85 value: function(event)
86 {
87 this._mouseDownHitRec = null;
88 this._mouseUpHitRec = null;
89
90 snapManager.clearAvoidList();
91 snapManager.clearDragPlane();
92
93 // the translate tool does snap align to the bounds of the object only.
94 // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method
95 snapManager.enableSnapAlign( false );
96
97 // snap to element and snap to grid are conditionally enabled based
98 // on the snap results of the mouse down. enable everything for the first snap
99 this._snapToElements = snapManager.elementSnapEnabledAppLevel();
100 this._snapToGrid = snapManager.gridSnapEnabledAppLevel();
101
102 this._dragPlane = null;
103 var do3DSnap = true;
104
105// if(this._handleMode === null)
106// {
107// if(!this._activateOriginHandle)
108// {
109// this.doSelection(event);
110
111 snapManager.enableElementSnap ( true );
112// snapManager.enableGridSnap ( true );
113// }
114// }
115// else
116// {
117// this._matL = this._handles[this._handleMode]._matL.slice(0);
118// this._planeEq = this._handles[this._handleMode]._planeEq.slice(0);
119// this._dirVecL = this._handles[this._handleMode]._dirVecL.slice(0);
120// this.m_startPoint = MathUtils.getLocalPoint(event.layerX, event.layerY, this._planeEq, this._matL);
121// if(!this.m_startPoint)
122// {
123// this.m_startPoint = [this.m_xStart, this.m_yStart];
124// }
125// }
126
127
128 if(this._targets)
129 {
130 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas,
131 new WebKitPoint(event.pageX, event.pageY));
132 // do the snap before setting up the avoid list to allow
133 // a snap on the mouse down
134 var hitRec = snapManager.snap(point.x, point.y, do3DSnap);
135
136 // we don't want to snap to selected objects during the drag
137 var len = this._targets.length;
138 for(var i=0; i<len; i++)
139 {
140 snapManager.addToAvoidList( this._targets[i].elt );
141 }
142 if (hitRec)
143 {
144 // disable snap attributes
145 if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT)
146 {
147 this._snapToElements = false;
148 this._snapToGrid = false;
149 }
150 else if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_CENTER)
151 {
152 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() );
153 }
154
155 // parameterize the snap point on the target
156 this._snapParam = this.parameterizeSnap( hitRec );
157
158 if(!this._dragPlane)
159 {
160// if( this._inLocalMode && (this._startMatArray.length === 1) )
161// {
162// this._dragPlane = viewUtils.getUnprojectedElementPlane(this._clickedObject);
163// snapManager.setupDragPlaneFromPlane(this._dragPlane);
164// }
165// else
166// {
167 this._dragPlane = snapManager.setupDragPlanes( hitRec );
168// }
169 }
170
171 var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane );
172 this._mouseDownHitRec = wpHitRec;
173 this._mouseUpHitRec = null;
174
175 var pt = hitRec.getScreenPoint();
176 this.downPoint.x = pt[0];
177 this.downPoint.y = pt[1];
178
179 snapManager.drawLastHit();
180
181 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() );
182 snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() );
183 snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() );
184 }
185 }
186 else
187 {
188 this.target = null;
189 }
190 }
191 },
192
193 /*
194 * The parameterization is based on the position of the
195 * snap point in pre-transformed element screen space
196 */
197 parameterizeSnap:
198 {
199 value: function( hitRec )
200 {
201 var paramPt = [0,0,0];
202 var elt = this._getObjectBeingTracked(hitRec);
203 if (elt)
204 {
205 this.clickedObject = elt;
206
207 var worldPt = hitRec.calculateStageWorldPoint();
208 MathUtils.makeDimension4( worldPt );
209 var mat = viewUtils.getObjToStageWorldMatrix( elt, true );
210 if(mat)
211 {
212 var invMat = glmat4.inverse(mat, []);
213 var scrPt = MathUtils.transformHomogeneousPoint( worldPt, invMat );
214 scrPt = MathUtils.applyHomogeneousCoordinate( scrPt );
215
216 var bounds = viewUtils.getElementViewBounds3D( elt );
217 var x0 = bounds[0][0], x1 = bounds[3][0],
218 y0 = bounds[0][1], y1 = bounds[1][1];
219 var dx = x1 - x0, dy = y1 - y0;
220 var u = 0, v = 0;
221 if (MathUtils.fpSign(dx) != 0)
222 u = (scrPt[0] - x0) / dx;
223 if (MathUtils.fpSign(dy) != 0)
224 v = (scrPt[1] - y0) / dy;
225
226 paramPt[0] = u;
227