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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // An OSG-based 3D view on the simulation
16 /****************************************************************************/
17 #ifndef GUIOSGView_h
18 #define GUIOSGView_h
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #ifdef HAVE_OSG
26 
27 #include <string>
28 #include <osgGA/TerrainManipulator>
29 #include <osgViewer/Viewer>
30 #include <osg/PositionAttitudeTransform>
31 #include <osg/ShapeDrawable>
33 #include <utils/geom/Boundary.h>
34 #include <utils/geom/Position.h>
35 #include <utils/common/RGBColor.h>
37 #include <gui/GUISUMOViewParent.h>
39 
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 class GUINet;
45 class GUISUMOViewParent;
46 class GUIVehicle;
47 class GUILaneWrapper;
48 class MSRoute;
49 namespace osgGA {
50 class CameraManipulator;
51 class NodeTrackerManipulator;
52 }
53 
54 
55 // ===========================================================================
56 // class definitions
57 // ===========================================================================
62 class GUIOSGView : public GUISUMOAbstractView {
63  FXDECLARE(GUIOSGView)
64 public:
69  class Command_TLSChange : public MSTLLogicControl::OnSwitchAction {
70  public:
79  Command_TLSChange(const MSLink* const link, osg::Switch* switchNode);
80 
81 
83  virtual ~Command_TLSChange();
84 
85 
92  void execute();
93 
94 
95  private:
97  const MSLink* const myLink;
98 
100  osg::ref_ptr<osg::Switch> mySwitch;
101 
103  LinkState myLastState;
104 
105 
106  private:
108  Command_TLSChange(const Command_TLSChange&);
109 
111  Command_TLSChange& operator=(const Command_TLSChange&);
112 
113  };
114 
115 
116  struct OSGMovable {
117  osg::ref_ptr<osg::PositionAttitudeTransform> pos;
118  osg::ref_ptr<osg::ShapeDrawable> geom;
119  osg::ref_ptr<osg::Switch> lights;
120  bool active;
121  };
122 
123 
125  GUIOSGView(FXComposite* p, GUIMainWindow& app,
126  GUISUMOViewParent* parent, GUINet& net, FXGLVisual* glVis,
127  FXGLCanvas* share);
128 
129  virtual ~GUIOSGView();
130 
132  virtual void buildViewToolBars(GUIGlChildWindow&);
133 
135  void recenterView();
136 
143  void centerTo(GUIGlID id, bool applyZoom, double zoomDist = 20);
144 
145  void showViewportEditor();
146 
148  void setViewportFromToRot(const Position& lookFrom, const Position& lookAt, double rotation);
149 
151  void copyViewportTo(GUISUMOAbstractView* view);
152 
156  void startTrack(int id);
157 
158 
161  void stopTrack();
162 
163 
167  GUIGlID getTrackedID() const;
168 
169  bool setColorScheme(const std::string& name);
170 
172  void onGamingClick(Position pos);
173 
175  SUMOTime getCurrentTimeStep() const;
176 
177  void removeVeh(MSVehicle* veh);
178  void removeTransportable(MSTransportable* t);
179 
180  // callback
181  long onConfigure(FXObject*, FXSelector, void*);
182  long onKeyPress(FXObject*, FXSelector, void*);
183  long onKeyRelease(FXObject*, FXSelector, void*);
184  long onLeftBtnPress(FXObject*, FXSelector, void*);
185  long onLeftBtnRelease(FXObject*, FXSelector, void*);
186  long onMiddleBtnPress(FXObject*, FXSelector, void*);
187  long onMiddleBtnRelease(FXObject*, FXSelector, void*);
188  long onRightBtnPress(FXObject*, FXSelector, void*);
189  long onRightBtnRelease(FXObject*, FXSelector, void*);
190  //long onMotion(FXObject*, FXSelector, void*);
191  long onMouseMove(FXObject*, FXSelector, void*);
192  long onPaint(FXObject*, FXSelector, void*);
193  long OnIdle(FXObject* sender, FXSelector sel, void* ptr);
194 
195 private:
196  class SUMOTerrainManipulator : public osgGA::TerrainManipulator {
197  public:
198  SUMOTerrainManipulator() {
199  setAllowThrow(false);
200  setRotationMode(ELEVATION_AZIM_ROLL); // default is ELEVATION_AZIM and this prevents rotating the view around the z-axis
201  }
202  bool performMovementLeftMouseButton(const double eventTimeDelta, const double dx, const double dy) {
203  return osgGA::TerrainManipulator::performMovementMiddleMouseButton(eventTimeDelta, dx, dy);
204  }
205  bool performMovementMiddleMouseButton(const double eventTimeDelta, const double dx, const double dy) {
206  return osgGA::TerrainManipulator::performMovementLeftMouseButton(eventTimeDelta, dx, dy);
207  }
208  bool performMovementRightMouseButton(const double eventTimeDelta, const double dx, const double dy) {
209  return osgGA::TerrainManipulator::performMovementRightMouseButton(eventTimeDelta, dx, -dy);
210  }
211  };
212 
213  class FXOSGAdapter : public osgViewer::GraphicsWindow {
214  public:
215  FXOSGAdapter(GUISUMOAbstractView* parent, FXCursor* cursor);
216  void grabFocus();
217  void grabFocusIfPointerInWindow() {}
218  void useCursor(bool cursorOn);
219 
220  bool makeCurrentImplementation();
221  bool releaseContext();
222  void swapBuffersImplementation();
223 
224  // not implemented yet...just use dummy implementation to get working.
225  bool valid() const {
226  return true;
227  }
228  bool realizeImplementation() {
229  return true;
230  }
231  bool isRealizedImplementation() const {
232  return true;
233  }
234  void closeImplementation() {}
235  bool releaseContextImplementation() {
236  return true;
237  }
238 
239  protected:
240  ~FXOSGAdapter();
241  private:
242  GUISUMOAbstractView* const myParent;
243  FXCursor* const myOldCursor;
244  };
245 
246 protected:
247 
248  osg::ref_ptr<FXOSGAdapter> myAdapter;
249  osg::ref_ptr<osgViewer::Viewer> myViewer;
250  osg::ref_ptr<osg::Group> myRoot;
251 
252 private:
253  GUIVehicle* myTracked;
254  osg::ref_ptr<osgGA::CameraManipulator> myCameraManipulator;
255 
256  SUMOTime myLastUpdate;
257 
258  std::map<MSVehicle*, OSGMovable > myVehicles;
259  std::map<MSTransportable*, OSGMovable > myPersons;
260 
261  osg::ref_ptr<osg::Node> myGreenLight;
262  osg::ref_ptr<osg::Node> myYellowLight;
263  osg::ref_ptr<osg::Node> myRedLight;
264  osg::ref_ptr<osg::Node> myRedYellowLight;
265 
266 protected:
267  GUIOSGView() { }
268 
269 };
270 
271 #endif
272 
273 #endif
274 
275 /****************************************************************************/
276 
277 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:35
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:39
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:43
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:83
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:54