LCOV - code coverage report
Current view: top level - src/utils/gui/windows - GUIMainWindow.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 44.6 % 334 149
Test Date: 2026-10-12 15:53:19 Functions: 56.4 % 39 22

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2026 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              : /****************************************************************************/
      14              : /// @file    GUIMainWindow.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @date    Tue, 29.05.2005
      19              : ///
      20              : //
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : 
      24              : #include <string>
      25              : #include <algorithm>
      26              : #include <utils/foxtools/fxheader.h>
      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
      35              : #include <utils/common/MsgHandler.h>
      36              : #include <utils/common/StringUtils.h>
      37              : #include <utils/common/StringTokenizer.h>
      38              : #include <utils/geom/GeoConvHelper.h>
      39              : #include <utils/foxtools/MFXImageHelper.h>
      40              : #include <utils/foxtools/MFXStaticToolTip.h>
      41              : #include <utils/gui/images/GUITexturesHelper.h>
      42              : #include <utils/gui/div/GUIDesigns.h>
      43              : #include <utils/options/OptionsCont.h>
      44              : #include <regex>
      45              : #include "GUIMainWindow.h"
      46              : #include "GUIGlChildWindow.h"
      47              : #include "GUISUMOAbstractView.h"
      48              : 
      49              : 
      50              : // ===========================================================================
      51              : // static member definitions
      52              : // ===========================================================================
      53              : GUIMainWindow* GUIMainWindow::myInstance = nullptr;
      54              : 
      55              : // ===========================================================================
      56              : // member method definitions
      57              : // ===========================================================================
      58         9020 : GUIMainWindow::GUIMainWindow(FXApp* app) :
      59              :     FXMainWindow(app, "sumo-gui main window", nullptr, nullptr, DECOR_ALL, 20, 20, 600, 400),
      60         9020 :     myAmFullScreen(false),
      61         9020 :     myTrackerLock(true),
      62         9020 :     myGLVisual(new FXGLVisual(app, VISUAL_DOUBLEBUFFER)),
      63         9020 :     myAmGaming(false),
      64         9020 :     myListInternal(false),
      65         9020 :     myListParking(true),
      66        18040 :     myListTeleporting(false) {
      67              :     // build static tooltips
      68         9020 :     myStaticTooltipMenu = new MFXStaticToolTip(app);
      69         9020 :     myStaticTooltipView = new MFXStaticToolTip(app);
      70              :     // build bold font
      71              :     FXFontDesc fdesc;
      72         9020 :     app->getNormalFont()->getFontDesc(fdesc);
      73         9020 :     const double uiScale = app->reg().readRealEntry("SETTINGS", "uiscale", 1);
      74         9020 :     fdesc.size = (FXushort)(fdesc.size * uiScale);
      75         9020 :     myNormalFont = new FXFont(app, fdesc);
      76         9020 :     app->setNormalFont(myNormalFont);
      77         9020 :     fdesc.weight = FXFont::Bold;
      78         9020 :     GUIDesignHeight = (int)(fdesc.size / 90.0 * 18) + 5;
      79         9020 :     myBoldFont = new FXFont(app, fdesc);
      80              :     // https://en.wikipedia.org/wiki/Noto_fonts should be widely available
      81         9020 :     myFallbackFont = new FXFont(app, "Noto Sans CJK JP");
      82              :     // build docks
      83         9020 :     myTopDock = new FXDockSite(this, LAYOUT_SIDE_TOP | LAYOUT_FILL_X);
      84         9020 :     myBottomDock = new FXDockSite(this, LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X);
      85         9020 :     myLeftDock = new FXDockSite(this, LAYOUT_SIDE_LEFT | LAYOUT_FILL_Y);
      86         9020 :     myRightDock = new FXDockSite(this, LAYOUT_SIDE_RIGHT | LAYOUT_FILL_Y);
      87              :     // avoid instance Windows twice
      88         9020 :     if (myInstance != nullptr) {
      89            0 :         throw ProcessError("MainWindow initialized twice");
      90              :     }
      91         9020 :     myInstance = this;
      92              :     //myGLVisual->setStencilSize(8); // enable stencil buffer
      93         9020 : }
      94              : 
      95              : 
      96         8993 : GUIMainWindow::~GUIMainWindow() {
      97         8993 :     delete myStaticTooltipMenu;
      98         8993 :     delete myStaticTooltipView;
      99         8993 :     delete myNormalFont;
     100         8993 :     delete myBoldFont;
     101         8993 :     delete myFallbackFont;
     102         8993 :     delete myTopDock;
     103         8993 :     delete myBottomDock;
     104         8993 :     delete myLeftDock;
     105         8993 :     delete myRightDock;
     106         8993 :     myInstance = nullptr;
     107         8993 : }
     108              : 
     109              : 
     110              : 
     111              : void
     112         8535 : GUIMainWindow::addGLChild(GUIGlChildWindow* child) {
     113         8535 :     myGLWindows.push_back(child);
     114         8535 : }
     115              : 
     116              : 
     117              : void
     118         8511 : GUIMainWindow::removeGLChild(GUIGlChildWindow* child) {
     119         8511 :     std::vector<GUIGlChildWindow*>::iterator i = std::find(myGLWindows.begin(), myGLWindows.end(), child);
     120         8511 :     if (i != myGLWindows.end()) {
     121         8508 :         myGLWindows.erase(i);
     122              :     }
     123         8511 : }
     124              : 
     125              : 
     126              : void
     127            0 : GUIMainWindow::addChild(FXMainWindow* child) {
     128            0 :     myTrackerLock.lock();
     129            0 :     myTrackerWindows.push_back(child);
     130            0 :     myTrackerLock.unlock();
     131            0 : }
     132              : 
     133              : 
     134              : void
     135            0 : GUIMainWindow::removeChild(FXMainWindow* child) {
     136            0 :     myTrackerLock.lock();
     137            0 :     std::vector<FXMainWindow*>::iterator i = std::find(myTrackerWindows.begin(), myTrackerWindows.end(), child);
     138            0 :     myTrackerWindows.erase(i);
     139            0 :     myTrackerLock.unlock();
     140            0 : }
     141              : 
     142              : 
     143              : FXDockSite*
     144            0 : GUIMainWindow::getTopDock() {
     145            0 :     return myTopDock;
     146              : }
     147              : 
     148              : 
     149              : std::vector<std::string>
     150          675 : GUIMainWindow::getViewIDs() const {
     151              :     std::vector<std::string> ret;
     152         1654 :     for (GUIGlChildWindow* const window : myGLWindows) {
     153         1958 :         ret.push_back(window->getTitle().text());
     154              :     }
     155          675 :     return ret;
     156            0 : }
     157              : 
     158              : 
     159              : GUIGlChildWindow*
     160          345 : GUIMainWindow::getViewByID(const std::string& id) const {
     161          348 :     for (GUIGlChildWindow* const window : myGLWindows) {
     162          345 :         if (std::string(window->getTitle().text()) == id) {
     163              :             return window;
     164              :         }
     165              :     }
     166              :     return nullptr;
     167              : }
     168              : 
     169              : 
     170              : void
     171            3 : GUIMainWindow::removeViewByID(const std::string& id) {
     172            6 :     for (GUIGlChildWindow* const window : myGLWindows) {
     173            6 :         if (std::string(window->getTitle().text()) == id) {
     174            3 :             window->close();
     175            3 :             removeGLChild(window);
     176              :             return;
     177              :         }
     178              :     }
     179              : }
     180              : 
     181              : 
     182              : FXFont*
     183            0 : GUIMainWindow::getBoldFont() {
     184            0 :     return myBoldFont;
     185              : }
     186              : 
     187              : FXFont*
     188            0 : GUIMainWindow::getFallbackFont() {
     189            0 :     return myFallbackFont;
     190              : }
     191              : 
     192              : const std::vector<GUIGlChildWindow*>&
     193     13173185 : GUIMainWindow::getViews() const {
     194     13173185 :     return myGLWindows;
     195              : }
     196              : 
     197              : 
     198              : void
     199     13164752 : GUIMainWindow::updateChildren(int msg) {
     200              :     // inform views
     201     13164752 :     myMDIClient->forallWindows(this, FXSEL(SEL_COMMAND, msg), nullptr);
     202              :     // inform other windows
     203     13164752 :     myTrackerLock.lock();
     204     13164752 :     for (int i = 0; i < (int)myTrackerWindows.size(); i++) {
     205            0 :         myTrackerWindows[i]->handle(this, FXSEL(SEL_COMMAND, msg), nullptr);
     206              :     }
     207     13164752 :     myTrackerLock.unlock();
     208     13164752 : }
     209              : 
     210              : 
     211              : FXGLVisual*
     212         8535 : GUIMainWindow::getGLVisual() const {
     213         8535 :     return myGLVisual;
     214              : }
     215              : 
     216              : 
     217              : MFXStaticToolTip*
     218       123993 : GUIMainWindow::getStaticTooltipMenu() const {
     219       123993 :     return myStaticTooltipMenu;
     220              : }
     221              : 
     222              : 
     223              : MFXStaticToolTip*
     224      1610144 : GUIMainWindow::getStaticTooltipView() const {
     225      1610144 :     return myStaticTooltipView;
     226              : }
     227              : 
     228              : 
     229              : FXTextField*
     230          790 : GUIMainWindow::getCartesianLabel() {
     231          790 :     return myCartesianCoordinate;
     232              : }
     233              : 
     234              : 
     235              : FXTextField*
     236         1185 : GUIMainWindow::getGeoLabel() {
     237         1185 :     return myGeoCoordinate;
     238              : }
     239              : 
     240              : 
     241              : bool
     242            0 : GUIMainWindow::parseGeoCoordinate(const std::string& text, double& lat, double& lon) {
     243            0 :     std::string s = StringUtils::to_lower_case(StringUtils::prune(text));
     244            0 :     if (s.empty()) {
     245              :         return false;
     246              :     }
     247            0 :     std::regex latRegex(R"((?:lat(?:itude)?)\s*[:=]?\s*([+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?))");
     248            0 :     std::regex lonRegex(R"((?:lon(?:gitude)?)\s*[:=]?\s*([+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?))");
     249              :     std::smatch latMatch, lonMatch;
     250            0 :     if (std::regex_search(s, latMatch, latRegex) && std::regex_search(s, lonMatch, lonRegex)) {
     251              :         try {
     252            0 :             double l1 = std::stod(latMatch[1]);
     253            0 :             double l2 = std::stod(lonMatch[1]);
     254            0 :             if (l1 >= -90.0 && l1 <= 90.0 && l2 >= -180.0 && l2 <= 180.0) {
     255            0 :                 lat = l1;
     256            0 :                 lon = l2;
     257            0 :                 return true;
     258              :             }
     259            0 :         } catch (...) {
     260              :             return false;
     261            0 :         }
     262              :         return false;
     263              :     }
     264              :     std::string clean = s;
     265            0 :     for (char& c : clean) {
     266            0 :         if (c == ',' || c == ';' || c == '/' || c == '\t') {
     267            0 :             c = ' ';
     268              :         }
     269              :     }
     270            0 :     StringTokenizer st(clean, " ");
     271              :     std::vector<double> vals;
     272            0 :     while (st.hasNext()) {
     273            0 :         std::string token = st.next();
     274              :         try {
     275            0 :             size_t idx = 0;
     276            0 :             double v = std::stod(token, &idx);
     277            0 :             if (idx == token.size()) {
     278            0 :                 vals.push_back(v);
     279              :             }
     280            0 :         } catch (...) {}
     281              :     }
     282            0 :     if (vals.size() >= 2) {
     283            0 :         double v1 = vals[0];
     284            0 :         double v2 = vals[1];
     285            0 :         if (std::abs(v1) > 90.0 && std::abs(v2) <= 90.0) {
     286            0 :             lon = v1;
     287            0 :             lat = v2;
     288            0 :         } else if (std::abs(v2) > 90.0 && std::abs(v1) <= 90.0) {
     289            0 :             lat = v1;
     290            0 :             lon = v2;
     291              :         } else {
     292            0 :             lat = v1;
     293            0 :             lon = v2;
     294              :         }
     295            0 :         if (lat >= -90.0 && lat <= 90.0 && lon >= -180.0 && lon <= 180.0) {
     296              :             return true;
     297              :         }
     298              :     }
     299              :     return false;
     300            0 : }
     301              : 
     302              : 
     303              : bool
     304            0 : GUIMainWindow::parseCartesianCoordinate(const std::string& text, double& x, double& y) {
     305            0 :     std::string s = StringUtils::to_lower_case(StringUtils::prune(text));
     306            0 :     if (s.empty()) {
     307              :         return false;
     308              :     }
     309            0 :     std::regex xRegex(R"((?:x)\s*[:=]?\s*([+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?))");
     310            0 :     std::regex yRegex(R"((?:y)\s*[:=]?\s*([+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?))");
     311              :     std::smatch xMatch, yMatch;
     312            0 :     if (std::regex_search(s, xMatch, xRegex) && std::regex_search(s, yMatch, yRegex)) {
     313              :         try {
     314            0 :             x = std::stod(xMatch[1]);
     315            0 :             y = std::stod(yMatch[1]);
     316            0 :             return true;
     317            0 :         } catch (...) {
     318              :             return false;
     319            0 :         }
     320              :     }
     321              :     std::string clean = s;
     322            0 :     for (char& c : clean) {
     323            0 :         if (c == ',' || c == ';' || c == '/' || c == '\t') {
     324            0 :             c = ' ';
     325              :         }
     326              :     }
     327            0 :     StringTokenizer st(clean, " ");
     328              :     std::vector<double> vals;
     329            0 :     while (st.hasNext()) {
     330            0 :         std::string token = st.next();
     331              :         try {
     332            0 :             size_t idx = 0;
     333            0 :             double v = std::stod(token, &idx);
     334            0 :             if (idx == token.size()) {
     335            0 :                 vals.push_back(v);
     336              :             }
     337            0 :         } catch (...) {}
     338              :     }
     339            0 :     if (vals.size() >= 2) {
     340            0 :         x = vals[0];
     341            0 :         y = vals[1];
     342            0 :         return true;
     343              :     }
     344              :     return false;
     345            0 : }
     346              : 
     347              : 
     348              : long
     349            0 : GUIMainWindow::onCmdSetGeoCoordinate(FXObject*, FXSelector, void*) {
     350            0 :     if (myGeoCoordinate) {
     351            0 :         myGeoCoordinate->killFocus();
     352            0 :         if (!GeoConvHelper::getFinal().usingGeoProjection()) {
     353            0 :             setStatusBarText(TL("No projection defined"));
     354            0 :             myGeoCoordinate->setText(TL("(No projection defined)"));
     355            0 :             myGeoCoordinate->disable();
     356            0 :             myGeoCoordinate->setEditable(false);
     357            0 :             return 1;
     358              :         }
     359            0 :         const std::string text = myGeoCoordinate->getText().text();
     360              :         double lat, lon;
     361            0 :         if (parseGeoCoordinate(text, lat, lon)) {
     362            0 :             Position p(lon, lat);
     363            0 :             if (GeoConvHelper::getFinal().x2cartesian_const(p)) {
     364            0 :                 GUISUMOAbstractView* view = getActiveView();
     365            0 :                 if (view) {
     366            0 :                     view->centerToPos(p, false);
     367            0 :                     view->update();
     368            0 :                     setStatusBarText(TLF("Centered view on %. Geo coordinates: lat %, lon %", toString(p), toString(lat, gPrecisionGeo), toString(lon, gPrecisionGeo)));
     369            0 :                     return 1;
     370              :                 }
     371              :             }
     372              :         }
     373            0 :         setStatusBarText(TL("Invalid geo coordinate. Use 'lat, lon' or 'lat:... lon:...'"));
     374              :     }
     375              :     return 1;
     376              : }
     377              : 
     378              : 
     379              : long
     380            0 : GUIMainWindow::onCmdSetCartesianCoordinate(FXObject*, FXSelector, void*) {
     381            0 :     if (myCartesianCoordinate) {
     382            0 :         myCartesianCoordinate->killFocus();
     383            0 :         const std::string text = myCartesianCoordinate->getText().text();
     384              :         double x, y;
     385            0 :         if (parseCartesianCoordinate(text, x, y)) {
     386            0 :             Position p(x, y);
     387            0 :             GUISUMOAbstractView* view = getActiveView();
     388            0 :             if (view) {
     389            0 :                 view->centerToPos(p, false);
     390            0 :                 view->update();
     391            0 :                 setStatusBarText(TLF("Centered view on x: %, y: %", toString(x), toString(y)));
     392            0 :                 return 1;
     393              :             }
     394              :         }
     395            0 :         setStatusBarText(TL("Invalid cartesian coordinate. Use 'x, y' or 'x:... y:...'"));
     396              :     }
     397              :     return 1;
     398              : }
     399              : 
     400              : 
     401              : long
     402            0 : GUIMainWindow::onCmdFocusCoordinate(FXObject* sender, FXSelector, void*) {
     403            0 :     FXTextField* tf = dynamic_cast<FXTextField*>(sender);
     404            0 :     if (tf && tf->isEnabled()) {
     405            0 :         tf->setBackColor(FXRGB(255, 255, 255));
     406            0 :         tf->selectAll();
     407              :     }
     408            0 :     return 1;
     409              : }
     410              : 
     411              : 
     412              : long
     413            0 : GUIMainWindow::onCmdUnfocusCoordinate(FXObject* sender, FXSelector, void*) {
     414            0 :     FXTextField* tf = dynamic_cast<FXTextField*>(sender);
     415            0 :     if (tf && tf->getParent()) {
     416            0 :         tf->setBackColor(tf->getParent()->getBackColor());
     417              :     }
     418            0 :     return 1;
     419              : }
     420              : 
     421              : 
     422              : FXLabel*
     423            0 : GUIMainWindow::getTestLabel() {
     424            0 :     return myTestCoordinate;
     425              : }
     426              : 
     427              : 
     428              : FXHorizontalFrame*
     429          395 : GUIMainWindow::getTestFrame() {
     430          395 :     return myTestFrame;
     431              : }
     432              : 
     433              : 
     434              : bool
     435        17113 : GUIMainWindow::isGaming() const {
     436        17113 :     return myAmGaming;
     437              : }
     438              : 
     439              : 
     440              : bool
     441            0 : GUIMainWindow::listInternal() const {
     442            0 :     return myListInternal;
     443              : }
     444              : 
     445              : 
     446              : bool
     447            0 : GUIMainWindow::listParking() const {
     448            0 :     return myListParking;
     449              : }
     450              : 
     451              : 
     452              : bool
     453            0 : GUIMainWindow::listTeleporting() const {
     454            0 :     return myListTeleporting;
     455              : }
     456              : 
     457              : 
     458              : GUIMainWindow*
     459     13174473 : GUIMainWindow::getInstance() {
     460     13174473 :     if (myInstance != nullptr) {
     461     13174425 :         return myInstance;
     462              :     }
     463           96 :     throw ProcessError("A GUIMainWindow instance was not yet constructed.");
     464              : }
     465              : 
     466              : 
     467              : GUISUMOAbstractView*
     468           51 : GUIMainWindow::getActiveView() const {
     469           51 :     GUIGlChildWindow* w = dynamic_cast<GUIGlChildWindow*>(myMDIClient->getActiveChild());
     470           51 :     if (w != nullptr) {
     471           51 :         return w->getView();
     472              :     }
     473            0 :     if (!myGLWindows.empty()) {
     474            0 :         return myGLWindows.front()->getView();
     475              :     }
     476              :     return nullptr;
     477              : }
     478              : 
     479              : 
     480              : void
     481        17551 : GUIMainWindow::setWindowSizeAndPos() {
     482        17551 :     int windowWidth = getApp()->reg().readIntEntry("SETTINGS", "width", 600);
     483        17551 :     int windowHeight = getApp()->reg().readIntEntry("SETTINGS", "height", 400);
     484        17551 :     const OptionsCont& oc = OptionsCont::getOptions();
     485        35102 :     if (oc.isSet("window-size")) {
     486          108 :         std::vector<std::string> windowSize = oc.getStringVector("window-size");
     487           54 :         if (windowSize.size() != 2) {
     488            0 :             WRITE_ERROR(TL("option window-size requires INT,INT"));
     489              :         } else {
     490              :             try {
     491           54 :                 windowWidth = StringUtils::toInt(windowSize[0]);
     492           54 :                 windowHeight = StringUtils::toInt(windowSize[1]);
     493            0 :             } catch (NumberFormatException& e) {
     494            0 :                 WRITE_ERROR("option window-size requires INT,INT " + toString(e.what()));
     495            0 :             }
     496              :         }
     497           54 :     }
     498        35102 :     if (oc.isSet("window-size") || getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 0 || oc.isSet("window-pos")) {
     499              :         // when restoring previous pos, make sure the window fits fully onto the current screen
     500        17551 :         int x = MAX2(0, MIN2(getApp()->reg().readIntEntry("SETTINGS", "x", 150), getApp()->getRootWindow()->getWidth() - windowWidth));
     501        17551 :         int y = MAX2(50, MIN2(getApp()->reg().readIntEntry("SETTINGS", "y", 150), getApp()->getRootWindow()->getHeight() - windowHeight));
     502        35102 :         if (oc.isSet("window-pos")) {
     503          108 :             std::vector<std::string> windowPos = oc.getStringVector("window-pos");
     504           54 :             if (windowPos.size() != 2) {
     505            0 :                 WRITE_ERROR(TL("option window-pos requires INT,INT"));
     506              :             } else {
     507              :                 try {
     508           54 :                     x = StringUtils::toInt(windowPos[0]);
     509           54 :                     y = StringUtils::toInt(windowPos[1]);
     510            0 :                 } catch (NumberFormatException& e) {
     511            0 :                     WRITE_ERROR("option window-pos requires INT,INT " + toString(e.what()));
     512            0 :                 }
     513              :             }
     514           54 :         }
     515        17551 :         move(x, y);
     516        17551 :         resize(windowWidth, windowHeight);
     517              :     }
     518        17551 : }
     519              : 
     520              : void
     521         9020 : GUIMainWindow::storeWindowSizeAndPos() {
     522         9020 :     if (!myAmFullScreen) {
     523         9020 :         getApp()->reg().writeIntEntry("SETTINGS", "x", getX());
     524         9020 :         getApp()->reg().writeIntEntry("SETTINGS", "y", getY());
     525         9020 :         getApp()->reg().writeIntEntry("SETTINGS", "width", getWidth());
     526         9020 :         getApp()->reg().writeIntEntry("SETTINGS", "height", getHeight());
     527              :     }
     528         9020 : }
     529              : 
     530              : 
     531              : void
     532         9020 : GUIMainWindow::buildLanguageMenu(FXMenuBar* menuBar) {
     533         9020 :     myLanguageMenu = new FXMenuPane(this);
     534         9020 :     GUIDesigns::buildFXMenuTitle(menuBar, TL("Langua&ge"), nullptr, myLanguageMenu);
     535              : 
     536        18040 :     GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "English", "", TL("Change language to english. (en)"),
     537              :                                            GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_EN), this, MID_LANGUAGE_EN);
     538        18040 :     GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "Deutsch", "", TL("Change language to german. (de)"),
     539              :                                            GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_DE), this, MID_LANGUAGE_DE);
     540        18040 :     GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "Español", "", TL("Change language to spanish. (es)"),
     541              :                                            GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_ES), this, MID_LANGUAGE_ES);
     542        18040 :     GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "Português", "", TL("Change language to portuguese. (pt)"),
     543              :                                            GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_PT), this, MID_LANGUAGE_PT);
     544        18040 :     GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "Français", "", TL("Change language to french. (fr)"),
     545              :                                            GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_FR), this, MID_LANGUAGE_FR);
     546        18040 :     GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "Italiano", "", TL("Change language to italian. (it)"),
     547              :                                            GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_IT), this, MID_LANGUAGE_IT);
     548        18040 :     GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "简体中文", "", TL("简体中文 (zh)"),
     549              :                                            GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_ZH), this, MID_LANGUAGE_ZH);
     550        18040 :     GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "繁體中文", "", TL("繁體中文 (zh-Hant)"),
     551              :                                            GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_ZHT), this, MID_LANGUAGE_ZHT);
     552        18040 :     GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "Türkçe", "", TL("Change language to turkish. (tr)"),
     553              :                                            GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_TR), this, MID_LANGUAGE_TR);
     554        18040 :     GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "日本語", "", TL("Change language to japanese. (ja)"),
     555              :                                            GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_JA), this, MID_LANGUAGE_JA);
     556        18040 :     GUIDesigns::buildFXMenuCommandShortcut(myLanguageMenu, "한국어", "", TL("Change language to korean. (ko)"),
     557              :                                            GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_KO), this, MID_LANGUAGE_KO);
     558         9020 : }
     559              : 
     560              : 
     561              : long
     562            0 : GUIMainWindow::onCmdChangeLanguage(FXObject*, FXSelector sel, void*) {
     563              :     // set language
     564              :     std::string langID;
     565              :     std::string lang;
     566              :     // continue depending of called button
     567            0 :     switch (FXSELID(sel)) {
     568              :         case MID_LANGUAGE_DE:
     569              :             langID = "de";
     570            0 :             lang = TL("german");
     571              :             break;
     572              :         case MID_LANGUAGE_ES:
     573              :             langID = "es";
     574            0 :             lang = TL("spanish");
     575              :             break;
     576              :         case MID_LANGUAGE_PT:
     577              :             langID = "pt";
     578            0 :             lang = TL("portuguese");
     579              :             break;
     580              :         case MID_LANGUAGE_FR:
     581              :             langID = "fr";
     582            0 :             lang = TL("french");
     583              :             break;
     584              :         case MID_LANGUAGE_IT:
     585              :             langID = "it";
     586            0 :             lang = TL("italian");
     587              :             break;
     588              :         case MID_LANGUAGE_ZH:
     589              :             langID = "zh";
     590            0 :             lang = TL("simplified chinese");
     591              :             break;
     592              :         case MID_LANGUAGE_ZHT:
     593              :             langID = "zh-Hant";
     594            0 :             lang = TL("traditional chinese");
     595              :             break;
     596              :         case MID_LANGUAGE_TR:
     597              :             langID = "tr";
     598            0 :             lang = TL("turkish");
     599              :             break;
     600              :         case MID_LANGUAGE_JA:
     601              :             langID = "ja";
     602            0 :             lang = TL("japanese");
     603              :             break;
     604              :         case MID_LANGUAGE_KO:
     605              :             langID = "ko";
     606            0 :             lang = TL("korean");
     607              :             break;
     608              :         default:
     609              :             langID = "C";
     610            0 :             lang = TL("english");
     611              :             break;
     612              :     }
     613              :     // check if change language
     614            0 :     if (langID != gLanguage) {
     615              :         // update language
     616              :         gLanguage = langID;
     617              :         // show info
     618            0 :         WRITE_MESSAGE(TL("Language changed to ") + lang);
     619              :         // show dialog
     620            0 :         const std::string header = TL("Restart needed");
     621            0 :         const std::string body = TL("Changing display language needs restart to take effect.") + std::string("\n") +
     622              : #ifdef DEBUG
     623              : #ifdef WIN32
     624              :                                  TL("For the Debug build you might also need to set the LANG environment variable.") + std::string("\n") +
     625              : #endif
     626              : #endif
     627            0 :                                  TL("Under development. You can help to improve the translation at:") + std::string("\n") +
     628              :                                  "https://hosted.weblate.org/projects/eclipse-sumo/";
     629            0 :         FXMessageBox::information(getApp(), MBOX_OK, header.c_str(), "%s", body.c_str());
     630              :         // update language in registry (common for sumo and netedit)
     631            0 :         std::string appKey = getApp()->reg().getAppKey().text();
     632            0 :         if (appKey == "SUMO GUI") {
     633              :             // registry is written again later so we have to modify the "live" version
     634            0 :             getApp()->reg().writeStringEntry("gui", "language", langID.c_str());
     635              :         } else {
     636            0 :             FXRegistry reg("SUMO GUI", "sumo-gui");
     637            0 :             reg.read();
     638            0 :             reg.writeStringEntry("gui", "language", langID.c_str());
     639            0 :             reg.write();
     640            0 :         }
     641              :     }
     642            0 :     return 1;
     643              : }
     644              : 
     645              : 
     646              : long
     647      4743865 : GUIMainWindow::onUpdChangeLanguage(FXObject* obj, FXSelector, void*) {
     648              :     // get language menu command
     649      4743865 :     FXMenuCommand* menuCommand = dynamic_cast<FXMenuCommand*>(obj);
     650      4743865 :     if (menuCommand) {
     651              :         // check if change color
     652      4743865 :         if ((gLanguage == "C") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_EN))) {
     653       474424 :             menuCommand->setTextColor(GUIDesignTextColorBlue);
     654      4269441 :         } else if ((gLanguage == "de") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_DE))) {
     655            0 :             menuCommand->setTextColor(GUIDesignTextColorBlue);
     656      4269441 :         } else if ((gLanguage == "es") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_ES))) {
     657            0 :             menuCommand->setTextColor(GUIDesignTextColorBlue);
     658      4269441 :         } else if ((gLanguage == "pt") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_PT))) {
     659            0 :             menuCommand->setTextColor(GUIDesignTextColorBlue);
     660      4269441 :         } else if ((gLanguage == "fr") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_FR))) {
     661            0 :             menuCommand->setTextColor(GUIDesignTextColorBlue);
     662      4269441 :         } else if ((gLanguage == "it") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_IT))) {
     663            0 :             menuCommand->setTextColor(GUIDesignTextColorBlue);
     664      4269441 :         } else if ((gLanguage == "zh") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_ZH))) {
     665            0 :             menuCommand->setTextColor(GUIDesignTextColorBlue);
     666      4269441 :         } else if ((gLanguage == "zh-Hant") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_ZHT))) {
     667            0 :             menuCommand->setTextColor(GUIDesignTextColorBlue);
     668      4269441 :         } else if ((gLanguage == "tr") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_TR))) {
     669            0 :             menuCommand->setTextColor(GUIDesignTextColorBlue);
     670      4269441 :         } else if ((gLanguage == "ja") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_JA))) {
     671            0 :             menuCommand->setTextColor(GUIDesignTextColorBlue);
     672      4269441 :         } else if ((gLanguage == "ko") && (menuCommand->getIcon() == GUIIconSubSys::getIcon(GUIIcon::LANGUAGE_KO))) {
     673            0 :             menuCommand->setTextColor(GUIDesignTextColorBlue);
     674              :         } else {
     675      4269441 :             menuCommand->setTextColor(GUIDesignTextColorBlack);
     676              :         }
     677              :     }
     678      4743865 :     return 1;
     679              : }
     680              : 
     681              : 
     682              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1