Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2012-2026 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 Shape.cpp
15 : /// @author Jakob Erdmann
16 : /// @author Michael Behrisch
17 : /// @date Oct 2012
18 : ///
19 : // A 2D- or 3D-Shape
20 : /****************************************************************************/
21 : #include <config.h>
22 :
23 : #include <utils/gui/globjects/GUIGlObjectTypes.h>
24 : #include <utils/iodevices/OutputDevice.h>
25 :
26 : #include "Shape.h"
27 :
28 : // ===========================================================================
29 : // static member definitions
30 : // ===========================================================================
31 :
32 : const std::string Shape::DEFAULT_TYPE = "";
33 : const double Shape::DEFAULT_LAYER = 0;
34 : const double Shape::DEFAULT_LINEWIDTH = 1;
35 : const double Shape::DEFAULT_LAYER_POI = (double)GLO_POI;
36 : const double Shape::DEFAULT_ANGLE = 0;
37 : const std::string Shape::DEFAULT_IMG_FILE = "";
38 : const double Shape::DEFAULT_IMG_WIDTH = 2.6;
39 : const double Shape::DEFAULT_IMG_HEIGHT = 1;
40 : const double Shape::DEFAULT_HEIGHT = 0;
41 : const std::string Shape::DEFAULT_NAME = "";
42 : const Parameterised::Map Shape::DEFAULT_PARAMETERS = Parameterised::Map();
43 :
44 : // ===========================================================================
45 : // member definitions
46 : // ===========================================================================
47 :
48 0 : Shape::Shape(const std::string& id) :
49 : Named(id),
50 0 : myName(DEFAULT_NAME) {
51 0 : }
52 :
53 :
54 160007 : Shape::Shape(const std::string& id, const std::string& type, const RGBColor& color, double layer,
55 160007 : double angle, const std::string& imgFile, const std::string& name) :
56 : Named(id),
57 160007 : myType(type),
58 160007 : myColor(color),
59 160007 : myLayer(layer),
60 160007 : myNaviDegreeAngle(angle),
61 160007 : myImgFile(imgFile),
62 320014 : myName(name) {
63 160007 : }
64 :
65 :
66 159027 : Shape::~Shape() {}
67 :
68 :
69 : void
70 0 : Shape::writeShapeAttributes(OutputDevice& device, const RGBColor& defaultColor, const double defaultLayer) const {
71 : // name
72 0 : if (myName != DEFAULT_NAME) {
73 0 : device.writeAttr(SUMO_ATTR_NAME, myName);
74 : }
75 : // type
76 0 : if (myType != DEFAULT_TYPE) {
77 0 : device.writeAttr(SUMO_ATTR_TYPE, StringUtils::escapeXML(myType));
78 : }
79 : // color
80 0 : if (myColor != defaultColor) {
81 0 : device.writeAttr(SUMO_ATTR_COLOR, myColor);
82 : }
83 : // layer
84 0 : if (myLayer != defaultLayer) {
85 0 : device.writeAttr(SUMO_ATTR_LAYER, myLayer);
86 : }
87 : // angle
88 0 : if (myNaviDegreeAngle != Shape::DEFAULT_ANGLE) {
89 0 : device.writeAttr(SUMO_ATTR_ANGLE, myNaviDegreeAngle);
90 : }
91 : // img file
92 0 : if (myImgFile != Shape::DEFAULT_IMG_FILE) {
93 0 : device.writeAttr(SUMO_ATTR_IMGFILE, myImgFile);
94 : }
95 0 : }
96 :
97 :
98 : const std::string&
99 13510 : Shape::getShapeType() const {
100 13510 : return myType;
101 : }
102 :
103 :
104 : const RGBColor&
105 81970 : Shape::getShapeColor() const {
106 81970 : return myColor;
107 : }
108 :
109 :
110 : double
111 82984 : Shape::getShapeLayer() const {
112 82984 : return myLayer;
113 : }
114 :
115 :
116 : double
117 73222 : Shape::getShapeNaviDegree() const {
118 73222 : return myNaviDegreeAngle;
119 : }
120 :
121 :
122 : const std::string&
123 122730 : Shape::getShapeImgFile() const {
124 122730 : return myImgFile;
125 : }
126 :
127 :
128 : const std::string&
129 6553 : Shape::getShapeName() const {
130 6553 : return myName;
131 : }
132 :
133 :
134 : void
135 12 : Shape::setShapeType(const std::string& type) {
136 12 : myType = type;
137 12 : }
138 :
139 :
140 : void
141 17 : Shape::setShapeColor(const RGBColor& col) {
142 17 : myColor = col;
143 17 : }
144 :
145 :
146 : void
147 746 : Shape::setShapeAlpha(unsigned char alpha) {
148 746 : myColor.setAlpha(alpha);
149 746 : }
150 :
151 :
152 : void
153 0 : Shape::setShapeLayer(const double layer) {
154 0 : myLayer = layer;
155 0 : }
156 :
157 :
158 : void
159 5 : Shape::setShapeNaviDegree(const double angle) {
160 5 : myNaviDegreeAngle = angle;
161 5 : }
162 :
163 :
164 : void
165 5 : Shape::setShapeImgFile(const std::string& imgFile) {
166 5 : myImgFile = imgFile;
167 5 : }
168 :
169 : void
170 0 : Shape::setShapeName(const std::string& name) {
171 0 : myName = name;
172 0 : }
173 :
174 : /****************************************************************************/
|