/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2005-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 ShapeContainer.h14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @author Jakob Erdmann17/// @date 2005-09-1518///19// Storage for geometrical objects, sorted by the layers they are in20/****************************************************************************/21#pragma once22#include <config.h>2324#include <string>25#include <map>26#include <memory>27#include <utils/common/NamedObjectCont.h>28#include "PointOfInterest.h"29#include "SUMOPolygon.h"303132// ===========================================================================33// class declarations34// ===========================================================================35class PolygonDynamics;36class SUMOTrafficObject;37template <class T, class S>38class ParametrisedWrappingCommand;394041// ===========================================================================42// class definitions43// ===========================================================================44/**45* @class ShapeContainer46* @brief Storage for geometrical objects47*/48class ShapeContainer {49public:5051/// @brief containers52typedef NamedObjectCont<SUMOPolygon*> Polygons;53typedef NamedObjectCont<PointOfInterest*> POIs;5455/// @brief Constructor56ShapeContainer();5758/// @brief Destructor59virtual ~ShapeContainer();6061/** @brief Builds a polygon using the given values and adds it to the container62* @param[in] id The name of the polygon63* @param[in] type The (abstract) type of the polygon64* @param[in] color The color of the polygon65* @param[in] layer The layer of the polygon66* @param[in] angle The rotation of the polygon67* @param[in] imgFile The raster image of the polygon68* @param[in] shape The shape of the polygon69* @param[in] geo specify if shape was loaded as GEO coordinate70* @param[in] fill Whether the polygon shall be filled71* @param[in] lineWidth Line width when drawing unfilled polygon72* @return whether the polygon could be added73*/74virtual bool addPolygon(const std::string& id, const std::string& type,75const RGBColor& color, double layer,76double angle, const std::string& imgFile,77const PositionVector& shape, bool geo,78bool fill, double lineWidth, bool ignorePruning = false,79const std::string& name = Shape::DEFAULT_NAME);8081/**82* @brief Adds dynamics (animation / tracking) to the given polygon83* @param polyID ID of the polygon which should become dynamic84* @return true if the operation was successful, false if not.85* @see PolygonDynamics()86*/87virtual PolygonDynamics* addPolygonDynamics(double simtime,88std::string polyID,89SUMOTrafficObject* trackedObject,90const std::vector<double>& timeSpan,91const std::vector<double>& alphaSpan,92bool looped,93bool rotate);9495/**96* @brief Remove dynamics (animation / tracking) for the given polygon97* @param polyID ID of the polygon for which dynamics shall be removed98* @return true if the operation was successful (dynamics existed for the polygon), false if not.99*/100virtual bool removePolygonDynamics(const std::string& polyID);101102/** @brief Builds a POI using the given values and adds it to the container103* @param[in] id The name of the POI104* @param[in] type The (abstract) type of the POI105* @param[in] color The color of the POI106* @param[in] pos The position of the POI107* @param[in[ geo use GEO coordinates (lon/lat)108* @param[in] lane The Lane in which this POI is placed109* @param[in] posOverLane The position over Lane110* @param[in] friendlyPos enable or disable friendly position over lane111* @param[in] posLat The position lateral over Lane112* @param[in] icon The icon of the POI113* @param[in] layer The layer of the POI114* @param[in] angle The rotation of the POI115* @param[in] imgFile The raster image of the POI116* @param[in] width The width of the POI image117* @param[in] height The height of the POI image118* @return whether the poi could be added119*/120virtual bool addPOI(const std::string& id, const std::string& type, const RGBColor& color, const Position& pos, bool geo,121const std::string& lane, double posOverLane, bool friendlyPos, double posLat, const std::string& icon, double layer,122double angle, const std::string& imgFile, double width, double height, bool ignorePruning = false);123124/** @brief Removes a polygon from the container125* @param[in] id The id of the polygon126* @return Whether the polygon could be removed127*/128virtual bool removePolygon(const std::string& id, bool useLock = true);129130/** @brief Removes a PoI from the container131* @param[in] id The id of the PoI132* @return Whether the poi could be removed133*/134virtual bool removePOI(const std::string& id);135136/** @brief Assigns a new position to the named PoI137* @param[in] id The id of the PoI to move138* @param[in] pos The PoI's new position139*/140virtual void movePOI(const std::string& id, const Position& pos);141142/** @brief Assigns a shape to the named polygon143* @param[in] id The id of the polygon to reshape144* @param[in] shape The polygon's new shape145*/146virtual void reshapePolygon(const std::string& id, const PositionVector& shape);147148/// @brief Returns all polygons149inline const Polygons& getPolygons() const {150return myPolygons;151}152153/// @brief Returns all pois154inline const POIs& getPOIs() const {155return myPOIs;156}157158/** @brief Regular update event for updating polygon dynamics159* @param[in] t The time at which the update is called160* @param[in] pd The dynamics to be updated161* @returns zero If dynamics has expired, next update time otherwise162*/163virtual SUMOTime polygonDynamicsUpdate(SUMOTime t, PolygonDynamics* pd);164165/// @brief Register update command (for descheduling at removal)166virtual void addPolygonUpdateCommand(std::string polyID, ParametrisedWrappingCommand<ShapeContainer, PolygonDynamics*>* cmd);167168/// @brief Remove all tracking polygons for the given object169virtual void removeTrackers(std::string objectID);170171/// @brief register highlight of the specified type if the given id172virtual void registerHighlight(const std::string& objectID, const int type, const std::string& polygonID);173174/** @brief Remove all dynamics before quick-loading state */175void clearState();176177protected:178/// @brief add polygon179virtual bool add(SUMOPolygon* poly, bool ignorePruning = false);180181/// @brief add poi182virtual bool add(PointOfInterest* poi, bool ignorePruning = false);183184/** @brief Unschedules the removal and update commands of the given polygon.185* @param[in] id The id of the polygon186*/187virtual void cleanupPolygonDynamics(const std::string& id);188189/// @name Management of highlights. For each type, only one highlight can be active,190/// @see myHighlightPolygons, myHighlightedObjects191/// @{192/// @brief Remove any previously added highlight polygon of the specified type193/// @param[out] toRemove will hold the id of any polygon that was highlighting the given object194virtual void clearHighlight(const std::string& objectID, const int type, std::string& toRemove);195/// @brief Clears all highlight information from the maps when the object leaves the net196/// (Highlight polygons and dynamics are removed via removeTrackers())197virtual void clearHighlights(const std::string& objectID, SUMOPolygon* p);198/// @}199200protected:201/// @brief stored Polygons202Polygons myPolygons;203204/// @brief stored PolygonDynamics205std::map<std::string, PolygonDynamics*> myPolygonDynamics;206207/// @brief maps objects to a map of highlight types to highlighting polygons208std::map<std::string, std::map<int, std::string> > myHighlightPolygons;209/// @brief inverse map to myHighlightPolygons saves the highlighted object for each polygon210std::map<std::string, std::string> myHighlightedObjects;211212/// @brief Information about tracked objects213/// @note Maps tracked object IDs to set of polygons, which are tracking the object.214/// Needed at object removal to cancel tacking (i.e. remove tracking poly).215std::map<const std::string, std::set<const SUMOPolygon*> > myTrackingPolygons;216217/// @brief stored POIs218POIs myPOIs;219220private:221/// @brief Command pointers for scheduled polygon update. Maps PolyID->Command222std::map<const std::string, ParametrisedWrappingCommand<ShapeContainer, PolygonDynamics*>*> myPolygonUpdateCommands;223224};225226227