Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/gui/windows/GUISUMOAbstractView.h
169684 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 GUISUMOAbstractView.h
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @author Andreas Gaubatz
19
/// @date Sept 2002
20
///
21
// The base class for a view
22
/****************************************************************************/
23
#pragma once
24
#include <config.h>
25
26
#include <string>
27
#include <vector>
28
#include <map>
29
#include <utils/foxtools/fxheader.h>
30
// fx3d includes windows.h so we need to guard against macro pollution
31
#ifdef WIN32
32
#define NOMINMAX
33
#endif
34
#include <fx3d.h>
35
#ifdef WIN32
36
#undef NOMINMAX
37
#endif
38
39
#include <utils/geom/Boundary.h>
40
#include <utils/geom/Position.h>
41
#include <utils/common/RGBColor.h>
42
#include <utils/common/SUMOTime.h>
43
#include <utils/gui/globjects/GUIGlObjectTypes.h>
44
#include <foreign/rtree/SUMORTree.h>
45
46
47
// ===========================================================================
48
// class declarations
49
// ===========================================================================
50
class GUIGlChildWindow;
51
class GUIVehicle;
52
class GUIPerspectiveChanger;
53
class GUIMainWindow;
54
class GUIGLObjectPopupMenu;
55
class GUIGlObject;
56
class GUIDialog_EditViewport;
57
class GUIDialog_ViewSettings;
58
class GUIVisualizationSettings;
59
class GUILane;
60
61
/// @brief comparator for resolving clicks
62
struct ComparatorClickPriority {
63
bool operator()(const GUIGlObject* const a, const GUIGlObject* const b) const {
64
if (a->getClickPriority() == b->getClickPriority()) {
65
// sorty by GUIGlID as second criterion to simplify
66
// duplicate removal
67
return a->getGlID() > b->getGlID();
68
} else {
69
return a->getClickPriority() > b->getClickPriority();
70
}
71
}
72
};
73
74
// ===========================================================================
75
// class definitions
76
// ===========================================================================
77
/**
78
* @class GUISUMOAbstractView
79
* This class is meant to be pure virtual later;
80
* It shall be the main class to inherit views of the simulation (micro-
81
* or macroscopic ones) from it.
82
*/
83
class GUISUMOAbstractView : public FXGLCanvas {
84
FXDECLARE(GUISUMOAbstractView)
85
86
public:
87
/// @brief constructor
88
GUISUMOAbstractView(FXComposite* p, GUIMainWindow& app, GUIGlChildWindow* parent, const SUMORTree& grid, FXGLVisual* glVis, FXGLCanvas* share);
89
90
/// @brief destructor
91
virtual ~GUISUMOAbstractView();
92
93
/// @brief recalculate boundaries
94
virtual void recalculateBoundaries() { };
95
96
/// @brief builds the view toolbars
97
virtual void buildViewToolBars(GUIGlChildWindow*) { }
98
99
/// @brief recenters the view
100
virtual void recenterView();
101
102
/** @brief centers to the chosen artifact
103
* @param[in] id The id of the artifact to center to
104
* @param[in] applyZoom Whether to zoom in
105
* @param[in] zoomDist The distance in m to use for the zoom, values < 0 means: use the centeringBoundary
106
* @note caller is responsible for calling update
107
*/
108
virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist = 20);
109
110
/** @brief centers to the chosen position
111
* @param[in] pos Position to center view
112
* @param[in] applyZoom Whether to zoom in
113
* @param[in] zoomDist The distance in m to use for the zoom, values < 0 means: use the centeringBoundary
114
* @note caller is responsible for calling update
115
*/
116
virtual void centerTo(const Position& pos, bool applyZoom, double zoomDist = 20);
117
118
/// @brief centers to the chosen artifact
119
void centerTo(const Boundary& bound);
120
121
/// @brief applies the given viewport settings
122
virtual void setViewportFromToRot(const Position& lookFrom, const Position& lookAt, double rotation);
123
124
/// @brief copy the viewport to the given view
125
virtual void copyViewportTo(GUISUMOAbstractView* view);
126
127
/// @brief meter-to-pixels conversion method
128
double m2p(double meter) const;
129
130
/// @brief pixels-to-meters conversion method
131
double p2m(double pixel) const;
132
133
/// @brief get main window
134
GUIMainWindow* getMainWindow() const;
135
136
/// @brief return windows cursor position
137
Position getWindowCursorPosition() const;
138
139
/// @brief Returns the gl-id of the object under the given coordinates
140
void setWindowCursorPosition(FXint x, FXint y);
141
142
/// @brief A reimplementation due to some internal reasons
143
FXbool makeCurrent();
144
145
/// @brief returns true, if the edit button was pressed
146
bool isInEditMode();
147
148
/// @brief get changer
149
GUIPerspectiveChanger& getChanger() const;
150
151
/// @brief get visible boundary
152
Boundary getVisibleBoundary() const;
153
154
/// @brief return whether this is a 3D view
155
virtual bool is3DView() const;
156
157
/// @brief zoom interface for 3D view
158
virtual void zoom2Pos(Position& camera, Position& lookAt, double zoom);
159
160
/// @brief mouse functions
161
//@{
162
virtual long onConfigure(FXObject*, FXSelector, void*);
163
virtual long onPaint(FXObject*, FXSelector, void*);
164
virtual long onLeftBtnPress(FXObject*, FXSelector, void*);
165
virtual long onLeftBtnRelease(FXObject*, FXSelector, void*);
166
virtual long onMiddleBtnPress(FXObject*, FXSelector, void*);
167
virtual long onMiddleBtnRelease(FXObject*, FXSelector, void*);
168
virtual long onRightBtnPress(FXObject*, FXSelector, void*);
169
virtual long onRightBtnRelease(FXObject*, FXSelector, void*);
170
virtual long onDoubleClicked(FXObject*, FXSelector, void*);
171
virtual long onMouseWheel(FXObject*, FXSelector, void*);
172
virtual long onMouseMove(FXObject*, FXSelector, void*);
173
virtual long onMouseLeft(FXObject*, FXSelector, void*);
174
//@}
175
176
/// @brief keyboard functions
177
//@{
178
virtual long onKeyPress(FXObject* o, FXSelector sel, void* data);
179
virtual long onKeyRelease(FXObject* o, FXSelector sel, void* data);
180
//@}
181
182
/// @brief interaction with the simulation
183
virtual long onCmdCloseLane(FXObject*, FXSelector, void*);
184
virtual long onCmdCloseEdge(FXObject*, FXSelector, void*);
185
virtual long onCmdAddRerouter(FXObject*, FXSelector, void*);
186
187
/// @brief highlight edges according to reachability
188
virtual long onCmdShowReachability(FXObject*, FXSelector, void*);
189
190
/// @brief hook to react on change in visualization settings
191
virtual long onVisualizationChange(FXObject*, FXSelector, void*);
192
193
/// @brief filter out duplicate and forbidden objects
194
std::vector<GUIGlObject*> filterContextObjects(const std::vector<GUIGlObject*>& objects);
195
196
/// @brief open object dialog at the cursor position
197
virtual void openObjectDialogAtCursor(const FXEvent* ev);
198
199
/// @brief open object dialog for the given object
200
void openObjectDialog(const std::vector<GUIGlObject*>& objects, const bool filter = true);
201
202
/// @brief A method that updates the tooltip
203
void updateToolTip();
204
205
/// @brief @name Dealing with snapshots
206
///@{
207
208
/** @brief Sets the snapshot time to file map
209
* @param[in] snaps The snapshots to take at certain times
210
* @param[in] w The snapshot image width
211
* @param[in] w The snapshot image height
212
*/
213
void addSnapshot(SUMOTime time, const std::string& file, const int w = -1, const int h = -1);
214
215
/** @brief Takes a snapshots and writes it into the given file
216
*
217
* The format to use is determined from the extension.
218
* If compiled with ffmpeg and a video format is requested it will instantiate a video encoder.
219
* @param[in] destFile The name of the file to write the snapshot into
220
* @param[in] w The snapshot image width
221
* @param[in] w The snapshot image height
222
* @return The error message, if an error occurred; "" otherwise
223
*/
224
std::string makeSnapshot(const std::string& destFile, const int w = -1, const int h = -1);
225
226
/// @brief Adds a frame to a video snapshot which will be initialized if necessary
227
virtual void saveFrame(const std::string& destFile, FXColor* buf);
228
229
/// @brief Ends a video snapshot
230
virtual void endSnapshot() {}
231
232
/// @brief Checks whether it is time for a snapshot
233
virtual void checkSnapshots();
234
235
void waitForSnapshots(const SUMOTime snapshotTime);
236
237
/// @brief get the current simulation time
238
virtual SUMOTime getCurrentTimeStep() const;
239
240
///@}
241
242
/// @brief get the viewport and create it on first access
243
GUIDialog_EditViewport* getViewportEditor();
244
245
/// @brief update the viewport chooser with the current view values
246
virtual void updateViewportValues();
247
248
/// @brief show viewport editor
249
virtual void showViewportEditor();
250
251
/// @brief show viewsscheme editor
252
void showViewschemeEditor();
253
254
/// @brief set color scheme
255
virtual bool setColorScheme(const std::string&);
256
257
/// @brief get visualization settings (read only)
258
const GUIVisualizationSettings& getVisualisationSettings() const;
259
260
/// @brief edit visualization settings (allow modify VisualizationSetings, use carefully)
261
GUIVisualizationSettings* editVisualisationSettings() const;
262
263
/// @brief recalibrate color scheme according to the current value range
264
virtual void buildColorRainbow(const GUIVisualizationSettings& /*s*/, GUIColorScheme& /*scheme*/, int /*active*/, GUIGlObjectType /*objectType*/,
265
const GUIVisualizationRainbowSettings& /*rs*/) {
266
}
267
268
/// @brief return list of loaded edgeData attributes
269
virtual std::vector<std::string> getEdgeDataAttrs() const {
270
return std::vector<std::string>();
271
}
272
273
/// @brief return list of loaded edgeData ids (being computed in the current simulation)
274
virtual std::vector<std::string> getMeanDataIDs() const {
275
return std::vector<std::string>();
276
}
277
278
/// @brief return list of available attributes for the given meanData id
279
virtual std::vector<std::string> getMeanDataAttrs(const std::string& meanDataID) const {
280
UNUSED_PARAMETER(meanDataID);
281
return std::vector<std::string>();
282
}
283
284
/// @brief return list of loaded edgeRelation and tazRelation attributes
285
virtual std::vector<std::string> getRelDataAttrs() const {
286
return std::vector<std::string>();
287
}
288
289
/// @brief return list of available edge parameters
290
virtual std::vector<std::string> getEdgeLaneParamKeys(bool /*edgeKeys*/) const {
291
return std::vector<std::string>();
292
}
293
294
/// @brief return list of available vehicle parameters
295
virtual std::vector<std::string> getVehicleParamKeys(bool /*vTypeKeys*/) const {
296
return std::vector<std::string>();
297
}
298
299
/// @brief return list of available vehicle parameters
300
virtual std::vector<std::string> getPOIParamKeys() const {
301
return std::vector<std::string>();
302
}
303
304
/// @brief remove viewport
305
void remove(GUIDialog_EditViewport*);
306
307
/// @brief remove view settings
308
void remove(GUIDialog_ViewSettings*);
309
310
/// @brief get grid width
311
// @todo: check why this is here
312
double getGridWidth() const;
313
314
/// @brief get grid height
315
// @todo: check why this is here
316
double getGridHeight() const;
317
318
/// @brief star track
319
virtual void startTrack(int /*id*/);
320
321
/// @brief stop track
322
virtual void stopTrack();
323
324
/// @brief get tracked id
325
virtual GUIGlID getTrackedID() const;
326
327
/// @brief on gaming click
328
virtual void onGamingClick(Position /*pos*/);
329
virtual void onGamingRightClick(Position /*pos*/);
330
331
/// @brief @name Additional visualisations
332
///@{
333
334
/** @brief Adds an object to call its additional visualisation method
335
* @param[in] which The object to add
336
* @return Always true
337
* @see GUIGlObject::drawGLAdditional
338
*/
339
bool addAdditionalGLVisualisation(GUIGlObject* const which);
340
341
/** @brief Removes an object from the list of objects that show additional things
342
* @param[in] which The object to remove
343
* @return True if the object was known, false otherwise
344
* @see GUIGlObject::drawGLAdditional
345
*/
346
bool removeAdditionalGLVisualisation(GUIGlObject* const which);
347
348
/** @brief Check if an object is added in the additional GL visualitation
349
* @param[in] which The object to check
350
* @see GUIGlObject::drawGLAdditional
351
*/
352
bool isAdditionalGLVisualisationEnabled(GUIGlObject* const which) const;
353
354
///@}
355
356
/// @brief ge the current popup-menu
357
GUIGLObjectPopupMenu* getPopup() const;
358
359
/// @brief get position of current popup
360
const Position& getPopupPosition() const;
361
362
/// @brief destroys the popup
363
void destroyPopup();
364
365
/// @brief replace PopUp
366
void replacePopup(GUIGLObjectPopupMenu* popUp);
367
368
///@struct Decal
369
/// @brief A decal (an image) that can be shown
370
struct Decal {
371
372
/// @brief Constructor
373
Decal() {};
374
375
/// @brief The path to the file the image is located at
376
std::string filename;
377
378
/// @brief The center of the image in x-direction (net coordinates, in m)
379
double centerX = 0;
380
381
/// @brief The center of the image in y-direction (net coordinates, in m)
382
double centerY = 0;
383
384
/// @brief The center of the image in z-direction (net coordinates, in m)
385
double centerZ = 0;
386
387
/// @brief The width of the image (net coordinates in x-direction, in m)
388
double width = 0;
389
390
/// @brief The height of the image (net coordinates in y-direction, in m)
391
double height = 0;
392
393
/// @brief The altitude of the image (net coordinates in z-direction, in m)
394
double altitude = 0;
395
396
/// @brief The rotation of the image in the ground plane (in degrees)
397
double rot = 0;
398
399
/// @brief The tilt of the image to the ground plane (in degrees)
400
double tilt = 0;
401
402
/// @brief The roll of the image to the ground plane (in degrees)
403
double roll = 0;
404
405
/// @brief The layer of the image
406
double layer = 0;
407
408
/// @brief Whether this image was initialised (inserted as a texture)
409
bool initialised = false;
410
411
/// @brief Whether this image should be skipped in 2D-views
412
bool skip2D = false;
413
414
/// @brief Whether this image should be skipped in 2D-views
415
bool screenRelative = false;
416
417
/// @brief whether the decal shall be drawn in screen coordinates, rather than network coordinates
418
int glID = -1;
419
420
/// @brief The image pointer for later cleanup
421
FXImage* image = nullptr;
422
};
423
424
/// @brief The list of decals to show
425
std::vector<Decal>& getDecals();
426
427
/// @brief The mutex to use before accessing the decals list in order to avoid thread conflicts
428
FXMutex& getDecalsLockMutex();
429
430
/// @brief get coloring schemes combo
431
MFXComboBoxIcon* getColoringSchemesCombo();
432
433
/// @brief Returns the cursor's x/y position within the network
434
virtual Position getPositionInformation() const;
435
436
/**@brief Returns a position that is mapped to the closest grid point if the grid is active
437
* @brief note: formats are pos(x,y,0) por pos(0,0,z)
438
*/
439
Position snapToActiveGrid(const Position& pos, bool snapXY = true) const;
440
441
/// @brief Translate screen position to network position
442
Position screenPos2NetPos(int x, int y) const;
443
444
/// @brief add decals
445
void addDecals(const std::vector<Decal>& decals);
446
447
/// @brief Returns the delay of the parent application
448
double getDelay() const;
449
450
/// @brief Sets the delay of the parent application
451
void setDelay(double delay);
452
453
/// @brief Sets the breakpoints of the parent application
454
void setBreakpoints(const std::vector<SUMOTime>& breakpoints);
455
456
/// @brief retrieve breakpoints if provided by the application
457
virtual const std::vector<SUMOTime> retrieveBreakpoints() const {
458
return std::vector<SUMOTime>();
459
}
460
461
/// @brief retrieve FPS
462
double getFPS() const;
463
464
/// @brief get GUIGlChildWindow
465
GUIGlChildWindow* getGUIGlChildWindow();
466
467
/// @brief Draw (or not) the JuPedSim pedestrian network
468
/// @param s The visualization settings
469
virtual void drawPedestrianNetwork(const GUIVisualizationSettings& /*s*/) const { };
470
471
/// @brief Change the color of the JuPedSim pedestrian network
472
/// @param s The visualization settings
473
virtual void changePedestrianNetworkColor(const GUIVisualizationSettings& /*s*/) const { };
474
475
protected:
476
/// @brief FOX needs this
477
FOX_CONSTRUCTOR(GUISUMOAbstractView)
478
479
/// @brief performs the painting of the simulation
480
void paintGL();
481
482
/// @brief update position information labels
483
virtual void updatePositionInformationLabel() const;
484
485
/// @brief paint GL
486
virtual int doPaintGL(int /*mode*/, const Boundary& /*boundary*/);
487
488
/// @brief doInit
489
virtual void doInit();
490
491
/// @brief paints a grid
492
void paintGLGrid() const;
493
494
/// @brief Draws a line with ticks, and the length information.
495
void displayLegend();
496
497
/// @brief Draws the configured legends
498
void displayLegends();
499
500
/// @brief Draws a legend for the given scheme
501
void displayColorLegend(const GUIColorScheme& scheme, bool leftSide, const std::string& key);
502
503
/// @brief Draws frames-per-second indicator
504
void drawFPS();
505
506
/// @brief returns the GUILane at cursor position (implementation depends on view)
507
virtual GUILane* getLaneUnderCursor();
508
509
/// @brief returns the id of object under cursor to show their tooltip
510
virtual GUIGlID getToolTipID();
511
512
/// @brief returns the id of the front object under the cursor using GL_SELECT
513
GUIGlID getObjectUnderCursor(double sensitivity = SENSITIVITY);
514
515
/// @brief returns the id of the objects under the cursor using GL_SELECT (including overlapped objects)
516
std::vector<GUIGlID> getObjectsUnderCursor();
517
518
/// @brief returns the GUIGlObject under the cursor using GL_SELECT (including overlapped objects)
519
std::vector<GUIGlObject*> getGUIGlObjectsUnderCursor();
520
521
/// @brief returns the GUIGlObject under the gripped cursor using GL_SELECT (including overlapped objects)
522
std::vector<GUIGlObject*> getGUIGlObjectsUnderSnappedCursor();
523
524
/// @brief returns the id of the object at position using GL_SELECT
525
GUIGlID getObjectAtPosition(Position pos, double sensitivity = SENSITIVITY);
526
527
/// @brief returns the ids of the object at position within the given (rectangular) radius using GL_SELECT
528
std::vector<GUIGlID> getObjectsAtPosition(Position pos, double radius);
529
530
/// @brief returns the GUIGlObjects at position within the given (rectangular) radius using GL_SELECT
531
std::vector<GUIGlObject*> getGUIGlObjectsAtPosition(Position pos, double radius);
532
533
/// @brief returns the ids of all objects in the given boundary
534
std::vector<GUIGlID> getObjectsInBoundary(Boundary bound);
535
536
/// @brief filter internal lanes in Objects under cursor
537
std::vector<GUIGlObject*> filterInternalLanes(const std::vector<GUIGlObject*>& objects) const;
538
539
/// @brief invokes the tooltip for the given object
540
bool showToolTipFor(const GUIGlID idToolTip);
541
542
/// @brief Draws the stored decals
543
void drawDecals();
544
545
/// @brief open popup dialog
546
void openPopupDialog();
547
548
/// @brief helper function for buildColorRainbow
549
void buildMinMaxRainbow(const GUIVisualizationSettings& s, GUIColorScheme& scheme, const GUIVisualizationRainbowSettings& rs, double minValue, double maxValue, bool hasMissingData);
550
551
/// @brief applies gl-transformations to fit the Boundary given by myChanger onto the canvas.
552
/// If fixRatio is true, this boundary will be enlarged to prevent anisotropic stretching.
553
/// (this should be set to false when doing selections)
554
Boundary applyGLTransform(bool fixRatio = true);
555
556
/// @brief check whether we can read image data or position with gdal
557
FXImage* checkGDALImage(Decal& d);
558
559
/// @brief The application
560
GUIMainWindow* myApp;
561
562
/// @brief The parent window
563
GUIGlChildWindow* myGlChildWindowParent;
564
565
/// @brief The visualization speed-up
566
const SUMORTree* myGrid;
567
568
/// @brief The perspective changer
569
GUIPerspectiveChanger* myChanger = nullptr;
570
571
/// @brief Panning flag
572
bool myPanning = false;
573
574
/// @brief Information whether too-tip informations shall be generated
575
bool myInEditMode = false;
576
577
/// @brief Offset to the mouse-hotspot from the mouse position
578
int myMouseHotspotX, myMouseHotspotY;
579
580
/// @brief The current popup-menu
581
GUIGLObjectPopupMenu* myPopup = nullptr;
582
583
/// @brief clicked poup position
584
Position myClickedPopupPosition = Position::INVALID;
585
586
/// @brief The current popup-menu position
587
Position myPopupPosition = Position(0, 0);
588
589
/// @brief vector with current objects dialog
590
std::vector<GUIGlObject*> myCurrentObjectsDialog;
591
592
/// @brief visualization settings
593
GUIVisualizationSettings* myVisualizationSettings;
594
595
/// @brief Internal information whether doInit() was called
596
bool myAmInitialised = false;
597
598
/// @brief viewport chooser
599
GUIDialog_EditViewport* myGUIDialogEditViewport = nullptr;
600
601
/// @brief Position of the cursor relative to the window
602
FXint myWindowCursorPositionX, myWindowCursorPositionY;
603
604
/// @brief Visualization changer
605
GUIDialog_ViewSettings* myGUIDialogViewSettings = nullptr;
606
607
/// @brief @name Optionally shown decals
608
///@{
609
610
/// @brief The list of decals to show
611
std::vector<Decal> myDecals;
612
613
/// @brief The mutex to use before accessing the decals list in order to avoid thread conflicts
614
FXMutex myDecalsLockMutex;
615
616
///@}
617
618
/// @brief Snapshots
619
std::map<SUMOTime, std::vector<std::tuple<std::string, int, int> > > mySnapshots;
620
621
/// @brief The mutex to use before accessing the decals list in order to avoid thread conflicts
622
FXMutex mySnapshotsMutex;
623
624
/// @brief the semaphore when waiting for snapshots to finish
625
FXCondition mySnapshotCondition;
626
627
/// @brief poly draw lock
628
mutable FXMutex myPolyDrawLock;
629
630
/// @brief List of objects for which GUIGlObject::drawGLAdditional is called
631
std::map<GUIGlObject*, int> myAdditionallyDrawn;
632
633
/// @brief counter for measuring rendering time
634
long myFrameDrawTime = 0;
635
636
// @brief sensitivity for "<>AtPosition(...) functions
637
static const double SENSITIVITY;
638
639
private:
640
/// @brief struct used for sorting objects by layer
641
struct LayerObject : public std::pair<double, std::pair<GUIGlObjectType, std::string> > {
642
643
public:
644
/// @brief constructor for shapes
645
LayerObject(double layer, GUIGlObject* object);
646
647
/// @brief constructor for non-shape elements
648
LayerObject(GUIGlObject* object);
649
650
/// @brief get GLObject
651
GUIGlObject* getGLObject() const;
652
653
private:
654
/// @brief GLObject
655
GUIGlObject* myGLObject;
656
};
657
658
};
659
660