SUMO - Simulation of Urban MObility
GUIOSGView.h
Go to the documentation of this file.
1 /****************************************************************************/
7 // An OSG-based 3D view on the simulation
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 #ifndef GUIOSGView_h
21 #define GUIOSGView_h
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #ifdef HAVE_OSG
33 
34 #include <string>
35 #include <osgGA/TerrainManipulator>
36 #include <osgViewer/Viewer>
37 #include <osg/PositionAttitudeTransform>
38 #include <osg/ShapeDrawable>
40 #include <utils/geom/Boundary.h>
41 #include <utils/geom/Position.h>
42 #include <utils/common/RGBColor.h>
44 #include <utils/shapes/Polygon.h>
45 #include <gui/GUISUMOViewParent.h>
47 
48 
49 // ===========================================================================
50 // class declarations
51 // ===========================================================================
52 class GUINet;
53 class GUISUMOViewParent;
54 class GUIVehicle;
55 class GUILaneWrapper;
56 class MSRoute;
57 namespace osgGA {
58 class CameraManipulator;
59 class NodeTrackerManipulator;
60 }
61 
62 
63 // ===========================================================================
64 // class definitions
65 // ===========================================================================
70 class GUIOSGView : public GUISUMOAbstractView {
71  FXDECLARE(GUIOSGView)
72 public:
77  class Command_TLSChange : public MSTLLogicControl::OnSwitchAction {
78  public:
87  Command_TLSChange(const MSLink* const link, osg::Switch* switchNode);
88 
89 
91  virtual ~Command_TLSChange();
92 
93 
100  void execute();
101 
102 
103  private:
105  const MSLink* const myLink;
106 
108  osg::ref_ptr<osg::Switch> mySwitch;
109 
111  LinkState myLastState;
112 
113 
114  private:
116  Command_TLSChange(const Command_TLSChange&);
117 
119  Command_TLSChange& operator=(const Command_TLSChange&);
120 
121  };
122 
123 
124  struct OSGMovable {
125  osg::ref_ptr<osg::PositionAttitudeTransform> pos;
126  osg::ref_ptr<osg::ShapeDrawable> geom;
127  osg::ref_ptr<osg::Switch> lights;
128  };
129 
130 
132  GUIOSGView(FXComposite* p, GUIMainWindow& app,
133  GUISUMOViewParent* parent, GUINet& net, FXGLVisual* glVis,
134  FXGLCanvas* share);
135 
136  virtual ~GUIOSGView();
137 
139  virtual void buildViewToolBars(GUIGlChildWindow&);
140 
142  void recenterView();
143 
150  void centerTo(GUIGlID id, bool applyZoom, SUMOReal zoomDist = 20);
151 
152  void showViewportEditor();
153 
155  void setViewportFromTo(const Position& lookFrom, const Position& lookAt);
156 
158  void copyViewportTo(GUISUMOAbstractView* view);
159 
163  void startTrack(int id);
164 
165 
168  void stopTrack();
169 
170 
174  GUIGlID getTrackedID() const;
175 
176  bool setColorScheme(const std::string& name);
177 
179  void onGamingClick(Position pos);
180 
182  SUMOTime getCurrentTimeStep() const;
183 
184  void remove(GUIVehicle* veh);
185 
186  // callback
187  long onConfigure(FXObject*, FXSelector, void*);
188  long onKeyPress(FXObject*, FXSelector, void*);
189  long onKeyRelease(FXObject*, FXSelector, void*);
190  long onLeftBtnPress(FXObject*, FXSelector, void*);
191  long onLeftBtnRelease(FXObject*, FXSelector, void*);
192  long onMiddleBtnPress(FXObject*, FXSelector, void*);
193  long onMiddleBtnRelease(FXObject*, FXSelector, void*);
194  long onRightBtnPress(FXObject*, FXSelector, void*);
195  long onRightBtnRelease(FXObject*, FXSelector, void*);
196  //long onMotion(FXObject*, FXSelector, void*);
197  long onMouseMove(FXObject*, FXSelector, void*);
198  long onPaint(FXObject*, FXSelector, void*);
199  long OnIdle(FXObject* sender, FXSelector sel, void* ptr);
200 
201 private:
202  class SUMOTerrainManipulator : public osgGA::TerrainManipulator {
203  public:
204  SUMOTerrainManipulator() {
205  setAllowThrow(false);
206  }
207  bool performMovementLeftMouseButton(const double eventTimeDelta, const double dx, const double dy) {
208  return osgGA::TerrainManipulator::performMovementMiddleMouseButton(eventTimeDelta, dx, dy);
209  }
210  bool performMovementMiddleMouseButton(const double eventTimeDelta, const double dx, const double dy) {
211  return osgGA::TerrainManipulator::performMovementLeftMouseButton(eventTimeDelta, dx, dy);
212  }
213  bool performMovementRightMouseButton(const double eventTimeDelta, const double dx, const double dy) {
214  return osgGA::TerrainManipulator::performMovementRightMouseButton(eventTimeDelta, dx, -dy);
215  }
216  };
217 
218  class FXOSGAdapter : public osgViewer::GraphicsWindow {
219  public:
220  FXOSGAdapter(GUISUMOAbstractView* parent, FXCursor* cursor);
221  void grabFocus();
222  void grabFocusIfPointerInWindow() {}
223  void useCursor(bool cursorOn);
224 
225  bool makeCurrentImplementation();
226  bool releaseContext();
227  void swapBuffersImplementation();
228 
229  // not implemented yet...just use dummy implementation to get working.
230  bool valid() const {
231  return true;
232  }
233  bool realizeImplementation() {
234  return true;
235  }
236  bool isRealizedImplementation() const {
237  return true;
238  }
239  void closeImplementation() {}
240  bool releaseContextImplementation() {
241  return true;
242  }
243 
244  protected:
245  ~FXOSGAdapter();
246  private:
247  GUISUMOAbstractView* const myParent;
248  FXCursor* const myOldCursor;
249  };
250 
251 protected:
252 
253  osg::ref_ptr<FXOSGAdapter> myAdapter;
254  osg::ref_ptr<osgViewer::Viewer> myViewer;
255  osg::ref_ptr<osg::Group> myRoot;
256 
257 private:
258  GUIVehicle* myTracked;
259  osg::ref_ptr<osgGA::CameraManipulator> myCameraManipulator;
260 
261  SUMOTime myLastUpdate;
262 
263  std::map<MSVehicle*, OSGMovable > myVehicles;
264  std::map<MSTransportable*, OSGMovable > myPersons;
265 
266  osg::ref_ptr<osg::Node> myGreenLight;
267  osg::ref_ptr<osg::Node> myYellowLight;
268  osg::ref_ptr<osg::Node> myRedLight;
269  osg::ref_ptr<osg::Node> myRedYellowLight;
270 
271 protected:
272  GUIOSGView() { }
273 
274 };
275 
276 #endif
277 
278 #endif
279 
280 /****************************************************************************/
281 
282 
long long int SUMOTime
Definition: SUMOTime.h:43
A class that stores and controls tls and switching of their programs.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
A single child window which contains a view of the simulation area.
unsigned int GUIGlID
Definition: GUIGlObject.h:50
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:89
#define SUMOReal
Definition: config.h:213
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:61