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.js4046
1 files changed, 2023 insertions, 2023 deletions
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index ab6d106d..e5044e09 100755
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -42,109 +42,109 @@ var Montage = require("montage/core/core").Montage,
42 NJUtils = require("js/lib/NJUtils").NJUtils; 42 NJUtils = require("js/lib/NJUtils").NJUtils;
43 43
44var SnapManager = exports.SnapManager = Montage.create(Component, { 44var SnapManager = exports.SnapManager = Montage.create(Component, {
45 /////////////////////////////////////////////////////////////////////// 45 ///////////////////////////////////////////////////////////////////////
46 // Instance variables 46 // Instance variables
47 /////////////////////////////////////////////////////////////////////// 47 ///////////////////////////////////////////////////////////////////////
48 48
49 currentStage: { value: null }, 49 currentStage: { value: null },
50 50
51 // we keep a stack of working planes to facilitate working on other planes temporarily 51 // we keep a stack of working planes to facilitate working on other planes temporarily
52 _workingPlaneStack : { value: [], writable: true }, 52 _workingPlaneStack : { value: [], writable: true },
53 53
54 // snapping radii relative to a 25 pixel grid 54 // snapping radii relative to a 25 pixel grid
55 GRID_VERTEX_HIT_RAD : { value: 10, writable: true }, 55 GRID_VERTEX_HIT_RAD : { value: 10, writable: true },
56 GRID_EDGE_HIT_RAD : { value: 6, writable: true}, 56 GRID_EDGE_HIT_RAD : { value: 6, writable: true},
57 57
58 // these are the grid snapping tolerances scaled to the current grid spacing 58 // these are the grid snapping tolerances scaled to the current grid spacing
59 _gridVertexHitRad : { value: this.GRID_VERTEX_HIT_RAD, writable: true }, 59 _gridVertexHitRad : { value: this.GRID_VERTEX_HIT_RAD, writable: true },
60 _gridEdgeHitRad : { value: this.GRID_EDGE_HIT_RAD, writable: true }, 60 _gridEdgeHitRad : { value: this.GRID_EDGE_HIT_RAD, writable: true },
61 61
62 ELEMENT_VERTEX_HIT_RAD : { value: 18, writable: true }, 62 ELEMENT_VERTEX_HIT_RAD : { value: 18, writable: true },
63 ELEMENT_EDGE_HIT_RAD : { value: 14, writable: true }, 63 ELEMENT_EDGE_HIT_RAD : { value: 14, writable: true },
64 64
65 // keep a reference to the most recent hitRecord. Used for drawing feedback on the stage 65 // keep a reference to the most recent hitRecord. Used for drawing feedback on the stage
66 _lastHit : { value: null, writable: true }, 66 _lastHit : { value: null, writable: true },
67 _hitRecords : { value: [], writable: true }, 67 _hitRecords : { value: [], writable: true },
68 68
69 // keep a list of objects to avoid snapping to 69 // keep a list of objects to avoid snapping to
70 _avoidList : { value: [], writable: true }, 70 _avoidList : { value: [], writable: true },
71 71
72 // keep a cache of 2D elements to snap to 72 // keep a cache of 2D elements to snap to
73 _elementCache : { value: null, writable: true }, 73 _elementCache : { value: null, writable: true },
74 _isCacheInvalid : { value: false, writable: true }, 74 _isCacheInvalid : { value: false, writable: true },
75 75
76 // the snap manager can handle a 2D plane for dragging. 76 // the snap manager can handle a 2D plane for dragging.
77 // A call to initDragPlane sets these variables. 77 // A call to initDragPlane sets these variables.
78 // a call to clearDragPlane MUST be called on the completion of a drag 78 // a call to clearDragPlane MUST be called on the completion of a drag
79 _hasDragPlane : {value: false, writable: true }, 79 _hasDragPlane : {value: false, writable: true },
80 _dragPlane : { value: null, writable: true }, 80 _dragPlane : { value: null, writable: true },
81 _dragPlaneToWorld : { value: Matrix.I(4), writable: true }, 81 _dragPlaneToWorld : { value: Matrix.I(4), writable: true },
82 _worldToDragPlane : { value: Matrix.I(4), writable: true }, 82 _worldToDragPlane : { value: Matrix.I(4), writable: true },
83 _dragPlaneActive : {value: false, writable: true }, 83 _dragPlaneActive : {value: false, writable: true },
84 84
85 // cache the matrix linking stage world and global spaces 85 // cache the matrix linking stage world and global spaces
86 _stageWorldToGlobalMat : { value: Matrix.I(4), writable: true }, 86 _stageWorldToGlobalMat : { value: Matrix.I(4), writable: true },
87 _globalToStageWorldMat : { value: Matrix.I(4), writable: true }, 87 _globalToStageWorldMat : { value: Matrix.I(4), writable: true },
88 88
89 // various flags to enable snapping 89 // various flags to enable snapping
90 _snapAlignEnabled : {value: true, writable: true }, 90 _snapAlignEnabled : {value: true, writable: true },
91 _elementSnapEnabled : {value: true, writable: true }, 91 _elementSnapEnabled : {value: true, writable: true },
92 _gridSnapEnabled : {value: true, writable: true }, 92 _gridSnapEnabled : {value: true, writable: true },
93 93
94 // these represent the app level snap settings as set by the end user through 94 // 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... 95 // the menus. These should be stored somewhere else and serialized. Putting them here for now...
96 _snapAlignEnabledAppLevel : {value: true, writable: true }, 96 _snapAlignEnabledAppLevel : {value: true, writable: true },
97 _elementSnapEnabledAppLevel : {value: true, writable: true }, 97 _elementSnapEnabledAppLevel : {value: true, writable: true },
98 _gridSnapEnabledAppLevel : {value: true, writable: true }, 98 _gridSnapEnabledAppLevel : {value: true, writable: true },
99 99
100 // App Model pointer 100 // App Model pointer
101 appModel: { value: null }, 101 appModel: { value: null },
102 102
103 103
104 /////////////////////////////////////////////////////////////////////// 104 ///////////////////////////////////////////////////////////////////////
105 // Property accessors 105 // Property accessors
106 /////////////////////////////////////////////////////////////////////// 106 ///////////////////////////////////////////////////////////////////////
107 pushWorkingPlane : { value: function (p) { this._workingPlaneStack.push(workingPlane.slice(0)); workingPlane = p.slice(0); }}, 107 pushWorkingPlane : { value: function (p) { this._workingPlaneStack.push(workingPlane.slice(0)); workingPlane = p.slice(0); }},
108 popWorkingPlane : { value: function () { workingPlane = this._workingPlaneStack.pop(); return workingPlane; }}, 108 popWorkingPlane : { value: function () { workingPlane = this._workingPlaneStack.pop(); return workingPlane; }},
109 109
110 getStageWidth : { value: function () { 110 getStageWidth : { value: function () {
111 return parseInt(this.currentStage.offsetWidth); 111 return parseInt(this.currentStage.offsetWidth);
112 }}, 112 }},
113 113
114 getStageHeight : { value: function () { 114 getStageHeight : { value: function () {
115 return parseInt(this.currentStage.offsetHeight); 115 return parseInt(this.currentStage.offsetHeight);
116 }}, 116 }},
117 117
118 getStage : { value: function() { return this.currentStage; }}, 118 getStage : { value: function() { return this.currentStage; }},
119 119
120 getGridVertexHitRad : { value: function() { return this._gridVertexHitRad; }}, 120 getGridVertexHitRad : { value: function() { return this._gridVertexHitRad; }},
121 getGridEdgeHitRad : { value: function() { return this._gridEdgeHitRad; }}, 121 getGridEdgeHitRad : { value: function() { return this._gridEdgeHitRad; }},
122 122
123 getLastHit : { value: function() { return this._lastHit; }}, 123 getLastHit : { value: function() { return this._lastHit; }},
124 setLastHit : { value: function(h) { this._lastHit = h; }}, 124 setLastHit : { value: function(h) { this._lastHit = h; }},
125 125
126 hasDragPlane : { value: function() { return this._hasDragPlane; }}, 126 hasDragPlane : { value: function() { return this._hasDragPlane; }},
127 getDragPlane : { value: function() { return this._dragPlane.slice(0); }}, 127 getDragPlane : { value: function() { return this._dragPlane.slice(0); }},
128 128
129 has2DCache : { value: function() { return (this._elementCache && !this._isCacheInvalid); }}, 129 has2DCache : { value: function() { return (this._elementCache && !this._isCacheInvalid); }},
130 130
131 enableSnapAlign : { value: function(e) { this._snapAlignEnabled = e; }}, 131 enableSnapAlign : { value: function(e) { this._snapAlignEnabled = e; }},
132 snapAlignEnabled : { value: function() { return this._snapAlignEnabled; }}, 132 snapAlignEnabled : { value: function() { return this._snapAlignEnabled; }},
133 enableElementSnap : { value: function(e) { this._elementSnapEnabled = e; }}, 133 enableElementSnap : { value: function(e) { this._elementSnapEnabled = e; }},
134 elementSnapEnabled : { value: function() { return this._elementSnapEnabled; }}, 134 elementSnapEnabled : { value: function() { return this._elementSnapEnabled; }},
135 enableGridSnap : { value: function(e) { this._gridSnapEnabled = e; }}, 135 enableGridSnap : { value: function(e) { this._gridSnapEnabled = e; }},
136 gridSnapEnabled : { value: function() { return this._gridSnapEnabled; }}, 136 gridSnapEnabled : { value: function() { return this._gridSnapEnabled; }},
137 137
138 enableSnapAlignAppLevel : { value: function(e) { this._snapAlignEnabledAppLevel = e; }}, 138 enableSnapAlignAppLevel : { value: function(e) { this._snapAlignEnabledAppLevel = e; }},
139 snapAlignEnabledAppLevel : { value: function() { return this._snapAlignEnabledAppLevel; }}, 139 snapAlignEnabledAppLevel : { value: function() { return this._snapAlignEnabledAppLevel; }},
140 enableElementSnapAppLevel : { value: function(e) { this._elementSnapEnabledAppLevel = e; }}, 140 enableElementSnapAppLevel : { value: function(e) { this._elementSnapEnabledAppLevel = e; }},
141 elementSnapEnabledAppLevel : { value: function() { return this._elementSnapEnabledAppLevel; }}, 141 elementSnapEnabledAppLevel : { value: function() { return this._elementSnapEnabledAppLevel; }},
142 enableGridSnapAppLevel : { value: function(e) { this._gridSnapEnabledAppLevel = e; }}, 142 enableGridSnapAppLevel : { value: function(e) { this._gridSnapEnabledAppLevel = e; }},
143 gridSnapEnabledAppLevel : { value: function() { return this._gridSnapEnabledAppLevel; }}, 143 gridSnapEnabledAppLevel : { value: function() { return this._gridSnapEnabledAppLevel; }},
144 144
145 /////////////////////////////////////////////////////////////////////// 145 ///////////////////////////////////////////////////////////////////////
146 // Methods 146 // Methods
147 /////////////////////////////////////////////////////////////////////// 147 ///////////////////////////////////////////////////////////////////////
148 initialize: { 148 initialize: {
149 value: function() { 149 value: function() {
150 this.eventManager.addEventListener("elementsRemoved", this, false); 150 this.eventManager.addEventListener("elementsRemoved", this, false);
@@ -209,734 +209,734 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
209 } 209 }
210 }, 210 },
211 211
212 snap : { 212 snap : {
213 value: function (xScreen, yScreen, snap3D, quadPt) 213 value: function (xScreen, yScreen, snap3D, quadPt)
214 { 214 {
215 // force a 3D snap if a 2D snap is requested but the 2D cache has not been initialized 215 // force a 3D snap if a 2D snap is requested but the 2D cache has not been initialized
216 if (!snap3D && !this._elementCache) snap3D = true; 216 if (!snap3D && !this._elementCache) snap3D = true;
217 217
218 // clear out the last hit record 218 // clear out the last hit record
219 this.setLastHit( null ); 219 this.setLastHit( null );
220 220
221 // snap to elements first, then the working plane 221 // snap to elements first, then the working plane
222 var screenPt = [xScreen, yScreen]; 222 var screenPt = [xScreen, yScreen];
223 var hitRecArray = new Array(); 223 var hitRecArray = new Array();
224 if (this.elementSnapEnabled()) 224 if (this.elementSnapEnabled())
225 { 225 {
226 if (snap3D) 226 if (snap3D)
227 this.snapToElements( screenPt, hitRecArray ); 227 this.snapToElements( screenPt, hitRecArray );
228 228
229