SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GUIMainWindow.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 //
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <algorithm>
35 #include <fx.h>
36 #include <fx3d.h>
41 #include "GUIAppEnum.h"
42 #include "GUIMainWindow.h"
43 #include "GUIGlChildWindow.h"
44 
45 #ifdef CHECK_MEMORY_LEAKS
46 #include <foreign/nvwa/debug_new.h>
47 #endif // CHECK_MEMORY_LEAKS
48 
49 
50 // ===========================================================================
51 // static member definitions
52 // ===========================================================================
54 
55 // ===========================================================================
56 // member method definitions
57 // ===========================================================================
59  : FXMainWindow(a, "SUMO-gui main window", NULL, NULL, DECOR_ALL, 20, 20, 600, 400),
60  myGLVisual(new FXGLVisual(a, VISUAL_DOUBLEBUFFER)),
61  myAmGaming(false), myListInternal(false) {
62 
63  FXFontDesc fdesc;
64  getApp()->getNormalFont()->getFontDesc(fdesc);
65  fdesc.weight = FXFont::Bold;
66  myBoldFont = new FXFont(getApp(), fdesc);
67 
68  myTopDock = new FXDockSite(this, LAYOUT_SIDE_TOP | LAYOUT_FILL_X);
69  myBottomDock = new FXDockSite(this, LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X);
70  myLeftDock = new FXDockSite(this, LAYOUT_SIDE_LEFT | LAYOUT_FILL_Y);
71  myRightDock = new FXDockSite(this, LAYOUT_SIDE_RIGHT | LAYOUT_FILL_Y);
72  if (myInstance != 0) {
73  throw ProcessError("MainWindow initialized twice");
74  }
75  myInstance = this;
76  //myGLVisual->setStencilSize(8); // enable stencil buffer
77 }
78 
79 
81  delete myBoldFont;
82  delete myTopDock;
83  delete myBottomDock;
84  delete myLeftDock;
85  delete myRightDock;
86 }
87 
88 
89 
90 void
91 GUIMainWindow::addChild(FXMDIChild* child, bool /*updateOnSimStep !!!*/) {
92  mySubWindows.push_back(child);
93 }
94 
95 
96 void
97 GUIMainWindow::removeChild(FXMDIChild* child) {
98  std::vector<FXMDIChild*>::iterator i = std::find(mySubWindows.begin(), mySubWindows.end(), child);
99  if (i != mySubWindows.end()) {
100  mySubWindows.erase(i);
101  }
102 }
103 
104 
105 void
106 GUIMainWindow::addChild(FXMainWindow* child, bool /*updateOnSimStep !!!*/) {
108  myTrackerWindows.push_back(child);
110 }
111 
112 
113 void
114 GUIMainWindow::removeChild(FXMainWindow* child) {
116  std::vector<FXMainWindow*>::iterator i = std::find(myTrackerWindows.begin(), myTrackerWindows.end(), child);
117  myTrackerWindows.erase(i);
119 }
120 
121 
122 std::vector<std::string>
124  std::vector<std::string> ret;
125  for (std::vector<FXMDIChild*>::const_iterator i = mySubWindows.begin(); i != mySubWindows.end(); ++i) {
126  ret.push_back((*i)->getTitle().text());
127  }
128  return ret;
129 }
130 
131 
132 FXMDIChild*
133 GUIMainWindow::getViewByID(const std::string& id) const {
134  for (std::vector<FXMDIChild*>::const_iterator i = mySubWindows.begin(); i != mySubWindows.end(); ++i) {
135  if (std::string((*i)->getTitle().text()) == id) {
136  return *i;
137  }
138  }
139  return 0;
140 }
141 
142 
143 FXFont*
145  return myBoldFont;
146 }
147 
148 
149 void
151  // inform views
152  myMDIClient->forallWindows(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), 0);
153  // inform other windows
155  for (int i = 0; i < (int)myTrackerWindows.size(); i++) {
156  myTrackerWindows[i]->handle(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), 0);
157  }
159 }
160 
161 
162 FXGLVisual*
164  return myGLVisual;
165 }
166 
167 
168 FXLabel&
170  return *myCartesianCoordinate;
171 }
172 
173 
174 FXLabel&
176  return *myGeoCoordinate;
177 }
178 
179 
182  if (myInstance != 0) {
183  return myInstance;
184  }
185  throw ProcessError("A GUIMainWindow instance was not yet constructed.");
186 }
187 
188 
191  GUIGlChildWindow* w = dynamic_cast<GUIGlChildWindow*>(myMDIClient->getActiveChild());
192  if (w != 0) {
193  return w->getView();
194  }
195  return 0;
196 }
197 
198 /****************************************************************************/
199 
std::vector< FXMainWindow * > myTrackerWindows
FXLabel * myGeoCoordinate
GUISUMOAbstractView * getView() const
FXFont * myBoldFont
Font used for popup-menu titles.
FXDockSite * myRightDock
FXGLVisual * myGLVisual
The gl-visual used.
FXMDIChild * getViewByID(const std::string &id) const
#define new
Definition: debug_new.h:121
FXLabel & getCartesianLabel()
std::vector< FXMDIChild * > mySubWindows
void addChild(FXMDIChild *child, bool updateOnSimStep=true)
Adds a further child window to the list.
GUISUMOAbstractView * getActiveView() const
get the active view or 0
static GUIMainWindow * getInstance()
FXDockSite * myLeftDock
A Simulation step was performed.
Definition: GUIAppEnum.h:291
static GUIMainWindow * myInstance
the singleton window instance
FXFont * getBoldFont()
FXGLVisual * getGLVisual() const
FXLabel & getGeoLabel()
void removeChild(FXMDIChild *child)
removes the given child window from the list
void unlock()
release mutex lock
Definition: MFXMutex.cpp:96
FXLabel * myCartesianCoordinate
Labels for the current cartesian and geo-coordinate.
FXDockSite * myBottomDock
MFXMutex myTrackerLock
A lock to make the removal and addition of trackers secure.
FXDockSite * myTopDock
virtual ~GUIMainWindow()
void lock()
lock mutex
Definition: MFXMutex.cpp:86
FXMDIClient * myMDIClient
The multi view panel.
std::vector< std::string > getViewIDs() const