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

Generated on Wed May 5 00:06:29 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6