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-2019 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 /****************************************************************************/
16 //
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <string>
26 #include <algorithm>
27 #include <fx.h>
28 // fx3d includes windows.h so we need to guard against macro pollution
29 #ifdef WIN32
30 #define NOMINMAX
31 #endif
32 #include <fx3d.h>
33 #ifdef WIN32
34 #undef NOMINMAX
35 #endif
41 #include "GUIAppEnum.h"
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(a, "SUMO-gui main window", nullptr, nullptr, DECOR_ALL, 20, 20, 600, 400),
56  myAmFullScreen(false),
57  myTrackerLock(true),
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) {
108  myTrackerLock.lock();
109  myTrackerWindows.push_back(child);
110  myTrackerLock.unlock();
111 }
112 
113 
114 void
115 GUIMainWindow::removeChild(FXMainWindow* child) {
116  myTrackerLock.lock();
117  std::vector<FXMainWindow*>::iterator i = std::find(myTrackerWindows.begin(), myTrackerWindows.end(), child);
118  myTrackerWindows.erase(i);
119  myTrackerLock.unlock();
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
155  myTrackerLock.lock();
156  for (int i = 0; i < (int)myTrackerWindows.size(); i++) {
157  myTrackerWindows[i]->handle(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), nullptr);
158  }
159  myTrackerLock.unlock();
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 
GUIMainWindow::~GUIMainWindow
virtual ~GUIMainWindow()
Definition: GUIMainWindow.cpp:81
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:135
MFXImageHelper.h
GUIMainWindow::myAmFullScreen
bool myAmFullScreen
whether to show the window in full screen mode
Definition: GUIMainWindow.h:144
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:73
GUIMainWindow::storeWindowSizeAndPos
void storeWindowSizeAndPos()
record window position and size in registry
Definition: GUIMainWindow.cpp:241
GUISUMOAbstractView
Definition: GUISUMOAbstractView.h:72
GUIMainWindow::myMDIClient
FXMDIClient * myMDIClient
The multi view panel.
Definition: GUIMainWindow.h:155
GUIMainWindow::myTopDock
FXDockSite * myTopDock
Definition: GUIMainWindow.h:167
OptionsCont.h
MsgHandler.h
GUIMainWindow::myBoldFont
FXFont * myBoldFont
Font used for popup-menu titles.
Definition: GUIMainWindow.h:152
GUIMainWindow::GUIMainWindow
GUIMainWindow(FXApp *a)
Definition: GUIMainWindow.cpp:54
GUIMainWindow::myGLWindows
std::vector< GUIGlChildWindow * > myGLWindows
Definition: GUIMainWindow.h:146
GUIMainWindow::getViewIDs
std::vector< std::string > getViewIDs() const
Definition: GUIMainWindow.cpp:124
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
GUIMainWindow.h
GUIAppEnum.h
OptionsCont::getStringVector
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
Definition: OptionsCont.cpp:235
GUIMainWindow::myTrackerLock
FXMutex myTrackerLock
A lock to make the removal and addition of trackers secure.
Definition: GUIMainWindow.h:149
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
GUIMainWindow::getActiveView
GUISUMOAbstractView * getActiveView() const
get the active view or 0
Definition: GUIMainWindow.cpp:191
NumberFormatException
Definition: UtilExceptions.h:95
GUIMainWindow::myCartesianCoordinate
FXLabel * myCartesianCoordinate
Labels for the current cartesian and geo-coordinate.
Definition: GUIMainWindow.h:161
GUIMainWindow::getInstance
static GUIMainWindow * getInstance()
Definition: GUIMainWindow.cpp:182
GUIMainWindow::setWindowSizeAndPos
void setWindowSizeAndPos()
perform initial window positioning and sizing according to user options / previous call
Definition: GUIMainWindow.cpp:201
GUIMainWindow::getCartesianLabel
FXLabel & getCartesianLabel()
Definition: GUIMainWindow.cpp:170
GUIMainWindow::myTrackerWindows
std::vector< FXMainWindow * > myTrackerWindows
Definition: GUIMainWindow.h:147
GUITexturesHelper.h
GUIMainWindow::getViewByID
GUIGlChildWindow * getViewByID(const std::string &id) const
Definition: GUIMainWindow.cpp:134
MID_SIMSTEP
A Simulation step was performed.
Definition: GUIAppEnum.h:456
GUIMainWindow::removeChild
void removeChild(FXMainWindow *child)
Definition: GUIMainWindow.cpp:115
GUIMainWindow::myBottomDock
FXDockSite * myBottomDock
Definition: GUIMainWindow.h:167
ProcessError
Definition: UtilExceptions.h:39
GUIMainWindow::myLeftDock
FXDockSite * myLeftDock
Definition: GUIMainWindow.h:167
GUIMainWindow::myRightDock
FXDockSite * myRightDock
Definition: GUIMainWindow.h:167
GUIMainWindow::updateChildren
void updateChildren()
Definition: GUIMainWindow.cpp:151
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
GUIMainWindow::getGeoLabel
FXLabel & getGeoLabel()
Definition: GUIMainWindow.cpp:176
GUIMainWindow::getGLVisual
FXGLVisual * getGLVisual() const
Definition: GUIMainWindow.cpp:164
GUIMainWindow::addGLChild
void addGLChild(GUIGlChildWindow *child)
Adds a further child window to the list.
Definition: GUIMainWindow.cpp:92
GUIMainWindow::myGLVisual
FXGLVisual * myGLVisual
The gl-visual used.
Definition: GUIMainWindow.h:165
GUIMainWindow::myGeoCoordinate
FXLabel * myGeoCoordinate
Definition: GUIMainWindow.h:161
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
StringUtils.h
StringUtils::toInt
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
Definition: StringUtils.cpp:278
GUIMainWindow
Definition: GUIMainWindow.h:46
GUIMainWindow::getBoldFont
FXFont * getBoldFont()
Definition: GUIMainWindow.cpp:145
GUIGlChildWindow.h
GUIMainWindow::removeGLChild
void removeGLChild(GUIGlChildWindow *child)
removes the given child window from the list
Definition: GUIMainWindow.cpp:98
config.h
GUIGlChildWindow
Definition: GUIGlChildWindow.h:40
GUIMainWindow::addChild
void addChild(FXMainWindow *child)
Definition: GUIMainWindow.cpp:107
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:283
GUIMainWindow::myInstance
static GUIMainWindow * myInstance
the singleton window instance
Definition: GUIMainWindow.h:182
GUIGlChildWindow::getView
GUISUMOAbstractView * getView() const
return GUISUMOAbstractView
Definition: GUIGlChildWindow.cpp:99