Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/guisim/GUIBaseVehicle.h
169668 views
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
Seat(): pos(Position::INVALID), angle(0) {}
69
70
Seat(const Position& _pos, double _angle):
71
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
double getNaviDegree() const {
106
return GeomHelper::naviDegree(getAngle());
107
}
108
109
/// @brief gets the color value according to the current scheme index
110
virtual double getColorValue(const GUIVisualizationSettings& s, int activeScheme) const = 0;
111
112
/// @brief draws the given guiShape with distinct carriages/modules
113
virtual void drawAction_drawCarriageClass(const GUIVisualizationSettings& s, double scaledLength, bool asImage) const = 0;
114
115
/** @brief Returns the time since the last lane change in seconds
116
* @see MSVehicle::myLastLaneChangeOffset
117
* @return The time since the last lane change in seconds
118
*/
119
virtual double getLastLaneChangeOffset() const = 0;
120
121
/** @brief Draws the route
122
* @param[in] r The route to draw
123
*/
124
virtual void drawRouteHelper(const GUIVisualizationSettings& s, ConstMSRoutePtr r, bool future, bool noLoop, const RGBColor& col) const = 0;
125
126
/// @brief retrieve information about the current stop state
127
virtual std::string getStopInfo() const = 0;
128
129
/// @brief adds the blocking foes to the current selection
130
virtual void selectBlockingFoes() const = 0;
131
132
/** @brief Returns an own parameter window
133
*
134
* @param[in] app The application needed to build the parameter window
135
* @param[in] parent The parent window needed to build the parameter window
136
* @return The built parameter window
137
* @see GUIGlObject::getParameterWindow
138
*/
139
virtual GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0;
140
141
/** @brief Returns an own type parameter window
142
*
143
* @param[in] app The application needed to build the parameter window
144
* @param[in] parent The parent window needed to build the parameter window
145
* @return The built parameter window
146
*/
147
virtual GUIParameterTableWindow* getTypeParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0;
148
149
virtual void drawAction_drawVehicleBlinker(double /*length*/) const {}
150
virtual void drawAction_drawVehicleBrakeLight(double length, bool onlyOne = false) const {
151
UNUSED_PARAMETER(length);
152
UNUSED_PARAMETER(onlyOne);
153
}
154
virtual void drawAction_drawLinkItems(const GUIVisualizationSettings& /*s*/) const {}
155
virtual void drawAction_drawPersonsAndContainers(const GUIVisualizationSettings& s) const;
156
/** @brief Draws the vehicle's best lanes */
157
virtual void drawBestLanes() const {};
158
virtual void drawAction_drawVehicleBlueLight() const {}
159
160
161
162
163
164
/// @name inherited from GUIGlObject
165
//@{
166
167
/** @brief Returns an own popup-menu
168
*
169
* @param[in] app The application needed to build the popup-menu
170
* @param[in] parent The parent window needed to build the popup-menu
171
* @return The built popup-menu
172
* @see GUIGlObject::getPopUpMenu
173
*/
174
GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent);
175
176
/// @brief notify object about popup menu removal
177
void removedPopupMenu();
178
179
/// @brief return exaggeration associated with this GLObject
180
double getExaggeration(const GUIVisualizationSettings& s) const;
181
182
/** @brief Returns the boundary to which the view shall be centered in order to show the object
183
*
184
* @return The boundary the object is within
185
* @see GUIGlObject::getCenteringBoundary
186
*/
187
virtual Boundary getCenteringBoundary() const;
188
189
/// @brief Returns the value for generic parameter 'name' or ''
190
const std::string getOptionalName() const;
191
192
/** @brief Draws the object on the specified position with the specified angle
193
* @param[in] s The settings for the current view (may influence drawing)
194
* @param[in] pos The position to draw the vehicle on
195
* @param[in] angle The drawing angle of the vehicle
196
*/
197
void drawOnPos(const GUIVisualizationSettings& s, const Position& pos, const double angle) const;
198
199
200
/** @brief Draws the object
201
* @param[in] s The settings for the current view (may influence drawing)
202
* @see GUIGlObject::drawGL
203
*/
204
void drawGL(const GUIVisualizationSettings& s) const;
205
206
207
/** @brief Draws additionally triggered visualisations
208
* @param[in] parent The view
209
* @param[in] s The settings for the current view (may influence drawing)
210
*/
211
virtual void drawGLAdditional(GUISUMOAbstractView* const parent, const GUIVisualizationSettings& s) const;
212
//@}
213
214
215
216
/// @name Additional visualisations
217
/// @{
218
219
/** @brief Returns whether the named feature is enabled in the given view
220
* @param[in] parent The view for which the feature may be enabled
221
* @param[in] which The visualisation feature
222
* @return see comment
223
*/
224
bool hasActiveAddVisualisation(GUISUMOAbstractView* const parent, int which) const;
225
226
227
/** @brief Adds the named visualisation feature to the given view
228
* @param[in] parent The view for which the feature shall be enabled
229
* @param[in] which The visualisation feature to enable
230
* @see GUISUMOAbstractView::addAdditionalGLVisualisation
231
*/
232
void addActiveAddVisualisation(GUISUMOAbstractView* const parent, int which);
233
234
235
/** @brief Adds the named visualisation feature to the given view
236
* @param[in] parent The view for which the feature shall be enabled
237
* @param[in] which The visualisation feature to enable
238
* @see GUISUMOAbstractView::removeAdditionalGLVisualisation
239
*/
240
void removeActiveAddVisualisation(GUISUMOAbstractView* const parent, int which);
241
/// @}
242
243
/// @brief return the number of passengers
244
int getNumPassengers() const;
245
246
/// @brief return the number of passengers
247
int getNumContainers() const;
248
249
/// @brief lists equipped device (types) for the current vehicle
250
std::string getDeviceDescription();
251
252
/**
253
* @class GUIBaseVehiclePopupMenu
254
*
255
* A popup-menu for vehicles. In comparison to the normal popup-menu, this one
256
* also allows to trigger further visualisations and to track the vehicle.
257
*/
258
class GUIBaseVehiclePopupMenu : public GUIGLObjectPopupMenu {
259
FXDECLARE(GUIBaseVehiclePopupMenu)
260
261
public:
262
/** @brief Constructor
263
* @param[in] app The main window for instantiation of other windows
264
* @param[in] parent The parent view for changing it
265
* @param[in] o The object of interest
266
*/
267
GUIBaseVehiclePopupMenu(GUIMainWindow& app, GUISUMOAbstractView& parent, GUIGlObject* o);
268
269
/// @brief Destructor
270
~GUIBaseVehiclePopupMenu();
271
272
/// @brief Called if all routes of the vehicle shall be shown
273
long onCmdShowAllRoutes(FXObject*, FXSelector, void*);
274
/// @brief Called if all routes of the vehicle shall be hidden
275
long onCmdHideAllRoutes(FXObject*, FXSelector, void*);
276
/// @brief Called if the current route of the vehicle shall be shown
277
long onCmdShowCurrentRoute(FXObject*, FXSelector, void*);
278
/// @brief Called if the current route of the vehicle shall be hidden
279
long onCmdHideCurrentRoute(FXObject*, FXSelector, void*);
280
/// @brief Called if the current route of the vehicle shall be shown
281
long onCmdShowFutureRoute(FXObject*, FXSelector, void*);
282
/// @brief Called if the current route of the vehicle shall be hidden
283
long onCmdHideFutureRoute(FXObject*, FXSelector, void*);
284
/// @brief Called if the current route of the vehicle shall be shown
285
long onCmdShowRouteNoLoops(FXObject*, FXSelector, void*);
286
/// @brief Called if the current route of the vehicle shall be hidden
287
long onCmdHideRouteNoLoops(FXObject*, FXSelector, void*);
288
/// @brief Called if the vehicle's best lanes shall be shown
289
long onCmdShowBestLanes(FXObject*, FXSelector, void*);
290
/// @brief Called if the vehicle's best lanes shall be hidden
291
long onCmdHideBestLanes(FXObject*, FXSelector, void*);
292
/// @brief Called if the vehicle shall be tracked
293
long onCmdStartTrack(FXObject*, FXSelector, void*);
294
/// @brief Called if the current shall not be tracked any longer
295
long onCmdStopTrack(FXObject*, FXSelector, void*);
296
/// @brief Called if all routes of the vehicle shall be shown
297
long onCmdShowLFLinkItems(FXObject*, FXSelector, void*);
298
/// @brief Called if all routes of the vehicle shall be hidden
299
long onCmdHideLFLinkItems(FXObject*, FXSelector, void*);
300
/// @brief Called to show (select) a vehicles foes
301
long onCmdShowFoes(FXObject*, FXSelector, void*);
302
/// @brief Called to select all riding persons and containers
303
long onCmdSelectTransported(FXObject*, FXSelector, void*);
304
/// @brief Called when removing the vehicle
305
long onCmdRemoveObject(FXObject*, FXSelector, void*);
306
/// @brief Called when toggling stop state
307
long onCmdToggleStop(FXObject*, FXSelector, void*);
308
309
protected:
310
FOX_CONSTRUCTOR(GUIBaseVehiclePopupMenu)
311
};
312
313
314
/// @name Additional visualisations
315
/// @{
316
317
/** @brief Additional visualisation feature ids
318
*/
319
enum VisualisationFeatures {
320
/// @brief show vehicle's best lanes
321
VO_SHOW_BEST_LANES = 1 << 0,
322
/// @brief show vehicle's current route
323
VO_SHOW_ROUTE = 1 << 1,
324
/// @brief show all vehicle's routes
325
VO_SHOW_ALL_ROUTES = 1 << 2,
326
/// @brief LFLinkItems
327
VO_SHOW_LFLINKITEMS = 1 << 3,
328
/// @brief draw vehicle outside the road network
329
VO_DRAW_OUTSIDE_NETWORK = 1 << 4,
330
/// @brief show vehicle's current continued from the current position
331
VO_SHOW_FUTURE_ROUTE = 1 << 5,
332
/// @brief show vehicle's routes without loops
333
VO_SHOW_ROUTE_NOLOOP = 1 << 6,
334
/// @brief track the vehicle (only needed for cleaning up)
335
VO_TRACK = 1 << 7
336
};
337
338
/// @brief Enabled visualisations, per view
339
std::map<GUISUMOAbstractView*, int> myAdditionalVisualizations;
340
341
342
/** @brief Chooses the route to draw and draws it, darkening it as given
343
* @param[in] s The visualisation settings, needed to determine the vehicle's color
344
* @param[in] routeNo The route to show (0: the current, >0: prior)
345
* @param[in] darken The amount to darken the route by
346
*/
347
void drawRoute(const GUIVisualizationSettings& s, int routeNo, double darken, bool future = false, bool noLoop = false) const;
348
349
void drawStopLabels(const GUIVisualizationSettings& s, bool noLoop, const RGBColor& col) const;
350
351
void drawParkingInfo(const GUIVisualizationSettings& s) const;
352
353
void drawChargingInfo(const GUIVisualizationSettings& s) const;
354
/// @}
355
356
const MSBaseVehicle& getVehicle() {
357
return myVehicle;
358
}
359
360
/// @brief gets the size multiplier value according to the current scheme index
361
double getScaleValue(const GUIVisualizationSettings& s, int activeScheme) const;
362
363
double getScaleVisual() const {
364
return myVehicle.getVehicleType().getParameter().scaleVisual;
365
}
366
367
/// @brief sets the color according to the current scheme index and some vehicle function
368
static bool setFunctionalColor(int activeScheme, const MSBaseVehicle* veh, RGBColor& col);
369
370
protected:
371
372
/// @brief sets the color according to the current settings
373
RGBColor setColor(const GUIVisualizationSettings& s) const;
374
375
/// @brief returns the seat position for the person with the given index
376
const Seat& getSeatPosition(int personIndex) const;
377
const Seat& getContainerPosition(int containerIndex) const;
378
379
static void drawLinkItem(const Position& pos, SUMOTime arrivalTime, SUMOTime leaveTime, double exagerate);
380
381
/// @brief A shortcut to myVehicle.myType
382
inline const MSVehicleType& getVType() const {
383
return myVehicle.getVehicleType();
384
}
385
386
/// @brief draw vehicle body and return whether carriages are being drawn
387
bool drawAction_drawVehicleAsPolyWithCarriagges(const GUIVisualizationSettings& s, double scaledLength, bool asImage = false) const;
388
389
/// @brief add seats to mySeatPositions and update requiredSeats
390
void computeSeats(const Position& front, const Position& back, double seatOffset, int maxSeats, double exaggeration, int& requiredSeats, Seats& into, double extraOffset = 0) const;
391
392
/// @brief whether to reverse trains in their reversed state
393
bool drawReversed(const GUIVisualizationSettings& s) const;
394
395
396
protected:
397
/// The mutex used to avoid concurrent updates of the vehicle buffer
398
mutable FXMutex myLock;
399
400
/// @brief positions of seats in the vehicle (updated at every drawing step)
401
mutable Seats mySeatPositions;
402
mutable Seats myContainerPositions;
403
404
private:
405
/// @brief The vehicle to which all calls should be delegated
406
MSBaseVehicle& myVehicle;
407
408
MSDevice_Vehroutes* myRoutes;
409
410
/// @brief current popup (to clean up in destructor). GUIBaseVehicle is not responsible for removal
411
GUIGLObjectPopupMenu* myPopup;
412
413
};
414
415