aboutsummaryrefslogtreecommitdiff
path: root/js/tools/drawing-tool-base.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/drawing-tool-base.js')
-rwxr-xr-xjs/tools/drawing-tool-base.js850
1 files changed, 425 insertions, 425 deletions
diff --git a/js/tools/drawing-tool-base.js b/js/tools/drawing-tool-base.js
index b2c8e6b4..e4f4d5d5 100755
--- a/js/tools/drawing-tool-base.js
+++ b/js/tools/drawing-tool-base.js
@@ -58,32 +58,32 @@ exports.DrawingToolBase = Montage.create(Component, {
58 */ 58 */
59 getInitialSnapPoint: { 59 getInitialSnapPoint: {
60 value: function(x, y, shapeCanvas) 60 value: function(x, y, shapeCanvas)
61 { 61 {
62 // update the snap settings 62 // update the snap settings
63 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); 63 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() );
64 snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() ); 64 snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() );
65 snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() ); 65 snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() );
66 66
67 // do the snap 67 // do the snap
68 this.dragPlane = null; 68 this.dragPlane = null;
69 var hitRec = snapManager.snap(x, y, true); 69 var hitRec = snapManager.snap(x, y, true);
70 if (hitRec) { 70 if (hitRec) {
71 if (shapeCanvas) 71 if (shapeCanvas)
72 { 72 {
73 this.dragPlane = viewUtils.getUnprojectedElementPlane( shapeCanvas ); 73 this.dragPlane = viewUtils.getUnprojectedElementPlane( shapeCanvas );
74 snapManager.setupDragPlaneFromPlane( this.dragPlane ); 74 snapManager.setupDragPlaneFromPlane( this.dragPlane );
75 } 75 }
76 else 76 else
77 { 77 {
78 this.dragPlane = snapManager.setupDragPlanes( hitRec, true ); 78 this.dragPlane = snapManager.setupDragPlanes( hitRec, true );
79 } 79 }
80// console.log( "drag plane: " + this.dragPlane ); 80// console.log( "drag plane: " + this.dragPlane );
81 81
82 var wpHitRec = hitRec.convertToWorkingPlane( this.dragPlane ); 82 var wpHitRec = hitRec.convertToWorkingPlane( this.dragPlane );
83 var pt = hitRec.getScreenPoint(); 83 var pt = hitRec.getScreenPoint();
84 84
85 return( [wpHitRec, pt[0], pt[1]] ); 85 return( [wpHitRec, pt[0], pt[1]] );
86 } 86 }
87 } 87 }
88 }, 88 },
89 89
@@ -93,27 +93,27 @@ exports.DrawingToolBase = Montage.create(Component, {
93 getUpdatedSnapPoint: { 93 getUpdatedSnapPoint: {
94 value: function(x,y, snap3d, downHitRec) { 94 value: function(x,y, snap3d, downHitRec) {
95 // update the snap settings 95 // update the snap settings
96 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); 96 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() );
97 snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() ); 97 snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() );
98 snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() ); 98 snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() );
99 99
100 var hitRec = snapManager.snap(x, y, snap3d ); 100 var hitRec = snapManager.snap(x, y, snap3d );
101 if (hitRec) { 101 if (hitRec) {
102// if ((hitRec.getType() !== hitRec.SNAP_TYPE_STAGE) && !hitRec.isSomeGridTypeSnap()) { 102// if ((hitRec.getType() !== hitRec.SNAP_TYPE_STAGE) && !hitRec.isSomeGridTypeSnap()) {
103// hitRec = hitRec.convertToWorkingPlane( snapManager.getDragPlane() ); 103// hitRec = hitRec.convertToWorkingPlane( snapManager.getDragPlane() );
104// } 104// }
105// 105//
106// if(downHitRec !== null) { 106// if(downHitRec !== null) {
107// // if we are working off-plane, do a snap to the projected locations of the geometry 107// // if we are working off-plane, do a snap to the projected locations of the geometry
108// var thePlane = workingPlane; 108// var thePlane = workingPlane;
109// if (snapManager.hasDragPlane()) 109// if (snapManager.hasDragPlane())
110// { 110// {
111// thePlane = snapManager.getDragPlane(); 111// thePlane = snapManager.getDragPlane();
112// } 112// }
113// 113//
114// // Return the up HitRec 114// // Return the up HitRec
115// return hitRec; 115// return hitRec;
116// } else { 116// } else {
117// return null; 117// return null;
118// } 118// }
119 if(downHitRec) { 119 if(downHitRec) {
@@ -130,24 +130,24 @@ exports.DrawingToolBase = Montage.create(Component, {
130 value: function(x,y, snap3d, downHitRec) { 130 value: function(x,y, snap3d, downHitRec) {
131 131
132 132
133 // do the first snap 133 // do the first snap
134 var hitRec = snapManager.snap(x, y, snap3d ); 134 var hitRec = snapManager.snap(x, y, snap3d );
135 if (hitRec) { 135 if (hitRec) {
136 if ((hitRec.getType() !== hitRec.SNAP_TYPE_STAGE) && !hitRec.isSomeGridTypeSnap()) { 136 if ((hitRec.getType() !== hitRec.SNAP_TYPE_STAGE) && !hitRec.isSomeGridTypeSnap()) {
137 hitRec = hitRec.convertToWorkingPlane( snapManager.getDragPlane() ); 137 hitRec = hitRec.convertToWorkingPlane( snapManager.getDragPlane() );
138 } 138 }
139 139
140 if(downHitRec !== null) { 140 if(downHitRec !== null) {
141 // if we are working off-plane, do a snap to the projected locations of the geometry 141 // if we are working off-plane, do a snap to the projected locations of the geometry
142 var thePlane = workingPlane; 142 var thePlane = workingPlane;
143 if (snapManager.hasDragPlane()) 143 if (snapManager.hasDragPlane())
144 { 144 {
145 thePlane = snapManager.getDragPlane(); 145 thePlane = snapManager.getDragPlane();
146 } 146 }
147 147
148 // Return the up HitRec 148 // Return the up HitRec
149 return hitRec; 149 return hitRec;
150 } else { 150 } else {
151 return null; 151 return null;
152 } 152 }
153 } 153 }
@@ -156,20 +156,20 @@ exports.DrawingToolBase = Montage.create(Component, {
156 156
157 157
158 setDownHitRec: { 158 setDownHitRec: {
159 value: function (x, y, do3DSnap) { 159 value: function (x, y, do3DSnap) {
160 var hitRec = snapManager.snap(x, y, do3DSnap ); 160 var hitRec = snapManager.snap(x, y, do3DSnap );
161 if (hitRec) { 161 if (hitRec) {
162 if ((hitRec.getType() != hitRec.SNAP_TYPE_STAGE) && !hitRec.isSomeGridTypeSnap()) { 162 if ((hitRec.getType() != hitRec.SNAP_TYPE_STAGE) && !hitRec.isSomeGridTypeSnap()) {
163 //hitRec = hitRec.convertToWorkingPlane( workingPlane ); 163 //hitRec = hitRec.convertToWorkingPlane( workingPlane );
164 snapManager.setupDragPlanes(hitRec); 164 snapManager.setupDragPlanes(hitRec);
165 hitRec = hitRec.convertToWorkingPlane( snapManager.getDragPlane() ); 165 hitRec = hitRec.convertToWorkingPlane( snapManager.getDragPlane() );
166 } 166 }
167 167
168 return hitRec; 168 return hitRec;
169 169
170 } 170 }
171 } 171 }
172 }, 172 },
173 173
174 drawSnapLastHit: { 174 drawSnapLastHit: {
175 value: function() { 175 value: function() {
@@ -208,86 +208,86 @@ exports.DrawingToolBase = Montage.create(Component, {
208 208
209 getCompletePoints: { 209 getCompletePoints: {
210 value: function(hitRec0, hitRec1) { 210 value: function(hitRec0, hitRec1) {
211 if (hitRec0 && hitRec1) { 211 if (hitRec0 && hitRec1) {
212 212
213 // get the 2 snap points in plane space 213 // get the 2 snap points in plane space
214 var p0 = hitRec0.getLocalPoint(), 214 var p0 = hitRec0.getLocalPoint(),
215 p1 = hitRec1.getLocalPoint(); 215 p1 = hitRec1.getLocalPoint();
216 216
217 var stageOffset = viewUtils.getElementOffset(this.application.ninja.currentDocument.model.documentRoot); 217 var stageOffset = viewUtils.getElementOffset(this.application.ninja.currentDocument.model.documentRoot);
218 viewUtils.setViewportObj(this.application.ninja.currentDocument.model.documentRoot); 218 viewUtils.setViewportObj(this.application.ninja.currentDocument.model.documentRoot);
219 219
220 // get the matrix taking the local hit point in plane space 220 // get the matrix taking the local hit point in plane space
221 // to world space of whatever element it is in. 221 // to world space of whatever element it is in.
222 var planeMat = hitRec0.getPlaneMatrix(); 222 var planeMat = hitRec0.getPlaneMatrix();
223 223
224 // get the center of the circle in stage world space 224 // get the center of the circle in stage world space
225 var s0 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(p0,hitRec0.getPlaneMatrix()), hitRec0.getElt() ), 225 var s0 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(p0,hitRec0.getPlaneMatrix()), hitRec0.getElt() ),
226 s1 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(p1,hitRec1.getPlaneMatrix()), hitRec1.getElt() ); 226 s1 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(p1,hitRec1.getPlaneMatrix()), hitRec1.getElt() );
227 227
228 // apply the projected snap points 228 // apply the projected snap points
229 var s0Proj = false, s1Proj = false; 229 var s0Proj = false, s1Proj = false;
230 230
231 // find a "reasonable" plane 231 // find a "reasonable" plane
232 var thePlane = workingPlane.slice(0); 232 var thePlane = workingPlane.slice(0);
233 if (snapManager.hasDragPlane()) { 233 if (snapManager.hasDragPlane()) {
234 thePlane = snapManager.getDragPlane(); 234 thePlane = snapManager.getDragPlane();
235 } 235 }
236 236
237 var d0 = vecUtils.vecDot( 3, thePlane, s0 ) + thePlane[3], 237 var d0 = vecUtils.vecDot( 3, thePlane, s0 ) + thePlane[3],
238 d1 = vecUtils.vecDot( 3, thePlane, s1 ) + thePlane[3]; 238 d1 = vecUtils.vecDot( 3, thePlane, s1 ) + thePlane[3];
239 var sign0 = MathUtils.fpSign( d0 ), sign1 = MathUtils.fpSign( d1 ); 239 var sign0 = MathUtils.fpSign( d0 ), sign1 = MathUtils.fpSign( d1 );
240 if ((sign0 !== 0) || (sign1 !== 0)) { 240 if ((sign0 !== 0) || (sign1 !== 0)) {
241 // we need to pick a different plane 241 // we need to pick a different plane
242 if ( MathUtils.fpCmp(d0,d1) === 0 ) {