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