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.sourceforge.net/
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  Position(myLookAtX->getValue(), myLookAtY->getValue(), myLookAtZ->getValue()));
142  hide();
143  return 1;
144 }
145 
146 
147 long
150  hide();
151  return 1;
152 }
153 
154 
155 long
157  myParent->setViewport(Position(myXOff->getValue(), myYOff->getValue(), myZoom->getValue()),
158  Position(myLookAtX->getValue(), myLookAtY->getValue(), myLookAtZ->getValue()));
159  return 1;
160 }
161 
162 
163 long
164 GUIDialog_EditViewport::onCmdLoad(FXObject*, FXSelector, void* /*data*/) {
165  FXFileDialog opendialog(this, "Load Viewport");
166  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
167  opendialog.setSelectMode(SELECTFILE_ANY);
168  opendialog.setPatternList("*.xml");
169  if (gCurrentFolder.length() != 0) {
170  opendialog.setDirectory(gCurrentFolder);
171  }
172  if (opendialog.execute()) {
173  gCurrentFolder = opendialog.getDirectory();
174  GUISettingsHandler handler(opendialog.getFilename().text());
175  Position lookFrom, lookAt;
176  handler.setViewport(lookFrom, lookAt);
177  if (lookFrom.z() > 0) {
178  setValues(lookFrom, lookAt);
179  myParent->setViewport(lookFrom, lookAt);
180  }
181  }
182  return 1;
183 }
184 
185 
186 long
187 GUIDialog_EditViewport::onCmdSave(FXObject*, FXSelector, void* /*data*/) {
188  FXFileDialog opendialog(this, "Save Viewport");
189  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
190  opendialog.setSelectMode(SELECTFILE_ANY);
191  opendialog.setPatternList("*.xml");
192  if (gCurrentFolder.length() != 0) {
193  opendialog.setDirectory(gCurrentFolder);
194  }
195  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
196  return 1;
197  }
198  try {
199  OutputDevice& dev = OutputDevice::getDevice(opendialog.getFilename().text());
200  dev << "<viewsettings>\n";
201  dev << " <viewport zoom=\"" << myZoom->getValue() << "\" x=\"" << myXOff->getValue() << "\" y=\"" << myYOff->getValue() << "\"";
202  dev << " centerX=\"" << myLookAtX->getValue() << "\" centerY=\"" << myLookAtY->getValue() << "\" centerZ=\"" << myLookAtZ->getValue() << "\"/>\n";
203  dev << "</viewsettings>\n";
204  dev.close();
205  } catch (IOError& e) {
206  FXMessageBox::error(this, MBOX_OK, "Storing failed!", "%s", e.what());
207  }
208  return 1;
209 }
210 
211 
212 void
214  myZoom->setValue(zoom);
215  myXOff->setValue(xoff);
216  myYOff->setValue(yoff);
217 }
218 
219 
220 void
222  myZoom->setValue(lookFrom.z());
223  myXOff->setValue(lookFrom.x());
224  myYOff->setValue(lookFrom.y());
225  myLookAtX->setValue(lookAt.x());
226  myLookAtY->setValue(lookAt.y());
227  myLookAtZ->setValue(lookAt.z());
228 }
229 
230 
231 void
233  setValues(lookFrom, lookAt);
234  myOldLookFrom = lookFrom;
235  myOldLookAt = lookAt;
236 }
237 
238 
239 bool
241  return myZoom->getDial().grabbed() || myXOff->getDial().grabbed() || myYOff->getDial().grabbed();
242 }
243 
244 
245 /****************************************************************************/
246