SUMO - Simulation of Urban MObility

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 (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 <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     myLock.lock();
00086     myObject->addParameterTable(this);
00087     myLock.unlock();
00088 }
00089 
00090 
00091 GUIParameterTableWindow::~GUIParameterTableWindow() throw() {
00092     myApplication->removeChild(this);
00093     myLock.lock();
00094     for (std::vector<GUIParameterTableItemInterface*>::iterator i=myItems.begin(); i!=myItems.end(); ++i) {
00095         delete(*i);
00096     }
00097     if (myObject!=0) {
00098         myObject->removeParameterTable(this);
00099     }
00100     myLock.unlock();
00101 }
00102 
00103 
00104 void
00105 GUIParameterTableWindow::removeObject(GUIGlObject* /*i*/) throw() {
00106     myLock.lock();
00107     myObject = 0;
00108     myLock.unlock();
00109 }
00110 
00111 
00112 long
00113 GUIParameterTableWindow::onSimStep(FXObject*,FXSelector,void*) {
00114     updateTable();
00115     update();
00116     return 1;
00117 }
00118 
00119 
00120 long
00121 GUIParameterTableWindow::onTableSelected(FXObject*,FXSelector,void*) {
00122     return 1;
00123 }
00124 
00125 
00126 long
00127 GUIParameterTableWindow::onTableDeselected(FXObject*,FXSelector,void*) {
00128     return 1;
00129 }
00130 
00131 
00132 long
00133 GUIParameterTableWindow::onRightButtonPress(FXObject* sender,
00134         FXSelector sel,
00135         void* data) {
00136     // check which value entry was pressed
00137     myTable->onLeftBtnPress(sender, sel, data);
00138     int row = myTable->getCurrentRow();
00139     if (row==-1||row>= (int)(myItems.size())) {
00140         return 1;
00141     }
00142     GUIParameterTableItemInterface* i = myItems[row];
00143     if (!i->dynamic()) {
00144         return 1;
00145     }
00146 
00147     GUIParam_PopupMenuInterface* p = new GUIParam_PopupMenuInterface(*myApplication, *this, *myObject, i->getName(), i->getSUMORealSourceCopy());
00148     new FXMenuCommand(p, "Open in new Tracker", 0, p, MID_OPENTRACKER);
00149     // set geometry
00150     p->setX(static_cast<FXEvent*>(data)->root_x);
00151     p->setY(static_cast<FXEvent*>(data)->root_y);
00152     p->create();
00153     // show
00154     p->show();
00155     return 1;
00156 }
00157 
00158 
00159 
00160 void
00161 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
00162                                 ValueSource<unsigned> *src) throw() {
00163     GUIParameterTableItemInterface* i = new GUIParameterTableItem<unsigned>(myTable, myCurrentPos++, name, dynamic, src);
00164     myItems.push_back(i);
00165 }
00166 
00167 
00168 void
00169 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
00170                                 ValueSource<SUMOReal> *src) throw() {
00171     GUIParameterTableItemInterface* i = new GUIParameterTableItem<SUMOReal>(myTable, myCurrentPos++, name, dynamic, src);
00172     myItems.push_back(i);
00173 }
00174 
00175 
00176 #ifndef HAVE_SUBSECOND_TIMESTEPS
00177 void
00178 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
00179                                 ValueSource<SUMOTime> *src) throw() {
00180     GUIParameterTableItemInterface* i = new GUIParameterTableItem<SUMOTime>(myTable, myCurrentPos++, name, dynamic, src);
00181     myItems.push_back(i);
00182 }
00183 #endif
00184 
00185 
00186 void
00187 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
00188                                 std::string value) throw() {
00189     GUIParameterTableItemInterface* i = new GUIParameterTableItem<SUMOReal>(myTable, myCurrentPos++, name, dynamic, value);
00190     myItems.push_back(i);
00191 }
00192 
00193 
00194 void
00195 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
00196                                 SUMOReal value) throw() {
00197     GUIParameterTableItemInterface* i = new GUIParameterTableItem<SUMOReal>(myTable, myCurrentPos++, name, dynamic, value);
00198     myItems.push_back(i);
00199 }
00200 
00201 
00202 void
00203 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
00204                                 unsigned value) throw() {
00205     GUIParameterTableItemInterface* i = new GUIParameterTableItem<unsigned>(myTable, myCurrentPos++, name, dynamic, value);
00206     myItems.push_back(i);
00207 }
00208 
00209 
00210 #ifndef HAVE_SUBSECOND_TIMESTEPS
00211 void
00212 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
00213                                 SUMOTime value) throw() {
00214     GUIParameterTableItemInterface* i = new GUIParameterTableItem<SUMOTime>(myTable, myCurrentPos++, name, dynamic, value);
00215     myItems.push_back(i);
00216 }
00217 #endif
00218 
00219 
00220 void
00221 GUIParameterTableWindow::updateTable() throw() {
00222     myLock.lock();
00223     if (myObject==0) {
00224         myLock.unlock();
00225         return;
00226     }
00227     for (std::vector<GUIParameterTableItemInterface*>::iterator i=myItems.begin(); i!=myItems.end(); i++) {
00228         (*i)->update();
00229     }
00230     myLock.unlock();
00231 }
00232 
00233 
00234 void
00235 GUIParameterTableWindow::closeBuilding() throw() {
00236     myApplication->addChild(this, true);
00237     create();
00238     show();
00239 }
00240 
00241 
00242 
00243 /****************************************************************************/
00244 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines