SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // The class responsible for building and deletion of vehicles (gui-version) 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 <utils/foxtools/MFXMutex.h> 00034 #include "GUIVehicleControl.h" 00035 #include "GUIVehicle.h" 00036 #include "GUINet.h" 00037 #include <gui/GUIGlobals.h> 00038 00039 #ifdef CHECK_MEMORY_LEAKS 00040 #include <foreign/nvwa/debug_new.h> 00041 #endif // CHECK_MEMORY_LEAKS 00042 00043 00044 // =========================================================================== 00045 // member method definitions 00046 // =========================================================================== 00047 GUIVehicleControl::GUIVehicleControl() 00048 : MSVehicleControl() {} 00049 00050 00051 GUIVehicleControl::~GUIVehicleControl() { 00052 // just to quit cleanly on a failure 00053 if (myLock.locked()) { 00054 myLock.unlock(); 00055 } 00056 } 00057 00058 00059 SUMOVehicle* 00060 GUIVehicleControl::buildVehicle(SUMOVehicleParameter* defs, 00061 const MSRoute* route, const MSVehicleType* type) { 00062 myLoadedVehNo++; 00063 MSVehicle* built = new GUIVehicle(defs, route, type, myLoadedVehNo - 1); 00064 MSNet::getInstance()->informVehicleStateListener(built, MSNet::VEHICLE_STATE_BUILT); 00065 return built; 00066 } 00067 00068 00069 bool 00070 GUIVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) { 00071 myLock.lock(); 00072 const bool result = MSVehicleControl::addVehicle(id, v); 00073 myLock.unlock(); 00074 return result; 00075 } 00076 00077 00078 void 00079 GUIVehicleControl::deleteVehicle(SUMOVehicle* veh, bool discard) { 00080 myLock.lock(); 00081 MSVehicleControl::deleteVehicle(veh, discard); 00082 myLock.unlock(); 00083 } 00084 00085 00086 void 00087 GUIVehicleControl::insertVehicleIDs(std::vector<GUIGlID> &into) { 00088 myLock.lock(); 00089 into.reserve(myVehicleDict.size()); 00090 for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) { 00091 SUMOVehicle* veh = (*i).second; 00092 if (veh->isOnRoad()) { 00093 into.push_back(static_cast<GUIVehicle*>((*i).second)->getGlID()); 00094 } 00095 } 00096 myLock.unlock(); 00097 } 00098 00099 00100 00101 /****************************************************************************/ 00102