SUMO - Simulation of Urban MObility
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.dlr.de/
12 // Copyright (C) 2001-2016 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 <fxkeys.h>
34 #include <utils/geom/Boundary.h>
35 #include <utils/geom/Position.h>
37 #include "GUIPerspectiveChanger.h"
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
49  GUISUMOAbstractView& callBack, const Boundary& viewPort) :
50  GUIPerspectiveChanger(callBack, viewPort),
51  myOrigWidth(viewPort.getWidth()),
52  myOrigHeight(viewPort.getHeight()),
53  myRotation(0),
54  myMouseButtonState(MOUSEBTN_NONE),
55  myMoveOnClick(false),
56  myZoomBase(viewPort.getCenter()),
57  myDragDelay(0) {
58 }
59 
60 
62 
63 
64 void
65 GUIDanielPerspectiveChanger::move(int xdiff, int ydiff) {
66  myViewPort.moveby(myCallback.p2m(xdiff), -myCallback.p2m(ydiff));
67  myCallback.update();
68 }
69 
70 
71 void
73  if (myCallback.getApp()->reg().readIntEntry("gui", "zoomAtCenter", 1)) {
75  }
76  if (factor > 0) {
78  myZoomBase.x() - (myZoomBase.x() - myViewPort.xmin()) / factor,
79  myZoomBase.y() - (myZoomBase.y() - myViewPort.ymin()) / factor,
80  myZoomBase.x() - (myZoomBase.x() - myViewPort.xmax()) / factor,
81  myZoomBase.y() - (myZoomBase.y() - myViewPort.ymax()) / factor);
82  myCallback.update();
83  }
84 }
85 
86 
87 void
89  /*
90  if (myCallback.allowRotation()) {
91  myRotation += (SUMOReal) diff / (SUMOReal) 10.0;
92  myCallback.update();
93  }
94  */
95 }
96 
97 
100  return myRotation;
101 }
102 
103 
104 SUMOReal
106  return myViewPort.getCenter().x();
107 }
108 
109 
110 SUMOReal
112  return myViewPort.getCenter().y();
113 }
114 
115 
116 SUMOReal
118  return myOrigWidth / myViewPort.getWidth() * 100;
119 }
120 
121 
122 void
124  bool applyZoom) {
125  if (applyZoom) {
126  myViewPort = Boundary();
127  myViewPort.add(pos);
128  myViewPort.grow(radius);
129  } else {
130  myViewPort.moveby(pos.x() - getXPos(), pos.y() - getYPos());
131  }
132 }
133 
134 
135 void
138  FXEvent* e = (FXEvent*) data;
139  myMouseXPosition = e->win_x;
140  myMouseYPosition = e->win_y;
141  myMoveOnClick = false;
142  myMouseDownTime = FXThread::time();
143 }
144 
145 
146 bool
149  FXEvent* e = (FXEvent*) data;
150  myMouseXPosition = e->win_x;
151  myMouseYPosition = e->win_y;
152  return myMoveOnClick;
153 }
154 
155 
156 void
159  FXEvent* e = (FXEvent*) data;
160  myMouseXPosition = e->win_x;
161  myMouseYPosition = e->win_y;
162  myMoveOnClick = false;
163  myMouseDownTime = FXThread::time();
165 }
166 
167 
168 bool
171  if (data != 0) {
172  FXEvent* e = (FXEvent*) data;
173  myMouseXPosition = e->win_x;
174  myMouseYPosition = e->win_y;
175  }
176  return myMoveOnClick;
177 }
178 
179 
180 void
182  FXEvent* e = (FXEvent*) data;
183  SUMOReal diff = 0.1;
184  if ((e->state & CONTROLMASK) != 0) {
185  diff /= 2;
186  } else if ((e->state & SHIFTMASK) != 0) {
187  diff *= 2;
188  }
189  if (e->code < 0) {
190  diff = -diff;
191  }
193  zoom(1.0 + diff);
195 }
196 
197 
198 void
200  FXEvent* e = (FXEvent*) data;
201  myCallback.setWindowCursorPosition(e->win_x, e->win_y);
202  const int xdiff = myMouseXPosition - e->win_x;
203  const int ydiff = myMouseYPosition - e->win_y;
204  const bool moved = xdiff != 0 || ydiff != 0;
205  const bool pastDelay = !gSchemeStorage.getDefault().gaming && FXThread::time() > (myMouseDownTime + myDragDelay);
206  switch (myMouseButtonState) {
207  case MOUSEBTN_LEFT:
208  if (pastDelay) {
209  move(xdiff, ydiff);
210  if (moved) {
211  myMoveOnClick = true;
212  }
213  }
214  break;
215  case MOUSEBTN_RIGHT:
216  if (pastDelay) {
217  zoom(1 + 10.0 * ydiff / myCallback.getWidth());
218  rotate(xdiff);
219  if (moved) {
220  myMoveOnClick = true;
221  }
222  }
223  break;
224  default:
225  if (moved) {
227  }
228  break;
229  }
230  myMouseXPosition = e->win_x;
231  myMouseYPosition = e->win_y;
232 }
233 
234 
235 void
237  SUMOReal xPos, SUMOReal yPos) {
238  const SUMOReal zoomFactor = zoom / 50; // /100 to normalize, *2 because growth is added on both sides
239  myViewPort = Boundary();
240  myViewPort.add(Position(xPos, yPos));
241  myViewPort.growHeight(myOrigHeight / zoomFactor);
242  myViewPort.growWidth(myOrigWidth / zoomFactor);
243  myCallback.update();
244 }
245 
246 
247 void
250  myViewPort.xmin() - myCallback.p2m(change),
251  myViewPort.ymin(),
252  myViewPort.xmax(),
253  myViewPort.ymax());
254 }
255 
256 
257 long
259  FXEvent* e = (FXEvent*) data;
260  SUMOReal zoomDiff = 0.1;
261  SUMOReal moveX = 0;
262  SUMOReal moveY = 0;
263  SUMOReal moveFactor = 1;
264  bool pageVertical = true;
265  bool ctrl = false;
266  if (e->state & CONTROLMASK) {
267  ctrl = true;
268  zoomDiff /= 2;
269  moveFactor /= 10;
270  } else if (e->state & SHIFTMASK) {
271  pageVertical = false;
272  zoomDiff *= 2;
273  }
274  switch (e->code) {
275  case FX::KEY_Left:
276  moveX = -1;
277  moveFactor /= 10;
278  break;
279  case FX::KEY_Right:
280  moveX = 1;
281  moveFactor /= 10;
282  break;
283  case FX::KEY_Up:
284  moveY = -1;
285  moveFactor /= 10;
286  break;
287  case FX::KEY_Down:
288  moveY = 1;
289  moveFactor /= 10;
290  break;
291  case FX::KEY_Page_Up:
292  if (pageVertical) {
293  moveY = -1;
294  } else {
295  moveX = -1;
296  }
297  break;
298  case FX::KEY_Page_Down:
299  if (pageVertical) {
300  moveY = 1;
301  } else {
302  moveX = 1;
303  }
304  break;
305  case FX::KEY_plus:
306  case FX::KEY_KP_Add:
308  zoom(1.0 + zoomDiff);
310  return 1;
311  case FX::KEY_minus:
312  case FX::KEY_KP_Subtract:
313  zoomDiff = -zoomDiff;
315  zoom(1.0 + zoomDiff);
317  return 1;
318  case FX::KEY_Home:
319  case FX::KEY_KP_Home:
321  myCallback.update();
322  return 1;
323  case FX::KEY_v:
324  // from an architecture standpoint this isn't the best place to put
325  // this. But its simple
326  if (ctrl) {
328  return 1;
329  }
330  default:
331  return 0;
332  }
333  myViewPort.moveby(moveX * moveFactor * myViewPort.getWidth(),
334  -moveY * moveFactor * myViewPort.getHeight());
335  myCallback.update();
336  return 1;
337 }
338 
339 
340 /****************************************************************************/
SUMOReal getHeight() const
Returns the height of the boundary.
Definition: Boundary.cpp:142
GUICompleteSchemeStorage gSchemeStorage
void growWidth(SUMOReal by)
Definition: Boundary.cpp:210
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
virtual void recenterView()
recenters the view
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:201
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:213
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:217
FXint myMouseXPosition
the current mouse position
void moveby(SUMOReal x, SUMOReal y)
Moves the boundary by the given amount.
Definition: Boundary.cpp:250
Position getPositionInformation() const
Returns the cursor&#39;s x/y position within the network.
virtual SUMOReal getZoom() const
Returns the zoom factor computed stored in this changer.