SUMO - Simulation of Urban MObility

GUIDialog_GLChosenEditor.cpp

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