Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/mesogui/GUIMEVehicleControl.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file GUIMEVehicleControl.cpp
15
/// @author Jakob Erdmann
16
/// @date Okt 2012
17
///
18
// The class responsible for building and deletion of meso vehicles (gui-version)
19
/****************************************************************************/
20
#include <config.h>
21
22
#include <utils/foxtools/fxheader.h>
23
#include <utils/vehicle/SUMOVehicle.h>
24
#include <gui/GUIGlobals.h>
25
#include <microsim/MSRouteHandler.h>
26
#include "GUIMEVehicleControl.h"
27
#include "GUIMEVehicle.h"
28
29
30
// ===========================================================================
31
// member method definitions
32
// ===========================================================================
33
GUIMEVehicleControl::GUIMEVehicleControl()
34
: MEVehicleControl() {}
35
36
37
GUIMEVehicleControl::~GUIMEVehicleControl() {
38
// just to quit cleanly on a failure
39
if (myLock.locked()) {
40
myLock.unlock();
41
}
42
}
43
44
45
SUMOVehicle*
46
GUIMEVehicleControl::buildVehicle(SUMOVehicleParameter* defs,
47
ConstMSRoutePtr route, MSVehicleType* type,
48
const bool ignoreStopErrors, const VehicleDefinitionSource source,
49
bool addRouteStops) {
50
MSBaseVehicle* built = new GUIMEVehicle(defs, route, type, type->computeChosenSpeedDeviation(source == VehicleDefinitionSource::ROUTEFILE ? MSRouteHandler::getParsingRNG() : nullptr));
51
initVehicle(built, ignoreStopErrors, addRouteStops, source);
52
return built;
53
}
54
55
56
57
bool
58
GUIMEVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
59
FXMutexLock locker(myLock);
60
return MEVehicleControl::addVehicle(id, v);
61
}
62
63
64
void
65
GUIMEVehicleControl::deleteVehicle(SUMOVehicle* veh, bool discard, bool wasKept) {
66
FXMutexLock locker(myLock);
67
MEVehicleControl::deleteVehicle(veh, discard, wasKept);
68
}
69
70
71
void
72
GUIMEVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into) {
73
FXMutexLock locker(myLock);
74
into.reserve(myVehicleDict.size());
75
for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
76
SUMOVehicle* veh = (*i).second;
77
if (veh->isOnRoad()) {
78
into.push_back(static_cast<GUIMEVehicle*>((*i).second)->getGlID());
79
}
80
}
81
}
82
83
std::pair<double, double>
84
GUIMEVehicleControl::getVehicleMeanSpeeds() const {
85
FXMutexLock locker(myLock);
86
return MSVehicleControl::getVehicleMeanSpeeds();
87
}
88
89
90
int
91
GUIMEVehicleControl::getHaltingVehicleNo() const {
92
FXMutexLock locker(myLock);
93
return MSVehicleControl::getHaltingVehicleNo();
94
}
95
96
97
void
98
GUIMEVehicleControl::secureVehicles() {
99
myLock.lock();
100
}
101
102
103
void
104
GUIMEVehicleControl::releaseVehicles() {
105
myLock.unlock();
106
}
107
108
109
/****************************************************************************/
110
111