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