1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2010-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    MSPushButton.h
11 /// @author  Federico Caselli
12 /// @date    May 2015
13 /// @version $Id$
14 ///
15 // The class for a PushButton
16 /****************************************************************************/
17 
18 #ifndef SRC_MICROSIM_TRAFFIC_LIGHTS_MSPUSHBUTTON_H_
19 #define SRC_MICROSIM_TRAFFIC_LIGHTS_MSPUSHBUTTON_H_
20 
21 #include <vector>
22 #include <map>
23 #include <string>
24 
25 class MSEdge;
26 class MSPhaseDefinition;
27 
28 /**
29  * Abstract push button class
30  */
31 class MSPushButton {
32 public:
33     virtual ~MSPushButton();
34 
35     /**
36      * @brief Checks if the the pushbutton has been pressed
37      * @return true if pressed, false otherwise
38      */
39     virtual bool isActivated() const = 0;
40 
41     /**
42      * @brief Checks if any pushbutton in the vector is active
43      * @return True if at least one pushbutton is active, false otherwise
44      */
45     static bool anyActive(const std::vector<MSPushButton*>&);
46 protected:
47     /**
48      * Protected constructor
49      * @param[in] edge: the edge where the push button is located
50      * @param[in] crossingEdge: the crossing controlled by the push button
51      */
52     MSPushButton(const MSEdge* edge, const MSEdge* crossingEdge);
53     const MSEdge* m_edge;
54     const MSEdge* m_crossingEdge;
55 };
56 
57 /**
58  * Pedestrian push button
59  */
60 class MSPedestrianPushButton: MSPushButton {
61 public:
62     /**
63      * MSPedestrianPushButton constructor
64      * @param[in] edge: the edge where the push button is located. Must be a walking area.
65      * @param[in] crossingEdge: the crossing controlled by the push button. Must be a crossing.
66      */
67     MSPedestrianPushButton(const MSEdge* walkingEdge, const MSEdge* crossingEdge);
~MSPedestrianPushButton()68     virtual ~MSPedestrianPushButton() {
69     }
70 
71     ///@brief  abstract methods inherited from PedestrianState
72     ///@{
73     bool isActivated() const;
74     ///@}
75 
76     /**
77      * @brief Static method with the same behavior of isActivated
78      * @brief Checks if the the pushbutton has been pressed for a particular crossing from a edge.
79      * @return true if pressed, false otherwise
80      */
81     static bool isActiveForEdge(const MSEdge* walkingEdge, const MSEdge* crossing);
82 
83     /**
84      * @brief Static method to check if the push button is active on both side of the road
85      * @param[in] A crossing edge
86      * @return true if pressed, false otherwise
87      */
88     static bool isActiveOnAnySideOfTheRoad(const MSEdge* crossing);
89 
90     /**
91      * @brief Loads all the pushbuttons for all the controlled lanes of a stage
92      * @param[in] A phase definition
93      * @return A list of pushbuttons
94      */
95     static std::vector<MSPushButton*> loadPushButtons(const MSPhaseDefinition*);
96 private:
97 //		Map edge id -> list of crossing edges that crosses it
98     static std::map<std::string, std::vector<std::string> > m_crossingEdgeMap;
99     static bool m_crossingEdgeMapLoaded;
100 //		Load the crossingEdgeMap
101     static void loadCrossingEdgeMap();
102 };
103 
104 #endif /* SRC_MICROSIM_TRAFFIC_LIGHTS_MSPUSHBUTTON_H_ */
105