PCPolyContainer.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029
00030 #include <string>
00031 #include <map>
00032 #include <utils/common/MsgHandler.h>
00033 #include <utils/common/ToString.h>
00034 #include <utils/shapes/Polygon2D.h>
00035 #include "PCPolyContainer.h"
00036 #include <utils/common/UtilExceptions.h>
00037 #include <utils/iodevices/OutputDevice.h>
00038 #include <utils/common/StringUtils.h>
00039
00040 #ifdef CHECK_MEMORY_LEAKS
00041 #include <foreign/nvwa/debug_new.h>
00042 #endif // CHECK_MEMORY_LEAKS
00043
00044
00045
00046
00047
00048 PCPolyContainer::PCPolyContainer(bool prune,
00049 const Boundary &prunningBoundary,
00050 const std::vector<std::string> &removeByNames) throw()
00051 : myPrunningBoundary(prunningBoundary), myDoPrunne(prune),
00052 myRemoveByNames(removeByNames) {}
00053
00054
00055 PCPolyContainer::~PCPolyContainer() throw() {
00056 clear();
00057 }
00058
00059
00060 bool
00061 PCPolyContainer::insert(const std::string &id, Polygon2D *poly,
00062 int layer, bool ignorePrunning) throw() {
00063
00064
00065 if (myDoPrunne&&!ignorePrunning) {
00066 Boundary b = poly->getShape().getBoxBoundary();
00067 if (!b.partialWithin(myPrunningBoundary)) {
00068 delete poly;
00069 return true;
00070 }
00071 }
00072
00073 if (find(myRemoveByNames.begin(), myRemoveByNames.end(), id)!=myRemoveByNames.end()) {
00074 delete poly;
00075 return true;
00076 }
00077
00078 PolyCont::iterator i=myPolyCont.find(id);
00079 if (i!=myPolyCont.end()) {
00080 return false;
00081 }
00082 myPolyCont[id] = poly;
00083 myPolyLayerMap[poly] = layer;
00084 return true;
00085 }
00086
00087
00088 bool
00089 PCPolyContainer::insert(const std::string &id, PointOfInterest *poi,
00090 int layer, bool ignorePrunning) throw() {
00091
00092
00093 if (myDoPrunne&&!ignorePrunning) {
00094 if (!myPrunningBoundary.around(*poi)) {
00095 delete poi;
00096 return true;
00097 }
00098 }
00099
00100 if (find(myRemoveByNames.begin(), myRemoveByNames.end(), id)!=myRemoveByNames.end()) {
00101 delete poi;
00102 return true;
00103 }
00104
00105 POICont::iterator i=myPOICont.find(id);
00106 if (i!=myPOICont.end()) {
00107 return false;
00108 }
00109 myPOICont[id] = poi;
00110 myPOILayerMap[poi] = layer;
00111 return true;
00112 }
00113
00114
00115 bool
00116 PCPolyContainer::containsPolygon(const std::string &id) throw() {
00117 return myPolyCont.find(id)!=myPolyCont.end();
00118 }
00119
00120
00121 void
00122 PCPolyContainer::clear() throw() {
00123
00124 for (PolyCont::iterator i=myPolyCont.begin(); i!=myPolyCont.end(); i++) {
00125 delete(*i).second;
00126 }
00127 myPolyCont.clear();
00128 myPolyLayerMap.clear();
00129
00130 for (POICont::iterator i=myPOICont.begin(); i!=myPOICont.end(); i++) {
00131 delete(*i).second;
00132 }
00133 myPOICont.clear();
00134 myPOILayerMap.clear();
00135 }
00136
00137
00138 void
00139 PCPolyContainer::report() throw() {
00140 WRITE_MESSAGE(" " + toString(getNoPolygons()) + " polygons loaded.");
00141 WRITE_MESSAGE(" " + toString(getNoPOIs()) + " pois loaded.");
00142 }
00143
00144
00145 void
00146 PCPolyContainer::save(const std::string &file) throw(IOError) {
00147 OutputDevice& out = OutputDevice::getDevice(file);
00148 out.writeXMLHeader("shapes");
00149
00150 for (PolyCont::iterator i=myPolyCont.begin(); i!=myPolyCont.end(); ++i) {
00151 out << " <poly id=\"" << StringUtils::escapeXML((*i).second->getID()) << "\" type=\""
00152 << (*i).second->getType() << "\" color=\""
00153 << (*i).second->getColor() << "\" fill=\""
00154 << (*i).second->fill() << "\"";
00155 out << " layer=\"" << myPolyLayerMap[(*i).second] << "\"";
00156 out << " shape=\"" << (*i).second->getShape() << "\"/>\n";
00157 }
00158
00159 for (POICont::iterator i=myPOICont.begin(); i!=myPOICont.end(); ++i) {
00160 out << " <poi id=\"" << StringUtils::escapeXML((*i).second->getID()) << "\" type=\""
00161 << (*i).second->getType() << "\" color=\""
00162 << *static_cast<RGBColor*>((*i).second) << '"';
00163 out << " layer=\"" << myPOILayerMap[(*i).second] << "\"";
00164 out << " x=\"" << (*i).second->x() << "\""
00165 << " y=\"" << (*i).second->y() << "\""
00166 << "/>\n";
00167 }
00168 out.close();
00169 }
00170
00171
00172 int
00173 PCPolyContainer::getEnumIDFor(const std::string &key) throw() {
00174 if (myIDEnums.find(key)==myIDEnums.end()) {
00175 myIDEnums[key] = 0;
00176 return 0;
00177 } else {
00178 myIDEnums[key] = myIDEnums[key] + 1;
00179 return myIDEnums[key];
00180 }
00181 }
00182
00183
00184
00185
00186