SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIDialog_Breakpoints.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Editor for simulation breakpoints
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <vector>
35 #include <iostream>
36 #include <fstream>
37 #include <set>
40 #include <gui/GUIGlobals.h>
43 #include <utils/common/ToString.h>
54 #include "GUIDialog_Breakpoints.h"
55 
56 #ifdef CHECK_MEMORY_LEAKS
57 #include <foreign/nvwa/debug_new.h>
58 #endif // CHECK_MEMORY_LEAKS
59 
60 
61 // ===========================================================================
62 // definitions
63 // ===========================================================================
64 #define INVALID_VALUE -1
65 #define INVALID_VALUE_STR "-1"
66 
67 
68 // ===========================================================================
69 // FOX callback mapping
70 // ===========================================================================
71 FXDEFMAP(GUIDialog_Breakpoints) GUIDialog_BreakpointsMap[] = {
72  FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_LOAD, GUIDialog_Breakpoints::onCmdLoad),
73  FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_SAVE, GUIDialog_Breakpoints::onCmdSave),
75  FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GUIDialog_Breakpoints::onCmdClose),
77 };
78 
79 
80 FXIMPLEMENT(GUIDialog_Breakpoints, FXMainWindow, GUIDialog_BreakpointsMap, ARRAYNUMBER(GUIDialog_BreakpointsMap))
81 
82 
83 // ===========================================================================
84 // method definitions
85 // ===========================================================================
87  : FXMainWindow(parent->getApp(), "Breakpoints Editor", NULL, NULL, DECOR_ALL, 20, 20, 300, 300),
88  myParent(parent) {
89  FXHorizontalFrame* hbox = new FXHorizontalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
90 
91  // build the table
92  myTable = new MFXAddEditTypedTable(hbox, this, MID_TABLE, LAYOUT_FILL_X | LAYOUT_FILL_Y);
93  myTable->setVisibleRows(20);
94  myTable->setVisibleColumns(1);
95  myTable->setTableSize(20, 1);
96  myTable->setBackColor(FXRGB(255, 255, 255));
97  myTable->setCellType(0, CT_REAL);
98  SUMOTime begin = string2time(OptionsCont::getOptions().getString("begin"));
99  SUMOTime end = string2time(OptionsCont::getOptions().getString("end"));
100  if (end < 0) {
101  end = SUMOTime_MAX;
102  }
103  myTable->setNumberCellParams(0, begin / 1000, end / 1000, 1, 10, 100, "%.2f");
104  myTable->getRowHeader()->setWidth(0);
105  rebuildList();
106  // build the layout
107  FXVerticalFrame* layout = new FXVerticalFrame(hbox, LAYOUT_TOP, 0, 0, 0, 0, 4, 4, 4, 4);
108  // "Load"
109  new FXButton(layout, "Load\t\t", 0, this, MID_CHOOSEN_LOAD, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED, 0, 0, 0, 0, 4, 4, 3, 3);
110  // "Save"
111  new FXButton(layout, "Save\t\t", 0, this, MID_CHOOSEN_SAVE, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED, 0, 0, 0, 0, 4, 4, 3, 3);
112  new FXHorizontalSeparator(layout, SEPARATOR_GROOVE | LAYOUT_FILL_X);
113  // "Clear List"
114  new FXButton(layout, "Clear\t\t", 0, this, MID_CHOOSEN_CLEAR, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED, 0, 0, 0, 0, 4, 4, 3, 3);
115  new FXHorizontalSeparator(layout, SEPARATOR_GROOVE | LAYOUT_FILL_X);
116  // "Close"
117  new FXButton(layout, "Close\t\t", 0, this, MID_CANCEL, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED, 0, 0, 0, 0, 4, 4, 3, 3);
118  //
120  myParent->addChild(this);
121 }
122 
123 
125  myParent->removeChild(this);
126 }
127 
128 
129 void
131  myTable->clearItems();
133  // set table attributes
134  myTable->setTableSize((FXint) GUIGlobals::gBreakpoints.size() + 1, 1);
135  myTable->setColumnText(0, "Time");
136  FXHeader* header = myTable->getColumnHeader();
137  header->setHeight(getApp()->getNormalFont()->getFontHeight() + getApp()->getNormalFont()->getFontAscent());
138  int k;
139  for (k = 0; k < 1; k++) {
140  header->setItemJustify(k, JUSTIFY_CENTER_X);
141  }
142  // insert into table
143  FXint row = 0;
144  std::vector<int>::iterator j;
145  for (j = GUIGlobals::gBreakpoints.begin(); j != GUIGlobals::gBreakpoints.end(); ++j) {
146  myTable->setItemText(row, 0, time2string(*j).c_str());
147  row++;
148  }
149  // insert dummy last field
150  for (k = 0; k < 1; k++) {
151  myTable->setItemText(row, k, " ");
152  }
153 }
154 
155 
156 long
158  FXFileDialog opendialog(this, "Load Breakpoints");
159  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
160  opendialog.setSelectMode(SELECTFILE_ANY);
161  opendialog.setPatternList("*.txt");
162  if (gCurrentFolder.length() != 0) {
163  opendialog.setDirectory(gCurrentFolder);
164  }
165  if (opendialog.execute()) {
166  gCurrentFolder = opendialog.getDirectory();
167  std::string file = opendialog.getFilename().text();
169  rebuildList();
170  }
171  return 1;
172 }
173 
174 
175 long
177  FXString file = MFXUtils::getFilename2Write(this, "Save Breakpoints", ".txt", GUIIconSubSys::getIcon(ICON_EMPTY), gCurrentFolder);
178  if (file == "") {
179  return 1;
180  }
181  std::string content = encode2TXT();
182  try {
183  OutputDevice& dev = OutputDevice::getDevice(file.text());
184  dev << content;
185  dev.close();
186  } catch (IOError& e) {
187  FXMessageBox::error(this, MBOX_OK, "Storing failed!", "%s", e.what());
188  }
189  return 1;
190 }
191 
192 
193 std::string
195  std::ostringstream strm;
196  std::sort(GUIGlobals::gBreakpoints.begin(), GUIGlobals::gBreakpoints.end());
197  for (std::vector<int>::iterator j = GUIGlobals::gBreakpoints.begin(); j != GUIGlobals::gBreakpoints.end(); ++j) {
198  if ((*j) != INVALID_VALUE) {
199  strm << time2string(*j) << std::endl;
200  }
201  }
202  return strm.str();
203 }
204 
205 
206 long
208  GUIGlobals::gBreakpoints.clear();
209  rebuildList();
210  return 1;
211 }
212 
213 
214 
215 long
217  close(true);
218  return 1;
219 }
220 
221 
222 long
225  std::string value = i->item->getText().text();
226  // check whether the inserted value is empty
227  if (value.find_first_not_of(" ") == std::string::npos) {
228  // replace by invalid if so
229  value = INVALID_VALUE_STR;
230  }
231  int row = i->row;
232  if (row == (int) GUIGlobals::gBreakpoints.size()) {
234  }
235 
236  switch (i->col) {
237  case 0:
238  try {
240  } catch (NumberFormatException&) {
241  std::string msg = "The value must be an int, is:" + value;
242  FXMessageBox::error(this, MBOX_OK, "Number format error", "%s", msg.c_str());
243  }
244  break;
245  default:
246  break;
247  }
248  if (!i->updateOnly) {
249  rebuildList();
250  }
251  return 1;
252 }
253 
254 
255 /****************************************************************************/
256