/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 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 GUIGlObject.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @author Laura Bieker18/// @date Oct 200219///20// Base class for all objects that may be displayed within the openGL-gui21/****************************************************************************/22#pragma once23#include <config.h>2425#include <string>26#include <set>2728#include <utils/geom/Boundary.h>29#include <utils/common/StdDefs.h>30#include <utils/common/StringUtils.h>31#include <utils/common/StringBijection.h>32#include <utils/common/RGBColor.h>33#include <utils/foxtools/fxheader.h>34#include <utils/xml/SUMOXMLDefinitions.h>3536#include "GUIGlObjectTypes.h"373839// ===========================================================================40// definitions41// ===========================================================================4243typedef unsigned int GUIGlID;4445// ===========================================================================46// class declarations47// ===========================================================================4849class GUIGlObjectStorage;50class GUIParameterTableWindow;51class GUIMainWindow;52class GUIGLObjectPopupMenu;53class GUISUMOAbstractView;54class GUIVisualizationSettings;55struct GUIVisualizationTextSettings;5657#ifdef HAVE_OSG58namespace osg {59class Node;60}61#endif6263// ===========================================================================64// class definitions65// ===========================================================================6667class GUIGlObject {6869public:70/// @brief associates object types with strings71static StringBijection<GUIGlObjectType> TypeNames;72static const GUIGlID INVALID_ID;73static const double INVALID_PRIORITY;7475/** @brief Constructor76*77* This is the standard constructor that assures that the object is known78* and its id is unique. Use it always :-)79*80* @param[in] type The GUIGlObjectType type81* @param[in] microsimID unique ID82* @param[in] icon optional icon associated with this GUIGLObject83* @see GUIGlObjectStorage84*/85GUIGlObject(GUIGlObjectType type, const std::string& microsimID, FXIcon* icon);8687/// @brief Destructor88virtual ~GUIGlObject();8990/// @name getter methods91/// @{92/// @brief Returns the full name appearing in the tool tip93/// @return This object's typed id94inline const std::string& getFullName() const {95return myFullName;96}9798/// @brief Returns the name of the parent object (if any)99/// @return This object's parent id100virtual std::string getParentName() const;101102/// @brief Returns the numerical id of the object103/// @return This object's gl-id104inline GUIGlID getGlID() const {105return myGlID;106}107108/// @brief get icon associated with this GL Object109FXIcon* getGLIcon() const;110111/// @}112113/// @name interfaces to be implemented by derived classes114/// @{115/** @brief Returns an own popup-menu116*117* @param[in] app The application needed to build the popup-menu118* @param[in] parent The parent window needed to build the popup-menu119* @return The built popup-menu120*/121virtual GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0;122123/// @brief notify object about popup menu removal124virtual void removedPopupMenu() {}125126/** @brief Returns an own parameter window127*128* @param[in] app The application needed to build the parameter window129* @param[in] parent The parent window needed to build the parameter window130* @return The built parameter window131*/132virtual GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0;133134/** @brief Returns an own type parameter window (optional)135*136* @param[in] app The application needed to build the parameter window137* @param[in] parent The parent window needed to build the parameter window138* @return The built parameter window139*/140virtual GUIParameterTableWindow* getTypeParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent);141142/// @brief Returns the id of the object as known to microsim143inline const std::string& getMicrosimID() const {144return myMicrosimID;145}146147/// @brief Returns the name of the object (default "")148virtual const std::string getOptionalName() const;149150/// @brief Changes the microsimID of the object151/// @note happens in netedit152virtual void setMicrosimID(const std::string& newID);153154/// @brief Returns the type of the object as coded in GUIGlObjectType155/// @see GUIGlObjectType156inline GUIGlObjectType getType() const {157return myGLObjectType;158}159160/// @brief Returns the priority of receiving mouse clicks161virtual double getClickPriority() const {162return (double)myGLObjectType;163}164165/// @brief get blocking status166inline bool isBlocked() const {167return myAmBlocked;168}169170/// @brief set blocking status171inline void setBlocked(const bool state = true) {172myAmBlocked = state;173}174175/// @brief return exaggeration associated with this GLObject176virtual double getExaggeration(const GUIVisualizationSettings& s) const {177UNUSED_PARAMETER(s);178return 1.;179}180181//// @brief Returns the boundary to which the view shall be centered in order to show the object182virtual Boundary getCenteringBoundary() const = 0;183184virtual Position getCenter() const {185return getCenteringBoundary().getCenter();186}187188/// @brief return individual scaling factor for this object189virtual double getScaleVisual() const {190return 1;191}192193/// @brief Draws the object194/// @param[in] s The settings for the current view (may influence drawing)195virtual void drawGL(const GUIVisualizationSettings& s) const = 0;196197/// @brief check if element is locked (Currently used only in netedit)198virtual bool isGLObjectLocked() const;199200/// @brief mark element as front element (Currently used only in netedit)201virtual void markAsFrontElement();202203/// @brief delete GLObject (Currently used only in netedit)204virtual void deleteGLObject();205206/// @brief select GLObject (Currently used only in netedit)207virtual void selectGLObject();208209/// @brief update GLObject (geometry, ID, etc.) (optional)210virtual void updateGLObject();211212virtual double getColorValue(const GUIVisualizationSettings& /*s*/, int /*activeScheme*/) const {213return 0;214}215/// @}216217/** @brief Draws additional, user-triggered visualisations218* @param[in] parent The view219* @param[in] s The settings for the current view (may influence drawing)220*/221virtual void drawGLAdditional(GUISUMOAbstractView* const parent, const GUIVisualizationSettings& s) const;222223/// @brief remove additional user-griggered visualisations224virtual void removeActiveAddVisualisation(GUISUMOAbstractView* const /*parent*/, int /*which*/) {}225226/// @brief notify object about left click227virtual void onLeftBtnPress(void* /*data*/) {}228229#ifdef HAVE_OSG230/// @brief get OSG Node231osg::Node* getNode() const;232233/// @brief set OSG Node234void setNode(osg::Node* node);235#endif236237/// @name Parameter table window I/O238/// @{239/// @brief Lets this object know a parameter window showing the object's values was opened240/// @param[in] w The opened parameter window241void addParameterTable(GUIParameterTableWindow* w);242243/// @brief Lets this object know a parameter window showing the object's values was closed244/// @param[in] w The closed parameter window245void removeParameterTable(GUIParameterTableWindow* w);246/// @}247248/// @brief draw name of item249void drawName(const Position& pos, const double scale, const GUIVisualizationTextSettings& settings, const double angle = 0, bool forceShow = false) const;250251protected:252/// @name helper methods for building popup-menus253/// @{254/// @brief build common popup options255void buildPopUpMenuCommonOptions(GUIGLObjectPopupMenu* ret, GUIMainWindow& app, GUISUMOAbstractView* parent, const SumoXMLTag tag,256const bool selected, bool addSeparator = true);257258/** @brief Builds the header259* @param[in, filled] ret The popup menu to add the entry to260* @param[in] addSeparator Whether a separator shall be added, too261*/262void buildPopupHeader(GUIGLObjectPopupMenu* ret, GUIMainWindow& app, bool addSeparator = true);263264/** @brief Builds an entry which allows to center to the object265* @param[in, filled] ret The popup menu to add the entry to266* @param[in] addSeparator Whether a separator shall be added, too267*/268void buildCenterPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);269270/** @brief Builds entries which allow to copy the name / typed name into the clipboard271* @param[in, filled] ret The popup menu to add the entry to272* @param[in] addSeparator Whether a separator shall be added, too273*/274void buildNameCopyPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);275276/** @brief Builds an entry which allows to (de)select the object277* @param[in, filled] ret The popup menu to add the entry to278* @param[in] addSeparator Whether a separator shall be added, too279*/280void buildSelectionPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);281282/** @brief Builds an entry which allows to open the parameter window283* @param[in, filled] ret The popup menu to add the entry to284* @param[in] addSeparator Whether a separator shall be added, too285*/286void buildShowParamsPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);287288/** @brief Builds an entry which allows to open the type parameter window289* @param[in, filled] ret The popup menu to add the entry to290* @param[in] addSeparator Whether a separator shall be added, too291*/292void buildShowTypeParamsPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);293294/** @brief Builds an entry which allows to copy the cursor position295* if geo projection is used, also builds an entry for copying the geo-position296* @param[in, filled] ret The popup menu to add the entry to297* @param[in] addSeparator Whether a separator shall be added, too298*/299void buildPositionCopyEntry(GUIGLObjectPopupMenu* ret, const GUIMainWindow& app, bool addSeparator = true) const;300301/** @brief Builds an entry which allows to open the manipulator window302* @param[in, filled] ret The popup menu to add the entry to303* @param[in] addSeparator Whether a separator shall be added, too304*/305void buildShowManipulatorPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);306307/// @}308309/// @brief build basic shape popup options. Used to unify pop-ups menu in netedit and SUMO-GUI310void buildShapePopupOptions(GUIMainWindow& app, GUIGLObjectPopupMenu* ret, const std::string& type);311312/// @brief build basic additional popup options. Used to unify pop-ups menu in netedit and SUMO-GUI313void buildAdditionalsPopupOptions(GUIMainWindow& app, GUIGLObjectPopupMenu* ret, const std::string& type);314315private:316/// @brief The numerical id of the object317const GUIGlID myGlID;318319/// @brief The type of the object320const GUIGlObjectType myGLObjectType;321322/// @brief ID of GL object323std::string myMicrosimID;324325/// @brief full name of GL Object326std::string myFullName;327328/// @brief icon associatd with this GL Object329FXIcon* myIcon;330331/// @brief whether the object can be deleted332bool myAmBlocked = false;333334/// @brief Parameter table windows which refer to this object335std::set<GUIParameterTableWindow*> myParamWindows;336337#ifdef HAVE_OSG338/// @brief OSG Node of this GL object339osg::Node* myOSGNode = nullptr;340#endif341342/// @brief create full name343std::string createFullName() const;344345/// @brief vector for TypeNames Initializer346static StringBijection<GUIGlObjectType>::Entry GUIGlObjectTypeNamesInitializer[];347348/// @brief Invalidated copy constructor.349GUIGlObject(const GUIGlObject&) = delete;350351/// @brief Invalidated assignment operator.352GUIGlObject& operator=(const GUIGlObject&) = delete;353};354355356