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-2013 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 long
134  // get the new file name
135  FXFileDialog opendialog(this, "Save Snapshot");
136  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
137  opendialog.setSelectMode(SELECTFILE_ANY);
138  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"
139  "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
140  "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
141  "JPEG Image (*.jpg, *.jpeg)\nTIFF Image (*.tif, *.tiff)\n"
142  "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n"
143  "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n"
144  "All Files (*)");
145  if (gCurrentFolder.length() != 0) {
146  opendialog.setDirectory(gCurrentFolder);
147  }
148  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
149  return 1;
150  }
151  gCurrentFolder = opendialog.getDirectory();
152  std::string file = opendialog.getFilename().text();
153  std::string error = myView->makeSnapshot(file);
154  if (error != "") {
155  FXMessageBox::error(this, MBOX_OK, "Saving failed.", "%s", error.c_str());
156  }
157  return 1;
158 }
159 
160 
161 long
162 GUISUMOViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
163  GUIGlObjectType type;
164  std::vector<GUIGlID> ids;
165  GUIIcon icon;
166  std::string title;
167  switch (FXSELID(sel)) {
168  case MID_LOCATEJUNCTION:
169  type = GLO_JUNCTION;
170  ids = static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs(myParent->listInternal());
171  icon = ICON_LOCATEJUNCTION;
172  title = "Junction Chooser";
173  break;
174  case MID_LOCATEEDGE:
175  type = GLO_EDGE;
177  icon = ICON_LOCATEEDGE;
178  title = "Edge Chooser";
179  break;
180  case MID_LOCATEVEHICLE:
181  type = GLO_VEHICLE;
182  static_cast<GUIVehicleControl&>(MSNet::getInstance()->getVehicleControl()).insertVehicleIDs(ids);
183  icon = ICON_LOCATEVEHICLE;
184  title = "Vehicle Chooser";
185  break;
186  case MID_LOCATETLS:
187  type = GLO_TLLOGIC;
188  ids = static_cast<GUINet*>(GUINet::getInstance())->getTLSIDs();
189  icon = ICON_LOCATETLS;
190  title = "Traffic Lights Chooser";
191  break;
192  case MID_LOCATEADD:
193  type = GLO_ADDITIONAL;
195  icon = ICON_LOCATEADD;
196  title = "Additional Objects Chooser";
197  break;
198  case MID_LOCATEPOI:
199  type = GLO_POI;
200  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPOIIds();
201  icon = ICON_LOCATESHAPE;
202  title = "POI Chooser";
203  break;
204  case MID_LOCATEPOLY:
205  type = GLO_POLYGON;
206  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPolygonIDs();
207  icon = ICON_LOCATESHAPE;
208  title = "Polygon Chooser";
209  break;
210  default:
211  throw ProcessError("Unknown Message ID in onCmdLocate");
212  }
213  myLocatorPopup->popdown();
214  myLocatorButton->killFocus();
215  myLocatorPopup->update();
217  this, GUIIconSubSys::getIcon(icon), title.c_str(), type, ids, GUIGlObjectStorage::gIDStorage);
218  chooser->create();
219  chooser->show();
220  return 1;
221 }
222 
223 
224 long
226  myView->update();
228  return 1;
229 }
230 
231 
232 bool
234  GUIGlObjectType type = o->getType();
235  if (gSelected.isSelected(type, o->getGlID())) {
236  return true;
237  } else if (type == GLO_EDGE) {
238  GUIEdge* edge = dynamic_cast<GUIEdge*>(o);
239  if (edge == 0) {
240  // hmph, just some security stuff
241  return false;
242  }
243  const std::vector<MSLane*>& lanes = edge->getLanes();
244  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
245  GUILane* l = dynamic_cast<GUILane*>(*j);
246  if (l != 0 && gSelected.isSelected(GLO_LANE, l->getGlID())) {
247  return true;
248  }
249  }
250  return false;
251  } else {
252  return false;
253  }
254 }
255 
256 
257 /****************************************************************************/
258 
static std::vector< GUIGlID > getIDList()
Returns the list of gl-ids of all additional objects.
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&#39;s lanes.
Definition: MSEdge.h:167
Locate vehicle - button.
Definition: GUIAppEnum.h:161
~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 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:150
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
FXDEFMAP(GUIDialog_AppSettings) GUIDialog_AppSettingsMap[]
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:349
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:248
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)
&quot;Initialises&quot; 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
a junction