LCOV - code coverage report
Current view: top level - src/utils/gui/globjects - GUIGlObject.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 40.9 % 22 9
Test Date: 2026-05-24 16:29:35 Functions: 11.1 % 9 1

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2026 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    GUIGlObject.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @author  Laura Bieker
      19              : /// @date    Oct 2002
      20              : ///
      21              : // Base class for all objects that may be displayed within the openGL-gui
      22              : /****************************************************************************/
      23              : #pragma once
      24              : #include <config.h>
      25              : 
      26              : #include <string>
      27              : #include <set>
      28              : 
      29              : #include <utils/geom/Boundary.h>
      30              : #include <utils/common/StdDefs.h>
      31              : #include <utils/common/StringUtils.h>
      32              : #include <utils/common/StringBijection.h>
      33              : #include <utils/common/RGBColor.h>
      34              : #include <utils/foxtools/fxheader.h>
      35              : #include <utils/xml/SUMOXMLDefinitions.h>
      36              : 
      37              : #include "GUIGlObjectTypes.h"
      38              : 
      39              : 
      40              : // ===========================================================================
      41              : // definitions
      42              : // ===========================================================================
      43              : 
      44              : typedef unsigned int GUIGlID;
      45              : 
      46              : // ===========================================================================
      47              : // class declarations
      48              : // ===========================================================================
      49              : 
      50              : class GUIGlObjectStorage;
      51              : class GUIParameterTableWindow;
      52              : class GUIMainWindow;
      53              : class GUIGLObjectPopupMenu;
      54              : class GUISUMOAbstractView;
      55              : class GUIVisualizationSettings;
      56              : struct GUIVisualizationTextSettings;
      57              : 
      58              : #ifdef HAVE_OSG
      59              : namespace osg {
      60              : class Node;
      61              : }
      62              : #endif
      63              : 
      64              : // ===========================================================================
      65              : // class definitions
      66              : // ===========================================================================
      67              : 
      68              : class GUIGlObject {
      69              : 
      70              : public:
      71              :     /// @brief associates object types with strings
      72              :     static StringBijection<GUIGlObjectType> TypeNames;
      73              :     static const GUIGlID INVALID_ID;
      74              :     static const double INVALID_PRIORITY;
      75              : 
      76              :     /** @brief Constructor
      77              :      *
      78              :      * This is the standard constructor that assures that the object is known
      79              :      *  and its id is unique. Use it always :-)
      80              :      *
      81              :      * @param[in] type The GUIGlObjectType type
      82              :      * @param[in] microsimID unique ID
      83              :      * @param[in] icon optional icon associated with this GUIGLObject
      84              :      * @see GUIGlObjectStorage
      85              :      */
      86              :     GUIGlObject(GUIGlObjectType type, const std::string& microsimID, FXIcon* icon);
      87              : 
      88              :     /// @brief Destructor
      89              :     virtual ~GUIGlObject();
      90              : 
      91              :     /// @name getter methods
      92              :     /// @{
      93              :     /// @brief Returns the full name appearing in the tool tip
      94              :     /// @return This object's typed id
      95              :     inline const std::string& getFullName() const {
      96      3888206 :         return myFullName;
      97              :     }
      98              : 
      99              :     /// @brief Returns the name of the parent object (if any)
     100              :     /// @return This object's parent id
     101              :     virtual std::string getParentName() const;
     102              : 
     103              :     /// @brief Returns the numerical id of the object
     104              :     /// @return This object's gl-id
     105              :     inline GUIGlID getGlID() const {
     106    206972815 :         return myGlID;
     107              :     }
     108              : 
     109              :     /// @brief get icon associated with this GL Object
     110              :     FXIcon* getGLIcon() const;
     111              : 
     112              :     /// @}
     113              : 
     114              :     /// @name interfaces to be implemented by derived classes
     115              :     /// @{
     116              :     /** @brief Returns an own popup-menu
     117              :      *
     118              :      * @param[in] app The application needed to build the popup-menu
     119              :      * @param[in] parent The parent window needed to build the popup-menu
     120              :      * @return The built popup-menu
     121              :      */
     122              :     virtual GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0;
     123              : 
     124              :     /// @brief notify object about popup menu removal
     125            0 :     virtual void removedPopupMenu() {}
     126              : 
     127              :     /** @brief Returns an own parameter window
     128              :      *
     129              :      * @param[in] app The application needed to build the parameter window
     130              :      * @param[in] parent The parent window needed to build the parameter window
     131              :      * @return The built parameter window
     132              :      */
     133              :     virtual GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0;
     134              : 
     135              :     /** @brief Returns an own type parameter window (optional)
     136              :      *
     137              :      * @param[in] app The application needed to build the parameter window
     138              :      * @param[in] parent The parent window needed to build the parameter window
     139              :      * @return The built parameter window
     140              :      */
     141              :     virtual GUIParameterTableWindow* getTypeParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent);
     142              : 
     143              :     /// @brief Returns the id of the object as known to microsim
     144              :     inline const std::string& getMicrosimID() const {
     145         4724 :         return myMicrosimID;
     146              :     }
     147              : 
     148              :     /// @brief Returns the name of the object (default "")
     149              :     virtual const std::string getOptionalName() const;
     150              : 
     151              :     /// @brief Changes the microsimID of the object
     152              :     /// @note happens in netedit
     153              :     virtual void setMicrosimID(const std::string& newID);
     154              : 
     155              :     /// @brief Returns the type of the object as coded in GUIGlObjectType
     156              :     /// @see GUIGlObjectType
     157              :     inline GUIGlObjectType getType() const {
     158    143987212 :         return myGLObjectType;
     159              :     }
     160              : 
     161              :     /// @brief Returns the priority of receiving mouse clicks
     162            0 :     virtual double getClickPriority() const {
     163            0 :         return (double)myGLObjectType;
     164              :     }
     165              : 
     166              :     /// @brief get blocking status
     167              :     inline bool isBlocked() const {
     168      1938233 :         return myAmBlocked;
     169              :     }
     170              : 
     171              :     /// @brief set blocking status
     172              :     inline void setBlocked(const bool state = true) {
     173        31155 :         myAmBlocked = state;
     174        31134 :     }
     175              : 
     176              :     /// @brief return exaggeration associated with this GLObject
     177            0 :     virtual double getExaggeration(const GUIVisualizationSettings& s) const {
     178              :         UNUSED_PARAMETER(s);
     179            0 :         return 1.;
     180              :     }
     181              : 
     182              :     //// @brief Returns the boundary to which the view shall be centered in order to show the object
     183              :     virtual Boundary getCenteringBoundary() const = 0;
     184              : 
     185            0 :     virtual Position getCenter() const {
     186            0 :         return getCenteringBoundary().getCenter();
     187              :     }
     188              : 
     189              :     /// @brief return individual scaling factor for this object
     190      9221130 :     virtual double getScaleVisual() const {
     191      9221130 :         return 1;
     192              :     }
     193              : 
     194              :     /// @brief Draws the object
     195              :     /// @param[in] s The settings for the current view (may influence drawing)
     196              :     virtual void drawGL(const GUIVisualizationSettings& s) const = 0;
     197              : 
     198              :     /// @brief check if element is locked (Currently used only in netedit)
     199              :     virtual bool isGLObjectLocked() const;
     200              : 
     201              :     /// @brief mark element as front element (Currently used only in netedit)
     202              :     virtual void markAsFrontElement();
     203              : 
     204              :     /// @brief delete GLObject (Currently used only in netedit)
     205              :     virtual void deleteGLObject();
     206              : 
     207              :     /// @brief select GLObject (Currently used only in netedit)
     208              :     virtual void selectGLObject();
     209              : 
     210              :     /// @brief update GLObject (geometry, ID, etc.) (optional)
     211              :     virtual void updateGLObject();
     212              : 
     213              :     /// @brief check if object is visible (Currently used only in netedit)
     214            0 :     virtual bool isVisible(const GUIVisualizationSettings& /*s*/) const {
     215            0 :         return true;
     216              :     }
     217              : 
     218            0 :     virtual double getColorValue(const GUIVisualizationSettings& /*s*/, int /*activeScheme*/) const {
     219            0 :         return 0;
     220              :     }
     221              :     /// @}
     222              : 
     223              :     /** @brief Draws additional, user-triggered visualisations
     224              :      * @param[in] parent The view
     225              :      * @param[in] s The settings for the current view (may influence drawing)
     226              :      */
     227              :     virtual void drawGLAdditional(GUISUMOAbstractView* const parent, const GUIVisualizationSettings& s) const;
     228              : 
     229              :     /// @brief remove additional user-griggered visualisations
     230            0 :     virtual void removeActiveAddVisualisation(GUISUMOAbstractView* const /*parent*/, int /*which*/) {}
     231              : 
     232              :     /// @brief notify object about left click
     233            0 :     virtual void onLeftBtnPress(void* /*data*/) {}
     234              : 
     235              : #ifdef HAVE_OSG
     236              :     /// @brief get OSG Node
     237              :     osg::Node* getNode() const;
     238              : 
     239              :     /// @brief set OSG Node
     240              :     void setNode(osg::Node* node);
     241              : #endif
     242              : 
     243              :     /// @name Parameter table window I/O
     244              :     /// @{
     245              :     /// @brief Lets this object know a parameter window showing the object's values was opened
     246              :     /// @param[in] w The opened parameter window
     247              :     void addParameterTable(GUIParameterTableWindow* w);
     248              : 
     249              :     /// @brief Lets this object know a parameter window showing the object's values was closed
     250              :     /// @param[in] w The closed parameter window
     251              :     void removeParameterTable(GUIParameterTableWindow* w);
     252              :     /// @}
     253              : 
     254              :     /// @brief draw name of item
     255              :     void drawName(const Position& pos, const double scale, const GUIVisualizationTextSettings& settings, const double angle = 0, bool forceShow = false) const;
     256              : 
     257              : protected:
     258              :     /// @name helper methods for building popup-menus
     259              :     /// @{
     260              :     /// @brief build common popup options
     261              :     void buildPopUpMenuCommonOptions(GUIGLObjectPopupMenu* ret, GUIMainWindow& app, GUISUMOAbstractView* parent, const SumoXMLTag tag,
     262              :                                      const bool selected, bool addSeparator = true);
     263              : 
     264              :     /** @brief Builds the header
     265              :      * @param[in, filled] ret The popup menu to add the entry to
     266              :      * @param[in] addSeparator Whether a separator shall be added, too
     267              :      */
     268              :     void buildPopupHeader(GUIGLObjectPopupMenu* ret, GUIMainWindow& app, bool addSeparator = true);
     269              : 
     270              :     /** @brief Builds an entry which allows to center to the object
     271              :      * @param[in, filled] ret The popup menu to add the entry to
     272              :      * @param[in] addSeparator Whether a separator shall be added, too
     273              :      */
     274              :     void buildCenterPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
     275              : 
     276              :     /** @brief Builds entries which allow to copy the name / typed name into the clipboard
     277              :      * @param[in, filled] ret The popup menu to add the entry to
     278              :      * @param[in] addSeparator Whether a separator shall be added, too
     279              :      */
     280              :     void buildNameCopyPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
     281              : 
     282              :     /** @brief Builds an entry which allows to (de)select the object
     283              :      * @param[in, filled] ret The popup menu to add the entry to
     284              :      * @param[in] addSeparator Whether a separator shall be added, too
     285              :      */
     286              :     void buildSelectionPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
     287              : 
     288              :     /** @brief Builds an entry which allows to open the parameter window
     289              :      * @param[in, filled] ret The popup menu to add the entry to
     290              :      * @param[in] addSeparator Whether a separator shall be added, too
     291              :      */
     292              :     void buildShowParamsPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
     293              : 
     294              :     /** @brief Builds an entry which allows to open the type parameter window
     295              :      * @param[in, filled] ret The popup menu to add the entry to
     296              :      * @param[in] addSeparator Whether a separator shall be added, too
     297              :      */
     298              :     void buildShowTypeParamsPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
     299              : 
     300              :     /** @brief Builds an entry which allows to copy the cursor position
     301              :      *   if geo projection is used, also builds an entry for copying the geo-position
     302              :      * @param[in, filled] ret The popup menu to add the entry to
     303              :      * @param[in] addSeparator Whether a separator shall be added, too
     304              :      */
     305              :     void buildPositionCopyEntry(GUIGLObjectPopupMenu* ret, const GUIMainWindow& app, bool addSeparator = true) const;
     306              : 
     307              :     /** @brief Builds an entry which allows to open the manipulator window
     308              :      * @param[in, filled] ret The popup menu to add the entry to
     309              :      * @param[in] addSeparator Whether a separator shall be added, too
     310              :      */
     311              :     void buildShowManipulatorPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
     312              : 
     313              :     /// @}
     314              : 
     315              :     /// @brief build basic shape popup options. Used to unify pop-ups menu in netedit and SUMO-GUI
     316              :     void buildShapePopupOptions(GUIMainWindow& app, GUIGLObjectPopupMenu* ret, const std::string& type);
     317              : 
     318              :     /// @brief build basic additional popup options. Used to unify pop-ups menu in netedit and SUMO-GUI
     319              :     void buildAdditionalsPopupOptions(GUIMainWindow& app, GUIGLObjectPopupMenu* ret, const std::string& type);
     320              : 
     321              :     /// @brief to be called by child class to ensure cleanup in correct order
     322              :     void cleanupOnDestruction();
     323              : 
     324              : private:
     325              :     /// @brief The numerical id of the object
     326              :     const GUIGlID myGlID;
     327              : 
     328              :     /// @brief The type of the object
     329              :     const GUIGlObjectType myGLObjectType;
     330              : 
     331              :     /// @brief ID of GL object
     332              :     std::string myMicrosimID;
     333              : 
     334              :     /// @brief full name of GL Object
     335              :     std::string myFullName;
     336              : 
     337              :     /// @brief icon associatd with this GL Object
     338              :     FXIcon* myIcon;
     339              : 
     340              :     /// @brief whether the object can be deleted
     341              :     bool myAmBlocked = false;
     342              : 
     343              :     /// @brief Parameter table windows which refer to this object
     344              :     std::set<GUIParameterTableWindow*> myParamWindows;
     345              : 
     346              : #ifdef HAVE_OSG
     347              :     /// @brief OSG Node of this GL object
     348              :     osg::Node* myOSGNode = nullptr;
     349              : #endif
     350              : 
     351              :     /// @brief create full name
     352              :     std::string createFullName() const;
     353              : 
     354              :     /// @brief vector for TypeNames Initializer
     355              :     static StringBijection<GUIGlObjectType>::Entry GUIGlObjectTypeNamesInitializer[];
     356              : 
     357              :     /// @brief Invalidated copy constructor.
     358              :     GUIGlObject(const GUIGlObject&) = delete;
     359              : 
     360              :     /// @brief Invalidated assignment operator.
     361              :     GUIGlObject& operator=(const GUIGlObject&) = delete;
     362              : };
        

Generated by: LCOV version 2.0-1