|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // Class for the window that allows to choose a street, junction or vehicle 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 00023 00024 // =========================================================================== 00025 // included modules 00026 // =========================================================================== 00027 #ifdef _MSC_VER 00028 #include <windows_config.h> 00029 #else 00030 #include <config.h> 00031 #endif 00032 00033 #include <string> 00034 #include <vector> 00035 #include <fxkeys.h> 00036 #include <utils/gui/windows/GUIAppEnum.h> 00037 #include <utils/gui/windows/GUIGlChildWindow.h> 00038 #include <utils/gui/windows/GUIMainWindow.h> 00039 #include <utils/gui/windows/GUIAppGlobals.h> 00040 #include <utils/gui/globjects/GUIGlObject.h> 00041 #include <utils/gui/globjects/GUIGlObjectStorage.h> 00042 #include <utils/gui/images/GUIIconSubSys.h> 00043 #include <utils/gui/div/GUIGlobalSelection.h> 00044 #include <utils/gui/globjects/GUIGlObject_AbstractAdd.h> 00045 #include "GUIDialog_GLObjChooser.h" 00046 00047 #ifdef _WIN32 00048 #include <windows.h> 00049 #endif 00050 00051 #include <GL/gl.h> 00052 00053 #ifdef CHECK_MEMORY_LEAKS 00054 #include <foreign/nvwa/debug_new.h> 00055 #endif // CHECK_MEMORY_LEAKS 00056 00057 00058 // =========================================================================== 00059 // FOX callback mapping 00060 // =========================================================================== 00061 FXDEFMAP(GUIDialog_GLObjChooser) GUIDialog_GLObjChooserMap[] = { 00062 FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_CENTER, GUIDialog_GLObjChooser::onCmdCenter), 00063 FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GUIDialog_GLObjChooser::onCmdClose), 00064 FXMAPFUNC(SEL_CHANGED, MID_CHOOSER_TEXT, GUIDialog_GLObjChooser::onChgText), 00065 FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_TEXT, GUIDialog_GLObjChooser::onCmdText), 00066 FXMAPFUNC(SEL_KEYPRESS, MID_CHOOSER_LIST, GUIDialog_GLObjChooser::onListKeyPress), 00067 }; 00068 00069 FXIMPLEMENT(GUIDialog_GLObjChooser, FXMainWindow, GUIDialog_GLObjChooserMap, ARRAYNUMBER(GUIDialog_GLObjChooserMap)) 00070 00071 00072 // =========================================================================== 00073 // method definitions 00074 // =========================================================================== 00075 GUIDialog_GLObjChooser::GUIDialog_GLObjChooser( 00076 GUIGlChildWindow* parent, 00077 FXIcon* icon, 00078 const FXString& title, 00079 GUIGlObjectType type, 00080 const std::vector<GUIGlID> &ids, 00081 GUIGlObjectStorage& glStorage): 00082 FXMainWindow(parent->getApp(), title, icon, NULL, DECOR_ALL, 20, 20, 300, 300), 00083 myObjectType(type), 00084 myParent(parent) { 00085 FXHorizontalFrame* hbox = new FXHorizontalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0); 00086 // build the list 00087 FXVerticalFrame* layout1 = new FXVerticalFrame(hbox, LAYOUT_FILL_X | LAYOUT_FILL_Y | LAYOUT_TOP, 0, 0, 0, 0, 4, 4, 4, 4); 00088 myTextEntry = new FXTextField(layout1, 0, this, MID_CHOOSER_TEXT, LAYOUT_FILL_X | FRAME_THICK | FRAME_SUNKEN); 00089 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); 00090 myList = new FXList(style1, this, MID_CHOOSER_LIST, LAYOUT_FILL_X | LAYOUT_FILL_Y | LIST_SINGLESELECT | FRAME_SUNKEN | FRAME_THICK); 00091 for (std::vector<GUIGlID>::const_iterator i = ids.begin(); i != ids.end(); ++i) { 00092 GUIGlObject* o = glStorage.getObjectBlocking(*i); 00093 if (o == 0) { 00094 continue; 00095 } 00096 const std::string& name = o->getMicrosimID(); 00097 bool selected = myParent->isSelected(o); 00098 FXIcon* icon = selected ? GUIIconSubSys::getIcon(ICON_FLAG) : 0; 00099 myIDs.insert(o->getGlID()); 00100 myList->appendItem(name.c_str(), icon, (void*) & (*myIDs.find(o->getGlID()))); 00101 glStorage.unblockObject(*i); 00102 } 00103 // build the buttons 00104 FXVerticalFrame* layout = new FXVerticalFrame(hbox, LAYOUT_TOP, 0, 0, 0, 0, 4, 4, 4, 4); 00105 new FXButton(layout, "Center\t\t", GUIIconSubSys::getIcon(ICON_RECENTERVIEW), 00106 this, MID_CHOOSER_CENTER, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED, 00107 0, 0, 0, 0, 4, 4, 4, 4); 00108 new FXHorizontalSeparator(layout, SEPARATOR_GROOVE | LAYOUT_FILL_X); 00109 new FXButton(layout, "Close\t\t", GUIIconSubSys::getIcon(ICON_NO), 00110 this, MID_CANCEL, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED, 00111 0, 0, 0, 0, 4, 4, 4, 4); 00112 00113 myParent->getParent()->addChild(this); 00114 myTextEntry->setFocus(); 00115 } 00116 00117 00118 GUIDialog_GLObjChooser::~GUIDialog_GLObjChooser() { 00119 myParent->getParent()->removeChild(this); 00120 } 00121 00122 00123 long 00124 GUIDialog_GLObjChooser::onCmdCenter(FXObject*, FXSelector, void*) { 00125 int selected = myList->getCurrentItem(); 00126 if (selected >= 0) { 00127 myParent->setView(*static_cast<GUIGlID*>(myList->getItemData(selected))); 00128 } 00129 return 1; 00130 } 00131 00132 00133 long 00134 GUIDialog_GLObjChooser::onCmdClose(FXObject*, FXSelector, void*) { 00135 close(true); 00136 return 1; 00137 } 00138 00139 00140 long 00141 GUIDialog_GLObjChooser::onChgText(FXObject*, FXSelector, void*) { 00142 int id = myList->findItem(myTextEntry->getText(), -1, SEARCH_PREFIX); 00143 if (id < 0) { 00144 return 1; 00145 } 00146 myList->deselectItem(myList->getCurrentItem()); 00147 myList->makeItemVisible(id); 00148 myList->selectItem(id); 00149 myList->setCurrentItem(id, true); 00150 return 1; 00151 } 00152 00153 00154 long 00155 GUIDialog_GLObjChooser::onCmdText(FXObject*, FXSelector, void*) { 00156 int current = myList->getCurrentItem(); 00157 if (current >= 0 && myList->isItemSelected(current)) { 00158 myParent->setView(*static_cast<GUIGlID*>(myList->getItemData(current))); 00159 } 00160 return 1; 00161 } 00162 00163 00164 00165 long 00166 GUIDialog_GLObjChooser::onListKeyPress(FXObject*, FXSelector, void* ptr) { 00167 FXEvent* event = (FXEvent*)ptr; 00168 switch (event->code) { 00169 case KEY_Return: 00170 onCmdText(0, 0, 0); 00171 break; 00172 default: 00173 break; 00174 } 00175 return 1; 00176 } 00177 00178 00179 00180 /****************************************************************************/ 00181