From 7bdcab084d1991361ba8d37a7435efd229648630 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 1 May 2012 10:12:40 -0700 Subject: Setting up new architecture for I/O --- js/document/models/base.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'js/document/models') diff --git a/js/document/models/base.js b/js/document/models/base.js index f237e793..f4dbbc0b 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js @@ -21,18 +21,26 @@ exports.BaseDocumentModel = Montage.create(Montage, { file: { value: null }, - + //////////////////////////////////////////////////////////////////// + // _name: { value: null }, - + //////////////////////////////////////////////////////////////////// + // _isActive: { value: null }, - + //////////////////////////////////////////////////////////////////// + // _needsSave: { value: null }, + //////////////////////////////////////////////////////////////////// + // + _currentView: { + value: null + }, //////////////////////////////////////////////////////////////////// // njdata: { @@ -42,6 +50,26 @@ exports.BaseDocumentModel = Montage.create(Montage, { // views: { value: null + }, + //////////////////////////////////////////////////////////////////// + // + save: { + value: null + }, + //////////////////////////////////////////////////////////////////// + // + saveAs: { + value: null + }, + //////////////////////////////////////////////////////////////////// + // + saveAll: { + value: null + }, + //////////////////////////////////////////////////////////////////// + // + close: { + value: null } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 4ba680a7e9168d0f505a81e42a287dfbc54b4d7d Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 1 May 2012 15:26:37 -0700 Subject: Preliminary IO to new DOM view --- js/document/models/base.js | 55 +++++++++++++++++++++++++++++++++++----------- js/document/models/html.js | 1 - 2 files changed, 42 insertions(+), 14 deletions(-) (limited to 'js/document/models') diff --git a/js/document/models/base.js b/js/document/models/base.js index f4dbbc0b..3bb69f6b 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js @@ -6,36 +6,49 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot //////////////////////////////////////////////////////////////////////// // -var Montage = require("montage/core/core").Montage; +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component; //////////////////////////////////////////////////////////////////////// // -exports.BaseDocumentModel = Montage.create(Montage, { +exports.BaseDocumentModel = Montage.create(Component, { //////////////////////////////////////////////////////////////////// // hasTemplate: { - enumerable: false, value: false }, //////////////////////////////////////////////////////////////////// // - file: { + _file: { value: null }, - //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// // - _name: { - value: null + file: { + get: function() {return this._file;}, + set: function(value) {this._file = value;} }, //////////////////////////////////////////////////////////////////// // _isActive: { value: null + }, + //////////////////////////////////////////////////////////////////// + // + isActive: { + get: function() {return this._isActive;}, + set: function(value) {this._isActive = value;} }, //////////////////////////////////////////////////////////////////// // _needsSave: { value: null }, + //////////////////////////////////////////////////////////////////// + // + needsSave: { + get: function() {return this._needsSave;}, + set: function(value) {this._needsSave = value;} + }, //////////////////////////////////////////////////////////////////// // _currentView: { @@ -43,33 +56,49 @@ exports.BaseDocumentModel = Montage.create(Montage, { }, //////////////////////////////////////////////////////////////////// // - njdata: { - value: null + currentView: { + get: function() {return this._currentView;}, + set: function(value) {this._currentView = value;} }, //////////////////////////////////////////////////////////////////// // views: { value: null }, + //////////////////////////////////////////////////////////////////// + // + switchViewTo: { + value: function () { + // + } + }, //////////////////////////////////////////////////////////////////// // save: { - value: null + value: function () { + // + } }, //////////////////////////////////////////////////////////////////// // saveAs: { - value: null + value: function () { + // + } }, //////////////////////////////////////////////////////////////////// // saveAll: { - value: null + value: function () { + // + } }, //////////////////////////////////////////////////////////////////// // close: { - value: null + value: function () { + // + } } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// diff --git a/js/document/models/html.js b/js/document/models/html.js index ff57454b..f45a0e21 100755 --- a/js/document/models/html.js +++ b/js/document/models/html.js @@ -14,7 +14,6 @@ exports.HtmlDocumentModel = Montage.create(BaseDocumentModel, { //////////////////////////////////////////////////////////////////// // hasTemplate: { - enumerable: false, value: false } //////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From efe62dff2ba6894551fb9679d150255bae5af36e Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Fri, 4 May 2012 16:00:14 -0700 Subject: Draw 3d grid by default since app model is not hooked up yet. Signed-off-by: Nivesh Rajbhandari --- js/document/models/html.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'js/document/models') diff --git a/js/document/models/html.js b/js/document/models/html.js index f45a0e21..5eedb731 100755 --- a/js/document/models/html.js +++ b/js/document/models/html.js @@ -15,6 +15,10 @@ exports.HtmlDocumentModel = Montage.create(BaseDocumentModel, { // hasTemplate: { value: false + }, + + draw3DGrid: { + value: false } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From b8c27edc106818ff84f93ebe30ce50359a03885b Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Mon, 7 May 2012 13:21:31 -0700 Subject: Adding webGL support for opening files Added I/O for loading webGL on open file. I/O support for saving to come. --- js/document/models/base.js | 13 +++ js/document/models/html.js | 197 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 207 insertions(+), 3 deletions(-) (limited to 'js/document/models') diff --git a/js/document/models/base.js b/js/document/models/base.js index 3bb69f6b..746922ad 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js @@ -72,6 +72,19 @@ exports.BaseDocumentModel = Montage.create(Component, { // } }, + //////////////////////////////////////////////////////////////////// + // + browserPreview: { + value: function (browser) { + // + switch (browser) { + case 'chrome': + break; + default: + break; + } + } + }, //////////////////////////////////////////////////////////////////// // save: { diff --git a/js/document/models/html.js b/js/document/models/html.js index 5eedb731..e0a18850 100755 --- a/js/document/models/html.js +++ b/js/document/models/html.js @@ -7,7 +7,10 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot //////////////////////////////////////////////////////////////////////// // var Montage = require("montage/core/core").Montage, - BaseDocumentModel = require("js/document/models/base").BaseDocumentModel; + BaseDocumentModel = require("js/document/models/base").BaseDocumentModel, + MaterialsModel = require("js/models/materials-model").MaterialsModel, + NJUtils = require("js/lib/NJUtils").NJUtils, + GLWorld = require("js/lib/drawing/world").World; //////////////////////////////////////////////////////////////////////// // exports.HtmlDocumentModel = Montage.create(BaseDocumentModel, { @@ -16,10 +19,198 @@ exports.HtmlDocumentModel = Montage.create(BaseDocumentModel, { hasTemplate: { value: false }, - + //////////////////////////////////////////////////////////////////// + // draw3DGrid: { value: false - } + }, + //////////////////////////////////////////////////////////////////// + // + _glData: { + value: null + }, + //////////////////////////////////////////////////////////////////// + // + glData: { + // + get: function() { + // + var elt = this.views.design.iframe.contentWindow.document.body; + // + if (elt) { + var matLib = MaterialsModel.exportMaterials(); + this._glData = [matLib]; + this.collectGLData(elt, this._glData ); + } else { + this._glData = null + } + // + return this._glData; + }, + // + set: function(value) { + // + var elt = this.views.design.iframe.contentWindow.document.body; + // + if (elt) { + /* + // Use this code to test the runtime version of WebGL + var cdm = new NinjaCvsRt.CanvasDataManager(); + cdm.loadGLData(elt, value, null ); + */ + + // + var i, nWorlds= value.length; + // + for (i = 0; i < nWorlds; i++) { + // get the data for the next canvas + var importStr = value[i], id, jObj, index = importStr.indexOf(';'), matLibStr, matLibObj, startIndex, endIndex, canvas, useWebGL, world; + // determine if it is the new (JSON) or old style format + if ((importStr[0] === 'v') && (index < 24)) { + // JSON format. pull off the + importStr = importStr.substr(index+1); + jObj = JSON.parse(importStr); + id = jObj.id; + } else { + // at this point the data could be either the materials library or + // an old style world. We can determine which by converting the string + // to an object via JSON.parse. That operation will fail if the string + // is an old style world. + matLibStr = 'materialLibrary;'; + index = importStr.indexOf(matLibStr); + if (index == 0) { + importStr = importStr.substr(matLibStr.length); + matLibObj = JSON.parse(importStr); + MaterialsModel.importMaterials(matLibObj); + } else { + startIndex = importStr.indexOf("id: "); + if (startIndex >= 0) { + endIndex = importStr.indexOf("\n", startIndex); + if (endIndex > 0) id = importStr.substring(startIndex+4, endIndex); + } + } + } + // + if (id != null) { + // + 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(); + } + // + if (jObj) { + useWebGL = jObj.webGL; + world = new GLWorld(canvas, useWebGL); + world.importJSON(jObj); + } + // + this.buildShapeModel(canvas.elementModel, world); + } + } + } + } + } + } + }, + //////////////////////////////////////////////////////////////////// + // + findCanvasWithID: { + value: function(id, elt) { + // + var i, child, nKids, foundElt, cid = elt.getAttribute("data-RDGE-id"); + // + if (cid == id) return elt; + // + if (elt.children) { + nKids = elt.children.length; + for (i=0; i= 0) { - endIndex = importStr.indexOf("\n", startIndex); - if (endIndex > 0) id = importStr.substring(startIndex+4, endIndex); - } - } - } - // - if (id != null) { - // - 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(); - } - // - if (jObj) { - useWebGL = jObj.webGL; - world = new GLWorld(canvas, useWebGL); - world.importJSON(jObj); - } - // - this.buildShapeModel(canvas.elementModel, world); - } - } - } - } - } - } - }, - //////////////////////////////////////////////////////////////////// - // - findCanvasWithID: { - value: function(id, elt) { - // - var i, child, nKids, foundElt, cid = elt.getAttribute("data-RDGE-id"); - // - if (cid == id) return elt; - // - if (elt.children) { - nKids = elt.children.length; - for (i=0; i