Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // The class responsible for building and deletion of vehicles (gui-version)
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <fx.h>
28 #include "GUIVehicleControl.h"
29 #include "GUIVehicle.h"
30 #include "GUINet.h"
31 #include <gui/GUIGlobals.h>
32 
33 
34 // ===========================================================================
35 // member method definitions
36 // ===========================================================================
38  : MSVehicleControl() {}
39 
40 
42  // just to quit cleanly on a failure
43  if (myLock.locked()) {
44  myLock.unlock();
45  }
46 }
47 
48 
51  const MSRoute* route, MSVehicleType* type,
52  const bool ignoreStopErrors, const bool fromRouteFile) {
53  myLoadedVehNo++;
54  MSVehicle* built = new GUIVehicle(defs, route, type, type->computeChosenSpeedDeviation(fromRouteFile ? MSRouteHandler::getParsingRNG() : nullptr));
55  built->addStops(ignoreStopErrors);
57  return built;
58 }
59 
60 
61 bool
62 GUIVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
63  FXMutexLock locker(myLock);
64  return MSVehicleControl::addVehicle(id, v);
65 }
66 
67 
68 void
70  FXMutexLock locker(myLock);
71  MSVehicleControl::deleteVehicle(veh, discard);
72 }
73 
74 
75 int
77  FXMutexLock locker(myLock);
79 }
80 
81 
82 std::pair<double, double>
84  FXMutexLock locker(myLock);
86 }
87 
88 
89 void
90 GUIVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into, bool listParking, bool listTeleporting) {
91  FXMutexLock locker(myLock);
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() || (listParking && veh->isParking()) || listTeleporting) {
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 
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:66
GUIVehicle.h
GUIVehicleControl::addVehicle
bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
Definition: GUIVehicleControl.cpp:62
GUIVehicleControl.h
MSNet::informVehicleStateListener
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to, const std::string &info="")
Informs all added listeners about a vehicle's state change.
Definition: MSNet.cpp:882
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:61
SUMOVehicle::isOnRoad
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
GUIVehicleControl::secureVehicles
void secureVehicles()
lock access to vehicle removal/additions for thread synchronization
Definition: GUIVehicleControl.cpp:103
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:291
GUINet.h
GUIVehicleControl::~GUIVehicleControl
~GUIVehicleControl()
Destructor.
Definition: GUIVehicleControl.cpp:41
MSRoute
Definition: MSRoute.h:67
MSVehicleControl::myLoadedVehNo
int myLoadedVehNo
The number of build vehicles.
Definition: MSVehicleControl.h:533
GUIVehicleControl::deleteVehicle
void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
Definition: GUIVehicleControl.cpp:69
GUIVehicleControl::getHaltingVehicleNo
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
Definition: GUIVehicleControl.cpp:76
MSVehicleControl::addVehicle
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
Definition: MSVehicleControl.cpp:210
MSVehicleType::computeChosenSpeedDeviation
double computeChosenSpeedDeviation(std::mt19937 *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
Definition: MSVehicleType.cpp:83
GUIVehicle
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:54
GUIGlobals.h
MSVehicleControl::myVehicleDict
VehicleDictType myVehicleDict
Dictionary of vehicles.
Definition: MSVehicleControl.h:581
MSVehicleControl::deleteVehicle
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
Definition: MSVehicleControl.cpp:245
GUIVehicleControl::getVehicleMeanSpeeds
virtual std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
Definition: GUIVehicleControl.cpp:83
MSNet::VEHICLE_STATE_BUILT
The vehicle was built, but has not yet departed.
Definition: MSNet.h:538
GUIVehicleControl::GUIVehicleControl
GUIVehicleControl()
Constructor.
Definition: GUIVehicleControl.cpp:37
MSBaseVehicle::addStops
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
Definition: MSBaseVehicle.cpp:559
MSVehicleControl::getHaltingVehicleNo
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
Definition: MSVehicleControl.cpp:438
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
GUIVehicleControl::buildVehicle
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.
Definition: GUIVehicleControl.cpp:50
GUIVehicleControl::releaseVehicles
void releaseVehicles()
unlock access to vehicle removal/additions for thread synchronization
Definition: GUIVehicleControl.cpp:109
MSRouteHandler::getParsingRNG
static std::mt19937 * getParsingRNG()
get parsing RNG
Definition: MSRouteHandler.h:63
GUIVehicleControl::insertVehicleIDs
void insertVehicleIDs(std::vector< GUIGlID > &into, bool listParking, bool listTeleporting)
Returns the list of all known vehicles by gl-id.
Definition: GUIVehicleControl.cpp:90
MSVehicleControl::getVehicleMeanSpeeds
virtual std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
Definition: MSVehicleControl.cpp:452
config.h
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:72
GUIVehicleControl::myLock
FXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
Definition: GUIVehicleControl.h:125
MSRouteHandler.h
SUMOVehicle::isParking
virtual bool isParking() const =0
Returns the information whether the vehicle is parked.
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80