Eclipse SUMO - Simulation of Urban MObility
GUIMEVehicleControl.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 /****************************************************************************/
18 // The class responsible for building and deletion of meso vehicles (gui-version)
19 /****************************************************************************/
20 #include <config.h>
21 
24 #include <gui/GUIGlobals.h>
26 #include "GUIMEVehicleControl.h"
27 #include "GUIMEVehicle.h"
28 
29 
30 // ===========================================================================
31 // member method definitions
32 // ===========================================================================
34  : MEVehicleControl() {}
35 
36 
38  // just to quit cleanly on a failure
39  if (myLock.locked()) {
40  myLock.unlock();
41  }
42 }
43 
44 
47  ConstMSRoutePtr route, MSVehicleType* type,
48  const bool ignoreStopErrors, const bool fromRouteFile,
49  bool addRouteStops) {
50  MSBaseVehicle* built = new GUIMEVehicle(defs, route, type, type->computeChosenSpeedDeviation(fromRouteFile ? MSRouteHandler::getParsingRNG() : nullptr));
51  initVehicle(built, ignoreStopErrors, addRouteStops);
52  return built;
53 }
54 
55 
56 
57 bool
58 GUIMEVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
59  FXMutexLock locker(myLock);
60  return MEVehicleControl::addVehicle(id, v);
61 }
62 
63 
64 void
65 GUIMEVehicleControl::deleteVehicle(SUMOVehicle* veh, bool discard, bool wasKept) {
66  FXMutexLock locker(myLock);
67  MEVehicleControl::deleteVehicle(veh, discard, wasKept);
68 }
69 
70 
71 void
72 GUIMEVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into) {
73  FXMutexLock locker(myLock);
74  into.reserve(myVehicleDict.size());
75  for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
76  SUMOVehicle* veh = (*i).second;
77  if (veh->isOnRoad()) {
78  into.push_back(static_cast<GUIMEVehicle*>((*i).second)->getGlID());
79  }
80  }
81 }
82 
83 std::pair<double, double>
85  FXMutexLock locker(myLock);
87 }
88 
89 
90 int
92  FXMutexLock locker(myLock);
94 }
95 
96 
97 void
99  myLock.lock();
100 }
101 
102 
103 void
105  myLock.unlock();
106 }
107 
108 
109 /****************************************************************************/
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition: Route.h:31
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:104
GUIMEVehicleControl()
Constructor.
virtual std::pair< double, double > getVehicleMeanSpeeds() const override
get current absolute and relative mean vehicle speed in the network
void secureVehicles()
lock access to vehicle removal/additions for thread synchronization
bool addVehicle(const std::string &id, SUMOVehicle *v) override
Tries to insert the vehicle into the internal vehicle container.
virtual int getHaltingVehicleNo() const override
Returns the number of halting vehicles.
~GUIMEVehicleControl()
Destructor.
void releaseVehicles()
unlock access to vehicle removal/additions for thread synchronization
void deleteVehicle(SUMOVehicle *v, bool discard=false, bool wasKept=false) override
Deletes the vehicle.
FXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
void insertVehicleIDs(std::vector< GUIGlID > &into)
Returns the list of all known vehicles by gl-id.
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.
A MSVehicle extended by some values for usage within the gui.
Definition: GUIMEVehicle.h:52
The class responsible for building and deletion of vehicles (gui-version)
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:55
static SumoRNG * getParsingRNG()
get parsing RNG
void initVehicle(MSBaseVehicle *built, const bool ignoreStopErrors, bool addRouteStops)
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.
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)
Structure representing possible vehicle parameter.