From a0d23354802ebc6b437698acb4b18d3395d47cd1 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 16 Mar 2012 12:26:30 -0700 Subject: Conversion to JSON based file IO for canvas2D and WebGL rendering --- js/lib/geom/circle.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 7 deletions(-) (limited to 'js/lib/geom/circle.js') diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index f94d4e6b..7d1a3452 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js @@ -53,13 +53,13 @@ var Circle = function GLCircle() { if(strokeMaterial){ this._strokeMaterial = strokeMaterial; } else { - this._strokeMaterial = MaterialsModel.exportFlatMaterial(); + this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); } if(fillMaterial) { this._fillMaterial = fillMaterial; } else { - this._fillMaterial = MaterialsModel.exportFlatMaterial(); + this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); } this.exportMaterials(); @@ -551,7 +551,65 @@ var Circle = function GLCircle() { } }; - this.export = function() { + this.exportJSON = function() + { + var jObj = + { + 'type' : this.geomType(), + 'xoff' : this._xOffset, + 'yoff' : this._yOffset, + 'width' : this._width, + 'height' : this._height, + 'strokeWidth' : this._strokeWidth, + 'strokeColor' : this._strokeColor, + 'fillColor' : this._fillColor, + 'innerRadius' : this._innerRadius, + 'strokeStyle' : this._strokeStyle, + 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(), + 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(), + 'materials' : this.exportMaterialsJSON() + }; + + return jObj; + }; + + this.importJSON = function( jObj ) + { + this._xOffset = jObj.xoff; + this._yOffset = jObj.yoff; + this._width = jObj.width; + this._height = jObj.height; + this._strokeWidth = jObj.strokeWidth; + this._strokeColor = jObj.strokeColor; + this._fillColor = jObj.fillColor; + this._innerRadius = jObj.innerRadius; + this._strokeStyle = jObj.strokeStyle; + var strokeMaterialName = jObj.strokeMat; + var fillMaterialName = jObj.fillMat; + this.importMaterialsJSON( jObj.materials ); + + var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); + if (!strokeMat) { + console.log( "object material not found in library: " + strokeMaterialName ); + strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + } + else + strokeMat = strokeMat.dup(); + this._strokeMaterial = strokeMat; + + var fillMat = MaterialsModel.getMaterial( fillMaterialName ); + if (!fillMat) { + console.log( "object material not found in library: " + fillMaterialName ); + fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + } + else + fillMat = fillMat.dup(); + this._fillMaterial = fillMat; + }; + + + this.export = function() + { var rtnStr = "type: " + this.geomType() + "\n"; rtnStr += "xoff: " + this._xOffset + "\n"; @@ -568,7 +626,7 @@ var Circle = function GLCircle() { if (this._strokeMaterial) { rtnStr += this._strokeMaterial.getName(); } else { - rtnStr += "flatMaterial"; + rtnStr += MaterialsModel.getDefaultMaterialName(); } rtnStr += "\n"; @@ -577,7 +635,7 @@ var Circle = function GLCircle() { if (this._fillMaterial) { rtnStr += this._fillMaterial.getName(); } else { - rtnStr += "flatMaterial"; + rtnStr += MaterialsModel.getDefaultMaterialName(); } rtnStr += "\n"; @@ -602,7 +660,7 @@ var Circle = function GLCircle() { var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); if (!strokeMat) { console.log( "object material not found in library: " + strokeMaterialName ); - strokeMat = MaterialsModel.exportFlatMaterial(); + strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); } this._strokeMaterial = strokeMat; @@ -610,7 +668,7 @@ var Circle = function GLCircle() { var fillMat = MaterialsModel.getMaterial( fillMaterialName ); if (!fillMat) { console.log( "object material not found in library: " + fillMaterialName ); - fillMat = MaterialsModel.exportFlatMaterial(); + fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); } this._fillMaterial = fillMat; -- cgit v1.2.3 From 98a02c1ac6f189aba93d7cce64ba5bdbc0617f6c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 20 Mar 2012 16:26:52 -0700 Subject: Bug Fixes for Canvas & WebGL File IO --- js/lib/geom/circle.js | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'js/lib/geom/circle.js') diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index fec62308..d48bf98b 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js @@ -634,24 +634,6 @@ var Circle = function GLCircle() { var strokeMaterialName = jObj.strokeMat; var fillMaterialName = jObj.fillMat; this.importMaterialsJSON( jObj.materials ); - - var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); - if (!strokeMat) { - console.log( "object material not found in library: " + strokeMaterialName ); - strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); - } - else - strokeMat = strokeMat.dup(); - this._strokeMaterial = strokeMat; - - var fillMat = MaterialsModel.getMaterial( fillMaterialName ); - if (!fillMat) { - console.log( "object material not found in library: " + fillMaterialName ); - fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); - } - else - fillMat = fillMat.dup(); - this._fillMaterial = fillMat; }; -- cgit v1.2.3