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-2020 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>
26 #include <fx.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
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 
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 != nullptr) {
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
92  myGLWindows.push_back(child);
93 }
94 
95 
96 void
98  std::vector<GUIGlChildWindow*>::iterator i = std::find(myGLWindows.begin(), myGLWindows.end(), child);
99  if (i != myGLWindows.end()) {
100  myGLWindows.erase(i);
101  }
102 }
103 
104 
105 void
106 GUIMainWindow::addChild(FXMainWindow* child) {
107  myTrackerLock.lock();
108  myTrackerWindows.push_back(child);
109  myTrackerLock.unlock();
110 }
111 
112 
113 void
114 GUIMainWindow::removeChild(FXMainWindow* child) {
115  myTrackerLock.lock();
116  std::vector<FXMainWindow*>::iterator i = std::find(myTrackerWindows.begin(), myTrackerWindows.end(), child);
117  myTrackerWindows.erase(i);
118  myTrackerLock.unlock();
119 }
120 
121 
122 FXDockSite*
124  return myTopDock;
125 }
126 
127 
128 std::vector<std::string>
130  std::vector<std::string> ret;
131  for (GUIGlChildWindow* const window : myGLWindows) {
132  ret.push_back(window->getTitle().text());
133  }
134  return ret;
135 }
136 
137 
139 GUIMainWindow::getViewByID(const std::string& id) const {
140  for (GUIGlChildWindow* const window : myGLWindows) {
141  if (std::string(window->getTitle().text()) == id) {
142  return window;
143  }
144  }
145  return nullptr;
146 }
147 
148 
149 FXFont*
151  return myBoldFont;
152 }
153 
154 
155 const std::vector<GUIGlChildWindow*>&
157  return myGLWindows;
158 }
159 
160 
161 void
163  // inform views
164  myMDIClient->forallWindows(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), nullptr);
165  // inform other windows
166  myTrackerLock.lock();
167  for (int i = 0; i < (int)myTrackerWindows.size(); i++) {
168  myTrackerWindows[i]->handle(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), nullptr);
169  }
170  myTrackerLock.unlock();
171 }
172 
173 
174 FXGLVisual*
176  return myGLVisual;
177 }
178 
179 
180 FXLabel&
182  return *myCartesianCoordinate;
183 }
184 
185 
186 FXLabel&
188  return *myGeoCoordinate;
189 }
190 
191 
192 bool
194  return myAmGaming;
195 }
196 
197 
198 bool
200  return myListInternal;
201 }
202 
203 
204 bool
206  return myListParking;
207 }
208 
209 
210 bool
212  return myListTeleporting;
213 }
214 
215 
218  if (myInstance != nullptr) {
219  return myInstance;
220  }
221  throw ProcessError("A GUIMainWindow instance was not yet constructed.");
222 }
223 
224 
227  GUIGlChildWindow* w = dynamic_cast<GUIGlChildWindow*>(myMDIClient->getActiveChild());
228  if (w != nullptr) {
229  return w->getView();
230  }
231  return nullptr;
232 }
233 
234 
235 void
237  int windowWidth = getApp()->reg().readIntEntry("SETTINGS", "width", 600);
238  int windowHeight = getApp()->reg().readIntEntry("SETTINGS", "height", 400);
239  const OptionsCont& oc = OptionsCont::getOptions();
240  if (oc.isSet("window-size")) {
241  std::vector<std::string> windowSize = oc.getStringVector("window-size");
242  if (windowSize.size() != 2) {
243  WRITE_ERROR("option window-size requires INT,INT");
244  } else {
245  try {
246  windowWidth = StringUtils::toInt(windowSize[0]);
247  windowHeight = StringUtils::toInt(windowSize[1]);
248  } catch (NumberFormatException& e) {
249  WRITE_ERROR("option window-size requires INT,INT " + toString(e.what()));
250  }
251  }
252  }
253  if (oc.isSet("window-size") || getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 0 || oc.isSet("window-pos")) {
254  // when restoring previous pos, make sure the window fits fully onto the current screen
255  int x = MAX2(0, MIN2(getApp()->reg().readIntEntry("SETTINGS", "x", 150), getApp()->getRootWindow()->getWidth() - windowWidth));
256  int y = MAX2(50, MIN2(getApp()->reg().readIntEntry("SETTINGS", "y", 150), getApp()->getRootWindow()->getHeight() - windowHeight));
257  if (oc.isSet("window-pos")) {
258  std::vector<std::string> windowPos = oc.getStringVector("window-pos");
259  if (windowPos.size() != 2) {
260  WRITE_ERROR("option window-pos requires INT,INT");
261  } else {
262  try {
263  x = StringUtils::toInt(windowPos[0]);
264  y = StringUtils::toInt(windowPos[1]);
265  } catch (NumberFormatException& e) {
266  WRITE_ERROR("option window-pos requires INT,INT " + toString(e.what()));
267  }
268  }
269  }
270  move(x, y);
271  resize(windowWidth, windowHeight);
272  }
273 }
274 
275 void
277  if (!myAmFullScreen) {
278  getApp()->reg().writeIntEntry("SETTINGS", "x", getX());
279  getApp()->reg().writeIntEntry("SETTINGS", "y", getY());
280  getApp()->reg().writeIntEntry("SETTINGS", "width", getWidth());
281  getApp()->reg().writeIntEntry("SETTINGS", "height", getHeight());
282  }
283 }
284 
285 
286 /****************************************************************************/
@ MID_SIMSTEP
A Simulation step was performed.
Definition: GUIAppEnum.h:481
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:284
T MIN2(T a, T b)
Definition: StdDefs.h:73
T MAX2(T a, T b)
Definition: StdDefs.h:79
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
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
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
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,...