SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIDialog_EditViewport.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // A dialog to change the viewport
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <utils/geom/Position.h>
37 #include "GUISUMOAbstractView.h"
40 #include "GUIDialog_EditViewport.h"
41 
42 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 
47 // ===========================================================================
48 // FOX callback mapping
49 // ===========================================================================
50 FXDEFMAP(GUIDialog_EditViewport) GUIDialog_EditViewportMap[] = {
56 };
57 
58 
59 // Object implementation
60 FXIMPLEMENT(GUIDialog_EditViewport, FXDialogBox, GUIDialog_EditViewportMap, ARRAYNUMBER(GUIDialog_EditViewportMap))
61 
62 
63 // ===========================================================================
64 // method definitions
65 // ===========================================================================
67  const char* name, int x, int y)
68  : FXDialogBox(parent, name, DECOR_TITLE | DECOR_BORDER, x, y, 0, 0),
69  myParent(parent) {
70  FXVerticalFrame* f1 = new FXVerticalFrame(this, LAYOUT_TOP | FRAME_NONE | LAYOUT_FILL_X, 0, 0, 0, 0, 0, 0, 1, 1);
71  {
72  FXHorizontalFrame* frame0 =
73  new FXHorizontalFrame(f1, FRAME_THICK, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2);
74  new FXButton(frame0, "\t\tLoad viewport from file",
76  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
77  new FXButton(frame0, "\t\tSave viewport to file",
79  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
80  }
81  FXMatrix* m1 = new FXMatrix(f1, 2, MATRIX_BY_COLUMNS);
82  {
83  new FXLabel(m1, "Zoom:", 0, LAYOUT_CENTER_Y);
84  myZoom = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
85  myZoom->setRange(0.0001, 100000);
86  myZoom->setNumberFormat(4);
87  }
88  {
89  new FXLabel(m1, "X:", 0, LAYOUT_CENTER_Y);
90  myXOff = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
91  myXOff->setRange(-1000000, 1000000);
92  myXOff->setNumberFormat(4);
93  }
94  {
95  new FXLabel(m1, "Y:", 0, LAYOUT_CENTER_Y);
96  myYOff = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
97  myYOff->setRange(-1000000, 1000000);
98  myYOff->setNumberFormat(4);
99  }
100 #ifdef HAVE_OSG
101  {
102  new FXLabel(m1, "LookAtX:", 0, LAYOUT_CENTER_Y);
103  myLookAtX = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
104  myLookAtX->setRange(-1000000, 100000);
105  myLookAtX->setNumberFormat(4);
106  }
107  {
108  new FXLabel(m1, "LookAtY:", 0, LAYOUT_CENTER_Y);
109  myLookAtY = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
110  myLookAtY->setRange(-1000000, 1000000);
111  myLookAtY->setNumberFormat(4);
112  }
113  {
114  new FXLabel(m1, "LookAtZ:", 0, LAYOUT_CENTER_Y);
115  myLookAtZ = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
116  myLookAtZ->setRange(-1000000, 1000000);
117  myLookAtZ->setNumberFormat(4);
118  }
119 #endif
120  // ok/cancel
121  new FXHorizontalSeparator(f1, SEPARATOR_GROOVE | LAYOUT_FILL_X);
122  FXHorizontalFrame* f6 = new FXHorizontalFrame(f1, LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_FILL_X | PACK_UNIFORM_WIDTH, 0, 0, 0, 0, 10, 10, 5, 0);
123  FXButton* initial =
124  new FXButton(f6, "&OK", NULL, this, GUIDialog_EditViewport::MID_OK,
125  BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X,
126  0, 0, 0, 0, 4, 4, 3, 3);
127  new FXButton(f6, "&Cancel", NULL, this, GUIDialog_EditViewport::MID_CANCEL,
128  FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X,
129  0, 0, 0, 0, 4, 4, 3, 3);
130  initial->setFocus();
132 }
133 
134 
136 
137 
138 long
140  myParent->setViewport(Position(myXOff->getValue(), myYOff->getValue(), myZoom->getValue()),
141 #ifdef HAVE_OSG
142  Position(myLookAtX->getValue(), myLookAtY->getValue(), myLookAtZ->getValue())
143 #else
145 #endif
146  );
147  hide();
148  return 1;
149 }
150 
151 
152 long
155  hide();
156  return 1;
157 }
158 
159 
160 long
162  myParent->setViewport(Position(myXOff->getValue(), myYOff->getValue(), myZoom->getValue()),
163 #ifdef HAVE_OSG
164  Position(myLookAtX->getValue(), myLookAtY->getValue(), myLookAtZ->getValue())
165 #else
167 #endif
168  );
169  return 1;
170 }
171 
172 
173 long
174 GUIDialog_EditViewport::onCmdLoad(FXObject*, FXSelector, void* /*data*/) {
175  FXFileDialog opendialog(this, "Load Viewport");
176  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
177  opendialog.setSelectMode(SELECTFILE_ANY);
178  opendialog.setPatternList("*.xml");
179  if (gCurrentFolder.length() != 0) {
180  opendialog.setDirectory(gCurrentFolder);
181  }
182  if (opendialog.execute()) {
183  gCurrentFolder = opendialog.getDirectory();
184  GUISettingsHandler handler(opendialog.getFilename().text());
185  Position lookFrom, lookAt;
186  handler.setViewport(lookFrom, lookAt);
187  if (lookFrom.z() > 0) {
188  setValues(lookFrom, lookAt);
189  myParent->setViewport(lookFrom, lookAt);
190  }
191  }
192  return 1;
193 }
194 
195 
196 long
197 GUIDialog_EditViewport::onCmdSave(FXObject*, FXSelector, void* /*data*/) {
198  FXFileDialog opendialog(this, "Save Viewport");
199  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
200  opendialog.setSelectMode(SELECTFILE_ANY);
201  opendialog.setPatternList("*.xml");
202  if (gCurrentFolder.length() != 0) {
203  opendialog.setDirectory(gCurrentFolder);
204  }
205  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
206  return 1;
207  }
208  try {
209  OutputDevice& dev = OutputDevice::getDevice(opendialog.getFilename().text());
210  dev << "<viewsettings>\n";
211  dev << " <viewport zoom=\"" << myZoom->getValue() << "\" x=\"" << myXOff->getValue() << "\" y=\"" << myYOff->getValue();
212 #ifdef HAVE_OSG
213  dev << "\" centerX=\"" << myLookAtX->getValue() << "\" centerY=\"" << myLookAtY->getValue() << "\" centerZ=\"" << myLookAtZ->getValue();
214 #endif
215  dev << "\"/>\n</viewsettings>\n";
216  dev.close();
217  } catch (IOError& e) {
218  FXMessageBox::error(this, MBOX_OK, "Storing failed!", "%s", e.what());
219  }
220  return 1;
221 }
222 
223 
224 void
226  myZoom->setValue(zoom);
227  myXOff->setValue(xoff);
228  myYOff->setValue(yoff);
229 }
230 
231 
232 void
233 GUIDialog_EditViewport::setValues(const Position& lookFrom, const Position& lookAt) {
234  myZoom->setValue(lookFrom.z());
235  myXOff->setValue(lookFrom.x());
236  myYOff->setValue(lookFrom.y());
237 #ifdef HAVE_OSG
238  myLookAtX->setValue(lookAt.x());
239  myLookAtY->setValue(lookAt.y());
240  myLookAtZ->setValue(lookAt.z());
241 #else
242  UNUSED_PARAMETER(lookAt);
243 #endif
244 }
245 
246 
247 void
248 GUIDialog_EditViewport::setOldValues(const Position& lookFrom, const Position& lookAt) {
249  setValues(lookFrom, lookAt);
250  myOldLookFrom = lookFrom;
251  myOldLookAt = lookAt;
252 }
253 
254 
255 bool
257  return myZoom->getDial().grabbed() || myXOff->getDial().grabbed() || myYOff->getDial().grabbed();
258 }
259 
260 
261 /****************************************************************************/
262