Eclipse SUMO - Simulation of Urban MObility
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-2024 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 SUMOPolygon::SUMOPolygon(const std::string& id, const std::string& type, const RGBColor& color,
35  const PositionVector& shape, bool geo, bool fill,
36  double lineWidth, double layer, double angle, const std::string& imgFile, bool relativePath,
37  const std::string& name, const Parameterised::Map& parameters) :
38  Shape(id, type, color, layer, angle, imgFile, name, relativePath),
39  Parameterised(parameters),
40  myShape(shape),
41  myGEO(geo),
42  myFill(fill),
43  myLineWidth(lineWidth) {
44 }
45 
46 
48 
49 
50 const PositionVector&
52  return myShape;
53 }
54 
55 
56 const std::vector<PositionVector>&
58  return myHoles;
59 }
60 
61 
62 bool
64  return myFill;
65 }
66 
67 
68 double
70  return myLineWidth;
71 }
72 
73 
74 void
76  myFill = fill;
77 }
78 
79 
80 void
81 SUMOPolygon::setLineWidth(double lineWidth) {
82  myLineWidth = lineWidth;
83 }
84 
85 
86 void
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 {
101  if (getShapeType().size() > 0) {
103  }
106  if (getLineWidth() != 1) {
108  }
110  if (!getShapeName().empty()) {
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++) {
118  }
119  }
121  out.writeAttr(SUMO_ATTR_SHAPE, shape);
122  out.setPrecision();
125  }
127  if (getShapeRelativePath()) {
128  // write only the file name, without file path
129  std::string file = getShapeImgFile();
130  file.erase(0, FileHelpers::getFilePath(getShapeImgFile()).size());
131  out.writeAttr(SUMO_ATTR_IMGFILE, file);
132  } else {
134  }
135  }
136  writeParams(out);
137  out.closeTag();
138 }
139 
140 
141 /****************************************************************************/
@ 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_TYPE
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_IMGFILE
int gPrecisionGeo
Definition: StdDefs.cpp:27
static std::string getFilePath(const std::string &path)
Removes the file information from the given path.
Definition: FileHelpers.cpp:83
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
const std::string & getID() const
Returns the id.
Definition: Named.h:74
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
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.
Definition: Parameterised.h:41
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
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.
Definition: SUMOPolygon.cpp:51
SUMOPolygon(const std::string &id, const std::string &type, const RGBColor &color, const PositionVector &shape, bool geo, bool fill, double lineWidth, double layer=DEFAULT_LAYER, double angle=DEFAULT_ANGLE, const std::string &imgFile=DEFAULT_IMG_FILE, bool relativePath=DEFAULT_RELATIVEPATH, const std::string &name=DEFAULT_NAME, const Parameterised::Map &parameters=DEFAULT_PARAMETERS)
Constructor.
Definition: SUMOPolygon.cpp:34
virtual void setHoles(const std::vector< PositionVector > &holes)
Sets the holes of the polygon.
Definition: SUMOPolygon.cpp:92
PositionVector myShape
The positions of the polygon.
Definition: SUMOPolygon.h:136
double myLineWidth
The line width for drawing an unfilled polygon.
Definition: SUMOPolygon.h:148
~SUMOPolygon()
Destructor.
Definition: SUMOPolygon.cpp:47
void setFill(bool fill)
Sets whether the polygon shall be filled.
Definition: SUMOPolygon.cpp:75
void setLineWidth(double lineWidth)
set line width
Definition: SUMOPolygon.cpp:81
double getLineWidth() const
Returns whether the polygon is filled.
Definition: SUMOPolygon.cpp:69
virtual void setShape(const PositionVector &shape)
Sets the shape of the polygon.
Definition: SUMOPolygon.cpp:87
std::vector< PositionVector > myHoles
The collection of the holes of the polygon, each given by a sequence of coodinates.
Definition: SUMOPolygon.h:139
const std::vector< PositionVector > & getHoles() const
Returns the holers of the polygon.
Definition: SUMOPolygon.cpp:57
void writeXML(OutputDevice &out, bool geo=false) const
Definition: SUMOPolygon.cpp:98
bool myFill
Information whether the polygon has to be filled.
Definition: SUMOPolygon.h:145
bool getFill() const
Returns whether the polygon is filled.
Definition: SUMOPolygon.cpp:63
A 2D- or 3D-Shape.
Definition: Shape.h:38
const std::string getShapeName() const
Returns the name of the Shape.
Definition: Shape.h:110
const RGBColor & getShapeColor() const
Returns the color of the Shape.
Definition: Shape.h:84
const std::string & getShapeImgFile() const
Returns the imgFile of the Shape.
Definition: Shape.h:105
bool getShapeRelativePath() const
Returns the relativePath of the Shape.
Definition: Shape.h:117
static const std::string DEFAULT_IMG_FILE
Definition: Shape.h:47
static const double DEFAULT_ANGLE
Definition: Shape.h:46
double getShapeLayer() const
Returns the layer of the Shape.
Definition: Shape.h:91
double getShapeNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition: Shape.h:98
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:77
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.