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.dev/sumo
3 // Copyright (C) 2001-2024 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 
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  ConstMSRoutePtr route, MSVehicleType* type,
50  const bool ignoreStopErrors, const bool fromRouteFile,
51  bool addRouteStops) {
52  MSVehicle* built = new GUIVehicle(defs, route, type, type->computeChosenSpeedDeviation(fromRouteFile ? MSRouteHandler::getParsingRNG() : nullptr));
53  initVehicle(built, ignoreStopErrors, addRouteStops);
54  return built;
55 }
56 
57 
58 bool
59 GUIVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
60  FXMutexLock locker(myLock);
61  return MSVehicleControl::addVehicle(id, v);
62 }
63 
64 
65 void
67  FXMutexLock locker(myLock);
68  MSVehicleControl::deleteVehicle(veh, discard);
69 }
70 
71 
72 int
74  FXMutexLock locker(myLock);
76 }
77 
78 
79 std::pair<double, double>
81  FXMutexLock locker(myLock);
83 }
84 
85 
86 void
87 GUIVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into, bool listParking, bool listTeleporting) {
88  FXMutexLock locker(myLock);
89  into.reserve(myVehicleDict.size());
90  for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
91  SUMOVehicle* veh = (*i).second;
92  if (veh->isOnRoad() || (listParking && veh->isParking()) || listTeleporting) {
93  into.push_back(static_cast<GUIVehicle*>((*i).second)->getGlID());
94  }
95  }
96 }
97 
98 
99 void
101  myLock.lock();
102 }
103 
104 
105 void
107  myLock.unlock();
108 }
109 
110 
111 /****************************************************************************/
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition: Route.h:31
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:104
virtual int getHaltingVehicleNo() const override
Returns the number of halting vehicles.
void secureVehicles()
lock access to vehicle removal/additions for thread synchronization
FXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
virtual std::pair< double, double > getVehicleMeanSpeeds() const override
get current absolute and relative mean vehicle speed in the network
SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, ConstMSRoutePtr route, MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true, bool addRouteStops=true) override
Builds a vehicle, increases the number of built vehicles.
void insertVehicleIDs(std::vector< GUIGlID > &into, bool listParking, bool listTeleporting)
Returns the list of all known vehicles by gl-id.
bool addVehicle(const std::string &id, SUMOVehicle *v) override
Tries to insert the vehicle into the internal vehicle container.
void deleteVehicle(SUMOVehicle *v, bool discard=false) override
Deletes the vehicle.
void releaseVehicles()
unlock access to vehicle removal/additions for thread synchronization
~GUIVehicleControl()
Destructor.
GUIVehicleControl()
Constructor.
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:51
static SumoRNG * getParsingRNG()
get parsing RNG
The class responsible for building and deletion of vehicles.
void initVehicle(MSBaseVehicle *built, const bool ignoreStopErrors, bool addRouteStops)
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
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:63
double computeChosenSpeedDeviation(SumoRNG *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
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.