aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-04-18 15:48:20 -0700
committerNivesh Rajbhandari2012-04-18 15:48:20 -0700
commit1f2d84716ddca3cfc9e5457f67ec1b007b3455a8 (patch)
tree8159c0b679e7acc276732610b8b05f0804edb4c4
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>
-rwxr-xr-xjs/tools/Rotate3DToolBase.js143
-rwxr-xr-xjs/tools/RotateObject3DTool.js142
2 files changed, 143 insertions, 142 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)
diff --git a/js/tools/RotateObject3DTool.js b/js/tools/RotateObject3DTool.js
index c1ddb286..ec2fcc0c 100755
--- a/js/tools/RotateObject3DTool.js
+++ b/js/tools/RotateObject3DTool.js
@@ -58,148 +58,6 @@ exports.RotateObject3DTool = Montage.create(Rotate3DToolBase, {
58 } 58 }
59 }, 59 },
60 60
61 initializeSnapping : {
62 value : function(event)
63 {
64// console.log( "initializeSnapping" );
65
66 var selectedElements = this.application.ninja.selectedElements;
67 if(this.rotateStage) {
68 selectedElements = [this.application.ninja.currentDocument.documentRoot];
69 }
70
71 this._mouseDownHitRec = null;
72 this._mouseUpHitRec = null;
73
74 snapManager.clearAvoidList();
75 snapManager.clearDragPlane();
76
77 // the translate tool does snap align to the bounds of the object only.
78 // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method
79 snapManager.enableSnapAlign( false );
80
81 // snap to element and snap to grid are conditionally enabled based
82 // on the snap results of the mouse down. enable everything for the first snap
83 this._snapToElements = snapManager.elementSnapEnabledAppLevel();
84 this._snapToGrid = snapManager.gridSnapEnabledAppLevel();
85
86 this._dragPlane = null;
87 this._clickedOnStage = false;
88 var do3DSnap = true;
89
90 if(this._handleMode === null)
91 {
92 snapManager.enableElementSnap ( true );
93 snapManager.enableGridSnap ( true );
94 }
95// else
96// {
97// this._delta = null;
98 // special case for z-translation
99// if(this._handleMode === 0)
100// {
101// this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target);
102// snapManager.setupDragPlaneFromPlane(this._dragPlane);
103// do3DSnap = false;
104
105// snapManager.enableElementSnap ( false );
106// snapManager.enableGridSnap ( false );
107// }
108// }
109
110 if (selectedElements.length)
111 {
112 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas,
113 new WebKitPoint(event.pageX, event.pageY));
114
115 // do the snap before setting up the avoid list to allow
116 // a snap on the mouse down
117 var hitRec = snapManager.snap(point.x, point.y, do3DSnap);
118
119// if(this._handleMode === 2)
120// {
121// // translate z doesn't snap to element so hitRec's element will always be different
122// // from what the browser says we clicked on. So, skip this check.
123// }
124// else
125// {
126// // Check that hitRec's element matches element that browser says we clicked on
127// // TODO - This is still not working when using a handle that is on top of an
128// // element that is not currently selected
129//