1 package org.opentrafficsim.road.network.lane;
2
3 import java.util.List;
4 import java.util.Set;
5
6 import org.djunits.value.vdouble.scalar.Length;
7 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
8 import org.opentrafficsim.core.geometry.OTSGeometryException;
9 import org.opentrafficsim.core.gtu.GTUType;
10 import org.opentrafficsim.core.network.LateralDirectionality;
11 import org.opentrafficsim.core.network.NetworkException;
12 import org.opentrafficsim.core.network.OTSNetwork;
13
14 /**
15 * Longitudinal road stripes; simple constructors.
16 * <p>
17 * Copyright (c) 2013-2017 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 Oct 25, 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 */
25 public class Stripe extends RoadMarkerAlong
26 {
27 /** */
28 private static final long serialVersionUID = 20151025L;
29
30 /**
31 * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
32 * the StartNode towards the EndNode as the longitudinal direction.
33 * @param parentLink Cross Section Link to which the element belongs
34 * @param lateralCenterPosition the lateral start position compared to the linear geometry of the Cross Section Link
35 * @param width positioned <i>symmetrically around</i> the center line given by the lateralCenterPosition.
36 * @throws OTSGeometryException when creation of the center line or contour geometry fails
37 * @throws NetworkException when id equal to null or not unique
38 */
39 public Stripe(final CrossSectionLink parentLink, final Length lateralCenterPosition, final Length width)
40 throws OTSGeometryException, NetworkException
41 {
42 super(parentLink, lateralCenterPosition, width);
43 }
44
45 /**
46 * Helper constructor that immediately provides permeability for a number of GTU classes.<br>
47 * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
48 * the StartNode towards the EndNode as the longitudinal direction.
49 * @param parentLink Cross Section Link to which the element belongs
50 * @param lateralCenterPosition the lateral start position compared to the linear geometry of the Cross Section Link
51 * @param width positioned <i>symmetrically around</i> the center line given by the lateralCenterPosition
52 * @param gtuTypes the GTU types for which the permeability is defined
53 * @param permeable one of the enums of Stripe.Permeable to define the permeability
54 * @throws OTSGeometryException when creation of the center line or contour geometry fails
55 * @throws NetworkException when id equal to null or not unique
56 */
57 public Stripe(final CrossSectionLink parentLink, final Length lateralCenterPosition, final Length width,
58 final Set<GTUType> gtuTypes, final Permeable permeable) throws OTSGeometryException, NetworkException
59 {
60 super(parentLink, lateralCenterPosition, width);
61 for (GTUType gtuType : gtuTypes)
62 {
63 addPermeability(gtuType, permeable);
64 }
65 }
66
67 /**
68 * Helper constructor that immediately provides permeability for all GTU classes.<br>
69 * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
70 * the StartNode towards the EndNode as the longitudinal direction.
71 * @param parentLink Cross Section Link to which the element belongs
72 * @param crossSectionSlices The offsets and widths at positions along the line, relative to the design line of the parent
73 * link. If there is just one with and offset, there should just be one element in the list with Length = 0. If
74 * there are more slices, the last one should be at the length of the design line. If not, a NetworkException is
75 * thrown.
76 * @param permeable one of the enums of Stripe.Permeable to define the permeability
77 * @throws OTSGeometryException when creation of the center line or contour geometry fails
78 * @throws NetworkException when id equal to null or not unique
79 */
80 public Stripe(final CrossSectionLink parentLink, final List<CrossSectionSlice> crossSectionSlices,
81 final Permeable permeable) throws OTSGeometryException, NetworkException
82 {
83 super(parentLink, crossSectionSlices);
84 addPermeability(GTUType.ALL, permeable);
85 }
86
87 /**
88 * Clone a Stripe for a new network.
89 * @param newParentLink the new link to which the clone belongs
90 * @param newSimulator the new simulator for this network
91 * @param animation whether to (re)create animation or not
92 * @param cse the element to clone from
93 * @throws NetworkException if link already exists in the network, if name of the link is not unique, or if the start node
94 * or the end node of the link are not registered in the network.
95 */
96 protected Stripe(final CrossSectionLink newParentLink, final OTSSimulatorInterface newSimulator, final boolean animation,
97 final Stripe cse) throws NetworkException
98 {
99 super(newParentLink, newSimulator, animation, cse);
100
101 if (animation)
102 {
103 OTSNetwork.cloneAnimation(cse, this, cse.getParentLink().getSimulator(), newSimulator);
104 }
105 }
106
107 /**
108 * @param gtuType GTU type to add permeability for.
109 * @param permeable direction(s) to add compared to the direction of the design line.
110 */
111 public final void addPermeability(final GTUType gtuType, final Permeable permeable)
112 {
113 if (permeable.equals(Permeable.LEFT) || permeable.equals(Permeable.BOTH))
114 {
115 addPermeability(gtuType, LateralDirectionality.LEFT);
116 }
117 if (permeable.equals(Permeable.RIGHT) || permeable.equals(Permeable.BOTH))
118 {
119 addPermeability(gtuType, LateralDirectionality.RIGHT);
120 }
121 }
122
123 /** The types of permeability of a stripe. */
124 public enum Permeable
125 {
126 /** Permeable in the positive lateral direction compared to the design line direction. */
127 LEFT,
128 /** Permeable in the negative lateral direction compared to the design line direction. */
129 RIGHT,
130 /** Permeable in both directions. */
131 BOTH;
132 }
133
134 /** {@inheritDoc} */
135 @Override
136 @SuppressWarnings("checkstyle:designforextension")
137 public String toString()
138 {
139 return String.format("Stripe offset %.2fm..%.2fm, width %.2fm..%.2fm", getDesignLineOffsetAtBegin().getSI(),
140 getDesignLineOffsetAtEnd().getSI(), getBeginWidth().getSI(), getEndWidth().getSI());
141 }
142
143 /** {@inheritDoc} */
144 @Override
145 @SuppressWarnings("checkstyle:designforextension")
146 public Stripe clone(final CrossSectionLink newParentLink, final OTSSimulatorInterface newSimulator, final boolean animation)
147 throws NetworkException
148 {
149 return new Stripe(newParentLink, newSimulator, animation, this);
150 }
151
152 }