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