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-2026 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 const double speedFactor = type->computeChosenSpeedDeviation(defs->speedFactor, source == VehicleDefinitionSource::ROUTEFILE ? MSRouteHandler::getParsingRNG() : nullptr);
53 MSVehicle* built = new GUIVehicle(defs, route, type, speedFactor);
54 initVehicle(built, ignoreStopErrors, addRouteStops, source);
55 return built;
56}
57
58
59bool
60GUIVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
61 FXMutexLock locker(myLock);
62 return MSVehicleControl::addVehicle(id, v);
63}
64
65
66void
67GUIVehicleControl::deleteVehicle(SUMOVehicle* veh, bool discard, bool wasKept) {
68 FXMutexLock locker(myLock);
69 MSVehicleControl::deleteVehicle(veh, discard, wasKept);
70}
71
72
73int
78
79
80std::pair<double, double>
85
86
87void
88GUIVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into, bool listParking, bool listTeleporting) {
89 FXMutexLock locker(myLock);
90 into.reserve(myVehicleDict.size());
91 for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
92 SUMOVehicle* veh = (*i).second;
93 if (veh->isOnRoad() || (listParking && veh->isParking()) || listTeleporting) {
94 into.push_back(static_cast<GUIVehicle*>((*i).second)->getGlID());
95 }
96 }
97}
98
99
100void
104
105
106void
110
111
112/****************************************************************************/
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:52
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(double speedFactorOverride, SumoRNG *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
Representation of a vehicle.
Definition SUMOVehicle.h:63
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.
double speedFactor
individual speedFactor (overriding distribution from vType)