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-2016 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,
87  GUIGlChildWindow* parent, const SUMORTree& grid,
88  FXGLVisual* glVis, FXGLCanvas* share);
89 
91  virtual ~GUISUMOAbstractView();
92 
95 
97  virtual void recenterView();
98 
105  virtual void centerTo(GUIGlID id, bool applyZoom, SUMOReal zoomDist = 20);
106 
108  void centerTo(const Boundary& bound);
109 
111  virtual void setViewport(const Position& lookFrom, const Position& lookAt);
112 
114  SUMOReal m2p(SUMOReal meter) const;
115 
117  SUMOReal p2m(SUMOReal pixel) const;
118 
120 // bool allowRotation() const;
121 
123  void setWindowCursorPosition(FXint x, FXint y);
124 
126  FXbool makeCurrent();
127 
129  bool isInEditMode();
130 
132  return *myChanger;
133  }
134 
136 
137  virtual long onConfigure(FXObject*, FXSelector, void*);
138  virtual long onPaint(FXObject*, FXSelector, void*);
139  virtual long onLeftBtnPress(FXObject*, FXSelector, void*);
140  virtual long onLeftBtnRelease(FXObject*, FXSelector, void*);
141  virtual long onMiddleBtnPress(FXObject*, FXSelector, void*) {
142  return 1;
143  }
144  virtual long onMiddleBtnRelease(FXObject*, FXSelector, void*) {
145  return 1;
146  }
147  virtual long onRightBtnPress(FXObject*, FXSelector, void*);
148  virtual long onRightBtnRelease(FXObject*, FXSelector, void*);
149  virtual long onMouseWheel(FXObject*, FXSelector, void*);
150  virtual long onMouseMove(FXObject*, FXSelector, void*);
151  virtual long onMouseLeft(FXObject*, FXSelector, void*);
152 
153  virtual long onKeyPress(FXObject* o, FXSelector sel, void* data);
154  virtual long onKeyRelease(FXObject* o, FXSelector sel, void* data);
155 
156 
157  virtual void openObjectDialog();
158 
160  void updateToolTip();
161 
162 
165 
169  void setSnapshots(std::map<SUMOTime, std::string> snaps);
170 
171 
180  std::string makeSnapshot(const std::string& destFile);
181 
182 
185  virtual void saveFrame(const std::string& destFile, FXColor* buf) {
186  UNUSED_PARAMETER(destFile);
187  UNUSED_PARAMETER(buf);
188  }
189 
190 
193  virtual void endSnapshot() {}
194 
195 
198  virtual void checkSnapshots();
199 
201  virtual SUMOTime getCurrentTimeStep() const {
202  return 0;
203  }
205 
206 
209 
210  virtual void showViewportEditor();
211 
212  void showViewschemeEditor();
213  void showToolTips(bool val);
214  virtual bool setColorScheme(const std::string&) {
215  return true;
216  }
217 
220  }
221 
222  void remove(GUIDialog_EditViewport*) {
223  myViewportChooser = 0;
224  }
225 
226  void remove(GUIDialog_ViewSettings*) {
228  }
229 
230 
231  // @todo: check why this is here
232  SUMOReal getGridWidth() const;
233  // @todo: check why this is here
234  SUMOReal getGridHeight() const;
235 
236  virtual void startTrack(int /*id*/) { }
237  virtual void stopTrack() { }
238  virtual int getTrackedID() const {
239  return -1;
240  }
241 
242  virtual void onGamingClick(Position /*pos*/) { }
243 
246 
252  bool addAdditionalGLVisualisation(GUIGlObject* const which);
253 
254 
260  bool removeAdditionalGLVisualisation(GUIGlObject* const which);
262 
263 
265  void destroyPopup();
266 
267 
268 public:
269 
273  struct Decal {
276  : filename(), centerX(0), centerY(0), centerZ(0),
277  width(0), height(0), altitude(0), rot(0), tilt(0), roll(0), layer(0),
278  initialised(false), skip2D(false), glID(-1), image(0) { }
279 
281  std::string filename;
305  bool skip2D;
307  int glID;
309  FXImage* image;
310  };
311 
312 
313 public:
314  FXComboBox& getColoringSchemesCombo();
315 
316 
321 
322  void addDecals(const std::vector<Decal>& decals) {
323  myDecals.insert(myDecals.end(), decals.begin(), decals.end());
324  }
325 
326 
329  }
330 
334  SUMOReal getDelay() const;
335 
338  void setDelay(SUMOReal delay);
339 
340 protected:
342  void paintGL();
343 
344  void updatePositionInformation() const;
345 
346 
347  virtual int doPaintGL(int /*mode*/, const Boundary& /*boundary*/) {
348  return 0;
349  }
350 
351  virtual void doInit() { }
352 
354  void paintGLGrid();
355 
360  void displayLegend();
361 
362 
365 
368 
370  std::vector<GUIGlID> getObjectsAtPosition(Position pos, SUMOReal radius);
371 
373  std::vector<GUIGlID> getObjectsInBoundary(const Boundary& bound);
374 
376  void showToolTipFor(unsigned int id);
377 
378 
379 protected:
382  FXImage* checkGDALImage(Decal& d);
383 
386  void drawDecals();
387 
388  // applies gl-transformations to fit the Boundary given by myChanger onto
389  // the canvas. If fixRatio is true, this boundary will be enlarged to
390  // prevent anisotropic stretching. (this should be set to false when doing
391  // selections)
392  void applyGLTransform(bool fixRatio = true);
393 
394 protected:
397 
400 
403 
406 
409 
412 
415 
417 
419 
422 
424 
427 
429 
430 
433 
435  std::vector<Decal> myDecals;
436 
440 
441 
442  std::map<SUMOTime, std::string> mySnapshots;
443 
445 
447  std::map<GUIGlObject*, int> myAdditionallyDrawn;
448 
449 
450 protected:
452 
453 };
454 
455 
456 #endif
457 
458 /****************************************************************************/
459 
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 *)
virtual void startTrack(int)
long long int SUMOTime
Definition: SUMOTime.h:43
FXImage * checkGDALImage(Decal &d)
check whether we can read image data or position with gdal
FXImage * image
The image pointer for later cleanup.
SUMOReal roll
The roll of the image to the ground plane (in degrees)
void showToolTipFor(unsigned int id)
invokes the tooltip for the given object
virtual void setViewport(const Position &lookFrom, const Position &lookAt)
applies the given viewport settings
GUIVisualizationSettings * getVisualisationSettings()
virtual void centerTo(GUIGlID id, bool applyZoom, SUMOReal zoomDist=20)
centers to the chosen artifact
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 *)
Stores the information about how to visualize structures.
The dialog to change the view (gui) settings.
GUIMainWindow * myApp
The application.
virtual SUMOTime getCurrentTimeStep() const
get the current simulation time
MFXMutex myDecalsLock
The mutex to use before accessing the decals list in order to avoid thread conficts.
SUMOReal p2m(SUMOReal pixel) const
pixels-to-meters conversion method
bool addAdditionalGLVisualisation(GUIGlObject *const which)
Adds an object to call its additional visualisation method.
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)
SUMOReal getGridHeight() const
SUMOReal centerZ
The center of the image in z-direction (net coordinates, in m)
int glID
The gl-id of the texture that holds this image.
void setSnapshots(std::map< SUMOTime, std::string > snaps)
Sets the snapshot time to file map.
SUMOReal width
The width of the image (net coordinates in x-direction, in m)
GUIDialog_ViewSettings * myVisualizationChanger
virtual void buildViewToolBars(GUIGlChildWindow &)
builds the view toolbars
GUIDialog_EditViewport * myViewportChooser
A RT-tree for efficient storing of SUMO&#39;s GL-objects.
Definition: SUMORTree.h:74
virtual void endSnapshot()
Ends a video snapshot.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
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)
virtual int getTrackedID() const
GUIPerspectiveChanger & getChanger() const
std::vector< GUIGlID > getObjectsAtPosition(Position pos, SUMOReal radius)
returns the ids of the object at position within the given (rectangular) radius using GL_SELECT ...
std::vector< Decal > myDecals
The list of decals to show.
GUIGlID getObjectAtPosition(Position pos)
returns the id of the object at position using GL_SELECT
virtual int doPaintGL(int, const Boundary &)
bool removeAdditionalGLVisualisation(GUIGlObject *const which)
Removes an object from the list of objects that show additional things.
virtual long onPaint(FXObject *, FXSelector, void *)
std::map< GUIGlObject *, int > myAdditionallyDrawn
List of objects for which GUIGlObject::drawGLAdditional is called.
Boundary getVisibleBoundary() const
virtual long onMiddleBtnPress(FXObject *, FXSelector, void *)
virtual long onKeyPress(FXObject *o, FXSelector sel, void *data)
virtual long onMiddleBtnRelease(FXObject *, FXSelector, void *)
SUMOReal altitude
The altitude of the image (net coordinates in z-direction, in m)
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
SUMOReal centerY
The center of the image in y-direction (net coordinates, in m)
virtual void saveFrame(const std::string &destFile, FXColor *buf)
Adds a frame to a video snapshot which will be initialized if neccessary.
FXComboBox & getColoringSchemesCombo()
bool initialised
Whether this image was initialised (inserted as a texture)
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.
std::map< SUMOTime, std::string > mySnapshots
void updatePositionInformation() const
SUMOReal getDelay() const
Returns the delay of the parent application.
GUIPerspectiveChanger * myChanger
The perspective changer.
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.
unsigned int GUIGlID
Definition: GUIGlObject.h:49
virtual void showViewportEditor()
FXbool makeCurrent()
A reimplementation due to some internal reasons.
SUMOReal height
The height of the image (net coordinates in y-direction, in m)
void applyGLTransform(bool fixRatio=true)
virtual long onLeftBtnRelease(FXObject *, FXSelector, void *)
SUMOReal centerX
The center of the image in x-direction (net coordinates, in m)
GUIVisualizationSettings * myVisualizationSettings
SUMOReal m2p(SUMOReal meter) const
meter-to-pixels conversion method
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.
SUMOReal getGridWidth() const
virtual bool setColorScheme(const std::string &)
void drawDecals()
Draws the stored decals.
SUMOReal layer
The layer of the image.
GUIVisualizationSettings * getVisualisationSettings() const
void setDelay(SUMOReal delay)
Sets the delay of the parent application.
bool skip2D
Whether this image should be skipped in 2D-views.
#define SUMOReal
Definition: config.h:213
void updateToolTip()
A method that updates the tooltip.
A dialog to change the viewport.
virtual void onGamingClick(Position)
SUMOReal tilt
The tilt of the image to the ground plane (in degrees)
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
SUMOReal rot
The rotation of the image in the ground plane (in degrees)
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