SUMO - Simulation of Urban MObility
GUIMEVehicleControl.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // The class responsible for building and deletion of meso vehicles (gui-version)
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
33 #include <gui/GUIGlobals.h>
35 #include "GUIMEVehicleControl.h"
36 #include "GUIMEVehicle.h"
37 
38 
39 // ===========================================================================
40 // member method definitions
41 // ===========================================================================
43  : MEVehicleControl() {}
44 
45 
47  // just to quit cleanly on a failure
48  if (myLock.locked()) {
49  myLock.unlock();
50  }
51 }
52 
53 
56  const MSRoute* route, const MSVehicleType* type,
57  const bool ignoreStopErrors, const bool fromRouteFile) {
58  myLoadedVehNo++;
59  if (fromRouteFile) {
61  }
62  MSBaseVehicle* built = new GUIMEVehicle(defs, route, type, type->computeChosenSpeedDeviation(fromRouteFile ? MSRouteHandler::getParsingRNG() : 0));
63  built->addStops(ignoreStopErrors);
65  return built;
66 }
67 
68 
69 
70 bool
71 GUIMEVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
73  return MEVehicleControl::addVehicle(id, v);
74 }
75 
76 
77 void
80  MEVehicleControl::deleteVehicle(veh, discard);
81 }
82 
83 
84 void
85 GUIMEVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into) {
87  into.reserve(myVehicleDict.size());
88  for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
89  SUMOVehicle* veh = (*i).second;
90  if (veh->isOnRoad()) {
91  into.push_back(static_cast<GUIMEVehicle*>((*i).second)->getGlID());
92  }
93  }
94 }
95 
96 
97 
98 void
100  myLock.lock();
101 }
102 
103 
104 void
106  myLock.unlock();
107 }
108 
109 
110 
111 /****************************************************************************/
112 
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
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
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
static MTRand * getParsingRNG()
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: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.
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:56
The car-following model and parameter.
Definition: MSVehicleType.h:74
double computeChosenSpeedDeviation(MTRand *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
GUIMEVehicleControl()
Constructor.
SUMOTime computeRandomDepartOffset() const
compute (optional) random offset to the departure time
Representation of a vehicle.
Definition: SUMOVehicle.h:67
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.
The class responsible for building and deletion of vehicles (gui-version)
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.
The vehicle was built, but has not yet departed.
Definition: MSNet.h:578
void unlock()
release mutex lock
Definition: MFXMutex.cpp:92
~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:71
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
FXbool locked()
Definition: MFXMutex.h:70