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