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