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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
21 // A single child window which contains a view of the simulation area
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <vector>
36 #include <fxkeys.h>
38 #include <utils/geom/Position.h>
39 #include <utils/geom/Boundary.h>
52 #include <guisim/GUIVehicle.h>
53 #include <guisim/GUIPerson.h>
54 #include <guisim/GUIEdge.h>
55 #include <guisim/GUILane.h>
56 #include <guisim/GUINet.h>
59 #include <microsim/MSJunction.h>
60 #include <microsim/MSGlobals.h>
61 #include "GUIGlobals.h"
62 #include "GUIViewTraffic.h"
63 #include "GUIApplicationWindow.h"
64 #include "GUISUMOViewParent.h"
65 
67 
68 #ifdef HAVE_OSG
69 #include <osgview/GUIOSGView.h>
70 #endif
71 
72 
73 // ===========================================================================
74 // FOX callback mapping
75 // ===========================================================================
76 FXDEFMAP(GUISUMOViewParent) GUISUMOViewParentMap[] = {
78  // FXMAPFUNC(SEL_COMMAND, MID_ALLOWROTATION, GUISUMOViewParent::onCmdAllowRotation),
79  FXMAPFUNC(SEL_COMMAND, MID_LOCATEJUNCTION, GUISUMOViewParent::onCmdLocate),
80  FXMAPFUNC(SEL_COMMAND, MID_LOCATEEDGE, GUISUMOViewParent::onCmdLocate),
81  FXMAPFUNC(SEL_COMMAND, MID_LOCATEVEHICLE, GUISUMOViewParent::onCmdLocate),
82  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPERSON, GUISUMOViewParent::onCmdLocate),
83  FXMAPFUNC(SEL_COMMAND, MID_LOCATETLS, GUISUMOViewParent::onCmdLocate),
84  FXMAPFUNC(SEL_COMMAND, MID_LOCATEADD, GUISUMOViewParent::onCmdLocate),
85  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOI, GUISUMOViewParent::onCmdLocate),
86  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOLY, GUISUMOViewParent::onCmdLocate),
87  FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUISUMOViewParent::onSimStep),
88 
89 };
90 
91 // Object implementation
92 FXIMPLEMENT(GUISUMOViewParent, GUIGlChildWindow, GUISUMOViewParentMap, ARRAYNUMBER(GUISUMOViewParentMap))
93 
94 
95 // ===========================================================================
96 // member method definitions
97 // ===========================================================================
98 GUISUMOViewParent::GUISUMOViewParent(FXMDIClient* p, FXMDIMenu* mdimenu,
99  const FXString& name,
100  GUIMainWindow* parentWindow,
101  FXIcon* ic, FXuint opts,
102  FXint x, FXint y, FXint w, FXint h)
103  : GUIGlChildWindow(p, parentWindow, mdimenu, name, ic, opts, x, y, w, h) {
104  myParent->addChild(this, false);
105 }
106 
107 
110  switch (type) {
111  default:
112  case VIEW_2D_OPENGL:
113  myView = new GUIViewTraffic(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
114  break;
115 #ifdef HAVE_OSG
116  case VIEW_3D_OSG:
117  myView = new GUIOSGView(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
118  break;
119 #endif
120  }
121  myView->buildViewToolBars(*this);
122  if (myParent->isGaming()) {
123  myNavigationToolBar->hide();
124  }
125  return myView;
126 }
127 
128 
130  myParent->removeChild(this);
131 }
132 
133 
134 void
136  if (value) {
137  myNavigationToolBar->show();
138  } else {
139  myNavigationToolBar->hide();
140  }
141 }
142 
143 
144 long
145 GUISUMOViewParent::onCmdMakeSnapshot(FXObject* sender, FXSelector, void*) {
146  MFXCheckableButton* button = static_cast<MFXCheckableButton*>(sender);
147  if (button->amChecked()) {
148  myView->endSnapshot();
149  button->setChecked(false);
150  return 1;
151  }
152  // get the new file name
153  FXFileDialog opendialog(this, "Save Snapshot");
154  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
155  opendialog.setSelectMode(SELECTFILE_ANY);
156 #ifdef HAVE_FFMPEG
157  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"
158  "All Video Files (*.h264,*.hevc)\n"
159 #else
160  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"
161 #endif
162  "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
163  "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
164  "JPEG Image (*.jpg,*.jpeg)\nTIFF Image (*.tif,*.tiff)\n"
165  "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n"
166  "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n"
167  "All Files (*)");
168  if (gCurrentFolder.length() != 0) {
169  opendialog.setDirectory(gCurrentFolder);
170  }
171  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
172  return 1;
173  }
174  gCurrentFolder = opendialog.getDirectory();
175  std::string file = opendialog.getFilename().text();
176  std::string error = myView->makeSnapshot(file);
177  if (error == "video") {
178  button->setChecked(!button->amChecked());
179  } else if (error != "") {
180  FXMessageBox::error(this, MBOX_OK, "Saving failed.", "%s", error.c_str());
181  }
182  return 1;
183 }
184 
185 
186 long
187 GUISUMOViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
188  std::vector<GUIGlID> ids;
189  GUIIcon icon;
190  std::string title;
191  switch (FXSELID(sel)) {
192  case MID_LOCATEJUNCTION:
193  ids = static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs(myParent->listInternal());
194  icon = ICON_LOCATEJUNCTION;
195  title = "Junction Chooser";
196  break;
197  case MID_LOCATEEDGE:
199  icon = ICON_LOCATEEDGE;
200  title = "Edge Chooser";
201  break;
202  case MID_LOCATEVEHICLE:
204  static_cast<GUIMEVehicleControl*>(static_cast<GUINet*>(MSNet::getInstance())->getGUIMEVehicleControl())->insertVehicleIDs(ids);
205  } else {
206  static_cast<GUIVehicleControl&>(MSNet::getInstance()->getVehicleControl()).insertVehicleIDs(
208  }
209  icon = ICON_LOCATEVEHICLE;
210  title = "Vehicle Chooser";
211  break;
212  case MID_LOCATEPERSON:
213  static_cast<GUITransportableControl&>(MSNet::getInstance()->getPersonControl()).insertPersonIDs(ids);
214  icon = ICON_LOCATEPERSON;
215  title = "Person Chooser";
216  break;
217  case MID_LOCATETLS:
218  ids = static_cast<GUINet*>(GUINet::getInstance())->getTLSIDs();
219  icon = ICON_LOCATETLS;
220  title = "Traffic Lights Chooser";
221  break;
222  case MID_LOCATEADD:
224  icon = ICON_LOCATEADD;
225  title = "Additional Objects Chooser";
226  break;
227  case MID_LOCATEPOI:
228  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPOIIds();
229  icon = ICON_LOCATEPOI;
230  title = "POI Chooser";
231  break;
232  case MID_LOCATEPOLY:
233  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPolygonIDs();
234  icon = ICON_LOCATEPOLY;
235  title = "Polygon Chooser";
236  break;
237  default:
238  throw ProcessError("Unknown Message ID in onCmdLocate");
239  }
240  myLocatorPopup->popdown();
241  myLocatorButton->killFocus();
242  myLocatorPopup->update();
244  this, GUIIconSubSys::getIcon(icon), title.c_str(), ids, GUIGlObjectStorage::gIDStorage);
245  chooser->create();
246  chooser->show();
247  return 1;
248 }
249 
250 
251 long
252 GUISUMOViewParent::onSimStep(FXObject*, FXSelector, void*) {
253  myView->update();
255  return 1;
256 }
257 
258 
259 bool
261  GUIGlObjectType type = o->getType();
262  if (gSelected.isSelected(type, o->getGlID())) {
263  return true;
264  } else if (type == GLO_EDGE) {
265  GUIEdge* edge = dynamic_cast<GUIEdge*>(o);
266  if (edge == 0) {
267  // hmph, just some security stuff
268  return false;
269  }
270  const std::vector<MSLane*>& lanes = edge->getLanes();
271  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
272  GUILane* l = dynamic_cast<GUILane*>(*j);
273  if (l != 0 && gSelected.isSelected(GLO_LANE, l->getGlID())) {
274  return true;
275  }
276  }
277  return false;
278  } else {
279  return false;
280  }
281 }
282 
283 
284 long
285 GUISUMOViewParent::onKeyPress(FXObject* o, FXSelector sel, void* data) {
286  myView->onKeyPress(o, sel, data);
287  return 0;
288 }
289 
290 
291 long
292 GUISUMOViewParent::onKeyRelease(FXObject* o, FXSelector sel, void* data) {
293  myView->onKeyRelease(o, sel, data);
294  return 0;
295 }
296 
297 
298 /****************************************************************************/
299 
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
Locate poi - button.
Definition: GUIAppEnum.h:184
FXGLVisual * getGLVisual() const
The class responsible for building and deletion of vehicles (gui-version)
Locate person - button.
Definition: GUIAppEnum.h:178
GUIGlObjectType
Storage for geometrical objects extended by mutexes.
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:42
void setChecked(bool val)
check or uncheck this MFXCheckableButton
Locate junction - button.
Definition: GUIAppEnum.h:172
~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:47
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:167
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
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
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:69
long onKeyRelease(FXObject *o, FXSelector sel, void *data)
A road/street connecting two junctions (gui-version)
Definition: GUIEdge.h:59
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:768
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:429
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:306
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:86
void removeChild(FXMDIChild *child)
removes the given child window from the list
virtual void checkSnapshots()
Checks whether it is time for a snapshot.
Locate polygons - button.
Definition: GUIAppEnum.h:186
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:91
A single child window which contains a view of the simulation area.
compound additional
static std::vector< GUIGlID > getIDs(bool includeInternal)
Definition: GUIEdge.cpp:95
bool listParking() const
return whether to list parking vehicles
Definition: GUIMainWindow.h:96
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:88
FXMenuButton * myLocatorButton
Locate vehicle - button.
Definition: GUIAppEnum.h:176
Locate addtional structure - button.
Definition: GUIAppEnum.h:182
an edge
GUISUMOAbstractView * myView
the view
Make snapshot - button.
Definition: GUIAppEnum.h:194
GUIGlID getGlID() const
Returns the numerical id of the object.
A Simulation step was performed.
Definition: GUIAppEnum.h:290
Locate edge - button.
Definition: GUIAppEnum.h:174
virtual GUISUMOAbstractView * init(FXGLCanvas *share, GUINet &net, ViewType type)
"Initialises" this window by building the contents
Locate TLS - button.
Definition: GUIAppEnum.h:180
GUISelectedStorage gSelected
A global holder of selected objects.
static bool gUseMesoSim
Definition: MSGlobals.h:97
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
FXVerticalFrame * myContentFrame
static std::vector< GUIGlID > getIDList(int typeFilter)
Returns the list of gl-ids of all additional objects that match the given type.
GUI-version of the transportable control for building gui persons and containers. ...