SUMO - Simulation of Urban MObility
GUIDialog_EditViewport.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00008 // A dialog to change the viewport
00009 /****************************************************************************/
00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00012 /****************************************************************************/
00013 //
00014 //   This file is part of SUMO.
00015 //   SUMO is free software: you can redistribute it and/or modify
00016 //   it under the terms of the GNU General Public License as published by
00017 //   the Free Software Foundation, either version 3 of the License, or
00018 //   (at your option) any later version.
00019 //
00020 /****************************************************************************/
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include "GUIDialog_EditViewport.h"
00033 #include "GUISUMOAbstractView.h"
00034 #include <utils/foxtools/FXRealSpinDial.h>
00035 #include <utils/gui/windows/GUIAppEnum.h>
00036 #include <utils/gui/images/GUIIconSubSys.h>
00037 #include <utils/gui/settings/GUISettingsHandler.h>
00038 #include <utils/gui/div/GUIIOGlobals.h>
00039 #include <utils/foxtools/MFXUtils.h>
00040 
00041 #ifdef CHECK_MEMORY_LEAKS
00042 #include <foreign/nvwa/debug_new.h>
00043 #endif // CHECK_MEMORY_LEAKS
00044 
00045 
00046 // ===========================================================================
00047 // FOX callback mapping
00048 // ===========================================================================
00049 FXDEFMAP(GUIDialog_EditViewport) GUIDialog_EditViewportMap[] = {
00050     FXMAPFUNC(SEL_COMMAND, GUIDialog_EditViewport::MID_CHANGED, GUIDialog_EditViewport::onCmdChanged),
00051     FXMAPFUNC(SEL_COMMAND, GUIDialog_EditViewport::MID_OK,      GUIDialog_EditViewport::onCmdOk),
00052     FXMAPFUNC(SEL_COMMAND, GUIDialog_EditViewport::MID_CANCEL,  GUIDialog_EditViewport::onCmdCancel),
00053     FXMAPFUNC(SEL_COMMAND, GUIDialog_EditViewport::MID_LOAD,    GUIDialog_EditViewport::onCmdLoad),
00054     FXMAPFUNC(SEL_COMMAND, GUIDialog_EditViewport::MID_SAVE,    GUIDialog_EditViewport::onCmdSave),
00055 };
00056 
00057 
00058 // Object implementation
00059 FXIMPLEMENT(GUIDialog_EditViewport, FXDialogBox, GUIDialog_EditViewportMap, ARRAYNUMBER(GUIDialog_EditViewportMap))
00060 
00061 
00062 // ===========================================================================
00063 // method definitions
00064 // ===========================================================================
00065 GUIDialog_EditViewport::GUIDialog_EditViewport(GUISUMOAbstractView* parent,
00066         const char* name, SUMOReal zoom, SUMOReal xoff, SUMOReal yoff, int x, int y)
00067     : FXDialogBox(parent, name, DECOR_TITLE | DECOR_BORDER, x, y, 0, 0),
00068       myParent(parent), myOldZoom(zoom), myOldXOff(xoff), myOldYOff(yoff) {
00069     FXVerticalFrame* f1 = new FXVerticalFrame(this, LAYOUT_TOP | FRAME_NONE | LAYOUT_FILL_X, 0, 0, 0, 0, 0, 0, 1, 1);
00070     {
00071         FXHorizontalFrame* frame0 =
00072             new FXHorizontalFrame(f1, FRAME_THICK, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2);
00073         new FXButton(frame0, "\t\tLoad viewport from file",
00074                      GUIIconSubSys::getIcon(ICON_OPEN_CONFIG), this, GUIDialog_EditViewport::MID_LOAD,
00075                      ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
00076         new FXButton(frame0, "\t\tSave viewport to file",
00077                      GUIIconSubSys::getIcon(ICON_SAVE), this, GUIDialog_EditViewport::MID_SAVE,
00078                      ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
00079     }
00080     FXMatrix* m1 = new FXMatrix(f1, 2, MATRIX_BY_COLUMNS);
00081     {
00082         new FXLabel(m1, "Zoom:", 0, LAYOUT_CENTER_Y);
00083         myZoom = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
00084         myZoom->setRange(0.0001, 100000);
00085         myZoom->setNumberFormat(4);
00086         myZoom->setValue(zoom);
00087     }
00088     {
00089         new FXLabel(m1, "X:", 0, LAYOUT_CENTER_Y);
00090         myXOff = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
00091         myXOff->setRange(-1000000, 1000000);
00092         myXOff->setNumberFormat(4);
00093         myXOff->setValue(xoff);
00094     }
00095     {
00096         new FXLabel(m1, "Y:", 0, LAYOUT_CENTER_Y);
00097         myYOff = new FXRealSpinDial(m1, 16, this, MID_CHANGED, LAYOUT_CENTER_Y | LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
00098         myYOff->setRange(-1000000, 1000000);
00099         myYOff->setNumberFormat(4);
00100         myYOff->setValue(yoff);
00101     }
00102     // ok/cancel
00103     new FXHorizontalSeparator(f1, SEPARATOR_GROOVE | LAYOUT_FILL_X);
00104     FXHorizontalFrame* f6 = new FXHorizontalFrame(f1, LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_FILL_X | PACK_UNIFORM_WIDTH, 0, 0, 0, 0, 10, 10, 5, 0);
00105     FXButton* initial =
00106         new FXButton(f6, "&OK", NULL, this, GUIDialog_EditViewport::MID_OK,
00107                      BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X,
00108                      0, 0, 0, 0,  4, 4, 3, 3);
00109     new FXButton(f6, "&Cancel", NULL, this, GUIDialog_EditViewport::MID_CANCEL,
00110                  FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X,
00111                  0, 0, 0, 0,  4, 4, 3, 3);
00112     initial->setFocus();
00113     setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
00114 }
00115 
00116 
00117 GUIDialog_EditViewport::~GUIDialog_EditViewport() {}
00118 
00119 
00120 long
00121 GUIDialog_EditViewport::onCmdOk(FXObject*, FXSelector, void*) {
00122     myParent->setViewport((SUMOReal) myZoom->getValue(), (SUMOReal) myXOff->getValue(), (SUMOReal) myYOff->getValue());
00123     hide();
00124     return 1;
00125 }
00126 
00127 
00128 long
00129 GUIDialog_EditViewport::onCmdCancel(FXObject*, FXSelector, void*) {
00130     myParent->setViewport(myOldZoom, myOldXOff, myOldYOff);
00131     hide();
00132     return 1;
00133 }
00134 
00135 
00136 long
00137 GUIDialog_EditViewport::onCmdChanged(FXObject*, FXSelector, void*) {
00138     myParent->setViewport((SUMOReal) myZoom->getValue(), (SUMOReal) myXOff->getValue(), (SUMOReal) myYOff->getValue());
00139     return 1;
00140 }
00141 
00142 
00143 long
00144 GUIDialog_EditViewport::onCmdLoad(FXObject*, FXSelector, void* /*data*/) {
00145     FXFileDialog opendialog(this, "Load Viewport");
00146     opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
00147     opendialog.setSelectMode(SELECTFILE_ANY);
00148     opendialog.setPatternList("*.xml");
00149     if (gCurrentFolder.length() != 0) {
00150         opendialog.setDirectory(gCurrentFolder);
00151     }
00152     if (opendialog.execute()) {
00153         gCurrentFolder = opendialog.getDirectory();
00154         GUISettingsHandler handler(opendialog.getFilename().text());
00155         SUMOReal zoom, xoff, yoff;
00156         handler.setViewport(zoom, xoff, yoff);
00157         if (zoom > 0) {
00158             setValues(zoom, xoff, yoff);
00159             myParent->setViewport(zoom, xoff, yoff);
00160         }
00161     }
00162     return 1;
00163 }
00164 
00165 
00166 long
00167 GUIDialog_EditViewport::onCmdSave(FXObject*, FXSelector, void* /*data*/) {
00168     FXFileDialog opendialog(this, "Save Viewport");
00169     opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
00170     opendialog.setSelectMode(SELECTFILE_ANY);
00171     opendialog.setPatternList("*.xml");
00172     if (gCurrentFolder.length() != 0) {
00173         opendialog.setDirectory(gCurrentFolder);
00174     }
00175     if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
00176         return 1;
00177     }
00178     try {
00179         OutputDevice& dev = OutputDevice::getDevice(opendialog.getFilename().text());
00180         dev << "<viewsettings>\n";
00181         dev << "    <viewport zoom=\"" << myZoom->getValue() << "\" x=\"" << myXOff->getValue() << "\" y=\"" << myYOff->getValue() << "\"/>\n";
00182         dev << "</viewsettings>\n";
00183         dev.close();
00184     } catch (IOError& e) {
00185         FXMessageBox::error(this, MBOX_OK, "Storing failed!", "%s", e.what());
00186     }
00187     return 1;
00188 }
00189 
00190 
00191 void
00192 GUIDialog_EditViewport::setValues(SUMOReal zoom, SUMOReal xoff, SUMOReal yoff) {
00193     myZoom->setValue(zoom);
00194     myXOff->setValue(xoff);
00195     myYOff->setValue(yoff);
00196 }
00197 
00198 
00199 void
00200 GUIDialog_EditViewport::setOldValues(SUMOReal zoom, SUMOReal xoff, SUMOReal yoff) {
00201     myZoom->setValue(zoom);
00202     myXOff->setValue(xoff);
00203     myYOff->setValue(yoff);
00204     myOldZoom = zoom;
00205     myOldXOff = xoff;
00206     myOldYOff = yoff;
00207 }
00208 
00209 
00210 bool
00211 GUIDialog_EditViewport::haveGrabbed() const {
00212     return myZoom->getDial().grabbed() || myXOff->getDial().grabbed() || myYOff->getDial().grabbed();
00213 }
00214 
00215 
00216 /****************************************************************************/
00217 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines