Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/gui/windows/GUIPerspectiveChanger.h
169684 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
14
/// @file GUIPerspectiveChanger.h
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Sept 2002
19
///
20
// A virtual class that allows to steer the visual output in dependence to
21
/****************************************************************************/
22
#pragma once
23
#include <config.h>
24
25
#include <utils/foxtools/fxheader.h>
26
#include <utils/geom/Boundary.h>
27
#include <utils/geom/Position.h>
28
#include "GUISUMOAbstractView.h"
29
30
31
// ===========================================================================
32
// class declarations
33
// ===========================================================================
34
class GUISUMOAbstractView;
35
36
37
// ===========================================================================
38
// class definitions
39
// ===========================================================================
40
/**
41
* @class GUIPerspectiveChanger
42
* This is the interface for implementation of own classes that handle the
43
* interaction between the user and a display field.
44
* While most of our (IVF) interfaces allow zooming by choosing the rectangle
45
* to show, other types of interaction are possible and have been implemented.
46
* To differ between the behaviours, all types of interaction between the
47
* user and the canvas are send to this class: mouse moving, mouse button
48
* pressing and releasing.
49
*/
50
class GUIPerspectiveChanger {
51
public:
52
/// @brief mouse states
53
enum MouseState {
54
MOUSEBTN_NONE = 0,
55
MOUSEBTN_LEFT = 1,
56
MOUSEBTN_RIGHT = 2,
57
MOUSEBTN_MIDDLE = 4
58
};
59
60
/// @brief Constructor
61
GUIPerspectiveChanger(GUISUMOAbstractView& callBack, const Boundary& viewPort);
62
63
/// @brief Destructor
64
virtual ~GUIPerspectiveChanger();
65
66
/// @brief mouse functions
67
//@{
68
/// @brief called when user press left button
69
virtual void onLeftBtnPress(void* data);
70
71
/// @brief called when user releases left button
72
virtual bool onLeftBtnRelease(void* data);
73
74
/// @brief called when user press middle button
75
virtual void onMiddleBtnPress(void* data);
76
77
/// @brief called when user releases middle button
78
virtual bool onMiddleBtnRelease(void* data);
79
80
/// @brief called when user press right button
81
virtual void onRightBtnPress(void* data);
82
83
/// @brief called when user releases right button
84
virtual bool onRightBtnRelease(void* data);
85
86
/// @brief called when user click two times
87
virtual void onDoubleClicked(void* data);
88
89
/// @brief called when user changes mouse wheel
90
virtual void onMouseWheel(void* data);
91
92
/// @brief called when user moves mouse
93
virtual void onMouseMove(void* data);
94
95
/// @brief called when user press a key
96
virtual long onKeyPress(void* data);
97
98
/// @brief called when user releases a key
99
virtual long onKeyRelease(void* data);
100
//@}
101
102
/// @brief Returns the rotation of the canvas stored in this changer
103
virtual double getRotation() const = 0;
104
105
/// @brief Returns the x-offset of the field to show stored in this changer
106
virtual double getXPos() const = 0;
107
108
/// @brief Returns the y-offset of the field to show stored in this changer
109
virtual double getYPos() const = 0;
110
111
/// @brief Returns the zoom factor computed stored in this changer
112
virtual double getZoom() const = 0;
113
114
/// @brief Returns the camera height corresponding to the current zoom factor
115
virtual double getZPos() const = 0;
116
117
/// @brief Returns the camera height at which the given zoom level is reached
118
virtual double zoom2ZPos(double zoom) const = 0;
119
120
/// @brief Returns the zoom level that is achieved at a given camera height
121
virtual double zPos2Zoom(double zPos) const = 0;
122
123
/// @brief Centers the view to the given position, setting it to a size that covers the radius. Used for: Centering of vehicles and junctions */
124
virtual void centerTo(const Position& pos, double radius, bool applyZoom = true) = 0;
125
126
/// @brief Sets the viewport Used for: Adapting a new viewport
127
virtual void setViewport(double zoom, double xPos, double yPos) = 0;
128
129
/// @brief Alternative method for setting the viewport
130
virtual void setViewportFrom(double xPos, double yPos, double zPos) = 0;
131
132
/// @brief Sets the rotation
133
virtual void setRotation(double rotation) = 0;
134
135
/// @brief Returns the last mouse x-position an event occurred at
136
FXint getMouseXPosition() const;
137
138
/// @brief Returns the last mouse y-position an event occurred at
139
FXint getMouseYPosition() const;
140
141
/* @brief Adapts the viewport so that a change in canvass size keeps most of the
142
* view intact (by showing more / less instead of zooming)
143
* The canvass is clipped/enlarged on the left side of the screen
144
*
145
* @param[in] change The horizontal change in canvas size in pixels
146
*/
147
virtual void changeCanvasSizeLeft(int change) = 0;
148
149
/// @brief get viewport
150
Boundary getViewport(bool fixRatio = true);
151
152
/// @brief set viewport
153
virtual void setViewport(const Boundary& viewPort);
154
155
protected:
156
/// @brief The parent window (canvas to scale)
157
GUISUMOAbstractView& myCallback;
158
159
/// @brief the current mouse position
160
FXint myMouseXPosition = 0;
161
FXint myMouseYPosition = 0;
162
163
/// @brief the intended viewport
164
Boundary myViewPort;
165
166
167
private:
168
/// @brief patched viewPort with the same aspect ratio as the canvas
169
Boundary patchedViewPort();
170
171
172
private:
173
/// @brief Invalidated copy constructor.
174
GUIPerspectiveChanger(const GUIPerspectiveChanger&);
175
176
/// @brief Invalidated assignment operator.
177
GUIPerspectiveChanger& operator=(const GUIPerspectiveChanger&);
178
};
179
180