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-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 /****************************************************************************/
18 // The base class for a view
19 /****************************************************************************/
20 #ifndef GUISUMOAbstractView_h
21 #define GUISUMOAbstractView_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <string>
30 #include <vector>
31 #include <map>
32 #include <fx.h>
33 // fx3d includes windows.h so we need to guard against macro pollution
34 #ifdef WIN32
35 #define NOMINMAX
36 #endif
37 #include <fx3d.h>
38 #ifdef WIN32
39 #undef NOMINMAX
40 #endif
41 
42 #include <utils/geom/Boundary.h>
43 #include <utils/geom/Position.h>
44 #include <utils/common/RGBColor.h>
45 #include <utils/common/SUMOTime.h>
48 
49 
50 // ===========================================================================
51 // class declarations
52 // ===========================================================================
53 class GUIGlChildWindow;
54 class GUIVehicle;
56 class GUIMainWindow;
58 class GUIGlObject;
62 
63 
64 // ===========================================================================
65 // class definitions
66 // ===========================================================================
73 class GUISUMOAbstractView : public FXGLCanvas {
74  FXDECLARE(GUISUMOAbstractView)
75 
76 public:
78  GUISUMOAbstractView(FXComposite* p, GUIMainWindow& app, GUIGlChildWindow* parent, const SUMORTree& grid, FXGLVisual* glVis, FXGLCanvas* share);
79 
81  virtual ~GUISUMOAbstractView();
82 
85 
87  virtual void recenterView();
88 
95  virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist = 20);
96 
103  virtual void centerTo(const Position& pos, bool applyZoom, double zoomDist = 20);
104 
106  void centerTo(const Boundary& bound);
107 
109  virtual void setViewportFromToRot(const Position& lookFrom, const Position& lookAt, double rotation);
110 
112  virtual void copyViewportTo(GUISUMOAbstractView* view);
113 
115  double m2p(double meter) const;
116 
118  double p2m(double pixel) const;
119 
122  //bool allowRotation() const;
123 
126 
128  void setWindowCursorPosition(FXint x, FXint y);
129 
131  FXbool makeCurrent();
132 
134  bool isInEditMode();
135 
138 
141 
143 
144  virtual long onConfigure(FXObject*, FXSelector, void*);
145  virtual long onPaint(FXObject*, FXSelector, void*);
146  virtual long onLeftBtnPress(FXObject*, FXSelector, void*);
147  virtual long onLeftBtnRelease(FXObject*, FXSelector, void*);
148  virtual long onMiddleBtnPress(FXObject*, FXSelector, void*);
149  virtual long onMiddleBtnRelease(FXObject*, FXSelector, void*);
150  virtual long onRightBtnPress(FXObject*, FXSelector, void*);
151  virtual long onRightBtnRelease(FXObject*, FXSelector, void*);
152  virtual long onDoubleClicked(FXObject*, FXSelector, void*);
153  virtual long onMouseWheel(FXObject*, FXSelector, void*);
154  virtual long onMouseMove(FXObject*, FXSelector, void*);
155  virtual long onMouseLeft(FXObject*, FXSelector, void*);
157 
159 
160  virtual long onKeyPress(FXObject* o, FXSelector sel, void* data);
161  virtual long onKeyRelease(FXObject* o, FXSelector sel, void* data);
163 
164  //@brief open object dialog
165  virtual void openObjectDialog();
166 
168  void updateToolTip();
169 
172 
175  void addSnapshot(SUMOTime time, const std::string& file, const int width = -1, const int height = -1);
176 
184  std::string makeSnapshot(const std::string& destFile, const int width = -1, const int height = -1);
185 
187  virtual void saveFrame(const std::string& destFile, FXColor* buf);
188 
190  virtual void endSnapshot() {}
191 
193  virtual void checkSnapshots();
194 
195  void waitForSnapshots(const SUMOTime snapshotTime);
196 
198  virtual SUMOTime getCurrentTimeStep() const;
200 
203 
205  virtual void showViewportEditor();
206 
208  void showViewschemeEditor();
209 
211  void showToolTips(bool val);
212 
214  virtual bool setColorScheme(const std::string&);
215 
218 
220  virtual void buildColorRainbow(const GUIVisualizationSettings& /*s*/, GUIColorScheme& /*scheme*/, int /*active*/, GUIGlObjectType /*objectType*/,
221  bool hide = false, double hideThreshold = 0) {
222  UNUSED_PARAMETER(hide);
223  UNUSED_PARAMETER(hideThreshold);
224  }
225 
227  virtual std::vector<std::string> getEdgeDataAttrs() const {
228  return std::vector<std::string>();
229  }
230 
232  virtual std::vector<std::string> getEdgeLaneParamKeys(bool /*edgeKeys*/) const {
233  return std::vector<std::string>();
234  }
235 
237  void remove(GUIDialog_EditViewport*);
238 
240  void remove(GUIDialog_ViewSettings*);
241 
243  // @todo: check why this is here
244  double getGridWidth() const;
245 
247  // @todo: check why this is here
248  double getGridHeight() const;
249 
251  virtual void startTrack(int /*id*/);
252 
254  virtual void stopTrack();
255 
257  virtual GUIGlID getTrackedID() const;
258 
260  virtual void onGamingClick(Position /*pos*/);
261  virtual void onGamingRightClick(Position /*pos*/);
262 
265 
270  bool addAdditionalGLVisualisation(const GUIGlObject* const which);
271 
277  bool removeAdditionalGLVisualisation(const GUIGlObject* const which);
278 
283  bool isAdditionalGLVisualisationEnabled(GUIGlObject* const which) const;
285 
287  const Position& getPopupPosition() const;
288 
290  void destroyPopup();
291 
292 public:
295  struct Decal {
297  Decal();
298 
300  std::string filename;
302  double centerX;
304  double centerY;
306  double centerZ;
308  double width;
310  double height;
312  double altitude;
314  double rot;
316  double tilt;
318  double roll;
320  double layer;
324  bool skip2D;
328  int glID;
330  FXImage* image;
331  };
332 
333 public:
335  FXComboBox* getColoringSchemesCombo();
336 
339 
343  Position snapToActiveGrid(const Position& pos, bool snapXY = true) const;
344 
346  Position screenPos2NetPos(int x, int y) const;
347 
349  void addDecals(const std::vector<Decal>& decals);
350 
353 
355  double getDelay() const;
356 
358  void setDelay(double delay);
359 
361  void setBreakpoints(const std::vector<SUMOTime>& breakpoints);
362 
364  virtual const std::vector<SUMOTime> retrieveBreakpoints() const {
365  return std::vector<SUMOTime>();
366  }
367 
369  double getFPS() const;
370 
371 protected:
373  void paintGL();
374 
376  void updatePositionInformation() const;
377 
379  virtual int doPaintGL(int /*mode*/, const Boundary& /*boundary*/);
380 
382  virtual void doInit();
383 
385  void paintGLGrid();
386 
388  void displayLegend();
389 
391  void displayColorLegend();
392 
394  void drawFPS();
395 
398 
400  std::vector<GUIGlID> getObjectstUnderCursor();
401 
403  std::vector<GUIGlObject*> getGUIGlObjectsUnderCursor();
404 
407 
409  std::vector<GUIGlID> getObjectsAtPosition(Position pos, double radius);
410 
412  std::vector<GUIGlObject*> getGUIGlObjectsAtPosition(Position pos, double radius);
413 
415  std::vector<GUIGlID> getObjectsInBoundary(Boundary bound);
416 
418  void showToolTipFor(const GUIGlID id);
419 
420 protected:
423 
425  FXImage* checkGDALImage(Decal& d);
426 
428  void drawDecals();
429 
433  Boundary applyGLTransform(bool fixRatio = true);
434 
435 protected:
438 
441 
444 
447 
450 
453 
456 
459 
462 
465 
468 
471 
474 
477 
481  std::vector<Decal> myDecals;
482 
484  FXMutex myDecalsLock;
486 
488  std::map<SUMOTime, std::vector<std::tuple<std::string, int, int> > > mySnapshots;
489 
492 
494  FXCondition mySnapshotCondition;
495 
497  mutable FXMutex myPolyDrawLock;
498 
500  std::map<const GUIGlObject*, int> myAdditionallyDrawn;
501 
504 
505 private:
506  // @brief sensitivity for "<>AtPosition(...) functions
507  static const double SENSITIVITY;
508 };
509 
510 
511 #endif
512 
513 /****************************************************************************/
514 
GUIDialog_EditViewport * getViewportEditor()
get the viewport and create it on first access
void paintGLGrid()
paints a grid
virtual std::vector< std::string > getEdgeDataAttrs() const
return list of loaded edgeData attributes
A decal (an image) that can be shown.
virtual long onConfigure(FXObject *, FXSelector, void *)
mouse functions
void showToolTips(bool val)
show tool tips
double altitude
The altitude of the image (net coordinates in z-direction, in m)
std::vector< GUIGlID > getObjectsAtPosition(Position pos, double radius)
returns the ids of the object at position within the given (rectangular) radius using GL_SELECT ...
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.
long long int SUMOTime
Definition: SUMOTime.h:35
FXImage * checkGDALImage(Decal &d)
check whether we can read image data or position with gdal
FXImage * image
The image pointer for later cleanup.
std::map< SUMOTime, std::vector< std::tuple< std::string, int, int > > > mySnapshots
Snapshots.
virtual long onDoubleClicked(FXObject *, FXSelector, void *)
GUIGlObjectType
bool myAmInitialised
Internal information whether doInit() was called.
virtual void recenterView()
recenters the view
std::vector< GUIGlID > getObjectsInBoundary(Boundary bound)
returns the ids of all objects in the given boundary
SUMORTree * myGrid
The visualization speed-up.
virtual long onMouseMove(FXObject *, FXSelector, void *)
virtual long onMiddleBtnPress(FXObject *, FXSelector, void *)
Stores the information about how to visualize structures.
The dialog to change the view (gui) settings.
void setDelay(double delay)
Sets the delay of the parent application.
void displayLegend()
Draws a line with ticks, and the length information.
void updatePositionInformation() const
update position information
GUIVisualizationSettings * getVisualisationSettings() const
get visualitation settings
GUIMainWindow * myApp
The application.
static const double SENSITIVITY
virtual void saveFrame(const std::string &destFile, FXColor *buf)
Adds a frame to a video snapshot which will be initialized if neccessary.
double centerX
The center of the image in x-direction (net coordinates, in m)
bool screenRelative
Whether this image should be skipped in 2D-views.
long myFrameDrawTime
counter for measuring rendering time
virtual long onLeftBtnPress(FXObject *, FXSelector, void *)
bool myInEditMode
Information whether too-tip informations shall be generated.
virtual long onKeyRelease(FXObject *o, FXSelector sel, void *data)
bool addAdditionalGLVisualisation(const GUIGlObject *const which)
Adds an object to call its additional visualisation method.
int glID
whether the decal shall be drawn in screen coordinates, rather than network coordinates ...
virtual void copyViewportTo(GUISUMOAbstractView *view)
copy the viewport to the given view
virtual void onGamingClick(Position)
on gaming click
GUIDialog_ViewSettings * myVisualizationChanger
Visualization changer.
virtual void buildViewToolBars(GUIGlChildWindow &)
builds the view toolbars
virtual void stopTrack()
stop track
GUIDialog_EditViewport * myViewportChooser
viewport chooser
A RT-tree for efficient storing of SUMO&#39;s GL-objects.
Definition: SUMORTree.h:69
double getGridHeight() const
get grid Height
double height
The height of the image (net coordinates in y-direction, in m)
virtual void endSnapshot()
Ends a video snapshot.
void waitForSnapshots(const SUMOTime snapshotTime)
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:32
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
int myMouseHotspotX
Offset to the mouse-hotspot from the mouse position.
void addDecals(const std::vector< Decal > &decals)
add decals
double getDelay() const
Returns the delay of the parent application.
bool removeAdditionalGLVisualisation(const GUIGlObject *const which)
Removes an object from the list of objects that show additional things.
FXCondition mySnapshotCondition
the semaphore when waiting for snapshots to finish
void drawFPS()
Draws frames-per-second indicator.
void setBreakpoints(const std::vector< SUMOTime > &breakpoints)
Sets the breakpoints of the parent application.
double layer
The layer of the image.
double p2m(double pixel) const
pixels-to-meters conversion method
std::map< const GUIGlObject *, int > myAdditionallyDrawn
List of objects for which GUIGlObject::drawGLAdditional is called.
double roll
The roll of the image to the ground plane (in degrees)
FXMutex myDecalsLock
The mutex to use before accessing the decals list in order to avoid thread conflicts.
FXMutex mySnapshotsMutex
The mutex to use before accessing the decals list in order to avoid thread conflicts.
std::vector< GUIGlID > getObjectstUnderCursor()
returns the id of the objects under the cursor using GL_SELECT (including overlapped objects) ...
Boundary applyGLTransform(bool fixRatio=true)
applies gl-transformations to fit the Boundary given by myChanger onto the canvas. If fixRatio is true, this boundary will be enlarged to prevent anisotropic stretching. (this should be set to false when doing selections)
std::vector< Decal > myDecals
double getGridWidth() const
get grid width
GUIGlID getObjectAtPosition(Position pos)
returns the id of the object at position using GL_SELECT
virtual GUIGlID getTrackedID() const
get tracked id
virtual void startTrack(int)
star track
virtual long onPaint(FXObject *, FXSelector, void *)
void showToolTipFor(const GUIGlID id)
invokes the tooltip for the given object
virtual long onKeyPress(FXObject *o, FXSelector sel, void *data)
keyboard functions
bool isInEditMode()
returns true, if the edit button was pressed
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
std::string makeSnapshot(const std::string &destFile, const int width=-1, const int height=-1)
Takes a snapshots and writes it into the given file.
FXComboBox * getColoringSchemesCombo()
get coloring schemes combo
double getFPS() const
retrieve FPS
double rot
The rotation of the image in the ground plane (in degrees)
virtual void buildColorRainbow(const GUIVisualizationSettings &, GUIColorScheme &, int, GUIGlObjectType, bool hide=false, double hideThreshold=0)
recalibrate color scheme according to the current value range
virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist=20)
centers to the chosen artifact
GUIPerspectiveChanger & getChanger() const
get changer
bool initialised
Whether this image was initialised (inserted as a texture)
void displayColorLegend()
Draws a legend for the current edge coloring scheme.
virtual void doInit()
doInit
double centerY
The center of the image in y-direction (net coordinates, in m)
virtual long onMouseWheel(FXObject *, FXSelector, void *)
virtual std::vector< std::string > getEdgeLaneParamKeys(bool) const
return list of available edge parameters
virtual void checkSnapshots()
Checks whether it is time for a snapshot.
virtual ~GUISUMOAbstractView()
destructor
std::string filename
The path to the file the image is located at.
virtual void setViewportFromToRot(const Position &lookFrom, const Position &lookAt, double rotation)
applies the given viewport settings
virtual int doPaintGL(int, const Boundary &)
paint GL
Position screenPos2NetPos(int x, int y) const
Translate screen position to network position.
GUIPerspectiveChanger * myChanger
The perspective changer.
bool myUseToolTips
use tool tips
GUIGLObjectPopupMenu * myPopup
The current popup-menu.
void destroyPopup()
destoys the popup
FXMutex myPolyDrawLock
poly draw lock
FXint myWindowCursorPositionX
Position of the cursor relative to the window.
virtual long onMiddleBtnRelease(FXObject *, FXSelector, void *)
double width
The width of the image (net coordinates in x-direction, in m)
virtual bool setColorScheme(const std::string &)
set color scheme
unsigned int GUIGlID
Definition: GUIGlObject.h:43
virtual void showViewportEditor()
show viewport editor
FXbool makeCurrent()
A reimplementation due to some internal reasons.
virtual long onLeftBtnRelease(FXObject *, FXSelector, void *)
virtual void onGamingRightClick(Position)
virtual const std::vector< SUMOTime > retrieveBreakpoints() const
retrieve breakpoints if provided by the application
double m2p(double meter) const
meter-to-pixels conversion method
GUIVisualizationSettings * myVisualizationSettings
visualization settings
Position myPopupPosition
The current popup-menu position.
bool isAdditionalGLVisualisationEnabled(GUIGlObject *const which) const
Check if an object is added in the additional GL visualitation.
void paintGL()
performs the painting of the simulation
std::vector< GUIGlObject * > getGUIGlObjectsAtPosition(Position pos, double radius)
returns the GUIGlObjects at position within the given (rectangular) radius using GL_SELECT ...
void setWindowCursorPosition(FXint x, FXint y)
Returns the gl-id of the object under the given coordinates.
The popup menu of a globject.
double centerZ
The center of the image in z-direction (net coordinates, in m)
void drawDecals()
Draws the stored decals.
double tilt
The tilt of the image to the ground plane (in degrees)
void addSnapshot(SUMOTime time, const std::string &file, const int width=-1, const int height=-1)
Sets the snapshot time to file map.
bool skip2D
Whether this image should be skipped in 2D-views.
GUISUMOAbstractView()
FOX need this.
virtual SUMOTime getCurrentTimeStep() const
get the current simulation time
Position getPositionInformation() const
Returns the cursor&#39;s x/y position within the network.
Boundary getVisibleBoundary() const
get visible boundary
void updateToolTip()
A method that updates the tooltip.
A dialog to change the viewport.
void showViewschemeEditor()
show viewsscheme editor
virtual long onRightBtnPress(FXObject *, FXSelector, void *)
virtual long onMouseLeft(FXObject *, FXSelector, void *)
std::vector< GUIGlObject * > getGUIGlObjectsUnderCursor()
returns the GUIGlObject under the cursor using GL_SELECT (including overlapped objects) ...
GUIGlID getObjectUnderCursor()
returns the id of the front object under the cursor using GL_SELECT
Position getWindowCursorPosition() const
Returns the information whether rotation is allowd.
GUIGlChildWindow * myParent
The parent window.
virtual long onRightBtnRelease(FXObject *, FXSelector, void *)
const Position & getPopupPosition() const
get position of current popup
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:54