1
/* This notice must be untouched at all times.
4
The latest version is available at
5
http://www.openjacob.org
7
Copyright (c) 2006 Andreas Herz. All rights reserved.
8
Created 5. 11. 2006 by Andreas Herz (Web: http://www.freegroup.de )
12
This library is free software; you can redistribute it and/or
13
modify it under the terms of the GNU Lesser General Public
14
License (LGPL) as published by the Free Software Foundation; either
15
version 2.1 of the License, or (at your option) any later version.
17
This library is distributed in the hope that it will be useful,
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
Lesser General Public License for more details.
22
You should have received a copy of the GNU Lesser General Public
23
License along with this library; if not, write to the Free Software
24
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA,
25
or see http://www.gnu.org/copyleft/lesser.html
29
* @class Routes a {@link draw2d.Connection}, possibly using a constraint.
32
* @author Andreas Herz
35
draw2d.BezierConnectionRouter=function(/*:boolean*/ noCheapRouter)
38
this.cheapRouter = new draw2d.ManhattanConnectionRouter();
40
this.cheapRouter=null;
42
// this.setTargetDecorator(new draw2d.ArrowConnectionDecorator());
45
draw2d.BezierConnectionRouter.prototype = new draw2d.ConnectionRouter;
46
draw2d.BezierConnectionRouter.prototype.type="BezierConnectionRouter";
49
draw2d.BezierConnectionRouter.prototype.drawBezier=function(/*:Array*/pointArray,/*:Array*/resultArray, /*:float*/t, /*:int*/iter)
52
var n = pointArray.length-1;
56
for (var i = 0; i < n_plus_1; i++)
59
q[i][0] = pointArray[i];
62
for (var j = 1; j <= n; j++)
64
for (var i = 0; i <= (n-j); i++)
66
q[i][j] = new draw2d.Point((1 - t) * q[i][j - 1].x + t * q[i + 1][j - 1].x,
67
(1 - t) * q[i][j - 1].y + t * q[i + 1][j - 1].y);
70
//Arrays für die Punkte der geteilten Kontrollpolygone C1, C2)
74
for (var i=0;i<n+1;i++)
82
this.drawBezier(c1,resultArray, t, --iter);
83
this.drawBezier(c2,resultArray, t, --iter);
89
resultArray.push(q[i][n-i]);
95
* @see draw2d.ConnectionRouter#route(Connection)
97
draw2d.BezierConnectionRouter.prototype.route=function(/*:draw2d.Connection*/ conn)
100
if(this.cheapRouter!=null && (conn.getSource().getParent().isMoving==true || conn.getTarget().getParent().isMoving==true ))
102
this.cheapRouter.route(conn);
106
var pointList = new Array();
107
var fromPt = conn.getStartPoint();
108
var toPt = conn.getEndPoint();
110
// create the Manhattan line stroke
112
this._route(pointList, conn, toPt, this.getEndDirection(conn), fromPt, this.getStartDirection(conn));
113
var resultList = new Array();
114
// create the Bezier spline from the ManhattanLineStroke
116
this.drawBezier(pointList,resultList, 0.5, this.iteration);
117
for(var i=0;i<resultList.length;i++)
119
conn.addPoint(resultList[i]);
127
draw2d.BezierConnectionRouter.prototype._route=function(pointList, /*:draw2d.Connection*/ conn,/*:draw2d.Point*/ fromPt, /*:int*/fromDir, /*:draw2d.Point*/toPt, /*:int*/toDir)
133
// fromPt is an x,y to start from.
134
// fromDir is an angle that the first link must
141
var xDiff = fromPt.x - toPt.x;
142
var yDiff = fromPt.y - toPt.y;
146
if (((xDiff * xDiff) < (TOLxTOL)) && ((yDiff * yDiff) < (TOLxTOL)))
148
pointList.push(new draw2d.Point(toPt.x, toPt.y));
154
if ((xDiff > 0) && ((yDiff * yDiff) < TOL) && (toDir == RIGHT))
163
point = new draw2d.Point(fromPt.x - MINDIST, fromPt.y);
165
else if (((yDiff > 0) && (toDir == DOWN)) || ((yDiff < 0) && (toDir == UP)))
167
point = new draw2d.Point(toPt.x, fromPt.y);
169
else if (fromDir == toDir)
171
var pos = Math.min(fromPt.x, toPt.x) - MINDIST;
172
point = new draw2d.Point(pos, fromPt.y);
176
point = new draw2d.Point(fromPt.x - (xDiff / 2), fromPt.y);
189
else if (fromDir == RIGHT)
191
if ((xDiff < 0) && ((yDiff * yDiff) < TOL)&& (toDir == LEFT))
200
point = new draw2d.Point(fromPt.x + MINDIST, fromPt.y);
202
else if (((yDiff > 0) && (toDir == DOWN)) || ((yDiff < 0) && (toDir == UP)))
204
point = new draw2d.Point(toPt.x, fromPt.y);
206
else if (fromDir == toDir)
208
var pos = Math.max(fromPt.x, toPt.x) + MINDIST;
209
point = new draw2d.Point(pos, fromPt.y);
213
point = new draw2d.Point(fromPt.x - (xDiff / 2), fromPt.y);
222
else if (fromDir == DOWN)
224
if (((xDiff * xDiff) < TOL) && (yDiff < 0)&& (toDir == UP))
233
point = new draw2d.Point(fromPt.x, fromPt.y + MINDIST);
235
else if (((xDiff > 0) && (toDir == RIGHT)) || ((xDiff < 0) && (toDir == LEFT)))
237
point = new draw2d.Point(fromPt.x, toPt.y);
239
else if (fromDir == toDir)
241
var pos = Math.max(fromPt.y, toPt.y) + MINDIST;
242
point = new draw2d.Point(fromPt.x, pos);
246
point = new draw2d.Point(fromPt.x, fromPt.y - (yDiff / 2));
255
else if (fromDir == UP)
257
if (((xDiff * xDiff) < TOL) && (yDiff > 0) && (toDir == DOWN))
266
point = new draw2d.Point(fromPt.x, fromPt.y - MINDIST);
268
else if (((xDiff > 0) && (toDir == RIGHT)) || ((xDiff < 0) && (toDir == LEFT)))
270
point = new draw2d.Point(fromPt.x, toPt.y);
272
else if (fromDir == toDir)
274
var pos = Math.min(fromPt.y, toPt.y) - MINDIST;
275
point = new draw2d.Point(fromPt.x, pos);
279
point = new draw2d.Point(fromPt.x, fromPt.y - (yDiff / 2));
288
this._route(pointList, conn,point, dir, toPt, toDir);
289
pointList.push(fromPt);