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 /****************************************************************************/
Locate junction - button.
Definition: GUIAppEnum.h:307
bool amChecked() const
check if this MFXCheckableButton is checked
FXGLVisual * getGLVisual() const
The class responsible for building and deletion of vehicles (gui-version)
GUIGlObjectType
Storage for geometrical objects extended by mutexes.
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:36
Locate addtional structure - button.
Definition: GUIAppEnum.h:321
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:41
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:165
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
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.
bool listTeleporting() const
return whether to list teleporting vehicles
Definition: GUIMainWindow.h:98
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
virtual void endSnapshot()
Ends a video snapshot.
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:62
long onKeyRelease(FXObject *o, FXSelector sel, void *data)
A road/street connecting two junctions (gui-version)
Definition: GUIEdge.h:53
GUIMainWindow * myParent
The parent window.
long onKeyPress(FXObject *o, FXSelector sel, void *data)
handle keys
Locate polygons - button.
Definition: GUIAppEnum.h:325
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:798
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:460
Locate person - button.
Definition: GUIAppEnum.h:317
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.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:337
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.
Locate vehicle - button.
Definition: GUIAppEnum.h:311
bool isGaming() const
return whether the gui is in gaming mode
Definition: GUIMainWindow.h:83
Locate edge - button.
Definition: GUIAppEnum.h:309
virtual void checkSnapshots()
Checks whether it is time for a snapshot.
Make snapshot - button.
Definition: GUIAppEnum.h:333
bool listInternal() const
return whether to list internal structures
Definition: GUIMainWindow.h:88
A single child window which contains a view of the simulation area.
reserved GLO type to pack all additionals
static std::vector< GUIGlID > getIDs(bool includeInternal)
Definition: GUIEdge.cpp:90
bool listParking() const
return whether to list parking vehicles
Definition: GUIMainWindow.h:93
Locate TLS - button.
Definition: GUIAppEnum.h:319
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:83
FXToolBar * myStaticNavigationToolBar
The static navigation tool bar.
FXMenuButton * myLocatorButton
The locator button.
A Simulation step was performed.
Definition: GUIAppEnum.h:441
an edge
GUISUMOAbstractView * myView
The view.
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 poi - button.
Definition: GUIAppEnum.h:323
GUISelectedStorage gSelected
A global holder of selected objects.
static bool gUseMesoSim
Definition: MSGlobals.h:91
static std::vector< GUIGlID > getIDList(GUIGlObjectType typeFilter)
Returns the list of gl-ids of all additional objects that match the given type.
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
FXVerticalFrame * myContentFrame
The contents frame.
void removeGLChild(GUIGlChildWindow *child)
removes the given child window from the list
GUI-version of the transportable control for building gui persons and containers. ...