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 
56 // ===========================================================================
57 // static member definitions
58 // ===========================================================================
60 
61 // ===========================================================================
62 // member method definitions
63 // ===========================================================================
65  FXMainWindow(a, "SUMO-gui main window", NULL, NULL, DECOR_ALL, 20, 20, 600, 400),
66  myGLVisual(new FXGLVisual(a, VISUAL_DOUBLEBUFFER)),
67  myAmGaming(false),
68  myListInternal(false),
69  myListParking(true),
70  myListTeleporting(false) {
71 
72  FXFontDesc fdesc;
73  getApp()->getNormalFont()->getFontDesc(fdesc);
74  fdesc.weight = FXFont::Bold;
75  myBoldFont = new FXFont(getApp(), fdesc);
76 
77  myTopDock = new FXDockSite(this, LAYOUT_SIDE_TOP | LAYOUT_FILL_X);
78  myBottomDock = new FXDockSite(this, LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X);
79  myLeftDock = new FXDockSite(this, LAYOUT_SIDE_LEFT | LAYOUT_FILL_Y);
80  myRightDock = new FXDockSite(this, LAYOUT_SIDE_RIGHT | LAYOUT_FILL_Y);
81  if (myInstance != 0) {
82  throw ProcessError("MainWindow initialized twice");
83  }
84  myInstance = this;
85  //myGLVisual->setStencilSize(8); // enable stencil buffer
86 }
87 
88 
90  delete myBoldFont;
91  delete myTopDock;
92  delete myBottomDock;
93  delete myLeftDock;
94  delete myRightDock;
95 }
96 
97 
98 
99 void
100 GUIMainWindow::addChild(FXMDIChild* child, bool /*updateOnSimStep !!!*/) {
101  mySubWindows.push_back(child);
102 }
103 
104 
105 void
106 GUIMainWindow::removeChild(FXMDIChild* child) {
107  std::vector<FXMDIChild*>::iterator i = std::find(mySubWindows.begin(), mySubWindows.end(), child);
108  if (i != mySubWindows.end()) {
109  mySubWindows.erase(i);
110  }
111 }
112 
113 
114 void
115 GUIMainWindow::addChild(FXMainWindow* child, bool /*updateOnSimStep !!!*/) {
117  myTrackerWindows.push_back(child);
119 }
120 
121 
122 void
123 GUIMainWindow::removeChild(FXMainWindow* child) {
125  std::vector<FXMainWindow*>::iterator i = std::find(myTrackerWindows.begin(), myTrackerWindows.end(), child);
126  myTrackerWindows.erase(i);
128 }
129 
130 
131 std::vector<std::string>
133  std::vector<std::string> ret;
134  for (std::vector<FXMDIChild*>::const_iterator i = mySubWindows.begin(); i != mySubWindows.end(); ++i) {
135  ret.push_back((*i)->getTitle().text());
136  }
137  return ret;
138 }
139 
140 
141 FXMDIChild*
142 GUIMainWindow::getViewByID(const std::string& id) const {
143  for (std::vector<FXMDIChild*>::const_iterator i = mySubWindows.begin(); i != mySubWindows.end(); ++i) {
144  if (std::string((*i)->getTitle().text()) == id) {
145  return *i;
146  }
147  }
148  return 0;
149 }
150 
151 
152 FXFont*
154  return myBoldFont;
155 }
156 
157 
158 void
160  // inform views
161  myMDIClient->forallWindows(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), 0);
162  // inform other windows
164  for (int i = 0; i < (int)myTrackerWindows.size(); i++) {
165  myTrackerWindows[i]->handle(this, FXSEL(SEL_COMMAND, MID_SIMSTEP), 0);
166  }
168 }
169 
170 
171 FXGLVisual*
173  return myGLVisual;
174 }
175 
176 
177 FXLabel&
179  return *myCartesianCoordinate;
180 }
181 
182 
183 FXLabel&
185  return *myGeoCoordinate;
186 }
187 
188 
191  if (myInstance != 0) {
192  return myInstance;
193  }
194  throw ProcessError("A GUIMainWindow instance was not yet constructed.");
195 }
196 
197 
200  GUIGlChildWindow* w = dynamic_cast<GUIGlChildWindow*>(myMDIClient->getActiveChild());
201  if (w != 0) {
202  return w->getView();
203  }
204  return 0;
205 }
206 
207 void
209  int windowWidth = getApp()->reg().readIntEntry("SETTINGS", "width", 600);
210  int windowHeight = getApp()->reg().readIntEntry("SETTINGS", "height", 400);
211  const OptionsCont& oc = OptionsCont::getOptions();
212  if (oc.isSet("window-size")) {
213  std::vector<std::string> windowSize = oc.getStringVector("window-size");
214  if (windowSize.size() != 2
215  || !TplCheck::_str2int(windowSize[0])
216  || !TplCheck::_str2int(windowSize[1])) {
217  WRITE_ERROR("option window-size requires INT,INT");
218  } else {
219  windowWidth = TplConvert::_str2int(windowSize[0]);
220  windowHeight = TplConvert::_str2int(windowSize[1]);
221  }
222  }
223  if (oc.isSet("window-size") || getApp()->reg().readIntEntry("SETTINGS", "maximized", 0) == 0 || oc.isSet("window-pos")) {
224  // when restoring previous pos, make sure the window fits fully onto the current screen
225  int x = MAX2(0, MIN2(getApp()->reg().readIntEntry("SETTINGS", "x", 150), getApp()->getRootWindow()->getWidth() - windowWidth));
226  int y = MAX2(0, MIN2(getApp()->reg().readIntEntry("SETTINGS", "y", 150), getApp()->getRootWindow()->getHeight() - windowHeight));
227  if (oc.isSet("window-pos")) {
228  std::vector<std::string> windowPos = oc.getStringVector("window-pos");
229  if (windowPos.size() != 2
230  || !TplCheck::_str2int(windowPos[0])
231  || !TplCheck::_str2int(windowPos[1])
232  ) {
233  WRITE_ERROR("option window-pos requires INT,INT");
234  } else {
235  x = TplConvert::_str2int(windowPos[0]);
236  y = TplConvert::_str2int(windowPos[1]);
237  }
238  }
239  setX(x);
240  setY(y);
241  setWidth(windowWidth);
242  setHeight(windowHeight);
243  }
244 }
245 
246 /****************************************************************************/
247 
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:48
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:70
FXGLVisual * myGLVisual
The gl-visual used.
std::vector< std::string > getViewIDs() const
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
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:160
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:64
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:92
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:99
virtual ~GUIMainWindow()
void lock()
lock mutex
Definition: MFXMutex.cpp:82
FXMDIClient * myMDIClient
The multi view panel.
A Simulation step was performed.
Definition: GUIAppEnum.h:293