View Javadoc

1   /*
2    * Created on 29-dec-2003
3    * 
4    * Copyright (c) 2003, 2004 Delft University of Technology Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  
11  package nl.tudelft.simulation.traffic.controlpoint.real;
12  
13  import java.awt.Color;
14  import java.rmi.RemoteException;
15  import javax.media.j3d.BoundingBox;
16  import javax.media.j3d.Bounds;
17  import javax.vecmath.Point3d;
18  import nl.tudelft.simulation.dsol.animation.LocatableInterface;
19  import nl.tudelft.simulation.dsol.simulators.AnimatorInterface;
20  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
21  import nl.tudelft.simulation.language.d3.DirectedPoint;
22  import nl.tudelft.simulation.traffic.animation.SpeedSignAnimation;
23  import nl.tudelft.simulation.traffic.track.TrackInterface;
24  import nl.tudelft.simulation.traffic.vehicle.VehiclePhysicalInterface;
25  
26  /***
27   * This class represents a simple sign. Basically it only implements the
28   * SpeedLimitInterface and extends the AbstractVisibleControlPoint. <br>
29   * <br>
30   * 
31   * @author J.H. Kwakkel & H.W.G. Phaff
32   * 
33   * @see nl.tudelft.simulation.traffic.controlpoint.real.SpeedLimitInterface
34   * @see nl.tudelft.simulation.traffic.controlpoint.real.AbstractVisibleControlPoint
35   */
36  public class SpeedSign extends AbstractVisibleControlPoint
37          implements
38              SpeedLimitInterface,
39              LocatableInterface
40  {
41      /*** the speed limit */
42      private double speedLimit;
43  
44      /*** the name */
45      private String name;
46  
47      /*** dx for animation (bounds) */
48      private double dx;
49  
50      /*** dy for animation (bounds) */
51      private double dy;
52  
53      /*** the text to display */
54      private String text;
55  
56      /***
57       * @param name
58       * @param track
59       * @param progression
60       * @param visibleDistance
61       * @param speedLimit
62       * @param simulator
63       * @param dx
64       * @param dy
65       * @param text
66       * @param backgroundColor
67       * @param textColor
68       * @param lineColor
69       */
70      public SpeedSign(final String name, final TrackInterface track,
71              final double progression, final double visibleDistance,
72              final double speedLimit, final SimulatorInterface simulator,
73              final double dx, final double dy, final String text,
74              final Color backgroundColor, final Color textColor,
75              final Color lineColor)
76      {
77          super(track, progression, visibleDistance, simulator);
78          this.name = name;
79          System.out.println(this + ", placed on " + track + " progression "
80                  + progression + " (length=" + track.getLength() + ")");
81          this.speedLimit = speedLimit;
82          this.dx = dx;
83          this.dy = dy;
84          this.text = text;
85          if (simulator instanceof AnimatorInterface)
86          {
87              new SpeedSignAnimation(this, simulator, dx, dy, backgroundColor,
88                      textColor, lineColor);
89          }
90      }
91  
92      /***
93       * @see nl.tudelft.simulation.traffic.controlpoint.ControlPointInterface#pass(nl.tudelft.simulation.traffic.vehicle.VehiclePhysicalInterface)
94       */
95      public void pass(VehiclePhysicalInterface vehicle)
96      {
97          vehicle.setMaximumSpeed(this.speedLimit);
98      }
99  
100     /***
101      * @see nl.tudelft.simulation.traffic.controlpoint.ControlPointInterface#getProgression()
102      */
103     public double getProgression()
104     {
105         return super.getProgression();
106     }
107 
108     /***
109      * @see nl.tudelft.simulation.traffic.controlpoint.ControlPointInterface#getTrack()
110      */
111     public TrackInterface getTrack()
112     {
113         return super.getTrack();
114     }
115 
116     /***
117      * @see nl.tudelft.simulation.traffic.controlpoint.real.SpeedLimitInterface#getSpeedLimit()
118      */
119     public double getSpeedLimit()
120     {
121         return this.speedLimit;
122     }
123 
124     /***
125      * @see nl.tudelft.simulation.dsol.animation.LocatableInterface#getLocation()
126      */
127     public DirectedPoint getLocation() throws RemoteException
128     {
129         DirectedPoint p = super.getTrack().getLocationOfProgression(
130                 super.getProgression());
131         return new DirectedPoint(p.x, p.y, p.z);
132     }
133 
134     /***
135      * @see nl.tudelft.simulation.dsol.animation.LocatableInterface#getBounds()
136      */
137     public Bounds getBounds() throws RemoteException
138     {
139         return new BoundingBox(new Point3d(this.dx - 3.0, this.dy, 0),
140                 new Point3d(this.dx + 3.0, this.dy + 6.0, 0));
141     }
142 
143     /***
144      * @return Returns the display text.
145      */
146     public String getText()
147     {
148         return this.text;
149     }
150 
151     /***
152      * @see java.lang.Object#toString()
153      */
154     public String toString()
155     {
156         return "Speedsign " + this.name;
157     }
158 }