1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2003-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.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Michael Behrisch
13 /// @author  Jakob Erdmann
14 /// @date    Wed, 10. Dec 2003
15 /// @version $Id$
16 ///
17 // The class responsible for building and deletion of vehicles (gui-version)
18 /****************************************************************************/
19 #ifndef GUIVehicleControl_h
20 #define GUIVehicleControl_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <vector>
29 #include <fx.h>
30 #include <microsim/MSVehicleControl.h>
31 #include <utils/gui/globjects/GUIGlObject.h>
32 
33 
34 // ===========================================================================
35 // class definitions
36 // ===========================================================================
37 /**
38  * @class GUIVehicleControl
39  * @brief The class responsible for building and deletion of vehicles (gui-version)
40  *
41  * Builds GUIVehicle instances instead of MSVehicle.
42  *
43  * @see MSVehicleControl
44  * @todo This is partially unsecure due to concurrent access...
45  * @todo Recheck vehicle deletion
46  */
47 class GUIVehicleControl : public MSVehicleControl {
48 public:
49     /// @brief Constructor
50     GUIVehicleControl();
51 
52 
53     /// @brief Destructor
54     ~GUIVehicleControl();
55 
56 
57     /// @name Vehicle creation
58     /// @{
59 
60     /** @brief Builds a vehicle, increases the number of built vehicles
61      *
62      * Instead of a MSVehicle, a GUIVehicle is built
63      *
64      * @param[in] defs The parameter defining the vehicle
65      * @param[in] route The route of this vehicle
66      * @param[in] type The type of this vehicle
67      * @param[in] ignoreStopErrors whether invalid stops trigger a warning only
68      * @param[in] fromRouteFile whether we are just reading the route file or creating via trigger, traci, ...
69      * @return The built vehicle (GUIVehicle instance)
70      * @see MSVehicleControl::buildVehicle
71      */
72     SUMOVehicle* buildVehicle(SUMOVehicleParameter* defs,
73                               const MSRoute* route, MSVehicleType* type,
74                               const bool ignoreStopErrors, const bool fromRouteFile = true);
75     /// @}
76 
77 
78     /** @brief Tries to insert the vehicle into the internal vehicle container
79      *
80      * Identical to the MSVehicleControl implementation except for locking.
81      *
82      * @param[in] id The id of the vehicle
83      * @param[in] v The vehicle
84      * @return Whether the vehicle could be inserted (no other vehicle with the same id was inserted before)
85      */
86     bool addVehicle(const std::string& id, SUMOVehicle* v);
87 
88 
89     /** @brief Deletes the vehicle
90      *
91      * Identical to the MSVehicleControl implementation except for locking.
92      *
93      * @param[in] v The vehicle to delete
94      * @param[discard] Whether the vehicle is discard during loading (scale < 1)
95      */
96     void deleteVehicle(SUMOVehicle* v, bool discard = false);
97 
98 
99     /** @brief Returns the list of all known vehicles by gl-id
100      * @param[fill] into The list to fill with vehicle ids
101      * @param[listParking] Whether parking vehicles shall be listed as well
102      * @param[listTeleporting] Whether teleporting vehicles shall be listed as well
103      * @todo Well, what about concurrent modifications?
104      */
105     void insertVehicleIDs(std::vector<GUIGlID>& into, bool listParking, bool listTeleporting);
106 
107 
108     /** @brief Returns the number of halting vehicles
109      * @return The number of halting vehicles
110      */
111     virtual int getHaltingVehicleNo() const;
112 
113     /// @brief get current absolute and relative mean vehicle speed in the network
114     virtual std::pair<double, double> getVehicleMeanSpeeds() const;
115 
116     /// @brief lock access to vehicle removal/additions for thread synchronization
117     void secureVehicles();
118 
119     /// @brief unlock access to vehicle removal/additions for thread synchronization
120     void releaseVehicles();
121 
122 
123 private:
124     /// The mutex used to avoid concurrent updates of the vehicle buffer
125     mutable FXMutex myLock;
126 
127 
128 private:
129     /// @brief invalidated copy constructor
130     GUIVehicleControl(const GUIVehicleControl& s);
131 
132     /// @brief invalidated assignment operator
133     GUIVehicleControl& operator=(const GUIVehicleControl& s);
134 
135 
136 };
137 
138 
139 #endif
140 
141 /****************************************************************************/
142 
143