LCOV - code coverage report
Current view: top level - src/utils/shapes - PointOfInterest.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 52 72 72.2 %
Date: 2024-05-05 15:31:14 Functions: 9 14 64.3 %

          Line data    Source code
       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             : /****************************************************************************/
      14             : /// @file    PointOfInterest.cpp
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Jakob Erdmann
      17             : /// @author  Michael Behrisch
      18             : /// @author  Melanie Knocke
      19             : /// @date    2005-09-15
      20             : ///
      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       18810 : 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       18810 :                                  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       18810 :     myGeo(geo),
      40       18810 :     myLane(lane),
      41       18810 :     myPosOverLane(posOverLane),
      42       18810 :     myFriendlyPos(friendlyPos),
      43       18810 :     myPosLat(posLat),
      44       18810 :     myIcon(SUMOXMLDefinitions::POIIcons.get(icon)),
      45       18810 :     myHalfImgWidth(width / 2.0),
      46       18810 :     myHalfImgHeight(height / 2.0) {
      47       18810 : }
      48             : 
      49             : 
      50       36271 : PointOfInterest::~PointOfInterest() {}
      51             : 
      52             : 
      53             : POIIcon
      54       64756 : PointOfInterest::getIcon() const {
      55       64756 :     return myIcon;
      56             : }
      57             : 
      58             : 
      59             : const std::string&
      60           0 : PointOfInterest::getIconStr() const {
      61           0 :     return SUMOXMLDefinitions::POIIcons.getString(myIcon);
      62             : }
      63             : 
      64             : 
      65             : double
      66       58894 : PointOfInterest::getWidth() const {
      67       58894 :     return myHalfImgWidth * 2.0;
      68             : }
      69             : 
      70             : 
      71             : double
      72       58894 : PointOfInterest::getHeight() const {
      73       58894 :     return myHalfImgHeight * 2.0;
      74             : }
      75             : 
      76             : 
      77             : Position
      78           0 : PointOfInterest::getCenter() const {
      79           0 :     return { x() + myHalfImgWidth, y() + myHalfImgHeight };
      80             : }
      81             : 
      82             : 
      83             : bool
      84           0 : PointOfInterest::getFriendlyPos() const {
      85           0 :     return myFriendlyPos;
      86             : }
      87             : 
      88             : 
      89             : void
      90           0 : PointOfInterest::setIcon(const std::string& icon) {
      91           0 :     myIcon = SUMOXMLDefinitions::POIIcons.get(icon);
      92           0 : }
      93             : 
      94             : 
      95             : void
      96           6 : PointOfInterest::setWidth(double width) {
      97           6 :     myHalfImgWidth = width / 2.0;
      98           6 : }
      99             : 
     100             : 
     101             : void
     102           6 : PointOfInterest::setHeight(double height) {
     103           6 :     myHalfImgHeight = height / 2.0;
     104           6 : }
     105             : 
     106             : 
     107             : void
     108           0 : PointOfInterest::setFriendlyPos(const bool friendlyPos) {
     109           0 :     myFriendlyPos = friendlyPos;
     110           0 : }
     111             : 
     112             : 
     113             : void
     114        5508 : 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        5508 :     out.openTag(SUMO_TAG_POI);
     117       11016 :     out.writeAttr(SUMO_ATTR_ID, StringUtils::escapeXML(getID()));
     118        5508 :     if (getShapeType().size() > 0) {
     119       11016 :         out.writeAttr(SUMO_ATTR_TYPE, StringUtils::escapeXML(getShapeType()));
     120             :     }
     121        5508 :     if (myIcon != POIIcon::NONE) {
     122           0 :         out.writeAttr(SUMO_ATTR_ICON, SUMOXMLDefinitions::POIIcons.getString(myIcon));
     123             :     }
     124             :     out.writeAttr(SUMO_ATTR_COLOR, getShapeColor());
     125       11016 :     out.writeAttr(SUMO_ATTR_LAYER, getShapeLayer() + zOffset);
     126        5508 :     if (!getShapeName().empty()) {
     127           0 :         out.writeAttr(SUMO_ATTR_NAME, getShapeName());
     128             :     }
     129        5508 :     if (laneID != "") {
     130             :         out.writeAttr(SUMO_ATTR_LANE, laneID);
     131             :         out.writeAttr(SUMO_ATTR_POSITION, pos);
     132           1 :         if (posLat != 0) {
     133             :             out.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
     134             :         }
     135           1 :         if (friendlyPos) {
     136             :             out.writeAttr(SUMO_ATTR_FRIENDLY_POS, friendlyPos);
     137             :         }
     138             :     } else {
     139        5507 :         if (geo) {
     140          43 :             Position POICartesianPos(*this);
     141          43 :             GeoConvHelper::getFinal().cartesian2geo(POICartesianPos);
     142          43 :             out.setPrecision(gPrecisionGeo);
     143          86 :             out.writeAttr(SUMO_ATTR_LON, POICartesianPos.x());
     144          43 :             out.writeAttr(SUMO_ATTR_LAT, POICartesianPos.y());
     145          43 :             out.setPrecision();
     146             :         } else {
     147       10928 :             out.writeAttr(SUMO_ATTR_X, x());
     148       10928 :             out.writeAttr(SUMO_ATTR_Y, y());
     149             :         }
     150        5507 :         if (z() != 0.) {
     151           0 :             out.writeAttr(SUMO_ATTR_Z, z());
     152             :         }
     153             :     }
     154        5508 :     if (getShapeNaviDegree() != Shape::DEFAULT_ANGLE) {
     155           0 :         out.writeAttr(SUMO_ATTR_ANGLE, getShapeNaviDegree());
     156             :     }
     157        5508 :     if (getShapeImgFile() != Shape::DEFAULT_IMG_FILE) {
     158           0 :         if (getShapeRelativePath()) {
     159             :             // write only the file name, without file path
     160             :             std::string file = getShapeImgFile();
     161           0 :             file.erase(0, FileHelpers::getFilePath(getShapeImgFile()).size());
     162             :             out.writeAttr(SUMO_ATTR_IMGFILE, file);
     163             :         } else {
     164             :             out.writeAttr(SUMO_ATTR_IMGFILE, getShapeImgFile());
     165             :         }
     166             :     }
     167        5508 :     if (getWidth() != Shape::DEFAULT_IMG_WIDTH) {
     168           0 :         out.writeAttr(SUMO_ATTR_WIDTH, getWidth());
     169             :     }
     170        5508 :     if (getHeight() != Shape::DEFAULT_IMG_HEIGHT) {
     171           0 :         out.writeAttr(SUMO_ATTR_HEIGHT, getHeight());
     172             :     }
     173        5508 :     writeParams(out);
     174        5508 :     out.closeTag();
     175        5508 : }
     176             : 
     177             : /****************************************************************************/

Generated by: LCOV version 1.14