SUMO - Simulation of Urban MObility
GUISUMOViewParent.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // A single child window which contains a view of the simulation area
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
36 #include <vector>
37 #include <fxkeys.h>
39 #include <utils/geom/Position.h>
40 #include <utils/geom/Boundary.h>
53 #include <guisim/GUIVehicle.h>
54 #include <guisim/GUIPerson.h>
55 #include <guisim/GUIEdge.h>
56 #include <guisim/GUILane.h>
57 #include <guisim/GUINet.h>
60 #include <microsim/MSJunction.h>
61 #include <microsim/MSGlobals.h>
62 #include "GUIGlobals.h"
63 #include "GUIViewTraffic.h"
64 #include "GUIApplicationWindow.h"
65 #include "GUISUMOViewParent.h"
66 
67 #ifdef HAVE_INTERNAL
68 #include <mesogui/GUIMEVehicleControl.h>
69 #endif
70 
71 #ifdef HAVE_OSG
72 #include <osgview/GUIOSGView.h>
73 #endif
74 
75 #ifdef CHECK_MEMORY_LEAKS
76 #include <foreign/nvwa/debug_new.h>
77 #endif // CHECK_MEMORY_LEAKS
78 
79 
80 // ===========================================================================
81 // FOX callback mapping
82 // ===========================================================================
83 FXDEFMAP(GUISUMOViewParent) GUISUMOViewParentMap[] = {
85  // FXMAPFUNC(SEL_COMMAND, MID_ALLOWROTATION, GUISUMOViewParent::onCmdAllowRotation),
86  FXMAPFUNC(SEL_COMMAND, MID_LOCATEJUNCTION, GUISUMOViewParent::onCmdLocate),
87  FXMAPFUNC(SEL_COMMAND, MID_LOCATEEDGE, GUISUMOViewParent::onCmdLocate),
88  FXMAPFUNC(SEL_COMMAND, MID_LOCATEVEHICLE, GUISUMOViewParent::onCmdLocate),
89  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPERSON, GUISUMOViewParent::onCmdLocate),
90  FXMAPFUNC(SEL_COMMAND, MID_LOCATETLS, GUISUMOViewParent::onCmdLocate),
91  FXMAPFUNC(SEL_COMMAND, MID_LOCATEADD, GUISUMOViewParent::onCmdLocate),
92  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOI, GUISUMOViewParent::onCmdLocate),
93  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOLY, GUISUMOViewParent::onCmdLocate),
94  FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUISUMOViewParent::onSimStep),
95 
96 };
97 
98 // Object implementation
99 FXIMPLEMENT(GUISUMOViewParent, GUIGlChildWindow, GUISUMOViewParentMap, ARRAYNUMBER(GUISUMOViewParentMap))
100 
101 
102 // ===========================================================================
103 // member method definitions
104 // ===========================================================================
105 GUISUMOViewParent::GUISUMOViewParent(FXMDIClient* p, FXMDIMenu* mdimenu,
106  const FXString& name,
107  GUIMainWindow* parentWindow,
108  FXIcon* ic, FXuint opts,
109  FXint x, FXint y, FXint w, FXint h)
110  : GUIGlChildWindow(p, parentWindow, mdimenu, name, ic, opts, x, y, w, h) {
111  myParent->addChild(this, false);
112 }
113 
114 
117  switch (type) {
118  default:
119  case VIEW_2D_OPENGL:
120  myView = new GUIViewTraffic(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
121  break;
122 #ifdef HAVE_OSG
123  case VIEW_3D_OSG:
124  myView = new GUIOSGView(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
125  break;
126 #endif
127  }
128  myView->buildViewToolBars(*this);
129  if (myParent->isGaming()) {
130  myNavigationToolBar->hide();
131  }
132  return myView;
133 }
134 
135 
137  myParent->removeChild(this);
138 }
139 
140 
141 void
143  if (value) {
144  myNavigationToolBar->show();
145  } else {
146  myNavigationToolBar->hide();
147  }
148 }
149 
150 
151 long
152 GUISUMOViewParent::onCmdMakeSnapshot(FXObject*, FXSelector, void*) {
153  // get the new file name
154  FXFileDialog opendialog(this, "Save Snapshot");
155  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
156  opendialog.setSelectMode(SELECTFILE_ANY);
157  opendialog.setPatternList("All Image Files (*.gif, *.bmp, *.xpm, *.pcx, *.ico, *.rgb, *.xbm, *.tga, *.png, *.jpg, *.jpeg, *.tif, *.tiff, *.ps, *.eps, *.pdf, *.svg, *.tex, *.pgf)\n"
158  "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
159  "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
160  "JPEG Image (*.jpg, *.jpeg)\nTIFF Image (*.tif, *.tiff)\n"
161  "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n"
162  "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n"
163  "All Files (*)");
164  if (gCurrentFolder.length() != 0) {
165  opendialog.setDirectory(gCurrentFolder);
166  }
167  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
168  return 1;
169  }
170  gCurrentFolder = opendialog.getDirectory();
171  std::string file = opendialog.getFilename().text();
172  std::string error = myView->makeSnapshot(file);
173  if (error != "") {
174  FXMessageBox::error(this, MBOX_OK, "Saving failed.", "%s", error.c_str());
175  }
176  return 1;
177 }
178 
179 
180 long
181 GUISUMOViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
182  std::vector<GUIGlID> ids;
183  GUIIcon icon;
184  std::string title;
185  switch (FXSELID(sel)) {
186  case MID_LOCATEJUNCTION:
187  ids = static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs(myParent->listInternal());
188  icon = ICON_LOCATEJUNCTION;
189  title = "Junction Chooser";
190  break;
191  case MID_LOCATEEDGE:
193  icon = ICON_LOCATEEDGE;
194  title = "Edge Chooser";
195  break;
196  case MID_LOCATEVEHICLE:
198 #ifdef HAVE_INTERNAL
199  static_cast<GUIMEVehicleControl*>(static_cast<GUINet*>(MSNet::getInstance())->getGUIMEVehicleControl())->insertVehicleIDs(ids);
200 #endif
201  } else {
202  static_cast<GUIVehicleControl&>(MSNet::getInstance()->getVehicleControl()).insertVehicleIDs(ids);
203  }
204  icon = ICON_LOCATEVEHICLE;
205  title = "Vehicle Chooser";
206  break;
207  case MID_LOCATEPERSON:
208  static_cast<GUIPersonControl&>(MSNet::getInstance()->getPersonControl()).insertPersonIDs(ids);
209  icon = ICON_LOCATEPERSON;
210  title = "Person Chooser";
211  break;
212  case MID_LOCATETLS:
213  ids = static_cast<GUINet*>(GUINet::getInstance())->getTLSIDs();
214  icon = ICON_LOCATETLS;
215  title = "Traffic Lights Chooser";
216  break;
217  case MID_LOCATEADD:
219  icon = ICON_LOCATEADD;
220  title = "Additional Objects Chooser";
221  break;
222  case MID_LOCATEPOI:
223  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPOIIds();
224  icon = ICON_LOCATEPOI;
225  title = "POI Chooser";
226  break;
227  case MID_LOCATEPOLY:
228  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPolygonIDs();
229  icon = ICON_LOCATEPOLY;
230  title = "Polygon Chooser";
231  break;
232  default:
233  throw ProcessError("Unknown Message ID in onCmdLocate");
234  }
235  myLocatorPopup->popdown();
236  myLocatorButton->killFocus();
237  myLocatorPopup->update();
239  this, GUIIconSubSys::getIcon(icon), title.c_str(), ids, GUIGlObjectStorage::gIDStorage);
240  chooser->create();
241  chooser->show();
242  return 1;
243 }
244 
245 
246 long
247 GUISUMOViewParent::onSimStep(FXObject*, FXSelector, void*) {
248  myView->update();
250  return 1;
251 }
252 
253 
254 bool
256  GUIGlObjectType type = o->getType();
257  if (gSelected.isSelected(type, o->getGlID())) {
258  return true;
259  } else if (type == GLO_EDGE) {
260  GUIEdge* edge = dynamic_cast<GUIEdge*>(o);
261  if (edge == 0) {
262  // hmph, just some security stuff
263  return false;
264  }
265  const std::vector<MSLane*>& lanes = edge->getLanes();
266  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
267  GUILane* l = dynamic_cast<GUILane*>(*j);
268  if (l != 0 && gSelected.isSelected(GLO_LANE, l->getGlID())) {
269  return true;
270  }
271  }
272  return false;
273  } else {
274  return false;
275  }
276 }
277 
278 
279 long
280 GUISUMOViewParent::onKeyPress(FXObject* o, FXSelector sel, void* data) {
281  myView->onKeyPress(o, sel, data);
282  return 0;
283 }
284 
285 
286 long
287 GUISUMOViewParent::onKeyRelease(FXObject* o, FXSelector sel, void* data) {
288  myView->onKeyRelease(o, sel, data);
289  return 0;
290 }
291 
292 
293 /****************************************************************************/
294 
static std::vector< GUIGlID > getIDList()
Returns the list of gl-ids of all additional objects.
void show()
sets the focus after the window is created to work-around bug in libfox
bool isSelected(GUIGlObject *o) const
true if the object is selected (may include extra logic besides calling gSelected) ...
Make snapshot - button.
Definition: GUIAppEnum.h:185
Locate vehicle - button.
Definition: GUIAppEnum.h:167
The class responsible for building and deletion of vehicles (gui-version)
Locate person - button.
Definition: GUIAppEnum.h:169
GUIGlObjectType
Storage for geometrical objects extended by mutexes.
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:43
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:186
Locate TLS - button.
Definition: GUIAppEnum.h:171
~GUISUMOViewParent()
Destructor.
FXDEFMAP(GUISUMOViewParent) GUISUMOViewParentMap[]
static FXbool userPermitsOverwritingWhenFileExists(FXWindow *const parent, const FXString &file)
Returns true if either the file given by its name does not exist or the user allows overwriting it...
Definition: MFXUtils.cpp:52
Locate poi - button.
Definition: GUIAppEnum.h:175
void setToolBarVisibility(const bool value)
about toggled gaming status
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:162
long onCmdLocate(FXObject *, FXSelector, void *)
locator-callback
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
long onSimStep(FXObject *sender, FXSelector, void *)
Called on a simulation step.
virtual long onKeyRelease(FXObject *o, FXSelector sel, void *data)
FXString gCurrentFolder
The folder used as last.
FXPopup * myLocatorPopup
The locator menu.
virtual void buildViewToolBars(GUIGlChildWindow &)
builds the view toolbars
bool isGaming() const
return whether the gui is in gaming mode
Definition: GUIMainWindow.h:84
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:123
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:70
long onKeyRelease(FXObject *o, FXSelector sel, void *data)
Locate addtional structure - button.
Definition: GUIAppEnum.h:173
A road/street connecting two junctions (gui-version)
Definition: GUIEdge.h:62
GUIMainWindow * myParent
The parent window.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:167
long onKeyPress(FXObject *o, FXSelector sel, void *data)
handle keys
virtual long onKeyPress(FXObject *o, FXSelector sel, void *data)
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:419
Locate edge - button.
Definition: GUIAppEnum.h:165
A Simulation step was performed.
Definition: GUIAppEnum.h:277
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:308
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
ViewType
Available view types.
FXGLVisual * getGLVisual() const
bool listInternal() const
return whether to list internal structures
Definition: GUIMainWindow.h:89
Locate junction - button.
Definition: GUIAppEnum.h:163
void removeChild(FXMDIChild *child)
removes the given child window from the list
void checkSnapshots()
Checks whether it is time for a snapshot.
FXToolBar * myNavigationToolBar
The tool bar.
std::string makeSnapshot(const std::string &destFile)
Takes a snapshots and writes it into the given file.
A single child window which contains a view of the simulation area.
static std::vector< GUIGlID > getIDs(bool includeInternal)
Definition: GUIEdge.cpp:102
long onCmdMakeSnapshot(FXObject *sender, FXSelector, void *)
Called if the user wants to make a snapshot (screenshot)
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:91
virtual MSPersonControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:696
FXMenuButton * myLocatorButton
Locate polygons - button.
Definition: GUIAppEnum.h:177
an edge
GUISUMOAbstractView * myView
the view
static const bool gUseMesoSim
Definition: MSGlobals.h:102
GUI-version of the person control for building gui persons.
virtual GUISUMOAbstractView * init(FXGLCanvas *share, GUINet &net, ViewType type)
"Initialises" this window by building the contents
GUISelectedStorage gSelected
A global holder of selected objects.
static FXIcon * getIcon(GUIIcon which)
FXVerticalFrame * myContentFrame