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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // The base class for a view
21 /****************************************************************************/
22 #ifndef GUISUMOAbstractView_h
23 #define GUISUMOAbstractView_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
36 #include <vector>
37 #include <map>
38 #include <fx.h>
39 // fx3d includes windows.h so we need to guard against macro pollution
40 #ifdef WIN32
41 #define NOMINMAX
42 #endif
43 #include <fx3d.h>
44 #ifdef WIN32
45 #undef NOMINMAX
46 #endif
47 
49 #include <utils/geom/Boundary.h>
50 #include <utils/geom/Position.h>
51 #include <utils/common/RGBColor.h>
52 #include <utils/common/SUMOTime.h>
55 
56 
57 // ===========================================================================
58 // class declarations
59 // ===========================================================================
60 class GUIGlChildWindow;
61 class GUIVehicle;
63 class GUIMainWindow;
65 class GUIGlObject;
69 
70 
71 // ===========================================================================
72 // class definitions
73 // ===========================================================================
80 class GUISUMOAbstractView : public FXGLCanvas {
81  FXDECLARE(GUISUMOAbstractView)
82 public:
84  GUISUMOAbstractView(FXComposite* p, GUIMainWindow& app, GUIGlChildWindow* parent, const SUMORTree& grid, FXGLVisual* glVis, FXGLCanvas* share);
85 
87  virtual ~GUISUMOAbstractView();
88 
91 
93  virtual void recenterView();
94 
101  virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist = 20);
102 
104  void centerTo(const Boundary& bound);
105 
107  virtual void setViewportFromTo(const Position& lookFrom, const Position& lookAt);
108 
110  virtual void copyViewportTo(GUISUMOAbstractView* view);
111 
113  double m2p(double meter) const;
114 
116  double p2m(double pixel) const;
117 
120  //bool allowRotation() const;
121 
123  void setWindowCursorPosition(FXint x, FXint y);
124 
126  FXbool makeCurrent();
127 
129  bool isInEditMode();
130 
133 
136 
138 
139  virtual long onConfigure(FXObject*, FXSelector, void*);
140  virtual long onPaint(FXObject*, FXSelector, void*);
141  virtual long onLeftBtnPress(FXObject*, FXSelector, void*);
142  virtual long onLeftBtnRelease(FXObject*, FXSelector, void*);
143  virtual long onMiddleBtnPress(FXObject*, FXSelector, void*);
144  virtual long onMiddleBtnRelease(FXObject*, FXSelector, void*);
145  virtual long onRightBtnPress(FXObject*, FXSelector, void*);
146  virtual long onRightBtnRelease(FXObject*, FXSelector, void*);
147  virtual long onDoubleClicked(FXObject*, FXSelector, void*);
148  virtual long onMouseWheel(FXObject*, FXSelector, void*);
149  virtual long onMouseMove(FXObject*, FXSelector, void*);
150  virtual long onMouseLeft(FXObject*, FXSelector, void*);
152 
154 
155  virtual long onKeyPress(FXObject* o, FXSelector sel, void* data);
156  virtual long onKeyRelease(FXObject* o, FXSelector sel, void* data);
158 
159  //@brief open object dialog
160  virtual void openObjectDialog();
161 
163  void updateToolTip();
164 
167 
170  void addSnapshot(SUMOTime time, const std::string& file);
171 
179  std::string makeSnapshot(const std::string& destFile);
180 
182  virtual void saveFrame(const std::string& destFile, FXColor* buf);
183 
185  virtual void endSnapshot() {}
186 
188  virtual void checkSnapshots();
189 
191  virtual SUMOTime getCurrentTimeStep() const;
193 
196 
198  virtual void showViewportEditor();
199 
201  void showViewschemeEditor();
202 
204  void showToolTips(bool val);
205 
207  virtual bool setColorScheme(const std::string&);
208 
211 
213  virtual void buildColorRainbow(GUIColorScheme& /*scheme*/, int /*active*/, GUIGlObjectType /*objectType*/) { }
214 
216  void remove(GUIDialog_EditViewport*);
217 
219  void remove(GUIDialog_ViewSettings*);
220 
222  // @todo: check why this is here
223  double getGridWidth() const;
224 
226  // @todo: check why this is here
227  double getGridHeight() const;
228 
230  virtual void startTrack(int /*id*/);
231 
233  virtual void stopTrack();
234 
236  virtual GUIGlID getTrackedID() const;
237 
239  virtual void onGamingClick(Position /*pos*/);
240 
243 
248  bool addAdditionalGLVisualisation(const GUIGlObject* const which);
249 
255  bool removeAdditionalGLVisualisation(const GUIGlObject* const which);
256 
261  bool isAdditionalGLVisualisationEnabled(GUIGlObject* const which) const;
263 
265  const Position& getPopupPosition() const;
266 
268  void destroyPopup();
269 
271  void setApplicationSnapshots(std::set<SUMOTime>* snapshots, FXMutex* lock) {
272  myApplicationSnapshots = snapshots;
274  }
275 
276 public:
279  struct Decal {
281  Decal();
282 
284  std::string filename;
286  double centerX;
288  double centerY;
290  double centerZ;
292  double width;
294  double height;
296  double altitude;
298  double rot;
300  double tilt;
302  double roll;
304  double layer;
308  bool skip2D;
312  int glID;
314  FXImage* image;
315  };
316 
317 public:
319  FXComboBox& getColoringSchemesCombo();
320 
323 
325  Position snapToActiveGrid(const Position& pos) const;
326 
328  Position screenPos2NetPos(int x, int y) const;
329 
331  void addDecals(const std::vector<Decal>& decals);
332 
335 
337  double getDelay() const;
338 
340  void setDelay(double delay);
341 
342 protected:
344  void paintGL();
345 
347  void updatePositionInformation() const;
348 
350  virtual int doPaintGL(int /*mode*/, const Boundary& /*boundary*/);
351 
353  virtual void doInit();
354 
356  void paintGLGrid();
357 
359  void displayLegend();
360 
363 
366 
368  std::vector<GUIGlID> getObjectsAtPosition(Position pos, double radius);
369 
371  std::vector<GUIGlID> getObjectsInBoundary(const Boundary& bound);
372 
374  void showToolTipFor(const GUIGlID id);
375 
376 protected:
378  FXImage* checkGDALImage(Decal& d);
379 
381  void drawDecals();
382 
386  void applyGLTransform(bool fixRatio = true);
387 
388 protected:
391 
394 
397 
400 
403 
406 
409 
412 
415 
418 
421 
424 
427 
430 
434  std::vector<Decal> myDecals;
435 
439 
441  std::map<SUMOTime, std::vector<std::string> > mySnapshots;
442  std::set<SUMOTime>* myApplicationSnapshots;
443 
447 
450 
452  std::map<const GUIGlObject*, int> myAdditionallyDrawn;
453 
454 protected:
457 };
458 
459 
460 #endif
461 
462 /****************************************************************************/
463 
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.
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.
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
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:73
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:47
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
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:45
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.
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:49
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
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
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.
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:51
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::set< SUMOTime > * myApplicationSnapshots
std::vector< GUIGlID > getObjectsInBoundary(const Boundary &bound)
returns the ids of all objects in the given boundary
const Position & getPopupPosition() const
get position of current popup
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:60