Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2012-2024 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file NBSign.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Michael Behrisch
17 : /// @author Jakob Erdmann
18 : /// @date Nov 2012
19 : ///
20 : // A class representing a street sign
21 : /****************************************************************************/
22 : #include <config.h>
23 :
24 : #include <cassert>
25 : #include <utils/common/RGBColor.h>
26 : #include <utils/common/ToString.h>
27 : #include <utils/geom/GeomHelper.h>
28 : #include <utils/iodevices/OutputDevice.h>
29 : #include "NBEdge.h"
30 : #include "NBSign.h"
31 :
32 :
33 : // ===========================================================================
34 : // static members
35 : // ===========================================================================
36 : static StringBijection<NBSign::SignType>::Entry signTypeStringsInitializer[] = {
37 : {"speed limit", NBSign::SIGN_TYPE_SPEED},
38 : {"yield", NBSign::SIGN_TYPE_YIELD},
39 : {"stop", NBSign::SIGN_TYPE_STOP},
40 : {"allway_stop", NBSign::SIGN_TYPE_ALLWAY_STOP},
41 : {"on ramp", NBSign::SIGN_TYPE_ON_RAMP},
42 : {"priority", NBSign::SIGN_TYPE_PRIORITY},
43 : {"right before left", NBSign::SIGN_TYPE_RIGHT_BEFORE_LEFT},
44 : {"left before right", NBSign::SIGN_TYPE_LEFT_BEFORE_RIGHT},
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 :
52 : StringBijection<NBSign::SignType> NBSign::SignTypeStrings(
53 : signTypeStringsInitializer, NBSign::SIGN_TYPE_INFO);
54 :
55 :
56 : // ===========================================================================
57 : // member method definitions
58 : // ===========================================================================
59 :
60 8 : NBSign::NBSign(SignType type, double offset, const std::string label) :
61 8 : myType(type),
62 8 : myOffset(offset),
63 8 : myLabel(label) {
64 8 : }
65 :
66 :
67 16 : NBSign::~NBSign() {}
68 :
69 :
70 : void
71 8 : NBSign::writeAsPOI(OutputDevice& into, const NBEdge* edge) const {
72 : PositionVector shp = edge->getLanes()[0].shape;
73 : try {
74 8 : shp.move2side(3);
75 0 : } catch (InvalidArgument&) {
76 : // we do not write anything, maybe we should
77 0 : }
78 8 : Position pos = shp.positionAtOffset(myOffset);
79 8 : into.openTag(SUMO_TAG_POI);
80 16 : into.writeAttr(SUMO_ATTR_ID, edge->getID() + "." + toString(myOffset));
81 8 : into.writeAttr(SUMO_ATTR_TYPE, SignTypeStrings.getString(myType));
82 8 : switch (myType) { /// XXX @todo add default colors
83 : case SIGN_TYPE_SPEED:
84 : case SIGN_TYPE_SLOPE:
85 : case SIGN_TYPE_CITY:
86 : case SIGN_TYPE_INFO:
87 : into.writeAttr(SUMO_ATTR_COLOR, RGBColor::GREY);
88 : break;
89 : case SIGN_TYPE_YIELD:
90 : case SIGN_TYPE_STOP:
91 : case SIGN_TYPE_ALLWAY_STOP:
92 : case SIGN_TYPE_ON_RAMP:
93 : case SIGN_TYPE_RAIL_CROSSING:
94 : into.writeAttr(SUMO_ATTR_COLOR, RGBColor::RED);
95 : break;
96 : case SIGN_TYPE_PRIORITY:
97 : into.writeAttr(SUMO_ATTR_COLOR, RGBColor::YELLOW);
98 : break;
99 4 : case SIGN_TYPE_RIGHT_BEFORE_LEFT:
100 : case SIGN_TYPE_LEFT_BEFORE_RIGHT:
101 4 : into.writeAttr(SUMO_ATTR_COLOR, RGBColor(255, 153, 0, 255));
102 4 : break;
103 : case SIGN_TYPE_ROUNDABOUT:
104 : into.writeAttr(SUMO_ATTR_COLOR, RGBColor::BLUE);
105 : break;
106 : }
107 16 : into.writeAttr(SUMO_ATTR_X, pos.x());
108 8 : into.writeAttr(SUMO_ATTR_Y, pos.y());
109 8 : into.writeAttr(SUMO_ATTR_ANGLE, GeomHelper::naviDegree(shp.rotationAtOffset(myOffset)));
110 : // @todo add image resources and default images for all signs
111 : //into.writeAttr(SUMO_ATTR_IMGFILE, p->getImgFile());
112 : //into.writeAttr(SUMO_ATTR_WIDTH, p->getWidth());
113 : //into.writeAttr(SUMO_ATTR_HEIGHT, p->getHeight());
114 16 : into.closeTag();
115 8 : }
116 :
117 :
118 : /****************************************************************************/
|