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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 //
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <algorithm>
28 #include <fx.h>
29 // fx3d includes windows.h so we need to guard against macro pollution
30 #ifdef WIN32
31 #define NOMINMAX
32 #endif
33 #include <fx3d.h>
34 #ifdef WIN32
35 #undef NOMINMAX
36 #endif
42 #include "GUIAppEnum.h"
43 #include "GUIMainWindow.h"
44 #include "GUIGlChildWindow.h"
45 
46 
47 // ===========================================================================
48 // static member definitions
49 // ===========================================================================
51 
52 // ===========================================================================
53 // member method definitions
54 // ===========================================================================
56  FXMainWindow(a, "SUMO-gui main window", nullptr, nullptr, DECOR_ALL, 20, 20, 600, 400),
57  myAmFullScreen(false),
58  myGLVisual(new FXGLVisual(a, VISUAL_DOUBLEBUFFER)),
59  myAmGaming(false),
60  myListInternal(false),
61  myListParking(true),
62  myListTeleporting(false) {
63 
64  FXFontDesc fdesc;
65  getApp()->getNormalFont()->getFontDesc(fdesc);
66  fdesc.weight = FXFont::Bold;
67  myBoldFont = new FXFont(getApp(), fdesc);
68 
69  myTopDock = new FXDockSite(this, LAYOUT_SIDE_TOP | LAYOUT_FILL_X);
70  myBottomDock = new FXDockSite(this, LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X);
71  myLeftDock = new FXDockSite(this, LAYOUT_SIDE_LEFT | LAYOUT_FILL_Y);
72  myRightDock = new FXDockSite(this, LAYOUT_SIDE_RIGHT | LAYOUT_FILL_Y);
73  if (myInstance != nullptr) {
74  throw ProcessError("MainWindow initialized twice");
75  }
76  myInstance = this;
77  //myGLVisual->setStencilSize(8); // enable stencil buffer
78 }
79 
80 
82  delete myBoldFont;
83  delete myTopDock;
84  delete myBottomDock;
85  delete myLeftDock;
86  delete myRightDock;
87 }
88 
89 
90 
91 void
93  myGLWindows.push_back(child);
94 }
95 
96 
97 void
99  std::vector<GUIGlChildWindow*>::iterator i = std::find(myGLWindows.begin(), myGLWindows.end(), child);
100  if (i != myGLWindows.end()) {
101  myGLWindows.erase(i);
102  }
103 }
104 
105 
106 void
107 GUIMainWindow::addChild(FXMainWindow* child) {
109  myTrackerWindows.push_back(child);
111 }
112 
113 
114 void
115 GUIMainWindow::removeChild(FXMainWindow* child) {
117  std::vector<FXMainWindow*>::iterator i = std::find(myTrackerWindows.begin(), myTrackerWindows.end(), child);
118  myTrackerWindows.erase(i);
120 }
121 
122 
123 std::vector<std::string>
125  std::vector<std::string> ret;
126  for (GUIGlChildWindow* const window : myGLWindows) {
127  ret.push_back(window->getTitle().text());
128  }
129  return ret;
130 }
131 
132 
134 GUIMainWindow::getViewByID(const std::string& id) const {
135  for (GUIGlChildWindow* const window : myGLWindows) {
136  if (std::string(window->getTitle().text()) == id) {
137  return window;
138  }
139  }
140  return nullptr;
141 }
142 
143 
144 FXFont*
146  return myBoldFont;
147 }
148 
149 
150 void
152  // inform views
153  myMDIClient->forallWindows(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), nullptr);
154  // inform other windows
156  for (int i = 0; i < (int)myTrackerWindows.size(); i++) {
157  myTrackerWindows[i]->handle(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), nullptr);
158  }
160 }
161 
162 
163 FXGLVisual*
165  return myGLVisual;
166 }
167 
168 
169 FXLabel&
171  return *myCartesianCoordinate;
172 }
173 
174 
175 FXLabel&
177  return *myGeoCoordinate;
178 }
179 
180 
183  if (myInstance != nullptr) {
184  return myInstance;
185  }
186  throw ProcessError("A GUIMainWindow instance was not yet constructed.");
187 }
188 
189 
192  GUIGlChildWindow* w = dynamic_cast<GUIGlChildWindow*>(myMDIClient->getActiveChild());
193  if (w != nullptr) {
194  return w->getView();
195  }
196  return nullptr;
197 }
198 
199 
200 void
202  int windowWidth = getApp()->reg().readIntEntry("SETTINGS", "width", 600);
203  int windowHeight = getApp()->reg().readIntEntry("SETTINGS", "height", 400);
204  const OptionsCont& oc = OptionsCont::getOptions();
205  if (oc.isSet("window-size")) {
206  std::vector<std::string> windowSize = oc.getStringVector("window-size");
207  if (windowSize.size() != 2) {
208  WRITE_ERROR("option window-size requires INT,INT");
209  } else {
210  try {
211  windowWidth = StringUtils::toInt(windowSize[0]);
212  windowHeight = StringUtils::toInt(windowSize[1]);
213  } catch (NumberFormatException& e) {
214  WRITE_ERROR("option window-size requires INT,INT " + toString(e.what()));
215  }
216  }
217  }
218  if (oc.isSet("window-size") || getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 0 || oc.isSet("window-pos")) {
219  // when restoring previous pos, make sure the window fits fully onto the current screen
220  int x = MAX2(0, MIN2(getApp()->reg().readIntEntry("SETTINGS", "x", 150), getApp()->getRootWindow()->getWidth() - windowWidth));
221  int y = MAX2(50, MIN2(getApp()->reg().readIntEntry("SETTINGS", "y", 150), getApp()->getRootWindow()->getHeight() - windowHeight));
222  if (oc.isSet("window-pos")) {
223  std::vector<std::string> windowPos = oc.getStringVector("window-pos");
224  if (windowPos.size() != 2) {
225  WRITE_ERROR("option window-pos requires INT,INT");
226  } else {
227  try {
228  x = StringUtils::toInt(windowPos[0]);
229  y = StringUtils::toInt(windowPos[1]);
230  } catch (NumberFormatException& e) {
231  WRITE_ERROR("option window-pos requires INT,INT " + toString(e.what()));
232  }
233  }
234  }
235  move(x, y);
236  resize(windowWidth, windowHeight);
237  }
238 }
239 
240 void
242  if (!myAmFullScreen) {
243  getApp()->reg().writeIntEntry("SETTINGS", "x", getX());
244  getApp()->reg().writeIntEntry("SETTINGS", "y", getY());
245  getApp()->reg().writeIntEntry("SETTINGS", "width", getWidth());
246  getApp()->reg().writeIntEntry("SETTINGS", "height", getHeight());
247  }
248 }
249 
250 /****************************************************************************/
251 
std::vector< FXMainWindow * > myTrackerWindows
FXLabel * myGeoCoordinate
GUISUMOAbstractView * getView() const
FXGLVisual * getGLVisual() const
void setWindowSizeAndPos()
perform initial window positioning and sizing according to user options / previous call ...
FXFont * myBoldFont
Font used for popup-menu titles.
FXDockSite * myRightDock
T MAX2(T a, T b)
Definition: StdDefs.h:76
FXGLVisual * myGLVisual
The gl-visual used.
std::vector< std::string > getViewIDs() const
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
FXLabel & getCartesianLabel()
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
GUISUMOAbstractView * getActiveView() const
get the active view or 0
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
static GUIMainWindow * getInstance()
FXDockSite * myLeftDock
static GUIMainWindow * myInstance
the singleton window instance
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
FXFont * getBoldFont()
T MIN2(T a, T b)
Definition: StdDefs.h:70
void addGLChild(GUIGlChildWindow *child)
Adds a further child window to the list.
FXLabel & getGeoLabel()
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
std::vector< GUIGlChildWindow * > myGLWindows
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:247
void unlock()
release mutex lock
Definition: MFXMutex.cpp:87
void removeChild(FXMainWindow *child)
FXLabel * myCartesianCoordinate
Labels for the current cartesian and geo-coordinate.
FXDockSite * myBottomDock
MFXMutex myTrackerLock
A lock to make the removal and addition of trackers secure.
A Simulation step was performed.
Definition: GUIAppEnum.h:294
FXDockSite * myTopDock
A storage for options typed value containers)
Definition: OptionsCont.h:92
virtual ~GUIMainWindow()
void lock()
lock mutex
Definition: MFXMutex.cpp:77
FXMDIClient * myMDIClient
The multi view panel.
bool myAmFullScreen
whether to show the window in full screen mode
GUIGlChildWindow * getViewByID(const std::string &id) const
void addChild(FXMainWindow *child)
void storeWindowSizeAndPos()
record window position and size in registry
void removeGLChild(GUIGlChildWindow *child)
removes the given child window from the list