SUMO - Simulation of Urban MObility
GUIVehicleControl.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // The class responsible for building and deletion of vehicles (gui-version)
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
34 #include "GUIVehicleControl.h"
35 #include "GUIVehicle.h"
36 #include "GUINet.h"
37 #include <gui/GUIGlobals.h>
38 
39 
40 // ===========================================================================
41 // member method definitions
42 // ===========================================================================
44  : MSVehicleControl() {}
45 
46 
48  // just to quit cleanly on a failure
49  if (myLock.locked()) {
50  myLock.unlock();
51  }
52 }
53 
54 
57  const MSRoute* route, MSVehicleType* type,
58  const bool ignoreStopErrors, const bool fromRouteFile) {
59  myLoadedVehNo++;
60  if (fromRouteFile) {
62  }
63  MSVehicle* built = new GUIVehicle(defs, route, type, type->computeChosenSpeedDeviation(fromRouteFile ? MSRouteHandler::getParsingRNG() : 0));
64  built->addStops(ignoreStopErrors);
66  return built;
67 }
68 
69 
70 bool
71 GUIVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
73  return MSVehicleControl::addVehicle(id, v);
74 }
75 
76 
77 void
80  MSVehicleControl::deleteVehicle(veh, discard);
81 }
82 
83 
84 void
85 GUIVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into, bool listParking, bool listTeleporting) {
87  into.reserve(myVehicleDict.size());
88  for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
89  SUMOVehicle* veh = (*i).second;
90  if (veh->isOnRoad() || (listParking && veh->isParking()) || listTeleporting) {
91  into.push_back(static_cast<GUIVehicle*>((*i).second)->getGlID());
92  }
93  }
94 }
95 
96 
97 void
99  myLock.lock();
100 }
101 
102 
103 void
105  myLock.unlock();
106 }
107 
108 
109 
110 /****************************************************************************/
111 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
MFXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
GUIVehicleControl()
Constructor.
void releaseVehicles()
unlock access to vehicle removal/additions for thread synchronization
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
VehicleDictType myVehicleDict
Dictionary of vehicles.
SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true)
Builds a vehicle, increases the number of built vehicles.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
void insertVehicleIDs(std::vector< GUIGlID > &into, bool listParking, bool listTeleporting)
Returns the list of all known vehicles by gl-id.
virtual bool isParking() const =0
Returns the information whether the vehicle is parked.
The car-following model and parameter.
Definition: MSVehicleType.h:72
double computeChosenSpeedDeviation(std::mt19937 *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
static std::mt19937 * getParsingRNG()
SUMOTime computeRandomDepartOffset() const
compute (optional) random offset to the departure time
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:484
void unlock()
release mutex lock
Definition: MFXMutex.cpp:93
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:70
void secureVehicles()
lock access to vehicle removal/additions for thread synchronization
void lock()
lock mutex
Definition: MFXMutex.cpp:83
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle&#39;s state change.
Definition: MSNet.cpp:849
~GUIVehicleControl()
Destructor.
void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
FXbool locked()
Definition: MFXMutex.h:69
The class responsible for building and deletion of vehicles.
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:60