SUMO - Simulation of Urban MObility
GUIShapeContainer.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Storage for geometrical objects extended by mutexes
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include "GUIShapeContainer.h"
31 
32 
33 // ===========================================================================
34 // method definitions
35 // ===========================================================================
37  myVis(vis),
38  myAllowReplacement(false) {
39 }
40 
41 
43 
44 
45 bool
46 GUIShapeContainer::addPOI(const std::string& id, const std::string& type, const RGBColor& color, const Position& pos, bool geo,
47  const std::string& lane, double posOverLane, double posLat, double layer, double angle,
48  const std::string& imgFile, bool relativePath, double width, double height, bool /* ignorePruning */) {
49  GUIPointOfInterest* p = new GUIPointOfInterest(id, type, color, pos, geo, lane, posOverLane, posLat, layer, angle, imgFile, relativePath, width, height);
51  if (!myPOIs.add(id, p)) {
52  if (myAllowReplacement) {
53  GUIPointOfInterest* oldP = dynamic_cast<GUIPointOfInterest*>(myPOIs.get(id));
55  myPOIs.remove(id);
56  myPOIs.add(id, p);
57  WRITE_WARNING("Replacing POI '" + id + "'");
58  } else {
59  delete p;
60  return false;
61  }
62  }
64  return true;
65 }
66 
67 
68 bool
69 GUIShapeContainer::addPolygon(const std::string& id, const std::string& type,
70  const RGBColor& color, double layer,
71  double angle, const std::string& imgFile, bool relativePath,
72  const PositionVector& shape, bool geo, bool fill, double lineWidth, bool /* ignorePruning */) {
73  GUIPolygon* p = new GUIPolygon(id, type, color, shape, geo, fill, lineWidth, layer, angle, imgFile, relativePath);
75  if (!myPolygons.add(id, p)) {
76  if (myAllowReplacement) {
77  GUIPolygon* oldP = dynamic_cast<GUIPolygon*>(myPolygons.get(id));
79  myPolygons.remove(id);
80  myPolygons.add(id, p);
81  WRITE_WARNING("Replacing polygon '" + id + "'");
82  } else {
83  delete p;
84  return false;
85  }
86  }
88  return true;
89 }
90 
91 
92 bool
93 GUIShapeContainer::removePolygon(const std::string& id) {
95  GUIPolygon* p = dynamic_cast<GUIPolygon*>(myPolygons.get(id));
96  if (p == nullptr) {
97  return false;
98  }
100  return myPolygons.remove(id);
101 }
102 
103 
104 bool
105 GUIShapeContainer::removePOI(const std::string& id) {
107  GUIPointOfInterest* p = dynamic_cast<GUIPointOfInterest*>(myPOIs.get(id));
108  if (p == nullptr) {
109  return false;
110  }
112  return myPOIs.remove(id);
113 }
114 
115 
116 void
117 GUIShapeContainer::movePOI(const std::string& id, const Position& pos) {
119  GUIPointOfInterest* p = dynamic_cast<GUIPointOfInterest*>(myPOIs.get(id));
120  if (p != nullptr) {
122  static_cast<Position*>(p)->set(pos);
124  }
125 }
126 
127 
128 void
129 GUIShapeContainer::reshapePolygon(const std::string& id, const PositionVector& shape) {
131  GUIPolygon* p = dynamic_cast<GUIPolygon*>(myPolygons.get(id));
132  if (p != nullptr) {
134  p->setShape(shape);
136  }
137 }
138 
139 
140 
141 std::vector<GUIGlID>
144  std::vector<GUIGlID> ret;
145  for (const auto& poi : getPOIs()) {
146  ret.push_back(static_cast<GUIPointOfInterest*>(poi.second)->getGlID());
147  }
148  return ret;
149 }
150 
151 
152 std::vector<GUIGlID>
155  std::vector<GUIGlID> ret;
156  for (const auto& poly : getPolygons()) {
157  ret.push_back(static_cast<GUIPolygon*>(poly.second)->getGlID());
158  }
159  return ret;
160 }
161 
162 /****************************************************************************/
163 
const Polygons & getPolygons() const
Returns all polygons.
std::vector< GUIGlID > getPOIIds() const
Returns the gl-ids of all pois.
T get(const std::string &id) const
Retrieves an item.
POIs myPOIs
stored POIs
Polygons myPolygons
stored Polygons
SUMORTree & myVis
The RTree structure to add and remove visualization elements.
void removeAdditionalGLObject(GUIGlObject *o)
Removes an additional object (detector/shape/trigger) from being visualised.
Definition: SUMORTree.h:152
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, double posLat, double layer, double angle, const std::string &imgFile, bool relativePath, double width, double height, bool ignorePruning=false)
Builds a POI using the given values and adds it to the container.
A RT-tree for efficient storing of SUMO&#39;s GL-objects.
Definition: SUMORTree.h:69
virtual bool removePOI(const std::string &id)
Removes a PoI from the container.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
bool add(const std::string &id, T item)
Adds an item.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
A list of positions.
virtual void movePOI(const std::string &id, const Position &pos)
Assigns a new position to the named PoI.
MFXMutex myLock
The mutex for adding/removing operations.
virtual ~GUIShapeContainer()
Destructor.
virtual void setShape(const PositionVector &shape)
set a new shape and update the tesselation
Definition: GUIPolygon.cpp:162
GUIShapeContainer(SUMORTree &vis)
Constructor.
void addAdditionalGLObject(GUIGlObject *o)
Adds an additional object (detector/shape/trigger) for visualisation.
Definition: SUMORTree.h:124
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:59
virtual bool removePolygon(const std::string &id)
Removes a polygon from the container.
bool remove(const std::string &id, const bool del=true)
Removes an item.
std::vector< GUIGlID > getPolygonIDs() const
Returns the gl-ids of all polygons.
virtual void reshapePolygon(const std::string &id, const PositionVector &shape)
Assigns a shape to the named polygon.
virtual bool addPolygon(const std::string &id, const std::string &type, const RGBColor &color, double layer, double angle, const std::string &imgFile, bool relativePath, const PositionVector &shape, bool geo, bool fill, double lineWidth, bool ignorePruning=false)
Builds a polygon using the given values and adds it to the container.
bool myAllowReplacement
whether existing ids shall be replaced
const POIs & getPOIs() const
Returns all pois.