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-sim.org/
14 // Copyright (C) 2001-2014 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>
39 #include <utils/geom/Position.h>
40 #include <utils/geom/Boundary.h>
52 #include <guisim/GUIVehicle.h>
53 #include <guisim/GUIEdge.h>
54 #include <guisim/GUILane.h>
55 #include <guisim/GUINet.h>
57 #include <microsim/MSJunction.h>
58 #include "GUIGlobals.h"
59 #include "GUIViewTraffic.h"
60 #include "GUIApplicationWindow.h"
61 #include "GUISUMOViewParent.h"
62 
63 #ifdef HAVE_OSG
64 #include <osgview/GUIOSGView.h>
65 #endif
66 
67 #ifdef CHECK_MEMORY_LEAKS
68 #include <foreign/nvwa/debug_new.h>
69 #endif // CHECK_MEMORY_LEAKS
70 
71 
72 // ===========================================================================
73 // FOX callback mapping
74 // ===========================================================================
75 FXDEFMAP(GUISUMOViewParent) GUISUMOViewParentMap[] = {
77  // FXMAPFUNC(SEL_COMMAND, MID_ALLOWROTATION, GUISUMOViewParent::onCmdAllowRotation),
78  FXMAPFUNC(SEL_COMMAND, MID_LOCATEJUNCTION, GUISUMOViewParent::onCmdLocate),
79  FXMAPFUNC(SEL_COMMAND, MID_LOCATEEDGE, GUISUMOViewParent::onCmdLocate),
80  FXMAPFUNC(SEL_COMMAND, MID_LOCATEVEHICLE, GUISUMOViewParent::onCmdLocate),
81  FXMAPFUNC(SEL_COMMAND, MID_LOCATETLS, GUISUMOViewParent::onCmdLocate),
82  FXMAPFUNC(SEL_COMMAND, MID_LOCATEADD, GUISUMOViewParent::onCmdLocate),
83  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOI, GUISUMOViewParent::onCmdLocate),
84  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOLY, GUISUMOViewParent::onCmdLocate),
85  FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUISUMOViewParent::onSimStep),
86 
87 };
88 
89 // Object implementation
90 FXIMPLEMENT(GUISUMOViewParent, GUIGlChildWindow, GUISUMOViewParentMap, ARRAYNUMBER(GUISUMOViewParentMap))
91 
92 
93 // ===========================================================================
94 // member method definitions
95 // ===========================================================================
96 GUISUMOViewParent::GUISUMOViewParent(FXMDIClient* p, FXMDIMenu* mdimenu,
97  const FXString& name,
98  GUIMainWindow* parentWindow,
99  FXIcon* ic, FXuint opts,
100  FXint x, FXint y, FXint w, FXint h)
101  : GUIGlChildWindow(p, parentWindow, mdimenu, name, ic, opts, x, y, w, h) {
102  myParent->addChild(this, false);
103 }
104 
105 
108  switch (type) {
109  default:
110  case VIEW_2D_OPENGL:
111  myView = new GUIViewTraffic(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
112  break;
113 #ifdef HAVE_OSG
114  case VIEW_3D_OSG:
115  myView = new GUIOSGView(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
116  break;
117 #endif
118  }
119  myView->buildViewToolBars(*this);
120  if (myParent->isGaming()) {
121  myNavigationToolBar->hide();
122  }
123  return myView;
124 }
125 
126 
128  myParent->removeChild(this);
129 }
130 
131 
132 void
134  if (myParent->isGaming()) {
135  myNavigationToolBar->hide();
136  } else {
137  myNavigationToolBar->show();
138  }
139 }
140 
141 
142 long
144  // get the new file name
145  FXFileDialog opendialog(this, "Save Snapshot");
146  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
147  opendialog.setSelectMode(SELECTFILE_ANY);
148  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"
149  "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
150  "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
151  "JPEG Image (*.jpg, *.jpeg)\nTIFF Image (*.tif, *.tiff)\n"
152  "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n"
153  "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n"
154  "All Files (*)");
155  if (gCurrentFolder.length() != 0) {
156  opendialog.setDirectory(gCurrentFolder);
157  }
158  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
159  return 1;
160  }
161  gCurrentFolder = opendialog.getDirectory();
162  std::string file = opendialog.getFilename().text();
163  std::string error = myView->makeSnapshot(file);
164  if (error != "") {
165  FXMessageBox::error(this, MBOX_OK, "Saving failed.", "%s", error.c_str());
166  }
167  return 1;
168 }
169 
170 
171 long
172 GUISUMOViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
173  GUIGlObjectType type;
174  std::vector<GUIGlID> ids;
175  GUIIcon icon;
176  std::string title;
177  switch (FXSELID(sel)) {
178  case MID_LOCATEJUNCTION:
179  type = GLO_JUNCTION;
180  ids = static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs(myParent->listInternal());
181  icon = ICON_LOCATEJUNCTION;
182  title = "Junction Chooser";
183  break;
184  case MID_LOCATEEDGE:
185  type = GLO_EDGE;
187  icon = ICON_LOCATEEDGE;
188  title = "Edge Chooser";
189  break;
190  case MID_LOCATEVEHICLE:
191  type = GLO_VEHICLE;
192  static_cast<GUIVehicleControl&>(MSNet::getInstance()->getVehicleControl()).insertVehicleIDs(ids);
193  icon = ICON_LOCATEVEHICLE;
194  title = "Vehicle Chooser";
195  break;
196  case MID_LOCATETLS:
197  type = GLO_TLLOGIC;
198  ids = static_cast<GUINet*>(GUINet::getInstance())->getTLSIDs();
199  icon = ICON_LOCATETLS;
200  title = "Traffic Lights Chooser";
201  break;
202  case MID_LOCATEADD:
203  type = GLO_ADDITIONAL;
205  icon = ICON_LOCATEADD;
206  title = "Additional Objects Chooser";
207  break;
208  case MID_LOCATEPOI:
209  type = GLO_POI;
210  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPOIIds();
211  icon = ICON_LOCATEPOI;
212  title = "POI Chooser";
213  break;
214  case MID_LOCATEPOLY:
215  type = GLO_POLYGON;
216  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPolygonIDs();
217  icon = ICON_LOCATEPOLY;
218  title = "Polygon Chooser";
219  break;
220  default:
221  throw ProcessError("Unknown Message ID in onCmdLocate");
222  }
223  myLocatorPopup->popdown();
224  myLocatorButton->killFocus();
225  myLocatorPopup->update();
227  this, GUIIconSubSys::getIcon(icon), title.c_str(), type, ids, GUIGlObjectStorage::gIDStorage);
228  chooser->create();
229  chooser->show();
230  return 1;
231 }
232 
233 
234 long
236  myView->update();
238  return 1;
239 }
240 
241 
242 bool
244  GUIGlObjectType type = o->getType();
245  if (gSelected.isSelected(type, o->getGlID())) {
246  return true;
247  } else if (type == GLO_EDGE) {
248  GUIEdge* edge = dynamic_cast<GUIEdge*>(o);
249  if (edge == 0) {
250  // hmph, just some security stuff
251  return false;
252  }
253  const std::vector<MSLane*>& lanes = edge->getLanes();
254  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
255  GUILane* l = dynamic_cast<GUILane*>(*j);
256  if (l != 0 && gSelected.isSelected(GLO_LANE, l->getGlID())) {
257  return true;
258  }
259  }
260  return false;
261  } else {
262  return false;
263  }
264 }
265 
266 
267 /****************************************************************************/
268 
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:167
a polygon
GUIGlObjectType
a vehicles
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's lanes.
Definition: MSEdge.h:173
Locate vehicle - button.
Definition: GUIAppEnum.h:161
~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:52
Locate TLS - button.
Definition: GUIAppEnum.h:163
Make snapshot - button.
Definition: GUIAppEnum.h:177
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
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.
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:77
Locate junction - button.
Definition: GUIAppEnum.h:157
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:115
A Simulation step was performed.
Definition: GUIAppEnum.h:263
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:70
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
Locate polygons - button.
Definition: GUIAppEnum.h:169
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:370
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:269
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
a tl-logic
ViewType
Available view types.
FXGLVisual * getGLVisual() const
bool listInternal() const
return whether to list internal structures
Definition: GUIMainWindow.h:82
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.
compound additional
static std::vector< GUIGlID > getIDs(bool includeInternal)
Definition: GUIEdge.cpp:97
Locate addtional structure - button.
Definition: GUIAppEnum.h:165
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
FXMenuButton * myLocatorButton
an edge
GUISUMOAbstractView * myView
the view
virtual GUISUMOAbstractView * init(FXGLCanvas *share, GUINet &net, ViewType type)
"Initialises" this window by building the contents
Locate edge - button.
Definition: GUIAppEnum.h:159
GUISelectedStorage gSelected
A global holder of selected objects.
static FXIcon * getIcon(GUIIcon which)
FXVerticalFrame * myContentFrame
void toggleGaming()
about toggled gaming status
a junction