GUIDialog_Breakpoints Class Reference

#include <GUIDialog_Breakpoints.h>

Inheritance diagram for GUIDialog_Breakpoints:

FXMainWindow

Detailed Description

Editor for simulation breakpoints.

This dialog shows and lets the user edit the list of breakpoints - simulation time steps where the simulation halts.

Todo:
Use a LineReader instead of >> while reading

Definition at line 55 of file GUIDialog_Breakpoints.h.


Public Member Functions

 GUIDialog_Breakpoints (GUIMainWindow *parent) throw ()
 Constructor.
long onCmdClear (FXObject *, FXSelector, void *)
 Called when the user presses the Clear-button.
long onCmdClose (FXObject *, FXSelector, void *)
 Called when the user presses the Close-button.
long onCmdEditTable (FXObject *, FXSelector, void *)
 Called when the table was changed.
long onCmdLoad (FXObject *, FXSelector, void *)
 Called when the user presses the Load-button.
long onCmdSave (FXObject *, FXSelector, void *)
 Called when the user presses the Save-button.
 ~GUIDialog_Breakpoints () throw ()
 Destructor.

Protected Member Functions

 GUIDialog_Breakpoints ()
 FOX needs this.

Private Member Functions

std::string encode2TXT () throw ()
 Builds a text representation of the items in the list.
void rebuildList () throw ()
 Rebuilds the entire list.

Private Attributes

GUIMainWindowmyParent
 The parent window.
MFXAddEditTypedTablemyTable
 The list that holds the ids.

Constructor & Destructor Documentation

GUIDialog_Breakpoints::GUIDialog_Breakpoints ( GUIMainWindow parent  )  throw ()

Constructor.

Parameters:
[in] parent The parent window

GUIDialog_Breakpoints::~GUIDialog_Breakpoints (  )  throw ()

Destructor.

Definition at line 130 of file GUIDialog_Breakpoints.cpp.

References myParent, and GUIMainWindow::removeChild().

00130                                                       {
00131     myParent->removeChild(this);
00132 }

GUIDialog_Breakpoints::GUIDialog_Breakpoints (  )  [inline, protected]

FOX needs this.

Definition at line 104 of file GUIDialog_Breakpoints.h.

00104 { }


Member Function Documentation

std::string GUIDialog_Breakpoints::encode2TXT (  )  throw () [private]

Builds a text representation of the items in the list.

Returns:
Breakpoints encoded as a string

Definition at line 212 of file GUIDialog_Breakpoints.cpp.

References gBreakpoints, and INVALID_VALUE.

Referenced by onCmdSave().

00212                                           {
00213     std::ostringstream strm;
00214     std::sort(gBreakpoints.begin(), gBreakpoints.end());
00215     //
00216     for (std::vector<int>::iterator j=gBreakpoints.begin(); j!=gBreakpoints.end(); ++j) {
00217         if ((*j)!=INVALID_VALUE) {
00218             strm << (*j) << std::endl;
00219         }
00220     }
00221     return strm.str();
00222 }

long GUIDialog_Breakpoints::onCmdClear ( FXObject ,
FXSelector  ,
void *   
)

Called when the user presses the Clear-button.

Definition at line 226 of file GUIDialog_Breakpoints.cpp.

References gBreakpoints, and rebuildList().

00226                                                             {
00227     gBreakpoints.clear();
00228     rebuildList();
00229     return 1;
00230 }

long GUIDialog_Breakpoints::onCmdClose ( FXObject ,
FXSelector  ,
void *   
)

Called when the user presses the Close-button.

Definition at line 235 of file GUIDialog_Breakpoints.cpp.

00235                                                             {
00236     close(true);
00237     return 1;
00238 }

long GUIDialog_Breakpoints::onCmdEditTable ( FXObject ,
FXSelector  ,
void *  data 
)

Called when the table was changed.

Definition at line 242 of file GUIDialog_Breakpoints.cpp.

References TplConvert< E >::_2int(), MFXEditedTableItem::col, gBreakpoints, INVALID_VALUE, INVALID_VALUE_STR, MFXEditedTableItem::item, rebuildList(), MFXEditedTableItem::row, and MFXEditedTableItem::updateOnly.

00242                                                                     {
00243     MFXEditedTableItem *i = (MFXEditedTableItem*) data;
00244     std::string value = i->item->getText().text();
00245     // check whether the inserted value is empty
00246     if (value.find_first_not_of(" ")==std::string::npos) {
00247         // replace by invalid if so
00248         value = INVALID_VALUE_STR;
00249     }
00250     int row = i->row;
00251     if (row==(int) gBreakpoints.size()) {
00252         gBreakpoints.push_back(INVALID_VALUE);
00253     }
00254 
00255     switch (i->col) {
00256     case 0:
00257         try {
00258             gBreakpoints[row] = TplConvert<char>::_2int(value.c_str());
00259         } catch (NumberFormatException &) {
00260             std::string msg = "The value must be an int, is:" + value;
00261             FXMessageBox::error(this, MBOX_OK, "Number format error", msg.c_str());
00262         }
00263         break;
00264     default:
00265         break;
00266     }
00267     if (!i->updateOnly) {
00268         rebuildList();
00269     }
00270     return 1;
00271 }

long GUIDialog_Breakpoints::onCmdLoad ( FXObject ,
FXSelector  ,
void *   
)

Called when the user presses the Load-button.

Definition at line 165 of file GUIDialog_Breakpoints.cpp.

References TplConvert< E >::_2int(), gBreakpoints, gCurrentFolder, MsgHandler::getErrorInstance(), GUIIconSubSys::getIcon(), ICON_EMPTY, MsgHandler::inform(), and rebuildList().

00165                                                            {
00166     FXFileDialog opendialog(this, "Save Breakpoints");
00167     opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
00168     opendialog.setSelectMode(SELECTFILE_ANY);
00169     opendialog.setPatternList("*.txt");
00170     if (gCurrentFolder.length()!=0) {
00171         opendialog.setDirectory(gCurrentFolder);
00172     }
00173     if (opendialog.execute()) {
00174         gCurrentFolder = opendialog.getDirectory();
00175         std::string file = opendialog.getFilename().text();
00176         std::ifstream strm(file.c_str());
00177         while (strm.good()) {
00178             std::string val;
00179             strm >> val;
00180             try {
00181                 int value = TplConvert<char>::_2int(val.c_str());
00182                 gBreakpoints.push_back(value);
00183             } catch (NumberFormatException&) {
00184                 MsgHandler::getErrorInstance()->inform(" A breakpoint-value must be an int, is:" + val);
00185             } catch (EmptyData&) {}
00186         }
00187         rebuildList();
00188     }
00189     return 1;
00190 }

long GUIDialog_Breakpoints::onCmdSave ( FXObject ,
FXSelector  ,
void *   
)

Called when the user presses the Save-button.

Definition at line 194 of file GUIDialog_Breakpoints.cpp.

References OutputDevice::close(), encode2TXT(), gCurrentFolder, OutputDevice::getDevice(), MFXUtils::getFilename2Write(), GUIIconSubSys::getIcon(), and ICON_EMPTY.

00194                                                            {
00195     FXString file = MFXUtils::getFilename2Write(this, "Save Breakpoints", ".txt", GUIIconSubSys::getIcon(ICON_EMPTY), gCurrentFolder);
00196     if (file=="") {
00197         return 1;
00198     }
00199     std::string content = encode2TXT();
00200     try {
00201         OutputDevice &dev = OutputDevice::getDevice(file.text());
00202         dev << content;
00203         dev.close();
00204     } catch (IOError &e) {
00205         FXMessageBox::error(this, MBOX_OK, "Storing failed!", e.what());
00206     }
00207     return 1;
00208 }

void GUIDialog_Breakpoints::rebuildList (  )  throw () [private]

Rebuilds the entire list.

Definition at line 136 of file GUIDialog_Breakpoints.cpp.

References gBreakpoints, and myTable.

Referenced by onCmdClear(), onCmdEditTable(), and onCmdLoad().

00136                                            {
00137     myTable->clearItems();
00138     sort(gBreakpoints.begin(), gBreakpoints.end());
00139 
00140     // set table attributes
00141     myTable->setTableSize((FXint) gBreakpoints.size()+1, 1);
00142     myTable->setColumnText(0, "Time");
00143     FXHeader *header = myTable->getColumnHeader();
00144     header->setHeight(getApp()->getNormalFont()->getFontHeight()+getApp()->getNormalFont()->getFontAscent());
00145     int k;
00146     for (k=0; k<1; k++) {
00147         header->setItemJustify(k, JUSTIFY_CENTER_X);
00148     }
00149 
00150     // insert into table
00151     FXint row = 0;
00152     std::vector<int>::iterator j;
00153     for (j=gBreakpoints.begin(); j!=gBreakpoints.end(); ++j) {
00154         myTable->setItemText(row, 0, toString<int>(*j).c_str());
00155         row++;
00156     }
00157     // insert dummy last field
00158     for (k=0; k<1; k++) {
00159         myTable->setItemText(row, k, " ");
00160     }
00161 }


Field Documentation

The parent window.

Definition at line 99 of file GUIDialog_Breakpoints.h.

Referenced by ~GUIDialog_Breakpoints().

The list that holds the ids.

Definition at line 96 of file GUIDialog_Breakpoints.h.

Referenced by rebuildList().


The documentation for this class was generated from the following files:

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