Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/shapes/Shape.cpp
193874 views
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 std::string Shape::DEFAULT_NAME = "";
41
const Parameterised::Map Shape::DEFAULT_PARAMETERS = Parameterised::Map();
42
43
// ===========================================================================
44
// member definitions
45
// ===========================================================================
46
47
Shape::Shape(const std::string& id) :
48
Named(id),
49
myType(DEFAULT_TYPE),
50
myColor(RGBColor::BLACK),
51
myLayer(DEFAULT_LAYER),
52
myNaviDegreeAngle(DEFAULT_ANGLE),
53
myImgFile(DEFAULT_IMG_FILE),
54
myName(DEFAULT_NAME) {
55
}
56
57
58
Shape::Shape(const std::string& id, const std::string& type, const RGBColor& color, double layer,
59
double angle, const std::string& imgFile, const std::string& name) :
60
Named(id),
61
myType(type),
62
myColor(color),
63
myLayer(layer),
64
myNaviDegreeAngle(angle),
65
myImgFile(imgFile),
66
myName(name) {
67
}
68
69
70
Shape::~Shape() {}
71
72
73
void
74
Shape::writeShapeAttributes(OutputDevice& device, const RGBColor& defaultColor, const double defaultLayer) const {
75
// name
76
if (myName != DEFAULT_NAME) {
77
device.writeAttr(SUMO_ATTR_NAME, myName);
78
}
79
// type
80
if (myType != DEFAULT_TYPE) {
81
device.writeAttr(SUMO_ATTR_TYPE, StringUtils::escapeXML(myType));
82
}
83
// color
84
if (myColor != defaultColor) {
85
device.writeAttr(SUMO_ATTR_COLOR, myColor);
86
}
87
// layer
88
if (myLayer != defaultLayer) {
89
device.writeAttr(SUMO_ATTR_LAYER, myLayer);
90
}
91
// angle
92
if (myNaviDegreeAngle != Shape::DEFAULT_ANGLE) {
93
device.writeAttr(SUMO_ATTR_ANGLE, myNaviDegreeAngle);
94
}
95
// img file
96
if (myImgFile != Shape::DEFAULT_IMG_FILE) {
97
device.writeAttr(SUMO_ATTR_IMGFILE, myImgFile);
98
}
99
}
100
101
102
const std::string&
103
Shape::getShapeType() const {
104
return myType;
105
}
106
107
108
const RGBColor&
109
Shape::getShapeColor() const {
110
return myColor;
111
}
112
113
114
double
115
Shape::getShapeLayer() const {
116
return myLayer;
117
}
118
119
120
double
121
Shape::getShapeNaviDegree() const {
122
return myNaviDegreeAngle;
123
}
124
125
126
const std::string&
127
Shape::getShapeImgFile() const {
128
return myImgFile;
129
}
130
131
132
const std::string&
133
Shape::getShapeName() const {
134
return myName;
135
}
136
137
138
void
139
Shape::setShapeType(const std::string& type) {
140
myType = type;
141
}
142
143
144
void
145
Shape::setShapeColor(const RGBColor& col) {
146
myColor = col;
147
}
148
149
150
void
151
Shape::setShapeAlpha(unsigned char alpha) {
152
myColor.setAlpha(alpha);
153
}
154
155
156
void
157
Shape::setShapeLayer(const double layer) {
158
myLayer = layer;
159
}
160
161
162
void
163
Shape::setShapeNaviDegree(const double angle) {
164
myNaviDegreeAngle = angle;
165
}
166
167
168
void
169
Shape::setShapeImgFile(const std::string& imgFile) {
170
myImgFile = imgFile;
171
}
172
173
void
174
Shape::setShapeName(const std::string& name) {
175
myName = name;
176
}
177
178
/****************************************************************************/
179
180