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-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 /****************************************************************************/
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 
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) {
63  return MEVehicleControl::addVehicle(id, v);
64 }
65 
66 
67 void
70  MEVehicleControl::deleteVehicle(veh, discard);
71 }
72 
73 
74 void
75 GUIMEVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into) {
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 
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
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
MFXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
void releaseVehicles()
unlock access to vehicle removal/additions for thread synchronization
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.
bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
void secureVehicles()
lock access to vehicle removal/additions for thread synchronization
void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
VehicleDictType myVehicleDict
Dictionary of vehicles.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:52
The car-following model and parameter.
Definition: MSVehicleType.h:66
static std::mt19937 * getParsingRNG()
GUIMEVehicleControl()
Constructor.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
void insertVehicleIDs(std::vector< GUIGlID > &into)
Returns the list of all known vehicles by gl-id.
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 class responsible for building and deletion of vehicles (gui-version)
The vehicle was built, but has not yet departed.
Definition: MSNet.h:496
void unlock()
release mutex lock
Definition: MFXMutex.cpp:87
~GUIMEVehicleControl()
Destructor.
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
Structure representing possible vehicle parameter.
A MSVehicle extended by some values for usage within the gui.
Definition: GUIMEVehicle.h:55
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:59
void lock()
lock mutex
Definition: MFXMutex.cpp:77
FXbool locked()
check if mutex is locked
Definition: MFXMutex.h:63
double computeChosenSpeedDeviation(std::mt19937 *rng, const double minDev=-1.) const
Computes and returns the speed deviation.