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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // The class responsible for building and deletion of meso vehicles (gui-version)
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
32 #include <gui/GUIGlobals.h>
34 #include "GUIMEVehicleControl.h"
35 #include "GUIMEVehicle.h"
36 
37 
38 // ===========================================================================
39 // member method definitions
40 // ===========================================================================
42  : MEVehicleControl() {}
43 
44 
46  // just to quit cleanly on a failure
47  if (myLock.locked()) {
48  myLock.unlock();
49  }
50 }
51 
52 
55  const MSRoute* route, MSVehicleType* type,
56  const bool ignoreStopErrors, const bool fromRouteFile) {
57  myLoadedVehNo++;
58  if (fromRouteFile) {
60  }
61  MSBaseVehicle* built = new GUIMEVehicle(defs, route, type, type->computeChosenSpeedDeviation(fromRouteFile ? MSRouteHandler::getParsingRNG() : 0));
62  built->addStops(ignoreStopErrors);
64  return built;
65 }
66 
67 
68 
69 bool
70 GUIMEVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
72  return MEVehicleControl::addVehicle(id, v);
73 }
74 
75 
76 void
79  MEVehicleControl::deleteVehicle(veh, discard);
80 }
81 
82 
83 void
84 GUIMEVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into) {
86  into.reserve(myVehicleDict.size());
87  for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
88  SUMOVehicle* veh = (*i).second;
89  if (veh->isOnRoad()) {
90  into.push_back(static_cast<GUIMEVehicle*>((*i).second)->getGlID());
91  }
92  }
93 }
94 
95 
96 
97 void
99  myLock.lock();
100 }
101 
102 
103 void
105  myLock.unlock();
106 }
107 
108 
109 
110 /****************************************************************************/
111 
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 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:167
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:55
The car-following model and parameter.
Definition: MSVehicleType.h:72
double computeChosenSpeedDeviation(std::mt19937 *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
static std::mt19937 * getParsingRNG()
GUIMEVehicleControl()
Constructor.
SUMOTime computeRandomDepartOffset() const
compute (optional) random offset to the departure time
Representation of a vehicle.
Definition: SUMOVehicle.h:66
void insertVehicleIDs(std::vector< GUIGlID > &into)
Returns the list of all known vehicles by gl-id.
SUMOTime depart
The vehicle&#39;s departure time.
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:484
void unlock()
release mutex lock
Definition: MFXMutex.cpp:93
~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:61
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:70
void lock()
lock mutex
Definition: MFXMutex.cpp:83
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle&#39;s state change.
Definition: MSNet.cpp:849
FXbool locked()
Definition: MFXMutex.h:69