Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file GUIBaseVehicle.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Sascha Krieg
18 : /// @author Michael Behrisch
19 : /// @date Sept 2002
20 : ///
21 : // A MSVehicle extended by some values for usage within the gui
22 : /****************************************************************************/
23 : #pragma once
24 : #include <config.h>
25 :
26 : #include <vector>
27 : #include <set>
28 : #include <string>
29 : #include <utils/foxtools/fxheader.h>
30 : #include <utils/common/RGBColor.h>
31 : #include <utils/geom/GeomHelper.h>
32 : #include <utils/geom/PositionVector.h>
33 : #include <utils/gui/globjects/GUIGlObject.h>
34 : #include <utils/gui/globjects/GUIGLObjectPopupMenu.h>
35 : #include <utils/gui/settings/GUIPropertySchemeStorage.h>
36 : #include <microsim/MSVehicle.h>
37 :
38 :
39 : // ===========================================================================
40 : // class declarations
41 : // ===========================================================================
42 : class GUISUMOAbstractView;
43 : class GUIGLObjectPopupMenu;
44 : class MSDevice_Vehroutes;
45 :
46 :
47 : // ===========================================================================
48 : // class definitions
49 : // ===========================================================================
50 : /**
51 : * @class GUIBaseVehicle
52 : * @brief A MSVehicle extended by some values for usage within the gui
53 : *
54 : * A visualisable MSVehicle. Extended by the possibility to retrieve names
55 : * of all available vehicles (static) and the possibility to retrieve the
56 : * color of the vehicle which is available in different forms allowing an
57 : * easier recognition of done actions such as lane changing.
58 : */
59 : class GUIBaseVehicle : public GUIGlObject {
60 : public:
61 :
62 : GUIBaseVehicle(MSBaseVehicle& vehicle);
63 :
64 : /// @brief destructor
65 : ~GUIBaseVehicle();
66 :
67 : struct Seat {
68 823762 : Seat(): pos(Position::INVALID), angle(0) {}
69 :
70 217820 : Seat(const Position& _pos, double _angle):
71 217820 : pos(_pos), angle(_angle) {}
72 :
73 : Position pos;
74 : double angle;
75 : };
76 : typedef std::vector<Seat> Seats;
77 :
78 : /** @brief Return current position (x/y, cartesian)
79 : *
80 : * If the vehicle's myLane is 0, Position::INVALID.
81 : * @param[in] offset optional offset in longitudinal direction
82 : * @return The current position (in cartesian coordinates)
83 : * @see myLane
84 : */
85 : virtual Position getPosition(const double offset = 0) const = 0;
86 :
87 : /** @brief Return current position taking into account secondary shape
88 : * @param[in] offset optional offset in longitudinal direction
89 : * @return The current position (in cartesian coordinates)
90 : */
91 : virtual Position getVisualPosition(bool s2, const double offset = 0) const = 0;
92 :
93 : /** @brief Returns the vehicle's direction in radians
94 : * @return The vehicle's current angle
95 : */
96 : virtual double getAngle() const = 0;
97 :
98 : /** @brief Returns the vehicle's direction in radians taking into account
99 : * secondary shape
100 : * @return The vehicle's current angle
101 : */
102 : virtual double getVisualAngle(bool s2) const = 0;
103 :
104 : /// @brief return the current angle in navigational degrees
105 0 : double getNaviDegree() const {
106 0 : return GeomHelper::naviDegree(getAngle());
107 : }
108 :
109 : /// @brief draws the given guiShape with distinct carriages/modules
110 : virtual void drawAction_drawCarriageClass(const GUIVisualizationSettings& s, double scaledLength, bool asImage) const = 0;
111 :
112 : /** @brief Returns the time since the last lane change in seconds
113 : * @see MSVehicle::myLastLaneChangeOffset
114 : * @return The time since the last lane change in seconds
115 : */
116 : virtual double getLastLaneChangeOffset() const = 0;
117 :
118 : /** @brief Draws the route
119 : * @param[in] r The route to draw
120 : */
121 : virtual void drawRouteHelper(const GUIVisualizationSettings& s, ConstMSRoutePtr r, bool future, bool noLoop, const RGBColor& col) const = 0;
122 :
123 : /// @brief retrieve information about the current stop state
124 : virtual std::string getStopInfo() const = 0;
125 :
126 : /// @brief adds the blocking foes to the current selection
127 : virtual void selectBlockingFoes() const = 0;
128 :
129 1268426 : virtual void drawAction_drawVehicleBlinker(double /*length*/) const {}
130 1268426 : virtual void drawAction_drawVehicleBrakeLight(double length, bool onlyOne = false) const {
131 : UNUSED_PARAMETER(length);
132 : UNUSED_PARAMETER(onlyOne);
133 1268426 : }
134 0 : virtual void drawAction_drawLinkItems(const GUIVisualizationSettings& /*s*/) const {}
135 : virtual void drawAction_drawPersonsAndContainers(const GUIVisualizationSettings& s) const;
136 : /** @brief Draws the vehicle's best lanes */
137 0 : virtual void drawBestLanes() const {};
138 0 : virtual void drawAction_drawVehicleBlueLight() const {}
139 :
140 : /// @name inherited from GUIGlObject
141 : //@{
142 :
143 : /** @brief Returns an own popup-menu
144 : *
145 : * @param[in] app The application needed to build the popup-menu
146 : * @param[in] parent The parent window needed to build the popup-menu
147 : * @return The built popup-menu
148 : * @see GUIGlObject::getPopUpMenu
149 : */
150 : GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
151 :
152 : /// @brief notify object about popup menu removal
153 : void removedPopupMenu() override;
154 :
155 : /// @brief return exaggeration associated with this GLObject
156 : double getExaggeration(const GUIVisualizationSettings& s) const override;
157 :
158 : /** @brief Returns the boundary to which the view shall be centered in order to show the object
159 : *
160 : * @return The boundary the object is within
161 : * @see GUIGlObject::getCenteringBoundary
162 : */
163 : virtual Boundary getCenteringBoundary() const override;
164 :
165 : /// @brief Returns the value for generic parameter 'name' or ''
166 : const std::string getOptionalName() const override;
167 :
168 : /** @brief Draws the object on the specified position with the specified angle
169 : * @param[in] s The settings for the current view (may influence drawing)
170 : * @param[in] pos The position to draw the vehicle on
171 : * @param[in] angle The drawing angle of the vehicle
172 : */
173 : void drawOnPos(const GUIVisualizationSettings& s, const Position& pos, const double angle) const;
174 :
175 :
176 : /** @brief Draws the object
177 : * @param[in] s The settings for the current view (may influence drawing)
178 : * @see GUIGlObject::drawGL
179 : */
180 : void drawGL(const GUIVisualizationSettings& s) const override;
181 :
182 :
183 : /** @brief Draws additionally triggered visualisations
184 : * @param[in] parent The view
185 : * @param[in] s The settings for the current view (may influence drawing)
186 : */
187 : virtual void drawGLAdditional(GUISUMOAbstractView* const parent, const GUIVisualizationSettings& s) const override;
188 : //@}
189 :
190 : /// @name Additional visualisations
191 : /// @{
192 :
193 : /** @brief Returns whether the named feature is enabled in the given view
194 : * @param[in] parent The view for which the feature may be enabled
195 : * @param[in] which The visualisation feature
196 : * @return see comment
197 : */
198 : bool hasActiveAddVisualisation(GUISUMOAbstractView* const parent, int which) const;
199 :
200 : /** @brief Adds the named visualisation feature to the given view
201 : * @param[in] parent The view for which the feature shall be enabled
202 : * @param[in] which The visualisation feature to enable
203 : * @see GUISUMOAbstractView::addAdditionalGLVisualisation
204 : */
205 : void addActiveAddVisualisation(GUISUMOAbstractView* const parent, int which);
206 :
207 : /** @brief Adds the named visualisation feature to the given view
208 : * @param[in] parent The view for which the feature shall be enabled
209 : * @param[in] which The visualisation feature to enable
210 : * @see GUISUMOAbstractView::removeAdditionalGLVisualisation
211 : */
212 : void removeActiveAddVisualisation(GUISUMOAbstractView* const parent, int which) override;
213 : /// @}
214 :
215 : /// @brief return the number of passengers
216 : int getNumPassengers() const;
217 :
218 : /// @brief return the number of passengers
219 : int getNumContainers() const;
220 :
221 : /// @brief lists equipped device (types) for the current vehicle
222 : std::string getDeviceDescription();
223 :
224 : /**
225 : * @class GUIBaseVehiclePopupMenu
226 : *
227 : * A popup-menu for vehicles. In comparison to the normal popup-menu, this one
228 : * also allows to trigger further visualisations and to track the vehicle.
229 : */
230 : class GUIBaseVehiclePopupMenu : public GUIGLObjectPopupMenu {
231 0 : FXDECLARE(GUIBaseVehiclePopupMenu)
232 :
233 : public:
234 : /** @brief Constructor
235 : * @param[in] app The main window for instantiation of other windows
236 : * @param[in] parent The parent view for changing it
237 : * @param[in] o The object of interest
238 : */
239 : GUIBaseVehiclePopupMenu(GUIMainWindow& app, GUISUMOAbstractView& parent, GUIGlObject* o);
240 :
241 : /// @brief Destructor
242 : ~GUIBaseVehiclePopupMenu();
243 :
244 : /// @brief Called if all routes of the vehicle shall be shown
245 : long onCmdShowAllRoutes(FXObject*, FXSelector, void*);
246 : /// @brief Called if all routes of the vehicle shall be hidden
247 : long onCmdHideAllRoutes(FXObject*, FXSelector, void*);
248 : /// @brief Called if the current route of the vehicle shall be shown
249 : long onCmdShowCurrentRoute(FXObject*, FXSelector, void*);
250 : /// @brief Called if the current route of the vehicle shall be hidden
251 : long onCmdHideCurrentRoute(FXObject*, FXSelector, void*);
252 : /// @brief Called if the current route of the vehicle shall be shown
253 : long onCmdShowFutureRoute(FXObject*, FXSelector, void*);
254 : /// @brief Called if the current route of the vehicle shall be hidden
255 : long onCmdHideFutureRoute(FXObject*, FXSelector, void*);
256 : /// @brief Called if the current route of the vehicle shall be shown
257 : long onCmdShowRouteNoLoops(FXObject*, FXSelector, void*);
258 : /// @brief Called if the current route of the vehicle shall be hidden
259 : long onCmdHideRouteNoLoops(FXObject*, FXSelector, void*);
260 : /// @brief Called if the vehicle's best lanes shall be shown
261 : long onCmdShowBestLanes(FXObject*, FXSelector, void*);
262 : /// @brief Called if the vehicle's best lanes shall be hidden
263 : long onCmdHideBestLanes(FXObject*, FXSelector, void*);
264 : /// @brief Called if the vehicle shall be tracked
265 : long onCmdStartTrack(FXObject*, FXSelector, void*);
266 : /// @brief Called if the current shall not be tracked any longer
267 : long onCmdStopTrack(FXObject*, FXSelector, void*);
268 : /// @brief Called if all routes of the vehicle shall be shown
269 : long onCmdShowLFLinkItems(FXObject*, FXSelector, void*);
270 : /// @brief Called if all routes of the vehicle shall be hidden
271 : long onCmdHideLFLinkItems(FXObject*, FXSelector, void*);
272 : /// @brief Called to show (select) a vehicles foes
273 : long onCmdShowFoes(FXObject*, FXSelector, void*);
274 : /// @brief Called to select all riding persons and containers
275 : long onCmdSelectTransported(FXObject*, FXSelector, void*);
276 : /// @brief Called when removing the vehicle
277 : long onCmdRemoveObject(FXObject*, FXSelector, void*);
278 : /// @brief Called when toggling stop state
279 : long onCmdToggleStop(FXObject*, FXSelector, void*);
280 :
281 : protected:
282 0 : FOX_CONSTRUCTOR(GUIBaseVehiclePopupMenu)
283 : };
284 :
285 :
286 : /// @name Additional visualisations
287 : /// @{
288 :
289 : /** @brief Additional visualisation feature ids
290 : */
291 : enum VisualisationFeatures {
292 : /// @brief show vehicle's best lanes
293 : VO_SHOW_BEST_LANES = 1 << 0,
294 : /// @brief show vehicle's current route
295 : VO_SHOW_ROUTE = 1 << 1,
296 : /// @brief show all vehicle's routes
297 : VO_SHOW_ALL_ROUTES = 1 << 2,
298 : /// @brief LFLinkItems
299 : VO_SHOW_LFLINKITEMS = 1 << 3,
300 : /// @brief draw vehicle outside the road network
301 : VO_DRAW_OUTSIDE_NETWORK = 1 << 4,
302 : /// @brief show vehicle's current continued from the current position
303 : VO_SHOW_FUTURE_ROUTE = 1 << 5,
304 : /// @brief show vehicle's routes without loops
305 : VO_SHOW_ROUTE_NOLOOP = 1 << 6,
306 : /// @brief track the vehicle (only needed for cleaning up)
307 : VO_TRACK = 1 << 7
308 : };
309 :
310 : /// @brief Enabled visualisations, per view
311 : std::map<GUISUMOAbstractView*, int> myAdditionalVisualizations;
312 :
313 :
314 : /** @brief Chooses the route to draw and draws it, darkening it as given
315 : * @param[in] s The visualisation settings, needed to determine the vehicle's color
316 : * @param[in] routeNo The route to show (0: the current, >0: prior)
317 : * @param[in] darken The amount to darken the route by
318 : */
319 : void drawRoute(const GUIVisualizationSettings& s, int routeNo, double darken, bool future = false, bool noLoop = false) const;
320 :
321 : void drawStopLabels(const GUIVisualizationSettings& s, bool noLoop, const RGBColor& col) const;
322 :
323 : void drawParkingInfo(const GUIVisualizationSettings& s) const;
324 :
325 : void drawChargingInfo(const GUIVisualizationSettings& s) const;
326 : /// @}
327 :
328 : const MSBaseVehicle& getVehicle() {
329 0 : return myVehicle;
330 : }
331 :
332 : /// @brief gets the size multiplier value according to the current scheme index
333 : double getScaleValue(const GUIVisualizationSettings& s, int activeScheme) const;
334 :
335 13231853 : double getScaleVisual() const override {
336 13231853 : return myVehicle.getVehicleType().getParameter().scaleVisual;
337 : }
338 :
339 : /// @brief sets the color according to the current scheme index and some vehicle function
340 : static bool setFunctionalColor(int activeScheme, const MSBaseVehicle* veh, RGBColor& col);
341 :
342 : protected:
343 :
344 : /// @brief sets the color according to the current settings
345 : RGBColor setColor(const GUIVisualizationSettings& s) const;
346 :
347 : /// @brief returns the seat position for the person with the given index
348 : const Seat& getSeatPosition(int personIndex) const;
349 : const Seat& getContainerPosition(int containerIndex) const;
350 :
351 : static void drawLinkItem(const Position& pos, SUMOTime arrivalTime, SUMOTime leaveTime, double exagerate);
352 :
353 : /// @brief A shortcut to myVehicle.myType
354 : inline const MSVehicleType& getVType() const {
355 79907295 : return myVehicle.getVehicleType();
356 : }
357 :
358 : /// @brief draw vehicle body and return whether carriages are being drawn
359 : bool drawAction_drawVehicleAsPolyWithCarriagges(const GUIVisualizationSettings& s, double scaledLength, bool asImage = false) const;
360 :
361 : /// @brief add seats to mySeatPositions and update requiredSeats
362 : void computeSeats(const Position& front, const Position& back, double seatOffset, int maxSeats, double exaggeration, int& requiredSeats, Seats& into, double extraOffset = 0) const;
363 :
364 : /// @brief whether to reverse trains in their reversed state
365 : bool drawReversed(const GUIVisualizationSettings& s) const;
366 :
367 :
368 : protected:
369 : /// The mutex used to avoid concurrent updates of the vehicle buffer
370 : mutable FXMutex myLock;
371 :
372 : /// @brief positions of seats in the vehicle (updated at every drawing step)
373 : mutable Seats mySeatPositions;
374 : mutable Seats myContainerPositions;
375 :
376 : private:
377 : /// @brief The vehicle to which all calls should be delegated
378 : MSBaseVehicle& myVehicle;
379 :
380 : MSDevice_Vehroutes* myRoutes;
381 :
382 : /// @brief current popup (to clean up in destructor). GUIBaseVehicle is not responsible for removal
383 : GUIGLObjectPopupMenu* myPopup;
384 :
385 : };
|