aboutsummaryrefslogtreecommitdiff
path: root/js/tools/Rotate3DToolBase.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-04-18 15:48:20 -0700
committerNivesh Rajbhandari2012-04-18 15:48:20 -0700
commit1f2d84716ddca3cfc9e5457f67ec1b007b3455a8 (patch)
tree8159c0b679e7acc276732610b8b05f0804edb4c4 /js/tools/Rotate3DToolBase.js
parente6bdea62cff68837239c1be579926693c1aa7bdf (diff)
downloadninja-1f2d84716ddca3cfc9e5457f67ec1b007b3455a8.tar.gz
Moving initialzeSnapping routine from RotateObject3DTool tool to Rotate3DToolBase so Rotate Stage uses the same code.
Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/tools/Rotate3DToolBase.js')
-rwxr-xr-xjs/tools/Rotate3DToolBase.js143
1 files changed, 143 insertions, 0 deletions
diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js
index 04bdc946..4fa8657e 100755
--- a/js/tools/Rotate3DToolBase.js
+++ b/js/tools/Rotate3DToolBase.js
@@ -25,6 +25,149 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
25 value: false 25 value: false
26 }, 26 },
27 27
28 initializeSnapping : {
29 value : function(event)
30 {
31// console.log( "initializeSnapping" );
32
33 var selectedElements = this.application.ninja.selectedElements;
34 if(this.rotateStage) {
35 selectedElements = [this.application.ninja.currentDocument.documentRoot];
36 }
37
38 this._mouseDownHitRec = null;
39 this._mouseUpHitRec = null;
40
41 snapManager.clearAvoidList();
42 snapManager.clearDragPlane();
43
44 // the translate tool does snap align to the bounds of the object only.
45 // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method
46 snapManager.enableSnapAlign( false );
47
48 // snap to element and snap to grid are conditionally enabled based
49 // on the snap results of the mouse down. enable everything for the first snap
50 this._snapToElements = snapManager.elementSnapEnabledAppLevel();
51 this._snapToGrid = snapManager.gridSnapEnabledAppLevel();
52
53 this._dragPlane = null;
54 this._clickedOnStage = false;
55 var do3DSnap = true;
56
57 if(this._handleMode === null)
58 {
59 snapManager.enableElementSnap ( true );
60 snapManager.enableGridSnap ( true );
61 }
62// else
63// {
64// this._delta = null;
65 // special case for z-translation
66// if(this._handleMode === 0)
67// {
68// this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target);
69// snapManager.setupDragPlaneFromPlane(this._dragPlane);
70// do3DSnap = false;
71
72// snapManager.enableElementSnap ( false );
73// snapManager.enableGridSnap ( false );
74// }
75// }
76
77 if (selectedElements.length)
78 {
79 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas,
80 new WebKitPoint(event.pageX, event.pageY));
81
82 // do the snap before setting up the avoid list to allow
83 // a snap on the mouse down
84 var hitRec = snapManager.snap(point.x, point.y, do3DSnap);
85
86// if(this._handleMode === 2)
87// {
88// // translate z doesn't snap to element so hitRec's element will always be different
89// // from what the browser says we clicked on. So, skip this check.
90// }
91// else
92// {
93// // Check that hitRec's element matches element that browser says we clicked on
94// // TODO - This is still not working when using a handle that is on top of an
95// // element that is not currently selected
96// var elt = this.application.ninja.stage.GetSelectableElement(event);
97// if(elt && (elt !== hitRec.getElement()))
98// {
99// hitRec = snapManager.findHitRecordForElement(elt);
100// }
101// if(elt === this.application.ninja.currentSelectedContainer)
102// {
103// this._clickedOnStage = true;
104// }
105// }
106
107 // we don't want to snap to selected objects during the drag
108// var len = this._targets.length;
109// for(var i=0; i<len; i++)
110// {
111// snapManager.addToAvoidList( this._targets[i].elt );
112// }
113 if (hitRec)
114 {
115 // disable snap attributes
116 if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT)
117 {
118 this._snapToElements = false;
119 this._snapToGrid = false;
120 }
121 else if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_CENTER)
122 {
123 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() );
124 }
125
126 if(this._handleMode === 0)
127 this.clickedObject = this._target;
128
129 // parameterize the snap point on the target
130 this._snapParam = this.parameterizeSnap( hitRec );
131
132 if(!this._dragPlane)
133 {
134 if (selectedElements.length === 1)
135 {
136 this._dragPlane = viewUtils.getUnprojectedElementPlane(this._clickedObject);
137 snapManager.setupDragPlaneFromPlane(this._dragPlane);
138 }
139 else
140 {
141 this._dragPlane = snapManager.setupDragPlanes( hitRec, true );
142 }
143
144 }
145
146 // no quadrant snapping for the rotate tool
147 this._shouldUseQuadPt = false;
148
149 var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane );
150 this._mouseDownHitRec = wpHitRec;
151 this._mouseUpHitRec = null;
152
153 var pt = hitRec.getScreenPoint();
154 this.downPoint.x = pt[0];
155 this.downPoint.y = pt[1];
156 this.downPoint.z = pt[2];
157
158 // TODO - need to figure out snapManager dependency by drawUtils.
159 // For now, bypassing by calling snapManager.drawLastHit();
160// drawUtils.refreshDisplay();
161// snapManager.drawLastHit();
162 }
163 }
164 else
165 {
166 this.target = null;
167 }
168 }
169 },
170
28 drawWithoutSnapping: 171 drawWithoutSnapping:
29 { 172 {
30 value: function(event) 173 value: function(event)