|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Storage for geometrical objects, sorted by the layers they are in 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 00020 00021 // =========================================================================== 00022 // included modules 00023 // =========================================================================== 00024 #ifdef _MSC_VER 00025 #include <windows_config.h> 00026 #else 00027 #include <config.h> 00028 #endif 00029 00030 #include <fstream> 00031 #include <stdlib.h> 00032 #include <iostream> 00033 #include <utility> 00034 #include <string> 00035 #include <cmath> 00036 #include <utils/common/NamedObjectCont.h> 00037 #include <utils/shapes/PointOfInterest.h> 00038 #include <utils/shapes/Polygon.h> 00039 #include <utils/shapes/ShapeContainer.h> 00040 #include <utils/common/MsgHandler.h> 00041 #include <utils/common/UtilExceptions.h> 00042 #include <utils/common/ToString.h> 00043 #include <utils/common/StdDefs.h> 00044 00045 #ifdef CHECK_MEMORY_LEAKS 00046 #include <foreign/nvwa/debug_new.h> 00047 #endif // CHECK_MEMORY_LEAKS 00048 00049 00050 // =========================================================================== 00051 // method definitions 00052 // =========================================================================== 00053 ShapeContainer::ShapeContainer() throw() 00054 : myMinLayer(100), myMaxLayer(-100) {} 00055 00056 00057 ShapeContainer::~ShapeContainer() throw() {} 00058 00059 00060 bool 00061 ShapeContainer::addPoI(const std::string& name, int layer, const std::string& type, const RGBColor& c, 00062 const Position& pos) throw() { 00063 PointOfInterest* p = new PointOfInterest(name, type, pos, c); 00064 if (!add(layer, p)) { 00065 delete p; 00066 return false; 00067 } 00068 return true; 00069 } 00070 00071 00072 bool 00073 ShapeContainer::addPolygon(const std::string& name, int layer, const std::string& type, const RGBColor& c, 00074 bool filled, const PositionVector& shape) throw() { 00075 Polygon* p = new Polygon(name, type, c, shape, filled); 00076 if (!add(layer, p)) { 00077 delete p; 00078 return false; 00079 } 00080 return true; 00081 } 00082 00083 00084 00085 bool 00086 ShapeContainer::removePolygon(int layer, const std::string& id) throw() { 00087 if (myPolygonLayers.find(layer)==myPolygonLayers.end()) { 00088 return false; 00089 } 00090 return myPolygonLayers.find(layer)->second.remove(id); 00091 } 00092 00093 00094 bool 00095 ShapeContainer::removePoI(int layer, const std::string& id) throw() { 00096 if (myPOILayers.find(layer)==myPOILayers.end()) { 00097 return false; 00098 } 00099 return myPOILayers.find(layer)->second.remove(id); 00100 } 00101 00102 00103 00104 void 00105 ShapeContainer::movePoI(int layer, const std::string& id, const Position& pos) throw() { 00106 if (myPOILayers.find(layer)!=myPOILayers.end()) { 00107 PointOfInterest* p = myPOILayers.find(layer)->second.get(id); 00108 if (p!=0) { 00109 static_cast<Position*>(p)->set(pos); 00110 } 00111 } 00112 } 00113 00114 00115 void 00116 ShapeContainer::reshapePolygon(int layer, const std::string& id, const PositionVector& shape) throw() { 00117 if (myPolygonLayers.find(layer)!=myPolygonLayers.end()) { 00118 Polygon* p = myPolygonLayers.find(layer)->second.get(id); 00119 if (p!=0) { 00120 p->setShape(shape); 00121 } 00122 } 00123 } 00124 00125 00126 00127 const NamedObjectCont<Polygon*> & 00128 ShapeContainer::getPolygonCont(int layer) const throw() { 00129 if (myPolygonLayers.find(layer)==myPolygonLayers.end()) { 00130 myPolygonLayers[layer] = NamedObjectCont<Polygon*>(); 00131 myMinLayer = MIN2(layer, myMinLayer); 00132 myMaxLayer = MAX2(layer, myMaxLayer); 00133 } 00134 return myPolygonLayers[layer]; 00135 } 00136 00137 00138 const NamedObjectCont<PointOfInterest*> & 00139 ShapeContainer::getPOICont(int layer) const throw() { 00140 if (myPOILayers.find(layer)==myPOILayers.end()) { 00141 myPOILayers[layer] = NamedObjectCont<PointOfInterest*>(); 00142 myMinLayer = MIN2(layer, myMinLayer); 00143 myMaxLayer = MAX2(layer, myMaxLayer); 00144 } 00145 return myPOILayers[layer]; 00146 } 00147 00148 00149 00150 bool 00151 ShapeContainer::add(int layer, Polygon* p) throw() { 00152 if (myPolygonLayers.find(layer)==myPolygonLayers.end()) { 00153 myPolygonLayers[layer] = NamedObjectCont<Polygon*>(); 00154 myMinLayer = MIN2(layer, myMinLayer); 00155 myMaxLayer = MAX2(layer, myMaxLayer); 00156 } 00157 return myPolygonLayers[layer].add(p->getID(), p); 00158 } 00159 00160 00161 bool 00162 ShapeContainer::add(int layer, PointOfInterest* p) throw() { 00163 if (myPOILayers.find(layer)==myPOILayers.end()) { 00164 myPOILayers[layer] = NamedObjectCont<PointOfInterest*>(); 00165 myMinLayer = MIN2(layer, myMinLayer); 00166 myMaxLayer = MAX2(layer, myMaxLayer); 00167 } 00168 return myPOILayers[layer].add(p->getID(), p); 00169 } 00170 00171 00172 00173 /****************************************************************************/ 00174