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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // A class representing a street sign
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <cassert>
27 #include <utils/common/RGBColor.h>
28 #include <utils/common/ToString.h>
30 #include "NBEdge.h"
31 #include "NBSign.h"
32 
33 
34 // ===========================================================================
35 // static members
36 // ===========================================================================
38  {"speed limit", NBSign::SIGN_TYPE_SPEED},
39  {"yield", NBSign::SIGN_TYPE_YIELD},
40  {"stop", NBSign::SIGN_TYPE_STOP},
41  {"allway_stop", NBSign::SIGN_TYPE_ALLWAY_STOP},
42  {"on ramp", NBSign::SIGN_TYPE_ON_RAMP},
43  {"priority", NBSign::SIGN_TYPE_PRIORITY},
44  {"right before left", NBSign::SIGN_TYPE_RIGHT_BEFORE_LEFT},
45  {"roundabout", NBSign::SIGN_TYPE_ROUNDABOUT},
46  {"rail crossing", NBSign::SIGN_TYPE_RAIL_CROSSING},
47  {"slope", NBSign::SIGN_TYPE_SLOPE},
48  {"city limits", NBSign::SIGN_TYPE_CITY},
49  {"info", NBSign::SIGN_TYPE_INFO},
50 };
51 
54 
55 
56 // ===========================================================================
57 // member method definitions
58 // ===========================================================================
59 
60 NBSign::NBSign(SignType type, double offset, const std::string label) :
61  myType(type),
62  myOffset(offset),
63  myLabel(label) {
64 }
65 
66 
68 
69 
70 void
71 NBSign::writeAsPOI(OutputDevice& into, const NBEdge* edge) const {
72  PositionVector shp = edge->getLanes()[0].shape;
73  try {
74  shp.move2side(3);
75  } catch (InvalidArgument&) {
76  // we do not write anything, maybe we should
77  }
79  into.openTag(SUMO_TAG_POI);
80  into.writeAttr(SUMO_ATTR_ID, edge->getID() + "." + toString(myOffset));
82  switch (myType) {
83  case SIGN_TYPE_SPEED:
84  case SIGN_TYPE_SLOPE:
85  case SIGN_TYPE_CITY:
86  case SIGN_TYPE_INFO:
88  break;
89  case SIGN_TYPE_YIELD:
90  case SIGN_TYPE_STOP:
92  case SIGN_TYPE_ON_RAMP:
95  break;
96  case SIGN_TYPE_PRIORITY:
98  break;
100  into.writeAttr(SUMO_ATTR_COLOR, RGBColor(255, 153, 0, 255));
101  break;
104  break;
105  }
106  into.writeAttr(SUMO_ATTR_X, pos.x());
107  into.writeAttr(SUMO_ATTR_Y, pos.y());
108  into.writeAttr(SUMO_ATTR_ANGLE, 0); // XXX use road angle?
109  // @todo add image resources and default images for all signs
110  //into.writeAttr(SUMO_ATTR_IMGFILE, p->getImgFile());
111  //into.writeAttr(SUMO_ATTR_WIDTH, p->getWidth());
112  //into.writeAttr(SUMO_ATTR_HEIGHT, p->getHeight());
113  into.closeTag();
114 }
115 
116 
117 /****************************************************************************/
118 
RGBColor::GREY
static const RGBColor GREY
Definition: RGBColor.h:199
SUMO_ATTR_TYPE
Definition: SUMOXMLDefinitions.h:382
SUMO_ATTR_ANGLE
Definition: SUMOXMLDefinitions.h:791
ToString.h
NBSign::SIGN_TYPE_RIGHT_BEFORE_LEFT
Definition: NBSign.h:54
NBSign::~NBSign
~NBSign()
Destructor.
Definition: NBSign.cpp:67
NBSign::SIGN_TYPE_ALLWAY_STOP
Definition: NBSign.h:51
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
StringBijection::getString
const std::string & getString(const T key) const
Definition: StringBijection.h:107
signTypeStringsInitializer
StringBijection< NBSign::SignType >::Entry signTypeStringsInitializer[]
Definition: NBSign.cpp:37
RGBColor::YELLOW
static const RGBColor YELLOW
Definition: RGBColor.h:193
SUMO_ATTR_COLOR
A color information.
Definition: SUMOXMLDefinitions.h:701
SUMO_TAG_POI
begin/end of the description of a Point of interest
Definition: SUMOXMLDefinitions.h:54
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
PositionVector
A list of positions.
Definition: PositionVector.h:46
RGBColor.h
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:86
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:254
NBSign::myOffset
double myOffset
The offset of the sign from the start of its edge.
Definition: NBSign.h:83
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
RGBColor
Definition: RGBColor.h:40
StringBijection
Definition: StringBijection.h:44
NBSign::NBSign
NBSign(SignType type, double offset, const std::string label="")
Constructor with id, and position.
Definition: NBSign.cpp:60
PositionVector::positionAtOffset
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Definition: PositionVector.cpp:246
OutputDevice.h
RGBColor::BLUE
static const RGBColor BLUE
Definition: RGBColor.h:192
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
Position::x
double x() const
Returns the x-position.
Definition: Position.h:57
SUMO_ATTR_Y
Definition: SUMOXMLDefinitions.h:400
RGBColor::RED
static const RGBColor RED
named colors
Definition: RGBColor.h:190
NBSign::myType
SignType myType
the type of the sign
Definition: NBSign.h:80
NBSign::SIGN_TYPE_ON_RAMP
Definition: NBSign.h:52
NBEdge::getLanes
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:644
NBSign::SIGN_TYPE_RAIL_CROSSING
Definition: NBSign.h:56
NBSign::SIGN_TYPE_CITY
Definition: NBSign.h:58
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:240
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
Position::y
double y() const
Returns the y-position.
Definition: Position.h:62
NBSign::SignType
SignType
Definition: NBSign.h:47
NBSign::SIGN_TYPE_STOP
Definition: NBSign.h:50
InvalidArgument
Definition: UtilExceptions.h:57
NBSign::SIGN_TYPE_SLOPE
Definition: NBSign.h:57
NBSign::SIGN_TYPE_PRIORITY
Definition: NBSign.h:53
StringBijection::Entry
Definition: StringBijection.h:52
NBSign.h
config.h
NBSign::writeAsPOI
void writeAsPOI(OutputDevice &into, const NBEdge *edge) const
write into device as POI positioned relative to the given edge
Definition: NBSign.cpp:71
NBSign::SIGN_TYPE_INFO
Definition: NBSign.h:59
NBSign::SIGN_TYPE_SPEED
Definition: NBSign.h:48
NBSign::SignTypeStrings
static StringBijection< SignType > SignTypeStrings
Definition: NBSign.h:88
SUMO_ATTR_X
Definition: SUMOXMLDefinitions.h:399
NBSign::SIGN_TYPE_ROUNDABOUT
Definition: NBSign.h:55
PositionVector::move2side
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
Definition: PositionVector.cpp:1086
NBEdge.h
NBSign::SIGN_TYPE_YIELD
Definition: NBSign.h:49
NBEdge::getID
const std::string & getID() const
Definition: NBEdge.h:1364