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-2018 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 
53  signTypeStringsInitializer, NBSign::SIGN_TYPE_INFO);
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 
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
static const RGBColor BLUE
Definition: RGBColor.h:186
const std::string & getString(const T key) const
double y() const
Returns the y-position.
Definition: Position.h:62
The representation of a single edge during network building.
Definition: NBEdge.h:65
double x() const
Returns the x-position.
Definition: Position.h:57
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:589
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:71
const std::string & getID() const
Returns the id.
Definition: Named.h:78
~NBSign()
Destructor.
Definition: NBSign.cpp:67
NBSign(SignType type, double offset, const std::string label="")
Constructor with id, and position.
Definition: NBSign.cpp:60
static const RGBColor GREY
Definition: RGBColor.h:193
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
A list of positions.
double myOffset
The offset of the sign from the start of its edge.
Definition: NBSign.h:83
void move2side(double amount)
move position vector to side using certain ammount
static const RGBColor YELLOW
Definition: RGBColor.h:187
static const RGBColor RED
named colors
Definition: RGBColor.h:184
static StringBijection< SignType > SignTypeStrings
Definition: NBSign.h:88
SignType myType
the type of the sign
Definition: NBSign.h:80
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
StringBijection< NBSign::SignType >::Entry signTypeStringsInitializer[]
Definition: NBSign.cpp:37
A color information.
SignType
Definition: NBSign.h:47
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.