Eclipse SUMO - Simulation of Urban MObility
PointOfInterest.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2005-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 /****************************************************************************/
21 // A point-of-interest (2D)
22 /****************************************************************************/
23 #include <config.h>
24 
25 #include "PointOfInterest.h"
26 
27 
28 // ===========================================================================
29 // member method definitions
30 // ===========================================================================
31 
32 PointOfInterest::PointOfInterest(const std::string& id, const std::string& type, const RGBColor& color, const Position& pos,
33  bool geo, const std::string& lane, double posOverLane, bool friendlyPos, double posLat,
34  const std::string& icon, double layer, double angle, const std::string& imgFile, bool relativePath,
35  double width, double height, const std::string& name, const Parameterised::Map& parameters) :
36  Shape(id, type, color, layer, angle, imgFile, name, relativePath),
37  Position(pos),
38  Parameterised(parameters),
39  myGeo(geo),
40  myLane(lane),
41  myPosOverLane(posOverLane),
42  myFriendlyPos(friendlyPos),
43  myPosLat(posLat),
44  myIcon(SUMOXMLDefinitions::POIIcons.get(icon)),
45  myHalfImgWidth(width / 2.0),
46  myHalfImgHeight(height / 2.0) {
47 }
48 
49 
51 
52 
53 POIIcon
55  return myIcon;
56 }
57 
58 
59 const std::string&
62 }
63 
64 
65 double
67  return myHalfImgWidth * 2.0;
68 }
69 
70 
71 double
73  return myHalfImgHeight * 2.0;
74 }
75 
76 
79  return { x() + myHalfImgWidth, y() + myHalfImgHeight };
80 }
81 
82 
83 bool
85  return myFriendlyPos;
86 }
87 
88 
89 void
90 PointOfInterest::setIcon(const std::string& icon) {
92 }
93 
94 
95 void
97  myHalfImgWidth = width / 2.0;
98 }
99 
100 
101 void
103  myHalfImgHeight = height / 2.0;
104 }
105 
106 
107 void
108 PointOfInterest::setFriendlyPos(const bool friendlyPos) {
109  myFriendlyPos = friendlyPos;
110 }
111 
112 
113 void
114 PointOfInterest::writeXML(OutputDevice& out, const bool geo, const double zOffset, const std::string laneID,
115  const double pos, const bool friendlyPos, const double posLat) const {
116  out.openTag(SUMO_TAG_POI);
118  if (getShapeType().size() > 0) {
120  }
121  if (myIcon != POIIcon::NONE) {
123  }
125  out.writeAttr(SUMO_ATTR_LAYER, getShapeLayer() + zOffset);
126  if (!getShapeName().empty()) {
128  }
129  if (laneID != "") {
130  out.writeAttr(SUMO_ATTR_LANE, laneID);
131  out.writeAttr(SUMO_ATTR_POSITION, pos);
132  if (posLat != 0) {
133  out.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
134  }
135  if (friendlyPos) {
136  out.writeAttr(SUMO_ATTR_FRIENDLY_POS, friendlyPos);
137  }
138  } else {
139  if (geo) {
140  Position POICartesianPos(*this);
141  GeoConvHelper::getFinal().cartesian2geo(POICartesianPos);
143  out.writeAttr(SUMO_ATTR_LON, POICartesianPos.x());
144  out.writeAttr(SUMO_ATTR_LAT, POICartesianPos.y());
145  out.setPrecision();
146  } else {
147  out.writeAttr(SUMO_ATTR_X, x());
148  out.writeAttr(SUMO_ATTR_Y, y());
149  }
150  if (z() != 0.) {
151  out.writeAttr(SUMO_ATTR_Z, z());
152  }
153  }
156  }
158  if (getShapeRelativePath()) {
159  // write only the file name, without file path
160  std::string file = getShapeImgFile();
161  file.erase(0, FileHelpers::getFilePath(getShapeImgFile()).size());
162  out.writeAttr(SUMO_ATTR_IMGFILE, file);
163  } else {
165  }
166  }
169  }
172  }
173  writeParams(out);
174  out.closeTag();
175 }
176 
177 /****************************************************************************/
POIIcon
POI icons.
@ SUMO_TAG_POI
begin/end of the description of a Point of interest
@ SUMO_ATTR_ICON
icon
@ SUMO_ATTR_LANE
@ SUMO_ATTR_LON
@ SUMO_ATTR_Y
@ SUMO_ATTR_Z
@ SUMO_ATTR_X
@ SUMO_ATTR_POSITION_LAT
@ SUMO_ATTR_NAME
@ SUMO_ATTR_LAYER
A layer number.
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_HEIGHT
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_LAT
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_IMGFILE
@ SUMO_ATTR_WIDTH
@ SUMO_ATTR_POSITION
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
PointOfInterest(const std::string &id, const std::string &type, const RGBColor &color, const Position &pos, bool geo, const std::string &lane, double posOverLane, bool friendlyPos, double posLat, const std::string &icon, double layer=DEFAULT_LAYER, double angle=DEFAULT_ANGLE, const std::string &imgFile=DEFAULT_IMG_FILE, bool relativePath=DEFAULT_RELATIVEPATH, double width=DEFAULT_IMG_WIDTH, double height=DEFAULT_IMG_HEIGHT, const std::string &name=DEFAULT_NAME, const Parameterised::Map &parameters=DEFAULT_PARAMETERS)
Constructor.
POIIcon myIcon
POI icon.
POIIcon getIcon() const
get icon
~PointOfInterest()
Destructor.
bool getFriendlyPos() const
returns friendly position
void setHeight(double height)
set the image height of the POI
double myHalfImgHeight
The half height of the image when rendering this POI.
void setFriendlyPos(const bool friendlyPos)
set friendly position
Position getCenter() const
Returns the image center of the POI.
void setWidth(double width)
set the image width of the POI
double getHeight() const
Returns the image height of the POI.
bool myFriendlyPos
friendlyPos enable or disable friendly position for position over lane
void setIcon(const std::string &icon)
set icon
double getWidth() const
Returns the image width of the POI.
const std::string & getIconStr() const
get icon(in string format)
void writeXML(OutputDevice &out, const bool geo=false, const double zOffset=0., const std::string laneID="", const double pos=0., const bool friendlyPos=false, const double posLat=0.) const
double myHalfImgWidth
The half width of the image when rendering this POI.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
double x() const
Returns the x-position.
Definition: Position.h:55
double z() const
Returns the z-position.
Definition: Position.h:65
double y() const
Returns the y-position.
Definition: Position.h:60
class for maintaining associations between enums and xml-strings
static StringBijection< POIIcon > POIIcons
POI icon values.
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
static const double DEFAULT_IMG_WIDTH
Definition: Shape.h:49
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
static const double DEFAULT_IMG_HEIGHT
Definition: Shape.h:50
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
const std::string & getString(const T key) const
T get(const std::string &str) const
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
auto get(const nlohmann::detail::iteration_proxy_value< IteratorType > &i) -> decltype(i.key())
Definition: json.hpp:4451