Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/gui/windows/GUIDanielPerspectiveChanger.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 GUIDanielPerspectiveChanger.h
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Sept 2002
19
///
20
// A class that allows to steer the visual output in dependence to
21
/****************************************************************************/
22
#pragma once
23
#include <config.h>
24
25
#include <utils/geom/Position.h>
26
#include "GUIPerspectiveChanger.h"
27
28
29
// ===========================================================================
30
// class declarations
31
// ===========================================================================
32
class Boundary;
33
34
35
// ===========================================================================
36
// class definitions
37
// ===========================================================================
38
/**
39
* @class GUIDanielPerspectiveChanger
40
* This changer has the following behaviour:
41
* - zooming by pressing the right mouse button and moving the
42
* mouse vertically
43
* - rotation by pressing the right mouse button and moving the
44
* mouse horizontally
45
* - network movement by pressing the left mouse button and
46
* moving the mouse
47
*/
48
class GUIDanielPerspectiveChanger : public GUIPerspectiveChanger {
49
public:
50
/* Constructor
51
* @param[in] callBack The view to be updated upon changes
52
*/
53
GUIDanielPerspectiveChanger(GUISUMOAbstractView& callBack, const Boundary& viewPort);
54
55
/// Destructor
56
~GUIDanielPerspectiveChanger();
57
58
void onLeftBtnPress(void* data);
59
bool onLeftBtnRelease(void* data);
60
void onMiddleBtnPress(void* data);
61
bool onMiddleBtnRelease(void* data);
62
void onRightBtnPress(void* data);
63
bool onRightBtnRelease(void* data);
64
void onMouseWheel(void* data);
65
void onMouseMove(void* data);
66
long onKeyPress(void* data);
67
68
/// Returns the rotation of the canvas stored in this changer
69
virtual double getRotation() const;
70
71
/// Returns the x-offset of the field to show stored in this changer
72
virtual double getXPos() const;
73
74
/// Returns the y-offset of the field to show stored in this changer
75
virtual double getYPos() const;
76
77
/// Returns the zoom factor computed stored in this changer
78
virtual double getZoom() const;
79
80
/// @brief Returns the camera height corresponding to the current zoom factor
81
virtual double getZPos() const;
82
83
/// @brief Returns the camera height at which the given zoom level is reached
84
virtual double zoom2ZPos(double zoom) const;
85
86
/// @brief Returns the zoom level that is achieved at a given camera height
87
virtual double zPos2Zoom(double zPos) const;
88
89
/// Centers the view to the given position, setting it to a size that covers the radius
90
void centerTo(const Position& pos, double radius, bool applyZoom = true);
91
92
/** @brief Sets the viewport */
93
void setViewport(double zoom, double xPos, double yPos);
94
using GUIPerspectiveChanger::setViewport; // to silence the warning C4266 about a hidden function
95
96
/// @brief Alternative method for setting the viewport
97
void setViewportFrom(double xPos, double yPos, double zPos);
98
99
/// @brief Sets the rotation
100
void setRotation(double rotation);
101
102
/* @brief Adapts the viewport so that a change in canvass size keeps most of the
103
* view intact (by showing more / less instead of zooming)
104
* The canvass is clipped/enlarged on the left side of the screen
105
*
106
* @param[in] change The horizontal change in canvas size in pixels
107
*/
108
void changeCanvasSizeLeft(int change);
109
110
/* @brief avoid unwanted flicker
111
* @param[in] delay The minimum time delay in nanoseconds after
112
* mouseDown after which mouse-movements should be interpreted as zoom/drag
113
*/
114
void setDragDelay(FXTime delay) {
115
myDragDelay = delay;
116
}
117
118
private:
119
/* Performs the view movement
120
* @param[in] xdiff the change to myViewCenter in pixel
121
* @param[in] ydiff the change to myViewCenter in pixel
122
*/
123
void move(int xdiff, int ydiff);
124
125
/// Performs the zooming of the view
126
void zoom(double factor);
127
128
/// Performs the rotation of the view
129
void rotate(int diff);
130
131
private:
132
/// the original viewport dimensions in m which serve as the reference point for 100% zoom
133
double myOrigWidth, myOrigHeight;
134
135
/// the current rotation
136
double myRotation;
137
138
/// the current mouse state
139
int myMouseButtonState;
140
141
/// Information whether the user has moved the cursor while pressing a mouse button
142
bool myMoveOnClick;
143
144
/// the network location on which to zoom using right click+drag
145
Position myZoomBase;
146
147
/// avoid flicker
148
FXTime myDragDelay;
149
FXlong myMouseDownTime;
150
151
152
private:
153
/// @brief Invalidated copy constructor.
154
GUIDanielPerspectiveChanger(const GUIDanielPerspectiveChanger&);
155
156
/// @brief Invalidated assignment operator.
157
GUIDanielPerspectiveChanger& operator=(const GUIDanielPerspectiveChanger&);
158
159
};
160
161