|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // Editor for the list of chosen objects 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 <iostream> 00036 #include <fstream> 00037 #include <utils/gui/windows/GUIAppEnum.h> 00038 #include <utils/gui/globjects/GUIGlObject.h> 00039 #include <utils/foxtools/MFXUtils.h> 00040 #include "GUIDialog_GLChosenEditor.h" 00041 #include <utils/gui/div/GUIGlobalSelection.h> 00042 #include <utils/gui/globjects/GUIGlObjectStorage.h> 00043 #include <utils/gui/div/GUIIOGlobals.h> 00044 #include <utils/gui/windows/GUIAppGlobals.h> 00045 #include <utils/gui/windows/GUIMainWindow.h> 00046 #include <utils/gui/images/GUIIconSubSys.h> 00047 00048 #ifdef _WIN32 00049 #include <windows.h> 00050 #endif 00051 00052 #include <GL/gl.h> 00053 00054 #ifdef CHECK_MEMORY_LEAKS 00055 #include <foreign/nvwa/debug_new.h> 00056 #endif // CHECK_MEMORY_LEAKS 00057 00058 00059 // =========================================================================== 00060 // FOX callback mapping 00061 // =========================================================================== 00062 FXDEFMAP(GUIDialog_GLChosenEditor) GUIDialog_GLChosenEditorMap[] = { 00063 FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_LOAD, GUIDialog_GLChosenEditor::onCmdLoad), 00064 FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_SAVE, GUIDialog_GLChosenEditor::onCmdSave), 00065 FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_DESELECT, GUIDialog_GLChosenEditor::onCmdDeselect), 00066 FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_CLEAR, GUIDialog_GLChosenEditor::onCmdClear), 00067 FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GUIDialog_GLChosenEditor::onCmdClose), 00068 }; 00069 00070 FXIMPLEMENT(GUIDialog_GLChosenEditor, FXMainWindow, GUIDialog_GLChosenEditorMap, ARRAYNUMBER(GUIDialog_GLChosenEditorMap)) 00071 00072 00073 // =========================================================================== 00074 // method definitions 00075 // =========================================================================== 00076 GUIDialog_GLChosenEditor::GUIDialog_GLChosenEditor(GUIMainWindow* parent, 00077 GUISelectedStorage* str) 00078 : FXMainWindow(parent->getApp(), "List of Selected Items", NULL, NULL, DECOR_ALL, 20, 20, 300, 300), 00079 myParent(parent), myStorage(str) { 00080 myStorage->add2Update(this); 00081 FXHorizontalFrame* hbox = 00082 new FXHorizontalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 00083 0, 0, 0, 0); 00084 // build the list 00085 myList = new FXList(hbox, 0, 0, 00086 LAYOUT_FILL_X | LAYOUT_FILL_Y | LIST_MULTIPLESELECT); 00087 rebuildList(); 00088 // build the layout 00089 FXVerticalFrame* layout = new FXVerticalFrame(hbox, LAYOUT_TOP, 0, 0, 0, 0, 00090 4, 4, 4, 4); 00091 // "Load" 00092 new FXButton(layout, "Load\t\t", 0, this, MID_CHOOSEN_LOAD, 00093 ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED, 00094 0, 0, 0, 0, 4, 4, 3, 3); 00095 // "Save" 00096 new FXButton(layout, "Save\t\t", 0, this, MID_CHOOSEN_SAVE, 00097 ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED, 00098 0, 0, 0, 0, 4, 4, 3, 3); 00099 00100 new FXHorizontalSeparator(layout, SEPARATOR_GROOVE | LAYOUT_FILL_X); 00101 00102 // "Deselect Chosen" 00103 new FXButton(layout, "Deselect Chosen\t\t", 0, this, MID_CHOOSEN_DESELECT, 00104 ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED, 00105 0, 0, 0, 0, 4, 4, 3, 3); 00106 // "Clear List" 00107 new FXButton(layout, "Clear\t\t", 0, this, MID_CHOOSEN_CLEAR, 00108 ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED, 00109 0, 0, 0, 0, 4, 4, 3, 3); 00110 00111 new FXHorizontalSeparator(layout, SEPARATOR_GROOVE | LAYOUT_FILL_X); 00112 00113 // "Close" 00114 new FXButton(layout, "Close\t\t", 0, this, MID_CANCEL, 00115 ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED, 00116 0, 0, 0, 0, 4, 4, 3, 3); 00117 setIcon(GUIIconSubSys::getIcon(ICON_APP_SELECTOR)); 00118 myParent->addChild(this); 00119 } 00120 00121 00122 GUIDialog_GLChosenEditor::~GUIDialog_GLChosenEditor() { 00123 myStorage->remove2Update(); 00124 myParent->removeChild(this); 00125 } 00126 00127 00128 void 00129 GUIDialog_GLChosenEditor::rebuildList() { 00130 myList->clearItems(); 00131 const std::set<GUIGlID> &chosen = gSelected.getSelected(); 00132 for (std::set<GUIGlID>::const_iterator i = chosen.begin(); i != chosen.end(); ++i) { 00133 GUIGlObject* object = GUIGlObjectStorage::gIDStorage.getObjectBlocking(*i); 00134 if (object != 0) { 00135 std::string name = object->getFullName(); 00136 FXListItem* item = myList->getItem(myList->appendItem(name.c_str())); 00137 item->setData(object); 00138 GUIGlObjectStorage::gIDStorage.unblockObject(*i); 00139 } 00140 } 00141 } 00142 00143 00144 void 00145 GUIDialog_GLChosenEditor::selectionUpdated() { 00146 rebuildList(); 00147 FXMainWindow::update(); 00148 } 00149 00150 00151 long 00152 GUIDialog_GLChosenEditor::onCmdLoad(FXObject*, FXSelector, void*) { 00153 // get the new file name 00154 FXFileDialog opendialog(this, "Open List of Selected Items"); 00155 opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY)); 00156 opendialog.setSelectMode(SELECTFILE_EXISTING); 00157 opendialog.setPatternList("*.txt"); 00158 if (gCurrentFolder.length() != 0) { 00159 opendialog.setDirectory(gCurrentFolder); 00160 } 00161 if (opendialog.execute()) { 00162 gCurrentFolder = opendialog.getDirectory(); 00163 std::string file = opendialog.getFilename().text(); 00164 std::string msg = gSelected.load(file); 00165 if (msg != "") { 00166 FXMessageBox::error(this, MBOX_OK, "Errors while loading Selection", msg.c_str()); 00167 } 00168 rebuildList(); 00169 } 00170 return 1; 00171 } 00172 00173 00174 long 00175 GUIDialog_GLChosenEditor::onCmdSave(FXObject*, FXSelector, void*) { 00176 FXString file = MFXUtils::getFilename2Write(this, "Save List of selected Items", ".txt", GUIIconSubSys::getIcon(ICON_EMPTY), gCurrentFolder); 00177 if (file == "") { 00178 return 1; 00179 } 00180 try { 00181 gSelected.save(file.text()); 00182 } catch (IOError& e) { 00183 FXMessageBox::error(this, MBOX_OK, "Storing failed!", e.what()); 00184 } 00185 return 1; 00186 } 00187 00188 00189 long 00190 GUIDialog_GLChosenEditor::onCmdDeselect(FXObject*, FXSelector, void*) { 00191 FXint no = myList->getNumItems(); 00192 FXint i; 00193 std::vector<GUIGlID> selected; 00194 for (i = 0; i < no; ++i) { 00195 if (myList->getItem(i)->isSelected()) { 00196 selected.push_back(static_cast<GUIGlObject*>(myList->getItem(i)->getData())->getGlID()); 00197 } 00198 } 00199 // remove items from list 00200 for (i = 0; i < (FXint) selected.size(); ++i) { 00201 gSelected.deselect(selected[i]); 00202 } 00203 // rebuild list 00204 rebuildList(); 00205 myParent->updateChildren(); 00206 return 1; 00207 } 00208 00209 00210 00211 long 00212 GUIDialog_GLChosenEditor::onCmdClear(FXObject*, FXSelector, void*) { 00213 myList->clearItems(); 00214 gSelected.clear(); 00215 myParent->updateChildren(); 00216 return 1; 00217 } 00218 00219 00220 00221 long 00222 GUIDialog_GLChosenEditor::onCmdClose(FXObject*, FXSelector, void*) { 00223 close(true); 00224 return 1; 00225 } 00226 00227 00228 00229 /****************************************************************************/ 00230