1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package nl.tudelft.simulation.traffic.station;
17
18 import java.rmi.RemoteException;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import javax.media.j3d.Bounds;
23 import javax.vecmath.Point3d;
24
25 import nl.tudelft.simulation.dsol.animation.LocatableInterface;
26 import nl.tudelft.simulation.dsol.simulators.AnimatorInterface;
27 import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
28 import nl.tudelft.simulation.language.d3.BoundingBox;
29 import nl.tudelft.simulation.language.d3.DirectedPoint;
30 import nl.tudelft.simulation.traffic.animation.StationAnimation;
31 import nl.tudelft.simulation.traffic.track.TrackInterface;
32 import nl.tudelft.simulation.traffic.track.util.TrackProgression;
33
34 /***
35 * <br>
36 * This class is the implementation of a station. A station is considered as
37 * just one side of the track. Therefore, it might be that two stations have the
38 * same name, but they will have different code/codecompany
39 *
40 * (c) copyright * 2003-2004 <a href="http://www.simulation.tudelft.nl">Delft
41 * University of Technology </a>, the Netherlands. <br>
42 * See for project information <a href="http://www.simulation.tudelft.nl">
43 * www.simulation.tudelft.nl </a> <br>
44 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
45 * License (GPL) </a>, no warranty <br>
46 *
47 * @version Aug 20, 2004 <br>
48 * @author <a
49 * href="http://www.tbm.tudelft.nl/webstaf/elisangelak/index.htm">Elisangela
50 * Kanacilo </a>
51 */
52 public class Station implements LocatableInterface
53 {
54 /*** name of the station */
55 private String name;
56
57 /*** string or number that identifies the stationTrack */
58 private String stationCode;
59
60 /*** number that identifies the stationTrack */
61 private String stationCompanyCode;
62
63 /*** starting track of the stationTrack */
64 private TrackInterface startTrack;
65
66 /*** starting point of the station track = progression related to startTrack */
67 private double progression;
68
69 /*** stationLength of the station */
70 private double stationLength;
71
72 /*** distance to request access to the station */
73 private double requestDistance;
74
75 /*** List of stopping places */
76 private List stoppingPlacesList = new ArrayList();
77
78 /*** Side of the station */
79 public static final String PLATFORM_LEFT = "LEFT";
80
81 /*** Side of the station */
82 public static final String PLATFORM_RIGHT = "RIGHT";
83
84 /*** side where the station will be placed */
85 public String platformSide;
86
87 /*** the standard halting time */
88 private double haltingTime;
89
90 /*** the location */
91 private DirectedPoint location = new DirectedPoint();
92
93 /***
94 * @param name of the station
95 * @param startTrack the first track of the station (first position where
96 * the vehicles will stop)
97 * @param stationCode string or number that identifies the stationTrack
98 * @param stationCompanyCode number that identifies the stationTrack
99 * @param platformSide side where the station will be placed
100 * @param stationProgression position related to the startTrack where the
101 * station starts
102 * @param requestDistance
103 * @param stationLength stationLength of the stationTrack
104 * @param stoppingPlaceLength stationLength of each stoppingPlace
105 * @param haltingTime
106 * @param simulator
107 */
108 public Station(final String name, final String stationCode,
109 final String stationCompanyCode, final TrackInterface startTrack,
110 final double stationProgression, final double requestDistance,
111 final double stationLength, final double stoppingPlaceLength,
112 final double haltingTime, final String platformSide,
113 final DEVSSimulatorInterface simulator)
114 {
115 this.name = name;
116 this.stationCode = stationCode;
117 this.stationCompanyCode = stationCompanyCode;
118
119
120 TrackProgression tp = startTrack
121 .calculateTrackProgressionListActive(stationProgression);
122 if (tp != null)
123 {
124 this.startTrack = tp.getTrack();
125 this.progression = tp.getProgression();
126 } else
127 {
128 System.err.println("NO TRACK / PROGRESSION FOR STATION " + name
129 + ", track: " + startTrack + "." + stationProgression);
130 return;
131 }
132 this.requestDistance = requestDistance;
133 this.stationLength = stationLength;
134 this.haltingTime = haltingTime;
135 this.platformSide = platformSide;
136
137
138 double startLength = 0;
139 while (startLength < stationLength)
140 {
141 StoppingPlace stoppingPlace = new StoppingPlace(this,
142 this.startTrack, this.progression - startLength,
143 this.requestDistance, stoppingPlaceLength, simulator);
144 this.addStoppingPlace(stoppingPlace);
145 startLength += stoppingPlaceLength;
146 }
147
148 Point3d p = this.startTrack.getLocationOfProgression(this.progression);
149 Point3d q = this.startTrack.getLocationOfProgression(this.progression
150 - this.stationLength);
151 double dx = q.x - p.x;
152 double dy = q.y - p.y;
153 double alpha = Math.atan2(dy, dx);
154 double beta;
155 if (this.platformSide.equals(Station.PLATFORM_LEFT))
156 beta = alpha - Math.PI / 2.0d;
157 else
158 beta = alpha + Math.PI / 2.0d;
159 double d = 3.0d;
160 this.location = new DirectedPoint(p.x + d * Math.cos(beta), p.y + d
161 * Math.sin(beta), p.z, 0.0d, 0.0d, alpha);
162 if (simulator instanceof AnimatorInterface)
163 {
164 new StationAnimation(this, simulator);
165 }
166 }
167
168 /***
169 * retrieve the accessible stopping place at the stationTrack
170 *
171 * @param stoppingPlacesList
172 * @return accessible stopping place or null if they are all occupied
173 */
174 public StoppingPlace getAccessibleStoppingPlace(List stoppingPlacesList)
175 {
176 StoppingPlace place;
177 boolean found = false;
178 int i = stoppingPlacesList.size() - 1;
179 while (i >= 0 && !found)
180 {
181 place = (StoppingPlace) stoppingPlacesList.get(i);
182 if (place.isClaimed())
183 {
184 found = true;
185 break;
186 }
187 i--;
188 }
189 if (i == stoppingPlacesList.size() - 1 && found == true)
190 return null;
191 else
192 return (StoppingPlace) stoppingPlacesList.get(i++);
193 }
194
195 /***
196 * @param stoppingPlace
197 */
198 private void addStoppingPlace(StoppingPlace stoppingPlace)
199 {
200 this.stoppingPlacesList.add(stoppingPlace);
201 }
202
203 /***
204 * @return Returns the station.
205 */
206 public String getName()
207 {
208 return this.name;
209 }
210
211 /***
212 * @return Returns the stationLength.
213 */
214 public double getStationLength()
215 {
216 return this.stationLength;
217 }
218
219 /***
220 * @return Returns the progression.
221 */
222 public double getProgression()
223 {
224 return this.progression;
225 }
226
227 /***
228 * @return Returns the startTrack.
229 */
230 public TrackInterface getStartTrack()
231 {
232 return this.startTrack;
233 }
234
235 /***
236 * @return Returns the stoppingPlacesList.
237 */
238 public List getStoppingPlacesList()
239 {
240 return this.stoppingPlacesList;
241 }
242
243 /***
244 * @return Returns the stationCode.
245 */
246 public String getStationCode()
247 {
248 return this.stationCode;
249 }
250
251 /***
252 * @return Returns the stationCompanyCode.
253 */
254 public String getStationCompanyCode()
255 {
256 return this.stationCompanyCode;
257 }
258
259 /***
260 * @return Returns the platformSide.
261 */
262 public String getPlatformSide()
263 {
264 return this.platformSide;
265 }
266
267 /***
268 * @return Returns the haltingTime.
269 */
270 public double getHaltingTime()
271 {
272 return this.haltingTime;
273 }
274
275 /***
276 * @see nl.tudelft.simulation.dsol.animation.LocatableInterface#getLocation()
277 */
278 public DirectedPoint getLocation() throws RemoteException
279 {
280 return this.location;
281 }
282
283 /***
284 * @see nl.tudelft.simulation.dsol.animation.LocatableInterface#getBounds()
285 */
286 public Bounds getBounds() throws RemoteException
287 {
288 Point3d p = this.location;
289 Point3d q = this.startTrack.getLocationOfProgression(this.progression
290 + this.stationLength);
291 return new BoundingBox(new Point3d(0, 0, 0), new Point3d(q.x - p.x, q.y
292 - p.y, 0));
293 }
294
295 }