diff options
Diffstat (limited to 'js/helper-classes/3D/snap-manager.js')
-rwxr-xr-x | js/helper-classes/3D/snap-manager.js | 4069 |
1 files changed, 2035 insertions, 2034 deletions
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index ab6d106d..d3db6567 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js | |||
@@ -1,24 +1,25 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | ||
5 | 4 | ||
6 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
8 | 7 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 8 | * Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 9 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 10 | |
12 | notice, this list of conditions and the following disclaimer in the | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
13 | documentation and/or other materials provided with the distribution. | 12 | this list of conditions and the following disclaimer in the documentation |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 13 | and/or other materials provided with the distribution. |
15 | may be used to endorse or promote products derived from this software | 14 | |
16 | without specific prior written permission. | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | contributors may be used to endorse or promote products derived from this | ||
17 | software without specific prior written permission. | ||
17 | 18 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
@@ -42,109 +43,109 @@ var Montage = require("montage/core/core").Montage, | |||
42 | NJUtils = require("js/lib/NJUtils").NJUtils; | 43 | NJUtils = require("js/lib/NJUtils").NJUtils; |
43 | 44 | ||
44 | var SnapManager = exports.SnapManager = Montage.create(Component, { | 45 | var SnapManager = exports.SnapManager = Montage.create(Component, { |
45 | /////////////////////////////////////////////////////////////////////// | 46 | /////////////////////////////////////////////////////////////////////// |
46 | // Instance variables | 47 | // Instance variables |
47 | /////////////////////////////////////////////////////////////////////// | 48 | /////////////////////////////////////////////////////////////////////// |
48 | 49 | ||
49 | currentStage: { value: null }, | 50 | currentStage: { value: null }, |
50 | 51 | ||
51 | // we keep a stack of working planes to facilitate working on other planes temporarily | 52 | // we keep a stack of working planes to facilitate working on other planes temporarily |
52 | _workingPlaneStack : { value: [], writable: true }, | 53 | _workingPlaneStack : { value: [], writable: true }, |
53 | 54 | ||
54 | // snapping radii relative to a 25 pixel grid | 55 | // snapping radii relative to a 25 pixel grid |
55 | GRID_VERTEX_HIT_RAD : { value: 10, writable: true }, | 56 | GRID_VERTEX_HIT_RAD : { value: 10, writable: true }, |
56 | GRID_EDGE_HIT_RAD : { value: 6, writable: true}, | 57 | GRID_EDGE_HIT_RAD : { value: 6, writable: true}, |
57 | 58 | ||
58 | // these are the grid snapping tolerances scaled to the current grid spacing | 59 | // these are the grid snapping tolerances scaled to the current grid spacing |
59 | _gridVertexHitRad : { value: this.GRID_VERTEX_HIT_RAD, writable: true }, | 60 | _gridVertexHitRad : { value: this.GRID_VERTEX_HIT_RAD, writable: true }, |
60 | _gridEdgeHitRad : { value: this.GRID_EDGE_HIT_RAD, writable: true }, | 61 | _gridEdgeHitRad : { value: this.GRID_EDGE_HIT_RAD, writable: true }, |
61 | 62 | ||
62 | ELEMENT_VERTEX_HIT_RAD : { value: 18, writable: true }, | 63 | ELEMENT_VERTEX_HIT_RAD : { value: 18, writable: true }, |
63 | ELEMENT_EDGE_HIT_RAD : { value: 14, writable: true }, | 64 | ELEMENT_EDGE_HIT_RAD : { value: 14, writable: true }, |
64 | 65 | ||
65 | // keep a reference to the most recent hitRecord. Used for drawing feedback on the stage | 66 | // keep a reference to the most recent hitRecord. Used for drawing feedback on the stage |
66 | _lastHit : { value: null, writable: true }, | 67 | _lastHit : { value: null, writable: true }, |
67 | _hitRecords : { value: [], writable: true }, | 68 | _hitRecords : { value: [], writable: true }, |
68 | 69 | ||
69 | // keep a list of objects to avoid snapping to | 70 | // keep a list of objects to avoid snapping to |
70 | _avoidList : { value: [], writable: true }, | 71 | _avoidList : { value: [], writable: true }, |
71 | 72 | ||
72 | // keep a cache of 2D elements to snap to | 73 | // keep a cache of 2D elements to snap to |
73 | _elementCache : { value: null, writable: true }, | 74 | _elementCache : { value: null, writable: true }, |
74 | _isCacheInvalid : { value: false, writable: true }, | 75 | _isCacheInvalid : { value: false, writable: true }, |
75 | 76 | ||
76 | // the snap manager can handle a 2D plane for dragging. | 77 | // the snap manager can handle a 2D plane for dragging. |
77 | // A call to initDragPlane sets these variables. | 78 | // A call to initDragPlane sets these variables. |
78 | // a call to clearDragPlane MUST be called on the completion of a drag | 79 | // a call to clearDragPlane MUST be called on the completion of a drag |
79 | _hasDragPlane : {value: false, writable: true }, | 80 | _hasDragPlane : {value: false, writable: true }, |
80 | _dragPlane : { value: null, writable: true }, | 81 | _dragPlane : { value: null, writable: true }, |
81 | _dragPlaneToWorld : { value: Matrix.I(4), writable: true }, | 82 | _dragPlaneToWorld : { value: Matrix.I(4), writable: true }, |
82 | _worldToDragPlane : { value: Matrix.I(4), writable: true }, | 83 | _worldToDragPlane : { value: Matrix.I(4), writable: true }, |
83 | _dragPlaneActive : {value: false, writable: true }, | 84 | _dragPlaneActive : {value: false, writable: true }, |
84 | 85 | ||
85 | // cache the matrix linking stage world and global spaces | 86 | // cache the matrix linking stage world and global spaces |
86 | _stageWorldToGlobalMat : { value: Matrix.I(4), writable: true }, | 87 | _stageWorldToGlobalMat : { value: Matrix.I(4), writable: true }, |
87 | _globalToStageWorldMat : { value: Matrix.I(4), writable: true }, | 88 | _globalToStageWorldMat : { value: Matrix.I(4), writable: true }, |
88 | 89 | ||
89 | // various flags to enable snapping | 90 | // various flags to enable snapping |
90 | _snapAlignEnabled : {value: true, writable: true }, | 91 | _snapAlignEnabled : {value: true, writable: true }, |
91 | _elementSnapEnabled : {value: true, writable: true }, | 92 | _elementSnapEnabled : {value: true, writable: true }, |
92 | _gridSnapEnabled : {value: true, writable: true }, | 93 | _gridSnapEnabled : {value: true, writable: true }, |
93 | 94 | ||
94 | // these represent the app level snap settings as set by the end user through | 95 | // these represent the app level snap settings as set by the end user through |
95 | // the menus. These should be stored somewhere else and serialized. Putting them here for now... | 96 | // the menus. These should be stored somewhere else and serialized. Putting them here for now... |
96 | _snapAlignEnabledAppLevel : {value: true, writable: true }, | 97 | _snapAlignEnabledAppLevel : {value: true, writable: true }, |
97 | _elementSnapEnabledAppLevel : {value: true, writable: true }, | 98 | _elementSnapEnabledAppLevel : {value: true, writable: true }, |
98 | _gridSnapEnabledAppLevel : {value: true, writable: true }, | 99 | _gridSnapEnabledAppLevel : {value: true, writable: true }, |
99 | 100 | ||
100 | // App Model pointer | 101 | // App Model pointer |
101 | appModel: { value: null }, | 102 | appModel: { value: null }, |
102 | 103 | ||
103 | 104 | ||
104 | /////////////////////////////////////////////////////////////////////// | 105 | /////////////////////////////////////////////////////////////////////// |
105 | // Property accessors | 106 | // Property accessors |
106 | /////////////////////////////////////////////////////////////////////// | 107 | /////////////////////////////////////////////////////////////////////// |
107 | pushWorkingPlane : { value: function (p) { this._workingPlaneStack.push(workingPlane.slice(0)); workingPlane = p.slice(0); }}, | 108 | pushWorkingPlane : { value: function (p) { this._workingPlaneStack.push(workingPlane.slice(0)); workingPlane = p.slice(0); }}, |
108 | popWorkingPlane : { value: function () { workingPlane = this._workingPlaneStack.pop(); return workingPlane; }}, | 109 | popWorkingPlane : { value: function () { workingPlane = this._workingPlaneStack.pop(); return workingPlane; }}, |
109 | 110 | ||
110 | getStageWidth : { value: function () { | 111 | getStageWidth : { value: function () { |
111 | return parseInt(this.currentStage.offsetWidth); | 112 | return parseInt(this.currentStage.offsetWidth); |
112 | }}, | 113 | }}, |
113 | 114 | ||
114 | getStageHeight : { value: function () { | 115 | getStageHeight : { value: function () { |
115 | return parseInt(this.currentStage.offsetHeight); | 116 | return parseInt(this.currentStage.offsetHeight); |
116 | }}, | 117 | }}, |
117 | 118 | ||
118 | getStage : { value: function() { return this.currentStage; }}, | 119 | getStage : { value: function() { return this.currentStage; }}, |
119 | 120 | ||
120 | getGridVertexHitRad : { value: function() { return this._gridVertexHitRad; }}, | 121 | getGridVertexHitRad : { value: function() { return this._gridVertexHitRad; }}, |
121 | getGridEdgeHitRad : { value: function() { return this._gridEdgeHitRad; }}, | 122 | getGridEdgeHitRad : { value: function() { return this._gridEdgeHitRad; }}, |
122 | 123 | ||
123 | getLastHit : { value: function() { return this._lastHit; }}, | 124 | getLastHit : { value: function() { return this._lastHit; }}, |
124 | setLastHit : { value: function(h) { this._lastHit = h; }}, | 125 | setLastHit : { value: function(h) { this._lastHit = h; }}, |
125 | 126 | ||
126 | hasDragPlane : { value: function() { return this._hasDragPlane; }}, | 127 | hasDragPlane : { value: function() { return this._hasDragPlane; }}, |
127 | getDragPlane : { value: function() { return this._dragPlane.slice(0); }}, | 128 | getDragPlane : { value: function() { return this._dragPlane.slice(0); }}, |
128 | 129 | ||
129 | has2DCache : { value: function() { return (this._elementCache && !this._isCacheInvalid); }}, | 130 | has2DCache : { value: function() { return (this._elementCache && !this._isCacheInvalid); }}, |
130 | 131 | ||
131 | enableSnapAlign : { value: function(e) { this._snapAlignEnabled = e; }}, | 132 | enableSnapAlign : { value: function(e) { this._snapAlignEnabled = e; }}, |
132 | snapAlignEnabled : { value: function() { return this._snapAlignEnabled; }}, | 133 | snapAlignEnabled : { value: function() { return this._snapAlignEnabled; }}, |
133 | enableElementSnap : { value: function(e) { this._elementSnapEnabled = e; }}, | 134 | enableElementSnap : { value: function(e) { this._elementSnapEnabled = e; }}, |
134 | elementSnapEnabled : { value: function() { return this._elementSnapEnabled; }}, | 135 | elementSnapEnabled : { value: function() { return this._elementSnapEnabled; }}, |
135 | enableGridSnap : { value: function(e) { this._gridSnapEnabled = e; }}, | 136 | enableGridSnap : { value: function(e) { this._gridSnapEnabled = e; }}, |
136 | gridSnapEnabled : { value: function() { return this._gridSnapEnabled; }}, | 137 | gridSnapEnabled : { value: function() { return this._gridSnapEnabled; }}, |
137 | 138 | ||
138 | enableSnapAlignAppLevel : { value: function(e) { this._snapAlignEnabledAppLevel = e; }}, | 139 | enableSnapAlignAppLevel : { value: function(e) { this._snapAlignEnabledAppLevel = e; }}, |
139 | snapAlignEnabledAppLevel : { value: function() { return this._snapAlignEnabledAppLevel; }}, | 140 | snapAlignEnabledAppLevel : { value: function() { return this._snapAlignEnabledAppLevel; }}, |
140 | enableElementSnapAppLevel : { value: function(e) { this._elementSnapEnabledAppLevel = e; }}, | 141 | enableElementSnapAppLevel : { value: function(e) { this._elementSnapEnabledAppLevel = e; }}, |
141 | elementSnapEnabledAppLevel : { value: function() { return this._elementSnapEnabledAppLevel; }}, | 142 | elementSnapEnabledAppLevel : { value: function() { return this._elementSnapEnabledAppLevel; }}, |
142 | enableGridSnapAppLevel : { value: function(e) { this._gridSnapEnabledAppLevel = e; }}, | 143 | enableGridSnapAppLevel : { value: function(e) { this._gridSnapEnabledAppLevel = e; }}, |
143 | gridSnapEnabledAppLevel : { value: function() { return this._gridSnapEnabledAppLevel; }}, | 144 | gridSnapEnabledAppLevel : { value: function() { return this._gridSnapEnabledAppLevel; }}, |
144 | 145 |