View Javadoc
1   package org.opentrafficsim.road.network.lane;
2   
3   import java.awt.Color;
4   import java.rmi.RemoteException;
5   import java.util.List;
6   
7   import javax.naming.NamingException;
8   
9   import org.djunits.value.vdouble.scalar.Length;
10  import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
11  import org.opentrafficsim.core.geometry.OTSGeometryException;
12  import org.opentrafficsim.core.network.NetworkException;
13  import org.opentrafficsim.road.network.animation.ShoulderAnimation;
14  
15  /**
16   * <p>
17   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
18   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
19   * <p>
20   * $LastChangedDate: 2015-09-03 13:38:01 +0200 (Thu, 03 Sep 2015) $, @version $Revision: 1378 $, by $Author: averbraeck $,
21   * initial version Aug 19, 2014 <br>
22   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
23   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
24   * @author <a href="http://www.citg.tudelft.nl">Guus Tamminga</a>
25   */
26  public class Shoulder extends CrossSectionElement
27  {
28      /** */
29      private static final long serialVersionUID = 20140819L;
30  
31      /**
32       * @param parentLink Cross Section Link to which the element belongs.
33       * @param id String; the id of the lane. Should be unique within the parentLink.
34       * @param lateralPositionStart the lateral start position compared to the linear geometry of the Cross Section Link.
35       * @param lateralPositionEnd the lateral end position compared to the linear geometry of the Cross Section Link
36       * @param beginWidth start width, positioned <i>symmetrically around</i> the lateral start position.
37       * @param endWidth end width, positioned <i>symmetrically around</i> the lateral end position.
38       * @throws OTSGeometryException when creation of the center line or contour geometry fails
39       * @throws NetworkException when id equal to null or not unique
40       */
41      public Shoulder(final CrossSectionLink parentLink, final String id, final Length lateralPositionStart,
42              final Length lateralPositionEnd, final Length beginWidth, final Length endWidth)
43              throws OTSGeometryException, NetworkException
44      {
45          super(parentLink, id, lateralPositionStart, lateralPositionEnd, beginWidth, endWidth);
46      }
47  
48      /**
49       * @param parentLink Cross Section Link to which the element belongs.
50       * @param id String; the id of the lane. Should be unique within the parentLink.
51       * @param lateralPosition the lateral start position compared to the linear geometry of the Cross Section Link.
52       * @param width the shoulder width, positioned <i>symmetrically around</i> the lateral start position.
53       * @throws OTSGeometryException when creation of the center line or contour geometry fails
54       * @throws NetworkException when id equal to null or not unique
55       */
56      public Shoulder(final CrossSectionLink parentLink, final String id, final Length lateralPosition, final Length width)
57              throws OTSGeometryException, NetworkException
58      {
59          super(parentLink, id, lateralPosition, width);
60      }
61  
62      /**
63       * @param parentLink Cross Section Link to which the element belongs.
64       * @param id String; the id of the lane. Should be unique within the parentLink.
65       * @param crossSectionSlices The offsets and widths at positions along the line, relative to the design line of the parent
66       *            link. If there is just one with and offset, there should just be one element in the list with Length = 0. If
67       *            there are more slices, the last one should be at the length of the design line. If not, a NetworkException is
68       *            thrown.
69       * @throws OTSGeometryException when creation of the center line or contour geometry fails
70       * @throws NetworkException when id equal to null or not unique
71       */
72      public Shoulder(final CrossSectionLink parentLink, final String id, final List<CrossSectionSlice> crossSectionSlices)
73              throws OTSGeometryException, NetworkException
74      {
75          super(parentLink, id, crossSectionSlices);
76      }
77  
78      /**
79       * Clone a Shoulder for a new network.
80       * @param newParentLink the new link to which the clone belongs
81       * @param newSimulator the new simulator for this network
82       * @param animation whether to (re)create animation or not
83       * @param cse the element to clone from
84       * @throws NetworkException if link already exists in the network, if name of the link is not unique, or if the start node
85       *             or the end node of the link are not registered in the network.
86       */
87      protected Shoulder(final CrossSectionLink newParentLink, final OTSSimulatorInterface newSimulator,
88              final boolean animation, final Shoulder cse) throws NetworkException
89      {
90          super(newParentLink, newSimulator, animation, cse);
91      }
92  
93      /** {@inheritDoc} */
94      @Override
95      protected final double getZ()
96      {
97          return -0.0002;
98      }
99  
100     /** {@inheritDoc} */
101     @Override
102     @SuppressWarnings("checkstyle:designforextension")
103     public String toString()
104     {
105         return String.format("Shoulder offset %.2fm..%.2fm, width %.2fm..%.2fm", getDesignLineOffsetAtBegin().getSI(),
106                 getDesignLineOffsetAtEnd().getSI(), getBeginWidth().getSI(), getEndWidth().getSI());
107     }
108 
109     /** {@inheritDoc} */
110     @Override
111     @SuppressWarnings("checkstyle:designforextension")
112     public Shoulder clone(final CrossSectionLink newParentLink, final OTSSimulatorInterface newSimulator,
113             final boolean animation) throws NetworkException
114     {
115         try
116         {
117             Shoulder newShoulder = new Shoulder(newParentLink, newSimulator, animation, this);
118             if (animation)
119             {
120                 new ShoulderAnimation(newShoulder, newSimulator, Color.GREEN);
121             }
122             return newShoulder;
123         }
124         catch (NamingException | RemoteException exception)
125         {
126             throw new NetworkException(exception);
127         }
128     }
129 
130 }