Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUIShapeContainer.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-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/****************************************************************************/
20// Storage for geometrical objects extended by mutexes
21/****************************************************************************/
22#include <config.h>
23
24#include "GUIShapeContainer.h"
30
31
32// ===========================================================================
33// method definitions
34// ===========================================================================
36 myVis(vis),
37 myAllowReplacement(false) {
38}
39
40
42
43
44bool
45GUIShapeContainer::addPOI(const std::string& id, const std::string& type, const RGBColor& color, const Position& pos, bool geo,
46 const std::string& lane, double posOverLane, bool friendlyPos, double posLat, const std::string& icon,
47 double layer, double angle, const std::string& imgFile, double width, double height,
48 bool /* ignorePruning */) {
49 GUIPointOfInterest* p = new GUIPointOfInterest(id, type, color, pos, geo, lane, posOverLane, friendlyPos, posLat, icon,
50 layer, angle, imgFile, width, height);
51 FXMutexLock locker(myLock);
52 if (!myPOIs.add(id, p)) {
54 GUIPointOfInterest* oldP = dynamic_cast<GUIPointOfInterest*>(myPOIs.get(id));
56 myPOIs.remove(id);
57 myPOIs.add(id, p);
58 WRITE_WARNINGF(TL("Replacing POI '%'"), id);
59 } else {
60 delete p;
61 return false;
62 }
63 }
65 return true;
66}
67
68
69bool
70GUIShapeContainer::addPolygon(const std::string& id, const std::string& type, const RGBColor& color, double layer,
71 double angle, const std::string& imgFile, const PositionVector& shape, bool geo, bool fill,
72 double lineWidth, bool /* ignorePruning */, const std::string& name) {
73 GUIPolygon* p = new GUIPolygon(id, type, color, shape, geo, fill, lineWidth, layer, angle, imgFile, name);
74 FXMutexLock locker(myLock);
75 if (!myPolygons.add(id, p)) {
77 GUIPolygon* oldP = dynamic_cast<GUIPolygon*>(myPolygons.get(id));
80 myPolygons.add(id, p);
81 WRITE_WARNINGF(TL("Replacing polygon '%'"), id);
82 } else {
83 delete p;
84 return false;
85 }
86 }
87 bool state = myInactivePolygonTypes.empty() || (std::find(myInactivePolygonTypes.begin(), myInactivePolygonTypes.end(), type) == myInactivePolygonTypes.end());
88 p->activate(state);
90 return true;
91}
92
93
96 std::string polyID,
97 SUMOTrafficObject* trackedObject,
98 const std::vector<double>& timeSpan,
99 const std::vector<double>& alphaSpan,
100 bool looped,
101 bool rotate) {
102 PolygonDynamics* pd = ShapeContainer::addPolygonDynamics(simtime, polyID, trackedObject, timeSpan, alphaSpan, looped, rotate);
103 if (pd != nullptr) {
104 pd->setRTree(&myVis);
105 }
106 return pd;
107}
108
109
112 FXMutexLock locker(myLock);
113 GUIPolygon* p = dynamic_cast<GUIPolygon*>(pd->getPolygon());
114 assert(p != nullptr);
117 if (next != 0) {
118 // Update polygon position in RTree
120 }
121 return next;
122}
123
124
125bool
126GUIShapeContainer::removePolygon(const std::string& id, bool useLock) {
127 GUIPolygon* p = dynamic_cast<GUIPolygon*>(myPolygons.get(id));
128 if (p == nullptr) {
129 return false;
130 }
131 FXMutexLock* locker = nullptr;
132 if (useLock) {
133 locker = new FXMutexLock(myLock);
134 }
136 bool succ = ShapeContainer::removePolygon(id);
137 delete locker;
138 return succ;
139}
140
141
142bool
143GUIShapeContainer::removePOI(const std::string& id) {
144 FXMutexLock locker(myLock);
145 GUIPointOfInterest* p = dynamic_cast<GUIPointOfInterest*>(myPOIs.get(id));
146 if (p == nullptr) {
147 return false;
148 }
150 return myPOIs.remove(id);
151}
152
153
154void
155GUIShapeContainer::movePOI(const std::string& id, const Position& pos) {
156 FXMutexLock locker(myLock);
157 GUIPointOfInterest* p = dynamic_cast<GUIPointOfInterest*>(myPOIs.get(id));
158 if (p != nullptr) {
160 static_cast<Position*>(p)->set(pos);
162 }
163}
164
165
166void
167GUIShapeContainer::reshapePolygon(const std::string& id, const PositionVector& shape) {
168 FXMutexLock locker(myLock);
169 GUIPolygon* p = dynamic_cast<GUIPolygon*>(myPolygons.get(id));
170 if (p != nullptr) {
172 p->setShape(shape);
174 }
175}
176
177
178
179std::vector<GUIGlID>
181 FXMutexLock locker(myLock);
182 std::vector<GUIGlID> ret;
183 for (const auto& poi : getPOIs()) {
184 ret.push_back(static_cast<GUIPointOfInterest*>(poi.second)->getGlID());
185 }
186 return ret;
187}
188
189
190std::vector<GUIGlID>
192 FXMutexLock locker(myLock);
193 std::vector<GUIGlID> ret;
194 for (const auto& poly : getPolygons()) {
195 ret.push_back(static_cast<GUIPolygon*>(poly.second)->getGlID());
196 }
197 return ret;
198}
199
200
201void
205
206
207void
208GUIShapeContainer::setInactivePolygonTypes(std::set<std::string> inactivePolygonTypes) {
209 myInactivePolygonTypes = inactivePolygonTypes;
211}
212
213
214void
215GUIShapeContainer::addInactivePolygonTypes(std::set<std::string> inactivePolygonTypes) {
216 myInactivePolygonTypes.insert(inactivePolygonTypes.begin(), inactivePolygonTypes.end());
218}
219
220
221void
222GUIShapeContainer::removeInactivePolygonTypes(std::set<std::string> inactivePolygonTypes) {
223 for (std::string type : inactivePolygonTypes) {
224 myInactivePolygonTypes.erase(type);
225 }
227}
228
229
230void
232 for (auto polygonWithID : myPolygons) {
233 GUIPolygon* polygon = (GUIPolygon*)polygonWithID.second;
234 bool state = std::find(myInactivePolygonTypes.begin(), myInactivePolygonTypes.end(), polygon->getShapeType()) == myInactivePolygonTypes.end();
235 polygon->activate(state);
236 }
237}
238
239/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:288
#define TL(string)
Definition MsgHandler.h:305
GUIGlID getGlID() const
Returns the numerical id of the object.
void activate(bool isActive)
Definition GUIPolygon.h:174
virtual void setShape(const PositionVector &shape) override
set a new shape and update the tesselation
void removeInactivePolygonTypes(std::set< std::string > inactivePolygonTypes)
Remove some polygon types that were deemed as inactive.
void setInactivePolygonTypes(std::set< std::string > inactivePolygonTypes)
Sets polygon types that define which one is active or not.
virtual void movePOI(const std::string &id, const Position &pos) override
Assigns a new position to the named PoI.
virtual bool removePOI(const std::string &id) override
Removes a PoI from the container.
SUMORTree & myVis
The RTree structure to add and remove visualization elements.
virtual bool addPOI(const std::string &id, const std::string &type, const RGBColor &color, const Position &pos, bool geo, const std::string &lane, double posOverLane, bool friendlyPos, double posLat, const std::string &icon, double layer, double angle, const std::string &imgFile, double width, double height, bool ignorePruning=false) override
Builds a POI using the given values and adds it to the container.
virtual ~GUIShapeContainer()
Destructor.
void allowReplacement()
allow replacement
SUMOTime polygonDynamicsUpdate(SUMOTime t, PolygonDynamics *pd) override
Update PolygonDynamics,.
virtual bool addPolygon(const std::string &id, const std::string &type, const RGBColor &color, double layer, double angle, const std::string &imgFile, const PositionVector &shape, bool geo, bool fill, double lineWidth, bool ignorePruning=false, const std::string &name=Shape::DEFAULT_NAME) override
Builds a polygon using the given values and adds it to the container.
std::vector< GUIGlID > getPOIIds() const
Returns the gl-ids of all pois.
std::set< std::string > myInactivePolygonTypes
The polygon types that define the inactive polygons.
std::vector< GUIGlID > getPolygonIDs() const
Returns the gl-ids of all polygons.
virtual bool removePolygon(const std::string &id, bool useLock=true) override
Removes a polygon from the container.
FXMutex myLock
The mutex for adding/removing operations.
GUIShapeContainer(SUMORTree &vis)
Constructor.
void computeActivePolygons(void)
Determine which polygons are active based on their type.
bool myAllowReplacement
whether existing ids shall be replaced
virtual void reshapePolygon(const std::string &id, const PositionVector &shape) override
Assigns a shape to the named polygon.
void addInactivePolygonTypes(std::set< std::string > inactivePolygonTypes)
Adds new polygon types to the set of inactive ones.
PolygonDynamics * addPolygonDynamics(double simtime, std::string polyID, SUMOTrafficObject *trackedObject, const std::vector< double > &timeSpan, const std::vector< double > &alphaSpan, bool looped, bool rotate) override
Adds dynamics to the given Polygon,.
T get(const std::string &id) const
Retrieves an item.
bool remove(const std::string &id, const bool del=true)
Removes an item.
bool add(const std::string &id, T item)
Adds an item.
SUMOPolygon * getPolygon() const
void setRTree(SUMORTree *rtree)
Set the RTree.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
A RT-tree for efficient storing of SUMO's GL-objects.
Definition SUMORTree.h:66
void addAdditionalGLObject(GUIGlObject *o, const double exaggeration=1)
Adds an additional object (detector/shape/trigger) for visualisation.
Definition SUMORTree.h:122
void removeAdditionalGLObject(GUIGlObject *o, const double exaggeration=1)
Removes an additional object (detector/shape/trigger) from being visualised.
Definition SUMORTree.h:158
Representation of a vehicle, person, or container.
virtual SUMOTime polygonDynamicsUpdate(SUMOTime t, PolygonDynamics *pd)
Regular update event for updating polygon dynamics.
virtual bool removePolygon(const std::string &id, bool useLock=true)
Removes a polygon from the container.
const Polygons & getPolygons() const
Returns all polygons.
POIs myPOIs
stored POIs
virtual PolygonDynamics * addPolygonDynamics(double simtime, std::string polyID, SUMOTrafficObject *trackedObject, const std::vector< double > &timeSpan, const std::vector< double > &alphaSpan, bool looped, bool rotate)
Adds dynamics (animation / tracking) to the given polygon.
const POIs & getPOIs() const
Returns all pois.
Polygons myPolygons
stored Polygons
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition Shape.h:75