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
28
29#include "SUMOPolygon.h"
30
31// ===========================================================================
32// member definitions
33// ===========================================================================
34
35SUMOPolygon::SUMOPolygon(const std::string& id, const std::string& type, const RGBColor& color,
36 const PositionVector& shape, const bool geo, const bool fill, const double lineWidth,
37 const double layer, const double angle, const std::string& imgFile, const std::string& name,
38 const double height, const Parameterised::Map& parameters) :
39 Shape(id, type, color, layer, angle, imgFile, name),
40 Parameterised(parameters),
41 myShape(shape),
42 myGEO(geo),
43 myFill(fill),
44 myLineWidth(lineWidth),
45 myHeight(height) {
46}
47
48
50
51
52const PositionVector&
54 return myShape;
55}
56
57
62
63
64const std::vector<PositionVector>&
66 return myHoles;
67}
68
69
70bool
72 return myFill;
73}
74
75
76double
78 return myLineWidth;
79}
80
81
82double
84 return myHeight;
85}
86
87
88void
90 myFill = fill;
91}
92
93
94void
95SUMOPolygon::setLineWidth(double lineWidth) {
96 myLineWidth = lineWidth;
97}
98
99
100void
102 myHeight = height;
103}
104
105
106void
108 myShape = shape;
109}
110
111void
112SUMOPolygon::setHoles(const std::vector<PositionVector>& holes) {
113 myHoles = holes;
114}
115
116
117void
118SUMOPolygon::writeXML(OutputDevice& out, bool geo) const {
121 if (getShapeType().size() > 0) {
123 }
128 }
131 }
133 if (!getShapeName().empty()) {
135 }
136 PositionVector shape = getShape();
137 if (geo) {
138 out.writeAttr(SUMO_ATTR_GEO, true);
139 for (int i = 0; i < (int) shape.size(); i++) {
141 }
142 }
144 out.writeAttr(SUMO_ATTR_SHAPE, shape);
145 out.setPrecision();
148 }
151 }
152 writeParams(out);
153 out.closeTag();
154}
155
156/****************************************************************************/
@ 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
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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:38
static const double DEFAULT_HEIGHT
Definition Shape.h:50
static const std::string DEFAULT_IMG_FILE
Definition Shape.h:47
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition Shape.cpp:99
static const double DEFAULT_LINEWIDTH
Definition Shape.h:44
static const double DEFAULT_ANGLE
Definition Shape.h:46
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.