SUMO - Simulation of Urban MObility
GUIOSGView.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 /****************************************************************************/
17 // An OSG-based 3D view on the simulation
18 /****************************************************************************/
19 #ifndef GUIOSGView_h
20 #define GUIOSGView_h
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #ifdef HAVE_OSG
32 
33 #include <string>
34 #include <osgGA/TerrainManipulator>
35 #include <osgViewer/Viewer>
36 #include <osg/PositionAttitudeTransform>
37 #include <osg/ShapeDrawable>
39 #include <utils/geom/Boundary.h>
40 #include <utils/geom/Position.h>
41 #include <utils/common/RGBColor.h>
43 #include <gui/GUISUMOViewParent.h>
45 
46 
47 // ===========================================================================
48 // class declarations
49 // ===========================================================================
50 class GUINet;
51 class GUISUMOViewParent;
52 class GUIVehicle;
53 class GUILaneWrapper;
54 class MSRoute;
55 namespace osgGA {
56 class CameraManipulator;
57 class NodeTrackerManipulator;
58 }
59 
60 
61 // ===========================================================================
62 // class definitions
63 // ===========================================================================
68 class GUIOSGView : public GUISUMOAbstractView {
69  FXDECLARE(GUIOSGView)
70 public:
75  class Command_TLSChange : public MSTLLogicControl::OnSwitchAction {
76  public:
85  Command_TLSChange(const MSLink* const link, osg::Switch* switchNode);
86 
87 
89  virtual ~Command_TLSChange();
90 
91 
98  void execute();
99 
100 
101  private:
103  const MSLink* const myLink;
104 
106  osg::ref_ptr<osg::Switch> mySwitch;
107 
109  LinkState myLastState;
110 
111 
112  private:
114  Command_TLSChange(const Command_TLSChange&);
115 
117  Command_TLSChange& operator=(const Command_TLSChange&);
118 
119  };
120 
121 
122  struct OSGMovable {
123  osg::ref_ptr<osg::PositionAttitudeTransform> pos;
124  osg::ref_ptr<osg::ShapeDrawable> geom;
125  osg::ref_ptr<osg::Switch> lights;
126  };
127 
128 
130  GUIOSGView(FXComposite* p, GUIMainWindow& app,
131  GUISUMOViewParent* parent, GUINet& net, FXGLVisual* glVis,
132  FXGLCanvas* share);
133 
134  virtual ~GUIOSGView();
135 
137  virtual void buildViewToolBars(GUIGlChildWindow&);
138 
140  void recenterView();
141 
148  void centerTo(GUIGlID id, bool applyZoom, double zoomDist = 20);
149 
150  void showViewportEditor();
151 
153  void setViewportFromTo(const Position& lookFrom, const Position& lookAt);
154 
156  void copyViewportTo(GUISUMOAbstractView* view);
157 
161  void startTrack(int id);
162 
163 
166  void stopTrack();
167 
168 
172  GUIGlID getTrackedID() const;
173 
174  bool setColorScheme(const std::string& name);
175 
177  void onGamingClick(Position pos);
178 
180  SUMOTime getCurrentTimeStep() const;
181 
182  void remove(GUIVehicle* veh);
183 
184  // callback
185  long onConfigure(FXObject*, FXSelector, void*);
186  long onKeyPress(FXObject*, FXSelector, void*);
187  long onKeyRelease(FXObject*, FXSelector, void*);
188  long onLeftBtnPress(FXObject*, FXSelector, void*);
189  long onLeftBtnRelease(FXObject*, FXSelector, void*);
190  long onMiddleBtnPress(FXObject*, FXSelector, void*);
191  long onMiddleBtnRelease(FXObject*, FXSelector, void*);
192  long onRightBtnPress(FXObject*, FXSelector, void*);
193  long onRightBtnRelease(FXObject*, FXSelector, void*);
194  //long onMotion(FXObject*, FXSelector, void*);
195  long onMouseMove(FXObject*, FXSelector, void*);
196  long onPaint(FXObject*, FXSelector, void*);
197  long OnIdle(FXObject* sender, FXSelector sel, void* ptr);
198 
199 private:
200  class SUMOTerrainManipulator : public osgGA::TerrainManipulator {
201  public:
202  SUMOTerrainManipulator() {
203  setAllowThrow(false);
204  }
205  bool performMovementLeftMouseButton(const double eventTimeDelta, const double dx, const double dy) {
206  return osgGA::TerrainManipulator::performMovementMiddleMouseButton(eventTimeDelta, dx, dy);
207  }
208  bool performMovementMiddleMouseButton(const double eventTimeDelta, const double dx, const double dy) {
209  return osgGA::TerrainManipulator::performMovementLeftMouseButton(eventTimeDelta, dx, dy);
210  }
211  bool performMovementRightMouseButton(const double eventTimeDelta, const double dx, const double dy) {
212  return osgGA::TerrainManipulator::performMovementRightMouseButton(eventTimeDelta, dx, -dy);
213  }
214  };
215 
216  class FXOSGAdapter : public osgViewer::GraphicsWindow {
217  public:
218  FXOSGAdapter(GUISUMOAbstractView* parent, FXCursor* cursor);
219  void grabFocus();
220  void grabFocusIfPointerInWindow() {}
221  void useCursor(bool cursorOn);
222 
223  bool makeCurrentImplementation();
224  bool releaseContext();
225  void swapBuffersImplementation();
226 
227  // not implemented yet...just use dummy implementation to get working.
228  bool valid() const {
229  return true;
230  }
231  bool realizeImplementation() {
232  return true;
233  }
234  bool isRealizedImplementation() const {
235  return true;
236  }
237  void closeImplementation() {}
238  bool releaseContextImplementation() {
239  return true;
240  }
241 
242  protected:
243  ~FXOSGAdapter();
244  private:
245  GUISUMOAbstractView* const myParent;
246  FXCursor* const myOldCursor;
247  };
248 
249 protected:
250 
251  osg::ref_ptr<FXOSGAdapter> myAdapter;
252  osg::ref_ptr<osgViewer::Viewer> myViewer;
253  osg::ref_ptr<osg::Group> myRoot;
254 
255 private:
256  GUIVehicle* myTracked;
257  osg::ref_ptr<osgGA::CameraManipulator> myCameraManipulator;
258 
259  SUMOTime myLastUpdate;
260 
261  std::map<MSVehicle*, OSGMovable > myVehicles;
262  std::map<MSTransportable*, OSGMovable > myPersons;
263 
264  osg::ref_ptr<osg::Node> myGreenLight;
265  osg::ref_ptr<osg::Node> myYellowLight;
266  osg::ref_ptr<osg::Node> myRedLight;
267  osg::ref_ptr<osg::Node> myRedYellowLight;
268 
269 protected:
270  GUIOSGView() { }
271 
272 };
273 
274 #endif
275 
276 #endif
277 
278 /****************************************************************************/
279 
280 
Base class for things to execute if a tls switches to a new phase.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
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:88
long long int SUMOTime
Definition: TraCIDefs.h:51
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:60