Eclipse SUMO - Simulation of Urban MObility
GUISUMOViewParent.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // A single child window which contains a view of the simulation area
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include <vector>
30 #include <fxkeys.h>
32 #include <utils/geom/Position.h>
33 #include <utils/geom/Boundary.h>
46 #include <guisim/GUIVehicle.h>
47 #include <guisim/GUIPerson.h>
48 #include <guisim/GUIEdge.h>
49 #include <guisim/GUILane.h>
50 #include <guisim/GUINet.h>
53 #include <microsim/MSJunction.h>
54 #include <microsim/MSGlobals.h>
55 #include "GUIGlobals.h"
56 #include "GUIViewTraffic.h"
57 #include "GUIApplicationWindow.h"
58 #include "GUISUMOViewParent.h"
59 
61 
62 #ifdef HAVE_OSG
63 #include <osgview/GUIOSGView.h>
64 #endif
65 
66 
67 // ===========================================================================
68 // FOX callback mapping
69 // ===========================================================================
70 FXDEFMAP(GUISUMOViewParent) GUISUMOViewParentMap[] = {
72  // FXMAPFUNC(SEL_COMMAND, MID_ALLOWROTATION, GUISUMOViewParent::onCmdAllowRotation),
73  FXMAPFUNC(SEL_COMMAND, MID_LOCATEJUNCTION, GUISUMOViewParent::onCmdLocate),
74  FXMAPFUNC(SEL_COMMAND, MID_LOCATEEDGE, GUISUMOViewParent::onCmdLocate),
75  FXMAPFUNC(SEL_COMMAND, MID_LOCATEVEHICLE, GUISUMOViewParent::onCmdLocate),
76  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPERSON, GUISUMOViewParent::onCmdLocate),
77  FXMAPFUNC(SEL_COMMAND, MID_LOCATETLS, GUISUMOViewParent::onCmdLocate),
78  FXMAPFUNC(SEL_COMMAND, MID_LOCATEADD, GUISUMOViewParent::onCmdLocate),
79  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOI, GUISUMOViewParent::onCmdLocate),
80  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOLY, GUISUMOViewParent::onCmdLocate),
81  FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUISUMOViewParent::onSimStep),
82 
83 };
84 
85 // Object implementation
86 FXIMPLEMENT(GUISUMOViewParent, GUIGlChildWindow, GUISUMOViewParentMap, ARRAYNUMBER(GUISUMOViewParentMap))
87 
88 
89 // ===========================================================================
90 // member method definitions
91 // ===========================================================================
92 GUISUMOViewParent::GUISUMOViewParent(FXMDIClient* p, FXMDIMenu* mdimenu,
93  const FXString& name,
94  GUIMainWindow* parentWindow,
95  FXIcon* ic, FXuint opts,
96  FXint x, FXint y, FXint w, FXint h) :
97  GUIGlChildWindow(p, parentWindow, mdimenu, name, nullptr, ic, opts, x, y, w, h) {
98  myParent->addGLChild(this);
99 }
100 
101 
104  switch (type) {
105  default:
106  case VIEW_2D_OPENGL:
107  myView = new GUIViewTraffic(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
108  break;
109 #ifdef HAVE_OSG
110  case VIEW_3D_OSG:
111  myView = new GUIOSGView(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
112  break;
113 #endif
114  }
115  myView->buildViewToolBars(*this);
116  if (myParent->isGaming()) {
118  }
119  return myView;
120 }
121 
122 
124  myParent->removeGLChild(this);
125 }
126 
127 
128 void
130  if (value) {
132  } else {
134  }
135 }
136 
137 
138 long
139 GUISUMOViewParent::onCmdMakeSnapshot(FXObject* sender, FXSelector, void*) {
140  MFXCheckableButton* button = dynamic_cast<MFXCheckableButton*>(sender);
141  // check if cast was sucesfully
142  if (button) {
143  if (button->amChecked()) {
144  myView->endSnapshot();
145  button->setChecked(false);
146  return 1;
147  }
148  // get the new file name
149  FXFileDialog opendialog(this, "Save Snapshot");
150  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
151  opendialog.setSelectMode(SELECTFILE_ANY);
152 #ifdef HAVE_FFMPEG
153  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"
154  "All Video Files (*.h264,*.hevc)\n"
155 #else
156  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"
157 #endif
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 == "video") {
174  button->setChecked(!button->amChecked());
175  } else if (error != "") {
176  FXMessageBox::error(this, MBOX_OK, "Saving failed.", "%s", error.c_str());
177  }
178  }
179  return 1;
180 }
181 
182 
183 long
184 GUISUMOViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
185  std::vector<GUIGlID> ids;
186  GUIIcon icon;
187  std::string title;
188  switch (FXSELID(sel)) {
189  case MID_LOCATEJUNCTION:
190  ids = static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs(myParent->listInternal());
191  icon = ICON_LOCATEJUNCTION;
192  title = "Junction Chooser";
193  break;
194  case MID_LOCATEEDGE:
196  icon = ICON_LOCATEEDGE;
197  title = "Edge Chooser";
198  break;
199  case MID_LOCATEVEHICLE:
201  static_cast<GUIMEVehicleControl*>(static_cast<GUINet*>(MSNet::getInstance())->getGUIMEVehicleControl())->insertVehicleIDs(ids);
202  } else {
203  static_cast<GUIVehicleControl&>(MSNet::getInstance()->getVehicleControl()).insertVehicleIDs(
205  }
206  icon = ICON_LOCATEVEHICLE;
207  title = "Vehicle Chooser";
208  break;
209  case MID_LOCATEPERSON:
210  static_cast<GUITransportableControl&>(MSNet::getInstance()->getPersonControl()).insertPersonIDs(ids);
211  icon = ICON_LOCATEPERSON;
212  title = "Person Chooser";
213  break;
214  case MID_LOCATETLS:
215  ids = static_cast<GUINet*>(GUINet::getInstance())->getTLSIDs();
216  icon = ICON_LOCATETLS;
217  title = "Traffic Lights Chooser";
218  break;
219  case MID_LOCATEADD:
221  icon = ICON_LOCATEADD;
222  title = "Additional Objects Chooser";
223  break;
224  case MID_LOCATEPOI:
225  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPOIIds();
226  icon = ICON_LOCATEPOI;
227  title = "POI Chooser";
228  break;
229  case MID_LOCATEPOLY:
230  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPolygonIDs();
231  icon = ICON_LOCATEPOLY;
232  title = "Polygon Chooser";
233  break;
234  default:
235  throw ProcessError("Unknown Message ID in onCmdLocate");
236  }
237  myLocatorPopup->popdown();
238  myLocatorButton->killFocus();
239  myLocatorPopup->update();
241  return 1;
242 }
243 
244 
245 long
246 GUISUMOViewParent::onSimStep(FXObject*, FXSelector, void*) {
247  myView->update();
249  return 1;
250 }
251 
252 
253 bool
255  GUIGlObjectType type = o->getType();
256  if (gSelected.isSelected(type, o->getGlID())) {
257  return true;
258  } else if (type == GLO_EDGE) {
259  GUIEdge* edge = dynamic_cast<GUIEdge*>(o);
260  if (edge == nullptr) {
261  // hmph, just some security stuff
262  return false;
263  }
264  const std::vector<MSLane*>& lanes = edge->getLanes();
265  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
266  GUILane* l = dynamic_cast<GUILane*>(*j);
267  if (l != nullptr && gSelected.isSelected(GLO_LANE, l->getGlID())) {
268  return true;
269  }
270  }
271  return false;
272  } else {
273  return false;
274  }
275 }
276 
277 
278 long
279 GUISUMOViewParent::onKeyPress(FXObject* o, FXSelector sel, void* data) {
280  myView->onKeyPress(o, sel, data);
281  return 0;
282 }
283 
284 
285 long
286 GUISUMOViewParent::onKeyRelease(FXObject* o, FXSelector sel, void* data) {
287  myView->onKeyRelease(o, sel, data);
288  return 0;
289 }
290 
291 
292 /****************************************************************************/
GUIGlObject::getType
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.cpp:181
MID_LOCATEPOI
Locate poi - button.
Definition: GUIAppEnum.h:323
GUIGlObject_AbstractAdd::getIDList
static std::vector< GUIGlID > getIDList(GUIGlObjectType typeFilter)
Returns the list of gl-ids of all additional objects that match the given type.
Definition: GUIGlObject_AbstractAdd.cpp:90
GUIViewTraffic.h
GUISUMOViewParent::setToolBarVisibility
void setToolBarVisibility(const bool value)
@notify about toggled gaming status
Definition: GUISUMOViewParent.cpp:129
Boundary.h
MID_LOCATETLS
Locate TLS - button.
Definition: GUIAppEnum.h:319
GUITransportableControl.h
GUIMainWindow::listParking
bool listParking() const
return whether to list parking vehicles
Definition: GUIMainWindow.h:93
MFXImageHelper.h
GUIMainWindow::listTeleporting
bool listTeleporting() const
return whether to list teleporting vehicles
Definition: GUIMainWindow.h:98
GUIGlObjectTypes.h
MFXCheckableButton::amChecked
bool amChecked() const
check if this MFXCheckableButton is checked
Definition: MFXCheckableButton.cpp:52
MID_LOCATEEDGE
Locate edge - button.
Definition: GUIAppEnum.h:309
GUIVehicle.h
GUISUMOAbstractView
Definition: GUISUMOAbstractView.h:73
GUISUMOViewParent
A single child window which contains a view of the simulation area.
Definition: GUISUMOViewParent.h:59
GUIViewTraffic
Definition: GUIViewTraffic.h:55
MFXCheckableButton::setChecked
void setChecked(bool val)
check or uncheck this MFXCheckableButton
Definition: MFXCheckableButton.cpp:58
GUIVehicleControl.h
GUIGlChildWindow::myView
GUISUMOAbstractView * myView
The view.
Definition: GUIGlChildWindow.h:107
GUIMEVehicleControl.h
GUIPerson.h
GUISUMOAbstractView::buildViewToolBars
virtual void buildViewToolBars(GUIGlChildWindow &)
builds the view toolbars
Definition: GUISUMOAbstractView.h:84
ICON_EMPTY
Definition: GUIIcons.h:42
GUIGlobalSelection.h
ICON_LOCATEEDGE
Definition: GUIIcons.h:77
MSGlobals::gUseMesoSim
static bool gUseMesoSim
Definition: MSGlobals.h:91
GUISUMOAbstractView::checkSnapshots
virtual void checkSnapshots()
Checks whether it is time for a snapshot.
Definition: GUISUMOAbstractView.cpp:1235
MID_LOCATEPERSON
Locate person - button.
Definition: GUIAppEnum.h:317
GUIGlChildWindow::myLocatorPopup
FXPopup * myLocatorPopup
The locator menu.
Definition: GUIGlChildWindow.h:110
ICON_LOCATETLS
Definition: GUIIcons.h:82
GUINet.h
GUIIconSubSys::getIcon
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Definition: GUIIconSubSys.cpp:602
GUISUMOViewParent::onSimStep
long onSimStep(FXObject *sender, FXSelector, void *)
Called on a simulation step.
Definition: GUISUMOViewParent.cpp:246
GUIGlObjectStorage.h
GUIAppEnum.h
GUISUMOViewParent::VIEW_3D_OSG
plain 3D OSG view (
Definition: GUISUMOViewParent.h:69
ICON_LOCATEADD
Definition: GUIIcons.h:83
GUIGlObjectType
GUIGlObjectType
Definition: GUIGlObjectTypes.h:40
GUIMainWindow::isGaming
bool isGaming() const
return whether the gui is in gaming mode
Definition: GUIMainWindow.h:83
ICON_LOCATEJUNCTION
Definition: GUIIcons.h:76
MSJunction.h
GUILane.h
GUIShapeContainer.h
GUIGlobals.h
GUISUMOViewParent::onKeyPress
long onKeyPress(FXObject *o, FXSelector sel, void *data)
handle keys
Definition: GUISUMOViewParent.cpp:279
FXDEFMAP
FXDEFMAP(GUISUMOViewParent) GUISUMOViewParentMap[]
ICON_LOCATEPOI
Definition: GUIIcons.h:84
MID_SIMSTEP
A Simulation step was performed.
Definition: GUIAppEnum.h:441
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:150
GUISUMOViewParent::ViewType
ViewType
Available view types.
Definition: GUISUMOViewParent.h:65
GUIGlChildWindow::myLocatorButton
FXMenuButton * myLocatorButton
The locator button.
Definition: GUIGlChildWindow.h:113
ProcessError
Definition: UtilExceptions.h:40
ICON_LOCATEPOLY
Definition: GUIIcons.h:85
GUIApplicationWindow.h
GUISUMOViewParent.h
GLO_EDGE
an edge
Definition: GUIGlObjectTypes.h:47
GUIIcons.h
MSGlobals.h
UtilExceptions.h
GUIIOGlobals.h
GLO_LANE
a lane
Definition: GUIGlObjectTypes.h:49
GUIMainWindow::getGLVisual
FXGLVisual * getGLVisual() const
Definition: GUIMainWindow.cpp:165
GUIGlObject
Definition: GUIGlObject.h:66
GUISUMOAbstractView::endSnapshot
virtual void endSnapshot()
Ends a video snapshot.
Definition: GUISUMOAbstractView.h:190
GUIIcon
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:36
gCurrentFolder
FXString gCurrentFolder
The folder used as last.
Definition: GUIIOGlobals.cpp:33
GUISUMOAbstractView::onKeyRelease
virtual long onKeyRelease(FXObject *o, FXSelector sel, void *data)
Definition: GUISUMOAbstractView.cpp:1047
ICON_LOCATEPERSON
Definition: GUIIcons.h:81
GUIIconSubSys.h
ICON_LOCATEVEHICLE
Definition: GUIIcons.h:78
GUISUMOViewParent::onCmdMakeSnapshot
long onCmdMakeSnapshot(FXObject *sender, FXSelector, void *)
Called if the user wants to make a snapshot (screenshot)
Definition: GUISUMOViewParent.cpp:139
Position.h
GUILane
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:62
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
GUIMainWindow
Definition: GUIMainWindow.h:47
GUIEdge
A road/street connecting two junctions (gui-version)
Definition: GUIEdge.h:53
GUISUMOViewParent::onCmdLocate
long onCmdLocate(FXObject *, FXSelector, void *)
locator-callback
Definition: GUISUMOViewParent.cpp:184
MID_LOCATEJUNCTION
Locate junction - button.
Definition: GUIAppEnum.h:307
GUISUMOViewParent::isSelected
bool isSelected(GUIGlObject *o) const
true if the object is selected (may include extra logic besides calling gSelected)
Definition: GUISUMOViewParent.cpp:254
MFXCheckableButton
Definition: MFXCheckableButton.h:31
GUISUMOViewParent::onKeyRelease
long onKeyRelease(FXObject *o, FXSelector sel, void *data)
Definition: GUISUMOViewParent.cpp:286
MFXUtils.h
GUIEdge.h
GUIOSGView.h
GUIGlChildWindow::myStaticNavigationToolBar
FXToolBar * myStaticNavigationToolBar
The static navigation tool bar.
Definition: GUIGlChildWindow.h:104
GUIGlObjectStorage::gIDStorage
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
Definition: GUIGlObjectStorage.h:141
GUIMainWindow::removeGLChild
void removeGLChild(GUIGlChildWindow *child)
removes the given child window from the list
Definition: GUIMainWindow.cpp:99
gSelected
GUISelectedStorage gSelected
A global holder of selected objects.
Definition: GUIGlobalSelection.cpp:34
GUIGlChildWindow::myParent
GUIMainWindow * myParent
The parent window.
Definition: GUIGlChildWindow.h:98
MSEdge::getLanes
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:165
MID_LOCATEVEHICLE
Locate vehicle - button.
Definition: GUIAppEnum.h:311
GUISUMOAbstractView::onKeyPress
virtual long onKeyPress(FXObject *o, FXSelector sel, void *data)
keyboard functions
Definition: GUISUMOAbstractView.cpp:1036
GUIDialog_GLObjChooser.h
config.h
GUIEdge::getIDs
static std::vector< GUIGlID > getIDs(bool includeInternal)
Definition: GUIEdge.cpp:90
GLO_ADDITIONAL
reserved GLO type to pack all additionals
Definition: GUIGlObjectTypes.h:60
GUISUMOAbstractView::makeSnapshot
std::string makeSnapshot(const std::string &destFile, const int width=-1, const int height=-1)
Takes a snapshots and writes it into the given file.
Definition: GUISUMOAbstractView.cpp:1069
GUIGlChildWindow
Definition: GUIGlChildWindow.h:41
MID_LOCATEPOLY
Locate polygons - button.
Definition: GUIAppEnum.h:325
GUINet
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:83
GUIGlChildWindow::myContentFrame
FXVerticalFrame * myContentFrame
The contents frame.
Definition: GUIGlChildWindow.h:116
GUIMainWindow::listInternal
bool listInternal() const
return whether to list internal structures
Definition: GUIMainWindow.h:88
MID_LOCATEADD
Locate addtional structure - button.
Definition: GUIAppEnum.h:321
MFXUtils::userPermitsOverwritingWhenFileExists
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:41
GUISUMOViewParent::VIEW_2D_OPENGL
plain 2D openGL view (
Definition: GUISUMOViewParent.h:67
MID_MAKESNAPSHOT
Make snapshot - button.
Definition: GUIAppEnum.h:333
GUISUMOViewParent::init
virtual GUISUMOAbstractView * init(FXGLCanvas *share, GUINet &net, ViewType type)
"Initialises" this window by building the contents
Definition: GUISUMOViewParent.cpp:103
GUIDialog_GLObjChooser
Definition: GUIDialog_GLObjChooser.h:52
GUISUMOViewParent::~GUISUMOViewParent
~GUISUMOViewParent()
Destructor.
Definition: GUISUMOViewParent.cpp:123
MFXCheckableButton.h
GUISelectedStorage::isSelected
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
Definition: GUISelectedStorage.cpp:95