SUMO - Simulation of Urban MObility
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.dlr.de/
14 // Copyright (C) 2001-2015 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/MSGlobals.h>
44 #include <microsim/MSEdge.h>
45 #include <microsim/MSLane.h>
48 #include <utils/common/RGBColor.h>
50 #include <utils/shapes/Polygon.h>
51 #include "GUISUMOViewParent.h"
52 #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  new FXButton(v.getLocatorPopup(),
122  "\tLocate Vehicle\tLocate a person within the network.",
124  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
125  // for tls
126  new FXButton(v.getLocatorPopup(),
127  "\tLocate TLS\tLocate a tls within the network.",
129  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
130  // for additional stuff
131  new FXButton(v.getLocatorPopup(),
132  "\tLocate Additional\tLocate an additional structure within the network.",
134  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
135  // for pois
136  new FXButton(v.getLocatorPopup(),
137  "\tLocate PoI\tLocate a PoI within the network.",
139  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
140  // for polygons
141  new FXButton(v.getLocatorPopup(),
142  "\tLocate Polygon\tLocate a Polygon within the network.",
144  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
145 }
146 
147 
148 bool
149 GUIViewTraffic::setColorScheme(const std::string& name) {
150  if (!gSchemeStorage.contains(name)) {
151  return false;
152  }
153  if (myVisualizationChanger != 0) {
154  if (myVisualizationChanger->getCurrentScheme() != name) {
156  }
157  }
158  myVisualizationSettings = &gSchemeStorage.get(name.c_str());
160  update();
161  return true;
162 }
163 
164 
165 int
166 GUIViewTraffic::doPaintGL(int mode, const Boundary& bound) {
167  // init view settings
168  glRenderMode(mode);
169  glMatrixMode(GL_MODELVIEW);
170  glPushMatrix();
171  glDisable(GL_TEXTURE_2D);
172  glDisable(GL_ALPHA_TEST);
173  glDisable(GL_BLEND);
174  glEnable(GL_DEPTH_TEST);
175 
176  // draw decals (if not in grabbing mode)
177  if (!myUseToolTips) {
178  drawDecals();
180  paintGLGrid();
181  }
182  }
183 
184  glLineWidth(1);
185  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
186  float minB[2];
187  float maxB[2];
188  minB[0] = bound.xmin();
189  minB[1] = bound.ymin();
190  maxB[0] = bound.xmax();
191  maxB[1] = bound.ymax();
193  glEnable(GL_POLYGON_OFFSET_FILL);
194  glEnable(GL_POLYGON_OFFSET_LINE);
195  int hits2 = myGrid->Search(minB, maxB, *myVisualizationSettings);
196  //
197  if (myAdditionallyDrawn.size() > 0) {
198  glTranslated(0, 0, -.01);
200  for (std::map<GUIGlObject*, int>::iterator i = myAdditionallyDrawn.begin(); i != myAdditionallyDrawn.end(); ++i) {
201  (i->first)->drawGLAdditional(this, *myVisualizationSettings);
202  }
204  glTranslated(0, 0, .01);
205  }
206  glPopMatrix();
207  /*
208  // draw legends
209  glMatrixMode(GL_MODELVIEW);
210  glLoadIdentity();
211  glTranslated(1.-.2, 1.-.5, 0.);
212  glScaled(.2, .5, 1.);
213  GUIColoringSchemesMap<GUILane> &sm = GUIViewTraffic::getLaneSchemesMap(); //!!!
214  sm.getColorer(myVisualizationSettings->laneEdgeMode)->drawLegend();
215  */
216  return hits2;
217 }
218 
219 
220 void
222  myTrackedID = id;
223 }
224 
225 
226 void
228  myTrackedID = -1;
229 }
230 
231 
232 int
234  return myTrackedID;
235 }
236 
237 
238 void
241  const std::vector<MSTrafficLightLogic*>& logics = tlsControl.getAllLogics();
242  MSTrafficLightLogic* minTll = 0;
243  SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity();
244  for (std::vector<MSTrafficLightLogic*>::const_iterator i = logics.begin(); i != logics.end(); ++i) {
245  // get the logic
246  MSTrafficLightLogic* tll = (*i);
247  if (tlsControl.isActive(tll)) {
248  // get the links
249  const MSTrafficLightLogic::LaneVector& lanes = tll->getLanesAt(0);
250  if (lanes.size() > 0) {
251  const Position& endPos = lanes[0]->getShape().back();
252  if (endPos.distanceTo(pos) < minDist) {
253  minDist = endPos.distanceTo(pos);
254  minTll = tll;
255  }
256  }
257  }
258  }
259  if (minTll != 0) {
260  const MSTLLogicControl::TLSLogicVariants& vars = tlsControl.get(minTll->getID());
261  const std::vector<MSTrafficLightLogic*> logics = vars.getAllLogics();
262  if (logics.size() > 1) {
264  for (unsigned int i = 0; i < logics.size() - 1; ++i) {
265  if (minTll->getProgramID() == logics[i]->getProgramID()) {
266  l = (MSSimpleTrafficLightLogic*) logics[i + 1];
267  tlsControl.switchTo(minTll->getID(), l->getProgramID());
268  }
269  }
270  if (l == logics[0]) {
271  tlsControl.switchTo(minTll->getID(), l->getProgramID());
272  }
274  update();
275  }
276  }
277 }
278 
279 
280 SUMOTime
283 }
284 
285 
286 /****************************************************************************/
void paintGLGrid()
paints a grid
void changeStepAndDuration(MSTLLogicControl &tlcontrol, SUMOTime simStep, unsigned int step, SUMOTime stepDuration)
Changes the current phase and her duration.
bool isActive(const MSTrafficLightLogic *tl) const
Returns whether the given tls program is the currently active for his tls.
virtual void buildViewToolBars(GUIGlChildWindow &)
builds the view toolbars
Locate vehicle - button.
Definition: GUIAppEnum.h:165
GUICompleteSchemeStorage gSchemeStorage
Locate person - button.
Definition: GUIAppEnum.h:167
const SUMOReal SUMO_const_laneWidth
Definition: StdDefs.h:46
Storage for all programs of a single tls.
bool setColorScheme(const std::string &name)
void unlock()
release exclusive access to the simulation state
Definition: GUINet.cpp:512
SUMORTree * myGrid
The visualization speed-up.
void switchTo(const std::string &id, const std::string &programID)
Switches the named (id) tls to the named (programID) program.
Locate TLS - button.
Definition: GUIAppEnum.h:169
bool gaming
whether the application is in gaming mode or not
SUMOTime getCurrentTimeStep() const
get the current simulation time
SUMOReal ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:124
GUIMainWindow * myApp
The application.
Locate poi - button.
Definition: GUIAppEnum.h:173
SUMOReal xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:112
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
void lock()
grant exclusive access to the simulation state
Definition: GUINet.cpp:506
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:229
GUIDialog_ViewSettings * myVisualizationChanger
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:235
bool isGaming() const
return whether the gui is in gaming mode
Definition: GUIMainWindow.h:77
SUMOReal xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:118
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
A fixed traffic light logic.
SUMOReal scale
information about a lane's width (temporary, used for a single view)
A class that stores and controls tls and switching of their programs.
std::vector< MSTrafficLightLogic * > getAllLogics() const
Locate addtional structure - button.
Definition: GUIAppEnum.h:171
const std::string & getID() const
Returns the id.
Definition: Named.h:60
SUMOTime duration
The duration of the phase.
const std::vector< std::string > & getNames() const
Returns a list of stored settings names.
int getTrackedID() const
Returns the id of the tracked vehicle (-1 if none)
std::string name
The name of this setting.
std::map< GUIGlObject *, int > myAdditionallyDrawn
List of objects for which GUIGlObject::drawGLAdditional is called.
void setCurrentScheme(const std::string &)
Sets the named scheme as the current.
static GUINet * getGUIInstance()
Returns the pointer to the unique instance of GUINet (singleton).
Definition: GUINet.cpp:490
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:349
Locate edge - button.
Definition: GUIAppEnum.h:163
FXComboBox & getColoringSchemesCombo()
const LaneVector & getLanesAt(unsigned int i) const
Returns the list of lanes that are controlled by the signals at the given position.
bool contains(const std::string &name) const
Returns the information whether a setting with the given name is stored.
GUIVisualizationSettings & get(const std::string &name)
Returns the named scheme.
const MSPhaseDefinition & getPhase(unsigned int givenstep) const
Returns the definition of the phase from the given position within the plan.
void onGamingClick(Position pos)
handle mouse click in gaming mode
void startTrack(int id)
Starts vehicle tracking.
Locate junction - button.
Definition: GUIAppEnum.h:161
std::string getCurrentScheme() const
Returns the name of the currently chosen scheme.
A single child window which contains a view of the simulation area.
std::vector< MSLane * > LaneVector
Definition of the list of links that participate in this tl-light.
GUIVisualizationSettings * myVisualizationSettings
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:90
virtual ~GUIViewTraffic()
destructor
int doPaintGL(int mode, const Boundary &bound)
SUMOReal m2p(SUMOReal meter) const
meter-to-pixels conversion method
Locate polygons - button.
Definition: GUIAppEnum.h:175
int SUMOTime
Definition: SUMOTime.h:43
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
bool showGrid
Information whether a grid shall be shown.
void drawDecals()
Draws the stored decals.
virtual int Search(const float a_min[2], const float a_max[2], const GUIVisualizationSettings &c) const
Find all within search rectangle.
Definition: SUMORTree.h:120
The parent class for traffic light logics.
#define SUMOReal
Definition: config.h:218
static const bool gUseMesoSim
Definition: MSGlobals.h:102
const std::string & getProgramID() const
Returns this tl-logic's id.
SUMOReal ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:130
std::vector< MSTrafficLightLogic * > getAllLogics() const
Returns a vector which contains all logics.
static FXIcon * getIcon(GUIIcon which)
void stopTrack()
Stops vehicle tracking.
FXPopup * getLocatorPopup()