SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIApplicationWindow.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // The main window of the SUMO-gui.
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #ifdef HAVE_VERSION_H
35 #include <version.h>
36 #endif
37 
38 #include <string>
39 #include <sstream>
40 #include <algorithm>
41 
42 #include <guisim/GUINet.h>
43 
44 #include "GUISUMOViewParent.h"
45 #include "GUILoadThread.h"
46 #include "GUIRunThread.h"
47 #include "GUIApplicationWindow.h"
50 
51 #include <utils/common/ToString.h>
56 
72 #include "GUIGlobals.h"
76 
77 #ifndef NO_TRACI
79 #include "TraCIServerAPI_GUI.h"
80 #endif
81 
82 #ifdef CHECK_MEMORY_LEAKS
83 #include <foreign/nvwa/debug_new.h>
84 #endif
85 
86 
87 // ===========================================================================
88 // FOX-declarations
89 // ===========================================================================
90 FXDEFMAP(GUIApplicationWindow) GUIApplicationWindowMap[] = {
91  FXMAPFUNC(SEL_COMMAND, MID_QUIT, GUIApplicationWindow::onCmdQuit),
92  FXMAPFUNC(SEL_SIGNAL, MID_QUIT, GUIApplicationWindow::onCmdQuit),
93  FXMAPFUNC(SEL_CLOSE, MID_WINDOW, GUIApplicationWindow::onCmdQuit),
94 
98  FXMAPFUNC(SEL_COMMAND, MID_RELOAD, GUIApplicationWindow::onCmdReload),
99  FXMAPFUNC(SEL_COMMAND, MID_CLOSE, GUIApplicationWindow::onCmdClose),
100  FXMAPFUNC(SEL_COMMAND, MID_EDITCHOSEN, GUIApplicationWindow::onCmdEditChosen),
102 
104  FXMAPFUNC(SEL_COMMAND, MID_GAMING, GUIApplicationWindow::onCmdGaming),
106  FXMAPFUNC(SEL_COMMAND, MID_ABOUT, GUIApplicationWindow::onCmdAbout),
107  FXMAPFUNC(SEL_COMMAND, MID_NEW_MICROVIEW, GUIApplicationWindow::onCmdNewView),
108 #ifdef HAVE_OSG
109  FXMAPFUNC(SEL_COMMAND, MID_NEW_OSGVIEW, GUIApplicationWindow::onCmdNewOSG),
110 #endif
111  FXMAPFUNC(SEL_COMMAND, MID_START, GUIApplicationWindow::onCmdStart),
112  FXMAPFUNC(SEL_COMMAND, MID_STOP, GUIApplicationWindow::onCmdStop),
113  FXMAPFUNC(SEL_COMMAND, MID_STEP, GUIApplicationWindow::onCmdStep),
115 
116  FXMAPFUNC(SEL_UPDATE, MID_OPEN_CONFIG, GUIApplicationWindow::onUpdOpen),
117  FXMAPFUNC(SEL_UPDATE, MID_OPEN_NETWORK, GUIApplicationWindow::onUpdOpen),
118  FXMAPFUNC(SEL_UPDATE, MID_RELOAD, GUIApplicationWindow::onUpdReload),
121 #ifdef HAVE_OSG
122  FXMAPFUNC(SEL_COMMAND, MID_NEW_OSGVIEW, GUIApplicationWindow::onUpdAddView),
123 #endif
124  FXMAPFUNC(SEL_UPDATE, MID_START, GUIApplicationWindow::onUpdStart),
125  FXMAPFUNC(SEL_UPDATE, MID_STOP, GUIApplicationWindow::onUpdStop),
126  FXMAPFUNC(SEL_UPDATE, MID_STEP, GUIApplicationWindow::onUpdStep),
129 
130  FXMAPFUNC(SEL_CLIPBOARD_REQUEST, 0, GUIApplicationWindow::onClipboardRequest),
131 
136 };
137 
138 // Object implementation
139 FXIMPLEMENT(GUIApplicationWindow, FXMainWindow, GUIApplicationWindowMap, ARRAYNUMBER(GUIApplicationWindowMap))
140 
141 // ===========================================================================
142 // member method definitions
143 // ===========================================================================
145  const std::string& configPattern)
146  : GUIMainWindow(a),
147  myLoadThread(0), myRunThread(0),
148  myAmLoading(false),
149  mySimDelay(50),
150  myRecentNets(a, "nets"), myConfigPattern(configPattern),
151  hadDependentBuild(false) {
153 }
154 
155 
156 void
158  // do this not twice
159  if (hadDependentBuild) {
160  return;
161  }
162  hadDependentBuild = true;
163 
164  setTarget(this);
165  setSelector(MID_WINDOW);
166 
167  // build menu bar
168  myMenuBarDrag = new FXToolBarShell(this, FRAME_NORMAL);
169  myMenuBar = new FXMenuBar(myTopDock, myMenuBarDrag,
170  LAYOUT_SIDE_TOP | LAYOUT_FILL_X | FRAME_RAISED);
171  new FXToolBarGrip(myMenuBar, myMenuBar, FXMenuBar::ID_TOOLBARGRIP,
172  TOOLBARGRIP_DOUBLE);
173  buildToolBars();
174  // build the thread - io
179 
180  // build the status bar
181  myStatusbar = new FXStatusBar(this, LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X | FRAME_RAISED);
182  {
183  myGeoFrame =
184  new FXHorizontalFrame(myStatusbar, LAYOUT_FIX_WIDTH | LAYOUT_FILL_Y | LAYOUT_RIGHT | FRAME_SUNKEN,
185  0, 0, 20, 0, 0, 0, 0, 0, 0, 0);
186  myGeoCoordinate = new FXLabel(myGeoFrame, "N/A", 0, LAYOUT_CENTER_Y);
188  new FXHorizontalFrame(myStatusbar, LAYOUT_FIX_WIDTH | LAYOUT_FILL_Y | LAYOUT_RIGHT | FRAME_SUNKEN,
189  0, 0, 20, 0, 0, 0, 0, 0, 0, 0);
190  myCartesianCoordinate = new FXLabel(myCartesianFrame, "N/A", 0, LAYOUT_CENTER_Y);
191  }
192 
193  // make the window a mdi-window
194  myMainSplitter = new FXSplitter(this,
195  SPLITTER_REVERSED | SPLITTER_VERTICAL | LAYOUT_FILL_X | LAYOUT_FILL_Y | SPLITTER_TRACKING | FRAME_RAISED | FRAME_THICK);
196  myMDIClient = new FXMDIClient(myMainSplitter,
197  LAYOUT_FILL_X | LAYOUT_FILL_Y | FRAME_SUNKEN | FRAME_THICK);
198  myMDIMenu = new FXMDIMenu(this, myMDIClient);
199  new FXMDIWindowButton(myMenuBar, myMDIMenu, myMDIClient,
200  FXMDIClient::ID_MDI_MENUWINDOW, LAYOUT_LEFT);
201  new FXMDIDeleteButton(myMenuBar, myMDIClient,
202  FXMDIClient::ID_MDI_MENUCLOSE, FRAME_RAISED | LAYOUT_RIGHT);
203  new FXMDIRestoreButton(myMenuBar, myMDIClient,
204  FXMDIClient::ID_MDI_MENURESTORE, FRAME_RAISED | LAYOUT_RIGHT);
205  new FXMDIMinimizeButton(myMenuBar, myMDIClient,
206  FXMDIClient::ID_MDI_MENUMINIMIZE, FRAME_RAISED | LAYOUT_RIGHT);
207 
208  // build the message window
210  // fill menu and tool bar
211  fillMenuBar();
212  if (game) {
213  onCmdGaming(0, 0, 0);
214  myMenuBar->hide();
215  myToolBar1->hide();
216  myToolBar2->hide();
217  myToolBar4->hide();
218  myToolBar5->hide();
219  myMessageWindow->hide();
220  }
221  // build additional threads
222  myLoadThread = new GUILoadThread(getApp(), this, myEvents, myLoadThreadEvent);
223  myRunThread = new GUIRunThread(getApp(), this, *mySimDelayTarget, myEvents,
225  // set the status bar
226  myStatusbar->getStatusLine()->setText("Ready.");
227  // set the caption
228  setTitle(MFXUtils::getTitleText(("SUMO " + std::string(VERSION_STRING)).c_str()));
229 
230  // start the simulation-thread (it will loop until the application ends deciding by itself whether to perform a step or not)
231  myRunThread->start();
233 }
234 
235 
236 void
238  if (getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 0) {
239  setX(getApp()->reg().readIntEntry("SETTINGS", "x", 150));
240  setY(getApp()->reg().readIntEntry("SETTINGS", "y", 150));
241  setWidth(getApp()->reg().readIntEntry("SETTINGS", "width", 600));
242  setHeight(getApp()->reg().readIntEntry("SETTINGS", "height", 400));
243  }
244  gCurrentFolder = getApp()->reg().readStringEntry("SETTINGS", "basedir", "");
245  FXMainWindow::create();
246  myMenuBarDrag->create();
247  myToolBarDrag1->create();
248  myToolBarDrag2->create();
249  myFileMenu->create();
250  myEditMenu->create();
251  mySettingsMenu->create();
252  myWindowsMenu->create();
253  myHelpMenu->create();
254 
255  FXint width = getApp()->getNormalFont()->getTextWidth("8", 1) * 24;
256  myCartesianFrame->setWidth(width);
257  myGeoFrame->setWidth(width);
258 
259  show(PLACEMENT_SCREEN);
260  if (getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 1) {
261  maximize();
262  }
263 }
264 
265 
268  myRunThread->join();
269  closeAllWindows();
270  //
272  delete myGLVisual;
273  // delete some non-parented windows
274  delete myToolBarDrag1;
275  //
276  delete myRunThread;
277  delete myFileMenu;
278  delete myEditMenu;
279  delete mySettingsMenu;
280  delete myWindowsMenu;
281  delete myHelpMenu;
282 
283  delete myLoadThread;
284 
285  while (!myEvents.empty()) {
286  // get the next event
287  GUIEvent* e = static_cast<GUIEvent*>(myEvents.top());
288  myEvents.pop();
289  delete e;
290  }
291 }
292 
293 
294 void
296  FXMainWindow::detach();
297  myMenuBarDrag->detach();
298  myToolBarDrag1->detach();
299 }
300 
301 
302 void
304  // build file menu
305  myFileMenu = new FXMenuPane(this);
306  new FXMenuTitle(myMenuBar, "&File", NULL, myFileMenu);
308  "&Open Simulation...\tCtl-O\tOpen a simulation (Configuration file).",
311  "Open &Network...\tCtl-N\tOpen a network.",
314  "&Reload\tCtl-R\tReloads the simulation / the network.",
316  new FXMenuSeparator(myFileMenu);
318  "&Close\tCtl-W\tClose the simulation.",
320  // Recent files
321  FXMenuSeparator* sep1 = new FXMenuSeparator(myFileMenu);
322  sep1->setTarget(&myRecentConfigs);
323  sep1->setSelector(FXRecentFiles::ID_ANYFILES);
324  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_1);
325  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_2);
326  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_3);
327  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_4);
328  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_5);
329  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_6);
330  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_7);
331  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_8);
332  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_9);
333  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_10);
334  new FXMenuCommand(myFileMenu, "C&lear Recent Configurations", NULL, &myRecentConfigs, FXRecentFiles::ID_CLEAR);
335  myRecentConfigs.setTarget(this);
336  myRecentConfigs.setSelector(MID_RECENTFILE);
337  FXMenuSeparator* sep2 = new FXMenuSeparator(myFileMenu);
338  sep2->setTarget(&myRecentNets);
339  sep2->setSelector(FXRecentFiles::ID_ANYFILES);
340  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_1);
341  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_2);
342  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_3);
343  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_4);
344  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_5);
345  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_6);
346  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_7);
347  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_8);
348  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_9);
349  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_10);
350  new FXMenuCommand(myFileMenu, "Cl&ear Recent Networks", NULL, &myRecentNets, FXRecentFiles::ID_CLEAR);
351  myRecentNets.setTarget(this);
352  myRecentNets.setSelector(MID_RECENTFILE);
353  new FXMenuSeparator(myFileMenu);
355  "&Quit\tCtl-Q\tQuit the Application.",
356  0, this, MID_QUIT, 0);
357 
358  // build edit menu
359  myEditMenu = new FXMenuPane(this);
360  new FXMenuTitle(myMenuBar, "&Edit", NULL, myEditMenu);
362  "Edit Chosen...\t\tOpens a Dialog for editing the List of chosen Items.",
364  new FXMenuSeparator(myEditMenu);
366  "Edit Breakpoints...\t\tOpens a Dialog for editing breakpoints.",
367  0, this, MID_EDIT_BREAKPOINTS);
368 
369  // build settings menu
370  mySettingsMenu = new FXMenuPane(this);
371  new FXMenuTitle(myMenuBar, "&Settings", NULL, mySettingsMenu);
373  "Application Settings...\t\tOpen a Dialog for Application Settings editing.",
374  NULL, this, MID_APPSETTINGS);
375  new FXMenuCheck(mySettingsMenu,
376  "Gaming Mode\t\tToggle gaming mode on/off.",
377  this, MID_GAMING);
378  new FXMenuCheck(mySettingsMenu,
379  "Locate Internal Structures\t\tList internal junctions and streets in the object locator.",
380  this, MID_LISTINTERNAL);
381 
382  // build windows menu
383  myWindowsMenu = new FXMenuPane(this);
384  new FXMenuTitle(myMenuBar, "&Windows", NULL, myWindowsMenu);
385  new FXMenuCheck(myWindowsMenu,
386  "Show Status Line\t\tToggle this Status Bar on/off.",
387  myStatusbar, FXWindow::ID_TOGGLESHOWN);
388  new FXMenuCheck(myWindowsMenu,
389  "Show Message Window\t\tToggle the Message Window on/off.",
390  myMessageWindow, FXWindow::ID_TOGGLESHOWN);
391  new FXMenuCheck(myWindowsMenu,
392  "Show Simulation Time\t\tToggle the Simulation Time on/off.",
393  myToolBar3, FXWindow::ID_TOGGLESHOWN);
394  new FXMenuCheck(myWindowsMenu,
395  "Show Simulation Delay\t\tToggle the Simulation Delay Entry on/off.",
396  myToolBar4, FXWindow::ID_TOGGLESHOWN);
398  new FXMenuSeparator(myWindowsMenu);
399  new FXMenuCommand(myWindowsMenu, "Tile &Horizontally",
401  myMDIClient, FXMDIClient::ID_MDI_TILEHORIZONTAL);
402  new FXMenuCommand(myWindowsMenu, "Tile &Vertically",
404  myMDIClient, FXMDIClient::ID_MDI_TILEVERTICAL);
405  new FXMenuCommand(myWindowsMenu, "C&ascade",
407  myMDIClient, FXMDIClient::ID_MDI_CASCADE);
408  new FXMenuCommand(myWindowsMenu, "&Close", NULL,
409  myMDIClient, FXMDIClient::ID_MDI_CLOSE);
410  sep1 = new FXMenuSeparator(myWindowsMenu);
411  sep1->setTarget(myMDIClient);
412  sep1->setSelector(FXMDIClient::ID_MDI_ANY);
413  new FXMenuCommand(myWindowsMenu, "", 0, myMDIClient, FXMDIClient::ID_MDI_1);
414  new FXMenuCommand(myWindowsMenu, "", 0, myMDIClient, FXMDIClient::ID_MDI_2);
415  new FXMenuCommand(myWindowsMenu, "", 0, myMDIClient, FXMDIClient::ID_MDI_3);
416  new FXMenuCommand(myWindowsMenu, "", 0, myMDIClient, FXMDIClient::ID_MDI_4);
417  new FXMenuCommand(myWindowsMenu, "&Others...", 0, myMDIClient, FXMDIClient::ID_MDI_OVER_5);
418  new FXMenuSeparator(myWindowsMenu);
420  "Clear Message Window\t\tClear the message window.",
421  0, this, MID_CLEARMESSAGEWINDOW);
422 
423  // build help menu
424  myHelpMenu = new FXMenuPane(this);
425  new FXMenuTitle(myMenuBar, "&Help", NULL, myHelpMenu);
427  this, MID_ABOUT);
428 }
429 
430 
431 void
433  // build tool bars
434  {
435  // file and simulation tool bar
436  myToolBarDrag1 = new FXToolBarShell(this, FRAME_NORMAL);
437  myToolBar1 = new FXToolBar(myTopDock, myToolBarDrag1,
438  LAYOUT_DOCK_NEXT | LAYOUT_SIDE_TOP | FRAME_RAISED);
439  new FXToolBarGrip(myToolBar1, myToolBar1, FXToolBar::ID_TOOLBARGRIP,
440  TOOLBARGRIP_DOUBLE);
441  // build file tools
442  new FXButton(myToolBar1, "\t\tOpen a simulation (Configuration file).",
444  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
445  new FXButton(myToolBar1, "\t\tOpen a network.",
447  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
448  new FXButton(myToolBar1, "\t\tReloads the simulation / the network.",
450  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
451  }
452  {
453  // build simulation tools
454  myToolBarDrag2 = new FXToolBarShell(this, FRAME_NORMAL);
455  myToolBar2 = new FXToolBar(myTopDock, myToolBarDrag2,
456  LAYOUT_DOCK_SAME | LAYOUT_SIDE_TOP | FRAME_RAISED);
457  new FXToolBarGrip(myToolBar2, myToolBar2, FXToolBar::ID_TOOLBARGRIP,
458  TOOLBARGRIP_DOUBLE);
459  new FXButton(myToolBar2, "\t\tStart the loaded simulation.",
461  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
462  new FXButton(myToolBar2, "\t\tStop the running simulation.",
464  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
465  new FXButton(myToolBar2, "\t\tPerform a single simulation step.",
467  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
468  }
469  {
470  // Simulation Step Display
471  myToolBarDrag3 = new FXToolBarShell(this, FRAME_NORMAL);
472  myToolBar3 = new FXToolBar(myTopDock, myToolBarDrag3,
473  LAYOUT_DOCK_SAME | LAYOUT_SIDE_TOP | FRAME_RAISED);
474  new FXToolBarGrip(myToolBar3, myToolBar3, FXToolBar::ID_TOOLBARGRIP,
475  TOOLBARGRIP_DOUBLE);
476  new FXLabel(myToolBar3, "Time:", 0, LAYOUT_CENTER_Y);
477  myLCDLabel = new FXEX::FXLCDLabel(myToolBar3, 9, 0, 0,
482  myLCDLabel->setGroove(2);
483  myLCDLabel->setText("-----------");
484  }
485  {
486  // Simulation Delay
487  myToolBarDrag4 = new FXToolBarShell(this, FRAME_NORMAL);
488  myToolBar4 = new FXToolBar(myTopDock, myToolBarDrag4,
489  LAYOUT_DOCK_SAME | LAYOUT_SIDE_TOP | FRAME_RAISED | LAYOUT_FILL_Y);
490  new FXToolBarGrip(myToolBar4, myToolBar4, FXToolBar::ID_TOOLBARGRIP,
491  TOOLBARGRIP_DOUBLE);
492  new FXLabel(myToolBar4, "Delay (ms):", 0, LAYOUT_CENTER_Y);
495  LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK | LAYOUT_FILL_Y);
497  mySimDelayTarget->setIncrements(1, 10, 10);
498  mySimDelayTarget->setRange(0, 1000);
500  }
501  {
502  // Views
503  myToolBarDrag5 = new FXToolBarShell(this, FRAME_NORMAL);
504  myToolBar5 = new FXToolBar(myTopDock, myToolBarDrag5,
505  LAYOUT_DOCK_SAME | LAYOUT_SIDE_TOP | FRAME_RAISED);
506  new FXToolBarGrip(myToolBar5, myToolBar5, FXToolBar::ID_TOOLBARGRIP,
507  TOOLBARGRIP_DOUBLE);
508  // build view tools
509  new FXButton(myToolBar5, "\t\tOpen a new microscopic view.",
511  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
512 #ifdef HAVE_OSG
513  new FXButton(myToolBar5, "\t\tOpen a new 3D view.",
515  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
516 #endif
517  }
518 }
519 
520 
521 long
523  getApp()->reg().writeIntEntry("SETTINGS", "x", getX());
524  getApp()->reg().writeIntEntry("SETTINGS", "y", getY());
525  getApp()->reg().writeIntEntry("SETTINGS", "width", getWidth());
526  getApp()->reg().writeIntEntry("SETTINGS", "height", getHeight());
527  getApp()->reg().writeStringEntry("SETTINGS", "basedir", gCurrentFolder.text());
528  if (isMaximized()) {
529  getApp()->reg().writeIntEntry("SETTINGS", "maximized", 1);
530  } else {
531  getApp()->reg().writeIntEntry("SETTINGS", "maximized", 0);
532  }
533  getApp()->exit(0);
534  return 1;
535 }
536 
537 
538 long
540  GUIDialog_GLChosenEditor* chooser =
542  chooser->create();
543  chooser->show();
544  return 1;
545 }
546 
547 
548 long
550  GUIDialog_Breakpoints* chooser = new GUIDialog_Breakpoints(this);
551  chooser->create();
552  chooser->show();
553  return 1;
554 }
555 
556 
557 long
559  // get the new file name
560  FXFileDialog opendialog(this, "Open Simulation Configuration");
561  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
562  opendialog.setSelectMode(SELECTFILE_EXISTING);
563  opendialog.setPatternList(myConfigPattern.c_str());
564  if (gCurrentFolder.length() != 0) {
565  opendialog.setDirectory(gCurrentFolder);
566  }
567  if (opendialog.execute()) {
568  gCurrentFolder = opendialog.getDirectory();
569  std::string file = opendialog.getFilename().text();
570  load(file, false);
571  myRecentConfigs.appendFile(file.c_str());
572  }
573  return 1;
574 }
575 
576 
577 long
579  // get the new file name
580  FXFileDialog opendialog(this, "Open Network");
581  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
582  opendialog.setSelectMode(SELECTFILE_EXISTING);
583  opendialog.setPatternList("SUMO nets (*.net.xml)\nAll files (*)");
584  if (gCurrentFolder.length() != 0) {
585  opendialog.setDirectory(gCurrentFolder);
586  }
587  if (opendialog.execute()) {
588  gCurrentFolder = opendialog.getDirectory();
589  std::string file = opendialog.getFilename().text();
590  load(file, true);
591  myRecentNets.appendFile(file.c_str());
592  }
593  return 1;
594 }
595 
596 
597 long
599  load("", false, true);
600  return 1;
601 }
602 
603 
604 long
605 GUIApplicationWindow::onCmdOpenRecent(FXObject* sender, FXSelector, void* data) {
606  if (myAmLoading) {
607  myStatusbar->getStatusLine()->setText("Already loading!");
608  return 1;
609  }
610  std::string file((const char*)data);
611  load(file, sender == &myRecentNets);
612  return 1;
613 }
614 
615 
616 long
618  closeAllWindows();
619  return 1;
620 }
621 
622 
623 long
624 GUIApplicationWindow::onUpdOpen(FXObject* sender, FXSelector, void* ptr) {
625  sender->handle(this,
626  myAmLoading ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
627  ptr);
628  return 1;
629 }
630 
631 
632 long
633 GUIApplicationWindow::onUpdReload(FXObject* sender, FXSelector, void* ptr) {
634  sender->handle(this,
636  ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
637  ptr);
638  return 1;
639 }
640 
641 
642 long
643 GUIApplicationWindow::onUpdOpenRecent(FXObject* sender, FXSelector, void* ptr) {
644  sender->handle(this,
645  myAmLoading ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
646  ptr);
647  return 1;
648 }
649 
650 
651 long
652 GUIApplicationWindow::onUpdAddView(FXObject* sender, FXSelector, void* ptr) {
653  sender->handle(this,
655  ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
656  ptr);
657  return 1;
658 }
659 
660 
661 long
663  // check whether a net was loaded successfully
665  myStatusbar->getStatusLine()->setText("No simulation loaded!");
666  return 1;
667  }
668  // check whether it was started before and paused;
669  if (!myWasStarted) {
670  myRunThread->begin();
671  myWasStarted = true;
672  }
673  myRunThread->resume();
674  return 1;
675 }
676 
677 
678 long
680  myRunThread->stop();
681  return 1;
682 }
683 
684 
685 long
687  // check whether a net was loaded successfully
689  myStatusbar->getStatusLine()->setText("No simulation loaded!");
690  return 1;
691  }
692  // check whether it was started before and paused;
693  if (!myWasStarted) {
694  myRunThread->begin();
695  myWasStarted = true;
696  }
698  return 1;
699 }
700 
701 
702 long
705  return 1;
706 }
707 
708 
709 long
710 GUIApplicationWindow::onUpdStart(FXObject* sender, FXSelector, void* ptr) {
711  sender->handle(this,
713  ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
714  ptr);
715  return 1;
716 }
717 
718 
719 long
720 GUIApplicationWindow::onUpdStop(FXObject* sender, FXSelector, void* ptr) {
721  sender->handle(this,
723  ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
724  ptr);
725  return 1;
726 }
727 
728 
729 long
730 GUIApplicationWindow::onUpdStep(FXObject* sender, FXSelector, void* ptr) {
731  sender->handle(this,
733  ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
734  ptr);
735  return 1;
736 }
737 
738 
739 long
740 GUIApplicationWindow::onUpdEditChosen(FXObject* sender, FXSelector, void* ptr) {
741  sender->handle(this,
743  ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
744  ptr);
745  return 1;
746 }
747 
748 
749 long
750 GUIApplicationWindow::onUpdEditBreakpoints(FXObject* sender, FXSelector, void* ptr) {
751  sender->handle(this,
753  ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
754  ptr);
755  return 1;
756 }
757 
758 
759 long
762  d->create();
763  d->show(PLACEMENT_OWNER);
764  return 1;
765 }
766 
767 
768 long
771  if (myAmGaming) {
772  mySimDelayTarget->setValue(1000);
773  }
774  return 1;
775 }
776 
777 
778 long
781  return 1;
782 }
783 
784 
785 long
788  return 1;
789 }
790 
791 
792 #ifdef HAVE_OSG
793 long
794 GUIApplicationWindow::onCmdNewOSG(FXObject*, FXSelector, void*) {
796  return 1;
797 }
798 #endif
799 
800 
801 long
803  GUIDialog_AboutSUMO* about =
804  new GUIDialog_AboutSUMO(this, "About SUMO", 0, 0);
805  about->create();
806  about->show(PLACEMENT_OWNER);
807  return 1;
808 }
809 
810 
811 long GUIApplicationWindow::onClipboardRequest(FXObject* /* sender */, FXSelector /* sel */, void* ptr) {
812  FXEvent* event = (FXEvent*)ptr;
813  FXString string = GUIUserIO::clipped.c_str();
814  setDNDData(FROM_CLIPBOARD, event->target, string);
815  return 1;
816 }
817 
818 
819 long
821  eventOccured();
822  return 1;
823 }
824 
825 
826 long
828  eventOccured();
829  return 1;
830 }
831 
832 
833 void
835  while (!myEvents.empty()) {
836  // get the next event
837  GUIEvent* e = static_cast<GUIEvent*>(myEvents.top());
838  myEvents.pop();
839  // process
840  switch (e->getOwnType()) {
843  break;
845  if (myRunThread->simulationAvailable()) { // avoid race-condition related crash if reload was pressed
847  }
848  break;
851  case EVENT_ERROR_OCCURED:
853  break;
856  break;
857  default:
858  break;
859  }
860  delete e;
861  }
862  myToolBar2->forceRefresh();
863  myToolBar3->forceRefresh();
864 }
865 
866 
867 void
869  myAmLoading = false;
871  if (ec->myNet != 0) {
872 #ifndef NO_TRACI
873  std::map<int, traci::TraCIServer::CmdExecutor> execs;
876  try {
878  } catch (ProcessError& e) {
880  WRITE_ERROR(e.what());
881  delete ec->myNet;
882  ec->myNet = 0;
883  }
884 #endif
885  }
886 
887  // check whether the loading was successfull
888  if (ec->myNet == 0) {
889  // report failure
890  setStatusBarText("Loading of '" + ec->myFile + "' failed!");
892  closeAllWindows();
893  getApp()->exit(1);
894  }
895  } else {
896  // report success
897  setStatusBarText("'" + ec->myFile + "' loaded.");
898  // initialise simulation thread
899  myRunThread->init(ec->myNet, ec->myBegin, ec->myEnd);
900  myWasStarted = false;
901  // initialise views
902  myViewNumber = 0;
904  if (ec->mySettingsFiles.size() > 0) {
905  // open a view for each file and apply settings
906  for (std::vector<std::string>::const_iterator it = ec->mySettingsFiles.begin();
907  it != ec->mySettingsFiles.end(); ++it) {
908  GUISettingsHandler settings(*it);
909  GUISUMOViewParent::ViewType vt = defaultType;
910  if (settings.getViewType() == "osg" || settings.getViewType() == "3d") {
912  }
913  if (settings.getViewType() == "opengl" || settings.getViewType() == "2d") {
915  }
916  GUISUMOAbstractView* view = openNewView(vt);
917  if (view == 0) {
918  break;
919  }
920  std::string settingsName = settings.addSettings(view);
921  view->addDecals(settings.getDecals());
922  settings.setViewport(view);
923  settings.setSnapshots(view);
924  if (settings.getDelay() > 0) {
925  mySimDelayTarget->setValue(settings.getDelay());
926  }
927  if (settings.getBreakpoints().size() > 0) {
929  }
930  }
931  } else {
932  openNewView(defaultType);
933  }
934 
935  if (isGaming()) {
936  setTitle("SUMO Traffic Light Game");
937  } else {
938  // set simulation name on the caption
939  std::string caption = "SUMO " + std::string(VERSION_STRING);
940  setTitle(MFXUtils::getTitleText(caption.c_str(), ec->myFile.c_str()));
941  }
942  // set simulation step begin information
943  std::string t = time2string(ec->myNet->getCurrentTimeStep());
944  if (myAmGaming || fmod(TS, 1.) == 0.) {
945  myLCDLabel->setText(t.substr(0, t.length() - 3).c_str());
946  } else {
947  myLCDLabel->setText(t.c_str());
948  }
949  }
950  getApp()->endWaitCursor();
951  // start if wished
953  onCmdStart(0, 0, 0);
954  }
955  update();
956 }
957 
958 
959 void
961  updateChildren();
962  std::string t = time2string(myRunThread->getNet().getCurrentTimeStep());
963  if (myAmGaming || fmod(TS, 1.) == 0.) {
964  myLCDLabel->setText(t.substr(0, t.length() - 3).c_str());
965  } else {
966  myLCDLabel->setText(t.c_str());
967  }
968  update();
969 }
970 
971 
972 void
974  GUIEvent_Message* ec = static_cast<GUIEvent_Message*>(e);
976 }
977 
978 
979 void
981  GUIEvent_SimulationEnded* ec = static_cast<GUIEvent_SimulationEnded*>(e);
982  onCmdStop(0, 0, 0);
984  closeAllWindows();
985  getApp()->exit(ec->getReason() == MSNet::SIMSTATE_ERROR_IN_SIM);
986  } else {
987  // build the text
988  const std::string text = "Simulation ended at time: " + time2string(ec->getTimeStep()) +
989  ".\nReason: " + MSNet::getStateMessage(ec->getReason());
990  FXMessageBox::warning(this, MBOX_OK, "Simulation ended", "%s", text.c_str());
991  }
992 }
993 
994 
995 
996 void
997 GUIApplicationWindow::load(const std::string& file, bool isNet, bool isReload) {
998  getApp()->beginWaitCursor();
999  myAmLoading = true;
1000  closeAllWindows();
1001  if (isReload) {
1002  myLoadThread->start();
1003  setStatusBarText("Reloading.");
1004  } else {
1005  gSchemeStorage.saveViewport(0, 0, -1); // recenter view
1006  myLoadThread->load(file, isNet);
1007  setStatusBarText("Loading '" + file + "'.");
1008  }
1009  update();
1010 }
1011 
1012 
1015  if (!myRunThread->simulationAvailable()) {
1016  myStatusbar->getStatusLine()->setText("No simulation loaded!");
1017  return 0;
1018  }
1019  std::string caption = "View #" + toString(myViewNumber++);
1020  FXuint opts = MDI_TRACKING;
1021  GUISUMOViewParent* w = new GUISUMOViewParent(myMDIClient, myMDIMenu, FXString(caption.c_str()),
1022  this, GUIIconSubSys::getIcon(ICON_APP), opts, 10, 10, 300, 200);
1024  w->create();
1025  if (myMDIClient->numChildren() == 1) {
1026  w->maximize();
1027  } else {
1028  myMDIClient->vertical(true);
1029  }
1030  myMDIClient->setActiveChild(w);
1031  return v;
1032 }
1033 
1034 
1035 FXGLCanvas*
1037  if (myMDIClient->numChildren() == 0) {
1038  return 0;
1039  }
1040  GUISUMOViewParent* share_tmp1 =
1041  static_cast<GUISUMOViewParent*>(myMDIClient->childAtIndex(0));
1042  return share_tmp1->getBuildGLCanvas();
1043 }
1044 
1045 
1046 void
1048  myTrackerLock.lock();
1049  myLCDLabel->setText("-----------");
1050  // remove trackers and other external windows
1051  size_t i;
1052  for (i = 0; i < mySubWindows.size(); ++i) {
1053  mySubWindows[i]->destroy();
1054  }
1055  for (i = 0; i < myTrackerWindows.size(); ++i) {
1056  myTrackerWindows[i]->destroy();
1057  }
1058  // delete the simulation
1060  // reset the caption
1061  setTitle(MFXUtils::getTitleText(("SUMO " + std::string(VERSION_STRING)).c_str()));
1062  // delete other children
1063  while (myTrackerWindows.size() != 0) {
1064  delete myTrackerWindows[0];
1065  }
1066  while (mySubWindows.size() != 0) {
1067  delete mySubWindows[0];
1068  }
1069  mySubWindows.clear();
1070  // clear selected items
1071  gSelected.clear();
1072  // add a separator to the log
1075  // remove coordinate information
1076  myGeoCoordinate->setText("N/A");
1077  myCartesianCoordinate->setText("N/A");
1078  //
1080  update();
1081 }
1082 
1083 
1084 FXCursor*
1086  return getApp()->getDefaultCursor(DEF_ARROW_CURSOR);
1087 }
1088 
1089 
1090 SUMOTime
1093 }
1094 
1095 
1096 void
1098  load("", false);
1099 }
1100 
1101 
1102 void
1103 GUIApplicationWindow::setStatusBarText(const std::string& text) {
1104  myStatusbar->getStatusLine()->setText(text.c_str());
1105  myStatusbar->getStatusLine()->setNormalText(text.c_str());
1106 }
1107 
1108 
1109 /****************************************************************************/
1110