SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // Storage for geometrical objects extended by mutexes 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 "GUIShapeContainer.h" 00034 #include <foreign/rtree/SUMORTree.h> 00035 #include <utils/gui/globjects/GUIPolygon.h> 00036 #include <utils/gui/globjects/GUIPointOfInterest.h> 00037 00038 #ifdef CHECK_MEMORY_LEAKS 00039 #include <foreign/nvwa/debug_new.h> 00040 #endif // CHECK_MEMORY_LEAKS 00041 00042 00043 // =========================================================================== 00044 // method definitions 00045 // =========================================================================== 00046 GUIShapeContainer::GUIShapeContainer(SUMORTree& vis) 00047 : myVis(vis) {} 00048 00049 00050 GUIShapeContainer::~GUIShapeContainer() {} 00051 00052 00053 bool 00054 GUIShapeContainer::addPoI(const std::string& name, int layer, const std::string& type, const RGBColor& c, 00055 const Position& pos) { 00056 GUIPointOfInterest* p = new GUIPointOfInterest(layer, name, type, pos, c); 00057 myLock.lock(); 00058 const bool ret = add(layer, p); 00059 if (ret) { 00060 myVis.addAdditionalGLObject(p); 00061 } else { 00062 delete p; 00063 } 00064 myLock.unlock(); 00065 return ret; 00066 } 00067 00068 00069 bool 00070 GUIShapeContainer::addPolygon(const std::string& name, int layer, const std::string& type, const RGBColor& c, 00071 bool filled, const PositionVector& shape) { 00072 GUIPolygon* p = new GUIPolygon(layer, name, type, c, shape, filled); 00073 myLock.lock(); 00074 const bool ret = add(layer, p); 00075 if (ret) { 00076 myVis.addAdditionalGLObject(p); 00077 } else { 00078 delete p; 00079 } 00080 myLock.unlock(); 00081 return ret; 00082 } 00083 00084 00085 00086 bool 00087 GUIShapeContainer::removePoI(int layer, const std::string& id) { 00088 myLock.lock(); 00089 if (myPOILayers.find(layer) == myPOILayers.end()) { 00090 myLock.unlock(); 00091 return false; 00092 } 00093 NamedObjectCont<PointOfInterest*> &c = myPOILayers.find(layer)->second; 00094 PointOfInterest* p = c.get(id); 00095 if (p == 0) { 00096 myLock.unlock(); 00097 return false; 00098 } 00099 myVis.removeAdditionalGLObject(static_cast<GUIPointOfInterest*>(p)); 00100 bool ret = c.remove(id); 00101 myLock.unlock(); 00102 return ret; 00103 } 00104 00105 00106 bool 00107 GUIShapeContainer::removePolygon(int layer, const std::string& id) { 00108 myLock.lock(); 00109 if (myPolygonLayers.find(layer) == myPolygonLayers.end()) { 00110 myLock.unlock(); 00111 return false; 00112 } 00113 GUIPolygon* p = static_cast<GUIPolygon*>(myPolygonLayers.find(layer)->second.get(id)); 00114 if (p == 0) { 00115 myLock.unlock(); 00116 return false; 00117 } 00118 myVis.removeAdditionalGLObject(p); 00119 bool ret = myPolygonLayers.find(layer)->second.remove(id); 00120 myLock.unlock(); 00121 return ret; 00122 } 00123 00124 00125 00126 void 00127 GUIShapeContainer::movePoI(int layer, const std::string& id, const Position& pos) { 00128 myLock.lock(); 00129 if (myPOILayers.find(layer) != myPOILayers.end()) { 00130 PointOfInterest* p = myPOILayers.find(layer)->second.get(id); 00131 if (p != 0) { 00132 myVis.removeAdditionalGLObject(static_cast<GUIPointOfInterest*>(p)); 00133 static_cast<Position*>(p)->set(pos); 00134 myVis.addAdditionalGLObject(static_cast<GUIPointOfInterest*>(p)); 00135 } 00136 } 00137 myLock.unlock(); 00138 } 00139 00140 00141 void 00142 GUIShapeContainer::reshapePolygon(int layer, const std::string& id, const PositionVector& shape) { 00143 myLock.lock(); 00144 if (myPolygonLayers.find(layer) != myPolygonLayers.end()) { 00145 GUIPolygon* p = static_cast<GUIPolygon*>(myPolygonLayers.find(layer)->second.get(id)); 00146 if (p != 0) { 00147 myVis.removeAdditionalGLObject(p); 00148 p->setShape(shape); 00149 myVis.addAdditionalGLObject(p); 00150 } 00151 } 00152 myLock.unlock(); 00153 } 00154 00155 00156 std::vector<GUIGlID> 00157 GUIShapeContainer::getShapeIDs() const { 00158 std::vector<GUIGlID> ret; 00159 for (int j = myMinLayer; j <= myMaxLayer; ++j) { 00160 const PolyMap& pol = getPolygonCont(j).getMyMap(); 00161 for (PolyMap::const_iterator i = pol.begin(); i != pol.end(); ++i) { 00162 ret.push_back(static_cast<GUIPolygon*>((*i).second)->getGlID()); 00163 } 00164 const std::map<std::string, PointOfInterest*> &poi = getPOICont(j).getMyMap(); 00165 for (std::map<std::string, PointOfInterest*>::const_iterator i = poi.begin(); i != poi.end(); ++i) { 00166 ret.push_back(static_cast<GUIPointOfInterest*>((*i).second)->getGlID()); 00167 } 00168 } 00169 return ret; 00170 } 00171 00172 00173 /****************************************************************************/ 00174