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