diff options
Diffstat (limited to 'js')
-rwxr-xr-x | js/document/html-document.js | 2 | ||||
-rwxr-xr-x | js/helper-classes/3D/snap-manager.js | 274 | ||||
-rwxr-xr-x | js/lib/drawing/world.js | 9 | ||||
-rwxr-xr-x | js/lib/geom/circle.js | 8 | ||||
-rwxr-xr-x | js/lib/geom/rectangle.js | 39 | ||||
-rwxr-xr-x | js/tools/OvalTool.js | 2 | ||||
-rwxr-xr-x | js/tools/PanTool.js | 20 | ||||
-rwxr-xr-x | js/tools/ShapeTool.js | 22 |
8 files changed, 179 insertions, 197 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js index 54db9eaa..f33a1177 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js | |||
@@ -228,7 +228,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
228 | { | 228 | { |
229 | // JSON format. pull off the | 229 | // JSON format. pull off the |
230 | importStr = importStr.substr( index+1 ); | 230 | importStr = importStr.substr( index+1 ); |
231 | jObj = jObj = JSON.parse( importStr ); | 231 | jObj = JSON.parse( importStr ); |
232 | id = jObj.id; | 232 | id = jObj.id; |
233 | } | 233 | } |
234 | else | 234 | else |
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index cd8cc102..2c975985 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js | |||
@@ -1077,7 +1077,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1077 | var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D ); | 1077 | var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D ); |
1078 | 1078 | ||
1079 | // see if we can snap to a contained geometry object | 1079 | // see if we can snap to a contained geometry object |
1080 | if (hitRec && this.getGLWorld(elt) && !this.isARectangle(elt)) | 1080 | if (hitRec && this.getGLWorld(elt)) // && !this.isARectangle(elt)) |
1081 | { | 1081 | { |
1082 | var localPt = hitRec.calculateElementWorldPoint(); | 1082 | var localPt = hitRec.calculateElementWorldPoint(); |
1083 | if (hitRec.getType() != hitRec.SNAP_TYPE_ELEMENT) | 1083 | if (hitRec.getType() != hitRec.SNAP_TYPE_ELEMENT) |
@@ -1320,193 +1320,135 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1320 | } | 1320 | } |
1321 | }, | 1321 | }, |
1322 | 1322 | ||
1323 | snapToContainedElement : | 1323 | doSnapToContainedElement: |
1324 | { | 1324 | { |
1325 | value: function( eyePt, dir, glObj, hitRec, targetScrPt ) | 1325 | value: function( eyePt, dir, glObj, hitRec, targetScrPt ) |
1326 | { | 1326 | { |
1327 | var rtnVal = false; | 1327 | var rtnVal = false; |
1328 | var elt = hitRec.getElement(); | ||
1329 | 1328 | ||
1329 | var elt = hitRec.getElt(); | ||
1330 | var world = glObj.getWorld(); | 1330 | var world = glObj.getWorld(); |
1331 | switch (glObj.geomType()) | 1331 | |
1332 | var nearVrt = glObj.getNearVertex( eyePt, dir ); | ||
1333 | if (nearVrt) | ||
1332 | { | 1334 | { |
1333 | case glObj.GEOM_TYPE_RECTANGLE: | 1335 | var viewPt = this.GLToView(nearVrt, world ); |
1334 | break; | 1336 | var mat = viewUtils.getMatrixFromElement( elt ); |
1337 | var worldPt = MathUtils.transformPoint( viewPt, mat ); | ||
1335 | 1338 | ||
1336 | case glObj.GEOM_TYPE_CIRCLE: | 1339 | viewUtils.pushViewportObj( elt ); |
1340 | var scrPt = viewUtils.viewToScreen( worldPt ); | ||
1341 | var offset = viewUtils.getElementOffset( elt ); | ||
1342 | MathUtils.makeDimension3( offset ); | ||
1343 | var parentPt = vecUtils.vecAdd(3, scrPt, offset ); | ||
1344 | var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); | ||
1345 | |||
1346 | var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); | ||
1347 | if (dist < this.ELEMENT_VERTEX_HIT_RAD) | ||
1348 | { | ||
1349 | console.log( "hit a vertex" ); | ||
1350 | |||
1351 | // check if the distance is less than | ||
1352 | // the distance on the current hit record | ||
1353 | if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() )) | ||
1337 | { | 1354 | { |
1338 | var nearVrt = glObj.getNearVertex( eyePt, dir ); | 1355 | console.log( "rejected - further than existing snap" ); |
1339 | if (nearVrt) | 1356 | |
1340 | { | 1357 | hitRec.setScreenPoint( globalPt ); |
1341 | var viewPt = this.GLToView(nearVrt, world ); | 1358 | //var localMatInv = hitRec.getPlaneMatrix().inverse(); |
1342 | var mat = viewUtils.getMatrixFromElement( elt ); | 1359 | var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); |
1343 | var worldPt = MathUtils.transformPoint( viewPt, mat ); | 1360 | viewUtils.pushViewportObj( hitRec.getElement() ); |
1344 | 1361 | var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); | |
1345 | viewUtils.pushViewportObj( elt ); | 1362 | viewUtils.popViewportObj(); |
1346 | var scrPt = viewUtils.viewToScreen( worldPt ); | 1363 | localPt = MathUtils.transformPoint( localPt, localMatInv ); |
1347 | var offset = viewUtils.getElementOffset( elt ); | 1364 | hitRec.setLocalPoint( localPt ); |
1348 | MathUtils.makeDimension3( offset ); | 1365 | hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT ); |
1349 | var parentPt = vecUtils.vecAdd(3, scrPt, offset ); | ||
1350 | var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); | ||
1351 | |||
1352 | var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); | ||
1353 | if (dist < this.ELEMENT_VERTEX_HIT_RAD) | ||
1354 | { | ||
1355 | // check if the distance is less than | ||
1356 | // the distance on the current hit record | ||
1357 | if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() )) | ||
1358 | { | ||
1359 | hitRec.setScreenPoint( globalPt ); | ||
1360 | //var localMatInv = hitRec.getPlaneMatrix().inverse(); | ||
1361 | var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); | ||
1362 | viewUtils.pushViewportObj( hitRec.getElement() ); | ||
1363 | var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); | ||
1364 | viewUtils.popViewportObj(); | ||
1365 | localPt = MathUtils.transformPoint( localPt, localMatInv ); | ||
1366 | hitRec.setLocalPoint( localPt ); | ||
1367 | hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT ); | ||
1368 | |||
1369 | rtnVal = true; | ||
1370 | } | ||
1371 | } | ||
1372 | } // if (nearVrt) | ||
1373 | 1366 | ||
1374 | if (!rtnVal) | 1367 | rtnVal = true; |
1375 | { | 1368 | } |
1376 | var nearPt = glObj.getNearPoint( eyePt, dir ); | 1369 | } |
1377 | if (nearPt) | 1370 | } |
1378 | { | ||
1379 | var viewPt = this.GLToView(nearPt, world ); | ||
1380 | var mat = viewUtils.getMatrixFromElement( elt ); | ||
1381 | var worldPt = MathUtils.transformPoint( viewPt, mat ); | ||
1382 | |||
1383 | viewUtils.pushViewportObj( elt ); | ||
1384 | var scrPt = viewUtils.viewToScreen( worldPt ); | ||
1385 | var offset = viewUtils.getElementOffset( elt ); | ||
1386 | MathUtils.makeDimension3( offset ); | ||
1387 | var parentPt = vecUtils.vecAdd(3, scrPt, offset ); | ||
1388 | var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); | ||
1389 | |||
1390 | var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); | ||
1391 | if (dist < this.ELEMENT_EDGE_HIT_RAD) | ||
1392 | { | ||
1393 | // check if the distance is less than | ||
1394 | // the distance on the current hit record | ||
1395 | //var dist2 = vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() ); | ||
1396 | //if (dist <= dist2+1 ) | ||
1397 | { | ||
1398 | hitRec.setScreenPoint( globalPt ); | ||
1399 | //var localMatInv = hitRec.getPlaneMatrix().inverse(); | ||
1400 | var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); | ||
1401 | viewUtils.pushViewportObj( hitRec.getElement() ); | ||
1402 | var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); | ||
1403 | viewUtils.popViewportObj(); | ||
1404 | localPt = MathUtils.transformPoint( localPt, localMatInv ); | ||
1405 | hitRec.setLocalPoint( localPt ); | ||
1406 | hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT ); | ||
1407 | |||
1408 | rtnVal = true; | ||
1409 | } | ||
1410 | } | ||
1411 | } | ||
1412 | } // if (!rtnVal) | ||
1413 | 1371 | ||
1414 | if (!rtnVal && glObj.containsPoint( eyePt, dir )) | 1372 | if (!rtnVal) |
1373 | { | ||
1374 | var nearPt = glObj.getNearPoint( eyePt, dir ); | ||
1375 | if (nearPt) | ||
1376 | { | ||
1377 | var viewPt = this.GLToView(nearPt, world ); | ||
1378 | var mat = viewUtils.getMatrixFromElement( elt ); | ||
1379 | var worldPt = MathUtils.transformPoint( viewPt, mat ); | ||
1380 | |||
1381 | viewUtils.pushViewportObj( elt ); | ||
1382 | var scrPt = viewUtils.viewToScreen( worldPt ); | ||
1383 | var offset = viewUtils.getElementOffset( elt ); | ||
1384 | MathUtils.makeDimension3( offset ); | ||
1385 | var parentPt = vecUtils.vecAdd(3, scrPt, offset ); | ||
1386 | var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); | ||
1387 | |||
1388 | var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); | ||
1389 | if (dist < this.ELEMENT_EDGE_HIT_RAD) | ||
1390 | { | ||
1391 | console.log( "hit an edge" ); | ||
1392 | |||
1393 | // check if the distance is less than | ||
1394 | // the distance on the current hit record | ||
1395 | //var dist2 = vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() ); | ||
1396 | //if (dist <= dist2+1 ) | ||
1415 | { | 1397 | { |
1398 | hitRec.setScreenPoint( globalPt ); | ||
1399 | //var localMatInv = hitRec.getPlaneMatrix().inverse(); | ||
1400 | var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); | ||
1401 |