SUMO - Simulation of Urban MObility
GUIShapeContainer.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Storage for geometrical objects extended by mutexes
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include "GUIShapeContainer.h"
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
43  : myVis(vis) {}
44 
45 
47 
48 
49 bool
50 GUIShapeContainer::addPOI(const std::string& id, const std::string& type,
51  const RGBColor& color, double layer, double angle, const std::string& imgFile,
52  const Position& pos, double width, double height, bool /* ignorePruning */) {
53  GUIPointOfInterest* p = new GUIPointOfInterest(id, type, color, pos, layer, angle, imgFile, width, height);
55  if (!myPOIs.add(id, p)) {
56  delete p;
57  return false;
58  } else {
60  return true;
61  }
62 }
63 
64 
65 bool
66 GUIShapeContainer::addPolygon(const std::string& id, const std::string& type,
67  const RGBColor& color, double layer,
68  double angle, const std::string& imgFile,
69  const PositionVector& shape, bool fill, bool /* ignorePruning */) {
70  GUIPolygon* p = new GUIPolygon(id, type, color, shape, fill, layer, angle, imgFile);
72  if (!myPolygons.add(id, p)) {
73  delete p;
74  return false;
75  } else {
77  return true;
78  }
79 }
80 
81 
82 bool
83 GUIShapeContainer::removePolygon(const std::string& id) {
85  GUIPolygon* p = dynamic_cast<GUIPolygon*>(myPolygons.get(id));
86  if (p == 0) {
87  return false;
88  }
90  return myPolygons.remove(id);
91 }
92 
93 
94 bool
95 GUIShapeContainer::removePOI(const std::string& id) {
97  GUIPointOfInterest* p = dynamic_cast<GUIPointOfInterest*>(myPOIs.get(id));
98  if (p == 0) {
99  return false;
100  }
102  return myPOIs.remove(id);
103 }
104 
105 
106 void
107 GUIShapeContainer::movePOI(const std::string& id, const Position& pos) {
109  GUIPointOfInterest* p = dynamic_cast<GUIPointOfInterest*>(myPOIs.get(id));
110  if (p != 0) {
112  static_cast<Position*>(p)->set(pos);
114  }
115 }
116 
117 
118 void
119 GUIShapeContainer::reshapePolygon(const std::string& id, const PositionVector& shape) {
121  GUIPolygon* p = dynamic_cast<GUIPolygon*>(myPolygons.get(id));
122  if (p != 0) {
124  p->setShape(shape);
126  }
127 }
128 
129 
130 
131 std::vector<GUIGlID>
134  std::vector<GUIGlID> ret;
135  const std::map<std::string, PointOfInterest*>& pois = getPOIs().getMyMap();
136  for (std::map<std::string, PointOfInterest*>::const_iterator it = pois.begin(); it != pois.end(); ++it) {
137  ret.push_back(static_cast<GUIPointOfInterest*>(it->second)->getGlID());
138  }
139  return ret;
140 }
141 
142 
143 std::vector<GUIGlID>
146  std::vector<GUIGlID> ret;
147  const std::map<std::string, SUMOPolygon*>& polygons = getPolygons().getMyMap();
148  for (std::map<std::string, SUMOPolygon*>::const_iterator it = polygons.begin(); it != polygons.end(); ++it) {
149  ret.push_back(static_cast<GUIPolygon*>(it->second)->getGlID());
150  }
151  return ret;
152 }
153 
154 /****************************************************************************/
155 
virtual bool addPOI(const std::string &id, const std::string &type, const RGBColor &color, double layer, double angle, const std::string &imgFile, const Position &pos, double width, double height, bool ignorePruning=false)
Builds a POI using the given values and adds it to the container.
std::vector< GUIGlID > getPOIIds() const
Returns the gl-ids of all pois.
virtual bool add(const std::string &id, T item)
Adds 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:141
A RT-tree for efficient storing of SUMO&#39;s GL-objects.
Definition: SUMORTree.h:74
virtual bool removePOI(const std::string &id)
Removes a PoI from the container.
const Polygons & getPolygons() const
Returns all polygons.
T get(const std::string &id) const
Retrieves an item.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
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 bool remove(const std::string &id)
Removes an item.
virtual ~GUIShapeContainer()
Destructor.
virtual void setShape(const PositionVector &shape)
set a new shape and update the tesselation
Definition: GUIPolygon.cpp:232
const POIs & getPOIs() const
Returns all pois.
GUIShapeContainer(SUMORTree &vis)
Constructor.
const IDMap & getMyMap() const
Returns a reference to the internal map.
void addAdditionalGLObject(GUIGlObject *o)
Adds an additional object (detector/shape/trigger) for visualisation.
Definition: SUMORTree.h:129
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:71
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 fill, bool ignorePruning=false)
Builds a polygon using the given values and adds it to the container.
virtual bool removePolygon(const std::string &id)
Removes a polygon from the container.
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.