00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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 <set>
00035 #include <gui/GUIApplicationWindow.h>
00036 #include <utils/gui/windows/GUIAppEnum.h>
00037 #include <gui/GUIGlobals.h>
00038 #include <utils/gui/globjects/GUIGlObject.h>
00039 #include <utils/foxtools/MFXUtils.h>
00040 #include <utils/common/ToString.h>
00041 #include <utils/common/TplConvert.h>
00042 #include "GUIDialog_Breakpoints.h"
00043 #include <utils/gui/windows/GUISUMOAbstractView.h>
00044 #include <utils/foxtools/MFXAddEditTypedTable.h>
00045 #include <utils/common/FileHelpers.h>
00046 #include <utils/common/MsgHandler.h>
00047 #include <utils/options/OptionsCont.h>
00048 #include <utils/gui/div/GUIIOGlobals.h>
00049 #include <utils/gui/windows/GUIAppGlobals.h>
00050 #include <utils/gui/windows/GUIAppGlobals.h>
00051 #include <utils/gui/images/GUIIconSubSys.h>
00052 #include <utils/iodevices/OutputDevice.h>
00053
00054 #ifdef CHECK_MEMORY_LEAKS
00055 #include <foreign/nvwa/debug_new.h>
00056 #endif // CHECK_MEMORY_LEAKS
00057
00058
00059
00060
00061
00062 #define INVALID_VALUE -1
00063 #define INVALID_VALUE_STR "-1"
00064
00065
00066
00067
00068
00069 FXDEFMAP(GUIDialog_Breakpoints) GUIDialog_BreakpointsMap[]= {
00070 FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_LOAD, GUIDialog_Breakpoints::onCmdLoad),
00071 FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_SAVE, GUIDialog_Breakpoints::onCmdSave),
00072 FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_CLEAR, GUIDialog_Breakpoints::onCmdClear),
00073 FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GUIDialog_Breakpoints::onCmdClose),
00074 FXMAPFUNC(SEL_CHANGED, MFXAddEditTypedTable::ID_TEXT_CHANGED, GUIDialog_Breakpoints::onCmdEditTable),
00075 };
00076
00077
00078 FXIMPLEMENT(GUIDialog_Breakpoints, FXMainWindow, GUIDialog_BreakpointsMap, ARRAYNUMBER(GUIDialog_BreakpointsMap))
00079
00080
00081
00082
00083
00084 GUIDialog_Breakpoints::GUIDialog_Breakpoints(GUIMainWindow *parent) throw()
00085 : FXMainWindow(parent->getApp(), "Breakpoints Editor", NULL, NULL, DECOR_ALL, 20,20,300, 300),
00086 myParent(parent) {
00087 FXHorizontalFrame *hbox = new FXHorizontalFrame(this, LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0, 0,0,0,0);
00088
00089
00090 myTable = new MFXAddEditTypedTable(hbox, this, MID_TABLE, LAYOUT_FILL_X|LAYOUT_FILL_Y);
00091 myTable->setVisibleRows(20);
00092 myTable->setVisibleColumns(1);
00093 myTable->setTableSize(20,1);
00094 myTable->setBackColor(FXRGB(255,255,255));
00095 myTable->setCellType(0, CT_INT);
00096 SUMOTime begin = string2time(OptionsCont::getOptions().getString("begin"));
00097 SUMOTime end = string2time(OptionsCont::getOptions().getString("end"));
00098 if(end<0) {
00099 end = SUMOTime_MAX;
00100 }
00101 myTable->setNumberCellParams(0, begin, end, 1, 10, 100, "%.0f");
00102 myTable->getRowHeader()->setWidth(0);
00103 rebuildList();
00104
00105 FXVerticalFrame *layout = new FXVerticalFrame(hbox, LAYOUT_TOP,0,0,0,0, 4,4,4,4);
00106
00107 new FXButton(layout, "Load\t\t", 0, this, MID_CHOOSEN_LOAD,
00108 ICON_BEFORE_TEXT|LAYOUT_FILL_X|FRAME_THICK|FRAME_RAISED,
00109 0, 0, 0, 0, 4, 4, 3, 3);
00110
00111 new FXButton(layout, "Save\t\t", 0, this, MID_CHOOSEN_SAVE,
00112 ICON_BEFORE_TEXT|LAYOUT_FILL_X|FRAME_THICK|FRAME_RAISED,
00113 0, 0, 0, 0, 4, 4, 3, 3);
00114 new FXHorizontalSeparator(layout,SEPARATOR_GROOVE|LAYOUT_FILL_X);
00115
00116 new FXButton(layout, "Clear\t\t", 0, this, MID_CHOOSEN_CLEAR,
00117 ICON_BEFORE_TEXT|LAYOUT_FILL_X|FRAME_THICK|FRAME_RAISED,
00118 0, 0, 0, 0, 4, 4, 3, 3);
00119 new FXHorizontalSeparator(layout,SEPARATOR_GROOVE|LAYOUT_FILL_X);
00120
00121 new FXButton(layout, "Close\t\t", 0, this, MID_CANCEL,
00122 ICON_BEFORE_TEXT|LAYOUT_FILL_X|FRAME_THICK|FRAME_RAISED,
00123 0, 0, 0, 0, 4, 4, 3, 3);
00124
00125 setIcon(GUIIconSubSys::getIcon(ICON_APP_BREAKPOINTS));
00126 myParent->addChild(this);
00127 }
00128
00129
00130 GUIDialog_Breakpoints::~GUIDialog_Breakpoints() throw() {
00131 myParent->removeChild(this);
00132 }
00133
00134
00135 void
00136 GUIDialog_Breakpoints::rebuildList() throw() {
00137 myTable->clearItems();
00138 sort(gBreakpoints.begin(), gBreakpoints.end());
00139
00140
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
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
00158 for (k=0; k<1; k++) {
00159 myTable->setItemText(row, k, " ");
00160 }
00161 }
00162
00163
00164 long
00165 GUIDialog_Breakpoints::onCmdLoad(FXObject*,FXSelector,void*) {
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 }
00191
00192
00193 long
00194 GUIDialog_Breakpoints::onCmdSave(FXObject*,FXSelector,void*) {
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 }
00209
00210
00211 std::string
00212 GUIDialog_Breakpoints::encode2TXT() throw() {
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 }
00223
00224
00225 long
00226 GUIDialog_Breakpoints::onCmdClear(FXObject*,FXSelector,void*) {
00227 gBreakpoints.clear();
00228 rebuildList();
00229 return 1;
00230 }
00231
00232
00233
00234 long
00235 GUIDialog_Breakpoints::onCmdClose(FXObject*,FXSelector,void*) {
00236 close(true);
00237 return 1;
00238 }
00239
00240
00241 long
00242 GUIDialog_Breakpoints::onCmdEditTable(FXObject*,FXSelector,void*data) {
00243 MFXEditedTableItem *i = (MFXEditedTableItem*) data;
00244 std::string value = i->item->getText().text();
00245
00246 if (value.find_first_not_of(" ")==std::string::npos) {
00247
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 }
00272
00273
00274
00275