LCOV - code coverage report
Current view: top level - src/utils/gui/globjects - GUIGlObject.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 43.8 % 16 7
Test Date: 2024-11-22 15:46:21 Functions: 0.0 % 6 0

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

Generated by: LCOV version 2.0-1