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-2016 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 
68 
69 #ifdef HAVE_OSG
70 #include <osgview/GUIOSGView.h>
71 #endif
72 
73 #ifdef CHECK_MEMORY_LEAKS
74 #include <foreign/nvwa/debug_new.h>
75 #endif // CHECK_MEMORY_LEAKS
76 
77 
78 // ===========================================================================
79 // FOX callback mapping
80 // ===========================================================================
81 FXDEFMAP(GUISUMOViewParent) GUISUMOViewParentMap[] = {
83  // FXMAPFUNC(SEL_COMMAND, MID_ALLOWROTATION, GUISUMOViewParent::onCmdAllowRotation),
84  FXMAPFUNC(SEL_COMMAND, MID_LOCATEJUNCTION, GUISUMOViewParent::onCmdLocate),
85  FXMAPFUNC(SEL_COMMAND, MID_LOCATEEDGE, GUISUMOViewParent::onCmdLocate),
86  FXMAPFUNC(SEL_COMMAND, MID_LOCATEVEHICLE, GUISUMOViewParent::onCmdLocate),
87  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPERSON, GUISUMOViewParent::onCmdLocate),
88  FXMAPFUNC(SEL_COMMAND, MID_LOCATETLS, GUISUMOViewParent::onCmdLocate),
89  FXMAPFUNC(SEL_COMMAND, MID_LOCATEADD, GUISUMOViewParent::onCmdLocate),
90  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOI, GUISUMOViewParent::onCmdLocate),
91  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOLY, GUISUMOViewParent::onCmdLocate),
92  FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUISUMOViewParent::onSimStep),
93 
94 };
95 
96 // Object implementation
97 FXIMPLEMENT(GUISUMOViewParent, GUIGlChildWindow, GUISUMOViewParentMap, ARRAYNUMBER(GUISUMOViewParentMap))
98 
99 
100 // ===========================================================================
101 // member method definitions
102 // ===========================================================================
103 GUISUMOViewParent::GUISUMOViewParent(FXMDIClient* p, FXMDIMenu* mdimenu,
104  const FXString& name,
105  GUIMainWindow* parentWindow,
106  FXIcon* ic, FXuint opts,
107  FXint x, FXint y, FXint w, FXint h)
108  : GUIGlChildWindow(p, parentWindow, mdimenu, name, ic, opts, x, y, w, h) {
109  myParent->addChild(this, false);
110 }
111 
112 
115  switch (type) {
116  default:
117  case VIEW_2D_OPENGL:
118  myView = new GUIViewTraffic(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
119  break;
120 #ifdef HAVE_OSG
121  case VIEW_3D_OSG:
122  myView = new GUIOSGView(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
123  break;
124 #endif
125  }
126  myView->buildViewToolBars(*this);
127  if (myParent->isGaming()) {
128  myNavigationToolBar->hide();
129  }
130  return myView;
131 }
132 
133 
135  myParent->removeChild(this);
136 }
137 
138 
139 void
141  if (value) {
142  myNavigationToolBar->show();
143  } else {
144  myNavigationToolBar->hide();
145  }
146 }
147 
148 
149 long
150 GUISUMOViewParent::onCmdMakeSnapshot(FXObject* sender, FXSelector, void*) {
151  MFXCheckableButton* button = static_cast<MFXCheckableButton*>(sender);
152  if (button->amChecked()) {
153  myView->endSnapshot();
154  button->setChecked(false);
155  return 1;
156  }
157  // get the new file name
158  FXFileDialog opendialog(this, "Save Snapshot");
159  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
160  opendialog.setSelectMode(SELECTFILE_ANY);
161 #ifdef HAVE_FFMPEG
162  opendialog.setPatternList("All Image and Video Files (*.gif,*.bmp,*.xpm,*.pcx,*.ico,*.rgb,*.xbm,*.tga,*.png,*.jpg,*.jpeg,*.tif,*.tiff,*.ps,*.eps,*.pdf,*.svg,*.tex,*.pgf,*.h264,*.hevc)\n"
163  "All Video Files (*.h264,*.hevc)\n"
164 #else
165  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"
166 #endif
167  "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
168  "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
169  "JPEG Image (*.jpg,*.jpeg)\nTIFF Image (*.tif,*.tiff)\n"
170  "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n"
171  "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n"
172  "All Files (*)");
173  if (gCurrentFolder.length() != 0) {
174  opendialog.setDirectory(gCurrentFolder);
175  }
176  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
177  return 1;
178  }
179  gCurrentFolder = opendialog.getDirectory();
180  std::string file = opendialog.getFilename().text();
181  std::string error = myView->makeSnapshot(file);
182  if (error == "video") {
183  button->setChecked(!button->amChecked());
184  } else if (error != "") {
185  FXMessageBox::error(this, MBOX_OK, "Saving failed.", "%s", error.c_str());
186  }
187  return 1;
188 }
189 
190 
191 long
192 GUISUMOViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
193  std::vector<GUIGlID> ids;
194  GUIIcon icon;
195  std::string title;
196  switch (FXSELID(sel)) {
197  case MID_LOCATEJUNCTION:
198  ids = static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs(myParent->listInternal());
199  icon = ICON_LOCATEJUNCTION;
200  title = "Junction Chooser";
201  break;
202  case MID_LOCATEEDGE:
204  icon = ICON_LOCATEEDGE;
205  title = "Edge Chooser";
206  break;
207  case MID_LOCATEVEHICLE:
209  static_cast<GUIMEVehicleControl*>(static_cast<GUINet*>(MSNet::getInstance())->getGUIMEVehicleControl())->insertVehicleIDs(ids);
210  } else {
211  static_cast<GUIVehicleControl&>(MSNet::getInstance()->getVehicleControl()).insertVehicleIDs(ids);
212  }
213  icon = ICON_LOCATEVEHICLE;
214  title = "Vehicle Chooser";
215  break;
216  case MID_LOCATEPERSON:
217  static_cast<GUIPersonControl&>(MSNet::getInstance()->getPersonControl()).insertPersonIDs(ids);
218  icon = ICON_LOCATEPERSON;
219  title = "Person Chooser";
220  break;
221  case MID_LOCATETLS:
222  ids = static_cast<GUINet*>(GUINet::getInstance())->getTLSIDs();
223  icon = ICON_LOCATETLS;
224  title = "Traffic Lights Chooser";
225  break;
226  case MID_LOCATEADD:
228  icon = ICON_LOCATEADD;
229  title = "Additional Objects Chooser";
230  break;
231  case MID_LOCATEPOI:
232  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPOIIds();
233  icon = ICON_LOCATEPOI;
234  title = "POI Chooser";
235  break;
236  case MID_LOCATEPOLY:
237  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPolygonIDs();
238  icon = ICON_LOCATEPOLY;
239  title = "Polygon Chooser";
240  break;
241  default:
242  throw ProcessError("Unknown Message ID in onCmdLocate");
243  }
244  myLocatorPopup->popdown();
245  myLocatorButton->killFocus();
246  myLocatorPopup->update();
248  this, GUIIconSubSys::getIcon(icon), title.c_str(), ids, GUIGlObjectStorage::gIDStorage);
249  chooser->create();
250  chooser->show();
251  return 1;
252 }
253 
254 
255 long
256 GUISUMOViewParent::onSimStep(FXObject*, FXSelector, void*) {
257  myView->update();
259  return 1;
260 }
261 
262 
263 bool
265  GUIGlObjectType type = o->getType();
266  if (gSelected.isSelected(type, o->getGlID())) {
267  return true;
268  } else if (type == GLO_EDGE) {
269  GUIEdge* edge = dynamic_cast<GUIEdge*>(o);
270  if (edge == 0) {
271  // hmph, just some security stuff
272  return false;
273  }
274  const std::vector<MSLane*>& lanes = edge->getLanes();
275  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
276  GUILane* l = dynamic_cast<GUILane*>(*j);
277  if (l != 0 && gSelected.isSelected(GLO_LANE, l->getGlID())) {
278  return true;
279  }
280  }
281  return false;
282  } else {
283  return false;
284  }
285 }
286 
287 
288 long
289 GUISUMOViewParent::onKeyPress(FXObject* o, FXSelector sel, void* data) {
290  myView->onKeyPress(o, sel, data);
291  return 0;
292 }
293 
294 
295 long
296 GUISUMOViewParent::onKeyRelease(FXObject* o, FXSelector sel, void* data) {
297  myView->onKeyRelease(o, sel, data);
298  return 0;
299 }
300 
301 
302 /****************************************************************************/
303 
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:185
Locate TLS - button.
Definition: GUIAppEnum.h:171
void setChecked(bool val)
~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
The class responsible for building and deletion of vehicles (gui-version)
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:160
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
virtual void endSnapshot()
Ends a video snapshot.
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:60
GUIMainWindow * myParent
The parent window.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:180
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:279
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
virtual 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:100
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:89
virtual MSPersonControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:690
FXMenuButton * myLocatorButton
Locate polygons - button.
Definition: GUIAppEnum.h:177
an edge
GUISUMOAbstractView * myView
the view
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 bool gUseMesoSim
Definition: MSGlobals.h:87
static FXIcon * getIcon(GUIIcon which)
FXVerticalFrame * myContentFrame