SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIDanielPerspectiveChanger.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A class that allows to steer the visual output in dependence to
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <utils/geom/Boundary.h>
34 #include <utils/geom/Position.h>
36 #include "GUIPerspectiveChanger.h"
38 
39 #ifdef CHECK_MEMORY_LEAKS
40 #include <foreign/nvwa/debug_new.h>
41 #endif // CHECK_MEMORY_LEAKS
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
48  GUISUMOAbstractView& callBack, const Boundary& viewPort) :
49  GUIPerspectiveChanger(callBack, viewPort),
50  myOrigWidth(viewPort.getWidth()),
51  myOrigHeight(viewPort.getHeight()),
52  myRotation(0),
53  myMouseButtonState(MOUSEBTN_NONE),
54  myMoveOnClick(false),
55  myDragDelay(0) {}
56 
57 
59 
60 
61 void
62 GUIDanielPerspectiveChanger::move(int xdiff, int ydiff) {
63  myViewPort.moveby(myCallback.p2m(xdiff), -myCallback.p2m(ydiff));
64  myCallback.update();
65 }
66 
67 
68 void
70  if (myCallback.getApp()->reg().readIntEntry("gui", "zoomAtCenter", 1)) {
72  }
73  if (factor > 0) {
75  myZoomBase.x() - (myZoomBase.x() - myViewPort.xmin()) / factor,
76  myZoomBase.y() - (myZoomBase.y() - myViewPort.ymin()) / factor,
77  myZoomBase.x() - (myZoomBase.x() - myViewPort.xmax()) / factor,
78  myZoomBase.y() - (myZoomBase.y() - myViewPort.ymax()) / factor);
79  myCallback.update();
80  }
81 }
82 
83 
84 void
86  /*
87  if (myCallback.allowRotation()) {
88  myRotation += (SUMOReal) diff / (SUMOReal) 10.0;
89  myCallback.update();
90  }
91  */
92 }
93 
94 
97  return myRotation;
98 }
99 
100 
101 SUMOReal
103  return myViewPort.getCenter().x();
104 }
105 
106 
107 SUMOReal
109  return myViewPort.getCenter().y();
110 }
111 
112 
113 SUMOReal
115  return myOrigWidth / myViewPort.getWidth() * 100;
116 }
117 
118 
119 void
121  bool applyZoom) {
122  if (applyZoom) {
123  myViewPort = Boundary();
124  myViewPort.add(pos);
125  myViewPort.grow(radius);
126  } else {
127  myViewPort.moveby(pos.x() - getXPos(), pos.y() - getYPos());
128  }
129 }
130 
131 
132 void
135  FXEvent* e = (FXEvent*) data;
136  myMouseXPosition = e->win_x;
137  myMouseYPosition = e->win_y;
138  myMoveOnClick = false;
139  myMouseDownTime = FXThread::time();
140 }
141 
142 
143 bool
146  FXEvent* e = (FXEvent*) data;
147  myMouseXPosition = e->win_x;
148  myMouseYPosition = e->win_y;
149  return myMoveOnClick;
150 }
151 
152 
153 void
156  FXEvent* e = (FXEvent*) data;
157  myMouseXPosition = e->win_x;
158  myMouseYPosition = e->win_y;
159  myMoveOnClick = false;
160  myMouseDownTime = FXThread::time();
162 }
163 
164 
165 bool
168  if (data != 0) {
169  FXEvent* e = (FXEvent*) data;
170  myMouseXPosition = e->win_x;
171  myMouseYPosition = e->win_y;
172  }
173  return myMoveOnClick;
174 }
175 
176 
177 void
179  FXEvent* e = (FXEvent*) data;
180  SUMOReal diff = 0.1;
181  if (e->state & CONTROLMASK) {
182  diff /= 2;
183  } else if (e->state & SHIFTMASK) {
184  diff *= 2;
185  }
186  if (e->code < 0) {
187  diff = -diff;
188  }
190  zoom(1.0 + diff);
192 }
193 
194 
195 void
197  FXEvent* e = (FXEvent*) data;
198  myCallback.setWindowCursorPosition(e->win_x, e->win_y);
199  const int xdiff = myMouseXPosition - e->win_x;
200  const int ydiff = myMouseYPosition - e->win_y;
201  const bool moved = xdiff != 0 || ydiff != 0;
202  const bool pastDelay = !gSchemeStorage.getDefault().gaming && FXThread::time() > (myMouseDownTime + myDragDelay);
203  switch (myMouseButtonState) {
204  case MOUSEBTN_LEFT:
205  if (pastDelay) {
206  move(xdiff, ydiff);
207  if (moved) {
208  myMoveOnClick = true;
209  }
210  }
211  break;
212  case MOUSEBTN_RIGHT:
213  if (pastDelay) {
214  zoom(1 + 10.0 * ydiff / myCallback.getWidth());
215  rotate(xdiff);
216  if (moved) {
217  myMoveOnClick = true;
218  }
219  }
220  break;
221  default:
222  if (moved) {
224  }
225  break;
226  }
227  myMouseXPosition = e->win_x;
228  myMouseYPosition = e->win_y;
229 }
230 
231 
232 void
234  SUMOReal xPos, SUMOReal yPos) {
235  const SUMOReal zoomFactor = zoom / 50; // /100 to normalize, *2 because growth is added on both sides
236  myViewPort = Boundary();
237  myViewPort.add(Position(xPos, yPos));
238  myViewPort.growHeight(myOrigHeight / zoomFactor);
239  myViewPort.growWidth(myOrigWidth / zoomFactor);
240  myCallback.update();
241 }
242 
243 
244 void
247  myViewPort.xmin() - myCallback.p2m(change),
248  myViewPort.ymin(),
249  myViewPort.xmax(),
250  myViewPort.ymax());
251 }
252 
253 /****************************************************************************/
GUICompleteSchemeStorage gSchemeStorage
void growWidth(SUMOReal by)
Definition: Boundary.cpp:209
SUMOReal getWidth() const
Returns the width of the boudary.
Definition: Boundary.cpp:136
bool myMoveOnClick
Information whether the user has moved the cursor while pressing a mouse button.
Position getCenter() const
Returns the center of the boundary.
Definition: Boundary.cpp:106
bool gaming
whether the application is in gaming mode or not
SUMOReal ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:124
Position myZoomBase
the network location on which to zoom using right click+drag
SUMOReal xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:112
SUMOReal p2m(SUMOReal pixel) const
pixels-to-meters conversion method
virtual SUMOReal getRotation() const
Returns the rotation of the canvas stored in this changer.
void rotate(int diff)
Performs the rotation of the view.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
SUMOReal myOrigWidth
the original viewport dimensions in m which serve as the reference point for 100% zoom ...
virtual SUMOReal getXPos() const
Returns the x-offset of the field to show stored in this changer.
SUMOReal xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:118
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
GUIDanielPerspectiveChanger(GUISUMOAbstractView &callBack, const Boundary &viewPort)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
void centerTo(const Position &pos, SUMOReal radius, bool applyZoom=true)
Centers the view to the given position, setting it to a size that covers the radius.
int myMouseButtonState
the current mouse state
GUISUMOAbstractView & myCallback
The parent window (canvas to scale)
void zoom(SUMOReal factor)
Performs the zooming of the view.
SUMOReal myRotation
the current rotation
void setViewport(SUMOReal zoom, SUMOReal xPos, SUMOReal yPos)
Sets the viewport.
void add(SUMOReal x, SUMOReal y)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:76
GUIVisualizationSettings & getDefault()
Returns the default scheme.
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
Definition: Boundary.cpp:200
Boundary myViewPort
the intended viewport
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
void setWindowCursorPosition(FXint x, FXint y)
Returns the information whether rotation is allowd.
virtual SUMOReal getYPos() const
Returns the y-offset of the field to show stored in this changer.
#define SUMOReal
Definition: config.h:215
void updateToolTip()
A method that updates the tooltip.
SUMOReal ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:130
void growHeight(SUMOReal by)
Definition: Boundary.cpp:216
FXint myMouseXPosition
the current mouse position
void moveby(SUMOReal x, SUMOReal y)
Moves the boundary by the given amount.
Definition: Boundary.cpp:249
Position getPositionInformation() const
Returns the cursor's x/y position within the network.
virtual SUMOReal getZoom() const
Returns the zoom factor computed stored in this changer.