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