SUMO - Simulation of Urban MObility
Polygon.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A 2D-polygon
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2004-2016 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
36 #include "Polygon.h"
37 using namespace SUMO;
38 
39 #ifdef CHECK_MEMORY_LEAKS
40 #include <foreign/nvwa/debug_new.h>
41 #endif // CHECK_MEMORY_LEAKS
42 
43 
44 // ===========================================================================
45 // member definitions
46 // ===========================================================================
47 Polygon::Polygon(const std::string& id, const std::string& type,
48  const RGBColor& color, const PositionVector& shape, bool fill,
49  SUMOReal layer, SUMOReal angle, const std::string& imgFile) :
50  Shape(id, type, color, layer, angle, imgFile),
51  myShape(shape),
52  myFill(fill) {
53 }
54 
55 
57 
58 
59 void
67  PositionVector shape = getShape();
68  if (geo) {
69  out.writeAttr(SUMO_ATTR_GEO, true);
70  for (int i = 0; i < (int) shape.size(); i++) {
72  }
73  }
74  out.writeAttr(SUMO_ATTR_SHAPE, shape);
77  }
80  }
81  for (std::map<std::string, std::string>::const_iterator j = getMap().begin(); j != getMap().end(); ++j) {
83  out.writeAttr(SUMO_ATTR_KEY, (*j).first);
84  out.writeAttr(SUMO_ATTR_VALUE, (*j).second);
85  out.closeTag();
86  }
87  out.closeTag();
88 }
89 
90 /****************************************************************************/
91 
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
const std::string & getImgFile() const
Returns the imgFile of the Shape.
Definition: Shape.h:101
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
static const std::string DEFAULT_IMG_FILE
Definition: Shape.h:152
A layer number.
const PositionVector & getShape() const
Returns whether the shape of the polygon.
Definition: Polygon.h:82
void writeXML(OutputDevice &out, bool geo=false)
Definition: Polygon.cpp:60
Polygon(const std::string &id, const std::string &type, const RGBColor &color, const PositionVector &shape, bool fill, SUMOReal layer=DEFAULT_LAYER, SUMOReal angle=DEFAULT_ANGLE, const std::string &imgFile=DEFAULT_IMG_FILE)
Constructor.
Definition: Polygon.cpp:47
static std::string escapeXML(const std::string &orig)
Replaces the standard escapes by their XML entities.
const std::map< std::string, std::string > & getMap() const
Returns the inner key/value map.
static const SUMOReal DEFAULT_ANGLE
Definition: Shape.h:151
const std::string & getID() const
Returns the id.
Definition: Named.h:65
A list of positions.
A 2D- or 3D-Shape.
Definition: Shape.h:46
const RGBColor & getColor() const
Returns the color of the Shape.
Definition: Shape.h:79
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
Definition: Polygon.h:43
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:213
SUMOReal getLayer() const
Returns the layer of the Shape.
Definition: Shape.h:87
const std::string & getType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:71
A color information.
bool getFill() const
Returns whether the polygon is filled.
Definition: Polygon.h:90
Fill the polygon.
SUMOReal getNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition: Shape.h:94
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
virtual ~Polygon()
Destructor.
Definition: Polygon.cpp:56