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-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 <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"
64 #include <utils/gui/div/GLHelper.h>
66 
67 #ifdef CHECK_MEMORY_LEAKS
68 #include <foreign/nvwa/debug_new.h>
69 #endif // CHECK_MEMORY_LEAKS
70 
71 
72 // ===========================================================================
73 // member method definitions
74 // ===========================================================================
76  FXComposite* p,
77  GUIMainWindow& app,
78  GUISUMOViewParent* parent,
79  GUINet& net, FXGLVisual* glVis,
80  FXGLCanvas* share) :
81  GUISUMOAbstractView(p, app, parent, net.getVisualisationSpeedUp(), glVis, share),
82  myTrackedID(-1) {}
83 
84 
86 }
87 
88 
89 void
91  // build coloring tools
92  {
93  const std::vector<std::string>& names = gSchemeStorage.getNames();
94  for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i) {
95  v.getColoringSchemesCombo().appendItem((*i).c_str());
96  if ((*i) == myVisualizationSettings->name) {
97  v.getColoringSchemesCombo().setCurrentItem(v.getColoringSchemesCombo().getNumItems() - 1);
98  }
99  }
100  v.getColoringSchemesCombo().setNumVisible(5);
101  }
102  // for junctions
103  new FXButton(v.getLocatorPopup(),
104  "\tLocate Junction\tLocate a junction within the network.",
106  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
107  // for edges
108  new FXButton(v.getLocatorPopup(),
109  "\tLocate Street\tLocate a street within the network.",
111  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
112 
113  if (!MSGlobals::gUseMesoSim) { // there are no gui-vehicles in mesosim
114  // for vehicles
115  new FXButton(v.getLocatorPopup(),
116  "\tLocate Vehicle\tLocate a vehicle within the network.",
118  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
119  }
120  // for tls
121  new FXButton(v.getLocatorPopup(),
122  "\tLocate TLS\tLocate a tls within the network.",
124  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
125  // for additional stuff
126  new FXButton(v.getLocatorPopup(),
127  "\tLocate Additional\tLocate an additional structure within the network.",
129  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
130  // for pois
131  new FXButton(v.getLocatorPopup(),
132  "\tLocate PoI\tLocate a PoI within the network.",
134  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
135  // for polygons
136  new FXButton(v.getLocatorPopup(),
137  "\tLocate Polygon\tLocate a Polygon within the network.",
139  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
140 }
141 
142 
143 bool
144 GUIViewTraffic::setColorScheme(const std::string& name) {
145  if (!gSchemeStorage.contains(name)) {
146  return false;
147  }
148  if (myVisualizationChanger != 0) {
149  if (myVisualizationChanger->getCurrentScheme() != name) {
151  }
152  }
153  myVisualizationSettings = &gSchemeStorage.get(name.c_str());
155  update();
156  return true;
157 }
158 
159 
160 int
161 GUIViewTraffic::doPaintGL(int mode, const Boundary& bound) {
162  // init view settings
163  glRenderMode(mode);
164  glMatrixMode(GL_MODELVIEW);
165  glPushMatrix();
166  glDisable(GL_TEXTURE_2D);
167  glDisable(GL_ALPHA_TEST);
168  glDisable(GL_BLEND);
169  glEnable(GL_DEPTH_TEST);
170 
171  // draw decals (if not in grabbing mode)
172  if (!myUseToolTips) {
173  drawDecals();
175  paintGLGrid();
176  }
177  }
178 
179  glLineWidth(1);
180  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
181  float minB[2];
182  float maxB[2];
183  minB[0] = bound.xmin();
184  minB[1] = bound.ymin();
185  maxB[0] = bound.xmax();
186  maxB[1] = bound.ymax();
188  glEnable(GL_POLYGON_OFFSET_FILL);
189  glEnable(GL_POLYGON_OFFSET_LINE);
190  int hits2 = myGrid->Search(minB, maxB, *myVisualizationSettings);
191  //
192  if (myAdditionallyDrawn.size() > 0) {
193  glTranslated(0, 0, -.01);
195  for (std::map<GUIGlObject*, int>::iterator i = myAdditionallyDrawn.begin(); i != myAdditionallyDrawn.end(); ++i) {
196  (i->first)->drawGLAdditional(this, *myVisualizationSettings);
197  }
199  glTranslated(0, 0, .01);
200  }
201  glPopMatrix();
202  /*
203  // draw legends
204  glMatrixMode(GL_MODELVIEW);
205  glLoadIdentity();
206  glTranslated(1.-.2, 1.-.5, 0.);
207  glScaled(.2, .5, 1.);
208  GUIColoringSchemesMap<GUILane> &sm = GUIViewTraffic::getLaneSchemesMap(); //!!!
209  sm.getColorer(myVisualizationSettings->laneEdgeMode)->drawLegend();
210  */
211  return hits2;
212 }
213 
214 
215 void
217  myTrackedID = id;
218 }
219 
220 
221 void
223  myTrackedID = -1;
224 }
225 
226 
227 int
229  return myTrackedID;
230 }
231 
232 
233 void
236  const std::vector<MSTrafficLightLogic*>& logics = tlsControl.getAllLogics();
237  MSTrafficLightLogic* minTll = 0;
238  SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity();
239  for (std::vector<MSTrafficLightLogic*>::const_iterator i = logics.begin(); i != logics.end(); ++i) {
240  // get the logic
241  MSTrafficLightLogic* tll = (*i);
242  if (tlsControl.isActive(tll)) {
243  // get the links
244  const MSTrafficLightLogic::LaneVector& lanes = tll->getLanesAt(0);
245  if (lanes.size() > 0) {
246  const Position& endPos = lanes[0]->getShape().back();
247  if (endPos.distanceTo(pos) < minDist) {
248  minDist = endPos.distanceTo(pos);
249  minTll = tll;
250  }
251  }
252  }
253  }
254  if (minTll != 0) {
255  const MSTLLogicControl::TLSLogicVariants& vars = tlsControl.get(minTll->getID());
256  const std::vector<MSTrafficLightLogic*> logics = vars.getAllLogics();
257  if (logics.size() > 1) {
259  for (unsigned int i = 0; i < logics.size() - 1; ++i) {
260  if (minTll->getProgramID() == logics[i]->getProgramID()) {
261  l = (MSSimpleTrafficLightLogic*) logics[i + 1];
262  tlsControl.switchTo(minTll->getID(), l->getProgramID());
263  }
264  }
265  if (l == logics[0]) {
266  tlsControl.switchTo(minTll->getID(), l->getProgramID());
267  }
269  update();
270  }
271  }
272 }
273 
274 
275 SUMOTime
278 }
279 /****************************************************************************/