View Javadoc
1   package org.opentrafficsim.road.network.lane.object.sensor;
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.compatibility.Compatible;
9   import org.opentrafficsim.core.gtu.RelativePosition;
10  import org.opentrafficsim.core.network.NetworkException;
11  import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
12  import org.opentrafficsim.road.network.animation.SinkAnimation;
13  import org.opentrafficsim.road.network.lane.CrossSectionElement;
14  import org.opentrafficsim.road.network.lane.Lane;
15  
16  import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
17  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
18  import nl.tudelft.simulation.language.Throw;
19  
20  /**
21   * A SinkSensor is a sensor that deletes every GTU that hits it.
22   * <p>
23   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.<br>
24   * All rights reserved. <br>
25   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
26   * <p>
27   * $LastChangedDate: 2015-08-12 16:37:45 +0200 (Wed, 12 Aug 2015) $, @version $Revision: 1240 $, by $Author: averbraeck $,
28   * initial version an 30, 2015 <br>
29   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
30   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
31   */
32  public class SinkSensor extends AbstractSensor
33  {
34      /** */
35      private static final long serialVersionUID = 20150130L;
36  
37      /**
38       * @param lane the lane that triggers the deletion of the GTU.
39       * @param position the position of the sensor
40       * @param simulator the simulator to enable animation.
41       * @throws NetworkException when the position on the lane is out of bounds w.r.t. the center line of the lane
42       */
43      public SinkSensor(final Lane lane, final Length position, final DEVSSimulatorInterface.TimeDoubleUnit simulator) throws NetworkException
44      {
45          super("SINK@" + lane.toString(), lane, position, RelativePosition.FRONT, simulator, Compatible.EVERYTHING);
46          try
47          {
48              new SinkAnimation(this, simulator);
49          }
50          catch (RemoteException | NamingException exception)
51          {
52              exception.printStackTrace();
53          }
54      }
55  
56      /**
57       * @param dummy1 dummy
58       * @param lane the lane that triggers the deletion of the GTU.
59       * @param position the position of the sensor
60       * @param dummy2 dummy
61       * @param simulator the simulator to enable animation.
62       * @throws NetworkException when the position on the lane is out of bounds w.r.t. the center line of the lane
63       */
64      public SinkSensor(final String dummy1, final Lane lane, final Length position, final RelativePosition.TYPE dummy2,
65              final DEVSSimulatorInterface.TimeDoubleUnit simulator) throws NetworkException
66      {
67          super("SINK@" + lane.toString(), lane, position, RelativePosition.FRONT, simulator, Compatible.EVERYTHING);
68          try
69          {
70              new SinkAnimation(this, simulator);
71          }
72          catch (RemoteException | NamingException exception)
73          {
74              exception.printStackTrace();
75          }
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      public final void triggerResponse(final LaneBasedGTU gtu)
81      {
82          gtu.destroy();
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      public final String toString()
88      {
89          return "SinkSensor [Lane=" + this.getLane() + "]";
90      }
91  
92      /** {@inheritDoc} */
93      @Override
94      @SuppressWarnings("checkstyle:designforextension")
95      public SinkSensor clone(final CrossSectionElement newCSE, final SimulatorInterface.TimeDoubleUnit newSimulator, final boolean animation)
96              throws NetworkException
97      {
98          Throw.when(!(newCSE instanceof Lane), NetworkException.class, "sensors can only be cloned for Lanes");
99          Throw.when(!(newSimulator instanceof DEVSSimulatorInterface.TimeDoubleUnit), NetworkException.class,
100                 "simulator should be a DEVSSimulator");
101         return new SinkSensor((Lane) newCSE, getLongitudinalPosition(), (DEVSSimulatorInterface.TimeDoubleUnit) newSimulator);
102     }
103 
104 }