aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/html-document.js157
1 files changed, 136 insertions, 21 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 23b55e92..d4db6e2f 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -8,7 +8,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
8// 8//
9var Montage = require("montage/core/core").Montage, 9var Montage = require("montage/core/core").Montage,
10 TextDocument = require("js/document/text-document").TextDocument, 10 TextDocument = require("js/document/text-document").TextDocument,
11 NJUtils = require("js/lib/NJUtils").NJUtils; 11 NJUtils = require("js/lib/NJUtils").NJUtils,
12 GLWorld = require("js/lib/drawing/world").World;
12//////////////////////////////////////////////////////////////////////// 13////////////////////////////////////////////////////////////////////////
13// 14//
14exports.HTMLDocument = Montage.create(TextDocument, { 15exports.HTMLDocument = Montage.create(TextDocument, {
@@ -187,32 +188,123 @@ exports.HTMLDocument = Montage.create(TextDocument, {
187// }, 188// },
188 189
189 glData: { 190 glData: {
190 get: function() 191 get: function() {
191 { 192 //
192 var elt = this.iframe.contentWindow.document.getElementById("UserContent"); 193 var elt = this.iframe.contentWindow.document.getElementById("UserContent");
193 this._glData = null; 194 //
194 if (elt) 195 if (elt) {
195 {
196 var cdm = new CanvasDataManager();
197 this._glData = []; 196 this._glData = [];
198 cdm.collectGLData( elt, this._glData ); 197 //if (path) {
198 //this.collectGLData(elt, this._glData, path);
199 //} else {
200 this.collectGLData(elt, this._glData );
201 //}
202 } else {
203 this._glData = null
199 } 204 }
200 205 //
201 return this._glData; 206 return this._glData;
202 }, 207 },
203 208 set: function(value) {
204 set: function(value)
205 {
206 var elt = this.documentRoot; 209 var elt = this.documentRoot;
207 if (elt) 210 if (elt)
208 { 211 {
209 console.log( "load canvas data: " , value ); 212 var nWorlds= value.length;
210 var cdm = new CanvasDataManager(); 213 for (var i=0; i<nWorlds; i++)
211 cdm.loadGLData(elt, value); 214 {
215 /*
216 // Use this code to test the runtime version of WebGL
217 var cdm = new CanvasDataManager();
218 cdm.loadGLData(elt, value, null );
219 */
220
221 // /*
222 var importStr = value[i];
223 var startIndex = importStr.indexOf( "id: " );
224 if (startIndex >= 0) {
225 var endIndex = importStr.indexOf( "\n", startIndex );
226 if (endIndex > 0) {
227 var id = importStr.substring( startIndex+4, endIndex );
228 if (id) {
229 var canvas = this.findCanvasWithID( id, elt );
230 if (canvas) {
231 if (!canvas.elementModel) {
232 NJUtils.makeElementModel(canvas, "Canvas", "shape", true);
233 }
234 if (canvas.elementModel) {
235 if (canvas.elementModel.shapeModel.GLWorld) {
236 canvas.elementModel.shapeModel.GLWorld.clearTree();
237 }
238 var index = importStr.indexOf( "webGL: " );
239 var useWebGL = (index >= 0)
240 var world = new GLWorld( canvas, useWebGL );
241 world.import( importStr );
242 this.buildShapeModel( canvas.elementModel, world );
243 }
244 }
245 }
246 }
247 }
248 // */
249 }
212 } 250 }
213 } 251 }
214 }, 252 },
215 253
254 buildShapeModel:
255 {
256 value: function( elementModel, world )
257 {
258 var shapeModel = elementModel.shapeModel;
259 shapeModel.shapeCount = 1; // for now...
260 shapeModel.useWebGl = world._useWebGL;
261 shapeModel.GLWorld = world;
262 var root = world.getGeomRoot();
263 if (root)
264 {
265 shapeModel.GLGeomObj = root;
266 shapeModel.strokeSize = root._strokeWidth;
267 shapeModel.stroke = root._strokeColor.slice();
268 shapeModel.strokeMaterial = root._strokeMaterial.dup();
269 shapeModel.strokeStyle = "solid";
270 //shapeModel.strokeStyleIndex
271 //shapeModel.border
272 //shapeModel.background
273 switch (root.geomType())
274 {
275 case root.GEOM_TYPE_RECTANGLE:
276 elementModel.selection = "Rectangle";
277 elementModel.pi = "RectanglePi";
278 shapeModel.fill = root._fillColor.slice();
279 shapeModel.fillMaterial = root._fillMaterial.dup();
280 shapeModel.tlRadius = root._tlRadius;
281 shapeModel.trRadius = root._trRadius;
282 shapeModel.blRadius = root._blRadius;
283 shapeModel.brRadius = root._brRadius;
284 break;
285
286 case root.GEOM_TYPE_CIRCLE:
287 elementModel.selection = "Oval";
288 elementModel.pi = "OvalPi";
289 shapeModel.fill = root._fillColor.slice();
290 shapeModel.fillMaterial = root._fillMaterial.dup();
291 shapeModel.innerRadius = root._innerRadius;
292 break;
293
294 case root.GEOM_TYPE_LINE:
295 elementModel.selection = "Line";
296 elementModel.pi = "LinePi";
297 shapeModel.slope = root._slope;
298 break;
299
300 default:
301 console.log( "geometry type not supported for file I/O, " + root.geomType());
302 break;
303 }
304 }
305 }
306 },
307
216 zoomFactor: { 308 zoomFactor: {
217 get: function() { return this._zoomFactor; }, 309 get: function() { return this._zoomFactor; },
218 set: function(value) { this._zoomFactor = value; } 310 set: function(value) { this._zoomFactor = value; }
@@ -240,6 +332,27 @@ exports.HTMLDocument = Montage.create(TextDocument, {
240 } 332 }
241 } 333 }
242 }, 334 },
335
336 /**
337 * search the DOM tree to find a canvas with the given id
338 */
339 findCanvasWithID: {
340 value: function( id, elt ) {
341 var cid = elt.getAttribute( "data-RDGE-id" );
342 if (cid == id) return elt;
343
344 if (elt.children)
345 {
346 var nKids = elt.children.length;
347 for (var i=0; i<nKids; i++)
348 {
349 var child = elt.children[i];
350 var foundElt = this.findCanvasWithID( id, child );
351 if (foundElt) return foundElt;
352 }
353 }
354 }
355 },
243 356
244 357
245 358
@@ -768,8 +881,12 @@ exports.HTMLDocument = Montage.create(TextDocument, {
768 value: function () { 881 value: function () {
769 //TODO: Add logic to handle save before preview 882 //TODO: Add logic to handle save before preview
770 this.application.ninja.documentController.handleExecuteSaveAll(null); 883 this.application.ninja.documentController.handleExecuteSaveAll(null);
771 //Launching 'blank' tab for testing movie 884 //Temp check for webGL Hack
772 window.open(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]); 885 if (this.application.ninja.documentController.activeDocument.glData.length && this.application.ninja.documentController.activeDocument.glData.length > 0) {
886 setTimeout(function () {window.open(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]);}.bind(this), 3500);
887 } else {
888 window.open(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]);
889 }
773 //chrome.tabs.create({url: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]}); 890 //chrome.tabs.create({url: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]});
774 } 891 }
775 }, 892 },
@@ -788,8 +905,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
788 } 905 }
789 } 906 }
790 } 907 }
791 //return {mode: 'html', document: this._userDocument, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; 908 return {mode: 'html', document: this._userDocument, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML};
792 return {mode: 'html', document: this._userDocument, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML};
793 } else if (this.currentView === "code"){ 909 } else if (this.currentView === "code"){
794 //TODO: Would this get call when we are in code of HTML? 910 //TODO: Would this get call when we are in code of HTML?
795 } else { 911 } else {
@@ -812,8 +928,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
812 } 928 }
813 } 929 }
814