diff options
Diffstat (limited to 'js')
40 files changed, 1853 insertions, 294 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js index 536fca47..8592a445 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js | |||
@@ -185,13 +185,113 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
185 | var elt = this.documentRoot; | 185 | var elt = this.documentRoot; |
186 | if (elt) | 186 | if (elt) |
187 | { | 187 | { |
188 | console.log( "load canvas data: " , value ); | 188 | var loadForRuntime = false; |
189 | var cdm = new CanvasDataManager(); | 189 | if (loadForRuntime) |
190 | cdm.loadGLData(elt, value); | 190 | { |
191 | //console.log( "load canvas data: " , value ); | ||
192 | var cdm = new CanvasDataManager(); | ||
193 | cdm.loadGLData(elt, value, NJUtils); | ||
194 | } | ||
195 | else | ||
196 | { | ||
197 | var nWorlds= value.length; | ||
198 | for (var i=0; i<nWorlds; i++) | ||
199 | { | ||
200 | var importStr = value[i]; | ||
201 | var startIndex = importStr.indexOf( "id: " ); | ||
202 | if (startIndex >= 0) | ||
203 | { | ||
204 | var endIndex = importStr.indexOf( "\n", startIndex ); | ||
205 | if (endIndex > 0) | ||
206 | { | ||
207 | var id = importStr.substring( startIndex+4, endIndex ); | ||
208 | if (id) | ||
209 | { | ||
210 | var canvas = this.findCanvasWithID( id, elt ); | ||
211 | if (canvas) | ||
212 | { | ||
213 | if (!canvas.elementModel) | ||
214 | { | ||
215 | NJUtils.makeElementModel(canvas, "Canvas", "shape", true); | ||
216 | } | ||
217 | |||
218 | if (canvas.elementModel) | ||
219 | { | ||
220 | if (canvas.elementModel.shapeModel.GLWorld) | ||
221 | canvas.elementModel.shapeModel.GLWorld.clearTree(); | ||
222 | |||
223 | var index = importStr.indexOf( "webGL: " ); | ||
224 | var useWebGL = (index >= 0) | ||
225 | var world = new GLWorld( canvas, useWebGL ); | ||
226 | world.import( importStr ); | ||
227 | canvas.elementModel.shapeModel.GLWorld = world; | ||
228 | |||
229 | this.buildShapeModel( canvas.elementModel, world ); | ||
230 | } | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | } | ||
236 | } | ||
191 | } | 237 | } |
192 | } | 238 | } |
193 | }, | 239 | }, |
194 | 240 | ||
241 | buildShapeModel: | ||
242 | { | ||
243 | value: function( elementModel, world ) | ||
244 | { | ||
245 | var shapeModel = elementModel.shapeModel; | ||
246 | shapeModel.shapeCount = 1; // for now... | ||
247 | shapeModel.useWebGl = world._useWebGL; | ||
248 | shapeModel.GLWorld = world; | ||
249 | var root = world.getGeomRoot(); | ||
250 | if (root) | ||
251 | { | ||
252 | shapeModel.GLGeomObj = root; | ||
253 | shapeModel.strokeSize = root._strokeWidth; | ||
254 | shapeModel.stroke = root._strokeColor.slice(); | ||
255 | shapeModel.strokeMaterial = root._strokeMaterial.dup(); | ||
256 | shapeModel.strokeStyle = "solid"; | ||
257 | //shapeModel.strokeStyleIndex | ||
258 | //shapeModel.border | ||
259 | //shapeModel.background | ||
260 | switch (root.geomType()) | ||
261 | { | ||
262 | case root.GEOM_TYPE_RECTANGLE: | ||
263 | elementModel.selection = "Rectangle"; | ||
264 | elementModel.pi = "RectanglePi"; | ||
265 | shapeModel.fill = root._fillColor.slice(); | ||
266 | shapeModel.fillMaterial = root._fillMaterial.dup(); | ||
267 | shapeModel.tlRadius = root._tlRadius; | ||
268 | shapeModel.trRadius = root._trRadius; | ||
269 | shapeModel.blRadius = root._blRadius; | ||
270 | shapeModel.brRadius = root._brRadius; | ||
271 | break; | ||
272 | |||
273 | case root.GEOM_TYPE_CIRCLE: | ||
274 | elementModel.selection = "Oval"; | ||
275 | elementModel.pi = "OvalPi"; | ||
276 | shapeModel.fill = root._fillColor.slice(); | ||
277 | shapeModel.fillMaterial = root._fillMaterial.dup(); | ||
278 | shapeModel.innerRadius = root._innerRadius; | ||
279 | break; | ||
280 | |||
281 | case root.GEOM_TYPE_LINE: | ||
282 | elementModel.selection = "Line"; | ||
283 | elementModel.pi = "LinePi"; | ||
284 | shapeModel.slope = root._slope; | ||
285 | break; | ||
286 | |||
287 | default: | ||
288 | console.log( "geometry type not supported for file I/O, " + root.geomType()); | ||
289 | break; | ||
290 | } | ||
291 | } | ||
292 | } | ||
293 | }, | ||
294 | |||
195 | zoomFactor: { | 295 | zoomFactor: { |
196 | get: function() { return this._zoomFactor; }, | 296 | get: function() { return this._zoomFactor; }, |
197 | set: function(value) { this._zoomFactor = value; } | 297 | set: function(value) { this._zoomFactor = value; } |
@@ -219,6 +319,27 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
219 | } | 319 | } |
220 | } | 320 | } |
221 | }, | 321 | }, |
322 | |||
323 | /** | ||
324 | * search the DOM tree to find a canvas with the given id | ||
325 | */ | ||
326 | findCanvasWithID: { | ||
327 | value: function( id, elt ) { | ||
328 | var cid = elt.getAttribute( "data-RDGE-id" ); | ||
329 | if (cid == id) return elt; | ||
330 | |||
331 | if (elt.children) | ||
332 | { | ||
333 | var nKids = elt.children.length; | ||
334 | for (var i=0; i<nKids; i++) | ||
335 | { | ||
336 | var child = elt.children[i]; | ||
337 | var foundElt = this.findCanvasWithID( id, child ); | ||
338 | if (foundElt) return foundElt; | ||