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.sourceforge.net/
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/GUINet.h>
56 #include <microsim/MSJunction.h>
57 #include "GUIGlobals.h"
58 #include "GUIViewTraffic.h"
59 #include "GUIApplicationWindow.h"
60 #include "GUISUMOViewParent.h"
61 
62 #ifdef HAVE_OSG
63 #include <osgview/GUIOSGView.h>
64 #endif
65 
66 #ifdef CHECK_MEMORY_LEAKS
67 #include <foreign/nvwa/debug_new.h>
68 #endif // CHECK_MEMORY_LEAKS
69 
70 
71 // ===========================================================================
72 // FOX callback mapping
73 // ===========================================================================
74 FXDEFMAP(GUISUMOViewParent) GUISUMOViewParentMap[] = {
76  // FXMAPFUNC(SEL_COMMAND, MID_ALLOWROTATION, GUISUMOViewParent::onCmdAllowRotation),
77  FXMAPFUNC(SEL_COMMAND, MID_LOCATEJUNCTION, GUISUMOViewParent::onCmdLocate),
78  FXMAPFUNC(SEL_COMMAND, MID_LOCATEEDGE, GUISUMOViewParent::onCmdLocate),
79  FXMAPFUNC(SEL_COMMAND, MID_LOCATEVEHICLE, GUISUMOViewParent::onCmdLocate),
80  FXMAPFUNC(SEL_COMMAND, MID_LOCATETLS, GUISUMOViewParent::onCmdLocate),
81  FXMAPFUNC(SEL_COMMAND, MID_LOCATEADD, GUISUMOViewParent::onCmdLocate),
82  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOI, GUISUMOViewParent::onCmdLocate),
83  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOLY, GUISUMOViewParent::onCmdLocate),
84  FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUISUMOViewParent::onSimStep),
85 
86 };
87 
88 // Object implementation
89 FXIMPLEMENT(GUISUMOViewParent, GUIGlChildWindow, GUISUMOViewParentMap, ARRAYNUMBER(GUISUMOViewParentMap))
90 
91 
92 // ===========================================================================
93 // member method definitions
94 // ===========================================================================
95 GUISUMOViewParent::GUISUMOViewParent(FXMDIClient* p, FXMDIMenu* mdimenu,
96  const FXString& name,
97  GUIMainWindow* parentWindow,
98  FXIcon* ic, FXuint opts,
99  FXint x, FXint y, FXint w, FXint h)
100  : GUIGlChildWindow(p, parentWindow, mdimenu, name, ic, opts, x, y, w, h) {
101  myParent->addChild(this, false);
102 }
103 
104 
107  switch (type) {
108  default:
109  case VIEW_2D_OPENGL:
110  myView = new GUIViewTraffic(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
111  break;
112 #ifdef HAVE_OSG
113  case VIEW_3D_OSG:
114  myView = new GUIOSGView(myContentFrame, *myParent, this, net, myParent->getGLVisual(), share);
115  break;
116 #endif
117  }
118  myView->buildViewToolBars(*this);
119  if (myParent->isGaming()) {
120  myNavigationToolBar->hide();
121  }
122  return myView;
123 }
124 
125 
127  myParent->removeChild(this);
128 }
129 
130 
131 long
133  // get the new file name
134  FXFileDialog opendialog(this, "Save Snapshot");
135  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
136  opendialog.setSelectMode(SELECTFILE_ANY);
137  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"
138  "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
139  "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
140  "JPEG Image (*.jpg, *.jpeg)\nTIFF Image (*.tif, *.tiff)\n"
141  "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n"
142  "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n"
143  "All Files (*)");
144  if (gCurrentFolder.length() != 0) {
145  opendialog.setDirectory(gCurrentFolder);
146  }
147  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
148  return 1;
149  }
150  gCurrentFolder = opendialog.getDirectory();
151  std::string file = opendialog.getFilename().text();
152  std::string error = myView->makeSnapshot(file);
153  if (error != "") {
154  FXMessageBox::error(this, MBOX_OK, "Saving failed.", "%s", error.c_str());
155  }
156  return 1;
157 }
158 
159 
160 long
161 GUISUMOViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
162  GUIGlObjectType type;
163  std::vector<GUIGlID> ids;
164  GUIIcon icon;
165  std::string title;
166  switch (FXSELID(sel)) {
167  case MID_LOCATEJUNCTION:
168  type = GLO_JUNCTION;
169  ids = static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs(myParent->listInternal());
170  icon = ICON_LOCATEJUNCTION;
171  title = "Junction Chooser";
172  break;
173  case MID_LOCATEEDGE:
174  type = GLO_EDGE;
176  icon = ICON_LOCATEEDGE;
177  title = "Edge Chooser";
178  break;
179  case MID_LOCATEVEHICLE:
180  type = GLO_VEHICLE;
181  static_cast<GUIVehicleControl&>(MSNet::getInstance()->getVehicleControl()).insertVehicleIDs(ids);
182  icon = ICON_LOCATEVEHICLE;
183  title = "Vehicle Chooser";
184  break;
185  case MID_LOCATETLS:
186  type = GLO_TLLOGIC;
187  ids = static_cast<GUINet*>(GUINet::getInstance())->getTLSIDs();
188  icon = ICON_LOCATETLS;
189  title = "Traffic Lights Chooser";
190  break;
191  case MID_LOCATEADD:
192  type = GLO_ADDITIONAL;
194  icon = ICON_LOCATEADD;
195  title = "Additional Objects Chooser";
196  break;
197  case MID_LOCATEPOI:
198  type = GLO_POI;
199  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPOIIds();
200  icon = ICON_LOCATESHAPE;
201  title = "POI Chooser";
202  break;
203  case MID_LOCATEPOLY:
204  type = GLO_POLYGON;
205  ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getPolygonIDs();
206  icon = ICON_LOCATESHAPE;
207  title = "Polygon Chooser";
208  break;
209  default:
210  throw ProcessError("Unknown Message ID in onCmdLocate");
211  }
212  myLocatorPopup->popdown();
213  myLocatorButton->killFocus();
214  myLocatorPopup->update();
216  this, GUIIconSubSys::getIcon(icon), title.c_str(), type, ids, GUIGlObjectStorage::gIDStorage);
217  chooser->create();
218  chooser->show();
219  return 1;
220 }
221 
222 
223 long
225  myView->update();
227  return 1;
228 }
229 
230 
231 bool
233  GUIGlObjectType type = o->getType();
234  if (gSelected.isSelected(type, o->getGlID())) {
235  return true;
236  } else if (type == GLO_EDGE) {
237  GUIEdge* edge = dynamic_cast<GUIEdge*>(o);
238  if (edge == 0) {
239  // hmph, just some security stuff
240  return false;
241  }
242  size_t noLanes = edge->getLanes().size();
243  for (size_t j = 0; j < noLanes; ++j) {
244  const GUILaneWrapper& l = edge->getLaneGeometry(j);
245  if (gSelected.isSelected(GLO_LANE, l.getGlID())) {
246  return true;
247  }
248  }
249  return false;
250  } else {
251  return false;
252  }
253 }
254 
255 
256 /****************************************************************************/
257