View Javadoc
1   package org.opentrafficsim.road.network.lane.object.trafficlight;
2   
3   import java.rmi.RemoteException;
4   
5   import javax.naming.NamingException;
6   
7   import org.djunits.value.vdouble.scalar.Length;
8   import org.opentrafficsim.core.network.NetworkException;
9   import org.opentrafficsim.road.network.animation.TrafficLightAnimation;
10  import org.opentrafficsim.road.network.lane.CrossSectionElement;
11  import org.opentrafficsim.road.network.lane.Lane;
12  
13  import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
14  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
15  import nl.tudelft.simulation.language.Throw;
16  
17  /**
18   * Standard implementation of a traffic light.
19   * <p>
20   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
21   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
22   * </p>
23   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
24   * initial version Nov 30, 2015 <br>
25   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
26   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
27   */
28  public class SimpleTrafficLight extends AbstractTrafficLight
29  {
30      /** */
31      private static final long serialVersionUID = 201601001L;
32  
33      /**
34       * @param id traffic light id
35       * @param lane lane where the traffic light is located
36       * @param longitudinalPosition position of the traffic light on the lane, in the design direction
37       * @param simulator the simulator for animation and timed events
38       * @throws NetworkException on failure to place the object
39       */
40      public SimpleTrafficLight(final String id, final Lane lane, final Length longitudinalPosition,
41              final DEVSSimulatorInterface.TimeDoubleUnit simulator) throws NetworkException
42      {
43          super(id, lane, longitudinalPosition, simulator);
44  
45          try
46          {
47              new TrafficLightAnimation(this, simulator);
48          }
49          catch (RemoteException | NamingException exception)
50          {
51              throw new NetworkException(exception);
52          }
53      }
54  
55      /** {@inheritDoc} */
56      @Override
57      @SuppressWarnings("checkstyle:designforextension")
58      public String toString()
59      {
60          return "SimpleTrafficLight [trafficLightColor=" + getTrafficLightColor() + "]";
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      @SuppressWarnings("checkstyle:designforextension")
66      public SimpleTrafficLight clone(final CrossSectionElement newCSE, final SimulatorInterface.TimeDoubleUnit newSimulator,
67              final boolean animation) throws NetworkException
68      {
69          Throw.when(!(newCSE instanceof Lane), NetworkException.class, "traffic lights can only be cloned for Lanes");
70          Throw.when(!(newSimulator instanceof DEVSSimulatorInterface.TimeDoubleUnit), NetworkException.class,
71                  "simulator should be a DEVSSimulator");
72          return new SimpleTrafficLight(getId(), (Lane) newCSE, getLongitudinalPosition(),
73                  (DEVSSimulatorInterface.TimeDoubleUnit) newSimulator);
74  
75          // the traffic light creates its own animation (for now)
76      }
77  
78  }