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-2012 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 <fx.h>
39 #include <fx3d.h>
40 #include <string>
41 #include <sstream>
42 #include <algorithm>
43 
44 #include <guisim/GUINet.h>
45 
46 #include "GUISUMOViewParent.h"
47 #include "GUILoadThread.h"
48 #include "GUIRunThread.h"
49 #include "GUIApplicationWindow.h"
52 
53 #include <utils/common/ToString.h>
58 
64 #include "GUIGlobals.h"
77 
78 #ifndef NO_TRACI
80 #include "TraCIServerAPI_GUI.h"
81 #endif
82 
83 #ifdef CHECK_MEMORY_LEAKS
84 #include <foreign/nvwa/debug_new.h>
85 #endif
86 
87 
88 // ===========================================================================
89 // FOX-declarations
90 // ===========================================================================
91 FXDEFMAP(GUIApplicationWindow) GUIApplicationWindowMap[] = {
92  FXMAPFUNC(SEL_COMMAND, MID_QUIT, GUIApplicationWindow::onCmdQuit),
93  FXMAPFUNC(SEL_SIGNAL, MID_QUIT, GUIApplicationWindow::onCmdQuit),
94  FXMAPFUNC(SEL_CLOSE, MID_WINDOW, GUIApplicationWindow::onCmdQuit),
95 
99  FXMAPFUNC(SEL_COMMAND, MID_RELOAD, GUIApplicationWindow::onCmdReload),
100  FXMAPFUNC(SEL_COMMAND, MID_CLOSE, GUIApplicationWindow::onCmdClose),
101  FXMAPFUNC(SEL_COMMAND, MID_EDITCHOSEN, GUIApplicationWindow::onCmdEditChosen),
103 
105  FXMAPFUNC(SEL_COMMAND, MID_GAMING, GUIApplicationWindow::onCmdGaming),
107  FXMAPFUNC(SEL_COMMAND, MID_ABOUT, GUIApplicationWindow::onCmdAbout),
108  FXMAPFUNC(SEL_COMMAND, MID_NEW_MICROVIEW, GUIApplicationWindow::onCmdNewView),
109 #ifdef HAVE_OSG
110  FXMAPFUNC(SEL_COMMAND, MID_NEW_OSGVIEW, GUIApplicationWindow::onCmdNewOSG),
111 #endif
112  FXMAPFUNC(SEL_COMMAND, MID_START, GUIApplicationWindow::onCmdStart),
113  FXMAPFUNC(SEL_COMMAND, MID_STOP, GUIApplicationWindow::onCmdStop),
114  FXMAPFUNC(SEL_COMMAND, MID_STEP, GUIApplicationWindow::onCmdStep),
116 
117  FXMAPFUNC(SEL_UPDATE, MID_OPEN_CONFIG, GUIApplicationWindow::onUpdOpen),
118  FXMAPFUNC(SEL_UPDATE, MID_OPEN_NETWORK, GUIApplicationWindow::onUpdOpen),
119  FXMAPFUNC(SEL_UPDATE, MID_RELOAD, GUIApplicationWindow::onUpdReload),
122 #ifdef HAVE_OSG
123  FXMAPFUNC(SEL_COMMAND, MID_NEW_OSGVIEW, GUIApplicationWindow::onUpdAddView),
124 #endif
125  FXMAPFUNC(SEL_UPDATE, MID_START, GUIApplicationWindow::onUpdStart),
126  FXMAPFUNC(SEL_UPDATE, MID_STOP, GUIApplicationWindow::onUpdStop),
127  FXMAPFUNC(SEL_UPDATE, MID_STEP, GUIApplicationWindow::onUpdStep),
130 
131  FXMAPFUNC(SEL_CLIPBOARD_REQUEST, 0, GUIApplicationWindow::onClipboardRequest),
132 
137 };
138 
139 // Object implementation
140 FXIMPLEMENT(GUIApplicationWindow, FXMainWindow, GUIApplicationWindowMap, ARRAYNUMBER(GUIApplicationWindowMap))
141 
142 // ===========================================================================
143 // member method definitions
144 // ===========================================================================
146  const std::string& configPattern)
147  : GUIMainWindow(a),
148  myLoadThread(0), myRunThread(0),
149  myAmLoading(false),
150  mySimDelay(50), myConfigPattern(configPattern), hadDependentBuild(false), myRecentNets(a, "nets") {
152 }
153 
154 
155 void
157  // do this not twice
158  if (hadDependentBuild) {
159  return;
160  }
161  hadDependentBuild = true;
162 
163  setTarget(this);
164  setSelector(MID_WINDOW);
165 
166  // build menu bar
167  myMenuBarDrag = new FXToolBarShell(this, FRAME_NORMAL);
168  myMenuBar = new FXMenuBar(myTopDock, myMenuBarDrag,
169  LAYOUT_SIDE_TOP | LAYOUT_FILL_X | FRAME_RAISED);
170  new FXToolBarGrip(myMenuBar, myMenuBar, FXMenuBar::ID_TOOLBARGRIP,
171  TOOLBARGRIP_DOUBLE);
172  buildToolBars();
173  // build the thread - io
178 
179  // build the status bar
180  myStatusbar = new FXStatusBar(this, LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X | FRAME_RAISED);
181  {
182  myGeoFrame =
183  new FXHorizontalFrame(myStatusbar, LAYOUT_FIX_WIDTH | LAYOUT_FILL_Y | LAYOUT_RIGHT | FRAME_SUNKEN,
184  0, 0, 20, 0, 0, 0, 0, 0, 0, 0);
185  myGeoCoordinate = new FXLabel(myGeoFrame, "N/A", 0, LAYOUT_CENTER_Y);
187  new FXHorizontalFrame(myStatusbar, LAYOUT_FIX_WIDTH | LAYOUT_FILL_Y | LAYOUT_RIGHT | FRAME_SUNKEN,
188  0, 0, 20, 0, 0, 0, 0, 0, 0, 0);
189  myCartesianCoordinate = new FXLabel(myCartesianFrame, "N/A", 0, LAYOUT_CENTER_Y);
190  }
191 
192  // make the window a mdi-window
193  myMainSplitter = new FXSplitter(this,
194  SPLITTER_REVERSED | SPLITTER_VERTICAL | LAYOUT_FILL_X | LAYOUT_FILL_Y | SPLITTER_TRACKING | FRAME_RAISED | FRAME_THICK);
195  myMDIClient = new FXMDIClient(myMainSplitter,
196  LAYOUT_FILL_X | LAYOUT_FILL_Y | FRAME_SUNKEN | FRAME_THICK);
197  myMDIMenu = new FXMDIMenu(this, myMDIClient);
198  new FXMDIWindowButton(myMenuBar, myMDIMenu, myMDIClient,
199  FXMDIClient::ID_MDI_MENUWINDOW, LAYOUT_LEFT);
200  new FXMDIDeleteButton(myMenuBar, myMDIClient,
201  FXMDIClient::ID_MDI_MENUCLOSE, FRAME_RAISED | LAYOUT_RIGHT);
202  new FXMDIRestoreButton(myMenuBar, myMDIClient,
203  FXMDIClient::ID_MDI_MENURESTORE, FRAME_RAISED | LAYOUT_RIGHT);
204  new FXMDIMinimizeButton(myMenuBar, myMDIClient,
205  FXMDIClient::ID_MDI_MENUMINIMIZE, FRAME_RAISED | LAYOUT_RIGHT);
206 
207  // build the message window
209  // fill menu and tool bar
210  fillMenuBar();
211  if (game) {
212  onCmdGaming(0, 0, 0);
213  myMenuBar->hide();
214  myToolBar1->hide();
215  myToolBar2->hide();
216  myToolBar4->hide();
217  myToolBar5->hide();
218  myMessageWindow->hide();
219  }
220  // build additional threads
221  myLoadThread = new GUILoadThread(getApp(), this, myEvents, myLoadThreadEvent);
222  myRunThread = new GUIRunThread(getApp(), this, *mySimDelayTarget, myEvents,
224  // set the status bar
225  myStatusbar->getStatusLine()->setText("Ready.");
226  // set the caption
227  setTitle(MFXUtils::getTitleText(("SUMO " + std::string(VERSION_STRING)).c_str()));
228 
229  // start the simulation-thread (it will loop until the application ends deciding by itself whether to perform a step or not)
230  myRunThread->start();
232 }
233 
234 
235 void
237  if (getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 0) {
238  setX(getApp()->reg().readIntEntry("SETTINGS", "x", 150));
239  setY(getApp()->reg().readIntEntry("SETTINGS", "y", 150));
240  setWidth(getApp()->reg().readIntEntry("SETTINGS", "width", 600));
241  setHeight(getApp()->reg().readIntEntry("SETTINGS", "height", 400));
242  }
243  gCurrentFolder = getApp()->reg().readStringEntry("SETTINGS", "basedir", "");
245  myMenuBarDrag->create();
246  myToolBarDrag1->create();
247  myToolBarDrag2->create();
248  myFileMenu->create();
249  myEditMenu->create();
250  mySettingsMenu->create();
251  myWindowsMenu->create();
252  myHelpMenu->create();
253 
254  FXint width = getApp()->getNormalFont()->getTextWidth("8", 1) * 22;
255  myCartesianFrame->setWidth(width);
256  myGeoFrame->setWidth(width);
257 
258  show(PLACEMENT_SCREEN);
259  if (getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 1) {
260  maximize();
261  }
262 }
263 
264 
267  myRunThread->join();
268  closeAllWindows();
269  //
271  delete myGLVisual;
272  // delete some non-parented windows
273  delete myToolBarDrag1;
274  //
275  delete myRunThread;
276  delete myFileMenu;
277  delete myEditMenu;
278  delete mySettingsMenu;
279  delete myWindowsMenu;
280  delete myHelpMenu;
281 
282  delete myLoadThread;
283 
284  while (!myEvents.empty()) {
285  // get the next event
286  GUIEvent* e = static_cast<GUIEvent*>(myEvents.top());
287  myEvents.pop();
288  delete e;
289  }
290 }
291 
292 
293 void
296  myMenuBarDrag->detach();
297  myToolBarDrag1->detach();
298 }
299 
300 
301 void
303  // build file menu
304  myFileMenu = new FXMenuPane(this);
305  new FXMenuTitle(myMenuBar, "&File", NULL, myFileMenu);
307  "&Open Simulation...\tCtl-O\tOpen a simulation (Configuration file).",
310  "Open &Network...\tCtl-N\tOpen a network.",
313  "&Reload\tCtl-R\tReloads the simulation / the network.",
315  new FXMenuSeparator(myFileMenu);
317  "&Close\tCtl-W\tClose the simulation.",
319  // Recent files
320  FXMenuSeparator* sep1 = new FXMenuSeparator(myFileMenu);
321  sep1->setTarget(&myRecentConfigs);
322  sep1->setSelector(FXRecentFiles::ID_ANYFILES);
323  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_1);
324  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_2);
325  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_3);
326  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_4);
327  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_5);
328  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_6);
329  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_7);
330  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_8);
331  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_9);
332  new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_10);
333  new FXMenuCommand(myFileMenu, "C&lear Recent Configurations", NULL, &myRecentConfigs, FXRecentFiles::ID_CLEAR);
334  myRecentConfigs.setTarget(this);
335  myRecentConfigs.setSelector(MID_RECENTFILE);
336  FXMenuSeparator* sep2 = new FXMenuSeparator(myFileMenu);
337  sep2->setTarget(&myRecentNets);
338  sep2->setSelector(FXRecentFiles::ID_ANYFILES);
339  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_1);
340  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_2);
341  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_3);
342  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_4);
343  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_5);
344  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_6);
345  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_7);
346  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_8);
347  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_9);
348  new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_10);
349  new FXMenuCommand(myFileMenu, "Cl&ear Recent Networks", NULL, &myRecentNets, FXRecentFiles::ID_CLEAR);
350  myRecentNets.setTarget(this);
351  myRecentNets.setSelector(MID_RECENTFILE);
352  new FXMenuSeparator(myFileMenu);
354  "&Quit\tCtl-Q\tQuit the Application.",
355  0, this, MID_QUIT, 0);
356 
357  // build edit menu
358  myEditMenu = new FXMenuPane(this);
359  new FXMenuTitle(myMenuBar, "&Edit", NULL, myEditMenu);
361  "Edit Chosen...\t\tOpens a Dialog for editing the List of chosen Items.",
363  new FXMenuSeparator(myEditMenu);
365  "Edit Breakpoints...\t\tOpens a Dialog for editing breakpoints.",
366  0, this, MID_EDIT_BREAKPOINTS);
367 
368  // build settings menu
369  mySettingsMenu = new FXMenuPane(this);
370  new FXMenuTitle(myMenuBar, "&Settings", NULL, mySettingsMenu);
372  "Application Settings...\t\tOpen a Dialog for Application Settings editing.",
373  NULL, this, MID_APPSETTINGS);
374  new FXMenuCheck(mySettingsMenu,
375  "Gaming Mode\t\tToggle gaming mode on/off.",
376  this, MID_GAMING);
377  new FXMenuCheck(mySettingsMenu,
378  "Locate Internal Structures\t\tList internal junctions and streets in the object locator.",
379  this, MID_LISTINTERNAL);
380 
381  // build windows menu
382  myWindowsMenu = new FXMenuPane(this);
383  new FXMenuTitle(myMenuBar, "&Windows", NULL, myWindowsMenu);
384  new FXMenuCheck(myWindowsMenu,
385  "Show Status Line\t\tToggle this Status Bar on/off.",
386  myStatusbar, FXWindow::ID_TOGGLESHOWN);
387  new FXMenuCheck(myWindowsMenu,
388  "Show Message Window\t\tToggle the Message Window on/off.",
389  myMessageWindow, FXWindow::ID_TOGGLESHOWN);
390  new FXMenuCheck(myWindowsMenu,
391  "Show Simulation Time\t\tToggle the Simulation Time on/off.",
392  myToolBar3, FXWindow::ID_TOGGLESHOWN);
393  new FXMenuCheck(myWindowsMenu,
394  "Show Simulation Delay\t\tToggle the Simulation Delay Entry on/off.",
395  myToolBar4, FXWindow::ID_TOGGLESHOWN);
397  new FXMenuSeparator(myWindowsMenu);
398  new FXMenuCommand(myWindowsMenu, "Tile &Horizontally",
400  myMDIClient, FXMDIClient::ID_MDI_TILEHORIZONTAL);
401  new FXMenuCommand(myWindowsMenu, "Tile &Vertically",
403  myMDIClient, FXMDIClient::ID_MDI_TILEVERTICAL);
404  new FXMenuCommand(myWindowsMenu, "C&ascade",
406  myMDIClient, FXMDIClient::ID_MDI_CASCADE);
407  new FXMenuCommand(myWindowsMenu, "&Close", NULL,
408  myMDIClient, FXMDIClient::ID_MDI_CLOSE);
409  sep1 = new FXMenuSeparator(myWindowsMenu);
410  sep1->setTarget(myMDIClient);
411  sep1->setSelector(FXMDIClient::ID_MDI_ANY);
412  new FXMenuCommand(myWindowsMenu, "", 0, myMDIClient, FXMDIClient::ID_MDI_1);
413  new FXMenuCommand(myWindowsMenu, "", 0, myMDIClient, FXMDIClient::ID_MDI_2);
414  new FXMenuCommand(myWindowsMenu, "", 0, myMDIClient, FXMDIClient::ID_MDI_3);
415  new FXMenuCommand(myWindowsMenu, "", 0, myMDIClient, FXMDIClient::ID_MDI_4);
416  new FXMenuCommand(myWindowsMenu, "&Others...", 0, myMDIClient, FXMDIClient::ID_MDI_OVER_5);
417  new FXMenuSeparator(myWindowsMenu);
419  "Clear Message Window\t\tClear the message window.",
420  0, this, MID_CLEARMESSAGEWINDOW);
421 
422  // build help menu
423  myHelpMenu = new FXMenuPane(this);
424  new FXMenuTitle(myMenuBar, "&Help", NULL, myHelpMenu);
426  this, MID_ABOUT);
427 }
428 
429 
430 void
432  // build tool bars
433  {
434  // file and simulation tool bar
435  myToolBarDrag1 = new FXToolBarShell(this, FRAME_NORMAL);
436  myToolBar1 = new FXToolBar(myTopDock, myToolBarDrag1,
437  LAYOUT_DOCK_NEXT | LAYOUT_SIDE_TOP | FRAME_RAISED);
438  new FXToolBarGrip(myToolBar1, myToolBar1, FXToolBar::ID_TOOLBARGRIP,
439  TOOLBARGRIP_DOUBLE);
440  // build file tools
441  new FXButton(myToolBar1, "\t\tOpen a simulation (Configuration file).",
443  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
444  new FXButton(myToolBar1, "\t\tOpen a network.",
446  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
447  new FXButton(myToolBar1, "\t\tReloads the simulation / the network.",
449  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
450  }
451  {
452  // build simulation tools
453  myToolBarDrag2 = new FXToolBarShell(this, FRAME_NORMAL);
454  myToolBar2 = new FXToolBar(myTopDock, myToolBarDrag2,
455  LAYOUT_DOCK_SAME | LAYOUT_SIDE_TOP | FRAME_RAISED);
456  new FXToolBarGrip(myToolBar2, myToolBar2, FXToolBar::ID_TOOLBARGRIP,
457  TOOLBARGRIP_DOUBLE);
458  new FXButton(myToolBar2, "\t\tStart the loaded simulation.",
460  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
461  new FXButton(myToolBar2, "\t\tStop the running simulation.",
463  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
464  new FXButton(myToolBar2, "\t\tPerform a single simulation step.",
466  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
467  }
468  {
469  // Simulation Step Display
470  myToolBarDrag3 = new FXToolBarShell(this, FRAME_NORMAL);
471  myToolBar3 = new FXToolBar(myTopDock, myToolBarDrag3,
472  LAYOUT_DOCK_SAME | LAYOUT_SIDE_TOP | FRAME_RAISED);
473  new FXToolBarGrip(myToolBar3, myToolBar3, FXToolBar::ID_TOOLBARGRIP,
474  TOOLBARGRIP_DOUBLE);
475  new FXLabel(myToolBar3, "Time:", 0, LAYOUT_CENTER_Y);
476  myLCDLabel = new FXEX::FXLCDLabel(myToolBar3, 9, 0, 0,
481  myLCDLabel->setGroove(2);
482  myLCDLabel->setText("-----------");
483  }
484  {
485  // Simulation Delay
486  myToolBarDrag4 = new FXToolBarShell(this, FRAME_NORMAL);
487  myToolBar4 = new FXToolBar(myTopDock, myToolBarDrag4,
488  LAYOUT_DOCK_SAME | LAYOUT_SIDE_TOP | FRAME_RAISED | LAYOUT_FILL_Y);
489  new FXToolBarGrip(myToolBar4, myToolBar4, FXToolBar::ID_TOOLBARGRIP,
490  TOOLBARGRIP_DOUBLE);
491  new FXLabel(myToolBar4, "Delay (ms):", 0, LAYOUT_CENTER_Y);
494  LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK | LAYOUT_FILL_Y);
496  mySimDelayTarget->setIncrements(1, 10, 10);
497  mySimDelayTarget->setRange(0, 1000);
499  }
500  {
501  // Views
502  myToolBarDrag5 = new FXToolBarShell(this, FRAME_NORMAL);
503  myToolBar5 = new FXToolBar(myTopDock, myToolBarDrag5,
504  LAYOUT_DOCK_SAME | LAYOUT_SIDE_TOP | FRAME_RAISED);
505  new FXToolBarGrip(myToolBar5, myToolBar5, FXToolBar::ID_TOOLBARGRIP,
506  TOOLBARGRIP_DOUBLE);
507  // build view tools
508  new FXButton(myToolBar5, "\t\tOpen a new microscopic view.",
510  ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
511 #ifdef HAVE_OSG
512  new FXButton(myToolBar5,"\t\tOpen a new 3D view.",
514  ICON_ABOVE_TEXT|BUTTON_TOOLBAR|FRAME_RAISED|LAYOUT_TOP|LAYOUT_LEFT);
515 #endif
516  }
517 }
518 
519 
520 long
522  getApp()->reg().writeIntEntry("SETTINGS", "x", getX());
523  getApp()->reg().writeIntEntry("SETTINGS", "y", getY());
524  getApp()->reg().writeIntEntry("SETTINGS", "width", getWidth());
525  getApp()->reg().writeIntEntry("SETTINGS", "height", getHeight());
526  getApp()->reg().writeStringEntry("SETTINGS", "basedir", gCurrentFolder.text());
527  if (isMaximized()) {
528  getApp()->reg().writeIntEntry("SETTINGS", "maximized", 1);
529  } else {
530  getApp()->reg().writeIntEntry("SETTINGS", "maximized", 0);
531  }
532  getApp()->exit(0);
533  return 1;
534 }
535 
536 
537 long
539  GUIDialog_GLChosenEditor* chooser =
541  chooser->create();
542  chooser->show();
543  return 1;
544 }
545 
546 
547 long
549  GUIDialog_Breakpoints* chooser =
550  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*)
795 {
797  return 1;
798 }
799 #endif
800 
801 
802 long
804  GUIDialog_AboutSUMO* about =
805  new GUIDialog_AboutSUMO(this, "About SUMO", 0, 0);
806  about->create();
807  about->show(PLACEMENT_OWNER);
808  return 1;
809 }
810 
811 
812 long GUIApplicationWindow::onClipboardRequest(FXObject* sender, FXSelector sel, void* ptr) {
813  FXEvent* event = (FXEvent*)ptr;
814  FXString string = GUIUserIO::clipped.c_str();
815  setDNDData(FROM_CLIPBOARD, event->target, string);
816  return 1;
817 }
818 
819 
820 long
822  eventOccured();
823  return 1;
824 }
825 
826 
827 long
829  eventOccured();
830  return 1;
831 }
832 
833 
834 void
836  while (!myEvents.empty()) {
837  // get the next event
838  GUIEvent* e = static_cast<GUIEvent*>(myEvents.top());
839  myEvents.pop();
840  // process
841  switch (e->getOwnType()) {
844  break;
846  if (myRunThread->simulationAvailable()) { // avoid race-condition related crash if reload was pressed
848  }
849  break;
852  case EVENT_ERROR_OCCURED:
854  break;
857  break;
858  default:
859  break;
860  }
861  delete e;
862  }
863  myToolBar2->forceRefresh();
864  myToolBar3->forceRefresh();
865 }
866 
867 
868 void
870  myAmLoading = false;
872  if (ec->myNet != 0) {
873 #ifndef NO_TRACI
874  std::map<int, traci::TraCIServer::CmdExecutor> execs;
877  try {
879  } catch (ProcessError& e) {
881  WRITE_ERROR(e.what());
882  delete ec->myNet;
883  ec->myNet = 0;
884  }
885 #endif
886  }
887 
888  // check whether the loading was successfull
889  if (ec->myNet == 0) {
890  // report failure
891  setStatusBarText("Loading of '" + ec->myFile + "' failed!");
893  closeAllWindows();
894  getApp()->exit(1);
895  }
896  } else {
897  // report success
898  setStatusBarText("'" + ec->myFile + "' loaded.");
899  // initialise simulation thread
900  myRunThread->init(ec->myNet, ec->myBegin, ec->myEnd);
901  myWasStarted = false;
902  // initialise views
903  myViewNumber = 0;
905  if (view && ec->mySettingsFile != "") {
906  GUISettingsHandler settings(ec->mySettingsFile);
907  std::string settingsName = settings.addSettings(view);
908  view->addDecals(settings.getDecals());
909  settings.setViewport(view);
910  settings.setSnapshots(view);
911  if (settings.getDelay() > 0) {
912  mySimDelayTarget->setValue(settings.getDelay());
913  }
914  }
915  if (isGaming()) {
916  setTitle("SUMO Traffic Light Game");
917  } else {
918  // set simulation name on the caption
919  std::string caption = "SUMO " + std::string(VERSION_STRING);
920  setTitle(MFXUtils::getTitleText(caption.c_str(), ec->myFile.c_str()));
921  }
922  // set simulation step begin information
923  std::string t = time2string(ec->myNet->getCurrentTimeStep());
924  if (myAmGaming || fmod(TS, 1.) == 0.) {
925  myLCDLabel->setText(t.substr(0, t.length() - 3).c_str());
926  } else {
927  myLCDLabel->setText(t.c_str());
928  }
929  }
930  getApp()->endWaitCursor();
931  // start if wished
933  onCmdStart(0, 0, 0);
934  }
935  update();
936 }
937 
938 
939 void
941  updateChildren();
942  std::string t = time2string(myRunThread->getNet().getCurrentTimeStep());
943  if (myAmGaming || fmod(TS, 1.) == 0.) {
944  myLCDLabel->setText(t.substr(0, t.length() - 3).c_str());
945  } else {
946  myLCDLabel->setText(t.c_str());
947  }
948  update();
949 }
950 
951 
952 void
954  GUIEvent_Message* ec = static_cast<GUIEvent_Message*>(e);
956 }
957 
958 
959 void
961  GUIEvent_SimulationEnded* ec = static_cast<GUIEvent_SimulationEnded*>(e);
962  onCmdStop(0, 0, 0);
964  closeAllWindows();
965  getApp()->exit(ec->getReason() == MSNet::SIMSTATE_ERROR_IN_SIM);
966  } else {
967  // build the text
968  const std::string text = "Simulation ended at time: " + time2string(ec->getTimeStep()) +
969  ".\nReason: " + MSNet::getStateMessage(ec->getReason());
970  FXMessageBox::warning(this, MBOX_OK, "Simulation ended", "%s", text.c_str());
971  }
972 }
973 
974 
975 
976 void
977 GUIApplicationWindow::load(const std::string& file, bool isNet, bool isReload) {
978  getApp()->beginWaitCursor();
979  myAmLoading = true;
980  closeAllWindows();
981  if (isReload) {
982  myLoadThread->start();
983  setStatusBarText("Reloading.");
984  } else {
985  gSchemeStorage.saveViewport(0, 0, -1); // recenter view
986  myLoadThread->load(file, isNet);
987  setStatusBarText("Loading '" + file + "'.");
988  }
989  update();
990 }
991 
992 
996  myStatusbar->getStatusLine()->setText("No simulation loaded!");
997  return 0;
998  }
999  std::string caption = "View #" + toString(myViewNumber++);
1000  FXuint opts = MDI_TRACKING;
1001  GUISUMOViewParent* w = new GUISUMOViewParent(myMDIClient, myMDIMenu, FXString(caption.c_str()),
1002  this, GUIIconSubSys::getIcon(ICON_APP), opts, 10, 10, 300, 200);
1004  w->create();
1005  if (myMDIClient->numChildren() == 1) {
1006  w->maximize();
1007  } else {
1008  myMDIClient->vertical(true);
1009  }
1010  myMDIClient->setActiveChild(w);
1011  return v;
1012 }
1013 
1014 
1015 FXGLCanvas*
1017  if (myMDIClient->numChildren() == 0) {
1018  return 0;
1019  }
1020  GUISUMOViewParent* share_tmp1 =
1021  static_cast<GUISUMOViewParent*>(myMDIClient->childAtIndex(0));
1022  return share_tmp1->getBuildGLCanvas();
1023 }
1024 
1025 
1026 void
1028  myTrackerLock.lock();
1029  myLCDLabel->setText("-----------");
1030  // remove trackers and other external windows
1031  size_t i;
1032  for (i = 0; i < mySubWindows.size(); ++i) {
1033  mySubWindows[i]->destroy();
1034  }
1035  for (i = 0; i < myTrackerWindows.size(); ++i) {
1036  myTrackerWindows[i]->destroy();
1037  }
1038  // delete the simulation
1040  // reset the caption
1041  setTitle(MFXUtils::getTitleText(("SUMO " + std::string(VERSION_STRING)).c_str()));
1042  // delete other children
1043  while (myTrackerWindows.size() != 0) {
1044  delete myTrackerWindows[0];
1045  }
1046  while (mySubWindows.size() != 0) {
1047  delete mySubWindows[0];
1048  }
1049  mySubWindows.clear();
1050  // clear selected items
1051  gSelected.clear();
1052  // add a separator to the log
1055  // remove coordinate information
1056  myGeoCoordinate->setText("N/A");
1057  myCartesianCoordinate->setText("N/A");
1058  //
1059  update();
1060 }
1061 
1062 
1063 FXCursor*
1065  return getApp()->getDefaultCursor(DEF_ARROW_CURSOR);
1066 }
1067 
1068 
1069 SUMOTime
1072 }
1073 
1074 
1075 void
1077  load("", false);
1078 }
1079 
1080 
1081 void
1082 GUIApplicationWindow::setStatusBarText(const std::string& text) {
1083  myStatusbar->getStatusLine()->setText(text.c_str());
1084  myStatusbar->getStatusLine()->setNormalText(text.c_str());
1085 }
1086 
1087 
1088 /****************************************************************************/
1089