aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/sub-path.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/sub-path.js')
-rwxr-xr-xjs/lib/geom/sub-path.js181
1 files changed, 76 insertions, 105 deletions
diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js
index d8d74928..35070915 100755
--- a/js/lib/geom/sub-path.js
+++ b/js/lib/geom/sub-path.js
@@ -95,6 +95,7 @@ var GLSubpath = function GLSubpath() {
95 this._planeMat = null; 95 this._planeMat = null;
96 this._planeMatInv = null; 96 this._planeMatInv = null;
97 this._planeCenter = null; 97 this._planeCenter = null;
98 this._dragPlane = null;
98 99
99 //used to query what the user selected, OR-able for future extensions 100 //used to query what the user selected, OR-able for future extensions
100 this.SEL_NONE = 0; //nothing was selected 101 this.SEL_NONE = 0; //nothing was selected
@@ -130,7 +131,10 @@ var GLSubpath = function GLSubpath() {
130 // get the world 131 // get the world
131 var world = this.getWorld(); 132 var world = this.getWorld();
132 if (!world) throw( "null world in subpath render" ); 133 if (!world) throw( "null world in subpath render" );
133 134 if (!this._canvas){
135 //set the canvas by querying the world
136 this._canvas = this.getWorld().getCanvas();
137 }
134 // get the context 138 // get the context
135 var ctx = world.get2DContext(); 139 var ctx = world.get2DContext();
136 if (!ctx) throw ("null context in subpath render"); 140 if (!ctx) throw ("null context in subpath render");
@@ -145,42 +149,19 @@ var GLSubpath = function GLSubpath() {
145 //build the coordinates of the samples in 2D (canvas) space (localDirty bit checked in buildLocalCoord 149 //build the coordinates of the samples in 2D (canvas) space (localDirty bit checked in buildLocalCoord
146 this.buildLocalCoord(); 150 this.buildLocalCoord();
147 151
148 // 152 //figure the size of the area we will draw into
149 var bboxWidth=0, bboxHeight=0; 153 var bboxWidth=0, bboxHeight=0;
150 //var bboxMid=[0,0,0];
151 if (useLocalCoord){ 154 if (useLocalCoord){
152 bboxWidth = this._LocalBBoxMax[0] - this._LocalBBoxMin[0]; 155 bboxWidth = this._LocalBBoxMax[0] - this._LocalBBoxMin[0];
153 bboxHeight = this._LocalBBoxMax[1] - this._LocalBBoxMin[1]; 156 bboxHeight = this._LocalBBoxMax[1] - this._LocalBBoxMin[1];
154 //bboxMid = [0.5 * (this._LocalBBoxMax[0] + this._LocalBBoxMin[0]), 0.5 * (this._LocalBBoxMax[1] + this._LocalBBoxMin[1]), 0.5 * (this._LocalBBoxMax[2] + this._LocalBBoxMin[2])];
155 } 157 }
156 else { 158 else {
157 var bboxMin = this.getBBoxMin(); 159 var bboxMin = this.getBBoxMin();
158 var bboxMax = this.getBBoxMax(); 160 var bboxMax = this.getBBoxMax();
159 bboxWidth = bboxMax[0] - bboxMin[0]; 161 bboxWidth = bboxMax[0] - bboxMin[0];
160 bboxHeight = bboxMax[1] - bboxMin[1]; 162 bboxHeight = bboxMax[1] - bboxMin[1];
161 //bboxMid = [0.5 * (bboxMax[0] + bboxMin[0]), 0.5 * (bboxMax[1] + bboxMin[1]), 0.5 * (bboxMax[2] + bboxMin[2])];
162 } 163 }
163 164
164 if (this._canvas) {
165 /*
166 var ViewUtils = require("js/helper-classes/3D/view-utils").ViewUtils;
167 //compute the plane center as the midpoint of the local bbox converted to stage world space
168 var planeCenter = ViewUtils.localToStageWorld(bboxMid, this._canvas);
169 planeCenter[0]+=400; planeCenter[1]+=300; //todo replace these lines with the correct call for the offset
170 console.log("PEN: local bboxMid: "+ bboxMid +", stage-world bboxMid: "+ planeCenter);
171 var newLeft = planeCenter[0] - 0.5*bboxWidth;
172 console.log("PEN: newLeft: "+ newLeft +", bboxWidth: "+bboxWidth);
173 newLeft = Math.round(newLeft);//Math.round(this._planeCenter[0] - 0.5 * bboxWidth);
174 console.log("PEN: newLeft rounded: "+ newLeft);
175 var newTop = Math.round(planeCenter[1] - 0.5 * bboxHeight);//Math.round(this._planeCenter[1] - 0.5 * bboxHeight);
176 //assign the new position, width, and height as the canvas dimensions through the canvas controller
177 CanvasController.setProperty(this._canvas, "left", newLeft+"px");
178 CanvasController.setProperty(this._canvas, "top", newTop+"px");
179 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px");
180 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px");
181 this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas);
182 */
183 }
184 ctx.save(); 165 ctx.save();
185 ctx.clearRect(0, 0, bboxWidth, bboxHeight); 166 ctx.clearRect(0, 0, bboxWidth, bboxHeight);
186 167
@@ -354,6 +335,10 @@ GLSubpath.prototype.setPlaneMatrix = function(planeMat){
354 this._planeMat = planeMat; 335 this._planeMat = planeMat;
355}; 336};
356 337
338GLSubpath.prototype.setDragPlane = function(p){
339 this._dragPlane = p;
340};
341
357GLSubpath.prototype.setPlaneMatrixInverse = function(planeMatInv){ 342GLSubpath.prototype.setPlaneMatrixInverse = function(planeMatInv){
358 this._planeMatInv = planeMatInv; 343 this._planeMatInv = planeMatInv;
359}; 344};
@@ -867,6 +852,12 @@ GLSubpath.prototype.getStrokeWidth = function () {
867}; 852};
868 853
869GLSubpath.prototype.translateSubpathPerCanvas = function(elemMediator){ 854GLSubpath.prototype.translateSubpathPerCanvas = function(elemMediator){
855 if (!this._canvas){
856 if (!this.getWorld())
857 return; //cannot do anything if there is no world
858 //set the canvas by querying the world
859 this._canvas = this.getWorld().getCanvas();
860 }
870 //check if the canvas was translated 861 //check if the canvas was translated
871 var penCanvasCurrentLeft = parseInt(elemMediator.getProperty(this._canvas, "left"));//parseFloat(DocumentControllerModule.DocumentController.GetElementStyle(this._penCanvas, "left")); 862 var penCanvasCurrentLeft = parseInt(elemMediator.getProperty(this._canvas, "left"));//parseFloat(DocumentControllerModule.DocumentController.GetElementStyle(this._penCanvas, "left"));
872 var penCanvasCurrentTop = parseInt(elemMediator.getProperty(this._canvas, "top"));//parseFloat(DocumentControllerModule.DocumentController.GetElementStyle(this._penCanvas, "top")); 863 var penCanvasCurrentTop = parseInt(elemMediator.getProperty(this._canvas, "top"));//parseFloat(DocumentControllerModule.DocumentController.GetElementStyle(this._penCanvas, "top"));
@@ -1516,95 +1507,75 @@ GLSubpath.prototype.isPointInQuad2D = function(r0,r1,r2,r3,p){
1516 return false; 1507 return false;
1517}; 1508};
1518 1509
1519GLSubpath.prototype.export = function() { 1510GLSubpath.prototype.exportJSON = function() {
1520 var rtnStr = "type: " + this.geomType() + "\n"; 1511 var retObject= new Object();
1521 1512 //the type of this object
1522 rtnStr += "strokeWidth: " + this._strokeWidth + "\n"; 1513 retObject.type = this.geomType();
1523 rtnStr += "strokeStyle: " + this._strokeStyle + "\n"; 1514 retObject.geomType = retObject.type;
1524
1525 rtnStr += "strokeMat: ";
1526 if (this._strokeMaterial)
1527 rtnStr += this._strokeMaterial.getName();
1528 else
1529 rtnStr += "flatMaterial";
1530 rtnStr += "\n";
1531
1532 rtnStr += "fillMat: ";
1533 if (this._fillMaterial)
1534 rtnStr += this._fillMaterial.getName();
1535 else
1536 rtnStr += "flatMaterial";
1537 rtnStr += "\n";
1538
1539 var isClosedStr = "false";
1540 if (this._isClosed)
1541 isClosedStr = "true";
1542 rtnStr += "isClosed: " + isClosedStr + "\n";
1543
1544 //add the anchor points
1545 var numAnchors = this._Anchors.length;
1546 rtnStr += "numAnchors: " + numAnchors + "\n";
1547 for (var i=0;i<numAnchors;i++){
1548 rtnStr += "anchor"+i+"x: " + this._Anchors[i].getPosX() + "\n";
1549 rtnStr += "anchor"+i+"y: " + this._Anchors[i].getPosY() + "\n";
1550 rtnStr += "anchor"+i+"z: " + this._Anchors[i].getPosZ() + "\n";
1551
1552 rtnStr += "anchor"+i+"prevx: " + this._Anchors[i].getPrevX() + "\n";
1553 rtnStr += "anchor"+i+"prevy: " + this._Anchors[i].getPrevY() + "\n";
1554 rtnStr += "anchor"+i+"prevz: " + this._Anchors[i].getPrevZ() + "\n";
1555
1556 rtnStr += "anchor"+i+"nextx: " + this._Anchors[i].getNextX() + "\n";
1557 rtnStr += "anchor"+i+"nexty: " + this._Anchors[i].getNextY() + "\n";
1558 rtnStr += "anchor"+i+"nextz: " + this._Anchors[i].getNextZ() + "\n";
1559 }
1560 return rtnStr;
1561};
1562 1515
1563GLSubpath.prototype.import = function( importStr ) { 1516 //the geometry for this object (anchor points in stage world space)
1564 this._strokeWidth = this.getPropertyFromString( "strokeWidth: ", importStr ); 1517 retObject.anchors = this._Anchors.slice(0);
1565 this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); 1518 retObject.isClosed = this._isClosed;
1566 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr );
1567 var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr );
1568
1569 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
1570 if (!strokeMat) {
1571 console.log( "object material not found in library: " + strokeMaterialName );
1572 strokeMat = new FlatMaterial();
1573 }
1574 1519
1575 this._strokeMaterial = strokeMat; 1520 //location of the canvas of this object
1521 retObject.canvasLeft = this._canvasLeft;
1522 retObject.canvasTop = this._canvasTop;
1576 1523
1577 var fillMat = MaterialsModel.getMaterial( fillMaterialName ); 1524 retObject.planeCenter = [this._planeCenter[0],this._planeCenter[1],this._planeCenter[2]];
1578 if (!fillMat) { 1525 retObject.planeMat = this._planeMat;
1579 console.log( "object material not found in library: " + fillMaterialName ); 1526 retObject.planeMatInv = this._planeMatInv;
1580 fillMat = new FlatMaterial(); 1527 retObject.dragPlane = [this._dragPlane[0],this._dragPlane[1],this._dragPlane[2],this._dragPlane[3]];
1581 }
1582 1528
1583 this._fillMaterial = fillMat; 1529 //stroke appearance properties
1530 retObject.strokeWidth = this._strokeWidth;
1531 retObject.strokeColor = this._strokeColor;
1532 retObject.fillColor = this._fillColor;
1533 return retObject;
1534};
1584 1535
1585 var isClosedStr = this.getPropertyFromString( "isClosed: ", importStr); 1536GLSubpath.prototype.export = function() {
1586 this._isClosed = isClosedStr === "true"; 1537 var jsonObject = this.exportJSON();
1538 var stringified = JSON.stringify(jsonObject);
1539 return "type: " + this.geomType() + "\n" + stringified;
1540};
1587 1541
1588 var numAnchors = this.getPropertyFromString("numAnchors: ", importStr); 1542GLSubpath.prototype.importJSON = function(jo) {
1589 for (var i=0;i<numAnchors;i++) { 1543 if (this.geomType()!== jo.geomType){
1590 var posX = this.getPropertyFromString("anchor"+i+"x", importStr); 1544 return;
1591 var posY = this.getPropertyFromString("anchor"+i+"y", importStr); 1545 }
1592 var posZ = this.getPropertyFromString("anchor"+i+"z", importStr); 1546 //the geometry for this object
1547 this._Anchors = [];
1548 var i=0;
1549 for (i=0;i<jo.anchors.length;i++){
1550 this.addAnchor(new AnchorPoint());
1551 var newAnchor = this.getAnchor(this.getSelectedAnchorIndex());
1552 var ipAnchor = jo.anchors[i];
1553 newAnchor.setPos(ipAnchor._x, ipAnchor._y, ipAnchor._z);
1554 newAnchor.setPrevPos(ipAnchor._prevX, ipAnchor._prevY, ipAnchor._prevZ);
1555 newAnchor.setNextPos(ipAnchor._nextX, ipAnchor._nextY, ipAnchor._nextZ);
1556 }
1557 this._isClosed = jo.isClosed;
1593 1558
1594 var prevX = this.getPropertyFromString("anchor"+i+"prevx", importStr); 1559 //location of the canvas for this object
1595 var prevY = this.getPropertyFromString("anchor"+i+"prevy", importStr); 1560 this._canvasLeft = jo.canvasLeft;
1596 var prevZ = this.getPropertyFromString("anchor"+i+"prevz", importStr); 1561 this._canvasTop = jo.canvasTop;
1562
1563 this._planeCenter = [jo.planeCenter[0],jo.planeCenter[1],jo.planeCenter[2]];
1564 this._planeMat = jo.planeMat;