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