From 232784ffafe834f75a46ca7fc311e8ca2ff5eec9 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 5 Mar 2012 16:33:51 -0800 Subject: Corrections for canvas file IO --- js/document/html-document.js | 69 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) (limited to 'js/document') diff --git a/js/document/html-document.js b/js/document/html-document.js index 7dd28385..f1b99866 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -185,9 +185,51 @@ exports.HTMLDocument = Montage.create(TextDocument, { var elt = this.documentRoot; if (elt) { - //console.log( "load canvas data: " , value ); - var cdm = new CanvasDataManager(); - cdm.loadGLData(elt, value); + var loadForRuntime = true; + if (loadForRuntime) + { + //console.log( "load canvas data: " , value ); + var cdm = new CanvasDataManager(); + cdm.loadGLData(elt, value, NJUtils); + } + else + { + var nWorlds= value.length; + for (var i=0; i= 0) + { + var endIndex = importStr.indexOf( "\n", startIndex ); + if (endIndex > 0) + { + var id = importStr.substring( startIndex+4, endIndex ); + if (id) + { + var canvas = this.findCanvasWithID( id, elt ); + if (canvas) + { + if (!canvas.elementModel) + { + NJUtils.makeElementModel(canvas, "Canvas", "shape", true); + } + + if (canvas.elementModel) + { + if (canvas.elementModel.shapeModel.GLWorld) + canvas.elementModel.shapeModel.GLWorld.clearTree(); + + var world = new GLWorld( canvas ); + canvas.elementModel.shapeModel.GLWorld = world; + world.import( importStr ); + } + } + } + } + } + } + } } } }, @@ -219,6 +261,27 @@ exports.HTMLDocument = Montage.create(TextDocument, { } } }, + + /** + * search the DOM tree to find a canvas with the given id + */ + findCanvasWithID: { + value: function( id, elt ) { + var cid = elt.getAttribute( "data-RDGE-id" ); + if (cid == id) return elt; + + if (elt.children) + { + var nKids = elt.children.length; + for (var i=0; i