SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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.sourceforge.net/
12 // Copyright (C) 2001-2012 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 #ifdef CHECK_MEMORY_LEAKS
39 #include <foreign/nvwa/debug_new.h>
40 #endif // CHECK_MEMORY_LEAKS
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
47  : myVis(vis) {}
48 
49 
51 
52 
53 bool
54 GUIShapeContainer::addPoI(const std::string& name, int layer, const std::string& type, const RGBColor& c,
55  const Position& pos) {
56  GUIPointOfInterest* p = new GUIPointOfInterest(layer, name, type, pos, c);
57  myLock.lock();
58  const bool ret = add(layer, p);
59  if (ret) {
61  } else {
62  delete p;
63  }
64  myLock.unlock();
65  return ret;
66 }
67 
68 
69 bool
70 GUIShapeContainer::addPolygon(const std::string& name, int layer, const std::string& type, const RGBColor& c,
71  bool filled, const PositionVector& shape) {
72  GUIPolygon* p = new GUIPolygon(layer, name, type, c, shape, filled);
73  myLock.lock();
74  const bool ret = add(layer, p);
75  if (ret) {
77  } else {
78  delete p;
79  }
80  myLock.unlock();
81  return ret;
82 }
83 
84 
85 
86 bool
87 GUIShapeContainer::removePoI(int layer, const std::string& id) {
88  myLock.lock();
89  if (myPOILayers.find(layer) == myPOILayers.end()) {
90  myLock.unlock();
91  return false;
92  }
93  NamedObjectCont<PointOfInterest*> &c = myPOILayers.find(layer)->second;
94  PointOfInterest* p = c.get(id);
95  if (p == 0) {
96  myLock.unlock();
97  return false;
98  }
99  myVis.removeAdditionalGLObject(static_cast<GUIPointOfInterest*>(p));
100  bool ret = c.remove(id);
101  myLock.unlock();
102  return ret;
103 }
104 
105 
106 bool
107 GUIShapeContainer::removePolygon(int layer, const std::string& id) {
108  myLock.lock();
109  if (myPolygonLayers.find(layer) == myPolygonLayers.end()) {
110  myLock.unlock();
111  return false;
112  }
113  GUIPolygon* p = static_cast<GUIPolygon*>(myPolygonLayers.find(layer)->second.get(id));
114  if (p == 0) {
115  myLock.unlock();
116  return false;
117  }
119  bool ret = myPolygonLayers.find(layer)->second.remove(id);
120  myLock.unlock();
121  return ret;
122 }
123 
124 
125 
126 void
127 GUIShapeContainer::movePoI(int layer, const std::string& id, const Position& pos) {
128  myLock.lock();
129  if (myPOILayers.find(layer) != myPOILayers.end()) {
130  PointOfInterest* p = myPOILayers.find(layer)->second.get(id);
131  if (p != 0) {
132  myVis.removeAdditionalGLObject(static_cast<GUIPointOfInterest*>(p));
133  static_cast<Position*>(p)->set(pos);
134  myVis.addAdditionalGLObject(static_cast<GUIPointOfInterest*>(p));
135  }
136  }
137  myLock.unlock();
138 }
139 
140 
141 void
142 GUIShapeContainer::reshapePolygon(int layer, const std::string& id, const PositionVector& shape) {
143  myLock.lock();
144  if (myPolygonLayers.find(layer) != myPolygonLayers.end()) {
145  GUIPolygon* p = static_cast<GUIPolygon*>(myPolygonLayers.find(layer)->second.get(id));
146  if (p != 0) {
148  p->setShape(shape);
150  }
151  }
152  myLock.unlock();
153 }
154 
155 
156 std::vector<GUIGlID>
158  std::vector<GUIGlID> ret;
159  for (int j = myMinLayer; j <= myMaxLayer; ++j) {
160  const PolyMap& pol = getPolygonCont(j).getMyMap();
161  for (PolyMap::const_iterator i = pol.begin(); i != pol.end(); ++i) {
162  ret.push_back(static_cast<GUIPolygon*>((*i).second)->getGlID());
163  }
164  const std::map<std::string, PointOfInterest*> &poi = getPOICont(j).getMyMap();
165  for (std::map<std::string, PointOfInterest*>::const_iterator i = poi.begin(); i != poi.end(); ++i) {
166  ret.push_back(static_cast<GUIPointOfInterest*>((*i).second)->getGlID());
167  }
168  }
169  return ret;
170 }
171 
172 
173 /****************************************************************************/
174