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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Storage for geometrical objects extended by mutexes
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include "GUIShapeContainer.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
42  : myVis(vis) {}
43 
44 
46 
47 
48 bool
49 GUIShapeContainer::addPOI(const std::string& id, const std::string& type, const RGBColor& color, const Position& pos, bool geo,
50  const std::string& lane, double posOverLane, double posLat, double layer, double angle,
51  const std::string& imgFile, double width, double height, bool /* ignorePruning */) {
52  GUIPointOfInterest* p = new GUIPointOfInterest(id, type, color, pos, geo, lane, posOverLane, posLat, layer, angle, imgFile, width, height);
54  if (!myPOIs.add(id, p)) {
55  delete p;
56  return false;
57  } else {
59  return true;
60  }
61 }
62 
63 
64 bool
65 GUIShapeContainer::addPolygon(const std::string& id, const std::string& type,
66  const RGBColor& color, double layer,
67  double angle, const std::string& imgFile,
68  const PositionVector& shape, bool geo, bool fill, bool /* ignorePruning */) {
69  GUIPolygon* p = new GUIPolygon(id, type, color, shape, geo, fill, layer, angle, imgFile);
71  if (!myPolygons.add(id, p)) {
72  delete p;
73  return false;
74  } else {
76  return true;
77  }
78 }
79 
80 
81 bool
82 GUIShapeContainer::removePolygon(const std::string& id) {
84  GUIPolygon* p = dynamic_cast<GUIPolygon*>(myPolygons.get(id));
85  if (p == 0) {
86  return false;
87  }
89  return myPolygons.remove(id);
90 }
91 
92 
93 bool
94 GUIShapeContainer::removePOI(const std::string& id) {
96  GUIPointOfInterest* p = dynamic_cast<GUIPointOfInterest*>(myPOIs.get(id));
97  if (p == 0) {
98  return false;
99  }
101  return myPOIs.remove(id);
102 }
103 
104 
105 void
106 GUIShapeContainer::movePOI(const std::string& id, const Position& pos) {
108  GUIPointOfInterest* p = dynamic_cast<GUIPointOfInterest*>(myPOIs.get(id));
109  if (p != 0) {
111  static_cast<Position*>(p)->set(pos);
113  }
114 }
115 
116 
117 void
118 GUIShapeContainer::reshapePolygon(const std::string& id, const PositionVector& shape) {
120  GUIPolygon* p = dynamic_cast<GUIPolygon*>(myPolygons.get(id));
121  if (p != 0) {
123  p->setShape(shape);
125  }
126 }
127 
128 
129 
130 std::vector<GUIGlID>
133  std::vector<GUIGlID> ret;
134  for (const auto& poi : getPOIs()) {
135  ret.push_back(static_cast<GUIPointOfInterest*>(poi.second)->getGlID());
136  }
137  return ret;
138 }
139 
140 
141 std::vector<GUIGlID>
144  std::vector<GUIGlID> ret;
145  for (const auto& poly : getPolygons()) {
146  ret.push_back(static_cast<GUIPolygon*>(poly.second)->getGlID());
147  }
148  return ret;
149 }
150 
151 /****************************************************************************/
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, double width, double height, bool ignorePruning=false)
Builds a POI using the given values and adds it to the container.
const Polygons & getPolygons() const
Returns all polygons.
std::vector< GUIGlID > getPOIIds() const
Returns the gl-ids of all pois.
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, bool ignorePruning=false)
Builds a polygon using the given values and adds it to the container.
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:140
A RT-tree for efficient storing of SUMO&#39;s GL-objects.
Definition: SUMORTree.h:73
virtual bool removePOI(const std::string &id)
Removes a PoI from the container.
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:45
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:230
GUIShapeContainer(SUMORTree &vis)
Constructor.
void addAdditionalGLObject(GUIGlObject *o)
Adds an additional object (detector/shape/trigger) for visualisation.
Definition: SUMORTree.h:128
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:70
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.
const POIs & getPOIs() const
Returns all pois.