SUMO - Simulation of Urban MObility
GUIApplicationWindow.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00010 // The main window of the SUMO-gui.
00011 /****************************************************************************/
00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00014 /****************************************************************************/
00015 //
00016 //   This file is part of SUMO.
00017 //   SUMO is free software: you can redistribute it and/or modify
00018 //   it under the terms of the GNU General Public License as published by
00019 //   the Free Software Foundation, either version 3 of the License, or
00020 //   (at your option) any later version.
00021 //
00022 /****************************************************************************/
00023 
00024 
00025 // ===========================================================================
00026 // included modules
00027 // ===========================================================================
00028 #ifdef _MSC_VER
00029 #include <windows_config.h>
00030 #else
00031 #include <config.h>
00032 #endif
00033 
00034 #ifdef HAVE_VERSION_H
00035 #include <version.h>
00036 #endif
00037 
00038 #include <fx.h>
00039 #include <fx3d.h>
00040 #include <string>
00041 #include <sstream>
00042 #include <algorithm>
00043 
00044 #include <guisim/GUINet.h>
00045 
00046 #include "GUISUMOViewParent.h"
00047 #include "GUILoadThread.h"
00048 #include "GUIRunThread.h"
00049 #include "GUIApplicationWindow.h"
00050 #include "GUIEvent_SimulationLoaded.h"
00051 #include "GUIEvent_SimulationEnded.h"
00052 
00053 #include <utils/common/ToString.h>
00054 #include <utils/foxtools/MFXUtils.h>
00055 #include <utils/foxtools/FXLCDLabel.h>
00056 #include <utils/foxtools/FXRealSpinDial.h>
00057 #include <utils/foxtools/FXThreadEvent.h>
00058 
00059 #include <utils/gui/windows/GUIAppEnum.h>
00060 #include <utils/gui/events/GUIEvent_SimulationStep.h>
00061 #include <utils/gui/events/GUIEvent_Message.h>
00062 #include <utils/gui/div/GUIMessageWindow.h>
00063 #include <utils/gui/div/GUIDialog_GLChosenEditor.h>
00064 #include "GUIGlobals.h"
00065 #include <utils/gui/tracker/GUIParameterTracker.h>
00066 #include <utils/gui/div/GUIParameterTableWindow.h>
00067 #include <utils/gui/images/GUIIconSubSys.h>
00068 #include "dialogs/GUIDialog_AboutSUMO.h"
00069 #include "dialogs/GUIDialog_AppSettings.h"
00070 #include "dialogs/GUIDialog_Breakpoints.h"
00071 #include <utils/gui/div/GUIIOGlobals.h>
00072 #include <utils/gui/div/GUIUserIO.h>
00073 #include <utils/gui/settings/GUICompleteSchemeStorage.h>
00074 #include <utils/gui/globjects/GUIGlObjectStorage.h>
00075 #include <utils/gui/div/GUIGlobalSelection.h>
00076 #include <utils/gui/settings/GUISettingsHandler.h>
00077 
00078 #ifndef NO_TRACI
00079 #include <traci-server/TraCIServer.h>
00080 #include "TraCIServerAPI_GUI.h"
00081 #endif
00082 
00083 #ifdef CHECK_MEMORY_LEAKS
00084 #include <foreign/nvwa/debug_new.h>
00085 #endif
00086 
00087 
00088 // ===========================================================================
00089 // FOX-declarations
00090 // ===========================================================================
00091 FXDEFMAP(GUIApplicationWindow) GUIApplicationWindowMap[] = {
00092     FXMAPFUNC(SEL_COMMAND,  MID_QUIT,        GUIApplicationWindow::onCmdQuit),
00093     FXMAPFUNC(SEL_SIGNAL,   MID_QUIT,        GUIApplicationWindow::onCmdQuit),
00094     FXMAPFUNC(SEL_CLOSE,    MID_WINDOW,      GUIApplicationWindow::onCmdQuit),
00095 
00096     FXMAPFUNC(SEL_COMMAND,  MID_OPEN_CONFIG,       GUIApplicationWindow::onCmdOpenConfiguration),
00097     FXMAPFUNC(SEL_COMMAND,  MID_OPEN_NETWORK,      GUIApplicationWindow::onCmdOpenNetwork),
00098     FXMAPFUNC(SEL_COMMAND,  MID_RECENTFILE,        GUIApplicationWindow::onCmdOpenRecent),
00099     FXMAPFUNC(SEL_COMMAND,  MID_RELOAD,            GUIApplicationWindow::onCmdReload),
00100     FXMAPFUNC(SEL_COMMAND,  MID_CLOSE,             GUIApplicationWindow::onCmdClose),
00101     FXMAPFUNC(SEL_COMMAND,  MID_EDITCHOSEN,        GUIApplicationWindow::onCmdEditChosen),
00102     FXMAPFUNC(SEL_COMMAND,  MID_EDIT_BREAKPOINTS,  GUIApplicationWindow::onCmdEditBreakpoints),
00103 
00104     FXMAPFUNC(SEL_COMMAND,  MID_APPSETTINGS,        GUIApplicationWindow::onCmdAppSettings),
00105     FXMAPFUNC(SEL_COMMAND,  MID_GAMING,             GUIApplicationWindow::onCmdGaming),
00106     FXMAPFUNC(SEL_COMMAND,  MID_LISTINTERNAL,       GUIApplicationWindow::onCmdListInternal),
00107     FXMAPFUNC(SEL_COMMAND,  MID_ABOUT,              GUIApplicationWindow::onCmdAbout),
00108     FXMAPFUNC(SEL_COMMAND,  MID_NEW_MICROVIEW,      GUIApplicationWindow::onCmdNewView),
00109 #ifdef HAVE_OSG
00110     FXMAPFUNC(SEL_COMMAND,  MID_NEW_OSGVIEW,        GUIApplicationWindow::onCmdNewOSG),
00111 #endif
00112     FXMAPFUNC(SEL_COMMAND,  MID_START,              GUIApplicationWindow::onCmdStart),
00113     FXMAPFUNC(SEL_COMMAND,  MID_STOP,               GUIApplicationWindow::onCmdStop),
00114     FXMAPFUNC(SEL_COMMAND,  MID_STEP,               GUIApplicationWindow::onCmdStep),
00115     FXMAPFUNC(SEL_COMMAND,  MID_CLEARMESSAGEWINDOW, GUIApplicationWindow::onCmdClearMsgWindow),
00116 
00117     FXMAPFUNC(SEL_UPDATE,   MID_OPEN_CONFIG,       GUIApplicationWindow::onUpdOpen),
00118     FXMAPFUNC(SEL_UPDATE,   MID_OPEN_NETWORK,      GUIApplicationWindow::onUpdOpen),
00119     FXMAPFUNC(SEL_UPDATE,   MID_RELOAD,            GUIApplicationWindow::onUpdReload),
00120     FXMAPFUNC(SEL_UPDATE,   MID_RECENTFILE,        GUIApplicationWindow::onUpdOpenRecent),
00121     FXMAPFUNC(SEL_UPDATE,   MID_NEW_MICROVIEW,     GUIApplicationWindow::onUpdAddView),
00122 #ifdef HAVE_OSG
00123     FXMAPFUNC(SEL_COMMAND,  MID_NEW_OSGVIEW,        GUIApplicationWindow::onUpdAddView),
00124 #endif
00125     FXMAPFUNC(SEL_UPDATE,   MID_START,             GUIApplicationWindow::onUpdStart),
00126     FXMAPFUNC(SEL_UPDATE,   MID_STOP,              GUIApplicationWindow::onUpdStop),
00127     FXMAPFUNC(SEL_UPDATE,   MID_STEP,              GUIApplicationWindow::onUpdStep),
00128     FXMAPFUNC(SEL_UPDATE,   MID_EDITCHOSEN,        GUIApplicationWindow::onUpdEditChosen),
00129     FXMAPFUNC(SEL_UPDATE,   MID_EDIT_BREAKPOINTS,  GUIApplicationWindow::onUpdEditBreakpoints),
00130 
00131     FXMAPFUNC(SEL_CLIPBOARD_REQUEST, 0, GUIApplicationWindow::onClipboardRequest),
00132 
00133     FXMAPFUNC(FXEX::SEL_THREAD_EVENT, ID_LOADTHREAD_EVENT, GUIApplicationWindow::onLoadThreadEvent),
00134     FXMAPFUNC(FXEX::SEL_THREAD_EVENT, ID_RUNTHREAD_EVENT,  GUIApplicationWindow::onRunThreadEvent),
00135     FXMAPFUNC(FXEX::SEL_THREAD, ID_LOADTHREAD_EVENT,       GUIApplicationWindow::onLoadThreadEvent),
00136     FXMAPFUNC(FXEX::SEL_THREAD, ID_RUNTHREAD_EVENT,        GUIApplicationWindow::onRunThreadEvent),
00137 };
00138 
00139 // Object implementation
00140 FXIMPLEMENT(GUIApplicationWindow, FXMainWindow, GUIApplicationWindowMap, ARRAYNUMBER(GUIApplicationWindowMap))
00141 
00142 // ===========================================================================
00143 // member method definitions
00144 // ===========================================================================
00145 GUIApplicationWindow::GUIApplicationWindow(FXApp* a,
00146         const std::string& configPattern)
00147     : GUIMainWindow(a),
00148       myLoadThread(0), myRunThread(0),
00149       myAmLoading(false),
00150       mySimDelay(50), myConfigPattern(configPattern), hadDependentBuild(false), myRecentNets(a, "nets") {
00151     GUIIconSubSys::init(a);
00152 }
00153 
00154 
00155 void
00156 GUIApplicationWindow::dependentBuild(bool game) {
00157     // do this not twice
00158     if (hadDependentBuild) {
00159         return;
00160     }
00161     hadDependentBuild = true;
00162 
00163     setTarget(this);
00164     setSelector(MID_WINDOW);
00165 
00166     // build menu bar
00167     myMenuBarDrag = new FXToolBarShell(this, FRAME_NORMAL);
00168     myMenuBar = new FXMenuBar(myTopDock, myMenuBarDrag,
00169                               LAYOUT_SIDE_TOP | LAYOUT_FILL_X | FRAME_RAISED);
00170     new FXToolBarGrip(myMenuBar, myMenuBar, FXMenuBar::ID_TOOLBARGRIP,
00171                       TOOLBARGRIP_DOUBLE);
00172     buildToolBars();
00173     // build the thread - io
00174     myLoadThreadEvent.setTarget(this),
00175                                 myLoadThreadEvent.setSelector(ID_LOADTHREAD_EVENT);
00176     myRunThreadEvent.setTarget(this),
00177                                myRunThreadEvent.setSelector(ID_RUNTHREAD_EVENT);
00178 
00179     // build the status bar
00180     myStatusbar = new FXStatusBar(this, LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X | FRAME_RAISED);
00181     {
00182         myGeoFrame =
00183             new FXHorizontalFrame(myStatusbar, LAYOUT_FIX_WIDTH | LAYOUT_FILL_Y | LAYOUT_RIGHT | FRAME_SUNKEN,
00184                                   0, 0, 20, 0, 0, 0, 0, 0, 0, 0);
00185         myGeoCoordinate = new FXLabel(myGeoFrame, "N/A", 0, LAYOUT_CENTER_Y);
00186         myCartesianFrame =
00187             new FXHorizontalFrame(myStatusbar, LAYOUT_FIX_WIDTH | LAYOUT_FILL_Y | LAYOUT_RIGHT | FRAME_SUNKEN,
00188                                   0, 0, 20, 0, 0, 0, 0, 0, 0, 0);
00189         myCartesianCoordinate = new FXLabel(myCartesianFrame, "N/A", 0, LAYOUT_CENTER_Y);
00190     }
00191 
00192     // make the window a mdi-window
00193     myMainSplitter = new FXSplitter(this,
00194                                     SPLITTER_REVERSED | SPLITTER_VERTICAL | LAYOUT_FILL_X | LAYOUT_FILL_Y | SPLITTER_TRACKING | FRAME_RAISED | FRAME_THICK);
00195     myMDIClient = new FXMDIClient(myMainSplitter,
00196                                   LAYOUT_FILL_X | LAYOUT_FILL_Y | FRAME_SUNKEN | FRAME_THICK);
00197     myMDIMenu = new FXMDIMenu(this, myMDIClient);
00198     new FXMDIWindowButton(myMenuBar, myMDIMenu, myMDIClient,
00199                           FXMDIClient::ID_MDI_MENUWINDOW, LAYOUT_LEFT);
00200     new FXMDIDeleteButton(myMenuBar, myMDIClient,
00201                           FXMDIClient::ID_MDI_MENUCLOSE, FRAME_RAISED | LAYOUT_RIGHT);
00202     new FXMDIRestoreButton(myMenuBar, myMDIClient,
00203                            FXMDIClient::ID_MDI_MENURESTORE, FRAME_RAISED | LAYOUT_RIGHT);
00204     new FXMDIMinimizeButton(myMenuBar, myMDIClient,
00205                             FXMDIClient::ID_MDI_MENUMINIMIZE, FRAME_RAISED | LAYOUT_RIGHT);
00206 
00207     // build the message window
00208     myMessageWindow = new GUIMessageWindow(myMainSplitter);
00209     // fill menu and tool bar
00210     fillMenuBar();
00211     if (game) {
00212         onCmdGaming(0, 0, 0);
00213         myMenuBar->hide();
00214         myToolBar1->hide();
00215         myToolBar2->hide();
00216         myToolBar4->hide();
00217         myToolBar5->hide();
00218         myMessageWindow->hide();
00219     }
00220     // build additional threads
00221     myLoadThread = new GUILoadThread(getApp(), this, myEvents, myLoadThreadEvent);
00222     myRunThread = new GUIRunThread(getApp(), this, *mySimDelayTarget, myEvents,
00223                                    myRunThreadEvent);
00224     // set the status bar
00225     myStatusbar->getStatusLine()->setText("Ready.");
00226     // set the caption
00227     setTitle(MFXUtils::getTitleText(("SUMO " + std::string(VERSION_STRING)).c_str()));
00228 
00229     // start the simulation-thread (it will loop until the application ends deciding by itself whether to perform a step or not)
00230     myRunThread->start();
00231     setIcon(GUIIconSubSys::getIcon(ICON_APP));
00232 }
00233 
00234 
00235 void
00236 GUIApplicationWindow::create() {
00237     if (getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 0) {
00238         setX(getApp()->reg().readIntEntry("SETTINGS", "x", 150));
00239         setY(getApp()->reg().readIntEntry("SETTINGS", "y", 150));
00240         setWidth(getApp()->reg().readIntEntry("SETTINGS", "width", 600));
00241         setHeight(getApp()->reg().readIntEntry("SETTINGS", "height", 400));
00242     }
00243     gCurrentFolder = getApp()->reg().readStringEntry("SETTINGS", "basedir", "");
00244     FXMainWindow::create();
00245     myMenuBarDrag->create();
00246     myToolBarDrag1->create();
00247     myToolBarDrag2->create();
00248     myFileMenu->create();
00249     myEditMenu->create();
00250     mySettingsMenu->create();
00251     myWindowsMenu->create();
00252     myHelpMenu->create();
00253 
00254     FXint width = getApp()->getNormalFont()->getTextWidth("8", 1) * 22;
00255     myCartesianFrame->setWidth(width);
00256     myGeoFrame->setWidth(width);
00257 
00258     show(PLACEMENT_SCREEN);
00259     if (getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 1) {
00260         maximize();
00261     }
00262 }
00263 
00264 
00265 GUIApplicationWindow::~GUIApplicationWindow() {
00266     myRunThread->prepareDestruction();
00267     myRunThread->join();
00268     closeAllWindows();
00269     //
00270     GUIIconSubSys::close();
00271     delete myGLVisual;
00272     // delete some non-parented windows
00273     delete myToolBarDrag1;
00274     //
00275     delete myRunThread;
00276     delete myFileMenu;
00277     delete myEditMenu;
00278     delete mySettingsMenu;
00279     delete myWindowsMenu;
00280     delete myHelpMenu;
00281 
00282     delete myLoadThread;
00283 
00284     while (!myEvents.empty()) {
00285         // get the next event
00286         GUIEvent* e = static_cast<GUIEvent*>(myEvents.top());
00287         myEvents.pop();
00288         delete e;
00289     }
00290 }
00291 
00292 
00293 void
00294 GUIApplicationWindow::detach() {
00295     FXMainWindow::detach();
00296     myMenuBarDrag->detach();
00297     myToolBarDrag1->detach();
00298 }
00299 
00300 
00301 void
00302 GUIApplicationWindow::fillMenuBar() {
00303     // build file menu
00304     myFileMenu = new FXMenuPane(this);
00305     new FXMenuTitle(myMenuBar, "&File", NULL, myFileMenu);
00306     new FXMenuCommand(myFileMenu,
00307                       "&Open Simulation...\tCtl-O\tOpen a simulation (Configuration file).",
00308                       GUIIconSubSys::getIcon(ICON_OPEN_CONFIG), this, MID_OPEN_CONFIG);
00309     new FXMenuCommand(myFileMenu,
00310                       "Open &Network...\tCtl-N\tOpen a network.",
00311                       GUIIconSubSys::getIcon(ICON_OPEN_NET), this, MID_OPEN_NETWORK);
00312     new FXMenuCommand(myFileMenu,
00313                       "&Reload\tCtl-R\tReloads the simulation / the network.",
00314                       GUIIconSubSys::getIcon(ICON_RELOAD), this, MID_RELOAD);
00315     new FXMenuSeparator(myFileMenu);
00316     new FXMenuCommand(myFileMenu,
00317                       "&Close\tCtl-W\tClose the simulation.",
00318                       GUIIconSubSys::getIcon(ICON_CLOSE), this, MID_CLOSE);
00319     // Recent files
00320     FXMenuSeparator* sep1 = new FXMenuSeparator(myFileMenu);
00321     sep1->setTarget(&myRecentConfigs);
00322     sep1->setSelector(FXRecentFiles::ID_ANYFILES);
00323     new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_1);
00324     new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_2);
00325     new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_3);
00326     new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_4);
00327     new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_5);
00328     new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_6);
00329     new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_7);
00330     new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_8);
00331     new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_9);
00332     new FXMenuCommand(myFileMenu, "", 0, &myRecentConfigs, FXRecentFiles::ID_FILE_10);
00333     new FXMenuCommand(myFileMenu, "C&lear Recent Configurations", NULL, &myRecentConfigs, FXRecentFiles::ID_CLEAR);
00334     myRecentConfigs.setTarget(this);
00335     myRecentConfigs.setSelector(MID_RECENTFILE);
00336     FXMenuSeparator* sep2 = new FXMenuSeparator(myFileMenu);
00337     sep2->setTarget(&myRecentNets);
00338     sep2->setSelector(FXRecentFiles::ID_ANYFILES);
00339     new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_1);
00340     new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_2);
00341     new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_3);
00342     new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_4);
00343     new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_5);
00344     new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_6);
00345     new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_7);
00346     new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_8);
00347     new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_9);
00348     new FXMenuCommand(myFileMenu, "", 0, &myRecentNets, FXRecentFiles::ID_FILE_10);
00349     new FXMenuCommand(myFileMenu, "Cl&ear Recent Networks", NULL, &myRecentNets, FXRecentFiles::ID_CLEAR);
00350     myRecentNets.setTarget(this);
00351     myRecentNets.setSelector(MID_RECENTFILE);
00352     new FXMenuSeparator(myFileMenu);
00353     new FXMenuCommand(myFileMenu,
00354                       "&Quit\tCtl-Q\tQuit the Application.",
00355                       0, this, MID_QUIT, 0);
00356 
00357     // build edit menu
00358     myEditMenu = new FXMenuPane(this);
00359     new FXMenuTitle(myMenuBar, "&Edit", NULL, myEditMenu);
00360     new FXMenuCommand(myEditMenu,
00361                       "Edit Chosen...\t\tOpens a Dialog for editing the List of chosen Items.",
00362                       GUIIconSubSys::getIcon(ICON_FLAG), this, MID_EDITCHOSEN);
00363     new FXMenuSeparator(myEditMenu);
00364     new FXMenuCommand(myEditMenu,
00365                       "Edit Breakpoints...\t\tOpens a Dialog for editing breakpoints.",
00366                       0, this, MID_EDIT_BREAKPOINTS);
00367 
00368     // build settings menu
00369     mySettingsMenu = new FXMenuPane(this);
00370     new FXMenuTitle(myMenuBar, "&Settings", NULL, mySettingsMenu);
00371     new FXMenuCommand(mySettingsMenu,
00372                       "Application Settings...\t\tOpen a Dialog for Application Settings editing.",
00373                       NULL, this, MID_APPSETTINGS);
00374     new FXMenuCheck(mySettingsMenu,
00375                     "Gaming Mode\t\tToggle gaming mode on/off.",
00376                     this, MID_GAMING);
00377     new FXMenuCheck(mySettingsMenu,
00378                     "Locate Internal Structures\t\tList internal junctions and streets in the object locator.",
00379                     this, MID_LISTINTERNAL);
00380 
00381     // build windows menu
00382     myWindowsMenu = new FXMenuPane(this);
00383     new FXMenuTitle(myMenuBar, "&Windows", NULL, myWindowsMenu);
00384     new FXMenuCheck(myWindowsMenu,
00385                     "Show Status Line\t\tToggle this Status Bar on/off.",
00386                     myStatusbar, FXWindow::ID_TOGGLESHOWN);
00387     new FXMenuCheck(myWindowsMenu,
00388                     "Show Message Window\t\tToggle the Message Window on/off.",
00389                     myMessageWindow, FXWindow::ID_TOGGLESHOWN);
00390     new FXMenuCheck(myWindowsMenu,
00391                     "Show Simulation Time\t\tToggle the Simulation Time on/off.",
00392                     myToolBar3, FXWindow::ID_TOGGLESHOWN);
00393     new FXMenuCheck(myWindowsMenu,
00394                     "Show Simulation Delay\t\tToggle the Simulation Delay Entry on/off.",
00395                     myToolBar4, FXWindow::ID_TOGGLESHOWN);
00396     addToWindowsMenu(myWindowsMenu);
00397     new FXMenuSeparator(myWindowsMenu);
00398     new FXMenuCommand(myWindowsMenu, "Tile &Horizontally",
00399                       GUIIconSubSys::getIcon(ICON_WINDOWS_TILE_HORI),
00400                       myMDIClient, FXMDIClient::ID_MDI_TILEHORIZONTAL);
00401     new FXMenuCommand(myWindowsMenu, "Tile &Vertically",
00402                       GUIIconSubSys::getIcon(ICON_WINDOWS_TILE_VERT),
00403                       myMDIClient, FXMDIClient::ID_MDI_TILEVERTICAL);
00404     new FXMenuCommand(myWindowsMenu, "C&ascade",
00405                       GUIIconSubSys::getIcon(ICON_WINDOWS_CASCADE),
00406                       myMDIClient, FXMDIClient::ID_MDI_CASCADE);
00407     new FXMenuCommand(myWindowsMenu, "&Close", NULL,
00408                       myMDIClient, FXMDIClient::ID_MDI_CLOSE);
00409     sep1 = new FXMenuSeparator(myWindowsMenu);
00410     sep1->setTarget(myMDIClient);
00411     sep1->setSelector(FXMDIClient::ID_MDI_ANY);
00412     new FXMenuCommand(myWindowsMenu, "", 0, myMDIClient, FXMDIClient::ID_MDI_1);
00413     new FXMenuCommand(myWindowsMenu, "", 0, myMDIClient, FXMDIClient::ID_MDI_2);
00414     new FXMenuCommand(myWindowsMenu, "", 0, myMDIClient, FXMDIClient::ID_MDI_3);
00415     new FXMenuCommand(myWindowsMenu, "", 0, myMDIClient, FXMDIClient::ID_MDI_4);
00416     new FXMenuCommand(myWindowsMenu, "&Others...", 0, myMDIClient, FXMDIClient::ID_MDI_OVER_5);
00417     new FXMenuSeparator(myWindowsMenu);
00418     new FXMenuCommand(myWindowsMenu,
00419                       "Clear Message Window\t\tClear the message window.",
00420                       0, this, MID_CLEARMESSAGEWINDOW);
00421 
00422     // build help menu
00423     myHelpMenu = new FXMenuPane(this);
00424     new FXMenuTitle(myMenuBar, "&Help", NULL, myHelpMenu);
00425     new FXMenuCommand(myHelpMenu, "&About", GUIIconSubSys::getIcon(ICON_APP),
00426                       this, MID_ABOUT);
00427 }
00428 
00429 
00430 void
00431 GUIApplicationWindow::buildToolBars() {
00432     // build tool bars
00433     {
00434         // file and simulation tool bar
00435         myToolBarDrag1 = new FXToolBarShell(this, FRAME_NORMAL);
00436         myToolBar1 = new FXToolBar(myTopDock, myToolBarDrag1,
00437                                    LAYOUT_DOCK_NEXT | LAYOUT_SIDE_TOP | FRAME_RAISED);
00438         new FXToolBarGrip(myToolBar1, myToolBar1, FXToolBar::ID_TOOLBARGRIP,
00439                           TOOLBARGRIP_DOUBLE);
00440         // build file tools
00441         new FXButton(myToolBar1, "\t\tOpen a simulation (Configuration file).",
00442                      GUIIconSubSys::getIcon(ICON_OPEN_CONFIG), this, MID_OPEN_CONFIG,
00443                      ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
00444         new FXButton(myToolBar1, "\t\tOpen a network.",
00445                      GUIIconSubSys::getIcon(ICON_OPEN_NET), this, MID_OPEN_NETWORK,
00446                      ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
00447         new FXButton(myToolBar1, "\t\tReloads the simulation / the network.",
00448                      GUIIconSubSys::getIcon(ICON_RELOAD), this, MID_RELOAD,
00449                      ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
00450     }
00451     {
00452         // build simulation tools
00453         myToolBarDrag2 = new FXToolBarShell(this, FRAME_NORMAL);
00454         myToolBar2 = new FXToolBar(myTopDock, myToolBarDrag2,
00455                                    LAYOUT_DOCK_SAME | LAYOUT_SIDE_TOP | FRAME_RAISED);
00456         new FXToolBarGrip(myToolBar2, myToolBar2, FXToolBar::ID_TOOLBARGRIP,
00457                           TOOLBARGRIP_DOUBLE);
00458         new FXButton(myToolBar2, "\t\tStart the loaded simulation.",
00459                      GUIIconSubSys::getIcon(ICON_START), this, MID_START,
00460                      ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
00461         new FXButton(myToolBar2, "\t\tStop the running simulation.",
00462                      GUIIconSubSys::getIcon(ICON_STOP), this, MID_STOP,
00463                      ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
00464         new FXButton(myToolBar2, "\t\tPerform a single simulation step.",
00465                      GUIIconSubSys::getIcon(ICON_STEP), this, MID_STEP,
00466                      ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
00467     }
00468     {
00469         // Simulation Step Display
00470         myToolBarDrag3 = new FXToolBarShell(this, FRAME_NORMAL);
00471         myToolBar3 = new FXToolBar(myTopDock, myToolBarDrag3,
00472                                    LAYOUT_DOCK_SAME | LAYOUT_SIDE_TOP | FRAME_RAISED);
00473         new FXToolBarGrip(myToolBar3, myToolBar3, FXToolBar::ID_TOOLBARGRIP,
00474                           TOOLBARGRIP_DOUBLE);
00475         new FXLabel(myToolBar3, "Time:", 0, LAYOUT_CENTER_Y);
00476         myLCDLabel = new FXEX::FXLCDLabel(myToolBar3, 9, 0, 0,
00477                                           FXEX::LCDLABEL_LEADING_ZEROS);
00478         myLCDLabel->setHorizontal(2);
00479         myLCDLabel->setVertical(6);
00480         myLCDLabel->setThickness(2);
00481         myLCDLabel->setGroove(2);
00482         myLCDLabel->setText("-----------");
00483     }
00484     {
00485         // Simulation Delay
00486         myToolBarDrag4 = new FXToolBarShell(this, FRAME_NORMAL);
00487         myToolBar4 = new FXToolBar(myTopDock, myToolBarDrag4,
00488                                    LAYOUT_DOCK_SAME | LAYOUT_SIDE_TOP | FRAME_RAISED | LAYOUT_FILL_Y);
00489         new FXToolBarGrip(myToolBar4, myToolBar4, FXToolBar::ID_TOOLBARGRIP,
00490                           TOOLBARGRIP_DOUBLE);
00491         new FXLabel(myToolBar4, "Delay (ms):", 0, LAYOUT_CENTER_Y);
00492         mySimDelayTarget =
00493             new FXRealSpinDial(myToolBar4, 7, 0, MID_SIMDELAY,
00494                                LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK | LAYOUT_FILL_Y);
00495         mySimDelayTarget->setNumberFormat(0);
00496         mySimDelayTarget->setIncrements(1, 10, 10);
00497         mySimDelayTarget->setRange(0, 1000);
00498         mySimDelayTarget->setValue(0);
00499     }
00500     {
00501         // Views
00502         myToolBarDrag5 = new FXToolBarShell(this, FRAME_NORMAL);
00503         myToolBar5 = new FXToolBar(myTopDock, myToolBarDrag5,
00504                                    LAYOUT_DOCK_SAME | LAYOUT_SIDE_TOP | FRAME_RAISED);
00505         new FXToolBarGrip(myToolBar5, myToolBar5, FXToolBar::ID_TOOLBARGRIP,
00506                           TOOLBARGRIP_DOUBLE);
00507         // build view tools
00508         new FXButton(myToolBar5, "\t\tOpen a new microscopic view.",
00509                      GUIIconSubSys::getIcon(ICON_MICROVIEW), this, MID_NEW_MICROVIEW,
00510                      ICON_ABOVE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
00511 #ifdef HAVE_OSG
00512         new FXButton(myToolBar5,"\t\tOpen a new 3D view.",
00513                      GUIIconSubSys::getIcon(ICON_MICROVIEW), this, MID_NEW_OSGVIEW,
00514                      ICON_ABOVE_TEXT|BUTTON_TOOLBAR|FRAME_RAISED|LAYOUT_TOP|LAYOUT_LEFT);
00515 #endif
00516     }
00517 }
00518 
00519 
00520 long
00521 GUIApplicationWindow::onCmdQuit(FXObject*, FXSelector, void*) {
00522     getApp()->reg().writeIntEntry("SETTINGS", "x", getX());
00523     getApp()->reg().writeIntEntry("SETTINGS", "y", getY());
00524     getApp()->reg().writeIntEntry("SETTINGS", "width", getWidth());
00525     getApp()->reg().writeIntEntry("SETTINGS", "height", getHeight());
00526     getApp()->reg().writeStringEntry("SETTINGS", "basedir", gCurrentFolder.text());
00527     if (isMaximized()) {
00528         getApp()->reg().writeIntEntry("SETTINGS", "maximized", 1);
00529     } else {
00530         getApp()->reg().writeIntEntry("SETTINGS", "maximized", 0);
00531     }
00532     getApp()->exit(0);
00533     return 1;
00534 }
00535 
00536 
00537 long
00538 GUIApplicationWindow::onCmdEditChosen(FXObject*, FXSelector, void*) {
00539     GUIDialog_GLChosenEditor* chooser =
00540         new GUIDialog_GLChosenEditor(this, &gSelected);
00541     chooser->create();
00542     chooser->show();
00543     return 1;
00544 }
00545 
00546 
00547 long
00548 GUIApplicationWindow::onCmdEditBreakpoints(FXObject*, FXSelector, void*) {
00549     GUIDialog_Breakpoints* chooser =
00550         new GUIDialog_Breakpoints(this);
00551     chooser->create();
00552     chooser->show();
00553     return 1;
00554 }
00555 
00556 
00557 long
00558 GUIApplicationWindow::onCmdOpenConfiguration(FXObject*, FXSelector, void*) {
00559     // get the new file name
00560     FXFileDialog opendialog(this, "Open Simulation Configuration");
00561     opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
00562     opendialog.setSelectMode(SELECTFILE_EXISTING);
00563     opendialog.setPatternList(myConfigPattern.c_str());
00564     if (gCurrentFolder.length() != 0) {
00565         opendialog.setDirectory(gCurrentFolder);
00566     }
00567     if (opendialog.execute()) {
00568         gCurrentFolder = opendialog.getDirectory();
00569         std::string file = opendialog.getFilename().text();
00570         load(file, false);
00571         myRecentConfigs.appendFile(file.c_str());
00572     }
00573     return 1;
00574 }
00575 
00576 
00577 long
00578 GUIApplicationWindow::onCmdOpenNetwork(FXObject*, FXSelector, void*) {
00579     // get the new file name
00580     FXFileDialog opendialog(this, "Open Network");
00581     opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
00582     opendialog.setSelectMode(SELECTFILE_EXISTING);
00583     opendialog.setPatternList("SUMO nets (*.net.xml)\nAll files (*)");
00584     if (gCurrentFolder.length() != 0) {
00585         opendialog.setDirectory(gCurrentFolder);
00586     }
00587     if (opendialog.execute()) {
00588         gCurrentFolder = opendialog.getDirectory();
00589         std::string file = opendialog.getFilename().text();
00590         load(file, true);
00591         myRecentNets.appendFile(file.c_str());
00592     }
00593     return 1;
00594 }
00595 
00596 
00597 long
00598 GUIApplicationWindow::onCmdReload(FXObject*, FXSelector, void*) {
00599     load("", false, true);
00600     return 1;
00601 }
00602 
00603 
00604 long
00605 GUIApplicationWindow::onCmdOpenRecent(FXObject* sender, FXSelector, void* data) {
00606     if (myAmLoading) {
00607         myStatusbar->getStatusLine()->setText("Already loading!");
00608         return 1;
00609     }
00610     std::string file((const char*)data);
00611     load(file, sender == &myRecentNets);
00612     return 1;
00613 }
00614 
00615 
00616 long
00617 GUIApplicationWindow::onCmdClose(FXObject*, FXSelector, void*) {
00618     closeAllWindows();
00619     return 1;
00620 }
00621 
00622 
00623 long
00624 GUIApplicationWindow::onUpdOpen(FXObject* sender, FXSelector, void* ptr) {
00625     sender->handle(this,
00626                    myAmLoading ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
00627                    ptr);
00628     return 1;
00629 }
00630 
00631 
00632 long
00633 GUIApplicationWindow::onUpdReload(FXObject* sender, FXSelector, void* ptr) {
00634     sender->handle(this,
00635                    myAmLoading || !myRunThread->simulationAvailable()
00636                    ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
00637                    ptr);
00638     return 1;
00639 }
00640 
00641 
00642 long
00643 GUIApplicationWindow::onUpdOpenRecent(FXObject* sender, FXSelector, void* ptr) {
00644     sender->handle(this,
00645                    myAmLoading ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
00646                    ptr);
00647     return 1;
00648 }
00649 
00650 
00651 long
00652 GUIApplicationWindow::onUpdAddView(FXObject* sender, FXSelector, void* ptr) {
00653     sender->handle(this,
00654                    myAmLoading || !myRunThread->simulationAvailable()
00655                    ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
00656                    ptr);
00657     return 1;
00658 }
00659 
00660 
00661 long
00662 GUIApplicationWindow::onCmdStart(FXObject*, FXSelector, void*) {
00663     // check whether a net was loaded successfully
00664     if (!myRunThread->simulationAvailable()) {
00665         myStatusbar->getStatusLine()->setText("No simulation loaded!");
00666         return 1;
00667     }
00668     // check whether it was started before and paused;
00669     if (!myWasStarted) {
00670         myRunThread->begin();
00671         myWasStarted = true;
00672     }
00673     myRunThread->resume();
00674     return 1;
00675 }
00676 
00677 
00678 long
00679 GUIApplicationWindow::onCmdStop(FXObject*, FXSelector, void*) {
00680     myRunThread->stop();
00681     return 1;
00682 }
00683 
00684 
00685 long
00686 GUIApplicationWindow::onCmdStep(FXObject*, FXSelector, void*) {
00687     // check whether a net was loaded successfully
00688     if (!myRunThread->simulationAvailable()) {
00689         myStatusbar->getStatusLine()->setText("No simulation loaded!");
00690         return 1;
00691     }
00692     // check whether it was started before and paused;
00693     if (!myWasStarted) {
00694         myRunThread->begin();
00695         myWasStarted = true;
00696     }
00697     myRunThread->singleStep();
00698     return 1;
00699 }
00700 
00701 
00702 long
00703 GUIApplicationWindow::onCmdClearMsgWindow(FXObject*, FXSelector, void*) {
00704     myMessageWindow->clear();
00705     return 1;
00706 }
00707 
00708 
00709 long
00710 GUIApplicationWindow::onUpdStart(FXObject* sender, FXSelector, void* ptr) {
00711     sender->handle(this,
00712                    !myRunThread->simulationIsStartable() || myAmLoading
00713                    ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
00714                    ptr);
00715     return 1;
00716 }
00717 
00718 
00719 long
00720 GUIApplicationWindow::onUpdStop(FXObject* sender, FXSelector, void* ptr) {
00721     sender->handle(this,
00722                    !myRunThread->simulationIsStopable() || myAmLoading
00723                    ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
00724                    ptr);
00725     return 1;
00726 }
00727 
00728 
00729 long
00730 GUIApplicationWindow::onUpdStep(FXObject* sender, FXSelector, void* ptr) {
00731     sender->handle(this,
00732                    !myRunThread->simulationIsStepable() || myAmLoading
00733                    ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
00734                    ptr);
00735     return 1;
00736 }
00737 
00738 
00739 long
00740 GUIApplicationWindow::onUpdEditChosen(FXObject* sender, FXSelector, void* ptr) {
00741     sender->handle(this,
00742                    !myRunThread->simulationAvailable() || myAmLoading
00743                    ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
00744                    ptr);
00745     return 1;
00746 }
00747 
00748 
00749 long
00750 GUIApplicationWindow::onUpdEditBreakpoints(FXObject* sender, FXSelector, void* ptr) {
00751     sender->handle(this,
00752                    !myRunThread->simulationAvailable() || myAmLoading
00753                    ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
00754                    ptr);
00755     return 1;
00756 }
00757 
00758 
00759 long
00760 GUIApplicationWindow::onCmdAppSettings(FXObject*, FXSelector, void*) {
00761     GUIDialog_AppSettings* d = new GUIDialog_AppSettings(this);
00762     d->create();
00763     d->show(PLACEMENT_OWNER);
00764     return 1;
00765 }
00766 
00767 
00768 long
00769 GUIApplicationWindow::onCmdGaming(FXObject*, FXSelector, void*) {
00770     myAmGaming = !myAmGaming;
00771     if (myAmGaming) {
00772         mySimDelayTarget->setValue(1000);
00773     }
00774     return 1;
00775 }
00776 
00777 
00778 long
00779 GUIApplicationWindow::onCmdListInternal(FXObject*, FXSelector, void*) {
00780     myListInternal = !myListInternal;
00781     return 1;
00782 }
00783 
00784 
00785 long
00786 GUIApplicationWindow::onCmdNewView(FXObject*, FXSelector, void*) {
00787     openNewView(GUISUMOViewParent::VIEW_2D_OPENGL);
00788     return 1;
00789 }
00790 
00791 
00792 #ifdef HAVE_OSG
00793 long
00794 GUIApplicationWindow::onCmdNewOSG(FXObject*,FXSelector,void*)
00795 {
00796     openNewView(GUISUMOViewParent::VIEW_3D_OSG);
00797     return 1;
00798 }
00799 #endif
00800 
00801 
00802 long
00803 GUIApplicationWindow::onCmdAbout(FXObject*, FXSelector, void*) {
00804     GUIDialog_AboutSUMO* about =
00805         new GUIDialog_AboutSUMO(this, "About SUMO", 0, 0);
00806     about->create();
00807     about->show(PLACEMENT_OWNER);
00808     return 1;
00809 }
00810 
00811 
00812 long GUIApplicationWindow::onClipboardRequest(FXObject* sender, FXSelector sel, void* ptr) {
00813     FXEvent* event = (FXEvent*)ptr;
00814     FXString string = GUIUserIO::clipped.c_str();
00815     setDNDData(FROM_CLIPBOARD, event->target, string);
00816     return 1;
00817 }
00818 
00819 
00820 long
00821 GUIApplicationWindow::onLoadThreadEvent(FXObject*, FXSelector, void*) {
00822     eventOccured();
00823     return 1;
00824 }
00825 
00826 
00827 long
00828 GUIApplicationWindow::onRunThreadEvent(FXObject*, FXSelector, void*) {
00829     eventOccured();
00830     return 1;
00831 }
00832 
00833 
00834 void
00835 GUIApplicationWindow::eventOccured() {
00836     while (!myEvents.empty()) {
00837         // get the next event
00838         GUIEvent* e = static_cast<GUIEvent*>(myEvents.top());
00839         myEvents.pop();
00840         // process
00841         switch (e->getOwnType()) {
00842             case EVENT_SIMULATION_LOADED:
00843                 handleEvent_SimulationLoaded(e);
00844                 break;
00845             case EVENT_SIMULATION_STEP:
00846                 if (myRunThread->simulationAvailable()) { // avoid race-condition related crash if reload was pressed
00847                     handleEvent_SimulationStep(e);
00848                 }
00849                 break;
00850             case EVENT_MESSAGE_OCCURED:
00851             case EVENT_WARNING_OCCURED:
00852             case EVENT_ERROR_OCCURED:
00853                 handleEvent_Message(e);
00854                 break;
00855             case EVENT_SIMULATION_ENDED:
00856                 handleEvent_SimulationEnded(e);
00857                 break;
00858             default:
00859                 break;
00860         }
00861         delete e;
00862     }
00863     myToolBar2->forceRefresh();
00864     myToolBar3->forceRefresh();
00865 }
00866 
00867 
00868 void
00869 GUIApplicationWindow::handleEvent_SimulationLoaded(GUIEvent* e) {
00870     myAmLoading = false;
00871     GUIEvent_SimulationLoaded* ec = static_cast<GUIEvent_SimulationLoaded*>(e);
00872     if (ec->myNet != 0) {
00873 #ifndef NO_TRACI
00874         std::map<int, traci::TraCIServer::CmdExecutor> execs;
00875         execs[CMD_GET_GUI_VARIABLE] = &TraCIServerAPI_GUI::processGet;
00876         execs[CMD_SET_GUI_VARIABLE] = &TraCIServerAPI_GUI::processSet;
00877         try {
00878             traci::TraCIServer::openSocket(execs);
00879         } catch (ProcessError& e) {
00880             myMessageWindow->appendText(EVENT_ERROR_OCCURED, e.what());
00881             WRITE_ERROR(e.what());
00882             delete ec->myNet;
00883             ec->myNet = 0;
00884         }
00885 #endif
00886     }
00887 
00888     // check whether the loading was successfull
00889     if (ec->myNet == 0) {
00890         // report failure
00891         setStatusBarText("Loading of '" + ec->myFile + "' failed!");
00892         if (GUIGlobals::gQuitOnEnd) {
00893             closeAllWindows();
00894             getApp()->exit(1);
00895         }
00896     } else {
00897         // report success
00898         setStatusBarText("'" + ec->myFile + "' loaded.");
00899         // initialise simulation thread
00900         myRunThread->init(ec->myNet, ec->myBegin, ec->myEnd);
00901         myWasStarted = false;
00902         // initialise views
00903         myViewNumber = 0;
00904         GUISUMOAbstractView* view = openNewView();
00905         if (view && ec->mySettingsFile != "") {
00906             GUISettingsHandler settings(ec->mySettingsFile);
00907             std::string settingsName = settings.addSettings(view);
00908             view->addDecals(settings.getDecals());
00909             settings.setViewport(view);
00910             settings.setSnapshots(view);
00911             if (settings.getDelay() > 0) {
00912                 mySimDelayTarget->setValue(settings.getDelay());
00913             }
00914         }
00915         if (isGaming()) {
00916             setTitle("SUMO Traffic Light Game");
00917         } else {
00918             // set simulation name on the caption
00919             std::string caption = "SUMO " + std::string(VERSION_STRING);
00920             setTitle(MFXUtils::getTitleText(caption.c_str(), ec->myFile.c_str()));
00921         }
00922         // set simulation step begin information
00923         std::string t = time2string(ec->myNet->getCurrentTimeStep());
00924         if (myAmGaming || fmod(TS, 1.) == 0.) {
00925             myLCDLabel->setText(t.substr(0, t.length() - 3).c_str());
00926         } else {
00927             myLCDLabel->setText(t.c_str());
00928         }
00929     }
00930     getApp()->endWaitCursor();
00931     // start if wished
00932     if (GUIGlobals::gRunAfterLoad && ec->myNet != 0 && myRunThread->simulationIsStartable()) {
00933         onCmdStart(0, 0, 0);
00934     }
00935     update();
00936 }
00937 
00938 
00939 void
00940 GUIApplicationWindow::handleEvent_SimulationStep(GUIEvent*) {
00941     updateChildren();
00942     std::string t = time2string(myRunThread->getNet().getCurrentTimeStep());
00943     if (myAmGaming || fmod(TS, 1.) == 0.) {
00944         myLCDLabel->setText(t.substr(0, t.length() - 3).c_str());
00945     } else {
00946         myLCDLabel->setText(t.c_str());
00947     }
00948     update();
00949 }
00950 
00951 
00952 void
00953 GUIApplicationWindow::handleEvent_Message(GUIEvent* e) {
00954     GUIEvent_Message* ec = static_cast<GUIEvent_Message*>(e);
00955     myMessageWindow->appendText(ec->getOwnType(), ec->getMsg());
00956 }
00957 
00958 
00959 void
00960 GUIApplicationWindow::handleEvent_SimulationEnded(GUIEvent* e) {
00961     GUIEvent_SimulationEnded* ec = static_cast<GUIEvent_SimulationEnded*>(e);
00962     onCmdStop(0, 0, 0);
00963     if (GUIGlobals::gQuitOnEnd) {
00964         closeAllWindows();
00965         getApp()->exit(ec->getReason() == MSNet::SIMSTATE_ERROR_IN_SIM);
00966     } else {
00967         // build the text
00968         const std::string text = "Simulation ended at time: " + time2string(ec->getTimeStep()) +
00969                                  ".\nReason: " + MSNet::getStateMessage(ec->getReason());
00970         FXMessageBox::warning(this, MBOX_OK, "Simulation ended", "%s", text.c_str());
00971     }
00972 }
00973 
00974 
00975 
00976 void
00977 GUIApplicationWindow::load(const std::string& file, bool isNet, bool isReload) {
00978     getApp()->beginWaitCursor();
00979     myAmLoading = true;
00980     closeAllWindows();
00981     if (isReload) {
00982         myLoadThread->start();
00983         setStatusBarText("Reloading.");
00984     } else {
00985         gSchemeStorage.saveViewport(0, 0, -1); // recenter view
00986         myLoadThread->load(file, isNet);
00987         setStatusBarText("Loading '" + file + "'.");
00988     }
00989     update();
00990 }
00991 
00992 
00993 GUISUMOAbstractView*
00994 GUIApplicationWindow::openNewView(GUISUMOViewParent::ViewType vt) {
00995     if (!myRunThread->simulationAvailable()) {
00996         myStatusbar->getStatusLine()->setText("No simulation loaded!");
00997         return 0;
00998     }
00999     std::string caption = "View #" + toString(myViewNumber++);
01000     FXuint opts = MDI_TRACKING;
01001     GUISUMOViewParent* w = new GUISUMOViewParent(myMDIClient, myMDIMenu, FXString(caption.c_str()),
01002             this, GUIIconSubSys::getIcon(ICON_APP), opts, 10, 10, 300, 200);
01003     GUISUMOAbstractView* v = w->init(getBuildGLCanvas(), myRunThread->getNet(), vt);
01004     w->create();
01005     if (myMDIClient->numChildren() == 1) {
01006         w->maximize();
01007     } else {
01008         myMDIClient->vertical(true);
01009     }
01010     myMDIClient->setActiveChild(w);
01011     return v;
01012 }
01013 
01014 
01015 FXGLCanvas*
01016 GUIApplicationWindow::getBuildGLCanvas() const {
01017     if (myMDIClient->numChildren() == 0) {
01018         return 0;
01019     }
01020     GUISUMOViewParent* share_tmp1 =
01021         static_cast<GUISUMOViewParent*>(myMDIClient->childAtIndex(0));
01022     return share_tmp1->getBuildGLCanvas();
01023 }
01024 
01025 
01026 void
01027 GUIApplicationWindow::closeAllWindows() {
01028     myTrackerLock.lock();
01029     myLCDLabel->setText("-----------");
01030     // remove trackers and other external windows
01031     size_t i;
01032     for (i = 0; i < mySubWindows.size(); ++i) {
01033         mySubWindows[i]->destroy();
01034     }
01035     for (i = 0; i < myTrackerWindows.size(); ++i) {
01036         myTrackerWindows[i]->destroy();
01037     }
01038     // delete the simulation
01039     myRunThread->deleteSim();
01040     // reset the caption
01041     setTitle(MFXUtils::getTitleText(("SUMO " + std::string(VERSION_STRING)).c_str()));
01042     // delete other children
01043     while (myTrackerWindows.size() != 0) {
01044         delete myTrackerWindows[0];
01045     }
01046     while (mySubWindows.size() != 0) {
01047         delete mySubWindows[0];
01048     }
01049     mySubWindows.clear();
01050     // clear selected items
01051     gSelected.clear();
01052     // add a separator to the log
01053     myMessageWindow->addSeparator();
01054     myTrackerLock.unlock();
01055     // remove coordinate information
01056     myGeoCoordinate->setText("N/A");
01057     myCartesianCoordinate->setText("N/A");
01058     //
01059     update();
01060 }
01061 
01062 
01063 FXCursor*
01064 GUIApplicationWindow::getDefaultCursor() {
01065     return getApp()->getDefaultCursor(DEF_ARROW_CURSOR);
01066 }
01067 
01068 
01069 SUMOTime
01070 GUIApplicationWindow::getCurrentSimTime() const {
01071     return myRunThread->getNet().getCurrentTimeStep();
01072 }
01073 
01074 
01075 void
01076 GUIApplicationWindow::loadOnStartup() {
01077     load("", false);
01078 }
01079 
01080 
01081 void
01082 GUIApplicationWindow::setStatusBarText(const std::string& text) {
01083     myStatusbar->getStatusLine()->setText(text.c_str());
01084     myStatusbar->getStatusLine()->setNormalText(text.c_str());
01085 }
01086 
01087 
01088 /****************************************************************************/
01089 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines