SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
12 // Copyright (C) 2012-2014 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 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // static members
47 // ===========================================================================
49  {"speed limit", NBSign::SIGN_TYPE_SPEED},
50  {"yield", NBSign::SIGN_TYPE_YIELD},
51  {"stop", NBSign::SIGN_TYPE_STOP},
52  {"allway_stop", NBSign::SIGN_TYPE_ALLWAY_STOP},
53  {"on ramp", NBSign::SIGN_TYPE_ON_RAMP},
54  {"priority", NBSign::SIGN_TYPE_PRIORITY},
55  {"right before left", NBSign::SIGN_TYPE_RIGHT_BEFORE_LEFT},
56  {"roundabout", NBSign::SIGN_TYPE_ROUNDABOUT},
57  {"rail crossing", NBSign::SIGN_TYPE_RAIL_CROSSING},
58  {"slope", NBSign::SIGN_TYPE_SLOPE},
59  {"city limits", NBSign::SIGN_TYPE_CITY},
60  {"info", NBSign::SIGN_TYPE_INFO},
61 };
62 
64  signTypeStringsInitializer, NBSign::SIGN_TYPE_INFO);
65 
66 
67 // ===========================================================================
68 // member method definitions
69 // ===========================================================================
70 
71 NBSign::NBSign(SignType type, SUMOReal offset, const std::string label) :
72  myType(type),
73  myOffset(offset),
74  myLabel(label)
75 { }
76 
77 
79 
80 
81 void
82 NBSign::writeAsPOI(OutputDevice& into, const NBEdge* edge) const {
83  PositionVector shp = edge->getLanes()[0].shape;
84  try {
85  shp.move2side(3);
86  } catch (InvalidArgument&) {
87  // we do not write anything, maybe we should
88  }
90  into.openTag(SUMO_TAG_POI);
91  into.writeAttr(SUMO_ATTR_ID, edge->getID() + "." + toString(myOffset));
93  switch (myType) {
94  case SIGN_TYPE_SPEED:
95  case SIGN_TYPE_SLOPE:
96  case SIGN_TYPE_CITY:
97  case SIGN_TYPE_INFO:
99  break;
100  case SIGN_TYPE_YIELD:
101  case SIGN_TYPE_STOP:
103  case SIGN_TYPE_ON_RAMP:
106  break;
107  case SIGN_TYPE_PRIORITY:
109  break;
111  into.writeAttr(SUMO_ATTR_COLOR, RGBColor(255, 153, 0, 255));
112  break;
115  break;
116  }
117  into.writeAttr(SUMO_ATTR_X, pos.x());
118  into.writeAttr(SUMO_ATTR_Y, pos.y());
119  into.writeAttr(SUMO_ATTR_ANGLE, 0); // XXX use road angle?
120  // @todo add image resources and default images for all signs
121  //into.writeAttr(SUMO_ATTR_IMGFILE, p->getImgFile());
122  //into.writeAttr(SUMO_ATTR_WIDTH, p->getWidth());
123  //into.writeAttr(SUMO_ATTR_HEIGHT, p->getHeight());
124  into.closeTag();
125 }
126 
127 
128 /****************************************************************************/
129 
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
static const RGBColor BLUE
Definition: RGBColor.h:191
SUMOReal myOffset
The offset of the sign from the start of its edge.
Definition: NBSign.h:90
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:503
The representation of a single edge during network building.
Definition: NBEdge.h:71
void writeAsPOI(OutputDevice &into, const NBEdge *edge) const
write into device as POI positioned relative to the given edge
Definition: NBSign.cpp:82
~NBSign()
Destructor.
Definition: NBSign.cpp:78
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
const std::string & getID() const
Returns the id.
Definition: Named.h:60
static const RGBColor GREY
Definition: RGBColor.h:197
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
const std::string & getString(const T key) const
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
NBSign(SignType type, SUMOReal offset, const std::string label="")
Constructor with id, and position.
Definition: NBSign.cpp:71
static const RGBColor YELLOW
Definition: RGBColor.h:192
static const RGBColor RED
Definition: RGBColor.h:189
static StringBijection< SignType > SignTypeStrings
Definition: NBSign.h:95
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
SignType myType
the type of the sign
Definition: NBSign.h:87
void move2side(SUMOReal amount)
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:215
StringBijection< NBSign::SignType >::Entry signTypeStringsInitializer[]
Definition: NBSign.cpp:48
A color information.
SignType
Definition: NBSign.h:54
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.