SUMO - Simulation of Urban MObility
GUISUMOAbstractView.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // The base class for a view
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef GUISUMOAbstractView_h
24 #define GUISUMOAbstractView_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <string>
37 #include <vector>
38 #include <map>
39 #include <fx.h>
40 // fx3d includes windows.h so we need to guard against macro pollution
41 #ifdef WIN32
42 #define NOMINMAX
43 #endif
44 #include <fx3d.h>
45 #ifdef WIN32
46 #undef NOMINMAX
47 #endif
48 
50 #include <utils/geom/Boundary.h>
51 #include <utils/geom/Position.h>
52 #include <utils/common/RGBColor.h>
53 #include <utils/common/SUMOTime.h>
56 
57 
58 // ===========================================================================
59 // class declarations
60 // ===========================================================================
61 class GUIGlChildWindow;
62 class GUIVehicle;
64 class GUIMainWindow;
66 class GUIGlObject;
70 
71 
72 // ===========================================================================
73 // class definitions
74 // ===========================================================================
81 class GUISUMOAbstractView : public FXGLCanvas {
82  FXDECLARE(GUISUMOAbstractView)
83 public:
85  GUISUMOAbstractView(FXComposite* p, GUIMainWindow& app, GUIGlChildWindow* parent, const SUMORTree& grid, FXGLVisual* glVis, FXGLCanvas* share);
86 
88  virtual ~GUISUMOAbstractView();
89 
92 
94  virtual void recenterView();
95 
102  virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist = 20);
103 
105  void centerTo(const Boundary& bound);
106 
108  virtual void setViewportFromTo(const Position& lookFrom, const Position& lookAt);
109 
111  virtual void copyViewportTo(GUISUMOAbstractView* view);
112 
114  double m2p(double meter) const;
115 
117  double p2m(double pixel) const;
118 
121  //bool allowRotation() const;
122 
124  void setWindowCursorPosition(FXint x, FXint y);
125 
127  FXbool makeCurrent();
128 
130  bool isInEditMode();
131 
134 
137 
139 
140  virtual long onConfigure(FXObject*, FXSelector, void*);
141  virtual long onPaint(FXObject*, FXSelector, void*);
142  virtual long onLeftBtnPress(FXObject*, FXSelector, void*);
143  virtual long onLeftBtnRelease(FXObject*, FXSelector, void*);
144  virtual long onMiddleBtnPress(FXObject*, FXSelector, void*);
145  virtual long onMiddleBtnRelease(FXObject*, FXSelector, void*);
146  virtual long onRightBtnPress(FXObject*, FXSelector, void*);
147  virtual long onRightBtnRelease(FXObject*, FXSelector, void*);
148  virtual long onDoubleClicked(FXObject*, FXSelector, void*);
149  virtual long onMouseWheel(FXObject*, FXSelector, void*);
150  virtual long onMouseMove(FXObject*, FXSelector, void*);
151  virtual long onMouseLeft(FXObject*, FXSelector, void*);
153 
155 
156  virtual long onKeyPress(FXObject* o, FXSelector sel, void* data);
157  virtual long onKeyRelease(FXObject* o, FXSelector sel, void* data);
159 
160  //@brief open object dialog
161  virtual void openObjectDialog();
162 
164  void updateToolTip();
165 
168 
171  void addSnapshot(SUMOTime time, const std::string& file);
172 
180  std::string makeSnapshot(const std::string& destFile);
181 
183  virtual void saveFrame(const std::string& destFile, FXColor* buf);
184 
186  virtual void endSnapshot() {}
187 
189  virtual void checkSnapshots();
190 
192  virtual SUMOTime getCurrentTimeStep() const;
194 
197 
199  virtual void showViewportEditor();
200 
202  void showViewschemeEditor();
203 
205  void showToolTips(bool val);
206 
208  virtual bool setColorScheme(const std::string&);
209 
212 
214  virtual void buildColorRainbow(GUIColorScheme& /*scheme*/, int /*active*/, GUIGlObjectType /*objectType*/) { }
215 
217  void remove(GUIDialog_EditViewport*);
218 
220  void remove(GUIDialog_ViewSettings*);
221 
223  // @todo: check why this is here
224  double getGridWidth() const;
225 
227  // @todo: check why this is here
228  double getGridHeight() const;
229 
231  virtual void startTrack(int /*id*/);
232 
234  virtual void stopTrack();
235 
237  virtual GUIGlID getTrackedID() const;
238 
240  virtual void onGamingClick(Position /*pos*/);
241 
244 
249  bool addAdditionalGLVisualisation(const GUIGlObject* const which);
250 
256  bool removeAdditionalGLVisualisation(const GUIGlObject* const which);
257 
262  bool isAdditionalGLVisualisationEnabled(GUIGlObject* const which) const;
264 
266  void destroyPopup();
267 
269  void setApplicationSnapshots(std::set<SUMOTime>* snapshots, FXMutex* lock) {
270  myApplicationSnapshots = snapshots;
272  }
273 
274 public:
277  struct Decal {
279  Decal();
280 
282  std::string filename;
284  double centerX;
286  double centerY;
288  double centerZ;
290  double width;
292  double height;
294  double altitude;
296  double rot;
298  double tilt;
300  double roll;
302  double layer;
306  bool skip2D;
310  int glID;
312  FXImage* image;
313  };
314 
315 public:
317  FXComboBox& getColoringSchemesCombo();
318 
321 
323  Position snapToActiveGrid(const Position& pos) const;
324 
326  Position screenPos2NetPos(int x, int y) const;
327 
329  void addDecals(const std::vector<Decal>& decals);
330 
333 
335  double getDelay() const;
336 
338  void setDelay(double delay);
339 
340 protected:
342  void paintGL();
343 
345  void updatePositionInformation() const;
346 
348  virtual int doPaintGL(int /*mode*/, const Boundary& /*boundary*/);
349 
351  virtual void doInit();
352 
354  void paintGLGrid();
355 
357  void displayLegend();
358 
361 
364 
366  std::vector<GUIGlID> getObjectsAtPosition(Position pos, double radius);
367 
369  std::vector<GUIGlID> getObjectsInBoundary(const Boundary& bound);
370 
372  void showToolTipFor(const GUIGlID id);
373 
374 protected:
376  FXImage* checkGDALImage(Decal& d);
377 
379  void drawDecals();
380 
384  void applyGLTransform(bool fixRatio = true);
385 
386 protected:
389 
392 
395 
398 
401 
404 
407 
410 
413 
416 
419 
422 
425 
429  std::vector<Decal> myDecals;
430 
434 
436  std::map<SUMOTime, std::vector<std::string> > mySnapshots;
437  std::set<SUMOTime>* myApplicationSnapshots;
438 
442 
445 
447  std::map<const GUIGlObject*, int> myAdditionallyDrawn;
448 
449 protected:
452 };
453 
454 
455 #endif
456 
457 /****************************************************************************/
458 
GUIDialog_EditViewport * getViewportEditor()
get the viewport and create it on first access
void paintGLGrid()
paints a grid
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 ...
FXImage * checkGDALImage(Decal &d)
check whether we can read image data or position with gdal
FXImage * image
The image pointer for later cleanup.
virtual long onDoubleClicked(FXObject *, FXSelector, void *)
virtual void setViewportFromTo(const Position &lookFrom, const Position &lookAt)
applies the given viewport settings
GUIGlObjectType
bool myAmInitialised
Internal information whether doInit() was called.
virtual void recenterView()
recenters the view
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()
a line with ticks, and the length information.
GUIMainWindow * myApp
The application.
void addSnapshot(SUMOTime time, const std::string &file)
Sets the snapshot time to file map.
virtual void saveFrame(const std::string &destFile, FXColor *buf)
Adds a frame to a video snapshot which will be initialized if neccessary.
MFXMutex myDecalsLock
The mutex to use before accessing the decals list in order to avoid thread conficts.
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.
virtual long onLeftBtnPress(FXObject *, FXSelector, void *)
bool myInEditMode
Information whether too-tip informations shall be generated.
virtual void openObjectDialog()
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
Position snapToActiveGrid(const Position &pos) const
Returns a position that is mapped to the closest grid point if the grid is active.
virtual void onGamingClick(Position)
on gaming click
GUIDialog_ViewSettings * myVisualizationChanger
Visualization changer.
virtual void buildViewToolBars(GUIGlChildWindow &)
builds the view toolbars
std::map< SUMOTime, std::vector< std::string > > mySnapshots
Snapshots.
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:74
double height
The height of the image (net coordinates in y-direction, in m)
virtual void endSnapshot()
Ends a video snapshot.
double getDelay() const
Returns the delay of the parent application.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
int myMouseHotspotX
Offset to the mouse-hotspot from the mouse position.
void addDecals(const std::vector< Decal > &decals)
add decals
virtual void buildColorRainbow(GUIColorScheme &, int, GUIGlObjectType)
recalibrate color scheme according to the current value range
bool removeAdditionalGLVisualisation(const GUIGlObject *const which)
Removes an object from the list of objects that show additional things.
MFXMutex myPolyDrawLock
poly draw lock
Position screenPos2NetPos(int x, int y) const
Translate screen position to network position.
double layer
The layer of the image.
std::map< const GUIGlObject *, int > myAdditionallyDrawn
List of objects for which GUIGlObject::drawGLAdditional is called.
virtual GUIGlID getTrackedID() const
get tracked id
double roll
The roll of the image to the ground plane (in degrees)
double getGridHeight() const
get grid Height
std::vector< Decal > myDecals
GUIGlID getObjectAtPosition(Position pos)
returns the id of the object at position using GL_SELECT
virtual void startTrack(int)
star track
virtual long onPaint(FXObject *, FXSelector, void *)
void showToolTipFor(const GUIGlID id)
invokes the tooltip for the given object
Boundary getVisibleBoundary() const
get visible boundary
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:46
double m2p(double meter) const
meter-to-pixels conversion method
double p2m(double pixel) const
pixels-to-meters conversion method
double getGridWidth() const
get grid width
double rot
The rotation of the image in the ground plane (in degrees)
virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist=20)
centers to the chosen artifact
FXComboBox & getColoringSchemesCombo()
get coloring schemes combo
bool initialised
Whether this image was initialised (inserted as a texture)
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 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 int doPaintGL(int, const Boundary &)
paint GL
void updatePositionInformation() const
update position information
GUIPerspectiveChanger * myChanger
The perspective changer.
bool myUseToolTips
use tool tips
std::string makeSnapshot(const std::string &destFile)
Takes a snapshots and writes it into the given file.
GUIGLObjectPopupMenu * myPopup
The current popup-menu.
FXMutex * myApplicationSnapshotsLock
void destroyPopup()
destoys the popup
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:50
virtual void showViewportEditor()
show viewport editor
FXbool makeCurrent()
A reimplementation due to some internal reasons.
void 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)
virtual long onLeftBtnRelease(FXObject *, FXSelector, void *)
GUIVisualizationSettings * myVisualizationSettings
visualization settings
void paintGL()
performs the painting of the simulation
virtual SUMOTime getCurrentTimeStep() const
get the current simulation time
void setWindowCursorPosition(FXint x, FXint y)
Returns the information whether rotation is allowd.
The popup menu of a globject.
double centerZ
The center of the image in z-direction (net coordinates, in m)
MFXMutex mySnapshotsLock
The mutex to use before accessing the decals list in order to avoid thread conficts.
void drawDecals()
Draws the stored decals.
bool isAdditionalGLVisualisationEnabled(GUIGlObject *const which) const
Check if an object is added in the additional GL visualitation.
double tilt
The tilt of the image to the ground plane (in degrees)
GUIPerspectiveChanger & getChanger() const
get changer
GUIVisualizationSettings * getVisualisationSettings() const
get visualitation settings
bool skip2D
Whether this image should be skipped in 2D-views.
GUISUMOAbstractView()
empty constructor
void updateToolTip()
A method that updates the tooltip.
A dialog to change the viewport.
long long int SUMOTime
Definition: TraCIDefs.h:52
void showViewschemeEditor()
show viewsscheme editor
virtual long onRightBtnPress(FXObject *, FXSelector, void *)
virtual long onMouseLeft(FXObject *, FXSelector, void *)
Position getPositionInformation() const
Returns the cursor&#39;s x/y position within the network.
GUIGlID getObjectUnderCursor()
returns the id of the object under the cursor using GL_SELECT
GUIGlChildWindow * myParent
The parent window.
virtual long onRightBtnRelease(FXObject *, FXSelector, void *)
std::set< SUMOTime > * myApplicationSnapshots
std::vector< GUIGlID > getObjectsInBoundary(const Boundary &bound)
returns the ids of all objects in the given boundary
void setApplicationSnapshots(std::set< SUMOTime > *snapshots, FXMutex *lock)
add snapshot synchronization
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:61