aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-03-22 16:26:02 -0700
committerJose Antonio Marquez2012-03-22 16:26:02 -0700
commit748a5c55e15809add748a15a87cd730e3fcee4bf (patch)
tree688f3ee299b2985fa5617426a5789d86f518b877 /js/document
parent7fbda862c62f37d4c67e4d5a619b7e3cffc309ff (diff)
parentb25195d010417417bb5b2e5362385078d68d9a84 (diff)
downloadninja-748a5c55e15809add748a15a87cd730e3fcee4bf.tar.gz
Merge branch 'refs/heads/Ninja-Montage-Integration' into FileIO-Montage-Components
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/html-document.js108
1 files changed, 76 insertions, 32 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 9de2d8d6..7ab4272b 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -9,7 +9,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
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 GLWorld = require("js/lib/drawing/world").World,
13 MaterialsModel = require("js/models/materials-model").MaterialsModel;
13//////////////////////////////////////////////////////////////////////// 14////////////////////////////////////////////////////////////////////////
14// 15//
15exports.HTMLDocument = Montage.create(TextDocument, { 16exports.HTMLDocument = Montage.create(TextDocument, {
@@ -193,12 +194,9 @@ exports.HTMLDocument = Montage.create(TextDocument, {
193 var elt = this.iframe.contentWindow.document.getElementById("UserContent"); 194 var elt = this.iframe.contentWindow.document.getElementById("UserContent");
194 // 195 //
195 if (elt) { 196 if (elt) {
196 this._glData = []; 197 var matLib = MaterialsModel.exportMaterials();
197 //if (path) { 198 this._glData = [matLib];
198 //this.collectGLData(elt, this._glData, path); 199 this.collectGLData(elt, this._glData );
199 //} else {
200 this.collectGLData(elt, this._glData );
201 //}
202 } else { 200 } else {
203 this._glData = null 201 this._glData = null
204 } 202 }
@@ -219,29 +217,74 @@ exports.HTMLDocument = Montage.create(TextDocument, {
219 */ 217 */
220 218
221 // /* 219 // /*
220 // get the data for the next canvas
222 var importStr = value[i]; 221 var importStr = value[i];
223 var startIndex = importStr.indexOf( "id: " ); 222
224 if (startIndex >= 0) { 223 // determine if it is the new (JSON) or old style format
225 var endIndex = importStr.indexOf( "\n", startIndex ); 224 var id = null;
226 if (endIndex > 0) { 225 var jObj = null;
227 var id = importStr.substring( startIndex+4, endIndex ); 226 var index = importStr.indexOf( ';' );
228 if (id) { 227 if ((importStr[0] === 'v') && (index < 24))
229 var canvas = this.findCanvasWithID( id, elt ); 228 {
230 if (canvas) { 229 // JSON format. pull off the
231 if (!canvas.elementModel) { 230 importStr = importStr.substr( index+1 );
232 NJUtils.makeElementModel(canvas, "Canvas", "shape", true); 231 jObj = jObj = JSON.parse( importStr );
233 } 232 id = jObj.id;
234 if (canvas.elementModel) { 233 }
235 if (canvas.elementModel.shapeModel.GLWorld) { 234 else
236 canvas.elementModel.shapeModel.GLWorld.clearTree(); 235 {
237 } 236 // at this point the data could be either the materials library or
238 var index = importStr.indexOf( "webGL: " ); 237 // an old style world. We can determine which by converting the string
239 var useWebGL = (index >= 0) 238 // to an object via JSON.parse. That operation will fail if the string
240 var world = new GLWorld( canvas, useWebGL ); 239 // is an old style world.
241 world.import( importStr ); 240 var matLibStr = 'materialLibrary;';
242 this.buildShapeModel( canvas.elementModel, world ); 241 index = importStr.indexOf( matLibStr );
243 } 242 if (index == 0)
243 {
244 importStr = importStr.substr( matLibStr.length );
245 var matLibObj = JSON.parse( importStr );
246 MaterialsModel.importMaterials( matLibObj );
247 }
248 else
249 {
250 var startIndex = importStr.indexOf( "id: " );
251 if (startIndex >= 0) {
252 var endIndex = importStr.indexOf( "\n", startIndex );
253 if (endIndex > 0)
254 id = importStr.substring( startIndex+4, endIndex );
255 }
256 }
257 }
258
259 if (id != null)
260 {
261 var canvas = this.findCanvasWithID( id, elt );
262 if (canvas)
263 {
264 if (!canvas.elementModel)
265 {
266 NJUtils.makeElementModel(canvas, "Canvas", "shape", true);
267 }
268 if (canvas.elementModel)
269 {
270 if (canvas.elementModel.shapeModel.GLWorld)
271 canvas.elementModel.shapeModel.GLWorld.clearTree();
272
273 if (jObj)
274 {
275 var useWebGL = jObj.webGL;
276 var world = new GLWorld( canvas, useWebGL );
277 world.importJSON( jObj );
278 }
279 else
280 {
281 var index = importStr.indexOf( "webGL: " );
282 var useWebGL = (index >= 0);
283 var world = new GLWorld( canvas, useWebGL );
284 world.import( importStr );
244 } 285 }
286
287 this.buildShapeModel( canvas.elementModel, world );
245 } 288 }
246 } 289 }
247 } 290 }
@@ -265,7 +308,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
265 shapeModel.GLGeomObj = root; 308 shapeModel.GLGeomObj = root;
266 shapeModel.strokeSize = root._strokeWidth; 309 shapeModel.strokeSize = root._strokeWidth;
267 shapeModel.stroke = root._strokeColor.slice(); 310 shapeModel.stroke = root._strokeColor.slice();
268 shapeModel.strokeMaterial = root._strokeMaterial.dup(); 311 shapeModel.strokeMaterial = root._strikeMaterial ? root._strokeMaterial.dup() : null;
269 shapeModel.strokeStyle = "solid"; 312 shapeModel.strokeStyle = "solid";
270 //shapeModel.strokeStyleIndex 313 //shapeModel.strokeStyleIndex
271 //shapeModel.border 314 //shapeModel.border
@@ -276,7 +319,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
276 elementModel.selection = "Rectangle"; 319 elementModel.selection = "Rectangle";
277 elementModel.pi = "RectanglePi"; 320 elementModel.pi = "RectanglePi";
278 shapeModel.fill = root._fillColor.slice(); 321 shapeModel.fill = root._fillColor.slice();
279 shapeModel.fillMaterial = root._fillMaterial.dup(); 322 shapeModel.fillMaterial = root._fillMaterial ? root._fillMaterial.dup() : null;
280 shapeModel.tlRadius = root._tlRadius; 323 shapeModel.tlRadius = root._tlRadius;
281 shapeModel.trRadius = root._trRadius; 324 shapeModel.trRadius = root._trRadius;
282 shapeModel.blRadius = root._blRadius; 325 shapeModel.blRadius = root._blRadius;
@@ -287,7 +330,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
287 elementModel.selection = "Oval"; 330 elementModel.selection = "Oval";
288 elementModel.pi = "OvalPi"; 331 elementModel.pi = "OvalPi";
289 shapeModel.fill = root._fillColor.slice(); 332 shapeModel.fill = root._fillColor.slice();
290 shapeModel.fillMaterial = root._fillMaterial.dup(); 333 shapeModel.fillMaterial = root._fillMaterial ? root._fillMaterial.dup() : null;
291 shapeModel.innerRadius = root._innerRadius; 334 shapeModel.innerRadius = root._innerRadius;
292 break; 335 break;
293 336
@@ -382,7 +425,8 @@ exports.HTMLDocument = Montage.create(TextDocument, {
382 { 425 {
383 if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) 426 if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld)
384 { 427 {
385 var data = elt.elementModel.shapeModel.GLWorld.export(); 428 var data = elt.elementModel.shapeModel.GLWorld.exportJSON();
429 //var data = elt.elementModel.shapeModel.GLWorld.export();
386 dataArray.push( data ); 430 dataArray.push( data );
387 } 431 }
388 432