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
40 #include "GUIAppEnum.h"
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(a, "sumo-gui main window", nullptr, nullptr, DECOR_ALL, 20, 20, 600, 400),
55  myAmFullScreen(false),
56  myTrackerLock(true),
57  myGLVisual(new FXGLVisual(a, VISUAL_DOUBLEBUFFER)),
58  myAmGaming(false),
59  myListInternal(false),
60  myListParking(true),
61  myListTeleporting(false) {
62 
63  FXFontDesc fdesc;
64  getApp()->getNormalFont()->getFontDesc(fdesc);
65  fdesc.weight = FXFont::Bold;
66  myBoldFont = new FXFont(getApp(), fdesc);
67  // https://en.wikipedia.org/wiki/Noto_fonts should be widely available
68  myFallbackFont = new FXFont(getApp(), "Noto Sans CJK JP");
69 
70  myTopDock = new FXDockSite(this, LAYOUT_SIDE_TOP | LAYOUT_FILL_X);
71  myBottomDock = new FXDockSite(this, LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X);
72  myLeftDock = new FXDockSite(this, LAYOUT_SIDE_LEFT | LAYOUT_FILL_Y);
73  myRightDock = new FXDockSite(this, LAYOUT_SIDE_RIGHT | LAYOUT_FILL_Y);
74  if (myInstance != nullptr) {
75  throw ProcessError("MainWindow initialized twice");
76  }
77  myInstance = this;
78  //myGLVisual->setStencilSize(8); // enable stencil buffer
79 }
80 
81 
83  delete myBoldFont;
84  delete myFallbackFont;
85  delete myTopDock;
86  delete myBottomDock;
87  delete myLeftDock;
88  delete myRightDock;
89 }
90 
91 
92 
93 void
95  myGLWindows.push_back(child);
96 }
97 
98 
99 void
101  std::vector<GUIGlChildWindow*>::iterator i = std::find(myGLWindows.begin(), myGLWindows.end(), child);
102  if (i != myGLWindows.end()) {
103  myGLWindows.erase(i);
104  }
105 }
106 
107 
108 void
109 GUIMainWindow::addChild(FXMainWindow* child) {
110  myTrackerLock.lock();
111  myTrackerWindows.push_back(child);
112  myTrackerLock.unlock();
113 }
114 
115 
116 void
117 GUIMainWindow::removeChild(FXMainWindow* child) {
118  myTrackerLock.lock();
119  std::vector<FXMainWindow*>::iterator i = std::find(myTrackerWindows.begin(), myTrackerWindows.end(), child);
120  myTrackerWindows.erase(i);
121  myTrackerLock.unlock();
122 }
123 
124 
125 FXDockSite*
127  return myTopDock;
128 }
129 
130 
131 std::vector<std::string>
133  std::vector<std::string> ret;
134  for (GUIGlChildWindow* const window : myGLWindows) {
135  ret.push_back(window->getTitle().text());
136  }
137  return ret;
138 }
139 
140 
142 GUIMainWindow::getViewByID(const std::string& id) const {
143  for (GUIGlChildWindow* const window : myGLWindows) {
144  if (std::string(window->getTitle().text()) == id) {
145  return window;
146  }
147  }
148  return nullptr;
149 }
150 
151 
152 FXFont*
154  return myBoldFont;
155 }
156 
157 FXFont*
159  return myFallbackFont;
160 }
161 
162 const std::vector<GUIGlChildWindow*>&
164  return myGLWindows;
165 }
166 
167 
168 void
170  // inform views
171  myMDIClient->forallWindows(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), nullptr);
172  // inform other windows
173  myTrackerLock.lock();
174  for (int i = 0; i < (int)myTrackerWindows.size(); i++) {
175  myTrackerWindows[i]->handle(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), nullptr);
176  }
177  myTrackerLock.unlock();
178 }
179 
180 
181 FXGLVisual*
183  return myGLVisual;
184 }
185 
186 
187 FXLabel&
189  return *myCartesianCoordinate;
190 }
191 
192 
193 FXLabel&
195  return *myGeoCoordinate;
196 }
197 
198 
199 bool
201  return myAmGaming;
202 }
203 
204 
205 bool
207  return myListInternal;
208 }
209 
210 
211 bool
213  return myListParking;
214 }
215 
216 
217 bool
219  return myListTeleporting;
220 }
221 
222 
225  if (myInstance != nullptr) {
226  return myInstance;
227  }
228  throw ProcessError("A GUIMainWindow instance was not yet constructed.");
229 }
230 
231 
234  GUIGlChildWindow* w = dynamic_cast<GUIGlChildWindow*>(myMDIClient->getActiveChild());
235  if (w != nullptr) {
236  return w->getView();
237  }
238  return nullptr;
239 }
240 
241 
242 void
244  int windowWidth = getApp()->reg().readIntEntry("SETTINGS", "width", 600);
245  int windowHeight = getApp()->reg().readIntEntry("SETTINGS", "height", 400);
246  const OptionsCont& oc = OptionsCont::getOptions();
247  if (oc.isSet("window-size")) {
248  std::vector<std::string> windowSize = oc.getStringVector("window-size");
249  if (windowSize.size() != 2) {
250  WRITE_ERROR("option window-size requires INT,INT");
251  } else {
252  try {
253  windowWidth = StringUtils::toInt(windowSize[0]);
254  windowHeight = StringUtils::toInt(windowSize[1]);
255  } catch (NumberFormatException& e) {
256  WRITE_ERROR("option window-size requires INT,INT " + toString(e.what()));
257  }
258  }
259  }
260  if (oc.isSet("window-size") || getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 0 || oc.isSet("window-pos")) {
261  // when restoring previous pos, make sure the window fits fully onto the current screen
262  int x = MAX2(0, MIN2(getApp()->reg().readIntEntry("SETTINGS", "x", 150), getApp()->getRootWindow()->getWidth() - windowWidth));
263  int y = MAX2(50, MIN2(getApp()->reg().readIntEntry("SETTINGS", "y", 150), getApp()->getRootWindow()->getHeight() - windowHeight));
264  if (oc.isSet("window-pos")) {
265  std::vector<std::string> windowPos = oc.getStringVector("window-pos");
266  if (windowPos.size() != 2) {
267  WRITE_ERROR("option window-pos requires INT,INT");
268  } else {
269  try {
270  x = StringUtils::toInt(windowPos[0]);
271  y = StringUtils::toInt(windowPos[1]);
272  } catch (NumberFormatException& e) {
273  WRITE_ERROR("option window-pos requires INT,INT " + toString(e.what()));
274  }
275  }
276  }
277  move(x, y);
278  resize(windowWidth, windowHeight);
279  }
280 }
281 
282 void
284  if (!myAmFullScreen) {
285  getApp()->reg().writeIntEntry("SETTINGS", "x", getX());
286  getApp()->reg().writeIntEntry("SETTINGS", "y", getY());
287  getApp()->reg().writeIntEntry("SETTINGS", "width", getWidth());
288  getApp()->reg().writeIntEntry("SETTINGS", "height", getHeight());
289  }
290 }
291 
292 
293 /****************************************************************************/
@ MID_SIMSTEP
A Simulation step was performed.
Definition: GUIAppEnum.h:495
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:288
T MIN2(T a, T b)
Definition: StdDefs.h:74
T MAX2(T a, T b)
Definition: StdDefs.h:80
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
GUIGlChildWindow * getViewByID(const std::string &id) const
get specific view by ID
std::vector< FXMainWindow * > myTrackerWindows
FXLabel & getCartesianLabel()
get cartesian label
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
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 and geo-coordinate.
FXMDIClient * myMDIClient
The multi view panel.
FXFont * getBoldFont()
get bold front
bool listTeleporting() const
return whether to list teleporting vehicles
FXFont * myBoldFont
Font used for popup-menu titles.
static GUIMainWindow * getInstance()
get instance
FXLabel * myGeoCoordinate
bool listParking() const
return whether to list parking vehicles
FXDockSite * myRightDock
FXDockSite * myBottomDock
void updateChildren()
update childrens
bool listInternal() const
return whether to list internal structures
void addGLChild(GUIGlChildWindow *child)
Adds a further child window to the list (GUIGlChildWindow)
FXMutex myTrackerLock
A lock to make the removal and addition of trackers secure.
FXDockSite * myTopDock
bool myListInternal
information whether the locator should list internal structures
void storeWindowSizeAndPos()
record window position and size in registry
GUIMainWindow(FXApp *a)
constructor
FXGLVisual * getGLVisual() const
get GL Visual
FXLabel & getGeoLabel()
get geo label
FXDockSite * myLeftDock
bool myAmFullScreen
fox need this
void removeGLChild(GUIGlChildWindow *child)
removes the given child window from the list (GUIGlChildWindow)
FXDockSite * getTopDock()
get top dock
FXFont * getFallbackFont()
get fallback front
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)
std::vector< GUIGlChildWindow * > myGLWindows
void addChild(FXMainWindow *child)
Adds a further child window to the list (FXMainWindow)
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:58
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...