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