Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/shapes/SUMOPolygon.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2004-2025 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 SUMOPolygon.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Michael Behrisch
17
/// @author Jakob Erdmann
18
/// @date Jun 2004
19
///
20
// A 2D-polygon
21
/****************************************************************************/
22
#include <config.h>
23
24
#include <utils/iodevices/OutputDevice.h>
25
#include <utils/common/FileHelpers.h>
26
#include <utils/common/StringUtils.h>
27
#include <utils/geom/GeoConvHelper.h>
28
29
#include "SUMOPolygon.h"
30
31
// ===========================================================================
32
// member definitions
33
// ===========================================================================
34
SUMOPolygon::SUMOPolygon(const std::string& id, const std::string& type, const RGBColor& color,
35
const PositionVector& shape, bool geo, bool fill, double lineWidth,
36
double layer, double angle, const std::string& imgFile, const std::string& name,
37
const Parameterised::Map& parameters) :
38
Shape(id, type, color, layer, angle, imgFile, name),
39
Parameterised(parameters),
40
myShape(shape),
41
myGEO(geo),
42
myFill(fill),
43
myLineWidth(lineWidth) {
44
}
45
46
47
SUMOPolygon::~SUMOPolygon() {}
48
49
50
const PositionVector&
51
SUMOPolygon::getShape() const {
52
return myShape;
53
}
54
55
56
const std::vector<PositionVector>&
57
SUMOPolygon::getHoles() const {
58
return myHoles;
59
}
60
61
62
bool
63
SUMOPolygon::getFill() const {
64
return myFill;
65
}
66
67
68
double
69
SUMOPolygon::getLineWidth() const {
70
return myLineWidth;
71
}
72
73
74
void
75
SUMOPolygon::setFill(bool fill) {
76
myFill = fill;
77
}
78
79
80
void
81
SUMOPolygon::setLineWidth(double lineWidth) {
82
myLineWidth = lineWidth;
83
}
84
85
86
void
87
SUMOPolygon::setShape(const PositionVector& shape) {
88
myShape = shape;
89
}
90
91
void
92
SUMOPolygon::setHoles(const std::vector<PositionVector>& holes) {
93
myHoles = holes;
94
}
95
96
97
void
98
SUMOPolygon::writeXML(OutputDevice& out, bool geo) const {
99
out.openTag(SUMO_TAG_POLY);
100
out.writeAttr(SUMO_ATTR_ID, StringUtils::escapeXML(getID()));
101
if (getShapeType().size() > 0) {
102
out.writeAttr(SUMO_ATTR_TYPE, StringUtils::escapeXML(getShapeType()));
103
}
104
out.writeAttr(SUMO_ATTR_COLOR, getShapeColor());
105
out.writeAttr(SUMO_ATTR_FILL, getFill());
106
if (getLineWidth() != 1) {
107
out.writeAttr(SUMO_ATTR_LINEWIDTH, getLineWidth());
108
}
109
out.writeAttr(SUMO_ATTR_LAYER, getShapeLayer());
110
if (!getShapeName().empty()) {
111
out.writeAttr(SUMO_ATTR_NAME, getShapeName());
112
}
113
PositionVector shape = getShape();
114
if (geo) {
115
out.writeAttr(SUMO_ATTR_GEO, true);
116
for (int i = 0; i < (int) shape.size(); i++) {
117
GeoConvHelper::getFinal().cartesian2geo(shape[i]);
118
}
119
}
120
out.setPrecision(gPrecisionGeo);
121
out.writeAttr(SUMO_ATTR_SHAPE, shape);
122
out.setPrecision();
123
if (getShapeNaviDegree() != Shape::DEFAULT_ANGLE) {
124
out.writeAttr(SUMO_ATTR_ANGLE, getShapeNaviDegree());
125
}
126
if (getShapeImgFile() != Shape::DEFAULT_IMG_FILE) {
127
out.writeAttr(SUMO_ATTR_IMGFILE, getShapeImgFile());
128
}
129
writeParams(out);
130
out.closeTag();
131
}
132
133
134
/****************************************************************************/
135
136