Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2025 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// ===========================================================================
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 VehicleDefinitionSource source,
51 bool addRouteStops) {
52 MSVehicle* built = new GUIVehicle(defs, route, type, type->computeChosenSpeedDeviation(source == VehicleDefinitionSource::ROUTEFILE ? MSRouteHandler::getParsingRNG() : nullptr));
53 initVehicle(built, ignoreStopErrors, addRouteStops, source);
54 return built;
55}
56
57
58bool
59GUIVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
60 FXMutexLock locker(myLock);
61 return MSVehicleControl::addVehicle(id, v);
62}
63
64
65void
66GUIVehicleControl::deleteVehicle(SUMOVehicle* veh, bool discard, bool wasKept) {
67 FXMutexLock locker(myLock);
68 MSVehicleControl::deleteVehicle(veh, discard, wasKept);
69}
70
71
72int
77
78
79std::pair<double, double>
84
85
86void
87GUIVehicleControl::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
99void
103
104
105void
109
110
111/****************************************************************************/
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
GUIGlID getGlID() const
Returns the numerical id of the object.
virtual int getHaltingVehicleNo() const override
Returns the number of halting vehicles.
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
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 secureVehicles() override
lock access to vehicle removal/additions for thread synchronization
SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, ConstMSRoutePtr route, MSVehicleType *type, const bool ignoreStopErrors, const VehicleDefinitionSource source=VehicleDefinitionSource::ROUTEFILE, bool addRouteStops=true) override
Builds a vehicle, increases the number of built vehicles.
void releaseVehicles() override
unlock access to vehicle removal/additions for thread synchronization
~GUIVehicleControl()
Destructor.
void deleteVehicle(SUMOVehicle *v, bool discard=false, bool wasKept=false) override
Deletes the vehicle.
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.
VehicleDefinitionSource
possible origins of a vehicle definition
void initVehicle(MSBaseVehicle *built, const bool ignoreStopErrors, bool addRouteStops, const VehicleDefinitionSource source)
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.
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false, bool wasKept=false)
Deletes the vehicle.
VehicleDictType myVehicleDict
Dictionary of vehicles.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
The car-following model and parameter.
double computeChosenSpeedDeviation(SumoRNG *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
Representation of a vehicle.
Definition SUMOVehicle.h:62
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.