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/globjects/GUIGlObject.h> 00040 #include <utils/gui/globjects/GUIGlObjectStorage.h> 00041 #include <utils/gui/images/GUIIconSubSys.h> 00042 #include <utils/gui/div/GUIGlobalSelection.h> 00043 #include <utils/gui/globjects/GUIGlObject_AbstractAdd.h> 00044 #include "GUIDialog_GLObjChooser.h" 00045 00046 #ifdef _WIN32 00047 #include <windows.h> 00048 #endif 00049 00050 #include <GL/gl.h> 00051 00052 #ifdef CHECK_MEMORY_LEAKS 00053 #include <foreign/nvwa/debug_new.h> 00054 #endif // CHECK_MEMORY_LEAKS 00055 00056 00057 // =========================================================================== 00058 // FOX callback mapping 00059 // =========================================================================== 00060 FXDEFMAP(GUIDialog_GLObjChooser) GUIDialog_GLObjChooserMap[] = { 00061 FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_CENTER, GUIDialog_GLObjChooser::onCmdCenter), 00062 FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GUIDialog_GLObjChooser::onCmdClose), 00063 FXMAPFUNC(SEL_CHANGED, MID_CHOOSER_TEXT, GUIDialog_GLObjChooser::onChgText), 00064 FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_TEXT, GUIDialog_GLObjChooser::onCmdText), 00065 FXMAPFUNC(SEL_KEYPRESS, MID_CHOOSER_LIST, GUIDialog_GLObjChooser::onListKeyPress), 00066 FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_FILTER, GUIDialog_GLObjChooser::onCmdFilter), 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, "Hide Unselected\t\t", GUIIconSubSys::getIcon(ICON_FLAG), 00110 this, MID_CHOOSER_FILTER, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED, 00111 0, 0, 0, 0, 4, 4, 4, 4); 00112 new FXHorizontalSeparator(layout, SEPARATOR_GROOVE | LAYOUT_FILL_X); 00113 new FXButton(layout, "Close\t\t", GUIIconSubSys::getIcon(ICON_NO), 00114 this, MID_CANCEL, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED, 00115 0, 0, 0, 0, 4, 4, 4, 4); 00116 00117 myParent->getParent()->addChild(this); 00118 myTextEntry->setFocus(); 00119 } 00120 00121 00122 GUIDialog_GLObjChooser::~GUIDialog_GLObjChooser() { 00123 myParent->getParent()->removeChild(this); 00124 } 00125 00126 00127 long 00128 GUIDialog_GLObjChooser::onCmdCenter(FXObject*, FXSelector, void*) { 00129 int selected = myList->getCurrentItem(); 00130 if (selected >= 0) { 00131 myParent->setView(*static_cast<GUIGlID*>(myList->getItemData(selected))); 00132 } 00133 return 1; 00134 } 00135 00136 00137 long 00138 GUIDialog_GLObjChooser::onCmdClose(FXObject*, FXSelector, void*) { 00139 close(true); 00140 return 1; 00141 } 00142 00143 00144 long 00145 GUIDialog_GLObjChooser::onChgText(FXObject*, FXSelector, void*) { 00146 int id = myList->findItem(myTextEntry->getText(), -1, SEARCH_PREFIX); 00147 if (id < 0) { 00148 return 1; 00149 } 00150 myList->deselectItem(myList->getCurrentItem()); 00151 myList->makeItemVisible(id); 00152 myList->selectItem(id); 00153 myList->setCurrentItem(id, true); 00154 return 1; 00155 } 00156 00157 00158 long 00159 GUIDialog_GLObjChooser::onCmdText(FXObject*, FXSelector, void*) { 00160 int current = myList->getCurrentItem(); 00161 if (current >= 0 && myList->isItemSelected(current)) { 00162 myParent->setView(*static_cast<GUIGlID*>(myList->getItemData(current))); 00163 } 00164 return 1; 00165 } 00166 00167 00168 00169 long 00170 GUIDialog_GLObjChooser::onListKeyPress(FXObject*, FXSelector, void* ptr) { 00171 FXEvent* event = (FXEvent*)ptr; 00172 switch (event->code) { 00173 case KEY_Return: 00174 onCmdText(0, 0, 0); 00175 break; 00176 default: 00177 break; 00178 } 00179 return 1; 00180 } 00181 00182 00183 long 00184 GUIDialog_GLObjChooser::onCmdFilter(FXObject*, FXSelector, void*) { 00185 FXIcon* flag = GUIIconSubSys::getIcon(ICON_FLAG); 00186 std::vector<GUIGlID> selectedGlIDs; 00187 std::vector<FXString> selectedMicrosimIDs; 00188 const int numItems = myList->getNumItems(); 00189 for (int i = 0; i < numItems; i++) { 00190 const GUIGlID glID = *static_cast<GUIGlID*>(myList->getItemData(i)); 00191 if (myList->getItemIcon(i) == flag) { 00192 selectedGlIDs.push_back(glID); 00193 selectedMicrosimIDs.push_back(myList->getItemText(i)); 00194 } 00195 } 00196 myList->clearItems(); 00197 const int numSelected = selectedGlIDs.size(); 00198 for (int i = 0; i < numSelected; i++) { 00199 myList->appendItem(selectedMicrosimIDs[i], flag, (void*) & (*myIDs.find(selectedGlIDs[i]))); 00200 } 00201 myList->update(); 00202 return 1; 00203 } 00204 00205 00206 /****************************************************************************/ 00207