SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PCPolyContainer.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A storage for loaded polygons and pois
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 <string>
34 #include <map>
36 #include <utils/common/ToString.h>
39 #include <utils/shapes/Polygon.h>
42 #include "PCPolyContainer.h"
43 
44 #ifdef CHECK_MEMORY_LEAKS
45 #include <foreign/nvwa/debug_new.h>
46 #endif // CHECK_MEMORY_LEAKS
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
53  const Boundary& prunningBoundary,
54  const std::vector<std::string> &removeByNames)
55  : myPrunningBoundary(prunningBoundary), myDoPrunne(prune),
56  myRemoveByNames(removeByNames) {}
57 
58 
60  clear();
61 }
62 
63 
64 bool
65 PCPolyContainer::insert(const std::string& id, Polygon* poly,
66  int layer, bool ignorePrunning) {
67  // check whether the polygon lies within the wished area
68  // - if such an area was given
69  if (myDoPrunne && !ignorePrunning) {
70  Boundary b = poly->getShape().getBoxBoundary();
72  delete poly;
73  return true;
74  }
75  }
76  // check whether the polygon was named to be a removed one
77  if (find(myRemoveByNames.begin(), myRemoveByNames.end(), id) != myRemoveByNames.end()) {
78  delete poly;
79  return true;
80  }
81  //
82  PolyCont::iterator i = myPolyCont.find(id);
83  if (i != myPolyCont.end()) {
84  return false;
85  }
86  myPolyCont[id] = poly;
87  myPolyLayerMap[poly] = layer;
88  return true;
89 }
90 
91 
92 bool
93 PCPolyContainer::insert(const std::string& id, PointOfInterest* poi,
94  int layer, bool ignorePrunning) {
95  // check whether the poi lies within the wished area
96  // - if such an area was given
97  if (myDoPrunne && !ignorePrunning) {
98  if (!myPrunningBoundary.around(*poi)) {
99  delete poi;
100  return true;
101  }
102  }
103  // check whether the polygon was named to be a removed one
104  if (find(myRemoveByNames.begin(), myRemoveByNames.end(), id) != myRemoveByNames.end()) {
105  delete poi;
106  return true;
107  }
108  //
109  POICont::iterator i = myPOICont.find(id);
110  if (i != myPOICont.end()) {
111  return false;
112  }
113  myPOICont[id] = poi;
114  myPOILayerMap[poi] = layer;
115  return true;
116 }
117 
118 
119 bool
120 PCPolyContainer::containsPolygon(const std::string& id) {
121  return myPolyCont.find(id) != myPolyCont.end();
122 }
123 
124 
125 void
127  // polys
128  for (PolyCont::iterator i = myPolyCont.begin(); i != myPolyCont.end(); i++) {
129  delete(*i).second;
130  }
131  myPolyCont.clear();
132  myPolyLayerMap.clear();
133  // pois
134  for (POICont::iterator i = myPOICont.begin(); i != myPOICont.end(); i++) {
135  delete(*i).second;
136  }
137  myPOICont.clear();
138  myPOILayerMap.clear();
139 }
140 
141 
142 void
144  WRITE_MESSAGE(" " + toString(getNoPolygons()) + " polygons loaded.");
145  WRITE_MESSAGE(" " + toString(getNoPOIs()) + " pois loaded.");
146 }
147 
148 
149 void
150 PCPolyContainer::save(const std::string& file) {
153  // write polygons
154  for (PolyCont::iterator i = myPolyCont.begin(); i != myPolyCont.end(); ++i) {
155  out.openTag("poly") << " id=\"" << StringUtils::escapeXML((*i).second->getID())
156  << "\" type=\"" << (*i).second->getType()
157  << "\" color=\"" << (*i).second->getColor()
158  << "\" fill=\"" << (*i).second->fill()
159  << "\" layer=\"" << myPolyLayerMap[(*i).second]
160  << "\" shape=\"" << (*i).second->getShape() << "\"";
161  out.closeTag(true);
162  }
163  // write pois
164  for (POICont::iterator i = myPOICont.begin(); i != myPOICont.end(); ++i) {
165  out.openTag("poi") << " id=\"" << StringUtils::escapeXML((*i).second->getID())
166  << "\" type=\"" << StringUtils::escapeXML((*i).second->getType())
167  << "\" color=\"" << *static_cast<RGBColor*>((*i).second)
168  << "\" layer=\"" << myPOILayerMap[(*i).second]
169  << "\" x=\"" << (*i).second->x()
170  << "\" y=\"" << (*i).second->y() << "\"";
171  out.closeTag(true);
172  }
173  out.close();
174 }
175 
176 
177 int
178 PCPolyContainer::getEnumIDFor(const std::string& key) {
179  if (myIDEnums.find(key) == myIDEnums.end()) {
180  myIDEnums[key] = 0;
181  return 0;
182  } else {
183  myIDEnums[key] = myIDEnums[key] + 1;
184  return myIDEnums[key];
185  }
186 }
187 
188 
189 
190 /****************************************************************************/
191