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-sim.org/
12 // Copyright (C) 2001-2013 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 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
49  : myVis(vis) {}
50 
51 
53 
54 
55 bool
56 GUIShapeContainer::addPOI(const std::string& id, const std::string& type,
57  const RGBColor& color, SUMOReal layer, SUMOReal angle, const std::string& imgFile,
58  const Position& pos, SUMOReal width, SUMOReal height) {
59  GUIPointOfInterest* p = new GUIPointOfInterest(id, type, color, pos, layer, angle, imgFile, width, height);
61  if (!myPOIs.add(id, p)) {
62  delete p;
63  return false;
64  } else {
66  return true;
67  }
68 }
69 
70 
71 bool
72 GUIShapeContainer::addPolygon(const std::string& id, const std::string& type,
73  const RGBColor& color, SUMOReal layer,
74  SUMOReal angle, const std::string& imgFile,
75  const PositionVector& shape, bool fill) {
76  GUIPolygon* p = new GUIPolygon(id, type, color, shape, fill, layer, angle, imgFile);
78  if (!myPolygons.add(id, p)) {
79  delete p;
80  return false;
81  } else {
83  return true;
84  }
85 }
86 
87 
88 bool
89 GUIShapeContainer::removePolygon(const std::string& id) {
91  GUIPolygon* p = dynamic_cast<GUIPolygon*>(myPolygons.get(id));
92  if (p == 0) {
93  return false;
94  }
96  return myPolygons.remove(id);
97 }
98 
99 
100 bool
101 GUIShapeContainer::removePOI(const std::string& id) {
103  GUIPointOfInterest* p = dynamic_cast<GUIPointOfInterest*>(myPOIs.get(id));
104  if (p == 0) {
105  return false;
106  }
108  return myPOIs.remove(id);
109 }
110 
111 
112 void
113 GUIShapeContainer::movePOI(const std::string& id, const Position& pos) {
115  GUIPointOfInterest* p = dynamic_cast<GUIPointOfInterest*>(myPOIs.get(id));
116  if (p != 0) {
118  static_cast<Position*>(p)->set(pos);
120  }
121 }
122 
123 
124 void
125 GUIShapeContainer::reshapePolygon(const std::string& id, const PositionVector& shape) {
127  GUIPolygon* p = dynamic_cast<GUIPolygon*>(myPolygons.get(id));
128  if (p != 0) {
130  p->setShape(shape);
132  }
133 }
134 
135 
136 
137 std::vector<GUIGlID>
140  std::vector<GUIGlID> ret;
141  const std::map<std::string, PointOfInterest*>& pois = getPOIs().getMyMap();
142  for (std::map<std::string, PointOfInterest*>::const_iterator it = pois.begin(); it != pois.end(); ++it) {
143  ret.push_back(static_cast<GUIPointOfInterest*>(it->second)->getGlID());
144  }
145  return ret;
146 }
147 
148 
149 std::vector<GUIGlID>
152  std::vector<GUIGlID> ret;
153  const std::map<std::string, SUMO::Polygon*>& polygons = getPolygons().getMyMap();
154  for (std::map<std::string, SUMO::Polygon*>::const_iterator it = polygons.begin(); it != polygons.end(); ++it) {
155  ret.push_back(static_cast<GUIPolygon*>(it->second)->getGlID());
156  }
157  return ret;
158 }
159 
160 /****************************************************************************/
161