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 /****************************************************************************/
16 // The class responsible for building and deletion of vehicles (gui-version)
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <fx.h>
27 #include "GUIVehicleControl.h"
28 #include "GUIVehicle.h"
29 #include "GUINet.h"
30 #include <gui/GUIGlobals.h>
31 
32 
33 // ===========================================================================
34 // member method definitions
35 // ===========================================================================
37  : MSVehicleControl() {}
38 
39 
41  // just to quit cleanly on a failure
42  if (myLock.locked()) {
43  myLock.unlock();
44  }
45 }
46 
47 
50  const MSRoute* route, MSVehicleType* type,
51  const bool ignoreStopErrors, const bool fromRouteFile) {
52  myLoadedVehNo++;
53  MSVehicle* built = new GUIVehicle(defs, route, type, type->computeChosenSpeedDeviation(fromRouteFile ? MSRouteHandler::getParsingRNG() : nullptr));
54  built->addStops(ignoreStopErrors);
56  return built;
57 }
58 
59 
60 bool
61 GUIVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
62  FXMutexLock locker(myLock);
63  return MSVehicleControl::addVehicle(id, v);
64 }
65 
66 
67 void
69  FXMutexLock locker(myLock);
70  MSVehicleControl::deleteVehicle(veh, discard);
71 }
72 
73 
74 int
76  FXMutexLock locker(myLock);
78 }
79 
80 
81 std::pair<double, double>
83  FXMutexLock locker(myLock);
85 }
86 
87 
88 void
89 GUIVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into, bool listParking, bool listTeleporting) {
90  FXMutexLock locker(myLock);
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() || (listParking && veh->isParking()) || listTeleporting) {
95  into.push_back(static_cast<GUIVehicle*>((*i).second)->getGlID());
96  }
97  }
98 }
99 
100 
101 void
103  myLock.lock();
104 }
105 
106 
107 void
109  myLock.unlock();
110 }
111 
112 
113 
114 /****************************************************************************/
115 
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:65
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:61
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:894
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
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:102
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:297
GUINet.h
GUIVehicleControl::~GUIVehicleControl
~GUIVehicleControl()
Destructor.
Definition: GUIVehicleControl.cpp:40
MSRoute
Definition: MSRoute.h:66
MSVehicleControl::myLoadedVehNo
int myLoadedVehNo
The number of build vehicles.
Definition: MSVehicleControl.h:521
GUIVehicleControl::deleteVehicle
void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
Definition: GUIVehicleControl.cpp:68
GUIVehicleControl::getHaltingVehicleNo
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
Definition: GUIVehicleControl.cpp:75
MSVehicleControl::addVehicle
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
Definition: MSVehicleControl.cpp:215
MSVehicleType::computeChosenSpeedDeviation
double computeChosenSpeedDeviation(std::mt19937 *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
Definition: MSVehicleType.cpp:82
GUIVehicle
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:53
GUIGlobals.h
MSVehicleControl::myVehicleDict
VehicleDictType myVehicleDict
Dictionary of vehicles.
Definition: MSVehicleControl.h:569
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:149
MSVehicleControl::deleteVehicle
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
Definition: MSVehicleControl.cpp:250
GUIVehicleControl::getVehicleMeanSpeeds
virtual std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
Definition: GUIVehicleControl.cpp:82
MSNet::VEHICLE_STATE_BUILT
@ VEHICLE_STATE_BUILT
The vehicle was built, but has not yet departed.
Definition: MSNet.h:537
GUIVehicleControl::GUIVehicleControl
GUIVehicleControl()
Constructor.
Definition: GUIVehicleControl.cpp:36
MSBaseVehicle::addStops
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
Definition: MSBaseVehicle.cpp:593
MSVehicleControl::getHaltingVehicleNo
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
Definition: MSVehicleControl.cpp:402
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
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:49
GUIVehicleControl::releaseVehicles
void releaseVehicles()
unlock access to vehicle removal/additions for thread synchronization
Definition: GUIVehicleControl.cpp:108
MSRouteHandler::getParsingRNG
static std::mt19937 * getParsingRNG()
get parsing RNG
Definition: MSRouteHandler.h:62
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:89
MSVehicleControl::getVehicleMeanSpeeds
virtual std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
Definition: MSVehicleControl.cpp:416
config.h
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:71
GUIVehicleControl::myLock
FXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
Definition: GUIVehicleControl.h:124
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:79