Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2026 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 GUIVehicleControl.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Michael Behrisch
18 : /// @date Wed, 10. Dec 2003
19 : ///
20 : // The class responsible for building and deletion of vehicles (gui-version)
21 : /****************************************************************************/
22 : #include <config.h>
23 :
24 : #include <utils/foxtools/fxheader.h>
25 : #include <microsim/MSRouteHandler.h>
26 : #include "GUIVehicleControl.h"
27 : #include "GUIVehicle.h"
28 : #include "GUINet.h"
29 : #include <gui/GUIGlobals.h>
30 :
31 :
32 : // ===========================================================================
33 : // member method definitions
34 : // ===========================================================================
35 5836 : GUIVehicleControl::GUIVehicleControl()
36 5836 : : MSVehicleControl() {}
37 :
38 :
39 11616 : GUIVehicleControl::~GUIVehicleControl() {
40 : // just to quit cleanly on a failure
41 5808 : if (myLock.locked()) {
42 0 : myLock.unlock();
43 : }
44 11616 : }
45 :
46 :
47 : SUMOVehicle*
48 641576 : GUIVehicleControl::buildVehicle(SUMOVehicleParameter* defs,
49 : ConstMSRoutePtr route, MSVehicleType* type,
50 : const bool ignoreStopErrors, const VehicleDefinitionSource source,
51 : bool addRouteStops) {
52 666686 : const double speedFactor = type->computeChosenSpeedDeviation(defs->speedFactor, source == VehicleDefinitionSource::ROUTEFILE ? MSRouteHandler::getParsingRNG() : nullptr);
53 1283152 : MSVehicle* built = new GUIVehicle(defs, route, type, speedFactor);
54 641576 : initVehicle(built, ignoreStopErrors, addRouteStops, source);
55 641568 : return built;
56 : }
57 :
58 :
59 : bool
60 621835 : GUIVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
61 621835 : FXMutexLock locker(myLock);
62 1243670 : return MSVehicleControl::addVehicle(id, v);
63 : }
64 :
65 :
66 : void
67 588288 : GUIVehicleControl::deleteVehicle(SUMOVehicle* veh, bool discard, bool wasKept) {
68 588288 : FXMutexLock locker(myLock);
69 588288 : MSVehicleControl::deleteVehicle(veh, discard, wasKept);
70 588288 : }
71 :
72 :
73 : int
74 22179 : GUIVehicleControl::getHaltingVehicleNo() const {
75 22179 : FXMutexLock locker(myLock);
76 44358 : return MSVehicleControl::getHaltingVehicleNo();
77 : }
78 :
79 :
80 : std::pair<double, double>
81 22179 : GUIVehicleControl::getVehicleMeanSpeeds() const {
82 22179 : FXMutexLock locker(myLock);
83 44358 : return MSVehicleControl::getVehicleMeanSpeeds();
84 : }
85 :
86 :
87 : void
88 0 : GUIVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into, bool listParking, bool listTeleporting) {
89 0 : FXMutexLock locker(myLock);
90 0 : into.reserve(myVehicleDict.size());
91 0 : for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
92 0 : SUMOVehicle* veh = (*i).second;
93 0 : if (veh->isOnRoad() || (listParking && veh->isParking()) || listTeleporting) {
94 0 : into.push_back(static_cast<GUIVehicle*>((*i).second)->getGlID());
95 : }
96 : }
97 0 : }
98 :
99 :
100 : void
101 0 : GUIVehicleControl::secureVehicles() {
102 0 : myLock.lock();
103 0 : }
104 :
105 :
106 : void
107 0 : GUIVehicleControl::releaseVehicles() {
108 0 : myLock.unlock();
109 0 : }
110 :
111 :
112 : /****************************************************************************/
|