SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2015 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 "GUIGlobals.h"
62 #include "GUIViewTraffic.h"
63 #include "GUIApplicationWindow.h"
64 #include "GUISUMOViewParent.h"
65 
66 #ifdef HAVE_OSG
67 #include <osgview/GUIOSGView.h>
68 #endif
69 
70 #ifdef CHECK_MEMORY_LEAKS
71 #include <foreign/nvwa/debug_new.h>
72 #endif // CHECK_MEMORY_LEAKS
73 
74 
75 // ===========================================================================
76 // FOX callback mapping
77 // ===========================================================================
78 FXDEFMAP(GUISUMOViewParent) GUISUMOViewParentMap[] = {
80  // FXMAPFUNC(SEL_COMMAND, MID_ALLOWROTATION, GUISUMOViewParent::onCmdAllowRotation),
81  FXMAPFUNC(SEL_COMMAND, MID_LOCATEJUNCTION, GUISUMOViewParent::onCmdLocate),
82  FXMAPFUNC(SEL_COMMAND, MID_LOCATEEDGE, GUISUMOViewParent::onCmdLocate),
83  FXMAPFUNC(SEL_COMMAND, MID_LOCATEVEHICLE, GUISUMOViewParent::onCmdLocate),
84  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPERSON, GUISUMOViewParent::onCmdLocate),
85  FXMAPFUNC(SEL_COMMAND, MID_LOCATETLS, GUISUMOViewParent::onCmdLocate),
86  FXMAPFUNC(SEL_COMMAND, MID_LOCATEADD, GUISUMOViewParent::onCmdLocate),
87  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOI, GUISUMOViewParent::onCmdLocate),
88  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOLY, GUISUMOViewParent::onCmdLocate),
89  FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUISUMOViewParent::onSimStep),
90 
91 };
92 
93 // Object implementation
94 FXIMPLEMENT(GUISUMOViewParent, GUIGlChildWindow, GUISUMOViewParentMap, ARRAYNUMBER(GUISUMOViewParentMap))
95 
96 
97 // ===========================================================================
98 // member method definitions
99 // ===========================================================================
100 GUISUMOViewParent::GUISUMOViewParent(FXMDIClient* p, FXMDIMenu* mdimenu,
101  const FXString& name,
102  GUIMainWindow* parentWindow,
103  FXIcon* ic, FXuint opts,
104  FXint x, FXint y, FXint w, FXint h)
105  : GUIGlChildWindow(p, parentWindow, mdimenu, name, ic, opts, x, y, w, h) {
106  myParent->addChild(this, false);
107 }
108 
109 
112  switch (type) {
113  default:
114  case VIEW_2D_OPENGL:
115  myView = new GUIViewTraffic(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
116  break;
117 #ifdef HAVE_OSG
118  case VIEW_3D_OSG:
119  myView = new GUIOSGView(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
120  break;
121 #endif
122  }
123  myView->buildViewToolBars(*this);
124  if (myParent->isGaming()) {
125  myNavigationToolBar->hide();
126  }
127  return myView;
128 }
129 
130 
132  myParent->removeChild(this);
133 }
134 
135 
136 void
138  if (value) {
139  myNavigationToolBar->show();
140  } else {
141  myNavigationToolBar->hide();
142  }
143 }
144 
145 
146 long
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  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"
153  "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
154  "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
155  "JPEG Image (*.jpg, *.jpeg)\nTIFF Image (*.tif, *.tiff)\n"
156  "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n"
157  "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n"
158  "All Files (*)");
159  if (gCurrentFolder.length() != 0) {
160  opendialog.setDirectory(gCurrentFolder);
161  }
162  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
163  return 1;
164  }
165  gCurrentFolder = opendialog.getDirectory();
166  std::string file = opendialog.getFilename().text();
167  std::string error = myView->makeSnapshot(file);
168  if (error != "") {
169  FXMessageBox::error(this, MBOX_OK, "Saving failed.", "%s", error.c_str());
170  }
171  return 1;
172 }
173 
174 
175 long
176 GUISUMOViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
177  std::vector<GUIGlID> ids;
178  GUIIcon icon;
179  std::string title;
180  switch (FXSELID(sel)) {
181  case MID_LOCATEJUNCTION:
182  ids = static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs(myParent->listInternal());
183  icon = ICON_LOCATEJUNCTION;
184  title = "Junction Chooser";
185  break;
186  case MID_LOCATEEDGE:
188  icon = ICON_LOCATEEDGE;
189  title = "Edge Chooser";
190  break;
191  case MID_LOCATEVEHICLE:
192  static_cast<GUIVehicleControl&>(MSNet::getInstance()->getVehicleControl()).insertVehicleIDs(ids);
193  icon = ICON_LOCATEVEHICLE;
194  title = "Vehicle Chooser";
195  break;
196  case MID_LOCATEPERSON:
197  static_cast<GUIPersonControl&>(MSNet::getInstance()->getPersonControl()).insertPersonIDs(ids);
198  icon = ICON_LOCATEPERSON;
199  title = "Person Chooser";
200  break;
201  case MID_LOCATETLS:
202  ids = static_cast<GUINet*>(GUINet::getInstance())->getTLSIDs();
203  icon = ICON_LOCATETLS;
204  title = "Traffic Lights Chooser";
205  break;
206  case MID_LOCATEADD:
208  icon = ICON_LOCATEADD;
209  title = "Additional Objects Chooser";
210  break;
211  case MID_LOCATEPOI:
212  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPOIIds();
213  icon = ICON_LOCATEPOI;
214  title = "POI Chooser";
215  break;
216  case MID_LOCATEPOLY:
217  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPolygonIDs();
218  icon = ICON_LOCATEPOLY;
219  title = "Polygon Chooser";
220  break;
221  default:
222  throw ProcessError("Unknown Message ID in onCmdLocate");
223  }
224  myLocatorPopup->popdown();
225  myLocatorButton->killFocus();
226  myLocatorPopup->update();
228  this, GUIIconSubSys::getIcon(icon), title.c_str(), ids, GUIGlObjectStorage::gIDStorage);
229  chooser->create();
230  chooser->show();
231  return 1;
232 }
233 
234 
235 long
237  myView->update();
239  return 1;
240 }
241 
242 
243 bool
245  GUIGlObjectType type = o->getType();
246  if (gSelected.isSelected(type, o->getGlID())) {
247  return true;
248  } else if (type == GLO_EDGE) {
249  GUIEdge* edge = dynamic_cast<GUIEdge*>(o);
250  if (edge == 0) {
251  // hmph, just some security stuff
252  return false;
253  }
254  const std::vector<MSLane*>& lanes = edge->getLanes();
255  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
256  GUILane* l = dynamic_cast<GUILane*>(*j);
257  if (l != 0 && gSelected.isSelected(GLO_LANE, l->getGlID())) {
258  return true;
259  }
260  }
261  return false;
262  } else {
263  return false;
264  }
265 }
266 
267 
268 long
269 GUISUMOViewParent::onKeyPress(FXObject* o, FXSelector sel, void* data) {
270  myView->onKeyPress(o, sel, data);
271  return 0;
272 }
273 
274 
275 long
276 GUISUMOViewParent::onKeyRelease(FXObject* o, FXSelector sel, void* data) {
277  myView->onKeyRelease(o, sel, data);
278  return 0;
279 }
280 
281 
282 /****************************************************************************/
283 
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) ...
The class responsible for building and deletion of vehicles (gui-version)
Locate poi - button.
Definition: GUIAppEnum.h:173
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:186
Locate vehicle - button.
Definition: GUIAppEnum.h:165
~GUISUMOViewParent()
Destructor.
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 person - button.
Definition: GUIAppEnum.h:167
void setToolBarVisibility(const bool value)
about toggled gaming status
Locate TLS - button.
Definition: GUIAppEnum.h:169
Make snapshot - button.
Definition: GUIAppEnum.h:183
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:162
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
Locate junction - button.
Definition: GUIAppEnum.h:161
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:115
FXDEFMAP(GUIDialog_AppSettings) GUIDialog_AppSettingsMap[]
A Simulation step was performed.
Definition: GUIAppEnum.h:273
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:61
GUIMainWindow * myParent
The parent window.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:159
long onKeyPress(FXObject *o, FXSelector sel, void *data)
handle keys
virtual long onKeyPress(FXObject *o, FXSelector sel, void *data)
Locate polygons - button.
Definition: GUIAppEnum.h:175
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:415
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:304
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
void removeChild(FXMDIChild *child)
removes the given child window from the list
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
Locate addtional structure - button.
Definition: GUIAppEnum.h:171
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:90
virtual MSPersonControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:685
FXMenuButton * myLocatorButton
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)
&quot;Initialises&quot; this window by building the contents
Locate edge - button.
Definition: GUIAppEnum.h:163
GUISelectedStorage gSelected
A global holder of selected objects.
static FXIcon * getIcon(GUIIcon which)
FXVerticalFrame * myContentFrame