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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // The class responsible for building and deletion of vehicles (gui-version)
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include <fx.h>
26 #include "GUIVehicleControl.h"
27 #include "GUIVehicle.h"
28 #include "GUINet.h"
29 #include <gui/GUIGlobals.h>
30 
31 
32 // ===========================================================================
33 // member method definitions
34 // ===========================================================================
36  : MSVehicleControl() {}
37 
38 
40  // just to quit cleanly on a failure
41  if (myLock.locked()) {
42  myLock.unlock();
43  }
44 }
45 
46 
49  const MSRoute* route, MSVehicleType* type,
50  const bool ignoreStopErrors, const bool fromRouteFile) {
51  MSVehicle* built = new GUIVehicle(defs, route, type, type->computeChosenSpeedDeviation(fromRouteFile ? MSRouteHandler::getParsingRNG() : nullptr));
52  initVehicle(built, ignoreStopErrors);
53  return built;
54 }
55 
56 
57 bool
58 GUIVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
59  FXMutexLock locker(myLock);
60  return MSVehicleControl::addVehicle(id, v);
61 }
62 
63 
64 void
66  FXMutexLock locker(myLock);
67  MSVehicleControl::deleteVehicle(veh, discard);
68 }
69 
70 
71 int
73  FXMutexLock locker(myLock);
75 }
76 
77 
78 std::pair<double, double>
80  FXMutexLock locker(myLock);
82 }
83 
84 
85 void
86 GUIVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into, bool listParking, bool listTeleporting) {
87  FXMutexLock locker(myLock);
88  into.reserve(myVehicleDict.size());
89  for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
90  SUMOVehicle* veh = (*i).second;
91  if (veh->isOnRoad() || (listParking && veh->isParking()) || listTeleporting) {
92  into.push_back(static_cast<GUIVehicle*>((*i).second)->getGlID());
93  }
94  }
95 }
96 
97 
98 void
100  myLock.lock();
101 }
102 
103 
104 void
106  myLock.unlock();
107 }
108 
109 
110 /****************************************************************************/
GUIGlID getGlID() const
Returns the numerical id of the object.
virtual std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
void secureVehicles()
lock access to vehicle removal/additions for thread synchronization
FXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
void insertVehicleIDs(std::vector< GUIGlID > &into, bool listParking, bool listTeleporting)
Returns the list of all known vehicles by gl-id.
void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
void releaseVehicles()
unlock access to vehicle removal/additions for thread synchronization
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
~GUIVehicleControl()
Destructor.
GUIVehicleControl()
Constructor.
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.
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:51
static std::mt19937 * getParsingRNG()
get parsing RNG
The class responsible for building and deletion of vehicles.
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
virtual std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
void initVehicle(MSBaseVehicle *built, const bool ignoreStopErrors)
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
VehicleDictType myVehicleDict
Dictionary of vehicles.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
The car-following model and parameter.
Definition: MSVehicleType.h:62
double computeChosenSpeedDeviation(std::mt19937 *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
Representation of a vehicle.
Definition: SUMOVehicle.h:58
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
virtual bool isParking() const =0
Returns the information whether the vehicle is parked.
Structure representing possible vehicle parameter.