Eclipse SUMO - Simulation of Urban MObility
NBSign.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // A class representing a street sign
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include <cassert>
25 #include <utils/common/RGBColor.h>
26 #include <utils/common/ToString.h>
28 #include "NBEdge.h"
29 #include "NBSign.h"
30 
31 
32 // ===========================================================================
33 // static members
34 // ===========================================================================
36  {"speed limit", NBSign::SIGN_TYPE_SPEED},
37  {"yield", NBSign::SIGN_TYPE_YIELD},
38  {"stop", NBSign::SIGN_TYPE_STOP},
39  {"allway_stop", NBSign::SIGN_TYPE_ALLWAY_STOP},
40  {"on ramp", NBSign::SIGN_TYPE_ON_RAMP},
41  {"priority", NBSign::SIGN_TYPE_PRIORITY},
42  {"right before left", NBSign::SIGN_TYPE_RIGHT_BEFORE_LEFT},
43  {"roundabout", NBSign::SIGN_TYPE_ROUNDABOUT},
44  {"rail crossing", NBSign::SIGN_TYPE_RAIL_CROSSING},
45  {"slope", NBSign::SIGN_TYPE_SLOPE},
46  {"city limits", NBSign::SIGN_TYPE_CITY},
47  {"info", NBSign::SIGN_TYPE_INFO},
48 };
49 
52 
53 
54 // ===========================================================================
55 // member method definitions
56 // ===========================================================================
57 
58 NBSign::NBSign(SignType type, double offset, const std::string label) :
59  myType(type),
60  myOffset(offset),
61  myLabel(label) {
62 }
63 
64 
66 
67 
68 void
69 NBSign::writeAsPOI(OutputDevice& into, const NBEdge* edge) const {
70  PositionVector shp = edge->getLanes()[0].shape;
71  try {
72  shp.move2side(3);
73  } catch (InvalidArgument&) {
74  // we do not write anything, maybe we should
75  }
77  into.openTag(SUMO_TAG_POI);
78  into.writeAttr(SUMO_ATTR_ID, edge->getID() + "." + toString(myOffset));
80  switch (myType) {
81  case SIGN_TYPE_SPEED:
82  case SIGN_TYPE_SLOPE:
83  case SIGN_TYPE_CITY:
84  case SIGN_TYPE_INFO:
86  break;
87  case SIGN_TYPE_YIELD:
88  case SIGN_TYPE_STOP:
90  case SIGN_TYPE_ON_RAMP:
93  break;
94  case SIGN_TYPE_PRIORITY:
96  break;
98  into.writeAttr(SUMO_ATTR_COLOR, RGBColor(255, 153, 0, 255));
99  break;
102  break;
103  }
104  into.writeAttr(SUMO_ATTR_X, pos.x());
105  into.writeAttr(SUMO_ATTR_Y, pos.y());
106  into.writeAttr(SUMO_ATTR_ANGLE, 0); // XXX use road angle?
107  // @todo add image resources and default images for all signs
108  //into.writeAttr(SUMO_ATTR_IMGFILE, p->getImgFile());
109  //into.writeAttr(SUMO_ATTR_WIDTH, p->getWidth());
110  //into.writeAttr(SUMO_ATTR_HEIGHT, p->getHeight());
111  into.closeTag();
112 }
113 
114 
115 /****************************************************************************/
StringBijection< NBSign::SignType >::Entry signTypeStringsInitializer[]
Definition: NBSign.cpp:35
@ SUMO_TAG_POI
begin/end of the description of a Point of interest
@ SUMO_ATTR_Y
@ SUMO_ATTR_X
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
The representation of a single edge during network building.
Definition: NBEdge.h:91
const std::string & getID() const
Definition: NBEdge.h:1423
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:677
void writeAsPOI(OutputDevice &into, const NBEdge *edge) const
write into device as POI positioned relative to the given edge
Definition: NBSign.cpp:69
SignType myType
the type of the sign
Definition: NBSign.h:77
double myOffset
The offset of the sign from the start of its edge.
Definition: NBSign.h:80
NBSign(SignType type, double offset, const std::string label="")
Constructor with id, and position.
Definition: NBSign.cpp:58
static StringBijection< SignType > SignTypeStrings
Definition: NBSign.h:85
~NBSign()
Destructor.
Definition: NBSign.cpp:65
SignType
Definition: NBSign.h:44
@ SIGN_TYPE_CITY
Definition: NBSign.h:55
@ SIGN_TYPE_RAIL_CROSSING
Definition: NBSign.h:53
@ SIGN_TYPE_SLOPE
Definition: NBSign.h:54
@ SIGN_TYPE_INFO
Definition: NBSign.h:56
@ SIGN_TYPE_SPEED
Definition: NBSign.h:45
@ SIGN_TYPE_ALLWAY_STOP
Definition: NBSign.h:48
@ SIGN_TYPE_YIELD
Definition: NBSign.h:46
@ SIGN_TYPE_STOP
Definition: NBSign.h:47
@ SIGN_TYPE_ROUNDABOUT
Definition: NBSign.h:52
@ SIGN_TYPE_ON_RAMP
Definition: NBSign.h:49
@ SIGN_TYPE_PRIORITY
Definition: NBSign.h:50
@ SIGN_TYPE_RIGHT_BEFORE_LEFT
Definition: NBSign.h:51
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:239
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
A list of positions.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
static const RGBColor BLUE
Definition: RGBColor.h:182
static const RGBColor GREY
Definition: RGBColor.h:189
static const RGBColor YELLOW
Definition: RGBColor.h:183
static const RGBColor RED
named colors
Definition: RGBColor.h:180
const std::string & getString(const T key) const