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-2018 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 /****************************************************************************/
17 // A 2D-polygon
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
29 #include "SUMOPolygon.h"
30 
31 
32 // ===========================================================================
33 // member definitions
34 // ===========================================================================
35 SUMOPolygon::SUMOPolygon(const std::string& id, const std::string& type,
36  const RGBColor& color, const PositionVector& shape, bool geo, bool fill, double lineWidth,
37  double layer, double angle, const std::string& imgFile, bool relativePath) :
38  Shape(id, type, color, layer, angle, imgFile, relativePath),
39  myShape(shape),
40  myGEO(geo),
41  myFill(fill),
42  myLineWidth(lineWidth)
43 {
44 }
45 
46 
48 
49 
50 void
54  if (getShapeType().size() > 0) {
56  }
59  if (getLineWidth() != 1) {
61  }
63  PositionVector shape = getShape();
64  if (geo) {
65  out.writeAttr(SUMO_ATTR_GEO, true);
66  for (int i = 0; i < (int) shape.size(); i++) {
68  }
69  }
71  out.writeAttr(SUMO_ATTR_SHAPE, shape);
72  out.setPrecision();
75  }
77  if (getShapeRelativePath()) {
78  // write only the file name, without file path
79  std::string file = getShapeImgFile();
80  file.erase(0, FileHelpers::getFilePath(getShapeImgFile()).size());
81  out.writeAttr(SUMO_ATTR_IMGFILE, file);
82  } else {
84  }
85  }
86  writeParams(out);
87  out.closeTag();
88 }
89 
90 
91 /****************************************************************************/
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
static const std::string DEFAULT_IMG_FILE
Definition: Shape.h:48
const std::string & getShapeImgFile() const
Returns the imgFile of the Shape.
Definition: Shape.h:104
A layer number.
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
const PositionVector & getShape() const
Returns whether the shape of the polygon.
Definition: SUMOPolygon.h:81
const std::string & getID() const
Returns the id.
Definition: Named.h:78
virtual ~SUMOPolygon()
Destructor.
Definition: SUMOPolygon.cpp:47
double getLineWidth() const
Returns whether the polygon is filled.
Definition: SUMOPolygon.h:96
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:76
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
bool getShapeRelativePath() const
Returns the relativePath of the Shape.
Definition: Shape.h:111
int gPrecisionGeo
Definition: StdDefs.cpp:28
A list of positions.
const RGBColor & getShapeColor() const
Returns the color of the Shape.
Definition: Shape.h:83
A 2D- or 3D-Shape.
Definition: Shape.h:39
edge: the shape in xml-definition
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:35
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
bool getFill() const
Returns whether the polygon is filled.
Definition: SUMOPolygon.h:89
double getShapeLayer() const
Returns the layer of the Shape.
Definition: Shape.h:90
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
void writeXML(OutputDevice &out, bool geo=false)
Definition: SUMOPolygon.cpp:51
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static std::string getFilePath(const std::string &path)
Removes the file information from the given path.
Definition: FileHelpers.cpp:65
A color information.
Fill the polygon.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
double getShapeNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition: Shape.h:97
static const double DEFAULT_ANGLE
Definition: Shape.h:47
begin/end of the description of a polygon