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-2017 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 <gui/GUISUMOViewParent.h>
46 
47 
48 // ===========================================================================
49 // class declarations
50 // ===========================================================================
51 class GUINet;
52 class GUISUMOViewParent;
53 class GUIVehicle;
54 class GUILaneWrapper;
55 class MSRoute;
56 namespace osgGA {
57 class CameraManipulator;
58 class NodeTrackerManipulator;
59 }
60 
61 
62 // ===========================================================================
63 // class definitions
64 // ===========================================================================
69 class GUIOSGView : public GUISUMOAbstractView {
70  FXDECLARE(GUIOSGView)
71 public:
76  class Command_TLSChange : public MSTLLogicControl::OnSwitchAction {
77  public:
86  Command_TLSChange(const MSLink* const link, osg::Switch* switchNode);
87 
88 
90  virtual ~Command_TLSChange();
91 
92 
99  void execute();
100 
101 
102  private:
104  const MSLink* const myLink;
105 
107  osg::ref_ptr<osg::Switch> mySwitch;
108 
110  LinkState myLastState;
111 
112 
113  private:
115  Command_TLSChange(const Command_TLSChange&);
116 
118  Command_TLSChange& operator=(const Command_TLSChange&);
119 
120  };
121 
122 
123  struct OSGMovable {
124  osg::ref_ptr<osg::PositionAttitudeTransform> pos;
125  osg::ref_ptr<osg::ShapeDrawable> geom;
126  osg::ref_ptr<osg::Switch> lights;
127  };
128 
129 
131  GUIOSGView(FXComposite* p, GUIMainWindow& app,
132  GUISUMOViewParent* parent, GUINet& net, FXGLVisual* glVis,
133  FXGLCanvas* share);
134 
135  virtual ~GUIOSGView();
136 
138  virtual void buildViewToolBars(GUIGlChildWindow&);
139 
141  void recenterView();
142 
149  void centerTo(GUIGlID id, bool applyZoom, double zoomDist = 20);
150 
151  void showViewportEditor();
152 
154  void setViewportFromTo(const Position& lookFrom, const Position& lookAt);
155 
157  void copyViewportTo(GUISUMOAbstractView* view);
158 
162  void startTrack(int id);
163 
164 
167  void stopTrack();
168 
169 
173  GUIGlID getTrackedID() const;
174 
175  bool setColorScheme(const std::string& name);
176 
178  void onGamingClick(Position pos);
179 
181  SUMOTime getCurrentTimeStep() const;
182 
183  void remove(GUIVehicle* veh);
184 
185  // callback
186  long onConfigure(FXObject*, FXSelector, void*);
187  long onKeyPress(FXObject*, FXSelector, void*);
188  long onKeyRelease(FXObject*, FXSelector, void*);
189  long onLeftBtnPress(FXObject*, FXSelector, void*);
190  long onLeftBtnRelease(FXObject*, FXSelector, void*);
191  long onMiddleBtnPress(FXObject*, FXSelector, void*);
192  long onMiddleBtnRelease(FXObject*, FXSelector, void*);
193  long onRightBtnPress(FXObject*, FXSelector, void*);
194  long onRightBtnRelease(FXObject*, FXSelector, void*);
195  //long onMotion(FXObject*, FXSelector, void*);
196  long onMouseMove(FXObject*, FXSelector, void*);
197  long onPaint(FXObject*, FXSelector, void*);
198  long OnIdle(FXObject* sender, FXSelector sel, void* ptr);
199 
200 private:
201  class SUMOTerrainManipulator : public osgGA::TerrainManipulator {
202  public:
203  SUMOTerrainManipulator() {
204  setAllowThrow(false);
205  }
206  bool performMovementLeftMouseButton(const double eventTimeDelta, const double dx, const double dy) {
207  return osgGA::TerrainManipulator::performMovementMiddleMouseButton(eventTimeDelta, dx, dy);
208  }
209  bool performMovementMiddleMouseButton(const double eventTimeDelta, const double dx, const double dy) {
210  return osgGA::TerrainManipulator::performMovementLeftMouseButton(eventTimeDelta, dx, dy);
211  }
212  bool performMovementRightMouseButton(const double eventTimeDelta, const double dx, const double dy) {
213  return osgGA::TerrainManipulator::performMovementRightMouseButton(eventTimeDelta, dx, -dy);
214  }
215  };
216 
217  class FXOSGAdapter : public osgViewer::GraphicsWindow {
218  public:
219  FXOSGAdapter(GUISUMOAbstractView* parent, FXCursor* cursor);
220  void grabFocus();
221  void grabFocusIfPointerInWindow() {}
222  void useCursor(bool cursorOn);
223 
224  bool makeCurrentImplementation();
225  bool releaseContext();
226  void swapBuffersImplementation();
227 
228  // not implemented yet...just use dummy implementation to get working.
229  bool valid() const {
230  return true;
231  }
232  bool realizeImplementation() {
233  return true;
234  }
235  bool isRealizedImplementation() const {
236  return true;
237  }
238  void closeImplementation() {}
239  bool releaseContextImplementation() {
240  return true;
241  }
242 
243  protected:
244  ~FXOSGAdapter();
245  private:
246  GUISUMOAbstractView* const myParent;
247  FXCursor* const myOldCursor;
248  };
249 
250 protected:
251 
252  osg::ref_ptr<FXOSGAdapter> myAdapter;
253  osg::ref_ptr<osgViewer::Viewer> myViewer;
254  osg::ref_ptr<osg::Group> myRoot;
255 
256 private:
257  GUIVehicle* myTracked;
258  osg::ref_ptr<osgGA::CameraManipulator> myCameraManipulator;
259 
260  SUMOTime myLastUpdate;
261 
262  std::map<MSVehicle*, OSGMovable > myVehicles;
263  std::map<MSTransportable*, OSGMovable > myPersons;
264 
265  osg::ref_ptr<osg::Node> myGreenLight;
266  osg::ref_ptr<osg::Node> myYellowLight;
267  osg::ref_ptr<osg::Node> myRedLight;
268  osg::ref_ptr<osg::Node> myRedYellowLight;
269 
270 protected:
271  GUIOSGView() { }
272 
273 };
274 
275 #endif
276 
277 #endif
278 
279 /****************************************************************************/
280 
281 
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
long long int SUMOTime
Definition: TraCIDefs.h:52
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:61