GUIParameterTableWindow.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // The window that holds the table of an object's parameter
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 <fx.h>
00032 #include "GUIParameterTableWindow.h"
00033 #include <utils/gui/globjects/GUIGlObject.h>
00034 #include <utils/common/ToString.h>
00035 #include <utils/gui/div/GUIParam_PopupMenu.h>
00036 #include <utils/gui/windows/GUIAppEnum.h>
00037 #include <utils/gui/windows/GUIMainWindow.h>
00038 #include <utils/gui/images/GUIIconSubSys.h>
00039 #include <utils/gui/div/GUIParameterTableItem.h>
00040 
00041 #ifdef CHECK_MEMORY_LEAKS
00042 #include <foreign/nvwa/debug_new.h>
00043 #endif // CHECK_MEMORY_LEAKS
00044 
00045 
00046 // ===========================================================================
00047 // FOX callback mapping
00048 // ===========================================================================
00049 FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[]= {
00050     FXMAPFUNC(SEL_COMMAND,          MID_SIMSTEP,    GUIParameterTableWindow::onSimStep),
00051     FXMAPFUNC(SEL_SELECTED,         MID_TABLE,      GUIParameterTableWindow::onTableSelected),
00052     FXMAPFUNC(SEL_DESELECTED,       MID_TABLE,      GUIParameterTableWindow::onTableDeselected),
00053     FXMAPFUNC(SEL_RIGHTBUTTONPRESS, MID_TABLE,      GUIParameterTableWindow::onRightButtonPress),
00054 };
00055 
00056 FXIMPLEMENT(GUIParameterTableWindow, FXMainWindow, GUIParameterTableWindowMap, ARRAYNUMBER(GUIParameterTableWindowMap))
00057 
00058 
00059 // ===========================================================================
00060 // method definitions
00061 // ===========================================================================
00062 GUIParameterTableWindow::GUIParameterTableWindow(GUIMainWindow &app,
00063         GUIGlObject &o, size_t noRows) throw()
00064         : FXMainWindow(app.getApp(), (o.getFullName() + " Parameter").c_str(),
00065                        NULL,NULL,DECOR_ALL,20,20,300,(FXint)(noRows*20+60)),
00066         myObject(&o),
00067         myApplication(&app), myCurrentPos(0) {
00068     myTable = new FXTable(this, this, MID_TABLE, TABLE_COL_SIZABLE|TABLE_ROW_SIZABLE|LAYOUT_FILL_X|LAYOUT_FILL_Y);
00069     myTable->setVisibleRows((FXint)(noRows+1));
00070     myTable->setVisibleColumns(3);
00071     myTable->setTableSize((FXint)(noRows+1), 3);
00072     myTable->setBackColor(FXRGB(255,255,255));
00073     myTable->setColumnText(0, "Name");
00074     myTable->setColumnText(1, "Value");
00075     myTable->setColumnText(2, "Dynamic");
00076     myTable->getRowHeader()->setWidth(0);
00077     FXHeader *header = myTable->getColumnHeader();
00078     header->setItemJustify(0, JUSTIFY_CENTER_X);
00079     header->setItemSize(0, 150);
00080     header->setItemJustify(1, JUSTIFY_CENTER_X);
00081     header->setItemSize(1, 80);
00082     header->setItemJustify(2, JUSTIFY_CENTER_X);
00083     header->setItemSize(2, 60);
00084     setIcon(GUIIconSubSys::getIcon(ICON_APP_TABLE));
00085 }
00086 
00087 
00088 GUIParameterTableWindow::~GUIParameterTableWindow() throw() {
00089     myApplication->removeChild(this);
00090     for (std::vector<GUIParameterTableItemInterface*>::iterator i=myItems.begin(); i!=myItems.end(); ++i) {
00091         delete(*i);
00092     }
00093 }
00094 
00095 
00096 long
00097 GUIParameterTableWindow::onSimStep(FXObject*,FXSelector,void*) {
00098     updateTable();
00099     update();
00100     return 1;
00101 }
00102 
00103 
00104 long
00105 GUIParameterTableWindow::onTableSelected(FXObject*,FXSelector,void*) {
00106     return 1;
00107 }
00108 
00109 
00110 long
00111 GUIParameterTableWindow::onTableDeselected(FXObject*,FXSelector,void*) {
00112     return 1;
00113 }
00114 
00115 
00116 long
00117 GUIParameterTableWindow::onRightButtonPress(FXObject*sender,
00118         FXSelector sel,
00119         void*data) {
00120     // check which value entry was pressed
00121     myTable->onLeftBtnPress(sender, sel, data);
00122     int row = myTable->getCurrentRow();
00123     if (row==-1||row>=myItems.size()) {
00124         return 1;
00125     }
00126     GUIParameterTableItemInterface *i = myItems[row];
00127     if (!i->dynamic()) {
00128         return 1;
00129     }
00130 
00131     GUIParam_PopupMenuInterface *p =
00132         new GUIParam_PopupMenuInterface(*myApplication, *this,
00133                                         *myObject, i->getName(), i->getSUMORealSourceCopy());
00134     new FXMenuCommand(p, "Open in new Tracker", 0, p, MID_OPENTRACKER);
00135     // set geometry
00136     p->setX(static_cast<FXEvent*>(data)->root_x);
00137     p->setY(static_cast<FXEvent*>(data)->root_y);
00138     p->create();
00139     // show
00140     p->show();
00141     return 1;
00142 }
00143 
00144 
00145 
00146 void
00147 GUIParameterTableWindow::mkItem(const char *name, bool dynamic,
00148                                 ValueSource<unsigned> *src) throw() {
00149     GUIParameterTableItemInterface *i = new GUIParameterTableItem<unsigned>(
00150         myTable, myCurrentPos++, name, dynamic, src);
00151     myItems.push_back(i);
00152 }
00153 
00154 
00155 void
00156 GUIParameterTableWindow::mkItem(const char *name, bool dynamic,
00157                                 ValueSource<SUMOReal> *src) throw() {
00158     GUIParameterTableItemInterface *i = new GUIParameterTableItem<SUMOReal>(
00159         myTable, myCurrentPos++, name, dynamic, src);
00160     myItems.push_back(i);
00161 }
00162 
00163 
00164 #ifndef HAVE_SUBSECOND_TIMESTEPS
00165 void
00166 GUIParameterTableWindow::mkItem(const char *name, bool dynamic,
00167                                 ValueSource<SUMOTime> *src) throw() {
00168     GUIParameterTableItemInterface *i = new GUIParameterTableItem<SUMOTime>(
00169         myTable, myCurrentPos++, name, dynamic, src);
00170     myItems.push_back(i);
00171 }
00172 #endif
00173 
00174 
00175 void
00176 GUIParameterTableWindow::mkItem(const char *name, bool dynamic,
00177                                 std::string value) throw() {
00178     GUIParameterTableItemInterface *i = new GUIParameterTableItem<SUMOReal>(
00179         myTable, myCurrentPos++, name, dynamic, value);
00180     myItems.push_back(i);
00181 }
00182 
00183 
00184 void
00185 GUIParameterTableWindow::mkItem(const char *name, bool dynamic,
00186                                 SUMOReal value) throw() {
00187     GUIParameterTableItemInterface *i = new GUIParameterTableItem<SUMOReal>(
00188         myTable, myCurrentPos++, name, dynamic, value);
00189     myItems.push_back(i);
00190 }
00191 
00192 
00193 void
00194 GUIParameterTableWindow::mkItem(const char *name, bool dynamic,
00195                                 unsigned value) throw() {
00196     GUIParameterTableItemInterface *i = new GUIParameterTableItem<unsigned>(
00197         myTable, myCurrentPos++, name, dynamic, value);
00198     myItems.push_back(i);
00199 }
00200 
00201 
00202 #ifndef HAVE_SUBSECOND_TIMESTEPS
00203 void
00204 GUIParameterTableWindow::mkItem(const char *name, bool dynamic,
00205                                 SUMOTime value) throw() {
00206     GUIParameterTableItemInterface *i = new GUIParameterTableItem<SUMOTime>(
00207         myTable, myCurrentPos++, name, dynamic, value);
00208     myItems.push_back(i);
00209 }
00210 #endif
00211 
00212 
00213 void
00214 GUIParameterTableWindow::updateTable() throw() {
00215     for (std::vector<GUIParameterTableItemInterface*>::iterator i=myItems.begin(); i!=myItems.end(); i++) {
00216         (*i)->update();
00217     }
00218 }
00219 
00220 
00221 void
00222 GUIParameterTableWindow::closeBuilding() throw() {
00223     myApplication->addChild(this, true);
00224     create();
00225     show();
00226 }
00227 
00228 
00229 
00230 /****************************************************************************/
00231 

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