LCOV - code coverage report
Current view: top level - src/utils/gui/globjects - GUIPolygon.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 38.5 % 13 5
Test Date: 2024-11-22 15:46:21 Functions: 20.0 % 5 1

            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    GUIPolygon.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @date    June 2006
      19              : ///
      20              : // The GUI-version of a polygon
      21              : /****************************************************************************/
      22              : #pragma once
      23              : #include <config.h>
      24              : 
      25              : #include <string>
      26              : #include <utils/shapes/SUMOPolygon.h>
      27              : #include <utils/gui/globjects/GUIGlObject_AbstractAdd.h>
      28              : #include <utils/gui/globjects/GLIncludes.h>
      29              : #include <utils/gui/settings/GUIVisualizationSettings.h>
      30              : 
      31              : 
      32              : // ===========================================================================
      33              : // class definitions
      34              : // ===========================================================================
      35              : 
      36              : /// @brief most likely I'm reinventing the wheel here
      37        18700 : struct GLPrimitive {
      38              :     GLenum type;
      39              :     std::vector<Position> vert;
      40              : };
      41              : 
      42              : 
      43              : class TesselatedPolygon : public SUMOPolygon {
      44              : 
      45              : public:
      46              : 
      47              :     /** @brief Constructor
      48              :      * @param[in] id The name of the polygon
      49              :      * @param[in] type The (abstract) type of the polygon
      50              :      * @param[in] color The color of the polygon
      51              :      * @param[in] layer The layer of the polygon
      52              :      * @param[in] angle The rotation of the polygon
      53              :      * @param[in] imgFile The raster image of the polygon
      54              :      * @param[in] relativePath set image file as relative path
      55              :      * @param[in] shape The shape of the polygon
      56              :      * @param[in] geo specify if shape was loaded as GEO
      57              :      * @param[in] fill Whether the polygon shall be filled
      58              :      * @param[in] lineWidth Line width when drawing unfilled polygon
      59              :      */
      60              :     TesselatedPolygon(const std::string& id, const std::string& type, const RGBColor& color, const PositionVector& shape,
      61              :                       bool geo, bool fill, double lineWidth, double layer = 0, double angle = 0, const std::string& imgFile = "",
      62              :                       bool relativePath = false, const std::string& name = DEFAULT_NAME,
      63        88694 :                       const Parameterised::Map& parameters = DEFAULT_PARAMETERS):
      64        88694 :         SUMOPolygon(id, type, color, shape, geo, fill, lineWidth, layer, angle, imgFile, relativePath, name, parameters)
      65              :     {}
      66              : 
      67              :     /// @brief Destructor
      68        88529 :     ~TesselatedPolygon() {}
      69              : 
      70              :     /// @brief perform the tesselation / drawing
      71              :     void drawTesselation(const PositionVector& shape) const;
      72              : 
      73              :     /// @brief id of the display list for the cached tesselation
      74              :     mutable std::vector<GLPrimitive> myTesselation;
      75              : };
      76              : 
      77              : /*
      78              :  * @class GUIPolygon
      79              :  * @brief The GUI-version of a polygon
      80              :  */
      81              : class GUIPolygon : public TesselatedPolygon, public GUIGlObject_AbstractAdd {
      82              : 
      83              : public:
      84              :     /** @brief Constructor
      85              :      * @param[in] id The name of the polygon
      86              :      * @param[in] type The (abstract) type of the polygon
      87              :      * @param[in] color The color of the polygon
      88              :      * @param[in] layer The layer of the polygon
      89              :      * @param[in] angle The rotation of the polygon
      90              :      * @param[in] imgFile The raster image of the polygon
      91              :      * @param[in] relativePath set image file as relative path
      92              :      * @param[in] shape The shape of the polygon
      93              :      * @param[in] geo specify if shape was loaded as GEO
      94              :      * @param[in] fill Whether the polygon shall be filled
      95              :      * @param[in] lineWidth Line width when drawing unfilled polygon
      96              :      */
      97              :     GUIPolygon(const std::string& id, const std::string& type, const RGBColor& color, const PositionVector& shape,
      98              :                bool geo, bool fill, double lineWidth, double layer = 0, double angle = 0, const std::string& imgFile = "",
      99              :                bool relativePath = false, const std::string& name = DEFAULT_NAME);
     100              : 
     101              :     /// @brief Destructor
     102              :     ~GUIPolygon();
     103              : 
     104              :     /// @name inherited from GUIGlObject
     105              :     //@{
     106              : 
     107              :     /** @brief Returns an own popup-menu
     108              :      *
     109              :      * @param[in] app The application needed to build the popup-menu
     110              :      * @param[in] parent The parent window needed to build the popup-menu
     111              :      * @return The built popup-menu
     112              :      * @see GUIGlObject::getPopUpMenu
     113              :      */
     114              :     GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
     115              : 
     116              :     /** @brief Returns an own parameter window
     117              :      *
     118              :      * @param[in] app The application needed to build the parameter window
     119              :      * @param[in] parent The parent window needed to build the parameter window
     120              :      * @return The built parameter window
     121              :      * @see GUIGlObject::getParameterWindow
     122              :      */
     123              :     GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
     124              : 
     125              :     /// @brief return exaggeration associated with this GLObject
     126              :     double getExaggeration(const GUIVisualizationSettings& s) const override;
     127              : 
     128              :     /** @brief Returns the boundary to which the view shall be centered in order to show the object
     129              :      *
     130              :      * @return The boundary the object is within
     131              :      * @see GUIGlObject::getCenteringBoundary
     132              :      */
     133              :     Boundary getCenteringBoundary() const override;
     134              : 
     135              :     /** @brief Draws the object
     136              :      * @param[in] s The settings for the current view (may influence drawing)
     137              :      * @see GUIGlObject::drawGL
     138              :      */
     139              :     virtual void drawGL(const GUIVisualizationSettings& s) const override;
     140              : 
     141            0 :     double getClickPriority() const override {
     142            0 :         return getShapeLayer();
     143              :     }
     144              : 
     145              :     /// @brief Returns the name of the object (default "")
     146            0 :     virtual const std::string getOptionalName() const override {
     147            0 :         return getShapeName();
     148              :     }
     149              :     //@}
     150              : 
     151              :     /// @brief set a new shape and update the tesselation
     152              :     virtual void setShape(const PositionVector& shape) override;
     153              : 
     154              :     /** @brief Sets a new angle in navigational degrees
     155              :      * @param[in] layer The new angle to use
     156              :      */
     157            0 :     virtual void setShapeNaviDegree(const double angle) override {
     158              :         SUMOPolygon::setShapeNaviDegree(angle);
     159            0 :         if (angle != 0.) {
     160            0 :             setShape(myShape);
     161              :         }
     162            0 :     }
     163              : 
     164              :     /// @brief set color
     165              :     static RGBColor setColor(const GUIVisualizationSettings& s, const SUMOPolygon* polygon, const GUIGlObject* o, bool disableSelectionColor, int alphaOverride);
     166              : 
     167              :     /// @brief check if Polygon can be drawn
     168              :     static bool checkDraw(const GUIVisualizationSettings& s, const SUMOPolygon* polygon, const GUIGlObject* o);
     169              : 
     170              :     /// @brief draw inner Polygon (before pushName() )
     171              :     static void drawInnerPolygon(const GUIVisualizationSettings& s, const TesselatedPolygon* polygon, const GUIGlObject* o,
     172              :                                  const PositionVector shape, const double layer, const bool fill,
     173              :                                  const bool disableSelectionColor = false,
     174              :                                  const int alphaOverride = -1,
     175              :                                  const bool disableText = false);
     176              : 
     177              :     inline void activate(bool isActive) {
     178          109 :         myIsActive = isActive;
     179              :     }
     180              : 
     181              :     inline bool isActive(void) const {
     182              :         return myIsActive;
     183              :     }
     184              : 
     185              : private:
     186              :     /// The mutex used to avoid concurrent updates of the shape
     187              :     mutable FXMutex myLock;
     188              : 
     189              :     /// @brief shape rotated on the centroid, if rotation is needed, nullptr otherwise
     190              :     PositionVector* myRotatedShape;
     191              : 
     192              :     /// @brief Is the polygon will be drawn or not
     193              :     bool myIsActive;
     194              : };
        

Generated by: LCOV version 2.0-1