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-2017 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 
74 // ===========================================================================
75 // FOX callback mapping
76 // ===========================================================================
77 FXDEFMAP(GUISUMOViewParent) GUISUMOViewParentMap[] = {
79  // FXMAPFUNC(SEL_COMMAND, MID_ALLOWROTATION, GUISUMOViewParent::onCmdAllowRotation),
80  FXMAPFUNC(SEL_COMMAND, MID_LOCATEJUNCTION, GUISUMOViewParent::onCmdLocate),
81  FXMAPFUNC(SEL_COMMAND, MID_LOCATEEDGE, GUISUMOViewParent::onCmdLocate),
82  FXMAPFUNC(SEL_COMMAND, MID_LOCATEVEHICLE, GUISUMOViewParent::onCmdLocate),
83  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPERSON, GUISUMOViewParent::onCmdLocate),
84  FXMAPFUNC(SEL_COMMAND, MID_LOCATETLS, GUISUMOViewParent::onCmdLocate),
85  FXMAPFUNC(SEL_COMMAND, MID_LOCATEADD, GUISUMOViewParent::onCmdLocate),
86  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOI, GUISUMOViewParent::onCmdLocate),
87  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOLY, GUISUMOViewParent::onCmdLocate),
88  FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUISUMOViewParent::onSimStep),
89 
90 };
91 
92 // Object implementation
93 FXIMPLEMENT(GUISUMOViewParent, GUIGlChildWindow, GUISUMOViewParentMap, ARRAYNUMBER(GUISUMOViewParentMap))
94 
95 
96 // ===========================================================================
97 // member method definitions
98 // ===========================================================================
99 GUISUMOViewParent::GUISUMOViewParent(FXMDIClient* p, FXMDIMenu* mdimenu,
100  const FXString& name,
101  GUIMainWindow* parentWindow,
102  FXIcon* ic, FXuint opts,
103  FXint x, FXint y, FXint w, FXint h)
104  : GUIGlChildWindow(p, parentWindow, mdimenu, name, ic, opts, x, y, w, h) {
105  myParent->addChild(this, false);
106 }
107 
108 
111  switch (type) {
112  default:
113  case VIEW_2D_OPENGL:
114  myView = new GUIViewTraffic(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
115  break;
116 #ifdef HAVE_OSG
117  case VIEW_3D_OSG:
118  myView = new GUIOSGView(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
119  break;
120 #endif
121  }
122  myView->buildViewToolBars(*this);
123  if (myParent->isGaming()) {
124  myNavigationToolBar->hide();
125  }
126  return myView;
127 }
128 
129 
131  myParent->removeChild(this);
132 }
133 
134 
135 void
137  if (value) {
138  myNavigationToolBar->show();
139  } else {
140  myNavigationToolBar->hide();
141  }
142 }
143 
144 
145 long
146 GUISUMOViewParent::onCmdMakeSnapshot(FXObject* sender, FXSelector, void*) {
147  MFXCheckableButton* button = static_cast<MFXCheckableButton*>(sender);
148  if (button->amChecked()) {
149  myView->endSnapshot();
150  button->setChecked(false);
151  return 1;
152  }
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 #ifdef HAVE_FFMPEG
158  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"
159  "All Video Files (*.h264,*.hevc)\n"
160 #else
161  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"
162 #endif
163  "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
164  "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
165  "JPEG Image (*.jpg,*.jpeg)\nTIFF Image (*.tif,*.tiff)\n"
166  "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n"
167  "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n"
168  "All Files (*)");
169  if (gCurrentFolder.length() != 0) {
170  opendialog.setDirectory(gCurrentFolder);
171  }
172  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
173  return 1;
174  }
175  gCurrentFolder = opendialog.getDirectory();
176  std::string file = opendialog.getFilename().text();
177  std::string error = myView->makeSnapshot(file);
178  if (error == "video") {
179  button->setChecked(!button->amChecked());
180  } else if (error != "") {
181  FXMessageBox::error(this, MBOX_OK, "Saving failed.", "%s", error.c_str());
182  }
183  return 1;
184 }
185 
186 
187 long
188 GUISUMOViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
189  std::vector<GUIGlID> ids;
190  GUIIcon icon;
191  std::string title;
192  switch (FXSELID(sel)) {
193  case MID_LOCATEJUNCTION:
194  ids = static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs(myParent->listInternal());
195  icon = ICON_LOCATEJUNCTION;
196  title = "Junction Chooser";
197  break;
198  case MID_LOCATEEDGE:
200  icon = ICON_LOCATEEDGE;
201  title = "Edge Chooser";
202  break;
203  case MID_LOCATEVEHICLE:
205  static_cast<GUIMEVehicleControl*>(static_cast<GUINet*>(MSNet::getInstance())->getGUIMEVehicleControl())->insertVehicleIDs(ids);
206  } else {
207  static_cast<GUIVehicleControl&>(MSNet::getInstance()->getVehicleControl()).insertVehicleIDs(
209  }
210  icon = ICON_LOCATEVEHICLE;
211  title = "Vehicle Chooser";
212  break;
213  case MID_LOCATEPERSON:
214  static_cast<GUITransportableControl&>(MSNet::getInstance()->getPersonControl()).insertPersonIDs(ids);
215  icon = ICON_LOCATEPERSON;
216  title = "Person Chooser";
217  break;
218  case MID_LOCATETLS:
219  ids = static_cast<GUINet*>(GUINet::getInstance())->getTLSIDs();
220  icon = ICON_LOCATETLS;
221  title = "Traffic Lights Chooser";
222  break;
223  case MID_LOCATEADD:
225  icon = ICON_LOCATEADD;
226  title = "Additional Objects Chooser";
227  break;
228  case MID_LOCATEPOI:
229  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPOIIds();
230  icon = ICON_LOCATEPOI;
231  title = "POI Chooser";
232  break;
233  case MID_LOCATEPOLY:
234  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPolygonIDs();
235  icon = ICON_LOCATEPOLY;
236  title = "Polygon Chooser";
237  break;
238  default:
239  throw ProcessError("Unknown Message ID in onCmdLocate");
240  }
241  myLocatorPopup->popdown();
242  myLocatorButton->killFocus();
243  myLocatorPopup->update();
245  this, GUIIconSubSys::getIcon(icon), title.c_str(), ids, GUIGlObjectStorage::gIDStorage);
246  chooser->create();
247  chooser->show();
248  return 1;
249 }
250 
251 
252 long
253 GUISUMOViewParent::onSimStep(FXObject*, FXSelector, void*) {
254  myView->update();
256  return 1;
257 }
258 
259 
260 bool
262  GUIGlObjectType type = o->getType();
263  if (gSelected.isSelected(type, o->getGlID())) {
264  return true;
265  } else if (type == GLO_EDGE) {
266  GUIEdge* edge = dynamic_cast<GUIEdge*>(o);
267  if (edge == 0) {
268  // hmph, just some security stuff
269  return false;
270  }
271  const std::vector<MSLane*>& lanes = edge->getLanes();
272  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
273  GUILane* l = dynamic_cast<GUILane*>(*j);
274  if (l != 0 && gSelected.isSelected(GLO_LANE, l->getGlID())) {
275  return true;
276  }
277  }
278  return false;
279  } else {
280  return false;
281  }
282 }
283 
284 
285 long
286 GUISUMOViewParent::onKeyPress(FXObject* o, FXSelector sel, void* data) {
287  myView->onKeyPress(o, sel, data);
288  return 0;
289 }
290 
291 
292 long
293 GUISUMOViewParent::onKeyRelease(FXObject* o, FXSelector sel, void* data) {
294  myView->onKeyRelease(o, sel, data);
295  return 0;
296 }
297 
298 
299 /****************************************************************************/
300 
Locate TLS - button.
Definition: GUIAppEnum.h:181
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 amChecked() const
check if this MFXCheckableButton is checked
FXGLVisual * getGLVisual() const
The class responsible for building and deletion of vehicles (gui-version)
Locate edge - button.
Definition: GUIAppEnum.h:175
GUIGlObjectType
Storage for geometrical objects extended by mutexes.
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:43
void setChecked(bool val)
check or uncheck this MFXCheckableButton
~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:48
void setToolBarVisibility(const bool value)
about toggled gaming status
The class responsible for building and deletion of vehicles (gui-version)
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:192
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:158
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.
Make snapshot - button.
Definition: GUIAppEnum.h:199
bool listTeleporting() const
return whether to list teleporting vehicles
virtual long onKeyRelease(FXObject *o, FXSelector sel, void *data)
FXString gCurrentFolder
The folder used as last.
FXPopup * myLocatorPopup
The locator menu.
Locate polygons - button.
Definition: GUIAppEnum.h:191
virtual void buildViewToolBars(GUIGlChildWindow &)
builds the view toolbars
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)
A road/street connecting two junctions (gui-version)
Definition: GUIEdge.h:60
GUIMainWindow * myParent
The parent window.
long onKeyPress(FXObject *o, FXSelector sel, void *data)
handle keys
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
virtual long onKeyPress(FXObject *o, FXSelector sel, void *data)
keyboard functions
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:730
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:433
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:310
bool isSelected(GUIGlObject *o) const
true if the object is selected (may include extra logic besides calling gSelected) ...
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
ViewType
Available view types.
bool isGaming() const
return whether the gui is in gaming mode
Definition: GUIMainWindow.h:85
void removeChild(FXMDIChild *child)
removes the given child window from the list
virtual void checkSnapshots()
Checks whether it is time for a snapshot.
Locate poi - button.
Definition: GUIAppEnum.h:189
FXToolBar * myNavigationToolBar
The tool bar.
std::string makeSnapshot(const std::string &destFile)
Takes a snapshots and writes it into the given file.
bool listInternal() const
return whether to list internal structures
Definition: GUIMainWindow.h:90
A single child window which contains a view of the simulation area.
static std::vector< GUIGlID > getIDs(bool includeInternal)
Definition: GUIEdge.cpp:97
bool listParking() const
return whether to list parking vehicles
Definition: GUIMainWindow.h:95
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
FXMenuButton * myLocatorButton
an edge
GUISUMOAbstractView * myView
the view
Locate vehicle - button.
Definition: GUIAppEnum.h:177
Locate addtional structure - button.
Definition: GUIAppEnum.h:187
GUIGlID getGlID() const
Returns the numerical id of the object.
virtual GUISUMOAbstractView * init(FXGLCanvas *share, GUINet &net, ViewType type)
"Initialises" this window by building the contents
Locate junction - button.
Definition: GUIAppEnum.h:173
A Simulation step was performed.
Definition: GUIAppEnum.h:293
Locate person - button.
Definition: GUIAppEnum.h:179
GUISelectedStorage gSelected
A global holder of selected objects.
static bool gUseMesoSim
Definition: MSGlobals.h:98
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
FXVerticalFrame * myContentFrame
GUI-version of the transportable control for building gui persons and containers. ...