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    GUIMEVehicleControl.cpp
11 /// @author  Jakob Erdmann
12 /// @date    Okt 2012
13 /// @version $Id$
14 ///
15 // The class responsible for building and deletion of meso vehicles (gui-version)
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <fx.h>
25 #include <utils/vehicle/SUMOVehicle.h>
26 #include <gui/GUIGlobals.h>
27 #include <microsim/MSRouteHandler.h>
28 #include "GUIMEVehicleControl.h"
29 #include "GUIMEVehicle.h"
30 
31 
32 // ===========================================================================
33 // member method definitions
34 // ===========================================================================
GUIMEVehicleControl()35 GUIMEVehicleControl::GUIMEVehicleControl()
36     : MEVehicleControl() {}
37 
38 
~GUIMEVehicleControl()39 GUIMEVehicleControl::~GUIMEVehicleControl() {
40     // just to quit cleanly on a failure
41     if (myLock.locked()) {
42         myLock.unlock();
43     }
44 }
45 
46 
47 SUMOVehicle*
buildVehicle(SUMOVehicleParameter * defs,const MSRoute * route,MSVehicleType * type,const bool ignoreStopErrors,const bool fromRouteFile)48 GUIMEVehicleControl::buildVehicle(SUMOVehicleParameter* defs,
49                                   const MSRoute* route, MSVehicleType* type,
50                                   const bool ignoreStopErrors, const bool fromRouteFile) {
51     myLoadedVehNo++;
52     MSBaseVehicle* built = new GUIMEVehicle(defs, route, type, type->computeChosenSpeedDeviation(fromRouteFile ? MSRouteHandler::getParsingRNG() : nullptr));
53     built->addStops(ignoreStopErrors);
54     MSNet::getInstance()->informVehicleStateListener(built, MSNet::VEHICLE_STATE_BUILT);
55     return built;
56 }
57 
58 
59 
60 bool
addVehicle(const std::string & id,SUMOVehicle * v)61 GUIMEVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
62     FXMutexLock locker(myLock);
63     return MEVehicleControl::addVehicle(id, v);
64 }
65 
66 
67 void
deleteVehicle(SUMOVehicle * veh,bool discard)68 GUIMEVehicleControl::deleteVehicle(SUMOVehicle* veh, bool discard) {
69     FXMutexLock locker(myLock);
70     MEVehicleControl::deleteVehicle(veh, discard);
71 }
72 
73 
74 void
insertVehicleIDs(std::vector<GUIGlID> & into)75 GUIMEVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into) {
76     FXMutexLock locker(myLock);
77     into.reserve(myVehicleDict.size());
78     for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
79         SUMOVehicle* veh = (*i).second;
80         if (veh->isOnRoad()) {
81             into.push_back(static_cast<GUIMEVehicle*>((*i).second)->getGlID());
82         }
83     }
84 }
85 
86 
87 
88 void
secureVehicles()89 GUIMEVehicleControl::secureVehicles() {
90     myLock.lock();
91 }
92 
93 
94 void
releaseVehicles()95 GUIMEVehicleControl::releaseVehicles() {
96     myLock.unlock();
97 }
98 
99 
100 
101 /****************************************************************************/
102 
103