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 /****************************************************************************/
16 // A class representing a street sign
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <cassert>
26 #include <utils/common/RGBColor.h>
27 #include <utils/common/ToString.h>
29 #include "NBEdge.h"
30 #include "NBSign.h"
31 
32 
33 // ===========================================================================
34 // static members
35 // ===========================================================================
37  {"speed limit", NBSign::SIGN_TYPE_SPEED},
38  {"yield", NBSign::SIGN_TYPE_YIELD},
39  {"stop", NBSign::SIGN_TYPE_STOP},
40  {"allway_stop", NBSign::SIGN_TYPE_ALLWAY_STOP},
41  {"on ramp", NBSign::SIGN_TYPE_ON_RAMP},
42  {"priority", NBSign::SIGN_TYPE_PRIORITY},
43  {"right before left", NBSign::SIGN_TYPE_RIGHT_BEFORE_LEFT},
44  {"roundabout", NBSign::SIGN_TYPE_ROUNDABOUT},
45  {"rail crossing", NBSign::SIGN_TYPE_RAIL_CROSSING},
46  {"slope", NBSign::SIGN_TYPE_SLOPE},
47  {"city limits", NBSign::SIGN_TYPE_CITY},
48  {"info", NBSign::SIGN_TYPE_INFO},
49 };
50 
53 
54 
55 // ===========================================================================
56 // member method definitions
57 // ===========================================================================
58 
59 NBSign::NBSign(SignType type, double offset, const std::string label) :
60  myType(type),
61  myOffset(offset),
62  myLabel(label) {
63 }
64 
65 
67 
68 
69 void
70 NBSign::writeAsPOI(OutputDevice& into, const NBEdge* edge) const {
71  PositionVector shp = edge->getLanes()[0].shape;
72  try {
73  shp.move2side(3);
74  } catch (InvalidArgument&) {
75  // we do not write anything, maybe we should
76  }
78  into.openTag(SUMO_TAG_POI);
79  into.writeAttr(SUMO_ATTR_ID, edge->getID() + "." + toString(myOffset));
81  switch (myType) {
82  case SIGN_TYPE_SPEED:
83  case SIGN_TYPE_SLOPE:
84  case SIGN_TYPE_CITY:
85  case SIGN_TYPE_INFO:
87  break;
88  case SIGN_TYPE_YIELD:
89  case SIGN_TYPE_STOP:
91  case SIGN_TYPE_ON_RAMP:
94  break;
95  case SIGN_TYPE_PRIORITY:
97  break;
99  into.writeAttr(SUMO_ATTR_COLOR, RGBColor(255, 153, 0, 255));
100  break;
103  break;
104  }
105  into.writeAttr(SUMO_ATTR_X, pos.x());
106  into.writeAttr(SUMO_ATTR_Y, pos.y());
107  into.writeAttr(SUMO_ATTR_ANGLE, 0); // XXX use road angle?
108  // @todo add image resources and default images for all signs
109  //into.writeAttr(SUMO_ATTR_IMGFILE, p->getImgFile());
110  //into.writeAttr(SUMO_ATTR_WIDTH, p->getWidth());
111  //into.writeAttr(SUMO_ATTR_HEIGHT, p->getHeight());
112  into.closeTag();
113 }
114 
115 
116 /****************************************************************************/
117 
RGBColor::GREY
static const RGBColor GREY
Definition: RGBColor.h:198
SUMO_ATTR_TYPE
Definition: SUMOXMLDefinitions.h:381
SUMO_ATTR_ANGLE
Definition: SUMOXMLDefinitions.h:794
ToString.h
NBSign::SIGN_TYPE_RIGHT_BEFORE_LEFT
Definition: NBSign.h:53
NBSign::~NBSign
~NBSign()
Destructor.
Definition: NBSign.cpp:66
NBSign::SIGN_TYPE_ALLWAY_STOP
Definition: NBSign.h:50
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
StringBijection::getString
const std::string & getString(const T key) const
Definition: StringBijection.h:106
signTypeStringsInitializer
StringBijection< NBSign::SignType >::Entry signTypeStringsInitializer[]
Definition: NBSign.cpp:36
RGBColor::YELLOW
static const RGBColor YELLOW
Definition: RGBColor.h:192
SUMO_ATTR_COLOR
A color information.
Definition: SUMOXMLDefinitions.h:704
SUMO_TAG_POI
begin/end of the description of a Point of interest
Definition: SUMOXMLDefinitions.h:53
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
PositionVector
A list of positions.
Definition: PositionVector.h:45
RGBColor.h
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
NBSign::myOffset
double myOffset
The offset of the sign from the start of its edge.
Definition: NBSign.h:82
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
RGBColor
Definition: RGBColor.h:39
StringBijection
Definition: StringBijection.h:43
NBSign::NBSign
NBSign(SignType type, double offset, const std::string label="")
Constructor with id, and position.
Definition: NBSign.cpp:59
PositionVector::positionAtOffset
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Definition: PositionVector.cpp:248
OutputDevice.h
RGBColor::BLUE
static const RGBColor BLUE
Definition: RGBColor.h:191
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
Position::x
double x() const
Returns the x-position.
Definition: Position.h:56
SUMO_ATTR_Y
Definition: SUMOXMLDefinitions.h:399
RGBColor::RED
static const RGBColor RED
named colors
Definition: RGBColor.h:189
NBSign::myType
SignType myType
the type of the sign
Definition: NBSign.h:79
NBSign::SIGN_TYPE_ON_RAMP
Definition: NBSign.h:51
NBEdge::getLanes
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:656
NBSign::SIGN_TYPE_RAIL_CROSSING
Definition: NBSign.h:55
NBSign::SIGN_TYPE_CITY
Definition: NBSign.h:57
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
Position::y
double y() const
Returns the y-position.
Definition: Position.h:61
NBSign::SignType
SignType
Definition: NBSign.h:46
NBSign::SIGN_TYPE_STOP
Definition: NBSign.h:49
InvalidArgument
Definition: UtilExceptions.h:56
NBSign::SIGN_TYPE_SLOPE
Definition: NBSign.h:56
NBSign::SIGN_TYPE_PRIORITY
Definition: NBSign.h:52
StringBijection::Entry
Definition: StringBijection.h:51
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:70
NBSign::SIGN_TYPE_INFO
Definition: NBSign.h:58
NBSign::SIGN_TYPE_SPEED
Definition: NBSign.h:47
NBSign::SignTypeStrings
static StringBijection< SignType > SignTypeStrings
Definition: NBSign.h:87
SUMO_ATTR_X
Definition: SUMOXMLDefinitions.h:398
NBSign::SIGN_TYPE_ROUNDABOUT
Definition: NBSign.h:54
PositionVector::move2side
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
Definition: PositionVector.cpp:1103
NBEdge.h
NBSign::SIGN_TYPE_YIELD
Definition: NBSign.h:48
NBEdge::getID
const std::string & getID() const
Definition: NBEdge.h:1380