1
2
3
4
5
6
7
8
9
10
11 package nl.tudelft.simulation.traffic.track;
12
13 import javax.media.j3d.BoundingSphere;
14 import javax.media.j3d.Bounds;
15 import javax.vecmath.Point3d;
16 import nl.tudelft.simulation.language.d3.DirectedPoint;
17 import nl.tudelft.simulation.logger.Logger;
18 import nl.tudelft.simulation.traffic.track.util.TrackList;
19
20 /***
21 * This is a complex track link, with several possible predecessors and several
22 * possible successors. <br>
23 * <br>
24 * (c) copyright 2003-2004 <a href="http://www.simulation.tudelft.nl">Delft
25 * University of Technology </a>, the Netherlands. <br>
26 * See for project information <a href="http://www.simulation.tudelft.nl">
27 * www.simulation.tudelft.nl </a> <br>
28 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
29 * License (GPL) </a>, no warranty <br>
30 *
31 * @version Jun 19, 2004 <br>
32 * @author <a
33 * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
34 * Verbraeck </a>
35 */
36 public class ComplexTrackLink extends DirectedPoint
37 implements
38 TrackLinkInterface
39 {
40 /*** the link name */
41 private String name;
42
43 /*** the predecessor tracks */
44 private TrackList predecessors = new TrackList();
45
46 /*** the successor tracks */
47 private TrackList successors = new TrackList();
48
49 /*** the active predecessor for complex link */
50 private TrackInterface activePredecessor;
51
52 /*** the active successor for complex link */
53 private TrackInterface activeSuccessor;
54
55 /***
56 * Construct a new ComplexTrackLink
57 *
58 * @param name
59 * @param location
60 *
61 */
62 public ComplexTrackLink(final String name, final DirectedPoint location)
63 {
64 super(location);
65 this.name = name;
66 }
67
68 /***
69 * Construct a new ComplexTrackLink
70 *
71 * @param name
72 * @param point
73 *
74 */
75 public ComplexTrackLink(final String name, final Point3d point)
76 {
77 super(point);
78 this.name = name;
79 }
80
81 /***
82 * Construct a new ComplexTrackLink
83 *
84 * @param name
85 * @param x
86 * @param y
87 * @param z
88 *
89 */
90 public ComplexTrackLink(final String name, final double x, final double y,
91 final double z)
92 {
93 super(x, y, z);
94 this.name = name;
95 }
96
97 /***
98 * @see nl.tudelft.simulation.traffic.track.TrackLinkInterface#addSuccessor(TrackInterface)
99 */
100 public void addSuccessor(final TrackInterface successor)
101 {
102 this.successors.add(successor);
103 }
104
105 /***
106 * @see nl.tudelft.simulation.traffic.track.TrackLinkInterface#addPredecessor(TrackInterface)
107 */
108 public void addPredecessor(final TrackInterface predecessor)
109 {
110 this.predecessors.add(predecessor);
111 }
112
113 /***
114 * @see nl.tudelft.simulation.traffic.track.TrackLinkInterface#setActiveSuccessor(TrackInterface,
115 * TrackInterface)
116 */
117 public void setActiveSuccessor(final TrackInterface prevTrack,
118 final TrackInterface nextTrack)
119 {
120 if (!this.predecessors.contains(prevTrack))
121 Logger.warning(this, "setActiveSuccessor", "Predecessor "
122 + prevTrack + " for " + this.name
123 + " not in list of predecessor");
124 if (!this.successors.contains(nextTrack))
125 Logger.warning(this, "setActiveSuccessor", "Active successor "
126 + nextTrack + " for " + this.name
127 + " not in list of successors");
128 this.activeSuccessor = nextTrack;
129 setActivePredecessor(nextTrack, prevTrack);
130 System.out.println("Sucessor changed successfully to: "
131 + nextTrack.toString());
132 }
133
134 /***
135 * @param successor
136 * @param predecessor
137 */
138 protected void setActivePredecessor(final TrackInterface successor,
139 final TrackInterface predecessor)
140 {
141 if (!this.predecessors.contains(predecessor))
142 Logger.warning(this, "setActivePredecessor", "Predecessor "
143 + predecessor + " for " + successor
144 + " not in list of predecessor");
145 if (!this.successors.contains(successor))
146 Logger.warning(this, "setActivePredecessor", "Active Successor "
147 + successor + " for " + predecessor
148 + " not in list of successors");
149 this.activePredecessor = successor;
150 System.out.println("Predecessor changed successfully to: "
151 + predecessor.toString());
152 }
153
154 /***
155 * @see nl.tudelft.simulation.traffic.track.TrackLinkInterface#getActiveSuccessor(TrackInterface)
156 */
157 public TrackInterface getActiveSuccessor(final TrackInterface predecessor)
158 {
159 if (!this.predecessors.contains(predecessor))
160 Logger.warning(this, "getActiveSuccessor", "Predecessor "
161 + predecessor + " for " + this.name
162 + " not in list of predecessor");
163 return this.activeSuccessor;
164 }
165
166 /***
167 * @param successor
168 * @return
169 */
170 public TrackInterface getActivePredecessor(final TrackInterface successor)
171 {
172 if (!this.successors.contains(successor))
173 Logger.warning(this, "getActivePredecessor", "Successor "
174 + successor + " for " + this.name
175 + " not in list of predecessor");
176 return this.activePredecessor;
177 }
178
179 /***
180 * @see nl.tudelft.simulation.traffic.track.TrackLinkInterface#getSuccessors()
181 */
182 public TrackList getSuccessors()
183 {
184 return this.successors;
185 }
186
187 /***
188 * @see nl.tudelft.simulation.traffic.track.TrackLinkInterface#getPredecessors()
189 */
190 public TrackList getPredecessors()
191 {
192 return this.predecessors;
193 }
194
195 /***
196 * @see nl.tudelft.simulation.traffic.track.TrackLinkInterface#getPosition()
197 */
198 public Point3d getPosition()
199 {
200 return this;
201 }
202
203 /***
204 * @see nl.tudelft.simulation.dsol.animation.LocatableInterface#getBounds()
205 */
206 public Bounds getBounds()
207 {
208 return new BoundingSphere(this, 1.0);
209 }
210
211 /***
212 * @see nl.tudelft.simulation.dsol.animation.LocatableInterface#getLocation()
213 */
214 public DirectedPoint getLocation()
215 {
216 return this;
217 }
218
219 /***
220 * @see java.lang.Object#toString()
221 */
222 public String toString()
223 {
224 return this.name;
225 }
226 }