LCOV - code coverage report
Current view: top level - src/utils/gui/globjects - GUIPointOfInterest.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 48 86 55.8 %
Date: 2024-05-05 15:31:14 Functions: 9 11 81.8 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2001-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    GUIPointOfInterest.cpp
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Jakob Erdmann
      17             : /// @author  Michael Behrisch
      18             : /// @date    June 2006
      19             : ///
      20             : // The GUI-version of a point of interest
      21             : /****************************************************************************/
      22             : 
      23             : #include <utils/common/StringTokenizer.h>
      24             : #include <utils/gui/div/GUIParameterTableWindow.h>
      25             : #include <utils/gui/globjects/GUIGLObjectPopupMenu.h>
      26             : #include <utils/gui/div/GUIGlobalSelection.h>
      27             : #include <utils/gui/images/GUITextureSubSys.h>
      28             : #include <utils/gui/div/GLHelper.h>
      29             : #include <utils/gui/globjects/GLIncludes.h>
      30             : 
      31             : #include "GUIPointOfInterest.h"
      32             : 
      33             : 
      34             : // ===========================================================================
      35             : // method definitions
      36             : // ===========================================================================
      37             : 
      38        1148 : GUIPointOfInterest::GUIPointOfInterest(const std::string& id, const std::string& type, const RGBColor& color, const Position& pos,
      39             :                                        bool geo, const std::string& lane, double posOverLane, bool friendlyPos, double posLat,
      40             :                                        const std::string& icon, double layer, double angle, const std::string& imgFile,
      41        1148 :                                        bool relativePath, double width, double height) :
      42             :     PointOfInterest(id, type, color, pos, geo, lane, posOverLane, friendlyPos, posLat, icon, layer, angle, imgFile, relativePath, width, height),
      43             :     GUIGlObject_AbstractAdd(GLO_POI, id,
      44        1148 :                             (lane.size() > 0) ? GUIIconSubSys::getIcon(GUIIcon::POILANE) : geo ? GUIIconSubSys::getIcon(GUIIcon::POIGEO) : GUIIconSubSys::getIcon(GUIIcon::POI)) {
      45        1148 : }
      46             : 
      47             : 
      48        1894 : GUIPointOfInterest::~GUIPointOfInterest() {}
      49             : 
      50             : 
      51             : GUIGLObjectPopupMenu*
      52           0 : GUIPointOfInterest::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {
      53           0 :     GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
      54             :     // build shape header
      55           0 :     buildShapePopupOptions(app, ret, getShapeType());
      56           0 :     return ret;
      57             : }
      58             : 
      59             : 
      60             : GUIParameterTableWindow*
      61           0 : GUIPointOfInterest::getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView&) {
      62           0 :     GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
      63             :     // add items
      64           0 :     ret->mkItem("type", false, getShapeType());
      65           0 :     ret->mkItem("icon", false, getIconStr());
      66           0 :     ret->mkItem("layer", false, getShapeLayer());
      67           0 :     ret->closeBuilding(this);
      68           0 :     return ret;
      69             : }
      70             : 
      71             : 
      72             : double
      73      106620 : GUIPointOfInterest::getExaggeration(const GUIVisualizationSettings& s) const {
      74      106620 :     return s.poiSize.getExaggeration(s, this);
      75             : }
      76             : 
      77             : 
      78             : Boundary
      79        1364 : GUIPointOfInterest::getCenteringBoundary() const {
      80        1364 :     Boundary b;
      81        1364 :     b.add(x(), y());
      82        1364 :     if (getShapeImgFile() != DEFAULT_IMG_FILE) {
      83         821 :         b.growWidth(myHalfImgWidth);
      84         821 :         b.growHeight(myHalfImgHeight);
      85             :     } else {
      86         543 :         b.grow(3);
      87             :     }
      88        1364 :     return b;
      89           0 : }
      90             : 
      91             : 
      92             : void
      93       53310 : GUIPointOfInterest::drawGL(const GUIVisualizationSettings& s) const {
      94             :     // check if POI can be drawn
      95       53310 :     if (checkDraw(s, this)) {
      96             :         // push name (needed for getGUIGlObjectsUnderCursor(...)
      97       53310 :         GLHelper::pushName(getGlID());
      98             :         // draw inner polygon
      99      106620 :         drawInnerPOI(s, this, this, false, s.altKeyPressed ? 0 : getShapeLayer(), getWidth(), getHeight());
     100             :         // pop name
     101       53310 :         GLHelper::popName();
     102             :     }
     103       53310 : }
     104             : 
     105             : 
     106             : bool
     107       53310 : GUIPointOfInterest::checkDraw(const GUIVisualizationSettings& s, const GUIGlObject* o) {
     108             :     // only continue if scale is valid
     109       53310 :     if (s.scale * (1.3 / 3.0) * o->getExaggeration(s) < s.poiSize.minSize) {
     110           0 :         return false;
     111             :     }
     112             :     return true;
     113             : }
     114             : 
     115             : 
     116             : void
     117       53310 : GUIPointOfInterest::setColor(const GUIVisualizationSettings& s, const PointOfInterest* POI, const GUIGlObject* o, bool disableSelectionColor) {
     118             :     const GUIColorer& c = s.poiColorer;
     119             :     const int active = c.getActive();
     120       53310 :     if (s.netedit && active != 1 && gSelected.isSelected(o->getType(), o->getGlID()) && disableSelectionColor) {
     121             :         // override with special colors (unless the color scheme is based on selection)
     122           0 :         GLHelper::setColor(RGBColor(0, 0, 204));
     123       53310 :     } else if (active == 0) {
     124       53310 :         GLHelper::setColor(POI->getShapeColor());
     125           0 :     } else if (active == 1) {
     126           0 :         GLHelper::setColor(c.getScheme().getColor(gSelected.isSelected(o->getType(), o->getGlID())));
     127             :     } else {
     128           0 :         GLHelper::setColor(c.getScheme().getColor(0));
     129             :     }
     130       53310 : }
     131             : 
     132             : 
     133             : void
     134       53310 : GUIPointOfInterest::drawInnerPOI(const GUIVisualizationSettings& s, const PointOfInterest* POI, const GUIGlObject* o,
     135             :                                  const bool disableSelectionColor, const double layer, const double width, const double height) {
     136       53310 :     const double exaggeration = o->getExaggeration(s);
     137       53310 :     GLHelper::pushMatrix();
     138       53310 :     setColor(s, POI, o, disableSelectionColor);
     139             :     // add extra offset z provided by icon to avoid overlapping
     140       53310 :     glTranslated(POI->x(), POI->y(), layer + (double)POI->getIcon());
     141       53310 :     glRotated(-POI->getShapeNaviDegree(), 0, 0, 1);
     142             :     // check if has to be drawn as a circle or with an image
     143       53310 :     if (POI->getShapeImgFile() != DEFAULT_IMG_FILE) {
     144       41864 :         int textureID = GUITexturesHelper::getTextureID(POI->getShapeImgFile());
     145       41864 :         if (textureID > 0) {
     146       41862 :             GUITexturesHelper::drawTexturedBox(textureID,
     147             :                                                width * -0.5 * exaggeration, height * -0.5 * exaggeration,
     148       41862 :                                                width * 0.5 * exaggeration,  height * 0.5 * exaggeration);
     149             :         }
     150             :     } else {
     151             :         // fallback if no image is defined
     152       11446 :         GLHelper::drawFilledCircle((double) 1.3 * exaggeration, s.poiDetail);
     153             :         // check if draw polygon
     154       11446 :         if (POI->getIcon() != POIIcon::NONE) {
     155             :             // translate
     156           0 :             glTranslated(0, 0, 0.1);
     157             :             // rotate
     158           0 :             glRotated(180, 0, 0, 1);
     159             :             // draw texture
     160           0 :             GUITexturesHelper::drawTexturedBox(GUITextureSubSys::getPOITexture(POI->getIcon()), exaggeration * 0.8);
     161             :         }
     162             :     }
     163       53310 :     GLHelper::popMatrix();
     164       53310 :     if (!s.drawForRectangleSelection) {
     165       53310 :         const Position namePos = *POI;
     166       53310 :         o->drawName(namePos, s.scale, s.poiName, s.angle);
     167       53310 :         if (s.poiType.show(o)) {
     168           0 :             const Position p = namePos + Position(0, -0.6 * s.poiType.size / s.scale);
     169           0 :             GLHelper::drawTextSettings(s.poiType, POI->getShapeType(), p, s.scale, s.angle);
     170             :         }
     171       53310 :         if (s.poiText.show(o)) {
     172           0 :             GLHelper::pushMatrix();
     173           0 :             glTranslated(POI->x(), POI->y(), 0);
     174           0 :             std::string value = POI->getParameter(s.poiTextParam, "");
     175           0 :             if (value != "") {
     176           0 :                 auto lines = StringTokenizer(value, StringTokenizer::NEWLINE).getVector();
     177           0 :                 glRotated(-s.angle, 0, 0, 1);
     178           0 :                 glTranslated(0, 0.7 * s.poiText.scaledSize(s.scale) * (double)lines.size(), 0);
     179           0 :                 glRotated(s.angle, 0, 0, 1);
     180             :                 // FONS_ALIGN_LEFT = 1
     181             :                 // FONS_ALIGN_CENTER = 2
     182             :                 // FONS_ALIGN_MIDDLE = 16
     183           0 :                 const int align = (lines.size() > 1 ? 1 : 2) | 16;
     184           0 :                 for (std::string& line : lines) {
     185           0 :                     GLHelper::drawTextSettings(s.poiText, line, Position(0, 0), s.scale, s.angle, GLO_MAX, align);
     186           0 :                     glRotated(-s.angle, 0, 0, 1);
     187           0 :                     glTranslated(0, -0.7 * s.poiText.scaledSize(s.scale), 0);
     188           0 :                     glRotated(s.angle, 0, 0, 1);
     189             :                 }
     190           0 :             }
     191           0 :             GLHelper::popMatrix();
     192             :         }
     193             :     }
     194       53310 : }
     195             : 
     196             : 
     197             : /****************************************************************************/

Generated by: LCOV version 1.14