SUMO - Simulation of Urban MObility
NBSign.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A class representing a street sign
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2012-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <cassert>
34 #include <utils/common/RGBColor.h>
35 #include <utils/common/ToString.h>
37 #include "NBEdge.h"
38 #include "NBSign.h"
39 
40 
41 // ===========================================================================
42 // static members
43 // ===========================================================================
45  {"speed limit", NBSign::SIGN_TYPE_SPEED},
46  {"yield", NBSign::SIGN_TYPE_YIELD},
47  {"stop", NBSign::SIGN_TYPE_STOP},
48  {"allway_stop", NBSign::SIGN_TYPE_ALLWAY_STOP},
49  {"on ramp", NBSign::SIGN_TYPE_ON_RAMP},
50  {"priority", NBSign::SIGN_TYPE_PRIORITY},
51  {"right before left", NBSign::SIGN_TYPE_RIGHT_BEFORE_LEFT},
52  {"roundabout", NBSign::SIGN_TYPE_ROUNDABOUT},
53  {"rail crossing", NBSign::SIGN_TYPE_RAIL_CROSSING},
54  {"slope", NBSign::SIGN_TYPE_SLOPE},
55  {"city limits", NBSign::SIGN_TYPE_CITY},
56  {"info", NBSign::SIGN_TYPE_INFO},
57 };
58 
60  signTypeStringsInitializer, NBSign::SIGN_TYPE_INFO);
61 
62 
63 // ===========================================================================
64 // member method definitions
65 // ===========================================================================
66 
67 NBSign::NBSign(SignType type, double offset, const std::string label) :
68  myType(type),
69  myOffset(offset),
70  myLabel(label) {
71 }
72 
73 
75 
76 
77 void
78 NBSign::writeAsPOI(OutputDevice& into, const NBEdge* edge) const {
79  PositionVector shp = edge->getLanes()[0].shape;
80  try {
81  shp.move2side(3);
82  } catch (InvalidArgument&) {
83  // we do not write anything, maybe we should
84  }
86  into.openTag(SUMO_TAG_POI);
87  into.writeAttr(SUMO_ATTR_ID, edge->getID() + "." + toString(myOffset));
89  switch (myType) {
90  case SIGN_TYPE_SPEED:
91  case SIGN_TYPE_SLOPE:
92  case SIGN_TYPE_CITY:
93  case SIGN_TYPE_INFO:
95  break;
96  case SIGN_TYPE_YIELD:
97  case SIGN_TYPE_STOP:
99  case SIGN_TYPE_ON_RAMP:
102  break;
103  case SIGN_TYPE_PRIORITY:
105  break;
107  into.writeAttr(SUMO_ATTR_COLOR, RGBColor(255, 153, 0, 255));
108  break;
111  break;
112  }
113  into.writeAttr(SUMO_ATTR_X, pos.x());
114  into.writeAttr(SUMO_ATTR_Y, pos.y());
115  into.writeAttr(SUMO_ATTR_ANGLE, 0); // XXX use road angle?
116  // @todo add image resources and default images for all signs
117  //into.writeAttr(SUMO_ATTR_IMGFILE, p->getImgFile());
118  //into.writeAttr(SUMO_ATTR_WIDTH, p->getWidth());
119  //into.writeAttr(SUMO_ATTR_HEIGHT, p->getHeight());
120  into.closeTag();
121 }
122 
123 
124 /****************************************************************************/
125 
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
static const RGBColor BLUE
Definition: RGBColor.h:191
const std::string & getString(const T key) const
double y() const
Returns the y-position.
Definition: Position.h:68
The representation of a single edge during network building.
Definition: NBEdge.h:71
double x() const
Returns the x-position.
Definition: Position.h:63
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:570
begin/end of the description of a polygon
void writeAsPOI(OutputDevice &into, const NBEdge *edge) const
write into device as POI positioned relative to the given edge
Definition: NBSign.cpp:78
const std::string & getID() const
Returns the id.
Definition: Named.h:66
~NBSign()
Destructor.
Definition: NBSign.cpp:74
NBSign(SignType type, double offset, const std::string label="")
Constructor with id, and position.
Definition: NBSign.cpp:67
static const RGBColor GREY
Definition: RGBColor.h:198
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
double myOffset
The offset of the sign from the start of its edge.
Definition: NBSign.h:90
void move2side(double amount)
move position vector to side using certain ammount
static const RGBColor YELLOW
Definition: RGBColor.h:192
static const RGBColor RED
Definition: RGBColor.h:189
static StringBijection< SignType > SignTypeStrings
Definition: NBSign.h:95
SignType myType
the type of the sign
Definition: NBSign.h:87
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
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:44
A color information.
SignType
Definition: NBSign.h:54
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.