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
39 #include <utils/common/TplCheck.h>
44 #include "GUIAppEnum.h"
45 #include "GUIMainWindow.h"
46 #include "GUIGlChildWindow.h"
47 
48 
49 // ===========================================================================
50 // static member definitions
51 // ===========================================================================
53 
54 // ===========================================================================
55 // member method definitions
56 // ===========================================================================
58  FXMainWindow(a, "SUMO-gui main window", NULL, NULL, DECOR_ALL, 20, 20, 600, 400),
59  myAmFullScreen(false),
60  myGLVisual(new FXGLVisual(a, VISUAL_DOUBLEBUFFER)),
61  myAmGaming(false),
62  myListInternal(false),
63  myListParking(true),
64  myListTeleporting(false) {
65 
66  FXFontDesc fdesc;
67  getApp()->getNormalFont()->getFontDesc(fdesc);
68  fdesc.weight = FXFont::Bold;
69  myBoldFont = new FXFont(getApp(), fdesc);
70 
71  myTopDock = new FXDockSite(this, LAYOUT_SIDE_TOP | LAYOUT_FILL_X);
72  myBottomDock = new FXDockSite(this, LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X);
73  myLeftDock = new FXDockSite(this, LAYOUT_SIDE_LEFT | LAYOUT_FILL_Y);
74  myRightDock = new FXDockSite(this, LAYOUT_SIDE_RIGHT | LAYOUT_FILL_Y);
75  if (myInstance != 0) {
76  throw ProcessError("MainWindow initialized twice");
77  }
78  myInstance = this;
79  //myGLVisual->setStencilSize(8); // enable stencil buffer
80 }
81 
82 
84  delete myBoldFont;
85  delete myTopDock;
86  delete myBottomDock;
87  delete myLeftDock;
88  delete myRightDock;
89 }
90 
91 
92 
93 void
94 GUIMainWindow::addChild(FXMDIChild* child, bool /*updateOnSimStep !!!*/) {
95  mySubWindows.push_back(child);
96 }
97 
98 
99 void
100 GUIMainWindow::removeChild(FXMDIChild* child) {
101  std::vector<FXMDIChild*>::iterator i = std::find(mySubWindows.begin(), mySubWindows.end(), child);
102  if (i != mySubWindows.end()) {
103  mySubWindows.erase(i);
104  }
105 }
106 
107 
108 void
109 GUIMainWindow::addChild(FXMainWindow* child, bool /*updateOnSimStep !!!*/) {
111  myTrackerWindows.push_back(child);
113 }
114 
115 
116 void
117 GUIMainWindow::removeChild(FXMainWindow* child) {
119  std::vector<FXMainWindow*>::iterator i = std::find(myTrackerWindows.begin(), myTrackerWindows.end(), child);
120  myTrackerWindows.erase(i);
122 }
123 
124 
125 std::vector<std::string>
127  std::vector<std::string> ret;
128  for (std::vector<FXMDIChild*>::const_iterator i = mySubWindows.begin(); i != mySubWindows.end(); ++i) {
129  ret.push_back((*i)->getTitle().text());
130  }
131  return ret;
132 }
133 
134 
135 FXMDIChild*
136 GUIMainWindow::getViewByID(const std::string& id) const {
137  for (std::vector<FXMDIChild*>::const_iterator i = mySubWindows.begin(); i != mySubWindows.end(); ++i) {
138  if (std::string((*i)->getTitle().text()) == id) {
139  return *i;
140  }
141  }
142  return 0;
143 }
144 
145 
146 FXFont*
148  return myBoldFont;
149 }
150 
151 
152 void
154  // inform views
155  myMDIClient->forallWindows(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), 0);
156  // inform other windows
158  for (int i = 0; i < (int)myTrackerWindows.size(); i++) {
159  myTrackerWindows[i]->handle(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), 0);
160  }
162 }
163 
164 
165 FXGLVisual*
167  return myGLVisual;
168 }
169 
170 
171 FXLabel&
173  return *myCartesianCoordinate;
174 }
175 
176 
177 FXLabel&
179  return *myGeoCoordinate;
180 }
181 
182 
185  if (myInstance != 0) {
186  return myInstance;
187  }
188  throw ProcessError("A GUIMainWindow instance was not yet constructed.");
189 }
190 
191 
194  GUIGlChildWindow* w = dynamic_cast<GUIGlChildWindow*>(myMDIClient->getActiveChild());
195  if (w != 0) {
196  return w->getView();
197  }
198  return 0;
199 }
200 
201 void
203  int windowWidth = getApp()->reg().readIntEntry("SETTINGS", "width", 600);
204  int windowHeight = getApp()->reg().readIntEntry("SETTINGS", "height", 400);
205  const OptionsCont& oc = OptionsCont::getOptions();
206  if (oc.isSet("window-size")) {
207  std::vector<std::string> windowSize = oc.getStringVector("window-size");
208  if (windowSize.size() != 2
209  || !TplCheck::_str2int(windowSize[0])
210  || !TplCheck::_str2int(windowSize[1])) {
211  WRITE_ERROR("option window-size requires INT,INT");
212  } else {
213  windowWidth = TplConvert::_str2int(windowSize[0]);
214  windowHeight = TplConvert::_str2int(windowSize[1]);
215  }
216  }
217  if (oc.isSet("window-size") || getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 0 || oc.isSet("window-pos")) {
218  // when restoring previous pos, make sure the window fits fully onto the current screen
219  int x = MAX2(0, MIN2(getApp()->reg().readIntEntry("SETTINGS", "x", 150), getApp()->getRootWindow()->getWidth() - windowWidth));
220  int y = MAX2(50, MIN2(getApp()->reg().readIntEntry("SETTINGS", "y", 150), getApp()->getRootWindow()->getHeight() - windowHeight));
221  if (oc.isSet("window-pos")) {
222  std::vector<std::string> windowPos = oc.getStringVector("window-pos");
223  if (windowPos.size() != 2
224  || !TplCheck::_str2int(windowPos[0])
225  || !TplCheck::_str2int(windowPos[1])
226  ) {
227  WRITE_ERROR("option window-pos requires INT,INT");
228  } else {
229  x = TplConvert::_str2int(windowPos[0]);
230  y = TplConvert::_str2int(windowPos[1]);
231  }
232  }
233  move(x, y);
234  resize(windowWidth, windowHeight);
235  }
236 }
237 
238 void
240  if (!myAmFullScreen) {
241  getApp()->reg().writeIntEntry("SETTINGS", "x", getX());
242  getApp()->reg().writeIntEntry("SETTINGS", "y", getY());
243  getApp()->reg().writeIntEntry("SETTINGS", "width", getWidth());
244  getApp()->reg().writeIntEntry("SETTINGS", "height", getHeight());
245  }
246 }
247 
248 /****************************************************************************/
249 
std::vector< FXMainWindow * > myTrackerWindows
FXLabel * myGeoCoordinate
static bool _str2int(const std::string &data)
check if a String can be parsed into a int check overflows
Definition: TplCheck.h:41
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:68
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.
std::vector< FXMDIChild * > mySubWindows
GUISUMOAbstractView * getActiveView() const
get the active view or 0
void addChild(FXMDIChild *child, bool updateOnSimStep=true)
Adds a further child window to the list.
static GUIMainWindow * getInstance()
FXDockSite * myLeftDock
static int _str2int(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
Definition: TplConvert.h:161
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:62
FXLabel & getGeoLabel()
void removeChild(FXMDIChild *child)
removes the given child window from the list
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:248
void unlock()
release mutex lock
Definition: MFXMutex.cpp:87
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.
FXMDIChild * getViewByID(const std::string &id) const
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
void storeWindowSizeAndPos()
record window position and size in registry