1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2004, 2010 IBM Corporation and others.
|
3
|
* All rights reserved. This program and the accompanying materials
|
4
|
* are made available under the terms of the Eclipse Public License v1.0
|
5
|
* which accompanies this distribution, and is available at
|
6
|
* http://www.eclipse.org/legal/epl-v10.html
|
7
|
*
|
8
|
* Contributors:
|
9
|
* IBM Corporation - initial API and implementation
|
10
|
*******************************************************************************/
|
11
|
package org.eclipse.draw2d.graph;
|
12
|
|
13
|
import org.eclipse.draw2d.PositionConstants;
|
14
|
import org.eclipse.draw2d.geometry.Point;
|
15
|
import org.eclipse.draw2d.geometry.Rectangle;
|
16
|
|
17
|
/**
|
18
|
* An obstacle representation for the ShortestPathRouting. This is a subclass of
|
19
|
* Rectangle.
|
20
|
*
|
21
|
* This class is for internal use only.
|
22
|
*
|
23
|
* @author Whitney Sorenson
|
24
|
* @since 3.0
|
25
|
*/
|
26
|
class Obstacle extends Rectangle {
|
27
|
|
28
|
boolean exclude;
|
29
|
Vertex topLeft, topRight, bottomLeft, bottomRight, center;
|
30
|
private ShortestPathRouter router;
|
31
|
|
32
|
/**
|
33
|
* Creates a new obstacle from the given rectangle bounds.
|
34
|
*
|
35
|
* @param rect
|
36
|
* the bounds
|
37
|
*/
|
38
|
Obstacle(Rectangle rect, ShortestPathRouter router) {
|
39
|
init(rect);
|
40
|
this.router = router;
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* Returns <code>true</code> if the given point is contained but not on the
|
45
|
* boundary of this obstacle.
|
46
|
*
|
47
|
* @param p
|
48
|
* a point
|
49
|
* @return <code>true</code> if properly contained
|
50
|
*/
|
51
|
public boolean containsProper(Point p) {
|
52
|
return p.x > this.x && p.x < this.x + this.width - 1 && p.y > this.y
|
53
|
&& p.y < this.y + this.height - 1;
|
54
|
}
|
55
|
|
56
|
public int getSpacing() {
|
57
|
return router.getSpacing();
|
58
|
}
|
59
|
|
60
|
private void growVertex(Vertex vertex) {
|
61
|
if (vertex.totalCount > 0)
|
62
|
vertex.grow();
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* Grows all vertices on this obstacle.
|
67
|
*/
|
68
|
void growVertices() {
|
69
|
growVertex(topLeft);
|
70
|
growVertex(topRight);
|
71
|
growVertex(bottomLeft);
|
72
|
growVertex(bottomRight);
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* Initializes this obstacle to the values of the given rectangle
|
77
|
*
|
78
|
* @param rect
|
79
|
* bounds of this obstacle
|
80
|
*/
|
81
|
void init(Rectangle rect) {
|
82
|
this.x = rect.x;
|
83
|
this.y = rect.y;
|
84
|
this.width = rect.width;
|
85
|
this.height = rect.height;
|
86
|
|
87
|
exclude = false;
|
88
|
|
89
|
topLeft = new Vertex(x, y, this);
|
90
|
topLeft.positionOnObstacle = PositionConstants.NORTH_WEST;
|
91
|
topRight = new Vertex(x + width - 1, y, this);
|
92
|
topRight.positionOnObstacle = PositionConstants.NORTH_EAST;
|
93
|
bottomLeft = new Vertex(x, y + height - 1, this);
|
94
|
bottomLeft.positionOnObstacle = PositionConstants.SOUTH_WEST;
|
95
|
bottomRight = new Vertex(x + width - 1, y + height - 1, this);
|
96
|
bottomRight.positionOnObstacle = PositionConstants.SOUTH_EAST;
|
97
|
center = new Vertex(getCenter(), this);
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* Requests a full reset on all four vertices of this obstacle.
|
102
|
*/
|
103
|
void reset() {
|
104
|
topLeft.fullReset();
|
105
|
bottomLeft.fullReset();
|
106
|
bottomRight.fullReset();
|
107
|
topRight.fullReset();
|
108
|
}
|
109
|
|
110
|
private void shrinkVertex(Vertex vertex) {
|
111
|
if (vertex.totalCount > 0)
|
112
|
vertex.shrink();
|
113
|
}
|
114
|
|
115
|
/**
|
116
|
* Shrinks all four vertices of this obstacle.
|
117
|
*/
|
118
|
void shrinkVertices() {
|
119
|
shrinkVertex(topLeft);
|
120
|
shrinkVertex(topRight);
|
121
|
shrinkVertex(bottomLeft);
|
122
|
shrinkVertex(bottomRight);
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* @see org.eclipse.draw2d.geometry.Rectangle#toString()
|
127
|
*/
|
128
|
public String toString() {
|
129
|
return "Obstacle(" + x + ", " + y + ", " + //$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
|
130
|
width + ", " + height + ")";//$NON-NLS-2$//$NON-NLS-1$
|
131
|
}
|
132
|
|
133
|
}
|