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.org/sumo
3 // Copyright (C) 2004-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // A 2D-polygon
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
28 #include "SUMOPolygon.h"
29 
30 
31 // ===========================================================================
32 // member definitions
33 // ===========================================================================
34 SUMOPolygon::SUMOPolygon(const std::string& id, const std::string& type,
35  const RGBColor& color, const PositionVector& shape, bool geo, bool fill, double lineWidth,
36  double layer, double angle, const std::string& imgFile, bool relativePath) :
37  Shape(id, type, color, layer, angle, imgFile, relativePath),
38  myShape(shape),
39  myGEO(geo),
40  myFill(fill),
41  myLineWidth(lineWidth) {
42 }
43 
44 
46 
47 
48 void
52  if (getShapeType().size() > 0) {
54  }
57  if (getLineWidth() != 1) {
59  }
61  PositionVector shape = getShape();
62  if (geo) {
63  out.writeAttr(SUMO_ATTR_GEO, true);
64  for (int i = 0; i < (int) shape.size(); i++) {
66  }
67  }
69  out.writeAttr(SUMO_ATTR_SHAPE, shape);
70  out.setPrecision();
73  }
75  if (getShapeRelativePath()) {
76  // write only the file name, without file path
77  std::string file = getShapeImgFile();
78  file.erase(0, FileHelpers::getFilePath(getShapeImgFile()).size());
79  out.writeAttr(SUMO_ATTR_IMGFILE, file);
80  } else {
82  }
83  }
84  writeParams(out);
85  out.closeTag();
86 }
87 
88 
89 /****************************************************************************/
SUMO_ATTR_TYPE
Definition: SUMOXMLDefinitions.h:381
SUMO_ATTR_ANGLE
Definition: SUMOXMLDefinitions.h:794
SUMO_ATTR_IMGFILE
Definition: SUMOXMLDefinitions.h:792
SUMO_TAG_POLY
begin/end of the description of a polygon
Definition: SUMOXMLDefinitions.h:57
SUMOPolygon::writeXML
void writeXML(OutputDevice &out, bool geo=false)
Definition: SUMOPolygon.cpp:49
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
Shape::getShapeNaviDegree
double getShapeNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition: Shape.h:96
OutputDevice::setPrecision
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
Definition: OutputDevice.cpp:221
GeoConvHelper.h
SUMO_ATTR_COLOR
A color information.
Definition: SUMOXMLDefinitions.h:704
Shape::getShapeImgFile
const std::string & getShapeImgFile() const
Returns the imgFile of the Shape.
Definition: Shape.h:103
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
PositionVector
A list of positions.
Definition: PositionVector.h:45
Shape::getShapeColor
const RGBColor & getShapeColor() const
Returns the color of the Shape.
Definition: Shape.h:82
gPrecisionGeo
int gPrecisionGeo
Definition: StdDefs.cpp:27
Parameterised::writeParams
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
Definition: Parameterised.cpp:154
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
FileHelpers::getFilePath
static std::string getFilePath(const std::string &path)
Removes the file information from the given path.
Definition: FileHelpers.cpp:76
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
RGBColor
Definition: RGBColor.h:39
SUMO_ATTR_LINEWIDTH
Definition: SUMOXMLDefinitions.h:715
Shape::getShapeLayer
double getShapeLayer() const
Returns the layer of the Shape.
Definition: Shape.h:89
GeoConvHelper::getFinal
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
Definition: GeoConvHelper.h:105
StringUtils::escapeXML
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
Definition: StringUtils.cpp:190
SUMO_ATTR_LAYER
A layer number.
Definition: SUMOXMLDefinitions.h:712
OutputDevice.h
GeoConvHelper::cartesian2geo
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
Definition: GeoConvHelper.cpp:293
Shape::getShapeType
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:75
Shape
A 2D- or 3D-Shape.
Definition: Shape.h:38
Shape::getShapeRelativePath
bool getShapeRelativePath() const
Returns the relativePath of the Shape.
Definition: Shape.h:110
SUMOPolygon::getShape
const PositionVector & getShape() const
Returns whether the shape of the polygon.
Definition: SUMOPolygon.h:81
SUMO_ATTR_FILL
Fill the polygon.
Definition: SUMOXMLDefinitions.h:714
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
StringUtils.h
Shape::DEFAULT_ANGLE
static const double DEFAULT_ANGLE
Definition: Shape.h:46
config.h
SUMOPolygon::getFill
bool getFill() const
Returns whether the polygon is filled.
Definition: SUMOPolygon.h:89
Shape::DEFAULT_IMG_FILE
static const std::string DEFAULT_IMG_FILE
Definition: Shape.h:47
SUMOPolygon.h
SUMO_ATTR_SHAPE
edge: the shape in xml-definition
Definition: SUMOXMLDefinitions.h:690
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
SUMO_ATTR_GEO
Definition: SUMOXMLDefinitions.h:816
SUMOPolygon::~SUMOPolygon
virtual ~SUMOPolygon()
Destructor.
Definition: SUMOPolygon.cpp:45
SUMOPolygon::SUMOPolygon
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)
Constructor.
Definition: SUMOPolygon.cpp:34
SUMOPolygon::getLineWidth
double getLineWidth() const
Returns whether the polygon is filled.
Definition: SUMOPolygon.h:96