SUMO - Simulation of Urban MObility
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.dlr.de/
12 // Copyright (C) 2005-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 <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  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  new FXLabel(m1, "X:", 0, LAYOUT_CENTER_Y);
88  myXOff = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK | SPINDIAL_NOMIN | SPINDIAL_NOMAX);
89  new FXLabel(m1, "Y:", 0, LAYOUT_CENTER_Y);
90  myYOff = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK | SPINDIAL_NOMIN | SPINDIAL_NOMAX);
91 #ifdef HAVE_OSG
92  new FXLabel(m1, "LookAtX:", 0, LAYOUT_CENTER_Y);
93  myLookAtX = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK | SPINDIAL_NOMIN | SPINDIAL_NOMAX);
94  new FXLabel(m1, "LookAtY:", 0, LAYOUT_CENTER_Y);
95  myLookAtY = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK | SPINDIAL_NOMIN | SPINDIAL_NOMAX);
96  new FXLabel(m1, "LookAtZ:", 0, LAYOUT_CENTER_Y);
97  myLookAtZ = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK | SPINDIAL_NOMIN | SPINDIAL_NOMAX);
98 #endif
99  // ok/cancel
100  new FXHorizontalSeparator(f1, SEPARATOR_GROOVE | LAYOUT_FILL_X);
101  FXHorizontalFrame* f6 = new FXHorizontalFrame(f1, LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_FILL_X | PACK_UNIFORM_WIDTH, 0, 0, 0, 0, 10, 10, 5, 0);
102  FXButton* initial =
103  new FXButton(f6, "&OK", NULL, this, GUIDialog_EditViewport::MID_OK,
104  BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X,
105  0, 0, 0, 0, 4, 4, 3, 3);
106  new FXButton(f6, "&Cancel", NULL, this, GUIDialog_EditViewport::MID_CANCEL,
107  FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X,
108  0, 0, 0, 0, 4, 4, 3, 3);
109  initial->setFocus();
111 }
112 
113 
115 
116 
117 long
118 GUIDialog_EditViewport::onCmdOk(FXObject*, FXSelector, void*) {
119  myParent->setViewport(Position(myXOff->getValue(), myYOff->getValue(), myZoom->getValue()),
120 #ifdef HAVE_OSG
121  Position(myLookAtX->getValue(), myLookAtY->getValue(), myLookAtZ->getValue())
122 #else
124 #endif
125  );
126  hide();
127  return 1;
128 }
129 
130 
131 long
132 GUIDialog_EditViewport::onCmdCancel(FXObject*, FXSelector, void*) {
134  hide();
135  return 1;
136 }
137 
138 
139 long
140 GUIDialog_EditViewport::onCmdChanged(FXObject*, FXSelector, void*) {
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  return 1;
149 }
150 
151 
152 long
153 GUIDialog_EditViewport::onCmdLoad(FXObject*, FXSelector, void* /*data*/) {
154  FXFileDialog opendialog(this, "Load Viewport");
155  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
156  opendialog.setSelectMode(SELECTFILE_ANY);
157  opendialog.setPatternList("*.xml");
158  if (gCurrentFolder.length() != 0) {
159  opendialog.setDirectory(gCurrentFolder);
160  }
161  if (opendialog.execute()) {
162  gCurrentFolder = opendialog.getDirectory();
163  GUISettingsHandler handler(opendialog.getFilename().text());
164  Position lookFrom, lookAt;
165  handler.setViewport(lookFrom, lookAt);
166  if (lookFrom.z() > 0) {
167  setValues(lookFrom, lookAt);
168  myParent->setViewport(lookFrom, lookAt);
169  }
170  }
171  return 1;
172 }
173 
174 
175 long
176 GUIDialog_EditViewport::onCmdSave(FXObject*, FXSelector, void* /*data*/) {
177  FXString file = MFXUtils::getFilename2Write(this, "Save Viewport", ".xml", GUIIconSubSys::getIcon(ICON_EMPTY), gCurrentFolder);
178  if (file == "") {
179  return 1;
180  }
181  try {
182  OutputDevice& dev = OutputDevice::getDevice(file.text());
184  writeXML(dev);
185  dev.closeTag();
186  dev.close();
187  } catch (IOError& e) {
188  FXMessageBox::error(this, MBOX_OK, "Storing failed!", "%s", e.what());
189  }
190  return 1;
191 }
192 
193 
194 void
197  dev.writeAttr(SUMO_ATTR_ZOOM, myZoom->getValue());
198  dev.writeAttr(SUMO_ATTR_X, myXOff->getValue());
199  dev.writeAttr(SUMO_ATTR_Y, myYOff->getValue());
200 #ifdef HAVE_OSG
201  dev.writeAttr(SUMO_ATTR_CENTER_X, myLookAtX->getValue());
202  dev.writeAttr(SUMO_ATTR_CENTER_Y, myLookAtY->getValue());
203  dev.writeAttr(SUMO_ATTR_CENTER_Z, myLookAtZ->getValue());
204 #endif
205  dev.closeTag();
206 }
207 
208 void
210  myZoom->setValue(zoom);
211  myXOff->setValue(xoff);
212  myYOff->setValue(yoff);
213 }
214 
215 
216 void
217 GUIDialog_EditViewport::setValues(const Position& lookFrom, const Position& lookAt) {
218  myZoom->setValue(lookFrom.z());
219  myXOff->setValue(lookFrom.x());
220  myYOff->setValue(lookFrom.y());
221 #ifdef HAVE_OSG
222  myLookAtX->setValue(lookAt.x());
223  myLookAtY->setValue(lookAt.y());
224  myLookAtZ->setValue(lookAt.z());
225 #else
226  UNUSED_PARAMETER(lookAt);
227 #endif
228 }
229 
230 
231 void
232 GUIDialog_EditViewport::setOldValues(const Position& lookFrom, const Position& lookAt) {
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 
void setValues(SUMOReal zoom, SUMOReal xoff, SUMOReal yoff)
Sets the given values into the dialog.
long onCmdOk(FXObject *, FXSelector, void *)
Called when the user wants to keep the viewport.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
void close()
Closes the device and removes it from the dictionary.
virtual void setViewport(const Position &lookFrom, const Position &lookAt)
applies the given viewport settings
long onCmdCancel(FXObject *, FXSelector, void *)
Called when the user wants to restore the viewport.
long onCmdChanged(FXObject *, FXSelector, void *)
Called when the user changes the viewport.
void writeXML(OutputDevice &dev)
write the settings to the given device
FXString gCurrentFolder
The folder used as last.
long onCmdLoad(FXObject *, FXSelector, void *)
Called when the user wants to load a viewport.
FXRealSpinDial * myZoom
The spin dialers used to change the view.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
static FXString getFilename2Write(FXWindow *parent, const FXString &header, const FXString &extension, FXIcon *icon, FXString &currentFolder)
Returns the file name to write.
Definition: MFXUtils.cpp:95
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
SUMOReal z() const
Returns the z-position.
Definition: Position.h:73
long onCmdSave(FXObject *, FXSelector, void *)
Called when the user wants to save a viewport.
GUISUMOAbstractView * myParent
The calling view.
FXDEFMAP(GUIDialog_EditViewport) GUIDialog_EditViewportMap[]
Position myOldLookFrom
The old viewport.
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:213
An XML-handler for visualisation schemes.
A dialog to change the viewport.
bool haveGrabbed() const
Returns the information whether one of the spin dialers is grabbed.
static FXIcon * getIcon(GUIIcon which)
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static const Position INVALID
Definition: Position.h:261
void setOldValues(const Position &lookFrom, const Position &lookAt)
Resets old values.