SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIViewTraffic.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // A view on the simulation; this view is a microscopic one
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 <iostream>
36 #include <utility>
37 #include <cmath>
38 #include <limits>
39 #include <guisim/GUINet.h>
40 #include <guisim/GUIEdge.h>
41 #include <guisim/GUILane.h>
42 #include <guisim/GUIVehicle.h>
43 #include <microsim/MSEdge.h>
44 #include <microsim/MSLane.h>
47 #include <utils/common/RGBColor.h>
49 #include <utils/shapes/Polygon.h>
50 #include "GUISUMOViewParent.h"
51 #include "GUIViewTraffic.h"
65 #include <utils/gui/div/GLHelper.h>
67 
68 #ifdef CHECK_MEMORY_LEAKS
69 #include <foreign/nvwa/debug_new.h>
70 #endif // CHECK_MEMORY_LEAKS
71 
72 
73 // ===========================================================================
74 // member method definitions
75 // ===========================================================================
77  FXComposite* p,
78  GUIMainWindow& app,
79  GUISUMOViewParent* parent,
80  GUINet& net, FXGLVisual* glVis,
81  FXGLCanvas* share) :
82  GUISUMOAbstractView(p, app, parent, net.getVisualisationSpeedUp(), glVis, share),
83  myTrackedID(-1) {}
84 
85 
87 }
88 
89 
90 void
92  // build coloring tools
93  {
94  const std::vector<std::string>& names = gSchemeStorage.getNames();
95  for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i) {
96  v.getColoringSchemesCombo().appendItem((*i).c_str());
97  if ((*i) == myVisualizationSettings->name) {
98  v.getColoringSchemesCombo().setCurrentItem(v.getColoringSchemesCombo().getNumItems() - 1);
99  }
100  }
101  v.getColoringSchemesCombo().setNumVisible(5);
102  }
103  // for junctions
104  new FXButton(v.getLocatorPopup(),
105  "\tLocate Junction\tLocate a junction within the network.",
107  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
108  // for edges
109  new FXButton(v.getLocatorPopup(),
110  "\tLocate Street\tLocate a street within the network.",
112  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
113 
114  if (!MSGlobals::gUseMesoSim) { // there are no gui-vehicles in mesosim
115  // for vehicles
116  new FXButton(v.getLocatorPopup(),
117  "\tLocate Vehicle\tLocate a vehicle within the network.",
119  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
120  }
121  // for tls
122  new FXButton(v.getLocatorPopup(),
123  "\tLocate TLS\tLocate a tls within the network.",
125  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
126  // for additional stuff
127  new FXButton(v.getLocatorPopup(),
128  "\tLocate Additional\tLocate an additional structure within the network.",
130  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
131  // for pois
132  new FXButton(v.getLocatorPopup(),
133  "\tLocate POI\tLocate a POI within the network.",
135  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
136  // for polygons
137  new FXButton(v.getLocatorPopup(),
138  "\tLocate Polygon\tLocate a Polygon within the network.",
140  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
141 }
142 
143 
144 bool
145 GUIViewTraffic::setColorScheme(const std::string& name) {
146  if (!gSchemeStorage.contains(name)) {
147  return false;
148  }
149  if (myVisualizationChanger != 0) {
150  if (myVisualizationChanger->getCurrentScheme() != name) {
152  }
153  }
154  myVisualizationSettings = &gSchemeStorage.get(name.c_str());
156  update();
157  return true;
158 }
159 
160 
161 int
162 GUIViewTraffic::doPaintGL(int mode, const Boundary& bound) {
163  // init view settings
164  glRenderMode(mode);
165  glMatrixMode(GL_MODELVIEW);
166  glPushMatrix();
167  glDisable(GL_TEXTURE_2D);
168  glDisable(GL_ALPHA_TEST);
169  glDisable(GL_BLEND);
170  glEnable(GL_DEPTH_TEST);
171 
172  // draw decals (if not in grabbing mode)
173  if (!myUseToolTips) {
174  drawDecals();
176  paintGLGrid();
177  }
178  }
179 
180  glLineWidth(1);
181  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
182  float minB[2];
183  float maxB[2];
184  minB[0] = bound.xmin();
185  minB[1] = bound.ymin();
186  maxB[0] = bound.xmax();
187  maxB[1] = bound.ymax();
189  glEnable(GL_POLYGON_OFFSET_FILL);
190  glEnable(GL_POLYGON_OFFSET_LINE);
191  int hits2 = myGrid->Search(minB, maxB, *myVisualizationSettings);
192  //
193  glTranslated(0, 0, -.01);
194  for (std::map<GUIGlObject*, int>::iterator i = myAdditionallyDrawn.begin(); i != myAdditionallyDrawn.end(); ++i) {
195  (i->first)->drawGLAdditional(this, *myVisualizationSettings);
196  }
197  glTranslated(0, 0, .01);
198  glPopMatrix();
199  /*
200  // draw legends
201  glMatrixMode(GL_MODELVIEW);
202  glLoadIdentity();
203  glTranslated(1.-.2, 1.-.5, 0.);
204  glScaled(.2, .5, 1.);
205  GUIColoringSchemesMap<GUILaneWrapper> &sm = GUIViewTraffic::getLaneSchemesMap(); //!!!
206  sm.getColorer(myVisualizationSettings->laneEdgeMode)->drawLegend();
207  */
208  return hits2;
209 }
210 
211 
212 void
214  myTrackedID = id;
215 }
216 
217 
218 void
220  myTrackedID = -1;
221 }
222 
223 
224 int
226  return myTrackedID;
227 }
228 
229 
230 void
232  if (myVisualizationChanger == 0) {
237  myVisualizationChanger->create();
238  } else {
240  }
241  myVisualizationChanger->show();
242 }
243 
244 
245 void
248  const std::vector<MSTrafficLightLogic*>& logics = tlsControl.getAllLogics();
249  MSTrafficLightLogic* minTll = 0;
250  SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity();
251  for (std::vector<MSTrafficLightLogic*>::const_iterator i = logics.begin(); i != logics.end(); ++i) {
252  // get the logic
253  MSTrafficLightLogic* tll = (*i);
254  if (tlsControl.isActive(tll)) {
255  // get the links
256  const MSTrafficLightLogic::LaneVector& lanes = tll->getLanesAt(0);
257  if (lanes.size() > 0) {
258  const Position& endPos = lanes[0]->getShape().getEnd();
259  if (endPos.distanceTo(pos) < minDist) {
260  minDist = endPos.distanceTo(pos);
261  minTll = tll;
262  }
263  }
264  }
265  }
266  if (minTll != 0) {
267  const MSTLLogicControl::TLSLogicVariants& vars = tlsControl.get(minTll->getID());
268  const std::vector<MSTrafficLightLogic*> logics = vars.getAllLogics();
269  if (logics.size() > 1) {
271  for (unsigned int i = 0; i < logics.size() - 1; i++) {
272  if (minTll->getProgramID() == logics[i]->getProgramID()) {
273  l = (MSSimpleTrafficLightLogic*) logics[i + 1];
274  tlsControl.switchTo(minTll->getID(), l->getProgramID());
275  }
276  }
277  if (l == logics[0]) {
278  tlsControl.switchTo(minTll->getID(), l->getProgramID());
279  }
281  update();
282  }
283  }
284 }
285 
286 
287 SUMOTime
290 }
291 /****************************************************************************/