GUIDialog_GLObjChooser.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Class for the window that allows to choose a street, junction or vehicle
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 <fxkeys.h>
00033 #include <gui/GUISUMOViewParent.h>
00034 #include <utils/gui/windows/GUIAppEnum.h>
00035 #include <gui/GUIGlobals.h>
00036 #include <utils/gui/globjects/GUIGlObject.h>
00037 #include <utils/gui/globjects/GUIGlObjectStorage.h>
00038 #include <utils/gui/images/GUIIconSubSys.h>
00039 #include <utils/gui/windows/GUIMainWindow.h>
00040 #include <microsim/MSJunction.h>
00041 #include <guisim/GUIVehicle.h>
00042 #include <guisim/GUIEdge.h>
00043 #include <guisim/GUINet.h>
00044 #include <guisim/GUIVehicleControl.h>
00045 #include "GUIDialog_GLObjChooser.h"
00046 #include <utils/gui/div/GUIGlobalSelection.h>
00047 #include <utils/gui/globjects/GUIGlObject_AbstractAdd.h>
00048 #include <utils/gui/windows/GUIAppGlobals.h>
00049 
00050 #ifdef _WIN32
00051 #include <windows.h>
00052 #endif
00053 
00054 #include <GL/gl.h>
00055 
00056 #ifdef CHECK_MEMORY_LEAKS
00057 #include <foreign/nvwa/debug_new.h>
00058 #endif // CHECK_MEMORY_LEAKS
00059 
00060 
00061 // ===========================================================================
00062 // FOX callback mapping
00063 // ===========================================================================
00064 FXDEFMAP(GUIDialog_GLObjChooser) GUIDialog_GLObjChooserMap[]= {
00065     FXMAPFUNC(SEL_COMMAND,  MID_CHOOSER_CENTER, GUIDialog_GLObjChooser::onCmdCenter),
00066     FXMAPFUNC(SEL_COMMAND,  MID_CANCEL,         GUIDialog_GLObjChooser::onCmdClose),
00067     FXMAPFUNC(SEL_CHANGED,  MID_CHOOSER_TEXT,   GUIDialog_GLObjChooser::onChgText),
00068     FXMAPFUNC(SEL_COMMAND,  MID_CHOOSER_TEXT,   GUIDialog_GLObjChooser::onCmdText),
00069     FXMAPFUNC(SEL_KEYPRESS,  MID_CHOOSER_LIST,   GUIDialog_GLObjChooser::onListKeyPress),
00070 };
00071 
00072 FXIMPLEMENT(GUIDialog_GLObjChooser, FXMainWindow, GUIDialog_GLObjChooserMap, ARRAYNUMBER(GUIDialog_GLObjChooserMap))
00073 
00074 
00075 // ===========================================================================
00076 // method definitions
00077 // ===========================================================================
00078 GUIDialog_GLObjChooser::GUIDialog_GLObjChooser(GUISUMOViewParent *parent,
00079         FXIcon *icon, const FXString &title,
00080         GUIGlObjectType type,
00081         GUIGlObjectStorage &glStorage)
00082         : FXMainWindow(parent->getApp(), title, icon, NULL, DECOR_ALL, 20,20,300, 300),
00083         myObjectType(type), myParent(parent), mySelected(0) {
00084     FXHorizontalFrame *hbox = new FXHorizontalFrame(this, LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,0,0, 0,0,0,0);
00085     // build the list
00086     FXVerticalFrame *layout1 = new FXVerticalFrame(hbox, LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP, 0,0,0,0, 4,4,4,4);
00087     myTextEntry = new FXTextField(layout1, 0, this, MID_CHOOSER_TEXT, LAYOUT_FILL_X|FRAME_THICK|FRAME_SUNKEN);
00088     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);
00089     myList = new FXList(style1, this, MID_CHOOSER_LIST, LAYOUT_FILL_X|LAYOUT_FILL_Y|LIST_SINGLESELECT|FRAME_SUNKEN|FRAME_THICK);
00090     // get the ids
00091     std::vector<GLuint> ids;
00092     switch (type) {
00093     case GLO_JUNCTION:
00094         ids = static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs();
00095         break;
00096     case GLO_EDGE:
00097         ids = GUIEdge::getIDs();
00098         break;
00099     case GLO_VEHICLE:
00100         static_cast<GUIVehicleControl&>(MSNet::getInstance()->getVehicleControl()).insertVehicleIDs(ids);
00101         break;
00102     case GLO_TLLOGIC:
00103         ids = static_cast<GUINet*>(GUINet::getInstance())->getTLSIDs();
00104         break;
00105     case GLO_ADDITIONAL:
00106         ids = GUIGlObject_AbstractAdd::getIDList();
00107         break;
00108     case GLO_SHAPE:
00109         ids = static_cast<GUINet*>(GUINet::getInstance())->getShapeIDs();
00110         break;
00111     default:
00112         break;
00113     }
00114     for (std::vector<GLuint>::iterator i=ids.begin(); i!=ids.end(); ++i) {
00115         GUIGlObject *o = glStorage.getObjectBlocking(*i);
00116         if (o==0) {
00117             continue;
00118         }
00119         const std::string &name = o->getMicrosimID();
00120         bool selected = false;
00121         if (type==GLO_EDGE) {
00122             size_t noLanes = static_cast<GUIEdge*>(o)->getLanes().size();
00123             for (size_t j=0; j<noLanes; ++j) {
00124                 const GUILaneWrapper &l = static_cast<GUIEdge*>(o)->getLaneGeometry(j);
00125                 if (gSelected.isSelected(GLO_LANE, l.getGlID())) {
00126                     selected = true;
00127                 }
00128             }
00129         } else {
00130             selected = gSelected.isSelected(type, *i);
00131         }
00132         if (selected) {
00133             myList->appendItem(name.c_str(), GUIIconSubSys::getIcon(ICON_FLAG), (void*) o);
00134         } else {
00135             myList->appendItem(name.c_str(), 0, (void*) o);
00136         }
00137         glStorage.unblockObject(*i);
00138     }
00139     // build the buttons
00140     FXVerticalFrame *layout = new FXVerticalFrame(hbox, LAYOUT_TOP, 0,0,0,0, 4,4,4,4);
00141     new FXButton(layout, "Center\t\t", GUIIconSubSys::getIcon(ICON_RECENTERVIEW),
00142                  this, MID_CHOOSER_CENTER, ICON_BEFORE_TEXT|LAYOUT_FILL_X|FRAME_THICK|FRAME_RAISED,
00143                  0, 0, 0, 0, 4, 4, 4, 4);
00144     new FXHorizontalSeparator(layout,SEPARATOR_GROOVE|LAYOUT_FILL_X);
00145     new FXButton(layout, "Close\t\t", GUIIconSubSys::getIcon(ICON_NO),
00146                  this, MID_CANCEL, ICON_BEFORE_TEXT|LAYOUT_FILL_X|FRAME_THICK|FRAME_RAISED,
00147                  0, 0, 0, 0, 4, 4, 4, 4);
00148 
00149     myParent->getParent()->addChild(this);
00150     myTextEntry->setFocus();
00151 }
00152 
00153 
00154 GUIDialog_GLObjChooser::~GUIDialog_GLObjChooser() {
00155     myParent->getParent()->removeChild(this);
00156 }
00157 
00158 
00159 long
00160 GUIDialog_GLObjChooser::onCmdCenter(FXObject*,FXSelector,void*) {
00161     int selected = myList->getCurrentItem();
00162     if (selected>=0) {
00163         mySelected = static_cast<GUIGlObject*>(myList->getItemData(selected));
00164     } else {
00165         mySelected = 0;
00166     }
00167     myParent->setView(mySelected);
00168     return 1;
00169 }
00170 
00171 
00172 long
00173 GUIDialog_GLObjChooser::onCmdClose(FXObject*,FXSelector,void*) {
00174     close(true);
00175     return 1;
00176 }
00177 
00178 
00179 long
00180 GUIDialog_GLObjChooser::onChgText(FXObject*,FXSelector,void*) {
00181     int id = myList->findItem(myTextEntry->getText(), -1, SEARCH_PREFIX);
00182     if (id<0) {
00183         return 1;
00184     }
00185     myList->deselectItem(myList->getCurrentItem());
00186     myList->makeItemVisible(id);
00187     myList->selectItem(id);
00188     myList->setCurrentItem(id, true);
00189     return 1;
00190 }
00191 
00192 
00193 long
00194 GUIDialog_GLObjChooser::onCmdText(FXObject*,FXSelector,void*) {
00195     int selected = myList->getCurrentItem();
00196     if (selected>=0) {
00197         mySelected = static_cast<GUIGlObject*>(myList->getItemData(selected));
00198         myParent->setView(mySelected);
00199     }
00200     return 1;
00201 }
00202 
00203 
00204 long
00205 GUIDialog_GLObjChooser::onListKeyPress(FXObject*,FXSelector,void*ptr) {
00206     FXEvent* event=(FXEvent*)ptr;
00207     switch (event->code) {
00208     case KEY_Return: {
00209         int current = myList->getCurrentItem();
00210         if (current>=0&&myList->isItemSelected(current)) {
00211             mySelected = static_cast<GUIGlObject*>(myList->getItemData(current));
00212             myParent->setView(mySelected);
00213         }
00214     }
00215     }
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