LCOV - code coverage report
Current view: top level - src/utils/shapes - ShapeContainer.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 2 2
Test Date: 2025-11-13 15:38:19 Functions: - 0 0

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2005-2025 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    ShapeContainer.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @author  Jakob Erdmann
      18              : /// @date    2005-09-15
      19              : ///
      20              : // Storage for geometrical objects, sorted by the layers they are in
      21              : /****************************************************************************/
      22              : #pragma once
      23              : #include <config.h>
      24              : 
      25              : #include <string>
      26              : #include <map>
      27              : #include <memory>
      28              : #include <utils/common/NamedObjectCont.h>
      29              : #include "PointOfInterest.h"
      30              : #include "SUMOPolygon.h"
      31              : 
      32              : 
      33              : // ===========================================================================
      34              : // class declarations
      35              : // ===========================================================================
      36              : class PolygonDynamics;
      37              : class SUMOTrafficObject;
      38              : template <class T, class S>
      39              : class ParametrisedWrappingCommand;
      40              : 
      41              : 
      42              : // ===========================================================================
      43              : // class definitions
      44              : // ===========================================================================
      45              : /**
      46              :  * @class ShapeContainer
      47              :  * @brief Storage for geometrical objects
      48              :  */
      49              : class ShapeContainer {
      50              : public:
      51              : 
      52              :     /// @brief containers
      53              :     typedef NamedObjectCont<SUMOPolygon*> Polygons;
      54              :     typedef NamedObjectCont<PointOfInterest*> POIs;
      55              : 
      56              :     /// @brief Constructor
      57              :     ShapeContainer();
      58              : 
      59              :     /// @brief Destructor
      60              :     virtual ~ShapeContainer();
      61              : 
      62              :     /** @brief Builds a polygon using the given values and adds it to the container
      63              :      * @param[in] id The name of the polygon
      64              :      * @param[in] type The (abstract) type of the polygon
      65              :      * @param[in] color The color of the polygon
      66              :      * @param[in] layer The layer of the polygon
      67              :      * @param[in] angle The rotation of the polygon
      68              :      * @param[in] imgFile The raster image of the polygon
      69              :      * @param[in] shape The shape of the polygon
      70              :      * @param[in] geo specify if shape was loaded as GEO coordinate
      71              :      * @param[in] fill Whether the polygon shall be filled
      72              :      * @param[in] lineWidth Line width when drawing unfilled polygon
      73              :      * @return whether the polygon could be added
      74              :      */
      75              :     virtual bool addPolygon(const std::string& id, const std::string& type,
      76              :                             const RGBColor& color, double layer,
      77              :                             double angle, const std::string& imgFile,
      78              :                             const PositionVector& shape, bool geo,
      79              :                             bool fill, double lineWidth, bool ignorePruning = false,
      80              :                             const std::string& name = Shape::DEFAULT_NAME);
      81              : 
      82              :     /**
      83              :      * @brief Adds dynamics (animation / tracking) to the given polygon
      84              :      * @param polyID ID of the polygon which should become dynamic
      85              :      * @return true if the operation was successful, false if not.
      86              :      * @see PolygonDynamics()
      87              :      */
      88              :     virtual PolygonDynamics* addPolygonDynamics(double simtime,
      89              :             std::string polyID,
      90              :             SUMOTrafficObject* trackedObject,
      91              :             const std::vector<double>& timeSpan,
      92              :             const std::vector<double>& alphaSpan,
      93              :             bool looped,
      94              :             bool rotate);
      95              : 
      96              :     /**
      97              :      * @brief Remove dynamics (animation / tracking) for the given polygon
      98              :      * @param polyID ID of the polygon for which dynamics shall be removed
      99              :      * @return true if the operation was successful (dynamics existed for the polygon), false if not.
     100              :      */
     101              :     virtual bool removePolygonDynamics(const std::string& polyID);
     102              : 
     103              :     /** @brief Builds a POI using the given values and adds it to the container
     104              :      * @param[in] id The name of the POI
     105              :      * @param[in] type The (abstract) type of the POI
     106              :      * @param[in] color The color of the POI
     107              :      * @param[in] pos The position of the POI
     108              :      * @param[in[ geo use GEO coordinates (lon/lat)
     109              :      * @param[in] lane The Lane in which this POI is placed
     110              :      * @param[in] posOverLane The position over Lane
     111              :      * @param[in] friendlyPos enable or disable friendly position over lane
     112              :      * @param[in] posLat The position lateral over Lane
     113              :      * @param[in] icon The icon of the POI
     114              :      * @param[in] layer The layer of the POI
     115              :      * @param[in] angle The rotation of the POI
     116              :      * @param[in] imgFile The raster image of the POI
     117              :      * @param[in] width The width of the POI image
     118              :      * @param[in] height The height of the POI image
     119              :      * @return whether the poi could be added
     120              :      */
     121              :     virtual bool addPOI(const std::string& id, const std::string& type, const RGBColor& color, const Position& pos, bool geo,
     122              :                         const std::string& lane, double posOverLane, bool friendlyPos, double posLat, const std::string& icon, double layer,
     123              :                         double angle, const std::string& imgFile, double width, double height, bool ignorePruning = false);
     124              : 
     125              :     /** @brief Removes a polygon from the container
     126              :      * @param[in] id The id of the polygon
     127              :      * @return Whether the polygon could be removed
     128              :      */
     129              :     virtual bool removePolygon(const std::string& id, bool useLock = true);
     130              : 
     131              :     /** @brief Removes a PoI from the container
     132              :      * @param[in] id The id of the PoI
     133              :      * @return Whether the poi could be removed
     134              :      */
     135              :     virtual bool removePOI(const std::string& id);
     136              : 
     137              :     /** @brief Assigns a new position to the named PoI
     138              :      * @param[in] id The id of the PoI to move
     139              :      * @param[in] pos The PoI's new position
     140              :      */
     141              :     virtual void movePOI(const std::string& id, const Position& pos);
     142              : 
     143              :     /** @brief Assigns a shape to the named polygon
     144              :      * @param[in] id The id of the polygon to reshape
     145              :      * @param[in] shape The polygon's new shape
     146              :      */
     147              :     virtual void reshapePolygon(const std::string& id, const PositionVector& shape);
     148              : 
     149              :     /// @brief Returns all polygons
     150              :     inline const Polygons& getPolygons() const {
     151          571 :         return myPolygons;
     152              :     }
     153              : 
     154              :     /// @brief Returns all pois
     155              :     inline const POIs& getPOIs() const {
     156          356 :         return myPOIs;
     157              :     }
     158              : 
     159              :     /** @brief Regular update event for updating polygon dynamics
     160              :     * @param[in] t  The time at which the update is called
     161              :     * @param[in] pd The dynamics to be updated
     162              :     * @returns zero If dynamics has expired, next update time otherwise
     163              :     */
     164              :     virtual SUMOTime polygonDynamicsUpdate(SUMOTime t, PolygonDynamics* pd);
     165              : 
     166              :     /// @brief Register update command (for descheduling at removal)
     167              :     virtual void addPolygonUpdateCommand(std::string polyID, ParametrisedWrappingCommand<ShapeContainer, PolygonDynamics*>* cmd);
     168              : 
     169              :     /// @brief Remove all tracking polygons for the given object
     170              :     virtual void removeTrackers(std::string objectID);
     171              : 
     172              :     /// @brief register highlight of the specified type if the given id
     173              :     virtual void registerHighlight(const std::string& objectID, const int type, const std::string& polygonID);
     174              : 
     175              :     /** @brief Remove all dynamics before quick-loading state */
     176              :     void clearState();
     177              : 
     178              : protected:
     179              :     /// @brief add polygon
     180              :     virtual bool add(SUMOPolygon* poly, bool ignorePruning = false);
     181              : 
     182              :     /// @brief add poi
     183              :     virtual bool add(PointOfInterest* poi, bool ignorePruning = false);
     184              : 
     185              :     /** @brief Unschedules the removal and update commands of the given polygon.
     186              :     * @param[in] id The id of the polygon
     187              :     */
     188              :     virtual void cleanupPolygonDynamics(const std::string& id);
     189              : 
     190              :     /// @name Management of highlights. For each type, only one highlight can be active,
     191              :     /// @see myHighlightPolygons, myHighlightedObjects
     192              :     /// @{
     193              :     /// @brief Remove any previously added highlight polygon of the specified type
     194              :     /// @param[out] toRemove will hold the id of any polygon that was highlighting the given object
     195              :     virtual void clearHighlight(const std::string& objectID, const int type, std::string& toRemove);
     196              :     /// @brief Clears all highlight information from the maps when the object leaves the net
     197              :     ///        (Highlight polygons and dynamics are removed via removeTrackers())
     198              :     virtual void clearHighlights(const std::string& objectID, SUMOPolygon* p);
     199              :     /// @}
     200              : 
     201              : protected:
     202              :     /// @brief stored Polygons
     203              :     Polygons myPolygons;
     204              : 
     205              :     /// @brief stored PolygonDynamics
     206              :     std::map<std::string, PolygonDynamics*> myPolygonDynamics;
     207              : 
     208              :     /// @brief maps objects to a map of highlight types to highlighting polygons
     209              :     std::map<std::string, std::map<int, std::string> > myHighlightPolygons;
     210              :     /// @brief inverse map to myHighlightPolygons saves the highlighted object for each polygon
     211              :     std::map<std::string, std::string> myHighlightedObjects;
     212              : 
     213              :     /// @brief Information about tracked objects
     214              :     /// @note  Maps tracked object IDs to set of polygons, which are tracking the object.
     215              :     ///        Needed at object removal to cancel tacking (i.e. remove tracking poly).
     216              :     std::map<const std::string, std::set<const SUMOPolygon*> > myTrackingPolygons;
     217              : 
     218              :     /// @brief stored POIs
     219              :     POIs myPOIs;
     220              : 
     221              : private:
     222              :     /// @brief Command pointers for scheduled polygon update. Maps PolyID->Command
     223              :     std::map<const std::string, ParametrisedWrappingCommand<ShapeContainer, PolygonDynamics*>*> myPolygonUpdateCommands;
     224              : 
     225              : };
        

Generated by: LCOV version 2.0-1