Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUIMainWindow.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 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
42#include "GUIMainWindow.h"
43#include "GUIGlChildWindow.h"
44
45
46// ===========================================================================
47// static member definitions
48// ===========================================================================
50
51// ===========================================================================
52// member method definitions
53// ===========================================================================
55 FXMainWindow(app, "sumo-gui main window", nullptr, nullptr, DECOR_ALL, 20, 20, 600, 400),
56 myAmFullScreen(false),
57 myTrackerLock(true),
58 myGLVisual(new FXGLVisual(app, VISUAL_DOUBLEBUFFER)),
59 myAmGaming(false),
60 myListInternal(false),
61 myListParking(true),
62 myListTeleporting(false) {
63 // build static tooltips
66 // build bold font
67 FXFontDesc fdesc;
68 app->getNormalFont()->getFontDesc(fdesc);
69 fdesc.weight = FXFont::Bold;
70 myBoldFont = new FXFont(app, fdesc);
71 // https://en.wikipedia.org/wiki/Noto_fonts should be widely available
72 myFallbackFont = new FXFont(app, "Noto Sans CJK JP");
73 // build docks
74 myTopDock = new FXDockSite(this, LAYOUT_SIDE_TOP | LAYOUT_FILL_X);
75 myBottomDock = new FXDockSite(this, LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X);
76 myLeftDock = new FXDockSite(this, LAYOUT_SIDE_LEFT | LAYOUT_FILL_Y);
77 myRightDock = new FXDockSite(this, LAYOUT_SIDE_RIGHT | LAYOUT_FILL_Y);
78 // avoid instance Windows twice
79 if (myInstance != nullptr) {
80 throw ProcessError("MainWindow initialized twice");
81 }
82 myInstance = this;
83 //myGLVisual->setStencilSize(8); // enable stencil buffer
84}
85
86
90 delete myBoldFont;
91 delete myFallbackFont;
92 delete myTopDock;
93 delete myBottomDock;
94 delete myLeftDock;
95 delete myRightDock;
96 myInstance = nullptr;
97}
98
99
100
101void
103 myGLWindows.push_back(child);
104}
105
106
107void
109 std::vector<GUIGlChildWindow*>::iterator i = std::find(myGLWindows.begin(), myGLWindows.end(), child);
110 if (i != myGLWindows.end()) {
111 myGLWindows.erase(i);
112 }
113}
114
115
116void
117GUIMainWindow::addChild(FXMainWindow* child) {
118 myTrackerLock.lock();
119 myTrackerWindows.push_back(child);
120 myTrackerLock.unlock();
121}
122
123
124void
125GUIMainWindow::removeChild(FXMainWindow* child) {
126 myTrackerLock.lock();
127 std::vector<FXMainWindow*>::iterator i = std::find(myTrackerWindows.begin(), myTrackerWindows.end(), child);
128 myTrackerWindows.erase(i);
129 myTrackerLock.unlock();
130}
131
132
133FXDockSite*
137
138
139std::vector<std::string>
141 std::vector<std::string> ret;
142 for (GUIGlChildWindow* const window : myGLWindows) {
143 ret.push_back(window->getTitle().text());
144 }
145 return ret;
146}
147
148
150GUIMainWindow::getViewByID(const std::string& id) const {
151 for (GUIGlChildWindow* const window : myGLWindows) {
152 if (std::string(window->getTitle().text()) == id) {
153 return window;
154 }
155 }
156 return nullptr;
157}
158
159
160void
161GUIMainWindow::removeViewByID(const std::string& id) {
162 for (GUIGlChildWindow* const window : myGLWindows) {
163 if (std::string(window->getTitle().text()) == id) {
164 window->close();
165 removeGLChild(window);
166 return;
167 }
168 }
169}
170
171
172FXFont*
176
177FXFont*
181
182const std::vector<GUIGlChildWindow*>&
184 return myGLWindows;
185}
186
187
188void
190 // inform views
191 myMDIClient->forallWindows(this, FXSEL(SEL_COMMAND, msg), nullptr);
192 // inform other windows
193 myTrackerLock.lock();
194 for (int i = 0; i < (int)myTrackerWindows.size(); i++) {
195 myTrackerWindows[i]->handle(this, FXSEL(SEL_COMMAND, msg), nullptr);
196 }
197 myTrackerLock.unlock();
198}
199
200
201FXGLVisual*
203 return myGLVisual;
204}
205
206
211
212
217
218
219FXLabel*
223
224
225FXLabel*
229
230
231FXLabel*
235
236
237FXHorizontalFrame*
241
242
243bool
245 return myAmGaming;
246}
247
248
249bool
253
254
255bool
257 return myListParking;
258}
259
260
261bool
265
266
269 if (myInstance != nullptr) {
270 return myInstance;
271 }
272 throw ProcessError("A GUIMainWindow instance was not yet constructed.");
273}
274
275
278 GUIGlChildWindow* w = dynamic_cast<GUIGlChildWindow*>(myMDIClient->getActiveChild());
279 if (w != nullptr) {
280 return w->getView();
281 }
282 return nullptr;
283}
284
285
286void
288 int windowWidth = getApp()->reg().readIntEntry("SETTINGS", "width", 600);
289 int windowHeight = getApp()->reg().readIntEntry("SETTINGS", "height", 400);
291 if (oc.isSet("window-size")) {
292 std::vector<std::string> windowSize = oc.getStringVector("window-size");
293 if (windowSize.size() != 2) {
294 WRITE_ERROR(TL("option window-size requires INT,INT"));
295 } else {
296 try {
297 windowWidth = StringUtils::toInt(windowSize[0]);
298 windowHeight = StringUtils::toInt(windowSize[1]);
299 } catch (NumberFormatException& e) {
300 WRITE_ERROR("option window-size requires INT,INT " + toString(e.what()));
301 }
302 }
303 }
304 if (oc.isSet("window-size") || getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 0 || oc.isSet("window-pos")) {
305 // when restoring previous pos, make sure the window fits fully onto the current screen
306 int x = MAX2(0, MIN2(getApp()->reg().readIntEntry("SETTINGS", "x", 150), getApp()->getRootWindow()->getWidth() - windowWidth));
307 int y = MAX2(50, MIN2(getApp()->reg().readIntEntry("SETTINGS", "y", 150), getApp()->getRootWindow()->getHeight() - windowHeight));
308 if (oc.isSet("window-pos")) {
309 std::vector<std::string> windowPos = oc.getStringVector("window-pos");
310 if (windowPos.size() != 2) {
311 WRITE_ERROR(TL("option window-pos requires INT,INT"));
312 } else {
313 try {
314 x = StringUtils::toInt(windowPos[0]);
315 y = StringUtils::toInt(windowPos[1]);
316 } catch (NumberFormatException& e) {
317 WRITE_ERROR("option window-pos requires INT,INT " + toString(e.what()));
318 }
319 }
320 }
321 move(x, y);
322 resize(windowWidth, windowHeight);
323 }
324}
325
326void
328 if (!myAmFullScreen) {
329 getApp()->reg().writeIntEntry("SETTINGS", "x", getX());
330 getApp()->reg().writeIntEntry("SETTINGS", "y", getY());
331 getApp()->reg().writeIntEntry("SETTINGS", "width", getWidth());
332 getApp()->reg().writeIntEntry("SETTINGS", "height", getHeight());
333 }
334}
335
336
337void
339 myLanguageMenu = new FXMenuPane(this);
340 GUIDesigns::buildFXMenuTitle(menuBar, TL("Langua&ge"), nullptr, myLanguageMenu);
341
342 GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "English", "", TL("Change language to english. (en)"),
344 GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "Deutsch", "", TL("Change language to german. (de)"),
346 GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "Español", "", TL("Change language to spanish. (es)"),
348 GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "Français", "", TL("Change language to french. (fr)"),
350 GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "Italiano", "", TL("Change language to italian. (it)"),
352 GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "简体中文", "", TL("简体中文 (zh)"),
354 GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "繁體中文", "", TL("繁體中文 (zh-Hant)"),
356 GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "Türkçe", "", TL("Change language to turkish. (tr)"),
358 GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "Magyar", "", TL("Change language to hungarian. (hu)"),
360}
361
362
363long
364GUIMainWindow::onCmdChangeLanguage(FXObject*, FXSelector sel, void*) {
365 // set language
366 std::string langID;
367 std::string lang;
368 // continue depending of called button
369 switch (FXSELID(sel)) {
370 case MID_LANGUAGE_DE:
371 langID = "de";
372 lang = TL("german");
373 break;
374 case MID_LANGUAGE_ES:
375 langID = "es";
376 lang = TL("spanish");
377 break;
378 case MID_LANGUAGE_FR:
379 langID = "fr";
380 lang = TL("french");
381 break;
382 case MID_LANGUAGE_IT:
383 langID = "it";
384 lang = TL("italian");
385 break;
386 case MID_LANGUAGE_ZH:
387 langID = "zh";
388 lang = TL("chinese");
389 break;
390 case MID_LANGUAGE_ZHT:
391 langID = "zh-Hant";
392 lang = TL("chinese simplified");
393 break;
394 case MID_LANGUAGE_TR:
395 langID = "tr";
396 lang = TL("turkish");
397 break;
398 case MID_LANGUAGE_HU:
399 langID = "hu";
400 lang = TL("hungarian");
401 break;
402 default:
403 langID = "C";
404 lang = TL("english");
405 break;
406 }
407 // check if change language
408 if (langID != gLanguage) {
409 // update language
410 gLanguage = langID;
411 // show info
412 WRITE_MESSAGE(TL("Language changed to ") + lang);
413 // show dialog
414 const std::string header = TL("Restart needed");
415 const std::string body = TL("Changing display language needs restart to take effect.") + std::string("\n") +
416#ifdef DEBUG
417#ifdef WIN32
418 TL("For the Debug build you might also need to set the LANG environment variable.") + std::string("\n") +
419#endif
420#endif
421 TL("Under development. You can help to improve the translation at:") + std::string("\n") +
422 "https://hosted.weblate.org/projects/eclipse-sumo/";
423 FXMessageBox::information(getApp(), MBOX_OK, header.c_str(), "%s", body.c_str());
424 // update language in registry (common for sumo and netedit)
425 std::string appKey = getApp()->reg().getAppKey().text();
426 if (appKey == "SUMO GUI") {
427 // registry is written again later so we have to modify the "life" version
428 getApp()->reg().writeStringEntry("gui", "language", langID.c_str());
429 } else {
430 FXRegistry reg("SUMO GUI", "sumo-gui");
431 reg.read();
432 reg.writeStringEntry("gui", "language", langID.c_str());
433 reg.write();
434 }
435 }
436 return 1;
437}
438
439
440long
441GUIMainWindow::onUpdChangeLanguage(FXObject* obj, FXSelector, void*) {
442 // get language menu command
443 FXMenuCommand* menuCommand = dynamic_cast<FXMenuCommand*>(obj);
444 if (menuCommand) {
445 // check if change color
446 if ((gLanguage == "C") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_EN))) {
447 menuCommand->setTextColor(FXRGB(0, 0, 255));
448 } else if ((gLanguage == "de") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_DE))) {
449 menuCommand->setTextColor(FXRGB(0, 0, 255));
450 } else if ((gLanguage == "es") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_ES))) {
451 menuCommand->setTextColor(FXRGB(0, 0, 255));
452 } else if ((gLanguage == "fr") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_FR))) {
453 menuCommand->setTextColor(FXRGB(0, 0, 255));
454 } else if ((gLanguage == "it") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_IT))) {
455 menuCommand->setTextColor(FXRGB(0, 0, 255));
456 } else if ((gLanguage == "zh") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_ZH))) {
457 menuCommand->setTextColor(FXRGB(0, 0, 255));
458 } else if ((gLanguage == "zh-Hant") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_ZHT))) {
459 menuCommand->setTextColor(FXRGB(0, 0, 255));
460 } else if ((gLanguage == "tr") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_TR))) {
461 menuCommand->setTextColor(FXRGB(0, 0, 255));
462 } else if ((gLanguage == "hu") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_HU))) {
463 menuCommand->setTextColor(FXRGB(0, 0, 255));
464 } else {
465 menuCommand->setTextColor(FXRGB(0, 0, 0));
466 }
467 }
468 return 1;
469}
470
471
472/****************************************************************************/
@ MID_LANGUAGE_TR
change language to turkish
@ MID_LANGUAGE_ZHT
change language to chinese (traditional)
@ MID_LANGUAGE_ES
change language to spanish
@ MID_LANGUAGE_HU
change language to hungarian
@ MID_LANGUAGE_IT
change language to italian
@ MID_LANGUAGE_EN
change language to english
@ MID_LANGUAGE_DE
change language to german
@ MID_LANGUAGE_ZH
change language to chinese (simplified)
@ MID_LANGUAGE_FR
change language to french
@ LANGUAGE_ZHT
@ LANGUAGE_EN
icons for languages
#define WRITE_MESSAGE(msg)
Definition MsgHandler.h:272
#define WRITE_ERROR(msg)
Definition MsgHandler.h:279
#define TL(string)
Definition MsgHandler.h:287
std::string gLanguage
the language for GUI elements and messages
Definition StdDefs.cpp:33
T MIN2(T a, T b)
Definition StdDefs.h:76
T MAX2(T a, T b)
Definition StdDefs.h:82
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
static FXMenuTitle * buildFXMenuTitle(FXComposite *p, const std::string &text, FXIcon *icon, FXMenuPane *menuPane)
build menu title
static FXMenuCommand * buildFXMenuCommandShortcut(FXComposite *p, const std::string &text, const std::string &shortcut, const std::string &info, FXIcon *icon, FXObject *tgt, FXSelector sel)
build menu command
GUISUMOAbstractView * getView() const
return GUISUMOAbstractView
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
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
FXMenuPane * myLanguageMenu
Language menu common to all applications.
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
void buildLanguageMenu(FXMenuBar *menuBar)
long onCmdChangeLanguage(FXObject *, FXSelector, void *)
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
FXHorizontalFrame * myTestFrame
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
FXHorizontalFrame * getTestFrame()
get test frame
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
long onUpdChangeLanguage(FXObject *, FXSelector, void *)
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.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...