SUMO - Simulation of Urban MObility

GUIShapeContainer.cpp

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