SUMO - Simulation of Urban MObility
GUIVehicleControl.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // The class responsible for building and deletion of vehicles (gui-version)
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
35 #include "GUIVehicleControl.h"
36 #include "GUIVehicle.h"
37 #include "GUINet.h"
38 #include <gui/GUIGlobals.h>
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // member method definitions
47 // ===========================================================================
49  : MSVehicleControl() {}
50 
51 
53  // just to quit cleanly on a failure
54  if (myLock.locked()) {
55  myLock.unlock();
56  }
57 }
58 
59 
62  const MSRoute* route, const MSVehicleType* type,
63  const bool ignoreStopErrors, const bool fromRouteFile) {
64  myLoadedVehNo++;
65  if (fromRouteFile) {
67  }
68  MSVehicle* built = new GUIVehicle(defs, route, type, type->computeChosenSpeedDeviation(fromRouteFile ? MSRouteHandler::getParsingRNG() : 0));
69  built->addStops(ignoreStopErrors);
71  return built;
72 }
73 
74 
75 bool
76 GUIVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
78  return MSVehicleControl::addVehicle(id, v);
79 }
80 
81 
82 void
85  MSVehicleControl::deleteVehicle(veh, discard);
86 }
87 
88 
89 void
90 GUIVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into) {
92  into.reserve(myVehicleDict.size());
93  for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
94  SUMOVehicle* veh = (*i).second;
95  if (veh->isOnRoad()) {
96  into.push_back(static_cast<GUIVehicle*>((*i).second)->getGlID());
97  }
98  }
99 }
100 
101 
102 void
104  myLock.lock();
105 }
106 
107 
108 void
110  myLock.unlock();
111 }
112 
113 
114 
115 /****************************************************************************/
116 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:82
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
MFXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
SUMOTime computeRandomDepartOffset() const
compute (optional) random offset to the departure time
GUIVehicleControl()
Constructor.
void releaseVehicles()
unlock access to vehicle removal/additions for thread synchronization
static MTRand * getParsingRNG()
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
VehicleDictType myVehicleDict
Dictionary of vehicles.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
The car-following model and parameter.
Definition: MSVehicleType.h:74
SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, const MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true)
Builds a vehicle, increases the number of built vehicles.
SUMOReal computeChosenSpeedDeviation(MTRand *rng, const SUMOReal minDevFactor=0.2) const
Computes and returns the speed deviation.
Representation of a vehicle.
Definition: SUMOVehicle.h:66
SUMOTime depart
The vehicle&#39;s departure time.
bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
int myLoadedVehNo
The number of build vehicles.
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
The vehicle was built, but has not yet departed.
Definition: MSNet.h:539
void unlock()
release mutex lock
Definition: MFXMutex.cpp:96
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
Structure representing possible vehicle parameter.
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:71
void secureVehicles()
lock access to vehicle removal/additions for thread synchronization
void lock()
lock mutex
Definition: MFXMutex.cpp:86
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle&#39;s state change.
Definition: MSNet.cpp:773
~GUIVehicleControl()
Destructor.
void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
void insertVehicleIDs(std::vector< GUIGlID > &into)
Returns the list of all known vehicles by gl-id.
FXbool locked()
Definition: MFXMutex.h:70
The class responsible for building and deletion of vehicles.
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:61