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 /****************************************************************************/
9 // A dialog to change the viewport
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2005-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/Position.h>
38 #include "GUISUMOAbstractView.h"
41 #include "GUIDialog_EditViewport.h"
42 
43 #ifdef CHECK_MEMORY_LEAKS
44 #include <foreign/nvwa/debug_new.h>
45 #endif // CHECK_MEMORY_LEAKS
46 
47 
48 // ===========================================================================
49 // FOX callback mapping
50 // ===========================================================================
51 FXDEFMAP(GUIDialog_EditViewport) GUIDialog_EditViewportMap[] = {
57 };
58 
59 
60 // Object implementation
61 FXIMPLEMENT(GUIDialog_EditViewport, FXDialogBox, GUIDialog_EditViewportMap, ARRAYNUMBER(GUIDialog_EditViewportMap))
62 
63 
64 // ===========================================================================
65 // method definitions
66 // ===========================================================================
68  const char* name, int x, int y)
69  : FXDialogBox(parent, name, DECOR_TITLE | DECOR_BORDER, x, y, 0, 0),
70  myParent(parent) {
71  FXVerticalFrame* f1 = new FXVerticalFrame(this, LAYOUT_TOP | FRAME_NONE | LAYOUT_FILL_X, 0, 0, 0, 0, 0, 0, 1, 1);
72  {
73  FXHorizontalFrame* frame0 =
74  new FXHorizontalFrame(f1, FRAME_THICK, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2);
75  new FXButton(frame0, "\t\tLoad viewport from file",
77  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
78  new FXButton(frame0, "\t\tSave viewport to file",
80  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
81  }
82  FXMatrix* m1 = new FXMatrix(f1, 2, MATRIX_BY_COLUMNS);
83  {
84  new FXLabel(m1, "Zoom:", 0, LAYOUT_CENTER_Y);
85  myZoom = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
86  myZoom->setRange(0.0001, 100000);
87  myZoom->setNumberFormat(4);
88  }
89  {
90  new FXLabel(m1, "X:", 0, LAYOUT_CENTER_Y);
91  myXOff = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
92  myXOff->setRange(-1000000, 1000000);
93  myXOff->setNumberFormat(4);
94  }
95  {
96  new FXLabel(m1, "Y:", 0, LAYOUT_CENTER_Y);
97  myYOff = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
98  myYOff->setRange(-1000000, 1000000);
99  myYOff->setNumberFormat(4);
100  }
101 #ifdef HAVE_OSG
102  {
103  new FXLabel(m1, "LookAtX:", 0, LAYOUT_CENTER_Y);
104  myLookAtX = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
105  myLookAtX->setRange(-1000000, 100000);
106  myLookAtX->setNumberFormat(4);
107  }
108  {
109  new FXLabel(m1, "LookAtY:", 0, LAYOUT_CENTER_Y);
110  myLookAtY = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
111  myLookAtY->setRange(-1000000, 1000000);
112  myLookAtY->setNumberFormat(4);
113  }
114  {
115  new FXLabel(m1, "LookAtZ:", 0, LAYOUT_CENTER_Y);
116  myLookAtZ = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
117  myLookAtZ->setRange(-1000000, 1000000);
118  myLookAtZ->setNumberFormat(4);
119  }
120 #endif
121  // ok/cancel
122  new FXHorizontalSeparator(f1, SEPARATOR_GROOVE | LAYOUT_FILL_X);
123  FXHorizontalFrame* f6 = new FXHorizontalFrame(f1, LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_FILL_X | PACK_UNIFORM_WIDTH, 0, 0, 0, 0, 10, 10, 5, 0);
124  FXButton* initial =
125  new FXButton(f6, "&OK", NULL, this, GUIDialog_EditViewport::MID_OK,
126  BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X,
127  0, 0, 0, 0, 4, 4, 3, 3);
128  new FXButton(f6, "&Cancel", NULL, this, GUIDialog_EditViewport::MID_CANCEL,
129  FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X,
130  0, 0, 0, 0, 4, 4, 3, 3);
131  initial->setFocus();
133 }
134 
135 
137 
138 
139 long
141  myParent->setViewport(Position(myXOff->getValue(), myYOff->getValue(), myZoom->getValue()),
142 #ifdef HAVE_OSG
143  Position(myLookAtX->getValue(), myLookAtY->getValue(), myLookAtZ->getValue())
144 #else
146 #endif
147  );
148  hide();
149  return 1;
150 }
151 
152 
153 long
156  hide();
157  return 1;
158 }
159 
160 
161 long
163  myParent->setViewport(Position(myXOff->getValue(), myYOff->getValue(), myZoom->getValue()),
164 #ifdef HAVE_OSG
165  Position(myLookAtX->getValue(), myLookAtY->getValue(), myLookAtZ->getValue())
166 #else
168 #endif
169  );
170  return 1;
171 }
172 
173 
174 long
175 GUIDialog_EditViewport::onCmdLoad(FXObject*, FXSelector, void* /*data*/) {
176  FXFileDialog opendialog(this, "Load Viewport");
177  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
178  opendialog.setSelectMode(SELECTFILE_ANY);
179  opendialog.setPatternList("*.xml");
180  if (gCurrentFolder.length() != 0) {
181  opendialog.setDirectory(gCurrentFolder);
182  }
183  if (opendialog.execute()) {
184  gCurrentFolder = opendialog.getDirectory();
185  GUISettingsHandler handler(opendialog.getFilename().text());
186  Position lookFrom, lookAt;
187  handler.setViewport(lookFrom, lookAt);
188  if (lookFrom.z() > 0) {
189  setValues(lookFrom, lookAt);
190  myParent->setViewport(lookFrom, lookAt);
191  }
192  }
193  return 1;
194 }
195 
196 
197 long
198 GUIDialog_EditViewport::onCmdSave(FXObject*, FXSelector, void* /*data*/) {
199  FXFileDialog opendialog(this, "Save Viewport");
200  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
201  opendialog.setSelectMode(SELECTFILE_ANY);
202  opendialog.setPatternList("*.xml");
203  if (gCurrentFolder.length() != 0) {
204  opendialog.setDirectory(gCurrentFolder);
205  }
206  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
207  return 1;
208  }
209  try {
210  OutputDevice& dev = OutputDevice::getDevice(opendialog.getFilename().text());
211  dev << "<viewsettings>\n";
212  dev << " <viewport zoom=\"" << myZoom->getValue() << "\" x=\"" << myXOff->getValue() << "\" y=\"" << myYOff->getValue();
213 #ifdef HAVE_OSG
214  dev << "\" centerX=\"" << myLookAtX->getValue() << "\" centerY=\"" << myLookAtY->getValue() << "\" centerZ=\"" << myLookAtZ->getValue();
215 #endif
216  dev << "\"/>\n</viewsettings>\n";
217  dev.close();
218  } catch (IOError& e) {
219  FXMessageBox::error(this, MBOX_OK, "Storing failed!", "%s", e.what());
220  }
221  return 1;
222 }
223 
224 
225 void
227  myZoom->setValue(zoom);
228  myXOff->setValue(xoff);
229  myYOff->setValue(yoff);
230 }
231 
232 
233 void
234 GUIDialog_EditViewport::setValues(const Position& lookFrom, const Position& lookAt) {
235  myZoom->setValue(lookFrom.z());
236  myXOff->setValue(lookFrom.x());
237  myYOff->setValue(lookFrom.y());
238 #ifdef HAVE_OSG
239  myLookAtX->setValue(lookAt.x());
240  myLookAtY->setValue(lookAt.y());
241  myLookAtZ->setValue(lookAt.z());
242 #else
243  UNUSED_PARAMETER(lookAt);
244 #endif
245 }
246 
247 
248 void
249 GUIDialog_EditViewport::setOldValues(const Position& lookFrom, const Position& lookAt) {
250  setValues(lookFrom, lookAt);
251  myOldLookFrom = lookFrom;
252  myOldLookAt = lookAt;
253 }
254 
255 
256 bool
258  return myZoom->getDial().grabbed() || myXOff->getDial().grabbed() || myYOff->getDial().grabbed();
259 }
260 
261 
262 /****************************************************************************/
263