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-2017 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>
39 #include "GUISUMOAbstractView.h"
43 #include "GUIDialog_EditViewport.h"
44 
45 #ifdef CHECK_MEMORY_LEAKS
46 #include <foreign/nvwa/debug_new.h>
47 #endif // CHECK_MEMORY_LEAKS
48 
49 
50 // ===========================================================================
51 // FOX callback mapping
52 // ===========================================================================
53 FXDEFMAP(GUIDialog_EditViewport) GUIDialog_EditViewportMap[] = {
59 };
60 
61 
62 // Object implementation
63 FXIMPLEMENT(GUIDialog_EditViewport, FXDialogBox, GUIDialog_EditViewportMap, ARRAYNUMBER(GUIDialog_EditViewportMap))
64 
65 
66 // ===========================================================================
67 // method definitions
68 // ===========================================================================
70  const char* name, int x, int y)
71  : FXDialogBox(parent, name, DECOR_TITLE | DECOR_BORDER, x, y, 0, 0),
72  myParent(parent) {
73  FXVerticalFrame* f1 = new FXVerticalFrame(this, LAYOUT_TOP | FRAME_NONE | LAYOUT_FILL_X, 0, 0, 0, 0, 0, 0, 1, 1);
74  {
75  FXHorizontalFrame* frame0 =
76  new FXHorizontalFrame(f1, FRAME_THICK, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2);
77  new FXButton(frame0, "\t\tLoad viewport from file",
79  new FXButton(frame0, "\t\tSave viewport to file",
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, GUIDesignSpinDial | SPINDIAL_NOMIN | SPINDIAL_NOMAX);
89  new FXLabel(m1, "Y:", 0, LAYOUT_CENTER_Y);
90  myYOff = new FXRealSpinDial(m1, 16, this, MID_CHANGED, GUIDesignSpinDial | SPINDIAL_NOMIN | SPINDIAL_NOMAX);
91  new FXLabel(m1, "Z:", 0, LAYOUT_CENTER_Y);
92  myZOff = new FXRealSpinDial(m1, 16, this, MID_CHANGED, GUIDesignSpinDial | SPINDIAL_NOMIN | SPINDIAL_NOMAX);
93 #ifdef HAVE_OSG
94  new FXLabel(m1, "LookAtX:", 0, LAYOUT_CENTER_Y);
95  myLookAtX = new FXRealSpinDial(m1, 16, this, MID_CHANGED, GUIDesignSpinDial | SPINDIAL_NOMIN | SPINDIAL_NOMAX);
96  new FXLabel(m1, "LookAtY:", 0, LAYOUT_CENTER_Y);
97  myLookAtY = new FXRealSpinDial(m1, 16, this, MID_CHANGED, GUIDesignSpinDial | SPINDIAL_NOMIN | SPINDIAL_NOMAX);
98  new FXLabel(m1, "LookAtZ:", 0, LAYOUT_CENTER_Y);
99  myLookAtZ = new FXRealSpinDial(m1, 16, this, MID_CHANGED, GUIDesignSpinDial | SPINDIAL_NOMIN | SPINDIAL_NOMAX);
100 #endif
101  // ok/cancel
102  new FXHorizontalSeparator(f1, GUIDesignHorizontalSeparator);
103  FXHorizontalFrame* f6 = new FXHorizontalFrame(f1, LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_FILL_X | PACK_UNIFORM_WIDTH, 0, 0, 0, 0, 10, 10, 5, 0);
104  FXButton* initial =
105  new FXButton(f6, "&OK", NULL, this, GUIDialog_EditViewport::MID_OK,
106  BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X,
107  0, 0, 0, 0, 4, 4, 3, 3);
108  new FXButton(f6, "&Cancel", NULL, this, GUIDialog_EditViewport::MID_CANCEL,
109  FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X,
110  0, 0, 0, 0, 4, 4, 3, 3);
111  initial->setFocus();
113 }
114 
115 
117 
118 
119 long
120 GUIDialog_EditViewport::onCmdOk(FXObject*, FXSelector, void*) {
121  myParent->setViewportFromTo(Position(myXOff->getValue(), myYOff->getValue(), myZOff->getValue()),
122 #ifdef HAVE_OSG
123  Position(myLookAtX->getValue(), myLookAtY->getValue(), myLookAtZ->getValue())
124 #else
126 #endif
127  );
128  hide();
129  return 1;
130 }
131 
132 
133 long
134 GUIDialog_EditViewport::onCmdCancel(FXObject*, FXSelector, void*) {
136  hide();
137  return 1;
138 }
139 
140 
141 long
142 GUIDialog_EditViewport::onCmdChanged(FXObject* o, FXSelector, void*) {
143  if (o == myZOff) {
144  myZoom->setValue(myParent->getChanger().zPos2Zoom(myZOff->getValue()));
145  } else if (o == myZoom) {
146  myZOff->setValue(myParent->getChanger().zoom2ZPos(myZoom->getValue()));
147  }
148  myParent->setViewportFromTo(Position(myXOff->getValue(), myYOff->getValue(), myZOff->getValue()),
149 #ifdef HAVE_OSG
150  Position(myLookAtX->getValue(), myLookAtY->getValue(), myLookAtZ->getValue())
151 #else
153 #endif
154  );
155  return 1;
156 }
157 
158 
159 long
160 GUIDialog_EditViewport::onCmdLoad(FXObject*, FXSelector, void* /*data*/) {
161  FXFileDialog opendialog(this, "Load Viewport");
162  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
163  opendialog.setSelectMode(SELECTFILE_ANY);
164  opendialog.setPatternList("*.xml");
165  if (gCurrentFolder.length() != 0) {
166  opendialog.setDirectory(gCurrentFolder);
167  }
168  if (opendialog.execute()) {
169  gCurrentFolder = opendialog.getDirectory();
170  GUISettingsHandler handler(opendialog.getFilename().text());
171  handler.applyViewport(myParent);
173  }
174  return 1;
175 }
176 
177 
178 long
179 GUIDialog_EditViewport::onCmdSave(FXObject*, FXSelector, void* /*data*/) {
180  FXString file = MFXUtils::getFilename2Write(this, "Save Viewport", ".xml", GUIIconSubSys::getIcon(ICON_EMPTY), gCurrentFolder);
181  if (file == "") {
182  return 1;
183  }
184  try {
185  OutputDevice& dev = OutputDevice::getDevice(file.text());
187  writeXML(dev);
188  dev.closeTag();
189  dev.close();
190  } catch (IOError& e) {
191  FXMessageBox::error(this, MBOX_OK, "Storing failed!", "%s", e.what());
192  }
193  return 1;
194 }
195 
196 
197 void
200  dev.writeAttr(SUMO_ATTR_ZOOM, myZoom->getValue());
201  dev.writeAttr(SUMO_ATTR_X, myXOff->getValue());
202  dev.writeAttr(SUMO_ATTR_Y, myYOff->getValue());
203 #ifdef HAVE_OSG
204  dev.writeAttr(SUMO_ATTR_CENTER_X, myLookAtX->getValue());
205  dev.writeAttr(SUMO_ATTR_CENTER_Y, myLookAtY->getValue());
206  dev.writeAttr(SUMO_ATTR_CENTER_Z, myLookAtZ->getValue());
207 #endif
208  dev.closeTag();
209 }
210 
211 void
213  myZoom->setValue(zoom);
214  myXOff->setValue(xoff);
215  myYOff->setValue(yoff);
216  myZOff->setValue(myParent->getChanger().zoom2ZPos(zoom));
217 }
218 
219 
220 void
221 GUIDialog_EditViewport::setValues(const Position& lookFrom, const Position& lookAt) {
222  myXOff->setValue(lookFrom.x());
223  myYOff->setValue(lookFrom.y());
224  myZOff->setValue(lookFrom.z());
225  myZoom->setValue(myParent->getChanger().zPos2Zoom(lookFrom.z()));
226 #ifdef HAVE_OSG
227  myLookAtX->setValue(lookAt.x());
228  myLookAtY->setValue(lookAt.y());
229  myLookAtZ->setValue(lookAt.z());
230 #else
231  UNUSED_PARAMETER(lookAt);
232 #endif
233 }
234 
235 
236 void
237 GUIDialog_EditViewport::setOldValues(const Position& lookFrom, const Position& lookAt) {
238  setValues(lookFrom, lookAt);
239  myOldLookFrom = lookFrom;
240  myOldLookAt = lookAt;
241 }
242 
243 
244 bool
246  return myZoom->getDial().grabbed() || myXOff->getDial().grabbed() || myYOff->getDial().grabbed();
247 }
248 
249 
250 /****************************************************************************/
251 
virtual SUMOReal zoom2ZPos(SUMOReal zoom) const =0
Returns the camera height at which the given zoom level is reached.
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:256
void close()
Closes the device and removes it from the dictionary.
virtual void setViewportFromTo(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.
#define GUIDesignButtonToolbar
little button with icon placed in navigation toolbar
Definition: GUIDesigns.h:89
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.
virtual SUMOReal getZoom() const =0
Returns the zoom factor computed stored in this changer.
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:38
virtual SUMOReal zPos2Zoom(SUMOReal zPos) const =0
Returns the zoom level that is achieved at a given camera height.
virtual SUMOReal getYPos() const =0
Returns the y-offset of the field to show stored in this changer.
#define GUIDesignHorizontalSeparator
Definition: GUIDesigns.h:266
void applyViewport(GUISUMOAbstractView *view) const
Sets the viewport which has been parsed.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
virtual SUMOReal getXPos() const =0
Returns the x-offset of the field to show stored in this changer.
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
GUIPerspectiveChanger & getChanger() const
get changer
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:208
An XML-handler for visualisation schemes.
#define GUIDesignSpinDial
Definition: GUIDesigns.h:286
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)
returns a icon previously defined in the enum GUIIcon
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:278
void setOldValues(const Position &lookFrom, const Position &lookAt)
Resets old values.