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 <algorithm>
35 #include <map>
37 #include <utils/common/ToString.h>
40 #include <utils/shapes/Polygon.h>
43 #include "PCPolyContainer.h"
44 
45 #ifdef CHECK_MEMORY_LEAKS
46 #include <foreign/nvwa/debug_new.h>
47 #endif // CHECK_MEMORY_LEAKS
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
54  const Boundary& prunningBoundary,
55  const std::vector<std::string>& removeByNames)
56  : myPrunningBoundary(prunningBoundary), myDoPrunne(prune),
57  myRemoveByNames(removeByNames) {}
58 
59 
61  clear();
62 }
63 
64 
65 bool
66 PCPolyContainer::insert(const std::string& id, Polygon* poly,
67  int layer, bool ignorePrunning) {
68  // check whether the polygon lies within the wished area
69  // - if such an area was given
70  if (myDoPrunne && !ignorePrunning) {
71  Boundary b = poly->getShape().getBoxBoundary();
73  delete poly;
74  return true;
75  }
76  }
77  // check whether the polygon was named to be a removed one
78  if (find(myRemoveByNames.begin(), myRemoveByNames.end(), id) != myRemoveByNames.end()) {
79  delete poly;
80  return true;
81  }
82  //
83  PolyCont::iterator i = myPolyCont.find(id);
84  if (i != myPolyCont.end()) {
85  return false;
86  }
87  myPolyCont[id] = poly;
88  myPolyLayerMap[poly] = layer;
89  return true;
90 }
91 
92 
93 bool
94 PCPolyContainer::insert(const std::string& id, PointOfInterest* poi,
95  int layer, bool ignorePrunning) {
96  // check whether the poi lies within the wished area
97  // - if such an area was given
98  if (myDoPrunne && !ignorePrunning) {
99  if (!myPrunningBoundary.around(*poi)) {
100  delete poi;
101  return true;
102  }
103  }
104  // check whether the polygon was named to be a removed one
105  if (find(myRemoveByNames.begin(), myRemoveByNames.end(), id) != myRemoveByNames.end()) {
106  delete poi;
107  return true;
108  }
109  //
110  POICont::iterator i = myPOICont.find(id);
111  if (i != myPOICont.end()) {
112  return false;
113  }
114  myPOICont[id] = poi;
115  myPOILayerMap[poi] = layer;
116  return true;
117 }
118 
119 
120 bool
121 PCPolyContainer::containsPolygon(const std::string& id) {
122  return myPolyCont.find(id) != myPolyCont.end();
123 }
124 
125 
126 void
128  // polys
129  for (PolyCont::iterator i = myPolyCont.begin(); i != myPolyCont.end(); i++) {
130  delete(*i).second;
131  }
132  myPolyCont.clear();
133  myPolyLayerMap.clear();
134  // pois
135  for (POICont::iterator i = myPOICont.begin(); i != myPOICont.end(); i++) {
136  delete(*i).second;
137  }
138  myPOICont.clear();
139  myPOILayerMap.clear();
140 }
141 
142 
143 void
145  WRITE_MESSAGE(" " + toString(getNoPolygons()) + " polygons loaded.");
146  WRITE_MESSAGE(" " + toString(getNoPOIs()) + " pois loaded.");
147 }
148 
149 
150 void
151 PCPolyContainer::save(const std::string& file) {
154  // write polygons
155  for (PolyCont::iterator i = myPolyCont.begin(); i != myPolyCont.end(); ++i) {
156  Polygon* p = i->second;
157  out.openTag(SUMO_TAG_POLY);
161  out.writeAttr(SUMO_ATTR_FILL, p->getFill());
164  if (p->getAngle() != Shape::DEFAULT_ANGLE) {
166  }
167  if (p->getImgFile() != Shape::DEFAULT_IMG_FILE) {
169  }
170  out.closeTag(true);
171  }
172  // write pois
173  for (POICont::iterator i = myPOICont.begin(); i != myPOICont.end(); ++i) {
174  PointOfInterest* p = i->second;
175  out.openTag(SUMO_TAG_POI);
180  out.writeAttr(SUMO_ATTR_X, p->x());
181  out.writeAttr(SUMO_ATTR_Y, p->y());
182  if (p->getAngle() != Shape::DEFAULT_ANGLE) {
184  }
185  if (p->getImgFile() != Shape::DEFAULT_IMG_FILE) {
187  }
188  if (p->getWidth() != Shape::DEFAULT_IMG_WIDTH) {
190  }
191  if (p->getHeight() != Shape::DEFAULT_IMG_HEIGHT) {
193  }
194  out.closeTag(true);
195  }
196  out.close();
197 }
198 
199 
200 int
201 PCPolyContainer::getEnumIDFor(const std::string& key) {
202  if (myIDEnums.find(key) == myIDEnums.end()) {
203  myIDEnums[key] = 0;
204  return 0;
205  } else {
206  myIDEnums[key] = myIDEnums[key] + 1;
207  return myIDEnums[key];
208  }
209 }
210 
211 
212 
213 /****************************************************************************/
214