View Javadoc
1   package org.opentrafficsim.road.gtu.lane.object;
2   
3   import java.rmi.RemoteException;
4   import java.util.UUID;
5   
6   import javax.naming.NamingException;
7   
8   import nl.tudelft.simulation.dsol.SimRuntimeException;
9   import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
10  
11  import org.djunits.value.vdouble.scalar.Length;
12  import org.opentrafficsim.core.dsol.OTSAnimatorInterface;
13  import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
14  import org.opentrafficsim.core.geometry.OTSGeometryException;
15  import org.opentrafficsim.core.gtu.GTUException;
16  import org.opentrafficsim.core.network.NetworkException;
17  import org.opentrafficsim.core.network.OTSNetwork;
18  import org.opentrafficsim.road.gtu.lane.object.animation.DefaultBlockAnimation;
19  import org.opentrafficsim.road.network.lane.Lane;
20  
21  /**
22   * <p>
23   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
24   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
25   * </p>
26   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
27   * initial version Jan 6, 2016 <br>
28   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
30   */
31  public class LaneBlock extends AbstractTrafficLight
32  {
33      /** */
34      private static final long serialVersionUID = 1L;
35  
36      /**
37       * @param lane The lane where the block has to be put
38       * @param position the position on the lane as a length
39       * @param simulator the simulator to avoid NullPointerExceptions
40       * @param animationClass Class&lt;? extends Renderable2D&gt;; the class for animation or null if no animation
41       * @param network the network that the GTU is initially registered in
42       * @throws GTUException when GTU cannot be created.
43       * @throws NamingException if an error occurs when adding the animation handler
44       * @throws NetworkException when the GTU cannot be placed on the given lane
45       * @throws OTSGeometryException x
46       * @throws SimRuntimeException x
47       */
48      public LaneBlock(final Lane lane, final Length.Rel position, final OTSDEVSSimulatorInterface simulator,
49          final Class<? extends Renderable2D> animationClass, final OTSNetwork network)
50          throws GTUException, NetworkException, NamingException, SimRuntimeException, OTSGeometryException
51      {
52          super(UUID.randomUUID().toString(), lane, position, simulator, network);
53          try
54          {
55              new DefaultBlockAnimation(this, getSimulator());
56              if (simulator instanceof OTSAnimatorInterface && animationClass != null)
57              {
58                  // TODO use animationClass
59              }
60          }
61          catch (RemoteException exception)
62          {
63              throw new NetworkException(exception);
64          }
65      }
66  
67      /** {@inheritDoc} */
68      @Override
69      public String toString()
70      {
71          return "LaneBlock [lane=" + this.laneTL + ", position=" + this.positionTL + "]";
72      }
73  
74  }