Eclipse SUMO - Simulation of Urban MObility
GUISUMOAbstractView.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 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 /****************************************************************************/
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 <fx.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>
45 
46 
47 // ===========================================================================
48 // class declarations
49 // ===========================================================================
50 class GUIGlChildWindow;
51 class GUIVehicle;
53 class GUIMainWindow;
55 class GUIGlObject;
59 
60 
61 // ===========================================================================
62 // class definitions
63 // ===========================================================================
70 class GUISUMOAbstractView : public FXGLCanvas {
71  FXDECLARE(GUISUMOAbstractView)
72 
73 public:
75  GUISUMOAbstractView(FXComposite* p, GUIMainWindow& app, GUIGlChildWindow* parent, const SUMORTree& grid, FXGLVisual* glVis, FXGLCanvas* share);
76 
78  virtual ~GUISUMOAbstractView();
79 
82 
84  virtual void recenterView();
85 
92  virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist = 20);
93 
100  virtual void centerTo(const Position& pos, bool applyZoom, double zoomDist = 20);
101 
103  void centerTo(const Boundary& bound);
104 
106  virtual void setViewportFromToRot(const Position& lookFrom, const Position& lookAt, double rotation);
107 
109  virtual void copyViewportTo(GUISUMOAbstractView* view);
110 
112  double m2p(double meter) const;
113 
115  double p2m(double pixel) const;
116 
119  //bool allowRotation() const;
120 
123 
125  void setWindowCursorPosition(FXint x, FXint y);
126 
128  FXbool makeCurrent();
129 
131  bool isInEditMode();
132 
135 
138 
140 
141  virtual long onConfigure(FXObject*, FXSelector, void*);
142  virtual long onPaint(FXObject*, FXSelector, void*);
143  virtual long onLeftBtnPress(FXObject*, FXSelector, void*);
144  virtual long onLeftBtnRelease(FXObject*, FXSelector, void*);
145  virtual long onMiddleBtnPress(FXObject*, FXSelector, void*);
146  virtual long onMiddleBtnRelease(FXObject*, FXSelector, void*);
147  virtual long onRightBtnPress(FXObject*, FXSelector, void*);
148  virtual long onRightBtnRelease(FXObject*, FXSelector, void*);
149  virtual long onDoubleClicked(FXObject*, FXSelector, void*);
150  virtual long onMouseWheel(FXObject*, FXSelector, void*);
151  virtual long onMouseMove(FXObject*, FXSelector, void*);
152  virtual long onMouseLeft(FXObject*, FXSelector, void*);
154 
156 
157  virtual long onKeyPress(FXObject* o, FXSelector sel, void* data);
158  virtual long onKeyRelease(FXObject* o, FXSelector sel, void* data);
160 
161  //@brief open object dialog
162  virtual void openObjectDialog();
163 
165  void updateToolTip();
166 
169 
174  void addSnapshot(SUMOTime time, const std::string& file, const int w = -1, const int h = -1);
175 
185  std::string makeSnapshot(const std::string& destFile, const int w = -1, const int h = -1);
186 
188  virtual void saveFrame(const std::string& destFile, FXColor* buf);
189 
191  virtual void endSnapshot() {}
192 
194  virtual void checkSnapshots();
195 
196  void waitForSnapshots(const SUMOTime snapshotTime);
197 
199  virtual SUMOTime getCurrentTimeStep() const;
201 
204 
206  virtual void showViewportEditor();
207 
209  void showViewschemeEditor();
210 
212  void showToolTips(bool val);
213 
215  virtual bool setColorScheme(const std::string&);
216 
219 
221  virtual void buildColorRainbow(const GUIVisualizationSettings& /*s*/, GUIColorScheme& /*scheme*/, int /*active*/, GUIGlObjectType /*objectType*/,
222  bool hide = false, double hideThreshold = 0) {
223  UNUSED_PARAMETER(hide);
224  UNUSED_PARAMETER(hideThreshold);
225  }
226 
228  virtual std::vector<std::string> getEdgeDataAttrs() const {
229  return std::vector<std::string>();
230  }
231 
233  virtual std::vector<std::string> getEdgeLaneParamKeys(bool /*edgeKeys*/) const {
234  return std::vector<std::string>();
235  }
236 
238  virtual std::vector<std::string> getVehicleParamKeys(bool /*vTypeKeys*/) const {
239  return std::vector<std::string>();
240  }
241 
243  virtual std::vector<std::string> getPOIParamKeys() const {
244  return std::vector<std::string>();
245  }
246 
249 
252 
254  // @todo: check why this is here
255  double getGridWidth() const;
256 
258  // @todo: check why this is here
259  double getGridHeight() const;
260 
262  virtual void startTrack(int /*id*/);
263 
265  virtual void stopTrack();
266 
268  virtual GUIGlID getTrackedID() const;
269 
271  virtual void onGamingClick(Position /*pos*/);
272  virtual void onGamingRightClick(Position /*pos*/);
273 
276 
281  bool addAdditionalGLVisualisation(GUIGlObject* const which);
282 
288  bool removeAdditionalGLVisualisation(GUIGlObject* const which);
289 
294  bool isAdditionalGLVisualisationEnabled(GUIGlObject* const which) const;
296 
298  const Position& getPopupPosition() const;
299 
301  void destroyPopup();
302 
303 public:
306  struct Decal {
308  Decal();
309 
311  std::string filename;
313  double centerX;
315  double centerY;
317  double centerZ;
319  double width;
321  double height;
323  double altitude;
325  double rot;
327  double tilt;
329  double roll;
331  double layer;
335  bool skip2D;
339  int glID;
341  FXImage* image;
342  };
343 
344 public:
346  FXComboBox* getColoringSchemesCombo();
347 
350 
354  Position snapToActiveGrid(const Position& pos, bool snapXY = true) const;
355 
357  Position screenPos2NetPos(int x, int y) const;
358 
360  void addDecals(const std::vector<Decal>& decals);
361 
363  double getDelay() const;
364 
366  void setDelay(double delay);
367 
369  void setBreakpoints(const std::vector<SUMOTime>& breakpoints);
370 
372  virtual const std::vector<SUMOTime> retrieveBreakpoints() const {
373  return std::vector<SUMOTime>();
374  }
375 
377  double getFPS() const;
378 
379 protected:
381  void paintGL();
382 
384  void updatePositionInformation() const;
385 
387  virtual int doPaintGL(int /*mode*/, const Boundary& /*boundary*/);
388 
390  virtual void doInit();
391 
393  void paintGLGrid();
394 
396  void displayLegend();
397 
399  void displayLegends();
400 
402  void displayColorLegend(const GUIColorScheme& scheme, bool leftSide);
403 
405  void drawFPS();
406 
409 
411  std::vector<GUIGlID> getObjectsUnderCursor();
412 
414  std::vector<GUIGlObject*> getGUIGlObjectsUnderCursor();
415 
417  std::vector<GUIGlObject*> getGUIGlObjectsUnderSnappedCursor();
418 
421 
423  std::vector<GUIGlID> getObjectsAtPosition(Position pos, double radius);
424 
426  std::vector<GUIGlObject*> getGUIGlObjectsAtPosition(Position pos, double radius);
427 
429  std::vector<GUIGlID> getObjectsInBoundary(Boundary bound, bool singlePosition);
430 
432  void showToolTipFor(const GUIGlID id);
433 
434 protected:
435  FOX_CONSTRUCTOR(GUISUMOAbstractView)
436 
437 
438  FXImage* checkGDALImage(Decal& d);
439 
441  void drawDecals();
442 
446  Boundary applyGLTransform(bool fixRatio = true);
447 
448 protected:
451 
454 
457 
460 
463 
466 
469 
472 
475 
478 
481 
484 
487 
490 
494  std::vector<Decal> myDecals;
495 
497  FXMutex myDecalsLock;
499 
501  std::map<SUMOTime, std::vector<std::tuple<std::string, int, int> > > mySnapshots;
502 
505 
507  FXCondition mySnapshotCondition;
508 
510  mutable FXMutex myPolyDrawLock;
511 
513  std::map<GUIGlObject*, int> myAdditionallyDrawn;
514 
517 
518 private:
519  // @brief sensitivity for "<>AtPosition(...) functions
520  static const double SENSITIVITY;
521 };
unsigned int GUIGlID
Definition: GUIGlObject.h:40
GUIGlObjectType
long long int SUMOTime
Definition: SUMOTime.h:31
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:29
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
A dialog to change the viewport.
The dialog to change the view (gui) settings.
The popup menu of a globject.
void paintGLGrid()
paints a grid
bool myAmInitialised
Internal information whether doInit() was called.
Position snapToActiveGrid(const Position &pos, bool snapXY=true) const
Returns a position that is mapped to the closest grid point if the grid is active.
std::string makeSnapshot(const std::string &destFile, const int w=-1, const int h=-1)
Takes a snapshots and writes it into the given file.
void updateToolTip()
A method that updates the tooltip.
virtual std::vector< std::string > getPOIParamKeys() const
return list of available vehicle parameters
void addDecals(const std::vector< Decal > &decals)
add decals
virtual void checkSnapshots()
Checks whether it is time for a snapshot.
void showViewschemeEditor()
show viewsscheme editor
GUISUMOAbstractView(FXComposite *p, GUIMainWindow &app, GUIGlChildWindow *parent, const SUMORTree &grid, FXGLVisual *glVis, FXGLCanvas *share)
constructor
static const double SENSITIVITY
virtual long onLeftBtnRelease(FXObject *, FXSelector, void *)
FXMutex myDecalsLock
The mutex to use before accessing the decals list in order to avoid thread conflicts.
void displayLegend()
Draws a line with ticks, and the length information.
std::vector< GUIGlObject * > getGUIGlObjectsUnderCursor()
returns the GUIGlObject under the cursor using GL_SELECT (including overlapped objects)
long myFrameDrawTime
counter for measuring rendering time
std::vector< GUIGlID > getObjectsAtPosition(Position pos, double radius)
returns the ids of the object at position within the given (rectangular) radius using GL_SELECT
virtual void endSnapshot()
Ends a video snapshot.
const SUMORTree * myGrid
The visualization speed-up.
virtual void saveFrame(const std::string &destFile, FXColor *buf)
Adds a frame to a video snapshot which will be initialized if neccessary.
virtual void recenterView()
recenters the view
virtual SUMOTime getCurrentTimeStep() const
get the current simulation time
GUIDialog_ViewSettings * myVisualizationChanger
Visualization changer.
std::vector< GUIGlID > getObjectsInBoundary(Boundary bound, bool singlePosition)
returns the ids of all objects in the given boundary
FXbool makeCurrent()
A reimplementation due to some internal reasons.
int myMouseHotspotX
Offset to the mouse-hotspot from the mouse position.
bool isInEditMode()
returns true, if the edit button was pressed
void updatePositionInformation() const
update position information
virtual long onMiddleBtnRelease(FXObject *, FXSelector, void *)
virtual long onMouseMove(FXObject *, FXSelector, void *)
GUIDialog_EditViewport * myViewportChooser
viewport chooser
GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings
bool isAdditionalGLVisualisationEnabled(GUIGlObject *const which) const
Check if an object is added in the additional GL visualitation.
FXCondition mySnapshotCondition
the semaphore when waiting for snapshots to finish
Position myPopupPosition
The current popup-menu position.
virtual void doInit()
doInit
virtual int doPaintGL(int, const Boundary &)
paint GL
virtual void buildViewToolBars(GUIGlChildWindow *)
builds the view toolbars
virtual void showViewportEditor()
show viewport editor
void setDelay(double delay)
Sets the delay of the parent application.
Boundary getVisibleBoundary() const
get visible boundary
FXMutex myPolyDrawLock
poly draw lock
Position screenPos2NetPos(int x, int y) const
Translate screen position to network position.
void addSnapshot(SUMOTime time, const std::string &file, const int w=-1, const int h=-1)
Sets the snapshot time to file map.
GUIGlID getObjectUnderCursor()
returns the id of the front object under the cursor using GL_SELECT
GUIPerspectiveChanger & getChanger() const
get changer
virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist=20)
centers to the chosen artifact
GUIMainWindow * myApp
The application.
GUIDialog_EditViewport * getViewportEditor()
get the viewport and create it on first access
virtual const std::vector< SUMOTime > retrieveBreakpoints() const
retrieve breakpoints if provided by the application
void showToolTips(bool val)
show tool tips
void drawFPS()
Draws frames-per-second indicator.
virtual long onMouseWheel(FXObject *, FXSelector, void *)
double getGridWidth() const
get grid width
bool removeAdditionalGLVisualisation(GUIGlObject *const which)
Removes an object from the list of objects that show additional things.
double getDelay() const
Returns the delay of the parent application.
std::vector< GUIGlObject * > getGUIGlObjectsAtPosition(Position pos, double radius)
returns the GUIGlObjects at position within the given (rectangular) radius using GL_SELECT
virtual long onLeftBtnPress(FXObject *, FXSelector, void *)
bool myUseToolTips
use tool tips
virtual void setViewportFromToRot(const Position &lookFrom, const Position &lookAt, double rotation)
applies the given viewport settings
double p2m(double pixel) const
pixels-to-meters conversion method
std::vector< Decal > myDecals
const Position & getPopupPosition() const
get position of current popup
double m2p(double meter) const
meter-to-pixels conversion method
virtual void onGamingClick(Position)
on gaming click
bool myInEditMode
Information whether too-tip informations shall be generated.
GUIVisualizationSettings * myVisualizationSettings
visualization settings
void destroyPopup()
destoys the popup
virtual std::vector< std::string > getEdgeDataAttrs() const
return list of loaded edgeData attributes
Position getWindowCursorPosition() const
Returns the information whether rotation is allowd.
virtual long onKeyPress(FXObject *o, FXSelector sel, void *data)
keyboard functions
virtual long onMiddleBtnPress(FXObject *, FXSelector, void *)
void paintGL()
performs the painting of the simulation
virtual void stopTrack()
stop track
Position getPositionInformation() const
Returns the cursor's x/y position within the network.
GUIGlID getObjectAtPosition(Position pos)
returns the id of the object at position using GL_SELECT
std::vector< GUIGlObject * > getGUIGlObjectsUnderSnappedCursor()
returns the GUIGlObject under the gripped cursor using GL_SELECT (including overlapped objects)
virtual long onKeyRelease(FXObject *o, FXSelector sel, void *data)
void showToolTipFor(const GUIGlID id)
invokes the tooltip for the given object
virtual std::vector< std::string > getVehicleParamKeys(bool) const
return list of available vehicle parameters
virtual void onGamingRightClick(Position)
void setWindowCursorPosition(FXint x, FXint y)
Returns the gl-id of the object under the given coordinates.
double getFPS() const
retrieve FPS
std::map< GUIGlObject *, int > myAdditionallyDrawn
List of objects for which GUIGlObject::drawGLAdditional is called.
void drawDecals()
Draws the stored decals.
std::vector< GUIGlID > getObjectsUnderCursor()
returns the id of the objects under the cursor using GL_SELECT (including overlapped objects)
virtual std::vector< std::string > getEdgeLaneParamKeys(bool) const
return list of available edge parameters
Boundary applyGLTransform(bool fixRatio=true)
applies gl-transformations to fit the Boundary given by myChanger onto the canvas....
FXImage * checkGDALImage(Decal &d)
check whether we can read image data or position with gdal
double getGridHeight() const
get grid height
virtual void startTrack(int)
star track
virtual long onDoubleClicked(FXObject *, FXSelector, void *)
void displayLegends()
Draws the configured legends.
void displayColorLegend(const GUIColorScheme &scheme, bool leftSide)
Draws a legend for the given scheme.
FXMutex mySnapshotsMutex
The mutex to use before accessing the decals list in order to avoid thread conflicts.
virtual long onMouseLeft(FXObject *, FXSelector, void *)
virtual long onRightBtnRelease(FXObject *, FXSelector, void *)
FXint myWindowCursorPositionX
Position of the cursor relative to the window.
GUIPerspectiveChanger * myChanger
The perspective changer.
GUIGLObjectPopupMenu * myPopup
The current popup-menu.
virtual void copyViewportTo(GUISUMOAbstractView *view)
copy the viewport to the given view
void setBreakpoints(const std::vector< SUMOTime > &breakpoints)
Sets the breakpoints of the parent application.
FXComboBox * getColoringSchemesCombo()
get coloring schemes combo
void waitForSnapshots(const SUMOTime snapshotTime)
bool addAdditionalGLVisualisation(GUIGlObject *const which)
Adds an object to call its additional visualisation method.
virtual bool setColorScheme(const std::string &)
set color scheme
GUIGlChildWindow * myParent
The parent window.
virtual long onPaint(FXObject *, FXSelector, void *)
virtual void buildColorRainbow(const GUIVisualizationSettings &, GUIColorScheme &, int, GUIGlObjectType, bool hide=false, double hideThreshold=0)
recalibrate color scheme according to the current value range
virtual long onRightBtnPress(FXObject *, FXSelector, void *)
virtual ~GUISUMOAbstractView()
destructor
virtual long onConfigure(FXObject *, FXSelector, void *)
mouse functions
std::map< SUMOTime, std::vector< std::tuple< std::string, int, int > > > mySnapshots
Snapshots.
void remove(GUIDialog_EditViewport *)
remove viewport
virtual GUIGlID getTrackedID() const
get tracked id
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:51
Stores the information about how to visualize structures.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
A RT-tree for efficient storing of SUMO's GL-objects.
Definition: SUMORTree.h:66
A decal (an image) that can be shown.
double tilt
The tilt of the image to the ground plane (in degrees)
double centerX
The center of the image in x-direction (net coordinates, in m)
double height
The height of the image (net coordinates in y-direction, in m)
bool skip2D
Whether this image should be skipped in 2D-views.
double width
The width of the image (net coordinates in x-direction, in m)
bool initialised
Whether this image was initialised (inserted as a texture)
FXImage * image
The image pointer for later cleanup.
double rot
The rotation of the image in the ground plane (in degrees)
double layer
The layer of the image.
double altitude
The altitude of the image (net coordinates in z-direction, in m)
double centerY
The center of the image in y-direction (net coordinates, in m)
double centerZ
The center of the image in z-direction (net coordinates, in m)
std::string filename
The path to the file the image is located at.
int glID
whether the decal shall be drawn in screen coordinates, rather than network coordinates
double roll
The roll of the image to the ground plane (in degrees)
bool screenRelative
Whether this image should be skipped in 2D-views.