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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include <algorithm>
34 #include <fx.h>
35 // fx3d includes windows.h so we need to guard against macro pollution
36 #ifdef WIN32
37 #define NOMINMAX
38 #endif
39 #include <fx3d.h>
40 #ifdef WIN32
41 #undef NOMINMAX
42 #endif
45 #include <utils/common/TplCheck.h>
50 #include "GUIAppEnum.h"
51 #include "GUIMainWindow.h"
52 #include "GUIGlChildWindow.h"
53 
54 
55 // ===========================================================================
56 // static member definitions
57 // ===========================================================================
59 
60 // ===========================================================================
61 // member method definitions
62 // ===========================================================================
64  FXMainWindow(a, "SUMO-gui main window", NULL, NULL, DECOR_ALL, 20, 20, 600, 400),
65  myGLVisual(new FXGLVisual(a, VISUAL_DOUBLEBUFFER)),
66  myAmGaming(false),
67  myListInternal(false),
68  myListParking(true),
69  myListTeleporting(false) {
70 
71  FXFontDesc fdesc;
72  getApp()->getNormalFont()->getFontDesc(fdesc);
73  fdesc.weight = FXFont::Bold;
74  myBoldFont = new FXFont(getApp(), fdesc);
75 
76  myTopDock = new FXDockSite(this, LAYOUT_SIDE_TOP | LAYOUT_FILL_X);
77  myBottomDock = new FXDockSite(this, LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X);
78  myLeftDock = new FXDockSite(this, LAYOUT_SIDE_LEFT | LAYOUT_FILL_Y);
79  myRightDock = new FXDockSite(this, LAYOUT_SIDE_RIGHT | LAYOUT_FILL_Y);
80  if (myInstance != 0) {
81  throw ProcessError("MainWindow initialized twice");
82  }
83  myInstance = this;
84  //myGLVisual->setStencilSize(8); // enable stencil buffer
85 }
86 
87 
89  delete myBoldFont;
90  delete myTopDock;
91  delete myBottomDock;
92  delete myLeftDock;
93  delete myRightDock;
94 }
95 
96 
97 
98 void
99 GUIMainWindow::addChild(FXMDIChild* child, bool /*updateOnSimStep !!!*/) {
100  mySubWindows.push_back(child);
101 }
102 
103 
104 void
105 GUIMainWindow::removeChild(FXMDIChild* child) {
106  std::vector<FXMDIChild*>::iterator i = std::find(mySubWindows.begin(), mySubWindows.end(), child);
107  if (i != mySubWindows.end()) {
108  mySubWindows.erase(i);
109  }
110 }
111 
112 
113 void
114 GUIMainWindow::addChild(FXMainWindow* child, bool /*updateOnSimStep !!!*/) {
116  myTrackerWindows.push_back(child);
118 }
119 
120 
121 void
122 GUIMainWindow::removeChild(FXMainWindow* child) {
124  std::vector<FXMainWindow*>::iterator i = std::find(myTrackerWindows.begin(), myTrackerWindows.end(), child);
125  myTrackerWindows.erase(i);
127 }
128 
129 
130 std::vector<std::string>
132  std::vector<std::string> ret;
133  for (std::vector<FXMDIChild*>::const_iterator i = mySubWindows.begin(); i != mySubWindows.end(); ++i) {
134  ret.push_back((*i)->getTitle().text());
135  }
136  return ret;
137 }
138 
139 
140 FXMDIChild*
141 GUIMainWindow::getViewByID(const std::string& id) const {
142  for (std::vector<FXMDIChild*>::const_iterator i = mySubWindows.begin(); i != mySubWindows.end(); ++i) {
143  if (std::string((*i)->getTitle().text()) == id) {
144  return *i;
145  }
146  }
147  return 0;
148 }
149 
150 
151 FXFont*
153  return myBoldFont;
154 }
155 
156 
157 void
159  // inform views
160  myMDIClient->forallWindows(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), 0);
161  // inform other windows
163  for (int i = 0; i < (int)myTrackerWindows.size(); i++) {
164  myTrackerWindows[i]->handle(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), 0);
165  }
167 }
168 
169 
170 FXGLVisual*
172  return myGLVisual;
173 }
174 
175 
176 FXLabel&
178  return *myCartesianCoordinate;
179 }
180 
181 
182 FXLabel&
184  return *myGeoCoordinate;
185 }
186 
187 
190  if (myInstance != 0) {
191  return myInstance;
192  }
193  throw ProcessError("A GUIMainWindow instance was not yet constructed.");
194 }
195 
196 
199  GUIGlChildWindow* w = dynamic_cast<GUIGlChildWindow*>(myMDIClient->getActiveChild());
200  if (w != 0) {
201  return w->getView();
202  }
203  return 0;
204 }
205 
206 void
208  int windowWidth = getApp()->reg().readIntEntry("SETTINGS", "width", 600);
209  int windowHeight = getApp()->reg().readIntEntry("SETTINGS", "height", 400);
210  const OptionsCont& oc = OptionsCont::getOptions();
211  if (oc.isSet("window-size")) {
212  std::vector<std::string> windowSize = oc.getStringVector("window-size");
213  if (windowSize.size() != 2
214  || !TplCheck::_str2int(windowSize[0])
215  || !TplCheck::_str2int(windowSize[1])) {
216  WRITE_ERROR("option window-size requires INT,INT");
217  } else {
218  windowWidth = TplConvert::_str2int(windowSize[0]);
219  windowHeight = TplConvert::_str2int(windowSize[1]);
220  }
221  }
222  if (oc.isSet("window-size") || getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 0 || oc.isSet("window-pos")) {
223  // when restoring previous pos, make sure the window fits fully onto the current screen
224  int x = MAX2(0, MIN2(getApp()->reg().readIntEntry("SETTINGS", "x", 150), getApp()->getRootWindow()->getWidth() - windowWidth));
225  int y = MAX2(0, MIN2(getApp()->reg().readIntEntry("SETTINGS", "y", 150), getApp()->getRootWindow()->getHeight() - windowHeight));
226  if (oc.isSet("window-pos")) {
227  std::vector<std::string> windowPos = oc.getStringVector("window-pos");
228  if (windowPos.size() != 2
229  || !TplCheck::_str2int(windowPos[0])
230  || !TplCheck::_str2int(windowPos[1])
231  ) {
232  WRITE_ERROR("option window-pos requires INT,INT");
233  } else {
234  x = TplConvert::_str2int(windowPos[0]);
235  y = TplConvert::_str2int(windowPos[1]);
236  }
237  }
238  move(x, y);
239  resize(windowWidth, windowHeight);
240  }
241 }
242 
243 /****************************************************************************/
244 
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:47
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:73
FXGLVisual * myGLVisual
The gl-visual used.
std::vector< std::string > getViewIDs() const
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
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:167
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:67
FXLabel & getGeoLabel()
void removeChild(FXMDIChild *child)
removes the given child window from the list
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
void unlock()
release mutex lock
Definition: MFXMutex.cpp:93
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
FXDockSite * myTopDock
A storage for options typed value containers)
Definition: OptionsCont.h:98
virtual ~GUIMainWindow()
void lock()
lock mutex
Definition: MFXMutex.cpp:83
FXMDIClient * myMDIClient
The multi view panel.
A Simulation step was performed.
Definition: GUIAppEnum.h:290