SUMO - Simulation of Urban MObility
GUIVehicleControl.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // The class responsible for building and deletion of vehicles (gui-version)
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
35 #include "GUIVehicleControl.h"
36 #include "GUIVehicle.h"
37 #include "GUINet.h"
38 #include <gui/GUIGlobals.h>
39 
40 
41 // ===========================================================================
42 // member method definitions
43 // ===========================================================================
45  : MSVehicleControl() {}
46 
47 
49  // just to quit cleanly on a failure
50  if (myLock.locked()) {
51  myLock.unlock();
52  }
53 }
54 
55 
58  const MSRoute* route, const MSVehicleType* type,
59  const bool ignoreStopErrors, const bool fromRouteFile) {
60  myLoadedVehNo++;
61  if (fromRouteFile) {
63  }
64  MSVehicle* built = new GUIVehicle(defs, route, type, type->computeChosenSpeedDeviation(fromRouteFile ? MSRouteHandler::getParsingRNG() : 0));
65  built->addStops(ignoreStopErrors);
67  return built;
68 }
69 
70 
71 bool
72 GUIVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
74  return MSVehicleControl::addVehicle(id, v);
75 }
76 
77 
78 void
81  MSVehicleControl::deleteVehicle(veh, discard);
82 }
83 
84 
85 void
86 GUIVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into, bool listParking, bool listTeleporting) {
88  into.reserve(myVehicleDict.size());
89  for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
90  SUMOVehicle* veh = (*i).second;
91  if (veh->isOnRoad() || (listParking && veh->isParking()) || listTeleporting) {
92  into.push_back(static_cast<GUIVehicle*>((*i).second)->getGlID());
93  }
94  }
95 }
96 
97 
98 void
100  myLock.lock();
101 }
102 
103 
104 void
106  myLock.unlock();
107 }
108 
109 
110 
111 /****************************************************************************/
112 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
MFXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
SUMOTime computeRandomDepartOffset() const
compute (optional) random offset to the departure time
GUIVehicleControl()
Constructor.
void releaseVehicles()
unlock access to vehicle removal/additions for thread synchronization
static MTRand * getParsingRNG()
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:158
VehicleDictType myVehicleDict
Dictionary of 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:74
SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, const MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true)
Builds a vehicle, increases the number of built vehicles.
Representation of a vehicle.
Definition: SUMOVehicle.h:67
SUMOTime depart
The vehicle&#39;s departure time.
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:578
void unlock()
release mutex lock
Definition: MFXMutex.cpp:92
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
Structure representing possible vehicle parameter.
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:71
void secureVehicles()
lock access to vehicle removal/additions for thread synchronization
void lock()
lock mutex
Definition: MFXMutex.cpp:82
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle&#39;s state change.
Definition: MSNet.cpp:811
~GUIVehicleControl()
Destructor.
void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
FXbool locked()
Definition: MFXMutex.h:70
double computeChosenSpeedDeviation(MTRand *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
The class responsible for building and deletion of vehicles.
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:61