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/****************************************************************************/
19// An OSG-based 3D view on the simulation
20/****************************************************************************/
21#pragma once
22#include <config.h>
23
24#ifdef HAVE_OSG
25
26#include "GUIOSGHeader.h"
27
28#include <string>
30#include <utils/geom/Boundary.h>
31#include <utils/geom/Position.h>
36
37
38// ===========================================================================
39// class declarations
40// ===========================================================================
41
42class GUINet;
44class GUIVehicle;
45class GUILaneWrapper;
46class MSRoute;
47class MSTransportable;
48class MSVehicle;
49
50namespace osgGA {
51class CameraManipulator;
52class NodeTrackerManipulator;
53}
54
55// ===========================================================================
56// class definitions
57// ===========================================================================
62class GUIOSGView : public GUISUMOAbstractView {
63 FXDECLARE(GUIOSGView)
64
65public:
66 friend class GUIOSGPerspectiveChanger;
67
69 enum NodeSetGroup {
71 NODESET_TLSDOMES,
73 NODESET_TLSLINKMARKERS,
75 NODESET_TLSMODELS,
76 };
77
82 class Command_TLSChange : public MSTLLogicControl::OnSwitchAction {
83 public:
92 Command_TLSChange(const MSLink* const link, osg::Switch* switchNode);
93
95 virtual ~Command_TLSChange();
96
103 void execute();
104
105 private:
107 const MSLink* const myLink;
108
110 osg::ref_ptr<osg::Switch> mySwitch;
111
113 LinkState myLastState;
114
115 private:
117 Command_TLSChange(const Command_TLSChange&) = delete;
118
120 Command_TLSChange& operator=(const Command_TLSChange&) = delete;
121 };
122
124 struct OSGMovable {
125 osg::ref_ptr<osg::PositionAttitudeTransform> pos;
126 osg::ref_ptr<osg::ShapeDrawable> geom;
127 osg::ref_ptr<osg::Material> mat;
128 osg::ref_ptr<osg::Switch> lights;
129 bool active;
130 };
131
133 GUIOSGView(FXComposite* p, GUIMainWindow& app,
134 GUISUMOViewParent* parent, GUINet& net, FXGLVisual* glVis,
135 FXGLCanvas* share);
136
138 virtual ~GUIOSGView();
139
142
145
147 bool is3DView() const;
148
150 virtual void buildViewToolBars(GUIGlChildWindow*);
151
153 void recenterView();
154
161 //void centerTo(GUIGlID id, bool applyZoom, double zoomDist = 20);
162
165
167 void showViewportEditor();
168
170 void setViewportFromToRot(const Position& lookFrom, const Position& lookAt, double rotation);
171
174
178 void startTrack(int id);
179
182 void stopTrack();
183
187 GUIGlID getTrackedID() const;
188
189 bool setColorScheme(const std::string& name);
190
192 void onGamingClick(Position pos);
193
196
197 void removeVeh(MSVehicle* veh);
198 void removeTransportable(MSTransportable* t);
199
200 // callback
201 long onConfigure(FXObject*, FXSelector, void*);
202 long onKeyPress(FXObject*, FXSelector, void*);
203 long onKeyRelease(FXObject*, FXSelector, void*);
204 long onLeftBtnPress(FXObject*, FXSelector, void*);
205 long onLeftBtnRelease(FXObject*, FXSelector, void*);
206 long onMiddleBtnPress(FXObject*, FXSelector, void*);
207 long onMiddleBtnRelease(FXObject*, FXSelector, void*);
208 long onRightBtnPress(FXObject*, FXSelector, void*);
209 long onRightBtnRelease(FXObject*, FXSelector, void*);
210 //long onMotion(FXObject*, FXSelector, void*);
211 long onMouseMove(FXObject*, FXSelector, void*);
212 long onPaint(FXObject*, FXSelector, void*);
213 long OnIdle(FXObject* sender, FXSelector sel, void* ptr);
214
216 long onCmdCloseLane(FXObject*, FXSelector, void*);
217 long onCmdCloseEdge(FXObject*, FXSelector, void*);
218 long onCmdAddRerouter(FXObject*, FXSelector, void*);
219
221 long onCmdShowReachability(FXObject*, FXSelector, void*);
222
224 long onVisualizationChange(FXObject*, FXSelector, void*);
225
226 // @brief get the new camera position given a zoom value
227 void zoom2Pos(Position& camera, Position& lookAt, double zoom);
228
229 // @brief convert RGBColor 0..255 RGBA values to osg::Vec4 0..1 vector
230 static osg::Vec4d toOSGColorVector(RGBColor c, bool useAlpha = false);
231
232protected:
234 void setWindowCursorPosition(float x, float y);
235
236 void updatePositionInformation() const;
237
239 bool getPositionAtCursor(float xNorm, float yNorm, Position& pos) const;
240
242 std::vector<GUIGlObject*> getGUIGlObjectsUnderCursor();
243
244 /* @brief Find GUILane which intersects with a ray from the camera to the stored cursor position
245 * @return The first found GUILane found or nullptr
246 */
248
250 void initChanger(const Boundary& viewPort);
251
253 void adoptViewSettings();
254
255private:
256 double calculateRotation(const osg::Vec3d& lookFrom, const osg::Vec3d& lookAt, const osg::Vec3d& up);
257
258 class SUMOTerrainManipulator : public osgGA::TerrainManipulator {
259 public:
260 SUMOTerrainManipulator() {
261 setAllowThrow(false);
262 setVerticalAxisFixed(false);
263 }
264 bool performMovementLeftMouseButton(const double eventTimeDelta, const double dx, const double dy) {
265 return osgGA::TerrainManipulator::performMovementMiddleMouseButton(eventTimeDelta, dx, dy);
266 }
267 bool performMovementMiddleMouseButton(const double eventTimeDelta, const double dx, const double dy) {
268 return osgGA::TerrainManipulator::performMovementLeftMouseButton(eventTimeDelta, dx, dy);
269 }
270 bool performMovementRightMouseButton(const double eventTimeDelta, const double dx, const double dy) {
271 return osgGA::TerrainManipulator::performMovementRightMouseButton(eventTimeDelta, dx, -dy);
272 }
273 };
274
275 class FXOSGAdapter : public osgViewer::GraphicsWindow {
276 public:
277 FXOSGAdapter(GUISUMOAbstractView* parent, FXCursor* cursor);
278 void grabFocus();
279 void grabFocusIfPointerInWindow() {}
280 void useCursor(bool cursorOn);
281
282 bool makeCurrentImplementation();
283 bool releaseContext();
284 void swapBuffersImplementation();
285
286 // not implemented yet...just use dummy implementation to get working.
287 bool valid() const {
288 return true;
289 }
290 bool realizeImplementation() {
291 return true;
292 }
293 bool isRealizedImplementation() const {
294 return true;
295 }
296 void closeImplementation() {}
297 bool releaseContextImplementation() {
298 return true;
299 }
300
301 protected:
302 ~FXOSGAdapter();
303 private:
304 GUISUMOAbstractView* const myParent;
305 FXCursor* const myOldCursor;
306 };
307
308 class PickHandler : public osgGA::GUIEventHandler {
309 public:
310 PickHandler(GUIOSGView* parent) : myParent(parent), myDrag(false) {};
311 bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
312 protected:
313 ~PickHandler() {};
314 private:
315 GUIOSGView* const myParent;
316 bool myDrag;
317 };
318
319protected:
320 GUIOSGView() {}
321
322 osg::ref_ptr<FXOSGAdapter> myAdapter;
323 osg::ref_ptr<osgViewer::Viewer> myViewer;
324 osg::ref_ptr<osg::Group> myRoot;
325
326private:
327 GUIVehicle* myTracked;
328 osg::ref_ptr<SUMOTerrainManipulator> myCameraManipulator;
329
330 SUMOTime myLastUpdate;
331
332 float myOSGNormalizedCursorX, myOSGNormalizedCursorY;
333
334 std::map<MSVehicle*, OSGMovable > myVehicles;
335 std::map<MSTransportable*, OSGMovable > myPersons;
336
337 osg::ref_ptr<osg::Node> myGreenLight;
338 osg::ref_ptr<osg::Node> myYellowLight;
339 osg::ref_ptr<osg::Node> myRedLight;
340 osg::ref_ptr<osg::Node> myRedYellowLight;
341 osg::ref_ptr<osg::Node> myPoleBase;
342};
343
344#endif
long long int SUMOTime
Definition: GUI.h:36
unsigned int GUIGlID
Definition: GUIGlObject.h:43
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:60
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:82
virtual long onLeftBtnRelease(FXObject *, FXSelector, void *)
virtual long onVisualizationChange(FXObject *, FXSelector, void *)
hook to react on change in visualization settings
std::vector< GUIGlObject * > getGUIGlObjectsUnderCursor()
returns the GUIGlObject under the cursor using GL_SELECT (including overlapped objects)
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 long onCmdCloseEdge(FXObject *, FXSelector, void *)
virtual void buildViewToolBars(GUIGlChildWindow *)
builds the view toolbars
virtual void showViewportEditor()
show viewport editor
virtual void zoom2Pos(Position &camera, Position &lookAt, double zoom)
zoom interface for 3D view
virtual long onCmdCloseLane(FXObject *, FXSelector, void *)
interaction with the simulation
virtual long onLeftBtnPress(FXObject *, FXSelector, void *)
virtual void setViewportFromToRot(const Position &lookFrom, const Position &lookAt, double rotation)
applies the given viewport settings
virtual GUILane * getLaneUnderCursor()
returns the GUILane at cursor position (implementation depends on view)
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 Position getPositionInformation() const
Returns the cursor's x/y position within the network.
virtual long onKeyRelease(FXObject *o, FXSelector sel, void *data)
void setWindowCursorPosition(FXint x, FXint y)
Returns the gl-id of the object under the given coordinates.
virtual long onCmdShowReachability(FXObject *, FXSelector, void *)
highlight edges according to reachability
virtual void recalculateBoundaries()=0
recalculate boundaries
virtual void updateViewportValues()
update the viewport chooser with the current view values
virtual void startTrack(int)
star track
virtual bool is3DView() const
return whether this is a 3D view
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 onCmdAddRerouter(FXObject *, FXSelector, void *)
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:77
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37