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-2012 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 "GUIDialog_EditViewport.h"
33 #include "GUISUMOAbstractView.h"
40 
41 #ifdef CHECK_MEMORY_LEAKS
42 #include <foreign/nvwa/debug_new.h>
43 #endif // CHECK_MEMORY_LEAKS
44 
45 
46 // ===========================================================================
47 // FOX callback mapping
48 // ===========================================================================
49 FXDEFMAP(GUIDialog_EditViewport) GUIDialog_EditViewportMap[] = {
55 };
56 
57 
58 // Object implementation
59 FXIMPLEMENT(GUIDialog_EditViewport, FXDialogBox, GUIDialog_EditViewportMap, ARRAYNUMBER(GUIDialog_EditViewportMap))
60 
61 
62 // ===========================================================================
63 // method definitions
64 // ===========================================================================
66  const char* name, SUMOReal zoom, SUMOReal xoff, SUMOReal yoff, int x, int y)
67  : FXDialogBox(parent, name, DECOR_TITLE | DECOR_BORDER, x, y, 0, 0),
68  myParent(parent), myOldZoom(zoom), myOldXOff(xoff), myOldYOff(yoff) {
69  FXVerticalFrame* f1 = new FXVerticalFrame(this, LAYOUT_TOP | FRAME_NONE | LAYOUT_FILL_X, 0, 0, 0, 0, 0, 0, 1, 1);
70  {
71  FXHorizontalFrame* frame0 =
72  new FXHorizontalFrame(f1, FRAME_THICK, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2);
73  new FXButton(frame0, "\t\tLoad viewport from file",
75  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
76  new FXButton(frame0, "\t\tSave viewport to file",
78  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
79  }
80  FXMatrix* m1 = new FXMatrix(f1, 2, MATRIX_BY_COLUMNS);
81  {
82  new FXLabel(m1, "Zoom:", 0, LAYOUT_CENTER_Y);
83  myZoom = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
84  myZoom->setRange(0.0001, 100000);
85  myZoom->setNumberFormat(4);
86  myZoom->setValue(zoom);
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  myXOff->setValue(xoff);
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  myYOff->setValue(yoff);
101  }
102  // ok/cancel
103  new FXHorizontalSeparator(f1, SEPARATOR_GROOVE | LAYOUT_FILL_X);
104  FXHorizontalFrame* f6 = new FXHorizontalFrame(f1, LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_FILL_X | PACK_UNIFORM_WIDTH, 0, 0, 0, 0, 10, 10, 5, 0);
105  FXButton* initial =
106  new FXButton(f6, "&OK", NULL, this, GUIDialog_EditViewport::MID_OK,
107  BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X,
108  0, 0, 0, 0, 4, 4, 3, 3);
109  new FXButton(f6, "&Cancel", NULL, this, GUIDialog_EditViewport::MID_CANCEL,
110  FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X,
111  0, 0, 0, 0, 4, 4, 3, 3);
112  initial->setFocus();
114 }
115 
116 
118 
119 
120 long
122  myParent->setViewport((SUMOReal) myZoom->getValue(), (SUMOReal) myXOff->getValue(), (SUMOReal) myYOff->getValue());
123  hide();
124  return 1;
125 }
126 
127 
128 long
131  hide();
132  return 1;
133 }
134 
135 
136 long
138  myParent->setViewport((SUMOReal) myZoom->getValue(), (SUMOReal) myXOff->getValue(), (SUMOReal) myYOff->getValue());
139  return 1;
140 }
141 
142 
143 long
144 GUIDialog_EditViewport::onCmdLoad(FXObject*, FXSelector, void* /*data*/) {
145  FXFileDialog opendialog(this, "Load Viewport");
146  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
147  opendialog.setSelectMode(SELECTFILE_ANY);
148  opendialog.setPatternList("*.xml");
149  if (gCurrentFolder.length() != 0) {
150  opendialog.setDirectory(gCurrentFolder);
151  }
152  if (opendialog.execute()) {
153  gCurrentFolder = opendialog.getDirectory();
154  GUISettingsHandler handler(opendialog.getFilename().text());
155  SUMOReal zoom, xoff, yoff;
156  handler.setViewport(zoom, xoff, yoff);
157  if (zoom > 0) {
158  setValues(zoom, xoff, yoff);
159  myParent->setViewport(zoom, xoff, yoff);
160  }
161  }
162  return 1;
163 }
164 
165 
166 long
167 GUIDialog_EditViewport::onCmdSave(FXObject*, FXSelector, void* /*data*/) {
168  FXFileDialog opendialog(this, "Save Viewport");
169  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
170  opendialog.setSelectMode(SELECTFILE_ANY);
171  opendialog.setPatternList("*.xml");
172  if (gCurrentFolder.length() != 0) {
173  opendialog.setDirectory(gCurrentFolder);
174  }
175  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
176  return 1;
177  }
178  try {
179  OutputDevice& dev = OutputDevice::getDevice(opendialog.getFilename().text());
180  dev << "<viewsettings>\n";
181  dev << " <viewport zoom=\"" << myZoom->getValue() << "\" x=\"" << myXOff->getValue() << "\" y=\"" << myYOff->getValue() << "\"/>\n";
182  dev << "</viewsettings>\n";
183  dev.close();
184  } catch (IOError& e) {
185  FXMessageBox::error(this, MBOX_OK, "Storing failed!", "%s", e.what());
186  }
187  return 1;
188 }
189 
190 
191 void
193  myZoom->setValue(zoom);
194  myXOff->setValue(xoff);
195  myYOff->setValue(yoff);
196 }
197 
198 
199 void
201  myZoom->setValue(zoom);
202  myXOff->setValue(xoff);
203  myYOff->setValue(yoff);
204  myOldZoom = zoom;
205  myOldXOff = xoff;
206  myOldYOff = yoff;
207 }
208 
209 
210 bool
212  return myZoom->getDial().grabbed() || myXOff->getDial().grabbed() || myYOff->getDial().grabbed();
213 }
214 
215 
216 /****************************************************************************/
217