diff options
Diffstat (limited to 'js/helper-classes')
46 files changed, 7862 insertions, 9667 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index d6334e6c..ec8eea0f 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js | |||
@@ -109,10 +109,11 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
109 | this._gridOrigin = [0,0]; // 2D plane space point | 109 | this._gridOrigin = [0,0]; // 2D plane space point |
110 | 110 | ||
111 | this.eventManager.addEventListener("elementAdded", this, false); | 111 | this.eventManager.addEventListener("elementAdded", this, false); |
112 | this.eventManager.addEventListener("elementDeleted", this, false); | 112 | this.eventManager.addEventListener("elementsRemoved", this, false); |
113 | this.eventManager.addEventListener("deleteSelection", this, false); | ||
114 | this.eventManager.addEventListener("elementChange", this, false); | 113 | this.eventManager.addEventListener("elementChange", this, false); |
114 | this.eventManager.addEventListener("elementChanging", this, false); | ||
115 | this.eventManager.addEventListener("closeDocument", this, false); | 115 | this.eventManager.addEventListener("closeDocument", this, false); |
116 | this.eventManager.addEventListener("elementReplaced", this, false); | ||
116 | } | 117 | } |
117 | }, | 118 | }, |
118 | 119 | ||
@@ -147,38 +148,75 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
147 | 148 | ||
148 | handleElementAdded: { | 149 | handleElementAdded: { |
149 | value: function(event) { | 150 | value: function(event) { |
150 | this.addElement(event.detail); | 151 | var elements = event.detail; |
152 | |||
153 | if(Array.isArray(elements)) { | ||
154 | elements.forEach(function(element) { | ||
155 | this.addElement(element); | ||
156 | }, this); | ||
157 | } else { | ||
158 | this.addElement(elements); | ||
159 | } | ||
160 | |||
151 | this.drawWorkingPlane(); | 161 | this.drawWorkingPlane(); |
152 | } | 162 | } |
153 | }, | 163 | }, |
154 | 164 | ||
155 | handleElementDeleted: { | 165 | handleElementsRemoved: { |
156 | value: function(event) { | 166 | value: function(event) { |
157 | this.removeElement(event.detail); | 167 | var elements = event.detail; |
168 | |||
169 | if(Array.isArray(elements)) { | ||
170 | elements = Array.prototype.slice.call(elements, 0); | ||
171 | elements.forEach(function(element) { | ||
172 | this.removeElement(element); | ||
173 | }, this); | ||
174 | } else { | ||
175 | this.removeElement(elements); | ||
176 | } | ||
177 | |||
178 | this.drawWorkingPlane(); | ||
158 | } | 179 | } |
159 | }, | 180 | }, |
160 | 181 | ||
161 | handleDeleteSelection: { | 182 | handleElementReplaced: { |
162 | value: function(event) { | 183 | value: function(event) { |
163 | this.drawWorkingPlane(); | 184 | var oldElement = event.detail.data.oldChild; |
185 | var newElement = event.detail.data.newChild; | ||
186 | |||
187 | // check if we already know about this object | ||
188 | var n = this._eltArray.length, | ||
189 | plane; | ||
190 | for (var i=0; i<n; i++) { | ||
191 | if (oldElement === this._eltArray[i]) { | ||
192 | this._eltArray[i] = newElement; | ||
193 | plane = this._planesArray[i]; | ||
194 | break; | ||
195 | } | ||
196 | } | ||
197 | |||
198 | if(!plane) { | ||
199 | this._eltArray.push( newElement ); | ||
200 | plane = Object.create(this.ElementPlanes, {}); | ||
201 | this._planesArray.push( plane ); | ||
202 | } | ||
203 | |||
204 | plane.setElement( newElement ); | ||
205 | plane.init(); | ||
206 | newElement.elementModel.props3D.elementPlane = plane; | ||
164 | } | 207 | } |
165 | }, | 208 | }, |
166 | 209 | ||
167 | _shouldUpdatePlanes: { | 210 | _shouldUpdatePlanes: { |
168 | value: function(props) { | 211 | value: function(props) { |
169 | if(!props) | 212 | if(!props) { |
170 | { | ||
171 | return false; | 213 | return false; |
172 | } | 214 | } else if (typeof props === "string") { |
173 | else if (typeof props === "string") | ||
174 | { | ||
175 | return (this._updatePlaneProps.indexOf(props) !== -1); | 215 | return (this._updatePlaneProps.indexOf(props) !== -1); |
176 | } | 216 | } |
177 | 217 | ||
178 | for (var p in props) | 218 | for (var p in props) { |
179 | { | 219 | if(this._updatePlaneProps.indexOf(p) !== -1) { |
180 | if(this._updatePlaneProps.indexOf(p) !== -1) | ||
181 | { | ||
182 | return true; | 220 | return true; |
183 | } | 221 | } |
184 | } | 222 | } |
@@ -190,24 +228,27 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
190 | // TODO - Check why handleElementChange is being fired before handleAddElement | 228 | // TODO - Check why handleElementChange is being fired before handleAddElement |
191 | handleElementChange: { | 229 | handleElementChange: { |
192 | value: function(event) { | 230 | value: function(event) { |
193 | if(!event.detail || !event.detail.data) | 231 | this._elementChangeHelper(event); |
194 | { | 232 | } |
233 | }, | ||
234 | |||
235 | handleElementChanging: { | ||
236 | value: function(event) { | ||
237 | this._elementChangeHelper(event); | ||
238 | } | ||
239 | }, | ||
240 | |||
241 | _elementChangeHelper: { | ||
242 | value: function(event) { | ||
243 | if(!event.detail || !event.detail.data) { | ||
195 | return; | 244 | return; |
196 | } | 245 | } |
197 | var els = event.detail.data.els; | 246 | var els = event.detail.data.els; |
198 | if(els && this._shouldUpdatePlanes(event.detail.data.prop)) | 247 | if(els && this._shouldUpdatePlanes(event.detail.data.prop)) { |
199 | { | 248 | var len = els.length; |
200 | var len = els.length, | 249 | for(var i=0; i < len; i++) { |
201 | i = 0, | 250 | if(els[i].elementModel.props3D.elementPlane) { |
202 | item, | 251 | els[i].elementModel.props3D.elementPlane.init(); |
203 | el; | ||
204 | |||