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-2018 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  }
201  bool performMovementLeftMouseButton(const double eventTimeDelta, const double dx, const double dy) {
202  return osgGA::TerrainManipulator::performMovementMiddleMouseButton(eventTimeDelta, dx, dy);
203  }
204  bool performMovementMiddleMouseButton(const double eventTimeDelta, const double dx, const double dy) {
205  return osgGA::TerrainManipulator::performMovementLeftMouseButton(eventTimeDelta, dx, dy);
206  }
207  bool performMovementRightMouseButton(const double eventTimeDelta, const double dx, const double dy) {
208  return osgGA::TerrainManipulator::performMovementRightMouseButton(eventTimeDelta, dx, -dy);
209  }
210  };
211 
212  class FXOSGAdapter : public osgViewer::GraphicsWindow {
213  public:
214  FXOSGAdapter(GUISUMOAbstractView* parent, FXCursor* cursor);
215  void grabFocus();
216  void grabFocusIfPointerInWindow() {}
217  void useCursor(bool cursorOn);
218 
219  bool makeCurrentImplementation();
220  bool releaseContext();
221  void swapBuffersImplementation();
222 
223  // not implemented yet...just use dummy implementation to get working.
224  bool valid() const {
225  return true;
226  }
227  bool realizeImplementation() {
228  return true;
229  }
230  bool isRealizedImplementation() const {
231  return true;
232  }
233  void closeImplementation() {}
234  bool releaseContextImplementation() {
235  return true;
236  }
237 
238  protected:
239  ~FXOSGAdapter();
240  private:
241  GUISUMOAbstractView* const myParent;
242  FXCursor* const myOldCursor;
243  };
244 
245 protected:
246 
247  osg::ref_ptr<FXOSGAdapter> myAdapter;
248  osg::ref_ptr<osgViewer::Viewer> myViewer;
249  osg::ref_ptr<osg::Group> myRoot;
250 
251 private:
252  GUIVehicle* myTracked;
253  osg::ref_ptr<osgGA::CameraManipulator> myCameraManipulator;
254 
255  SUMOTime myLastUpdate;
256 
257  std::map<MSVehicle*, OSGMovable > myVehicles;
258  std::map<MSTransportable*, OSGMovable > myPersons;
259 
260  osg::ref_ptr<osg::Node> myGreenLight;
261  osg::ref_ptr<osg::Node> myYellowLight;
262  osg::ref_ptr<osg::Node> myRedLight;
263  osg::ref_ptr<osg::Node> myRedYellowLight;
264 
265 protected:
266  GUIOSGView() { }
267 
268 };
269 
270 #endif
271 
272 #endif
273 
274 /****************************************************************************/
275 
276 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
long long int SUMOTime
Definition: SUMOTime.h:36
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:82
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:54