Path: blob/main/src/utils/gui/globjects/GUIPointOfInterest.cpp
193863 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GUIPointOfInterest.cpp14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date June 200618///19// The GUI-version of a point of interest20/****************************************************************************/2122#include <utils/common/StringTokenizer.h>23#include <utils/gui/div/GUIParameterTableWindow.h>24#include <utils/gui/globjects/GUIGLObjectPopupMenu.h>25#include <utils/gui/div/GUIGlobalSelection.h>26#include <utils/gui/images/GUITextureSubSys.h>27#include <utils/gui/div/GLHelper.h>28#include <utils/gui/globjects/GLIncludes.h>2930#include "GUIPointOfInterest.h"313233// ===========================================================================34// method definitions35// ===========================================================================3637GUIPointOfInterest::GUIPointOfInterest(const std::string& id, const std::string& type, const RGBColor& color, const Position& pos,38bool geo, const std::string& lane, double posOverLane, bool friendlyPos, double posLat,39const std::string& icon, double layer, double angle, const std::string& imgFile,40double width, double height) :41PointOfInterest(id, type, color, pos, geo, lane, posOverLane, friendlyPos, posLat, icon, layer, angle, imgFile, width, height),42GUIGlObject_AbstractAdd(GLO_POI, id,43(lane.size() > 0) ? GUIIconSubSys::getIcon(GUIIcon::POILANE) : geo ? GUIIconSubSys::getIcon(GUIIcon::POIGEO) : GUIIconSubSys::getIcon(GUIIcon::POI)) {44}454647GUIPointOfInterest::~GUIPointOfInterest() {}484950GUIGLObjectPopupMenu*51GUIPointOfInterest::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {52GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);53// build shape header54buildShapePopupOptions(app, ret, getShapeType());55return ret;56}575859GUIParameterTableWindow*60GUIPointOfInterest::getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView&) {61GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);62// add items63ret->mkItem("type", false, getShapeType());64ret->mkItem("icon", false, getIconStr());65ret->mkItem("layer", false, getShapeLayer());66ret->closeBuilding(this);67return ret;68}697071double72GUIPointOfInterest::getExaggeration(const GUIVisualizationSettings& s) const {73return s.poiSize.getExaggeration(s, this);74}757677Boundary78GUIPointOfInterest::getCenteringBoundary() const {79Boundary b;80b.add(x(), y());81if (getShapeImgFile() != DEFAULT_IMG_FILE) {82b.growWidth(myHalfImgWidth);83b.growHeight(myHalfImgHeight);84} else {85b.grow(3);86}87return b;88}899091void92GUIPointOfInterest::drawGL(const GUIVisualizationSettings& s) const {93// check if POI can be drawn94if (checkDraw(s, this)) {95// push name (needed for getGUIGlObjectsUnderCursor(...)96GLHelper::pushName(getGlID());97// draw inner polygon98const double exaggeration = getExaggeration(s);99const double layer = s.poiUseCustomLayer ? s.poiCustomLayer : getShapeLayer();100GLHelper::pushMatrix();101// set POI Color102setPOIColor(s, getShapeColor(), this, false);103// add extra offset z provided by icon to avoid overlapping104glTranslated(x(), y(), layer + (double)getIcon());105glRotated(-getShapeNaviDegree(), 0, 0, 1);106// check if has to be drawn as a circle or with an image107if (getShapeImgFile() != DEFAULT_IMG_FILE) {108int textureID = GUITexturesHelper::getTextureID(getShapeImgFile());109if (textureID > 0) {110GUITexturesHelper::drawTexturedBox(textureID,111getWidth() * -0.5 * exaggeration, getHeight() * -0.5 * exaggeration,112getWidth() * 0.5 * exaggeration, getHeight() * 0.5 * exaggeration);113}114} else {115// fallback if no image is defined116GLHelper::drawFilledCircle(std::max(getWidth(), getHeight()) * 0.5 * exaggeration, s.poiDetail);117// check if draw polygon118if (getIcon() != POIIcon::NONE) {119// translate120glTranslated(0, 0, 0.1);121// rotate122glRotated(180, 0, 0, 1);123// draw texture124GUITexturesHelper::drawTexturedBox(GUITextureSubSys::getPOITexture(getIcon()), exaggeration * 0.8);125}126}127GLHelper::popMatrix();128if (!s.drawForRectangleSelection) {129const Position namePos = *this;130drawName(namePos, s.scale, s.poiName, s.angle);131if (s.poiType.show(this)) {132const Position p = namePos + Position(0, -0.6 * s.poiType.size / s.scale);133GLHelper::drawTextSettings(s.poiType, getShapeType(), p, s.scale, s.angle);134}135if (s.poiText.show(this)) {136GLHelper::pushMatrix();137glTranslated(x(), y(), 0);138std::string value = getParameter(s.poiTextParam, "");139if (value != "") {140auto lines = StringTokenizer(value, StringTokenizer::NEWLINE).getVector();141glRotated(-s.angle, 0, 0, 1);142glTranslated(0, 0.7 * s.poiText.scaledSize(s.scale) * (double)lines.size(), 0);143glRotated(s.angle, 0, 0, 1);144// FONS_ALIGN_LEFT = 1145// FONS_ALIGN_CENTER = 2146// FONS_ALIGN_MIDDLE = 16147const int align = (lines.size() > 1 ? 1 : 2) | 16;148for (std::string& line : lines) {149GLHelper::drawTextSettings(s.poiText, line, Position(0, 0), s.scale, s.angle, GLO_MAX, align);150glRotated(-s.angle, 0, 0, 1);151glTranslated(0, -0.7 * s.poiText.scaledSize(s.scale), 0);152glRotated(s.angle, 0, 0, 1);153}154}155GLHelper::popMatrix();156}157}158// pop name159GLHelper::popName();160}161}162163164bool165GUIPointOfInterest::checkDraw(const GUIVisualizationSettings& s, const GUIGlObject* o) {166// only continue if scale is valid167if (s.scale * (1.3 / 3.0) * o->getExaggeration(s) < s.poiSize.minSize) {168return false;169}170return true;171}172173174void175GUIPointOfInterest::setPOIColor(const GUIVisualizationSettings& s, const RGBColor& shapeColor, const GUIGlObject* o, const bool disableSelectionColor) {176const GUIColorer& c = s.poiColorer;177const int active = c.getActive();178if (s.netedit && active != 1 && gSelected.isSelected(o->getType(), o->getGlID()) && disableSelectionColor) {179// override with special colors (unless the color scheme is based on selection)180GLHelper::setColor(RGBColor(0, 0, 204));181} else if (active == 0) {182GLHelper::setColor(shapeColor);183} else if (active == 1) {184GLHelper::setColor(c.getScheme().getColor(gSelected.isSelected(o->getType(), o->getGlID())));185} else {186GLHelper::setColor(c.getScheme().getColor(0));187}188}189190/****************************************************************************/191192193