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