Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
SUMOPolygon.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2004-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/****************************************************************************/
20// A 2D-polygon
21/****************************************************************************/
22#include <config.h>
23
29
30#include "SUMOPolygon.h"
31
32// ===========================================================================
33// member definitions
34// ===========================================================================
35
36SUMOPolygon::SUMOPolygon(const std::string& id, const std::string& type, const RGBColor& color,
37 const PositionVector& shape, const bool geo, const bool fill, const double lineWidth,
38 const double layer, const double angle, const std::string& imgFile, const std::string& name,
39 const double height, const Parameterised::Map& parameters) :
40 Shape(id, type, color, layer, angle, imgFile, name),
41 Parameterised(parameters),
42 myShape(shape),
43 myGEO(geo),
44 myFill(fill),
45 myLineWidth(lineWidth),
46 myHeight(height) {
47}
48
49
51
52
53const PositionVector&
55 return myShape;
56}
57
58
63
64
65const std::vector<PositionVector>&
67 return myHoles;
68}
69
70
71bool
73 return myFill;
74}
75
76
77double
79 return myLineWidth;
80}
81
82
83double
85 return myHeight;
86}
87
88
89void
91 myFill = fill;
92}
93
94
95void
96SUMOPolygon::setLineWidth(double lineWidth) {
97 myLineWidth = lineWidth;
98}
99
100
101void
103 myHeight = height;
104}
105
106
107void
109 myShape = shape;
110}
111
112void
113SUMOPolygon::setHoles(const std::vector<PositionVector>& holes) {
114 myHoles = holes;
115}
116
117
118void
119SUMOPolygon::writeXML(OutputDevice& out, bool geo) const {
122 if (getShapeType().size() > 0) {
124 }
129 }
132 }
134 if (!getShapeName().empty()) {
136 }
137 PositionVector shape = getShape();
138 if (geo) {
139 out.writeAttr(SUMO_ATTR_GEO, true);
140 for (int i = 0; i < (int) shape.size(); i++) {
142 }
143 }
145 out.writeAttr(SUMO_ATTR_SHAPE, shape);
146 out.setPrecision();
149 }
152 }
153 XMLHelpers::writeParams(out, *this);
154 out.closeTag();
155}
156
157/****************************************************************************/
@ SUMO_TAG_POLY
begin/end of the description of a polygon
@ SUMO_ATTR_LINEWIDTH
@ SUMO_ATTR_GEO
@ SUMO_ATTR_SHAPE
edge: the shape in xml-definition
@ SUMO_ATTR_FILL
Fill the polygon.
@ SUMO_ATTR_NAME
@ SUMO_ATTR_LAYER
A layer number.
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_HEIGHT
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_IMGFILE
int gPrecisionGeo
Definition StdDefs.cpp:29
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
const std::string & getID() const
Returns the id.
Definition Named.h:73
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
An upper class for objects with additional parameters.
std::map< std::string, std::string > Map
parameters map
A list of positions.
const PositionVector & getShape() const
Returns the shape of the polygon.
SUMOPolygon(const std::string &id, const std::string &type, const RGBColor &color, const PositionVector &shape, const bool geo, const bool fill, const double lineWidth, const double layer=DEFAULT_LAYER, const double angle=DEFAULT_ANGLE, const std::string &imgFile=DEFAULT_IMG_FILE, const std::string &name=DEFAULT_NAME, const double height=DEFAULT_HEIGHT, const Parameterised::Map &parameters=DEFAULT_PARAMETERS)
Constructor.
virtual void setHoles(const std::vector< PositionVector > &holes)
Sets the holes of the polygon.
PositionVector myShape
The positions of the polygon.
double myLineWidth
The line width for drawing an unfilled polygon.
~SUMOPolygon()
Destructor.
void setFill(bool fill)
Sets whether the polygon shall be filled.
double myHeight
The line width for drawing an unfilled polygon.
void setLineWidth(double lineWidth)
set line width
double getLineWidth() const
Returns the line width.
double getHeight() const
Returns the polygon height.
virtual void setShape(const PositionVector &shape)
Sets the shape of the polygon.
void setHeight(double height)
set height
std::vector< PositionVector > myHoles
The collection of the holes of the polygon, each given by a sequence of coodinates.
PositionVector & getShapeRef()
Return the exterior shape of the polygon.
const std::vector< PositionVector > & getHoles() const
Returns the holers of the polygon.
void writeXML(OutputDevice &out, bool geo=false) const
bool myFill
Information whether the polygon has to be filled.
bool getFill() const
Returns whether the polygon is filled.
A 2D- or 3D-Shape.
Definition Shape.h:44
static const double DEFAULT_HEIGHT
Definition Shape.h:56
static const std::string DEFAULT_IMG_FILE
Definition Shape.h:53
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition Shape.cpp:99
static const double DEFAULT_LINEWIDTH
Definition Shape.h:50
static const double DEFAULT_ANGLE
Definition Shape.h:52
double getShapeLayer() const
Returns the layer of the Shape.
Definition Shape.cpp:111
const std::string & getShapeImgFile() const
Returns the imgFile of the Shape.
Definition Shape.cpp:123
const std::string & getShapeName() const
Returns the name of the Shape.
Definition Shape.cpp:129
const RGBColor & getShapeColor() const
Returns the color of the Shape.
Definition Shape.cpp:105
double getShapeNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition Shape.cpp:117
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
static OutputDevice & writeParams(OutputDevice &device, const Parameterised &params)
write the parameters of the given object as param tags