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