Eclipse 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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // An OSG-based 3D view on the simulation
19 /****************************************************************************/
20 #pragma once
21 #include <config.h>
22 
23 #ifdef HAVE_OSG
24 
25 #include "GUIOSGHeader.h"
26 
27 #include <string>
29 #include <utils/geom/Boundary.h>
30 #include <utils/geom/Position.h>
31 #include <utils/common/RGBColor.h>
33 #include <gui/GUISUMOViewParent.h>
35 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 
41 class GUINet;
42 class GUISUMOViewParent;
43 class GUIVehicle;
44 class GUILaneWrapper;
45 class MSRoute;
46 class MSTransportable;
47 class MSVehicle;
48 
49 namespace osgGA {
50 class CameraManipulator;
51 class NodeTrackerManipulator;
52 }
53 
54 // ===========================================================================
55 // class definitions
56 // ===========================================================================
61 class GUIOSGView : public GUISUMOAbstractView {
62  FXDECLARE(GUIOSGView)
63 public:
68  class Command_TLSChange : public MSTLLogicControl::OnSwitchAction {
69  public:
78  Command_TLSChange(const MSLink* const link, osg::Switch* switchNode);
79 
81  virtual ~Command_TLSChange();
82 
89  void execute();
90 
91  private:
93  const MSLink* const myLink;
94 
96  osg::ref_ptr<osg::Switch> mySwitch;
97 
99  LinkState myLastState;
100 
101  private:
103  Command_TLSChange(const Command_TLSChange&) = delete;
104 
106  Command_TLSChange& operator=(const Command_TLSChange&) = delete;
107  };
108 
110  struct OSGMovable {
111  osg::ref_ptr<osg::PositionAttitudeTransform> pos;
112  osg::ref_ptr<osg::ShapeDrawable> geom;
113  osg::ref_ptr<osg::Switch> lights;
114  bool active;
115  };
116 
118  GUIOSGView(FXComposite* p, GUIMainWindow& app,
119  GUISUMOViewParent* parent, GUINet& net, FXGLVisual* glVis,
120  FXGLCanvas* share);
121 
123  virtual ~GUIOSGView();
124 
126  void recalculateBoundaries();
127 
129  virtual void buildViewToolBars(GUIGlChildWindow*);
130 
132  void recenterView();
133 
140  void centerTo(GUIGlID id, bool applyZoom, double zoomDist = 20);
141 
143  void showViewportEditor();
144 
146  void setViewportFromToRot(const Position& lookFrom, const Position& lookAt, double rotation);
147 
150 
154  void startTrack(int id);
155 
158  void stopTrack();
159 
163  GUIGlID getTrackedID() const;
164 
165  bool setColorScheme(const std::string& name);
166 
168  void onGamingClick(Position pos);
169 
172 
173  void removeVeh(MSVehicle* veh);
174  void removeTransportable(MSTransportable* t);
175 
176  // callback
177  long onConfigure(FXObject*, FXSelector, void*);
178  long onKeyPress(FXObject*, FXSelector, void*);
179  long onKeyRelease(FXObject*, FXSelector, void*);
180  long onLeftBtnPress(FXObject*, FXSelector, void*);
181  long onLeftBtnRelease(FXObject*, FXSelector, void*);
182  long onMiddleBtnPress(FXObject*, FXSelector, void*);
183  long onMiddleBtnRelease(FXObject*, FXSelector, void*);
184  long onRightBtnPress(FXObject*, FXSelector, void*);
185  long onRightBtnRelease(FXObject*, FXSelector, void*);
186  //long onMotion(FXObject*, FXSelector, void*);
187  long onMouseMove(FXObject*, FXSelector, void*);
188  long onPaint(FXObject*, FXSelector, void*);
189  long OnIdle(FXObject* sender, FXSelector sel, void* ptr);
190 
191 private:
192  class SUMOTerrainManipulator : public osgGA::TerrainManipulator {
193  public:
194  SUMOTerrainManipulator() {
195  setAllowThrow(false);
196  setRotationMode(ELEVATION_AZIM_ROLL); // default is ELEVATION_AZIM and this prevents rotating the view around the z-axis
197  }
198  bool performMovementLeftMouseButton(const double eventTimeDelta, const double dx, const double dy) {
199  return osgGA::TerrainManipulator::performMovementMiddleMouseButton(eventTimeDelta, dx, dy);
200  }
201  bool performMovementMiddleMouseButton(const double eventTimeDelta, const double dx, const double dy) {
202  return osgGA::TerrainManipulator::performMovementLeftMouseButton(eventTimeDelta, dx, dy);
203  }
204  bool performMovementRightMouseButton(const double eventTimeDelta, const double dx, const double dy) {
205  return osgGA::TerrainManipulator::performMovementRightMouseButton(eventTimeDelta, dx, -dy);
206  }
207  };
208 
209  class FXOSGAdapter : public osgViewer::GraphicsWindow {
210  public:
211  FXOSGAdapter(GUISUMOAbstractView* parent, FXCursor* cursor);
212  void grabFocus();
213  void grabFocusIfPointerInWindow() {}
214  void useCursor(bool cursorOn);
215 
216  bool makeCurrentImplementation();
217  bool releaseContext();
218  void swapBuffersImplementation();
219 
220  // not implemented yet...just use dummy implementation to get working.
221  bool valid() const {
222  return true;
223  }
224  bool realizeImplementation() {
225  return true;
226  }
227  bool isRealizedImplementation() const {
228  return true;
229  }
230  void closeImplementation() {}
231  bool releaseContextImplementation() {
232  return true;
233  }
234 
235  protected:
236  ~FXOSGAdapter();
237  private:
238  GUISUMOAbstractView* const myParent;
239  FXCursor* const myOldCursor;
240  };
241 
242 protected:
243  GUIOSGView() {}
244 
245  osg::ref_ptr<FXOSGAdapter> myAdapter;
246  osg::ref_ptr<osgViewer::Viewer> myViewer;
247  osg::ref_ptr<osg::Group> myRoot;
248 
249 private:
250  GUIVehicle* myTracked;
251  osg::ref_ptr<osgGA::CameraManipulator> myCameraManipulator;
252 
253  SUMOTime myLastUpdate;
254 
255  std::map<MSVehicle*, OSGMovable > myVehicles;
256  std::map<MSTransportable*, OSGMovable > myPersons;
257 
258  osg::ref_ptr<osg::Node> myGreenLight;
259  osg::ref_ptr<osg::Node> myYellowLight;
260  osg::ref_ptr<osg::Node> myRedLight;
261  osg::ref_ptr<osg::Node> myRedYellowLight;
262 };
263 
264 #endif
unsigned int GUIGlID
Definition: GUIGlObject.h:40
long long int SUMOTime
Definition: SUMOTime.h:32
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:81
virtual long onLeftBtnRelease(FXObject *, FXSelector, void *)
virtual void recenterView()
recenters the view
virtual SUMOTime getCurrentTimeStep() const
get the current simulation time
virtual long onMiddleBtnRelease(FXObject *, FXSelector, void *)
virtual long onMouseMove(FXObject *, FXSelector, void *)
virtual void buildViewToolBars(GUIGlChildWindow *)
builds the view toolbars
virtual void showViewportEditor()
show viewport editor
virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist=20)
centers to the chosen artifact
virtual long onLeftBtnPress(FXObject *, FXSelector, void *)
virtual void setViewportFromToRot(const Position &lookFrom, const Position &lookAt, double rotation)
applies the given viewport settings
virtual void onGamingClick(Position)
on gaming click
virtual long onKeyPress(FXObject *o, FXSelector sel, void *data)
keyboard functions
virtual long onMiddleBtnPress(FXObject *, FXSelector, void *)
virtual void stopTrack()
stop track
virtual long onKeyRelease(FXObject *o, FXSelector sel, void *data)
virtual void recalculateBoundaries()=0
recalculate boundaries
virtual void startTrack(int)
star track
virtual long onRightBtnRelease(FXObject *, FXSelector, void *)
virtual void copyViewportTo(GUISUMOAbstractView *view)
copy the viewport to the given view
virtual bool setColorScheme(const std::string &)
set color scheme
virtual long onPaint(FXObject *, FXSelector, void *)
virtual long onRightBtnPress(FXObject *, FXSelector, void *)
virtual long onConfigure(FXObject *, FXSelector, void *)
mouse functions
virtual GUIGlID getTrackedID() const
get tracked id
A single child window which contains a view of the simulation area.
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:51
Base class for things to execute if a tls switches to a new phase.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:75
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37