|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2003, 2005 IBM Corporation and others. |
2 |
* Copyright (c) 2003, 2008 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 10-16
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.draw2d.graph; |
11 |
package org.eclipse.draw2d.graph; |
| 12 |
|
12 |
|
| 13 |
import org.eclipse.draw2d.geometry.Insets; |
|
|
| 14 |
import org.eclipse.draw2d.geometry.Point; |
13 |
import org.eclipse.draw2d.geometry.Point; |
| 15 |
import org.eclipse.draw2d.geometry.PointList; |
14 |
import org.eclipse.draw2d.geometry.PointList; |
| 16 |
import org.eclipse.draw2d.geometry.Rectangle; |
15 |
import org.eclipse.draw2d.geometry.Rectangle; |
|
Lines 19-24
Link Here
|
| 19 |
* @author Randy Hudson |
18 |
* @author Randy Hudson |
| 20 |
*/ |
19 |
*/ |
| 21 |
class RouteEdges extends GraphVisitor { |
20 |
class RouteEdges extends GraphVisitor { |
|
|
21 |
|
| 22 |
private static int OBSTACLE_WIDTH = 10000; |
| 22 |
|
23 |
|
| 23 |
/** |
24 |
/** |
| 24 |
* @see GraphVisitor#visit(DirectedGraph) |
25 |
* @see GraphVisitor#visit(DirectedGraph) |
|
Lines 38-82
Link Here
|
| 38 |
edge.getTargetOffset() + edge.target.x, |
39 |
edge.getTargetOffset() + edge.target.x, |
| 39 |
edge.target.y); |
40 |
edge.target.y); |
| 40 |
|
41 |
|
| 41 |
if (edge.vNodes != null) |
42 |
if (edge.getRoutingStyle() == Edge.ORTHOGONAL_ROUTING_STYLE) { |
| 42 |
routeLongEdge(edge, g); |
43 |
routeOrthogonalEdge(edge, g); |
| 43 |
else { |
44 |
} else { |
| 44 |
PointList list = new PointList(); |
45 |
routeEdge(edge, g); |
| 45 |
list.addPoint(edge.start); |
|
|
| 46 |
list.addPoint(edge.end); |
| 47 |
edge.setPoints(list); |
| 48 |
} |
46 |
} |
| 49 |
} |
47 |
} |
| 50 |
} |
48 |
} |
| 51 |
|
49 |
|
| 52 |
static void routeLongEdge(Edge edge, DirectedGraph g) { |
50 |
void routeEdge(Edge edge, DirectedGraph g) { |
| 53 |
ShortestPathRouter router = new ShortestPathRouter(); |
51 |
ShortestPathRouter router = new ShortestPathRouter(); |
| 54 |
Path path = new Path(edge.start, edge.end); |
52 |
Path path = new Path(edge.start, edge.end); |
| 55 |
router.addPath(path); |
53 |
router.addPath(path); |
| 56 |
Rectangle o; |
54 |
if (edge.vNodes != null) { |
| 57 |
Insets padding; |
55 |
for (int i = 0; i < edge.vNodes.size(); i++) { |
| 58 |
for (int i = 0; i < edge.vNodes.size(); i++) { |
56 |
Node node = edge.vNodes.getNode(i); |
| 59 |
VirtualNode node = (VirtualNode)edge.vNodes.get(i); |
57 |
Rank r = g.ranks.getRank(node.rank); |
| 60 |
Node neighbor; |
58 |
if (node.left != null) { |
| 61 |
if (node.left != null) { |
59 |
int right = node.left.x + node.left.width + g.getPadding(node.left).right + edge.getPadding(); |
| 62 |
neighbor = node.left; |
60 |
int width = Math.max(right, OBSTACLE_WIDTH); |
| 63 |
o = new Rectangle(neighbor.x, neighbor.y, neighbor.width, neighbor.height); |
61 |
int height = Math.max(r.height, 2); |
| 64 |
padding = g.getPadding(neighbor); |
62 |
router.addObstacle(new Rectangle(right - width, node.left.y, width, height)); |
| 65 |
o.width += padding.right + padding.left; |
63 |
} |
| 66 |
o.width += (edge.getPadding() * 2); |
64 |
if (node.right != null) { |
| 67 |
o.x -= (padding.left + edge.getPadding()); |
65 |
int left = node.right.x - g.getPadding(node.right).left - edge.getPadding(); |
| 68 |
o.union(o.getLocation().translate(-100000, 2)); |
66 |
int width = Math.max(g.size.width - left, OBSTACLE_WIDTH); |
| 69 |
router.addObstacle(o); |
67 |
int height = Math.max(r.height, 2); |
| 70 |
} |
68 |
router.addObstacle(new Rectangle(left, node.right.y, width, height)); |
| 71 |
if (node.right != null) { |
69 |
} |
| 72 |
neighbor = node.right; |
|
|
| 73 |
o = new Rectangle(neighbor.x, neighbor.y, neighbor.width, neighbor.height); |
| 74 |
padding = g.getPadding(neighbor); |
| 75 |
o.width += padding.right + padding.left; |
| 76 |
o.width += (edge.getPadding() * 2); |
| 77 |
o.x -= (padding.left + edge.getPadding()); |
| 78 |
o.union(o.getLocation().translate(100000, 2)); |
| 79 |
router.addObstacle(o); |
| 80 |
} |
70 |
} |
| 81 |
} |
71 |
} |
| 82 |
router.setSpacing(0); |
72 |
router.setSpacing(0); |
|
Lines 84-87
Link Here
|
| 84 |
edge.setPoints(path.getPoints()); |
74 |
edge.setPoints(path.getPoints()); |
| 85 |
} |
75 |
} |
| 86 |
|
76 |
|
|
|
77 |
void routeOrthogonalEdge(Edge edge, DirectedGraph g) { |
| 78 |
PointList points = new PointList(); |
| 79 |
points.addPoint(edge.start); |
| 80 |
Node previousNode = edge.source instanceof Subgraph ? ((Subgraph)edge.source).tail : edge.source; |
| 81 |
if (edge.vNodes != null) { |
| 82 |
for (int i = 0; i < edge.vNodes.size(); i++) { |
| 83 |
Node vNode = edge.vNodes.getNode(i); |
| 84 |
int nextPtX = vNode.x + vNode.width / 2; |
| 85 |
int prevPtX = points.getLastPoint().x; |
| 86 |
if (prevPtX != nextPtX) { |
| 87 |
Rank previousRank = g.ranks.getRank(previousNode.rank); |
| 88 |
int rankBottomY = previousRank.location + previousRank.height; |
| 89 |
int midY = rankBottomY + (vNode.y - rankBottomY) / 2; |
| 90 |
points.addPoint(prevPtX, midY); |
| 91 |
points.addPoint(nextPtX, midY); |
| 92 |
} |
| 93 |
previousNode = vNode; |
| 94 |
} |
| 95 |
} |
| 96 |
Point prevPt = points.getLastPoint(); |
| 97 |
Point lastPt = edge.end; |
| 98 |
if (prevPt.x != lastPt.x) { |
| 99 |
Rank previousRank = g.ranks.getRank(previousNode.rank); |
| 100 |
int rankBottomY = previousRank.location + previousRank.height; |
| 101 |
int midY = rankBottomY + (lastPt.y - rankBottomY) / 2; |
| 102 |
points.addPoint(prevPt.x, midY); |
| 103 |
points.addPoint(lastPt.x, midY); |
| 104 |
} |
| 105 |
points.addPoint(edge.end); |
| 106 |
edge.setPoints(points); |
| 107 |
} |
| 108 |
|
| 87 |
} |
109 |
} |