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>
54 #include <utils/shapes/Polygon.h>
57 
58 
59 // ===========================================================================
60 // class declarations
61 // ===========================================================================
62 class GUIGlChildWindow;
63 class GUIVehicle;
65 class GUIMainWindow;
67 class GUIGlObject;
71 
72 
73 // ===========================================================================
74 // class definitions
75 // ===========================================================================
82 class GUISUMOAbstractView : public FXGLCanvas {
83  FXDECLARE(GUISUMOAbstractView)
84 public:
86  GUISUMOAbstractView(FXComposite* p, GUIMainWindow& app, GUIGlChildWindow* parent, const SUMORTree& grid, FXGLVisual* glVis, FXGLCanvas* share);
87 
89  virtual ~GUISUMOAbstractView();
90 
93 
95  virtual void recenterView();
96 
103  virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist = 20);
104 
106  void centerTo(const Boundary& bound);
107 
109  virtual void setViewportFromTo(const Position& lookFrom, const Position& lookAt);
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 
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 
172  void setSnapshots(std::map<SUMOTime, std::string> snaps);
173 
181  std::string makeSnapshot(const std::string& destFile);
182 
184  virtual void saveFrame(const std::string& destFile, FXColor* buf);
185 
187  virtual void endSnapshot() {}
188 
190  virtual void checkSnapshots();
191 
193  virtual SUMOTime getCurrentTimeStep() const;
195 
198 
200  virtual void showViewportEditor();
201 
203  void showViewschemeEditor();
204 
206  void showToolTips(bool val);
207 
209  virtual bool setColorScheme(const std::string&);
210 
213 
215  void remove(GUIDialog_EditViewport*);
216 
218  void remove(GUIDialog_ViewSettings*);
219 
221  // @todo: check why this is here
222  double getGridWidth() const;
223 
225  // @todo: check why this is here
226  double getGridHeight() const;
227 
229  virtual void startTrack(int /*id*/);
230 
232  virtual void stopTrack();
233 
235  virtual GUIGlID getTrackedID() const;
236 
238  virtual void onGamingClick(Position /*pos*/);
239 
242 
247  bool addAdditionalGLVisualisation(const GUIGlObject* const which);
248 
254  bool removeAdditionalGLVisualisation(const GUIGlObject* const which);
255 
260  bool isAdditionalGLVisualisationEnabled(GUIGlObject* const which) const;
262 
264  void destroyPopup();
265 
266 public:
269  struct Decal {
271  Decal();
272 
274  std::string filename;
276  double centerX;
278  double centerY;
280  double centerZ;
282  double width;
284  double height;
286  double altitude;
288  double rot;
290  double tilt;
292  double roll;
294  double layer;
298  bool skip2D;
302  int glID;
304  FXImage* image;
305  };
306 
307 public:
309  FXComboBox& getColoringSchemesCombo();
310 
313 
315  Position snapToActiveGrid(const Position& pos) const;
316 
318  Position screenPos2NetPos(int x, int y) const;
319 
321  void addDecals(const std::vector<Decal>& decals);
322 
325 
327  double getDelay() const;
328 
330  void setDelay(double delay);
331 
332 protected:
334  void paintGL();
335 
337  void updatePositionInformation() const;
338 
340  virtual int doPaintGL(int /*mode*/, const Boundary& /*boundary*/);
341 
343  virtual void doInit();
344 
346  void paintGLGrid();
347 
349  void displayLegend();
350 
353 
356 
358  std::vector<GUIGlID> getObjectsAtPosition(Position pos, double radius);
359 
361  std::vector<GUIGlID> getObjectsInBoundary(const Boundary& bound);
362 
364  void showToolTipFor(const GUIGlID id);
365 
366 protected:
368  FXImage* checkGDALImage(Decal& d);
369 
371  void drawDecals();
372 
376  void applyGLTransform(bool fixRatio = true);
377 
378 protected:
381 
384 
387 
390 
393 
396 
399 
402 
405 
408 
411 
414 
417 
421  std::vector<Decal> myDecals;
422 
426 
428  std::map<SUMOTime, std::string> mySnapshots;
429 
432 
434  std::map<const GUIGlObject*, int> myAdditionallyDrawn;
435 
436 protected:
439 };
440 
441 
442 #endif
443 
444 /****************************************************************************/
445 
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
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.
void updatePositionInformation() const
update position information
GUIVisualizationSettings * getVisualisationSettings() const
get visualitation settings
GUIMainWindow * myApp
The application.
Position snapToActiveGrid(const Position &pos) const
Returns a position that is mapped to the closest grid point if the grid is active.
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 ...
void setSnapshots(std::map< SUMOTime, std::string > snaps)
Sets the snapshot time to file map.
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:74
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.
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
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.
MFXMutex myPolyDrawLock
poly draw lock
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)
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:46
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
GUIPerspectiveChanger & getChanger() const
get changer
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
Position screenPos2NetPos(int x, int y) const
Translate screen position to network position.
std::map< SUMOTime, std::string > mySnapshots
Snapshots.
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.
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 *)
double m2p(double meter) const
meter-to-pixels conversion method
GUIVisualizationSettings * myVisualizationSettings
visualization settings
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
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)
void drawDecals()
Draws the stored decals.
double tilt
The tilt of the image to the ground plane (in degrees)
bool skip2D
Whether this image should be skipped in 2D-views.
GUISUMOAbstractView()
empty constructor
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.
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 *)
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::vector< GUIGlID > getObjectsInBoundary(const Boundary &bound)
returns the ids of all objects in the given boundary
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:61