Eclipse SUMO - Simulation of Urban MObility
GUIMainWindow.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20//
21/****************************************************************************/
22#include <config.h>
23
24#include <string>
25#include <algorithm>
27// fx3d includes windows.h so we need to guard against macro pollution
28#ifdef WIN32
29#define NOMINMAX
30#endif
31#include <fx3d.h>
32#ifdef WIN32
33#undef NOMINMAX
34#endif
41#include "GUIMainWindow.h"
42#include "GUIGlChildWindow.h"
43
44
45// ===========================================================================
46// static member definitions
47// ===========================================================================
49
50// ===========================================================================
51// member method definitions
52// ===========================================================================
54 FXMainWindow(app, "sumo-gui main window", nullptr, nullptr, DECOR_ALL, 20, 20, 600, 400),
55 myAmFullScreen(false),
56 myTrackerLock(true),
57 myGLVisual(new FXGLVisual(app, VISUAL_DOUBLEBUFFER)),
58 myAmGaming(false),
59 myListInternal(false),
60 myListParking(true),
61 myListTeleporting(false) {
62 // build static tooltips
65 // build bold font
66 FXFontDesc fdesc;
67 app->getNormalFont()->getFontDesc(fdesc);
68 fdesc.weight = FXFont::Bold;
69 myBoldFont = new FXFont(app, fdesc);
70 // https://en.wikipedia.org/wiki/Noto_fonts should be widely available
71 myFallbackFont = new FXFont(app, "Noto Sans CJK JP");
72 // build docks
73 myTopDock = new FXDockSite(this, LAYOUT_SIDE_TOP | LAYOUT_FILL_X);
74 myBottomDock = new FXDockSite(this, LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X);
75 myLeftDock = new FXDockSite(this, LAYOUT_SIDE_LEFT | LAYOUT_FILL_Y);
76 myRightDock = new FXDockSite(this, LAYOUT_SIDE_RIGHT | LAYOUT_FILL_Y);
77 // avoid instance Windows twice
78 if (myInstance != nullptr) {
79 throw ProcessError("MainWindow initialized twice");
80 }
81 myInstance = this;
82 //myGLVisual->setStencilSize(8); // enable stencil buffer
83}
84
85
89 delete myBoldFont;
90 delete myFallbackFont;
91 delete myTopDock;
92 delete myBottomDock;
93 delete myLeftDock;
94 delete myRightDock;
95}
96
97
98
99void
101 myGLWindows.push_back(child);
102}
103
104
105void
107 std::vector<GUIGlChildWindow*>::iterator i = std::find(myGLWindows.begin(), myGLWindows.end(), child);
108 if (i != myGLWindows.end()) {
109 myGLWindows.erase(i);
110 }
111}
112
113
114void
115GUIMainWindow::addChild(FXMainWindow* child) {
116 myTrackerLock.lock();
117 myTrackerWindows.push_back(child);
118 myTrackerLock.unlock();
119}
120
121
122void
123GUIMainWindow::removeChild(FXMainWindow* child) {
124 myTrackerLock.lock();
125 std::vector<FXMainWindow*>::iterator i = std::find(myTrackerWindows.begin(), myTrackerWindows.end(), child);
126 myTrackerWindows.erase(i);
127 myTrackerLock.unlock();
128}
129
130
131FXDockSite*
133 return myTopDock;
134}
135
136
137std::vector<std::string>
139 std::vector<std::string> ret;
140 for (GUIGlChildWindow* const window : myGLWindows) {
141 ret.push_back(window->getTitle().text());
142 }
143 return ret;
144}
145
146
148GUIMainWindow::getViewByID(const std::string& id) const {
149 for (GUIGlChildWindow* const window : myGLWindows) {
150 if (std::string(window->getTitle().text()) == id) {
151 return window;
152 }
153 }
154 return nullptr;
155}
156
157
158void
159GUIMainWindow::removeViewByID(const std::string& id) {
160 for (GUIGlChildWindow* const window : myGLWindows) {
161 if (std::string(window->getTitle().text()) == id) {
162 window->close();
163 removeGLChild(window);
164 return;
165 }
166 }
167}
168
169
170FXFont*
172 return myBoldFont;
173}
174
175FXFont*
177 return myFallbackFont;
178}
179
180const std::vector<GUIGlChildWindow*>&
182 return myGLWindows;
183}
184
185
186void
188 // inform views
189 myMDIClient->forallWindows(this, FXSEL(SEL_COMMAND, msg), nullptr);
190 // inform other windows
191 myTrackerLock.lock();
192 for (int i = 0; i < (int)myTrackerWindows.size(); i++) {
193 myTrackerWindows[i]->handle(this, FXSEL(SEL_COMMAND, msg), nullptr);
194 }
195 myTrackerLock.unlock();
196}
197
198
199FXGLVisual*
201 return myGLVisual;
202}
203
204
207 return myStaticTooltipMenu;
208}
209
210
213 return myStaticTooltipView;
214}
215
216
217FXLabel*
220}
221
222
223FXLabel*
225 return myGeoCoordinate;
226}
227
228
229FXLabel*
231 return myTestCoordinate;
232}
233
234
235bool
237 return myAmGaming;
238}
239
240
241bool
243 return myListInternal;
244}
245
246
247bool
249 return myListParking;
250}
251
252
253bool
255 return myListTeleporting;
256}
257
258
261 if (myInstance != nullptr) {
262 return myInstance;
263 }
264 throw ProcessError("A GUIMainWindow instance was not yet constructed.");
265}
266
267
270 GUIGlChildWindow* w = dynamic_cast<GUIGlChildWindow*>(myMDIClient->getActiveChild());
271 if (w != nullptr) {
272 return w->getView();
273 }
274 return nullptr;
275}
276
277
278void
280 int windowWidth = getApp()->reg().readIntEntry("SETTINGS", "width", 600);
281 int windowHeight = getApp()->reg().readIntEntry("SETTINGS", "height", 400);
283 if (oc.isSet("window-size")) {
284 std::vector<std::string> windowSize = oc.getStringVector("window-size");
285 if (windowSize.size() != 2) {
286 WRITE_ERROR(TL("option window-size requires INT,INT"));
287 } else {
288 try {
289 windowWidth = StringUtils::toInt(windowSize[0]);
290 windowHeight = StringUtils::toInt(windowSize[1]);
291 } catch (NumberFormatException& e) {
292 WRITE_ERROR("option window-size requires INT,INT " + toString(e.what()));
293 }
294 }
295 }
296 if (oc.isSet("window-size") || getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 0 || oc.isSet("window-pos")) {
297 // when restoring previous pos, make sure the window fits fully onto the current screen
298 int x = MAX2(0, MIN2(getApp()->reg().readIntEntry("SETTINGS", "x", 150), getApp()->getRootWindow()->getWidth() - windowWidth));
299 int y = MAX2(50, MIN2(getApp()->reg().readIntEntry("SETTINGS", "y", 150), getApp()->getRootWindow()->getHeight() - windowHeight));
300 if (oc.isSet("window-pos")) {
301 std::vector<std::string> windowPos = oc.getStringVector("window-pos");
302 if (windowPos.size() != 2) {
303 WRITE_ERROR(TL("option window-pos requires INT,INT"));
304 } else {
305 try {
306 x = StringUtils::toInt(windowPos[0]);
307 y = StringUtils::toInt(windowPos[1]);
308 } catch (NumberFormatException& e) {
309 WRITE_ERROR("option window-pos requires INT,INT " + toString(e.what()));
310 }
311 }
312 }
313 move(x, y);
314 resize(windowWidth, windowHeight);
315 }
316}
317
318void
320 if (!myAmFullScreen) {
321 getApp()->reg().writeIntEntry("SETTINGS", "x", getX());
322 getApp()->reg().writeIntEntry("SETTINGS", "y", getY());
323 getApp()->reg().writeIntEntry("SETTINGS", "width", getWidth());
324 getApp()->reg().writeIntEntry("SETTINGS", "height", getHeight());
325 }
326}
327
328
329/****************************************************************************/
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:274
#define TL(string)
Definition: MsgHandler.h:282
T MIN2(T a, T b)
Definition: StdDefs.h:71
T MAX2(T a, T b)
Definition: StdDefs.h:77
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
GUISUMOAbstractView * getView() const
return GUISUMOAbstractView
void setWindowSizeAndPos()
perform initial window positioning and sizing according to user options / previous call
const std::vector< GUIGlChildWindow * > & getViews() const
get views
bool myListParking
information whether the locator should list parking vehicles
static GUIMainWindow * myInstance
the singleton window instance
virtual ~GUIMainWindow()
destructor
FXDockSite * myRightDock
void removeViewByID(const std::string &id)
GUIGlChildWindow * getViewByID(const std::string &id) const
get specific view by ID
std::vector< FXMainWindow * > myTrackerWindows
list of tracker windows
MFXStaticToolTip * getStaticTooltipView() const
get static toolTip for view
FXFont * myFallbackFont
Fallback font for extended characters support.
std::vector< std::string > getViewIDs() const
get view IDs
GUISUMOAbstractView * getActiveView() const
get the active view or 0
FXLabel * getGeoLabel()
get geo label
bool isGaming() const
return whether the gui is in gaming mode
bool myListTeleporting
information whether the locator should list teleporting vehicles
FXLabel * myCartesianCoordinate
Labels for the current cartesian, geo-coordinate and test coordinates.
MFXStaticToolTip * myStaticTooltipMenu
static toolTip used in menus
FXMDIClient * myMDIClient
The multi view panel.
FXFont * getBoldFont()
get bold front
FXDockSite * myLeftDock
bool listTeleporting() const
return whether to list teleporting vehicles
FXLabel * getTestLabel()
get test label
MFXStaticToolTip * myStaticTooltipView
static toolTip used in view
MFXStaticToolTip * getStaticTooltipMenu() const
get static toolTip for menus
FXFont * myBoldFont
Font used for popup-menu titles.
static GUIMainWindow * getInstance()
get instance
bool listParking() const
return whether to list parking vehicles
FXDockSite * myBottomDock
bool listInternal() const
return whether to list internal structures
void addGLChild(GUIGlChildWindow *child)
Adds a further child window to the list (GUIGlChildWindow)
FXLabel * myTestCoordinate
FXMutex myTrackerLock
A lock to make the removal and addition of trackers secure.
FXDockSite * myTopDock
dock sites
bool myListInternal
information whether the locator should list internal structures
void storeWindowSizeAndPos()
record window position and size in registry
FXLabel * getCartesianLabel()
get cartesian label
FXGLVisual * getGLVisual() const
get GL Visual
bool myAmFullScreen
FOX need this.
void removeGLChild(GUIGlChildWindow *child)
removes the given child window from the list (GUIGlChildWindow)
FXDockSite * getTopDock()
get top dock
FXLabel * myGeoCoordinate
FXFont * getFallbackFont()
get fallback front
void updateChildren(int msg=MID_SIMSTEP)
update childrens
FXGLVisual * myGLVisual
The gl-visual used.
bool myAmGaming
information whether the gui is currently in gaming mode
void removeChild(FXMainWindow *child)
removes the given child window from the list (FXMainWindow)
GUIMainWindow(FXApp *app)
constructor
std::vector< GUIGlChildWindow * > myGLWindows
list of GLWindows
void addChild(FXMainWindow *child)
Adds a further child window to the list (FXMainWindow)
MFXStaticToolTip (based on FXToolTip)
A storage for options typed value containers)
Definition: OptionsCont.h:89
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:59
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...