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    GUIPerson.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Jakob Erdmann
13 /// @author  Sascha Krieg
14 /// @author  Michael Behrisch
15 /// @date    Sept 2002
16 /// @version $Id$
17 ///
18 // A MSVehicle extended by some values for usage within the gui
19 /****************************************************************************/
20 #ifndef GUIPerson_h
21 #define GUIPerson_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <vector>
30 #include <set>
31 #include <string>
32 #include <fx.h>
33 #include <utils/gui/globjects/GUIGlObject.h>
34 #include <utils/common/RGBColor.h>
35 #include <microsim/pedestrians/MSPerson.h>
36 #include <utils/gui/globjects/GUIGLObjectPopupMenu.h>
37 #include <utils/gui/settings/GUIPropertySchemeStorage.h>
38 
39 
40 // ===========================================================================
41 // class declarations
42 // ===========================================================================
43 class GUISUMOAbstractView;
44 class GUIGLObjectPopupMenu;
45 class MSDevice_Vehroutes;
46 
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
51 /**
52  * @class GUIPerson
53  */
54 class GUIPerson : public MSPerson, public GUIGlObject {
55 public:
56     /** @brief Constructor
57      */
58     GUIPerson(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan, const double speedFactor);
59 
60 
61     /// @brief destructor
62     ~GUIPerson();
63 
64 
65     /// @name inherited from GUIGlObject
66     //@{
67 
68     /** @brief Returns an own popup-menu
69      *
70      * @param[in] app The application needed to build the popup-menu
71      * @param[in] parent The parent window needed to build the popup-menu
72      * @return The built popup-menu
73      * @see GUIGlObject::getPopUpMenu
74      */
75     GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent);
76 
77 
78     /** @brief Returns an own parameter window
79      *
80      * @param[in] app The application needed to build the parameter window
81      * @param[in] parent The parent window needed to build the parameter window
82      * @return The built parameter window
83      * @see GUIGlObject::getParameterWindow
84      */
85     GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent);
86 
87     /** @brief Returns an own type parameter window
88      *
89      * @param[in] app The application needed to build the parameter window
90      * @param[in] parent The parent window needed to build the parameter window
91      * @return The built parameter window
92      */
93     GUIParameterTableWindow* getTypeParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent);
94 
95     /** @brief Returns the boundary to which the view shall be centered in order to show the object
96      *
97      * @return The boundary the object is within
98      * @see GUIGlObject::getCenteringBoundary
99      */
100     Boundary getCenteringBoundary() const;
101 
102 
103     /** @brief Draws the object
104      * @param[in] s The settings for the current view (may influence drawing)
105      * @see GUIGlObject::drawGL
106      */
107     void drawGL(const GUIVisualizationSettings& s) const;
108 
109 
110     /** @brief Draws additionally triggered visualisations
111      * @param[in] parent The view
112      * @param[in] s The settings for the current view (may influence drawing)
113      */
114     virtual void drawGLAdditional(GUISUMOAbstractView* const parent, const GUIVisualizationSettings& s) const;
115     //@}
116 
117     /* @brief set the position of a person while riding in a vehicle
118      * @note This must be called by the vehicle before the call to drawGl */
setPositionInVehicle(const Position & pos)119     void setPositionInVehicle(const Position& pos) {
120         myPositionInVehicle = pos;
121     }
122 
123     /// @name inherited from MSPerson with added locking
124     //@{
125 
126     /// @brief return the offset from the start of the current edge
127     double getEdgePos() const;
128 
129     /// @brief return the Network coordinate of the person
130     // @note overrides the base method and returns myPositionInVehicle while in driving stage
131     Position getPosition() const;
132 
133     /// @brief return the Network coordinate of the person (only for drawing centering and tracking)
134     Position getGUIPosition() const;
135 
136     /// @brief return the current angle of the person
137     double getNaviDegree() const;
138 
139     /// @brief the time this person spent waiting in seconds
140     double getWaitingSeconds() const;
141 
142     /// @brief the current speed of the person
143     double getSpeed() const;
144 
145     //@}
146 
147     /// @brief whether this person is selected in the GUI
148     bool isSelected() const;
149 
150     /**
151      * @class GUIPersonPopupMenu
152      *
153      * A popup-menu for vehicles. In comparison to the normal popup-menu, this one
154      *  also allows to trigger further visualisations and to track the vehicle.
155      */
156     class GUIPersonPopupMenu : public GUIGLObjectPopupMenu {
157         FXDECLARE(GUIPersonPopupMenu)
158     public:
159         /** @brief Constructor
160          * @param[in] app The main window for instantiation of other windows
161          * @param[in] parent The parent view for changing it
162          * @param[in] o The object of interest
163          * @param[in, out] additionalVisualizations Information which additional visualisations are enabled (per view)
164          */
165         GUIPersonPopupMenu(GUIMainWindow& app,
166                            GUISUMOAbstractView& parent, GUIGlObject& o, std::map<GUISUMOAbstractView*, int>& additionalVisualizations);
167 
168         /// @brief Destructor
169         ~GUIPersonPopupMenu();
170 
171         /// @brief Called if the current route of the person shall be shown
172         long onCmdShowCurrentRoute(FXObject*, FXSelector, void*);
173         /// @brief Called if the current route of the person shall be hidden
174         long onCmdHideCurrentRoute(FXObject*, FXSelector, void*);
175         /// @brief Called if the walkingarea path of the person shall be shown
176         long onCmdShowWalkingareaPath(FXObject*, FXSelector, void*);
177         /// @brief Called if the walkingarea path of the person shall be hidden
178         long onCmdHideWalkingareaPath(FXObject*, FXSelector, void*);
179         /// @brief Called if the plan shall be shown
180         long onCmdShowPlan(FXObject*, FXSelector, void*);
181         /// @brief Called if the person shall be tracked
182         long onCmdStartTrack(FXObject*, FXSelector, void*);
183         /// @brief Called if the person shall not be tracked any longer
184         long onCmdStopTrack(FXObject*, FXSelector, void*);
185 
186 
187     protected:
188         /// @brief Information which additional visualisations are enabled (per view)
189         std::map<GUISUMOAbstractView*, int>& myVehiclesAdditionalVisualizations;
190         /// @brief Needed for parameterless instantiation
191         std::map<GUISUMOAbstractView*, int> dummy;
192 
193     protected:
194         /// @brief default constructor needed by FOX
GUIPersonPopupMenu()195         GUIPersonPopupMenu() : myVehiclesAdditionalVisualizations(dummy) { }
196 
197     };
198 
199 
200     /** @brief Additional visualisation feature ids
201      */
202     enum VisualisationFeatures {
203         /// @brief show the current walkingarea path
204         VO_SHOW_WALKINGAREA_PATH = 1,
205         /// @brief show persons's current route
206         VO_SHOW_ROUTE = 2,
207         /// @brief track person
208         VO_TRACKED = 8
209     };
210 
211     /// @brief Enabled visualisations, per view
212     std::map<GUISUMOAbstractView*, int> myAdditionalVisualizations;
213 
214 
215     /// @name Additional visualisations
216     /// @{
217 
218     /** @brief Returns whether the named feature is enabled in the given view
219      * @param[in] parent The view for which the feature may be enabled
220      * @param[in] which The visualisation feature
221      * @return see comment
222      */
223     bool hasActiveAddVisualisation(GUISUMOAbstractView* const parent, int which) const;
224 
225 
226     /** @brief Adds the named visualisation feature to the given view
227      * @param[in] parent The view for which the feature shall be enabled
228      * @param[in] which The visualisation feature to enable
229      * @see GUISUMOAbstractView::addAdditionalGLVisualisation
230      */
231     void addActiveAddVisualisation(GUISUMOAbstractView* const parent, int which);
232 
233 
234     /** @brief Adds the named visualisation feature to the given view
235      * @param[in] parent The view for which the feature shall be enabled
236      * @param[in] which The visualisation feature to enable
237      * @see GUISUMOAbstractView::removeAdditionalGLVisualisation
238      */
239     void removeActiveAddVisualisation(GUISUMOAbstractView* const parent, int which);
240     /// @}
241 
242 
243 private:
244     /// The mutex used to avoid concurrent updates of the vehicle buffer
245     mutable FXMutex myLock;
246 
247     /// The position of a person while riding a vehicle
248     Position myPositionInVehicle;
249 
250     /// @brief sets the color according to the currente settings
251     void setColor(const GUIVisualizationSettings& s) const;
252 
253     /// @brief gets the color value according to the current scheme index
254     double getColorValue(int activeScheme) const;
255 
256     /// @brief sets the color according to the current scheme index and some vehicle function
257     bool setFunctionalColor(int activeScheme) const;
258 
259     /// @name drawing helper methods
260     /// @{
261     void drawAction_drawAsTriangle(const GUIVisualizationSettings& s) const;
262     void drawAction_drawAsCircle(const GUIVisualizationSettings& s) const;
263     void drawAction_drawAsPoly(const GUIVisualizationSettings& s) const;
264     void drawAction_drawAsImage(const GUIVisualizationSettings& s) const;
265 
266     void drawAction_drawWalkingareaPath(const GUIVisualizationSettings& s) const;
267     /// @}
268 };
269 
270 
271 #endif
272 
273 /****************************************************************************/
274 
275