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