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"
38 #include <utils/shapes/Polygon.h>
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
45  : myVis(vis) {}
46 
47 
49 
50 
51 bool
52 GUIShapeContainer::addPOI(const std::string& id, const std::string& type,
53  const RGBColor& color, double layer, double angle, const std::string& imgFile,
54  const Position& pos, double width, double height, bool /* ignorePruning */) {
55  GUIPointOfInterest* p = new GUIPointOfInterest(id, type, color, pos, layer, angle, imgFile, width, height);
57  if (!myPOIs.add(id, p)) {
58  delete p;
59  return false;
60  } else {
62  return true;
63  }
64 }
65 
66 
67 bool
68 GUIShapeContainer::addPolygon(const std::string& id, const std::string& type,
69  const RGBColor& color, double layer,
70  double angle, const std::string& imgFile,
71  const PositionVector& shape, bool fill, bool /* ignorePruning */) {
72  GUIPolygon* p = new GUIPolygon(id, type, color, shape, fill, layer, angle, imgFile);
74  if (!myPolygons.add(id, p)) {
75  delete p;
76  return false;
77  } else {
79  return true;
80  }
81 }
82 
83 
84 bool
85 GUIShapeContainer::removePolygon(const std::string& id) {
87  GUIPolygon* p = dynamic_cast<GUIPolygon*>(myPolygons.get(id));
88  if (p == 0) {
89  return false;
90  }
92  return myPolygons.remove(id);
93 }
94 
95 
96 bool
97 GUIShapeContainer::removePOI(const std::string& id) {
99  GUIPointOfInterest* p = dynamic_cast<GUIPointOfInterest*>(myPOIs.get(id));
100  if (p == 0) {
101  return false;
102  }
104  return myPOIs.remove(id);
105 }
106 
107 
108 void
109 GUIShapeContainer::movePOI(const std::string& id, const Position& pos) {
111  GUIPointOfInterest* p = dynamic_cast<GUIPointOfInterest*>(myPOIs.get(id));
112  if (p != 0) {
114  static_cast<Position*>(p)->set(pos);
116  }
117 }
118 
119 
120 void
121 GUIShapeContainer::reshapePolygon(const std::string& id, const PositionVector& shape) {
123  GUIPolygon* p = dynamic_cast<GUIPolygon*>(myPolygons.get(id));
124  if (p != 0) {
126  p->setShape(shape);
128  }
129 }
130 
131 
132 
133 std::vector<GUIGlID>
136  std::vector<GUIGlID> ret;
137  const std::map<std::string, PointOfInterest*>& pois = getPOIs().getMyMap();
138  for (std::map<std::string, PointOfInterest*>::const_iterator it = pois.begin(); it != pois.end(); ++it) {
139  ret.push_back(static_cast<GUIPointOfInterest*>(it->second)->getGlID());
140  }
141  return ret;
142 }
143 
144 
145 std::vector<GUIGlID>
148  std::vector<GUIGlID> ret;
149  const std::map<std::string, SUMO::Polygon*>& polygons = getPolygons().getMyMap();
150  for (std::map<std::string, SUMO::Polygon*>::const_iterator it = polygons.begin(); it != polygons.end(); ++it) {
151  ret.push_back(static_cast<GUIPolygon*>(it->second)->getGlID());
152  }
153  return ret;
154 }
155 
156 /****************************************************************************/
157 
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.
const Polygons & getPolygons() const
Returns all polygons.
virtual bool add(const std::string &id, T item)
Adds an item.
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: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.
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.
const IDMap & getMyMap() const
virtual ~GUIShapeContainer()
Destructor.
virtual void setShape(const PositionVector &shape)
set a new shape and update the tesselation
Definition: GUIPolygon.cpp:219
GUIShapeContainer(SUMORTree &vis)
Constructor.
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.
const POIs & getPOIs() const
Returns all pois.