SUMO - Simulation of Urban MObility
GUIMainWindow.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 //
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <algorithm>
35 #include <fx.h>
36 // fx3d includes windows.h so we need to guard against macro pollution
37 #ifdef WIN32
38 #define NOMINMAX
39 #endif
40 #include <fx3d.h>
41 #ifdef WIN32
42 #undef NOMINMAX
43 #endif
46 #include <utils/common/TplCheck.h>
51 #include "GUIAppEnum.h"
52 #include "GUIMainWindow.h"
53 #include "GUIGlChildWindow.h"
54 
55 #ifdef CHECK_MEMORY_LEAKS
56 #include <foreign/nvwa/debug_new.h>
57 #endif // CHECK_MEMORY_LEAKS
58 
59 
60 // ===========================================================================
61 // static member definitions
62 // ===========================================================================
64 
65 // ===========================================================================
66 // member method definitions
67 // ===========================================================================
69  FXMainWindow(a, "SUMO-gui main window", NULL, NULL, DECOR_ALL, 20, 20, 600, 400),
70  myGLVisual(new FXGLVisual(a, VISUAL_DOUBLEBUFFER)),
71  myAmGaming(false),
72  myListInternal(false),
73  myListParking(true),
74  myListTeleporting(false) {
75 
76  FXFontDesc fdesc;
77  getApp()->getNormalFont()->getFontDesc(fdesc);
78  fdesc.weight = FXFont::Bold;
79  myBoldFont = new FXFont(getApp(), fdesc);
80 
81  myTopDock = new FXDockSite(this, LAYOUT_SIDE_TOP | LAYOUT_FILL_X);
82  myBottomDock = new FXDockSite(this, LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X);
83  myLeftDock = new FXDockSite(this, LAYOUT_SIDE_LEFT | LAYOUT_FILL_Y);
84  myRightDock = new FXDockSite(this, LAYOUT_SIDE_RIGHT | LAYOUT_FILL_Y);
85  if (myInstance != 0) {
86  throw ProcessError("MainWindow initialized twice");
87  }
88  myInstance = this;
89  //myGLVisual->setStencilSize(8); // enable stencil buffer
90 }
91 
92 
94  delete myBoldFont;
95  delete myTopDock;
96  delete myBottomDock;
97  delete myLeftDock;
98  delete myRightDock;
99 }
100 
101 
102 
103 void
104 GUIMainWindow::addChild(FXMDIChild* child, bool /*updateOnSimStep !!!*/) {
105  mySubWindows.push_back(child);
106 }
107 
108 
109 void
110 GUIMainWindow::removeChild(FXMDIChild* child) {
111  std::vector<FXMDIChild*>::iterator i = std::find(mySubWindows.begin(), mySubWindows.end(), child);
112  if (i != mySubWindows.end()) {
113  mySubWindows.erase(i);
114  }
115 }
116 
117 
118 void
119 GUIMainWindow::addChild(FXMainWindow* child, bool /*updateOnSimStep !!!*/) {
121  myTrackerWindows.push_back(child);
123 }
124 
125 
126 void
127 GUIMainWindow::removeChild(FXMainWindow* child) {
129  std::vector<FXMainWindow*>::iterator i = std::find(myTrackerWindows.begin(), myTrackerWindows.end(), child);
130  myTrackerWindows.erase(i);
132 }
133 
134 
135 std::vector<std::string>
137  std::vector<std::string> ret;
138  for (std::vector<FXMDIChild*>::const_iterator i = mySubWindows.begin(); i != mySubWindows.end(); ++i) {
139  ret.push_back((*i)->getTitle().text());
140  }
141  return ret;
142 }
143 
144 
145 FXMDIChild*
146 GUIMainWindow::getViewByID(const std::string& id) const {
147  for (std::vector<FXMDIChild*>::const_iterator i = mySubWindows.begin(); i != mySubWindows.end(); ++i) {
148  if (std::string((*i)->getTitle().text()) == id) {
149  return *i;
150  }
151  }
152  return 0;
153 }
154 
155 
156 FXFont*
158  return myBoldFont;
159 }
160 
161 
162 void
164  // inform views
165  myMDIClient->forallWindows(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), 0);
166  // inform other windows
168  for (int i = 0; i < (int)myTrackerWindows.size(); i++) {
169  myTrackerWindows[i]->handle(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), 0);
170  }
172 }
173 
174 
175 FXGLVisual*
177  return myGLVisual;
178 }
179 
180 
181 FXLabel&
183  return *myCartesianCoordinate;
184 }
185 
186 
187 FXLabel&
189  return *myGeoCoordinate;
190 }
191 
192 
195  if (myInstance != 0) {
196  return myInstance;
197  }
198  throw ProcessError("A GUIMainWindow instance was not yet constructed.");
199 }
200 
201 
204  GUIGlChildWindow* w = dynamic_cast<GUIGlChildWindow*>(myMDIClient->getActiveChild());
205  if (w != 0) {
206  return w->getView();
207  }
208  return 0;
209 }
210 
211 void
213  int windowWidth = getApp()->reg().readIntEntry("SETTINGS", "width", 600);
214  int windowHeight = getApp()->reg().readIntEntry("SETTINGS", "height", 400);
215  const OptionsCont& oc = OptionsCont::getOptions();
216  if (oc.isSet("window-size")) {
217  std::vector<std::string> windowSize = oc.getStringVector("window-size");
218  if (windowSize.size() != 2
219  || !TplCheck::_str2int(windowSize[0])
220  || !TplCheck::_str2int(windowSize[1])) {
221  WRITE_ERROR("option window-size requires INT,INT");
222  } else {
223  windowWidth = TplConvert::_str2int(windowSize[0]);
224  windowHeight = TplConvert::_str2int(windowSize[1]);
225  }
226  }
227  if (oc.isSet("window-size") || getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 0 || oc.isSet("window-pos")) {
228  // when restoring previous pos, make sure the window fits fully onto the current screen
229  int x = MAX2(0, MIN2(getApp()->reg().readIntEntry("SETTINGS", "x", 150), getApp()->getRootWindow()->getWidth() - windowWidth));
230  int y = MAX2(0, MIN2(getApp()->reg().readIntEntry("SETTINGS", "y", 150), getApp()->getRootWindow()->getHeight() - windowHeight));
231  if (oc.isSet("window-pos")) {
232  std::vector<std::string> windowPos = oc.getStringVector("window-pos");
233  if (windowPos.size() != 2
234  || !TplCheck::_str2int(windowPos[0])
235  || !TplCheck::_str2int(windowPos[1])
236  ) {
237  WRITE_ERROR("option window-pos requires INT,INT");
238  } else {
239  x = TplConvert::_str2int(windowPos[0]);
240  y = TplConvert::_str2int(windowPos[1]);
241  }
242  }
243  setX(x);
244  setY(y);
245  setWidth(windowWidth);
246  setHeight(windowHeight);
247  }
248 }
249 
250 /****************************************************************************/
251 
std::vector< FXMainWindow * > myTrackerWindows
FXLabel * myGeoCoordinate
GUISUMOAbstractView * getView() const
static bool _str2int(const std::string &data)
check if a String can be parsed into a int check overflows
Definition: TplCheck.h:48
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) ...
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:70
FXGLVisual * myGLVisual
The gl-visual used.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
A Simulation step was performed.
Definition: GUIAppEnum.h:293
FXMDIChild * getViewByID(const std::string &id) const
#define new
Definition: debug_new.h:121
FXLabel & getCartesianLabel()
std::vector< FXMDIChild * > mySubWindows
void addChild(FXMDIChild *child, bool updateOnSimStep=true)
Adds a further child window to the list.
GUISUMOAbstractView * getActiveView() const
get the active view or 0
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:160
static GUIMainWindow * myInstance
the singleton window instance
FXFont * getBoldFont()
T MIN2(T a, T b)
Definition: StdDefs.h:64
FXGLVisual * getGLVisual() const
FXLabel & getGeoLabel()
void removeChild(FXMDIChild *child)
removes the given child window from the list
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
void unlock()
release mutex lock
Definition: MFXMutex.cpp:96
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.
FXDockSite * myTopDock
A storage for options typed value containers)
Definition: OptionsCont.h:99
virtual ~GUIMainWindow()
void lock()
lock mutex
Definition: MFXMutex.cpp:86
FXMDIClient * myMDIClient
The multi view panel.
std::vector< std::string > getViewIDs() const
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.