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