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.org/sumo
3 // Copyright (C) 2001-2019 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 /****************************************************************************/
15 // The class responsible for building and deletion of meso vehicles (gui-version)
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <fx.h>
26 #include <gui/GUIGlobals.h>
28 #include "GUIMEVehicleControl.h"
29 #include "GUIMEVehicle.h"
30 
31 
32 // ===========================================================================
33 // member method definitions
34 // ===========================================================================
36  : MEVehicleControl() {}
37 
38 
40  // just to quit cleanly on a failure
41  if (myLock.locked()) {
42  myLock.unlock();
43  }
44 }
45 
46 
49  const MSRoute* route, MSVehicleType* type,
50  const bool ignoreStopErrors, const bool fromRouteFile) {
51  myLoadedVehNo++;
52  MSBaseVehicle* built = new GUIMEVehicle(defs, route, type, type->computeChosenSpeedDeviation(fromRouteFile ? MSRouteHandler::getParsingRNG() : nullptr));
53  built->addStops(ignoreStopErrors);
55  return built;
56 }
57 
58 
59 
60 bool
61 GUIMEVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
62  FXMutexLock locker(myLock);
63  return MEVehicleControl::addVehicle(id, v);
64 }
65 
66 
67 void
69  FXMutexLock locker(myLock);
70  MEVehicleControl::deleteVehicle(veh, discard);
71 }
72 
73 
74 void
75 GUIMEVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into) {
76  FXMutexLock locker(myLock);
77  into.reserve(myVehicleDict.size());
78  for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
79  SUMOVehicle* veh = (*i).second;
80  if (veh->isOnRoad()) {
81  into.push_back(static_cast<GUIMEVehicle*>((*i).second)->getGlID());
82  }
83  }
84 }
85 
86 
87 
88 void
90  myLock.lock();
91 }
92 
93 
94 void
96  myLock.unlock();
97 }
98 
99 
100 
101 /****************************************************************************/
102 
GUIMEVehicle.h
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:66
GUIMEVehicleControl::GUIMEVehicleControl
GUIMEVehicleControl()
Constructor.
Definition: GUIMEVehicleControl.cpp:35
GUIMEVehicleControl::insertVehicleIDs
void insertVehicleIDs(std::vector< GUIGlID > &into)
Returns the list of all known vehicles by gl-id.
Definition: GUIMEVehicleControl.cpp:75
GUIMEVehicleControl.h
MSNet::informVehicleStateListener
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to, const std::string &info="")
Informs all added listeners about a vehicle's state change.
Definition: MSNet.cpp:882
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:61
SUMOVehicle::isOnRoad
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
GUIMEVehicle
A MSVehicle extended by some values for usage within the gui.
Definition: GUIMEVehicle.h:55
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:291
MSRoute
Definition: MSRoute.h:67
MSVehicleControl::myLoadedVehNo
int myLoadedVehNo
The number of build vehicles.
Definition: MSVehicleControl.h:533
SUMOVehicle.h
MSVehicleControl::addVehicle
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
Definition: MSVehicleControl.cpp:210
MSVehicleType::computeChosenSpeedDeviation
double computeChosenSpeedDeviation(std::mt19937 *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
Definition: MSVehicleType.cpp:83
GUIMEVehicleControl::releaseVehicles
void releaseVehicles()
unlock access to vehicle removal/additions for thread synchronization
Definition: GUIMEVehicleControl.cpp:95
GUIGlobals.h
MSVehicleControl::myVehicleDict
VehicleDictType myVehicleDict
Dictionary of vehicles.
Definition: MSVehicleControl.h:581
MSVehicleControl::deleteVehicle
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
Definition: MSVehicleControl.cpp:245
GUIMEVehicleControl::~GUIMEVehicleControl
~GUIMEVehicleControl()
Destructor.
Definition: GUIMEVehicleControl.cpp:39
MSNet::VEHICLE_STATE_BUILT
The vehicle was built, but has not yet departed.
Definition: MSNet.h:538
MEVehicleControl
The class responsible for building and deletion of vehicles (gui-version)
Definition: MEVehicleControl.h:43
GUIMEVehicleControl::addVehicle
bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
Definition: GUIMEVehicleControl.cpp:61
MSBaseVehicle::addStops
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
Definition: MSBaseVehicle.cpp:559
GUIMEVehicleControl::deleteVehicle
void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
Definition: GUIMEVehicleControl.cpp:68
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
MSRouteHandler::getParsingRNG
static std::mt19937 * getParsingRNG()
get parsing RNG
Definition: MSRouteHandler.h:63
MSBaseVehicle
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:52
config.h
GUIMEVehicleControl::buildVehicle
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.
Definition: GUIMEVehicleControl.cpp:48
GUIMEVehicleControl::secureVehicles
void secureVehicles()
lock access to vehicle removal/additions for thread synchronization
Definition: GUIMEVehicleControl.cpp:89
MSRouteHandler.h
GUIMEVehicleControl::myLock
FXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
Definition: GUIMEVehicleControl.h:104