aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/snap-manager.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/3D/snap-manager.js')
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js44
1 files changed, 32 insertions, 12 deletions
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index a755e9e2..02e81a62 100755
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -123,7 +123,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
123 /////////////////////////////////////////////////////////////////////// 123 ///////////////////////////////////////////////////////////////////////
124 initialize: { 124 initialize: {
125 value: function() { 125 value: function() {
126 this.eventManager.addEventListener("elementDeleted", this, false); 126 this.eventManager.addEventListener("elementsRemoved", this, false);
127 this.eventManager.addEventListener("elementReplaced", this, false);
127 } 128 }
128 }, 129 },
129 130
@@ -163,12 +164,26 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
163 }, 164 },
164 165
165 166
166 handleElementDeleted: { 167 handleElementsRemoved: {
167 value: function(event) { 168 value: function(event) {
168 this.removeElementFrom2DCache(event.detail); 169 var self = this, elements = event.detail;
170
171 if(Array.isArray(elements)) {
172 elements = Array.prototype.slice.call(elements, 0);
173 elements.forEach(function(element) {
174 self.removeElementFrom2DCache(element);
175 });
176 } else {
177 this.removeElementFrom2DCache(elements);
178 }
169 } 179 }
170 }, 180 },
171 181
182 handleElementReplaced: {
183 value: function(event) {
184 this._isCacheInvalid = true;
185 }
186 },
172 187
173 setCurrentStage: { 188 setCurrentStage: {
174 value: function(stage) { 189 value: function(stage) {
@@ -214,7 +229,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
214 parentPt = [quadPt[0], quadPt[1], 0.0]; 229 parentPt = [quadPt[0], quadPt[1], 0.0];
215 else 230 else
216 parentPt = [xScreen, yScreen, 0.0]; 231 parentPt = [xScreen, yScreen, 0.0];
217 var vec = viewUtils.parentToChildVec(parentPt, stage); 232
233 var eyePt = [];
234 var vec = viewUtils.parentToChildVec(parentPt, stage, eyePt);
218 if (vec) 235 if (vec)
219 { 236 {
220 // activate the drag working plane 237 // activate the drag working plane
@@ -226,7 +243,6 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
226 var wp = currentWorkingPlane.slice(0); 243 var wp = currentWorkingPlane.slice(0);
227 var mat = viewUtils.getMatrixFromElement(stage); 244 var mat = viewUtils.getMatrixFromElement(stage);
228 wp = MathUtils.transformPlane(wp, mat); 245 wp = MathUtils.transformPlane(wp, mat);
229 var eyePt = viewUtils.getEyePoint();
230 var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); 246 var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp);
231 if (projPt) 247 if (projPt)
232 { 248 {
@@ -489,6 +505,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
489 var n = this._elementCache.length; 505 var n = this._elementCache.length;
490 this._elementCache[index] = this._elementCache[n-1]; 506 this._elementCache[index] = this._elementCache[n-1];
491 this._elementCache.pop(); 507 this._elementCache.pop();
508 target.elementModel.isIn2DSnapCache = false;
492 found = true; 509 found = true;
493 } 510 }
494 511
@@ -693,8 +710,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
693 var wp = currentWorkingPlane.slice(0); 710 var wp = currentWorkingPlane.slice(0);
694 var mat = viewUtils.getMatrixFromElement(stage); 711 var mat = viewUtils.getMatrixFromElement(stage);
695 wp = MathUtils.transformPlane(wp, mat); 712 wp = MathUtils.transformPlane(wp, mat);
696 var eyePt = viewUtils.getEyePoint(); 713 var eyePt = [];
697 var vec = viewUtils.parentToChildVec(gPt, stage); 714 var vec = viewUtils.parentToChildVec(gPt, stage, eyePt);
698 var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); 715 var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp);
699 var wpMat = drawUtils.getPlaneToWorldMatrix(currentWorkingPlane, MathUtils.getPointOnPlane(currentWorkingPlane)); 716 var wpMat = drawUtils.getPlaneToWorldMatrix(currentWorkingPlane, MathUtils.getPointOnPlane(currentWorkingPlane));
700 projPt[3] = 1.0; 717 projPt[3] = 1.0;
@@ -1051,8 +1068,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1051 // Snapping is done in screen space, so convert the bounds from 1068 // Snapping is done in screen space, so convert the bounds from
1052 // local element space to global screen space 1069 // local element space to global screen space
1053 var bounds3D = new Array(); 1070 var bounds3D = new Array();
1071 var eltMat = viewUtils.getLocalToGlobalMatrix( elt );
1054 for (var i=0; i<4; i++) 1072 for (var i=0; i<4; i++)
1055 bounds3D[i] = viewUtils.localToGlobal( bounds[i], elt ); 1073 bounds3D[i] = viewUtils.localToGlobal2(bounds[i], eltMat);
1056 1074
1057 var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D ); 1075 var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D );
1058 1076
@@ -1336,7 +1354,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1336 var offset = viewUtils.getElementOffset( elt ); 1354 var offset = viewUtils.getElementOffset( elt );
1337 MathUtils.makeDimension3( offset ); 1355 MathUtils.makeDimension3( offset );
1338 var parentPt = vecUtils.vecAdd(3, scrPt, offset ); 1356 var parentPt = vecUtils.vecAdd(3, scrPt, offset );
1339 var globalPt = viewUtils.localToGlobal( parentPt, elt.parentElement ); 1357 var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent );
1340 1358
1341 var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); 1359 var dist = vecUtils.vecDist(2, globalPt, targetScrPt );
1342 if (dist < this.ELEMENT_VERTEX_HIT_RAD) 1360 if (dist < this.ELEMENT_VERTEX_HIT_RAD)
@@ -1374,7 +1392,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1374 var offset = viewUtils.getElementOffset( elt ); 1392 var offset = viewUtils.getElementOffset( elt );
1375 MathUtils.makeDimension3( offset ); 1393 MathUtils.makeDimension3( offset );
1376 var parentPt = vecUtils.vecAdd(3, scrPt, offset ); 1394 var parentPt = vecUtils.vecAdd(3, scrPt, offset );
1377 var globalPt = viewUtils.localToGlobal( parentPt, elt.parentElement ); 1395 var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent );
1378 1396
1379 var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); 1397 var dist = vecUtils.vecDist(2, globalPt, targetScrPt );
1380 if (dist < this.ELEMENT_EDGE_HIT_RAD) 1398 if (dist < this.ELEMENT_EDGE_HIT_RAD)
@@ -1411,6 +1429,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1411 case glObj.GEOM_TYPE_PATH: 1429 case glObj.GEOM_TYPE_PATH:
1412 // Snapping not implemented for these type, but don't throw an error... 1430 // Snapping not implemented for these type, but don't throw an error...
1413 break; 1431 break;
1432 case glObj.GEOM_TYPE_BRUSH_STROKE:
1433 break; //don't throw error because snapping not yet implemented
1414 case glObj.GEOM_TYPE_CUBIC_BEZIER: 1434 case glObj.GEOM_TYPE_CUBIC_BEZIER:
1415 { 1435 {
1416 var nearVrt = glObj.getNearVertex( eyePt, dir ); 1436 var nearVrt = glObj.getNearVertex( eyePt, dir );
@@ -1425,7 +1445,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1425 var offset = viewUtils.getElementOffset( elt ); 1445 var offset = viewUtils.getElementOffset( elt );
1426 MathUtils.makeDimension3( offset ); 1446 MathUtils.makeDimension3( offset );
1427 var parentPt = vecUtils.vecAdd(3, scrPt, offset ); 1447 var parentPt = vecUtils.vecAdd(3, scrPt, offset );
1428 var globalPt = viewUtils.localToGlobal( parentPt, elt.parentElement ); 1448 var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent );
1429 1449
1430 var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); 1450 var dist = vecUtils.vecDist(2, globalPt, targetScrPt );
1431 if (dist < this.ELEMENT_VERTEX_HIT_RAD) 1451 if (dist < this.ELEMENT_VERTEX_HIT_RAD)
@@ -1463,7 +1483,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1463 var offset = viewUtils.getElementOffset( elt ); 1483 var offset = viewUtils.getElementOffset( elt );
1464 MathUtils.makeDimension3( offset ); 1484 MathUtils.makeDimension3( offset );
1465 var parentPt = vecUtils.vecAdd(3, scrPt, offset ); 1485 var parentPt = vecUtils.vecAdd(3, scrPt, offset );
1466 var globalPt = viewUtils.localToGlobal( parentPt, elt.parentElement ); 1486 var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent );
1467 1487
1468 var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); 1488 var dist = vecUtils.vecDist(2, globalPt, targetScrPt );
1469 if (dist < this.ELEMENT_EDGE_HIT_RAD) 1489 if (dist < this.ELEMENT_EDGE_HIT_RAD)