1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    GUIVehicleControl.cpp
11 /// @author  Daniel Krajzewicz
12 /// @author  Jakob Erdmann
13 /// @author  Michael Behrisch
14 /// @date    Wed, 10. Dec 2003
15 /// @version $Id$
16 ///
17 // The class responsible for building and deletion of vehicles (gui-version)
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <fx.h>
27 #include <microsim/MSRouteHandler.h>
28 #include "GUIVehicleControl.h"
29 #include "GUIVehicle.h"
30 #include "GUINet.h"
31 #include <gui/GUIGlobals.h>
32 
33 
34 // ===========================================================================
35 // member method definitions
36 // ===========================================================================
GUIVehicleControl()37 GUIVehicleControl::GUIVehicleControl()
38     : MSVehicleControl() {}
39 
40 
~GUIVehicleControl()41 GUIVehicleControl::~GUIVehicleControl() {
42     // just to quit cleanly on a failure
43     if (myLock.locked()) {
44         myLock.unlock();
45     }
46 }
47 
48 
49 SUMOVehicle*
buildVehicle(SUMOVehicleParameter * defs,const MSRoute * route,MSVehicleType * type,const bool ignoreStopErrors,const bool fromRouteFile)50 GUIVehicleControl::buildVehicle(SUMOVehicleParameter* defs,
51                                 const MSRoute* route, MSVehicleType* type,
52                                 const bool ignoreStopErrors, const bool fromRouteFile) {
53     myLoadedVehNo++;
54     MSVehicle* built = new GUIVehicle(defs, route, type, type->computeChosenSpeedDeviation(fromRouteFile ? MSRouteHandler::getParsingRNG() : nullptr));
55     built->addStops(ignoreStopErrors);
56     MSNet::getInstance()->informVehicleStateListener(built, MSNet::VEHICLE_STATE_BUILT);
57     return built;
58 }
59 
60 
61 bool
addVehicle(const std::string & id,SUMOVehicle * v)62 GUIVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
63     FXMutexLock locker(myLock);
64     return MSVehicleControl::addVehicle(id, v);
65 }
66 
67 
68 void
deleteVehicle(SUMOVehicle * veh,bool discard)69 GUIVehicleControl::deleteVehicle(SUMOVehicle* veh, bool discard) {
70     FXMutexLock locker(myLock);
71     MSVehicleControl::deleteVehicle(veh, discard);
72 }
73 
74 
75 int
getHaltingVehicleNo() const76 GUIVehicleControl::getHaltingVehicleNo() const {
77     FXMutexLock locker(myLock);
78     return MSVehicleControl::getHaltingVehicleNo();
79 }
80 
81 
82 std::pair<double, double>
getVehicleMeanSpeeds() const83 GUIVehicleControl::getVehicleMeanSpeeds() const {
84     FXMutexLock locker(myLock);
85     return MSVehicleControl::getVehicleMeanSpeeds();
86 }
87 
88 
89 void
insertVehicleIDs(std::vector<GUIGlID> & into,bool listParking,bool listTeleporting)90 GUIVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into, bool listParking, bool listTeleporting) {
91     FXMutexLock locker(myLock);
92     into.reserve(myVehicleDict.size());
93     for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
94         SUMOVehicle* veh = (*i).second;
95         if (veh->isOnRoad() || (listParking && veh->isParking()) || listTeleporting) {
96             into.push_back(static_cast<GUIVehicle*>((*i).second)->getGlID());
97         }
98     }
99 }
100 
101 
102 void
secureVehicles()103 GUIVehicleControl::secureVehicles() {
104     myLock.lock();
105 }
106 
107 
108 void
releaseVehicles()109 GUIVehicleControl::releaseVehicles() {
110     myLock.unlock();
111 }
112 
113 
114 
115 /****************************************************************************/
116 
117