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 setViewport(const Position& lookFrom, const Position& lookAt);
156 
160  void startTrack(int id);
161 
162 
165  void stopTrack();
166 
167 
171  int getTrackedID() const;
172 
173  bool setColorScheme(const std::string& name);
174 
176  void onGamingClick(Position pos);
177 
179  SUMOTime getCurrentTimeStep() const;
180 
181  void remove(GUIVehicle* veh);
182 
183  // callback
184  long onConfigure(FXObject*, FXSelector, void*);
185  long onKeyPress(FXObject*, FXSelector, void*);
186  long onKeyRelease(FXObject*, FXSelector, void*);
187  long onLeftBtnPress(FXObject*, FXSelector, void*);
188  long onLeftBtnRelease(FXObject*, FXSelector, void*);
189  long onMiddleBtnPress(FXObject*, FXSelector, void*);
190  long onMiddleBtnRelease(FXObject*, FXSelector, void*);
191  long onRightBtnPress(FXObject*, FXSelector, void*);
192  long onRightBtnRelease(FXObject*, FXSelector, void*);
193  //long onMotion(FXObject*, FXSelector, void*);
194  long onMouseMove(FXObject*, FXSelector, void*);
195  long onPaint(FXObject*, FXSelector, void*);
196  long OnIdle(FXObject* sender, FXSelector sel, void* ptr);
197 
198 private:
199  class SUMOTerrainManipulator : public osgGA::TerrainManipulator {
200  public:
201  SUMOTerrainManipulator() {
202  setAllowThrow(false);
203  }
204  bool performMovementLeftMouseButton(const double eventTimeDelta, const double dx, const double dy) {
205  return osgGA::TerrainManipulator::performMovementMiddleMouseButton(eventTimeDelta, dx, dy);
206  }
207  bool performMovementMiddleMouseButton(const double eventTimeDelta, const double dx, const double dy) {
208  return osgGA::TerrainManipulator::performMovementLeftMouseButton(eventTimeDelta, dx, dy);
209  }
210  bool performMovementRightMouseButton(const double eventTimeDelta, const double dx, const double dy) {
211  return osgGA::TerrainManipulator::performMovementRightMouseButton(eventTimeDelta, dx, -dy);
212  }
213  };
214 
215  class FXOSGAdapter : public osgViewer::GraphicsWindow {
216  public:
217  FXOSGAdapter(GUISUMOAbstractView* parent, FXCursor* cursor);
218  void grabFocus();
219  void grabFocusIfPointerInWindow() {}
220  void useCursor(bool cursorOn);
221 
222  bool makeCurrentImplementation();
223  bool releaseContext();
224  void swapBuffersImplementation();
225 
226  // not implemented yet...just use dummy implementation to get working.
227  bool valid() const {
228  return true;
229  }
230  bool realizeImplementation() {
231  return true;
232  }
233  bool isRealizedImplementation() const {
234  return true;
235  }
236  void closeImplementation() {}
237  bool releaseContextImplementation() {
238  return true;
239  }
240 
241  protected:
242  ~FXOSGAdapter();
243  private:
244  GUISUMOAbstractView* const myParent;
245  FXCursor* const myOldCursor;
246  };
247 
248 protected:
249 
250  osg::ref_ptr<FXOSGAdapter> myAdapter;
251  osg::ref_ptr<osgViewer::Viewer> myViewer;
252  osg::ref_ptr<osg::Group> myRoot;
253 
254 private:
255  GUIVehicle* myTracked;
256  osg::ref_ptr<osgGA::CameraManipulator> myCameraManipulator;
257 
258  SUMOTime myLastUpdate;
259 
260  std::map<MSVehicle*, OSGMovable > myVehicles;
261  std::map<MSTransportable*, OSGMovable > myPersons;
262 
263  osg::ref_ptr<osg::Node> myGreenLight;
264  osg::ref_ptr<osg::Node> myYellowLight;
265  osg::ref_ptr<osg::Node> myRedLight;
266  osg::ref_ptr<osg::Node> myRedYellowLight;
267 
268 protected:
269  GUIOSGView() { }
270 
271 };
272 
273 #endif
274 
275 #endif
276 
277 /****************************************************************************/
278 
279 
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:49
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