Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2024 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 2491 : GUIMEVehicleControl::GUIMEVehicleControl()
34 2491 : : MEVehicleControl() {}
35 :
36 :
37 4982 : GUIMEVehicleControl::~GUIMEVehicleControl() {
38 : // just to quit cleanly on a failure
39 2491 : if (myLock.locked()) {
40 0 : myLock.unlock();
41 : }
42 4982 : }
43 :
44 :
45 : SUMOVehicle*
46 287386 : GUIMEVehicleControl::buildVehicle(SUMOVehicleParameter* defs,
47 : ConstMSRoutePtr route, MSVehicleType* type,
48 : const bool ignoreStopErrors, const VehicleDefinitionSource source,
49 : bool addRouteStops) {
50 581458 : MSBaseVehicle* built = new GUIMEVehicle(defs, route, type, type->computeChosenSpeedDeviation(source == VehicleDefinitionSource::ROUTEFILE ? MSRouteHandler::getParsingRNG() : nullptr));
51 287386 : initVehicle(built, ignoreStopErrors, addRouteStops, source);
52 287382 : return built;
53 : }
54 :
55 :
56 :
57 : bool
58 287138 : GUIMEVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
59 287138 : FXMutexLock locker(myLock);
60 574276 : return MEVehicleControl::addVehicle(id, v);
61 : }
62 :
63 :
64 : void
65 263959 : GUIMEVehicleControl::deleteVehicle(SUMOVehicle* veh, bool discard, bool wasKept) {
66 263959 : FXMutexLock locker(myLock);
67 263959 : MEVehicleControl::deleteVehicle(veh, discard, wasKept);
68 263959 : }
69 :
70 :
71 : void
72 0 : GUIMEVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into) {
73 0 : FXMutexLock locker(myLock);
74 0 : into.reserve(myVehicleDict.size());
75 0 : for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
76 0 : SUMOVehicle* veh = (*i).second;
77 0 : if (veh->isOnRoad()) {
78 0 : into.push_back(static_cast<GUIMEVehicle*>((*i).second)->getGlID());
79 : }
80 : }
81 0 : }
82 :
83 : std::pair<double, double>
84 19637 : GUIMEVehicleControl::getVehicleMeanSpeeds() const {
85 19637 : FXMutexLock locker(myLock);
86 39274 : return MSVehicleControl::getVehicleMeanSpeeds();
87 : }
88 :
89 :
90 : int
91 19637 : GUIMEVehicleControl::getHaltingVehicleNo() const {
92 19637 : FXMutexLock locker(myLock);
93 39274 : return MSVehicleControl::getHaltingVehicleNo();
94 : }
95 :
96 :
97 : void
98 323253 : GUIMEVehicleControl::secureVehicles() {
99 323253 : myLock.lock();
100 323253 : }
101 :
102 :
103 : void
104 323253 : GUIMEVehicleControl::releaseVehicles() {
105 323253 : myLock.unlock();
106 323253 : }
107 :
108 :
109 : /****************************************************************************/
|