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