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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // The class responsible for building and deletion of vehicles (gui-version)
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
28 #include "GUIVehicleControl.h"
29 #include "GUIVehicle.h"
30 #include "GUINet.h"
31 #include <gui/GUIGlobals.h>
32 
33 
34 // ===========================================================================
35 // member method definitions
36 // ===========================================================================
38  : MSVehicleControl() {}
39 
40 
42  // just to quit cleanly on a failure
43  if (myLock.locked()) {
44  myLock.unlock();
45  }
46 }
47 
48 
51  const MSRoute* route, MSVehicleType* type,
52  const bool ignoreStopErrors, const bool fromRouteFile) {
53  myLoadedVehNo++;
54  MSVehicle* built = new GUIVehicle(defs, route, type, type->computeChosenSpeedDeviation(fromRouteFile ? MSRouteHandler::getParsingRNG() : nullptr));
55  built->addStops(ignoreStopErrors);
57  return built;
58 }
59 
60 
61 bool
62 GUIVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
64  return MSVehicleControl::addVehicle(id, v);
65 }
66 
67 
68 void
71  MSVehicleControl::deleteVehicle(veh, discard);
72 }
73 
74 
75 int
79 }
80 
81 
82 std::pair<double, double>
86 }
87 
88 
89 void
90 GUIVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into, bool listParking, bool listTeleporting) {
92  into.reserve(myVehicleDict.size());
93  for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
94  SUMOVehicle* veh = (*i).second;
95  if (veh->isOnRoad() || (listParking && veh->isParking()) || listTeleporting) {
96  into.push_back(static_cast<GUIVehicle*>((*i).second)->getGlID());
97  }
98  }
99 }
100 
101 
102 void
104  myLock.lock();
105 }
106 
107 
108 void
110  myLock.unlock();
111 }
112 
113 
114 
115 /****************************************************************************/
116 
virtual std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
MFXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to, const std::string &info="")
Informs all added listeners about a vehicle&#39;s state change.
Definition: MSNet.cpp:855
GUIVehicleControl()
Constructor.
void releaseVehicles()
unlock access to vehicle removal/additions for thread synchronization
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
VehicleDictType myVehicleDict
Dictionary of vehicles.
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.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
void insertVehicleIDs(std::vector< GUIGlID > &into, bool listParking, bool listTeleporting)
Returns the list of all known vehicles by gl-id.
virtual bool isParking() const =0
Returns the information whether the vehicle is parked.
The car-following model and parameter.
Definition: MSVehicleType.h:66
static std::mt19937 * getParsingRNG()
virtual std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
Representation of a vehicle.
Definition: SUMOVehicle.h:60
bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
int myLoadedVehNo
The number of build vehicles.
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
The vehicle was built, but has not yet departed.
Definition: MSNet.h:496
void unlock()
release mutex lock
Definition: MFXMutex.cpp:87
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
Structure representing possible vehicle parameter.
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:59
void secureVehicles()
lock access to vehicle removal/additions for thread synchronization
void lock()
lock mutex
Definition: MFXMutex.cpp:77
~GUIVehicleControl()
Destructor.
void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
FXbool locked()
check if mutex is locked
Definition: MFXMutex.h:63
The class responsible for building and deletion of vehicles.
double computeChosenSpeedDeviation(std::mt19937 *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:54