SUMO - Simulation of Urban MObility

GUIDialog_GLObjChooser.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Class for the window that allows to choose a street, junction or vehicle
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 <string>
00031 #include <vector>
00032 #include <fxkeys.h>
00033 #include <utils/gui/windows/GUIAppEnum.h>
00034 #include <utils/gui/windows/GUIGlChildWindow.h>
00035 #include <utils/gui/windows/GUIMainWindow.h>
00036 #include <utils/gui/windows/GUIAppGlobals.h>
00037 #include <utils/gui/globjects/GUIGlObject.h>
00038 #include <utils/gui/globjects/GUIGlObjectStorage.h>
00039 #include <utils/gui/images/GUIIconSubSys.h>
00040 #include <utils/gui/div/GUIGlobalSelection.h>
00041 #include <utils/gui/globjects/GUIGlObject_AbstractAdd.h>
00042 #include "GUIDialog_GLObjChooser.h"
00043 
00044 #ifdef _WIN32
00045 #include <windows.h>
00046 #endif
00047 
00048 #include <GL/gl.h>
00049 
00050 #ifdef CHECK_MEMORY_LEAKS
00051 #include <foreign/nvwa/debug_new.h>
00052 #endif // CHECK_MEMORY_LEAKS
00053 
00054 
00055 // ===========================================================================
00056 // FOX callback mapping
00057 // ===========================================================================
00058 FXDEFMAP(GUIDialog_GLObjChooser) GUIDialog_GLObjChooserMap[]= {
00059     FXMAPFUNC(SEL_COMMAND,  MID_CHOOSER_CENTER, GUIDialog_GLObjChooser::onCmdCenter),
00060     FXMAPFUNC(SEL_COMMAND,  MID_CANCEL,         GUIDialog_GLObjChooser::onCmdClose),
00061     FXMAPFUNC(SEL_CHANGED,  MID_CHOOSER_TEXT,   GUIDialog_GLObjChooser::onChgText),
00062     FXMAPFUNC(SEL_COMMAND,  MID_CHOOSER_TEXT,   GUIDialog_GLObjChooser::onCmdText),
00063     FXMAPFUNC(SEL_KEYPRESS, MID_CHOOSER_LIST,   GUIDialog_GLObjChooser::onListKeyPress),
00064 };
00065 
00066 FXIMPLEMENT(GUIDialog_GLObjChooser, FXMainWindow, GUIDialog_GLObjChooserMap, ARRAYNUMBER(GUIDialog_GLObjChooserMap))
00067 
00068 
00069 // ===========================================================================
00070 // method definitions
00071 // ===========================================================================
00072 GUIDialog_GLObjChooser::GUIDialog_GLObjChooser(
00073     GUIGlChildWindow* parent,
00074     FXIcon* icon,
00075     const FXString& title,
00076     GUIGlObjectType type,
00077     const std::vector<GUIGlID> &ids,
00078     GUIGlObjectStorage& glStorage):
00079     FXMainWindow(parent->getApp(), title, icon, NULL, DECOR_ALL, 20,20,300, 300),
00080     myObjectType(type),
00081     myParent(parent) {
00082     FXHorizontalFrame* hbox = new FXHorizontalFrame(this, LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,0,0, 0,0,0,0);
00083     // build the list
00084     FXVerticalFrame* layout1 = new FXVerticalFrame(hbox, LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP, 0,0,0,0, 4,4,4,4);
00085     myTextEntry = new FXTextField(layout1, 0, this, MID_CHOOSER_TEXT, LAYOUT_FILL_X|FRAME_THICK|FRAME_SUNKEN);
00086     FXVerticalFrame* style1 = new FXVerticalFrame(layout1, LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|FRAME_THICK|FRAME_SUNKEN, 0,0,0,0, 0,0,0,0);
00087     myList = new FXList(style1, this, MID_CHOOSER_LIST, LAYOUT_FILL_X|LAYOUT_FILL_Y|LIST_SINGLESELECT|FRAME_SUNKEN|FRAME_THICK);
00088     for (std::vector<GUIGlID>::const_iterator i=ids.begin(); i!=ids.end(); ++i) {
00089         GUIGlObject* o = glStorage.getObjectBlocking(*i);
00090         if (o==0) {
00091             continue;
00092         }
00093         const std::string& name = o->getMicrosimID();
00094         bool selected = myParent->isSelected(o);
00095         FXIcon* icon = selected ? GUIIconSubSys::getIcon(ICON_FLAG) : 0;
00096         myIDs.insert(o->getGlID());
00097         myList->appendItem(name.c_str(), icon, (void*) &(*myIDs.find(o->getGlID())));
00098         glStorage.unblockObject(*i);
00099     }
00100     // build the buttons
00101     FXVerticalFrame* layout = new FXVerticalFrame(hbox, LAYOUT_TOP, 0,0,0,0, 4,4,4,4);
00102     new FXButton(layout, "Center\t\t", GUIIconSubSys::getIcon(ICON_RECENTERVIEW),
00103                  this, MID_CHOOSER_CENTER, ICON_BEFORE_TEXT|LAYOUT_FILL_X|FRAME_THICK|FRAME_RAISED,
00104                  0, 0, 0, 0, 4, 4, 4, 4);
00105     new FXHorizontalSeparator(layout,SEPARATOR_GROOVE|LAYOUT_FILL_X);
00106     new FXButton(layout, "Close\t\t", GUIIconSubSys::getIcon(ICON_NO),
00107                  this, MID_CANCEL, ICON_BEFORE_TEXT|LAYOUT_FILL_X|FRAME_THICK|FRAME_RAISED,
00108                  0, 0, 0, 0, 4, 4, 4, 4);
00109 
00110     myParent->getParent()->addChild(this);
00111     myTextEntry->setFocus();
00112 }
00113 
00114 
00115 GUIDialog_GLObjChooser::~GUIDialog_GLObjChooser() throw() {
00116     myParent->getParent()->removeChild(this);
00117 }
00118 
00119 
00120 long
00121 GUIDialog_GLObjChooser::onCmdCenter(FXObject*,FXSelector,void*) {
00122     int selected = myList->getCurrentItem();
00123     if (selected>=0) {
00124         myParent->setView(*static_cast<GUIGlID*>(myList->getItemData(selected)));
00125     }
00126     return 1;
00127 }
00128 
00129 
00130 long
00131 GUIDialog_GLObjChooser::onCmdClose(FXObject*,FXSelector,void*) {
00132     close(true);
00133     return 1;
00134 }
00135 
00136 
00137 long
00138 GUIDialog_GLObjChooser::onChgText(FXObject*,FXSelector,void*) {
00139     int id = myList->findItem(myTextEntry->getText(), -1, SEARCH_PREFIX);
00140     if (id<0) {
00141         return 1;
00142     }
00143     myList->deselectItem(myList->getCurrentItem());
00144     myList->makeItemVisible(id);
00145     myList->selectItem(id);
00146     myList->setCurrentItem(id, true);
00147     return 1;
00148 }
00149 
00150 
00151 long
00152 GUIDialog_GLObjChooser::onCmdText(FXObject*,FXSelector,void*) {
00153     int current = myList->getCurrentItem();
00154     if (current>=0 && myList->isItemSelected(current)) {
00155         myParent->setView(*static_cast<GUIGlID*>(myList->getItemData(current)));
00156     }
00157     return 1;
00158 }
00159 
00160 
00161 
00162 long
00163 GUIDialog_GLObjChooser::onListKeyPress(FXObject*,FXSelector,void* ptr) {
00164     FXEvent* event=(FXEvent*)ptr;
00165     switch (event->code) {
00166     case KEY_Return:
00167         onCmdText(0,0,0);
00168         break;
00169     default:
00170         break;
00171     }
00172     return 1;
00173 }
00174 
00175 
00176 
00177 /****************************************************************************/
00178 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines