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>
49 #include <utils/common/RGBColor.h>
51 #include <utils/shapes/Polygon.h>
52 #include "GUISUMOViewParent.h"
53 #include "GUIViewTraffic.h"
66 #include <utils/gui/div/GLHelper.h>
68 
69 #ifdef CHECK_MEMORY_LEAKS
70 #include <foreign/nvwa/debug_new.h>
71 #endif // CHECK_MEMORY_LEAKS
72 
73 /* -------------------------------------------------------------------------
74  * GUIViewTraffic - FOX callback mapping
75  * ----------------------------------------------------------------------- */
76 FXDEFMAP(GUIViewTraffic) GUIViewTrafficMap[] = {
77  FXMAPFUNC(SEL_COMMAND, MID_CLOSE_LANE, GUIViewTraffic::onCmdCloseLane),
78  FXMAPFUNC(SEL_COMMAND, MID_CLOSE_EDGE, GUIViewTraffic::onCmdCloseEdge),
79  FXMAPFUNC(SEL_COMMAND, MID_ADD_REROUTER, GUIViewTraffic::onCmdAddRerouter),
80 };
81 
82 
83 FXIMPLEMENT_ABSTRACT(GUIViewTraffic, GUISUMOAbstractView, GUIViewTrafficMap, ARRAYNUMBER(GUIViewTrafficMap))
84 
85 
86 // ===========================================================================
87 // member method definitions
88 // ===========================================================================
90  FXComposite* p,
91  GUIMainWindow& app,
92  GUISUMOViewParent* parent,
93  GUINet& net, FXGLVisual* glVis,
94  FXGLCanvas* share) :
95  GUISUMOAbstractView(p, app, parent, net.getVisualisationSpeedUp(), glVis, share),
96  myTrackedID(-1) {}
97 
98 
100 }
101 
102 
103 void
105  // build coloring tools
106  {
107  const std::vector<std::string>& names = gSchemeStorage.getNames();
108  for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i) {
109  v.getColoringSchemesCombo().appendItem((*i).c_str());
110  if ((*i) == myVisualizationSettings->name) {
111  v.getColoringSchemesCombo().setCurrentItem(v.getColoringSchemesCombo().getNumItems() - 1);
112  }
113  }
114  v.getColoringSchemesCombo().setNumVisible(5);
115  }
116  // for junctions
117  new FXButton(v.getLocatorPopup(),
118  "\tLocate Junction\tLocate a junction within the network.",
120  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
121  // for edges
122  new FXButton(v.getLocatorPopup(),
123  "\tLocate Street\tLocate a street within the network.",
125  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
126 
127  // for vehicles
128  new FXButton(v.getLocatorPopup(),
129  "\tLocate Vehicle\tLocate a vehicle within the network.",
131  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
132 
133  // for persons
134  if (!MSGlobals::gUseMesoSim) { // there are no persons in mesosim (yet)
135  new FXButton(v.getLocatorPopup(),
136  "\tLocate Vehicle\tLocate a person within the network.",
138  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
139  }
140 
141  // for tls
142  new FXButton(v.getLocatorPopup(),
143  "\tLocate TLS\tLocate a tls within the network.",
145  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
146  // for additional stuff
147  new FXButton(v.getLocatorPopup(),
148  "\tLocate Additional\tLocate an additional structure within the network.",
150  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
151  // for pois
152  new FXButton(v.getLocatorPopup(),
153  "\tLocate PoI\tLocate a PoI within the network.",
155  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
156  // for polygons
157  new FXButton(v.getLocatorPopup(),
158  "\tLocate Polygon\tLocate a Polygon within the network.",
160  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
161 }
162 
163 
164 bool
165 GUIViewTraffic::setColorScheme(const std::string& name) {
166  if (!gSchemeStorage.contains(name)) {
167  return false;
168  }
169  if (myVisualizationChanger != 0) {
170  if (myVisualizationChanger->getCurrentScheme() != name) {
172  }
173  }
174  myVisualizationSettings = &gSchemeStorage.get(name.c_str());
176  update();
177  return true;
178 }
179 
180 
181 int
182 GUIViewTraffic::doPaintGL(int mode, const Boundary& bound) {
183  // init view settings
184  glRenderMode(mode);
185  glMatrixMode(GL_MODELVIEW);
186  glPushMatrix();
187  glDisable(GL_TEXTURE_2D);
188  glDisable(GL_ALPHA_TEST);
189  glDisable(GL_BLEND);
190  glEnable(GL_DEPTH_TEST);
191 
192  // draw decals (if not in grabbing mode)
193  if (!myUseToolTips) {
194  drawDecals();
196  paintGLGrid();
197  }
198  }
199 
200  glLineWidth(1);
201  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
202  float minB[2];
203  float maxB[2];
204  minB[0] = bound.xmin();
205  minB[1] = bound.ymin();
206  maxB[0] = bound.xmax();
207  maxB[1] = bound.ymax();
209  glEnable(GL_POLYGON_OFFSET_FILL);
210  glEnable(GL_POLYGON_OFFSET_LINE);
211  int hits2 = myGrid->Search(minB, maxB, *myVisualizationSettings);
212  //
213  if (myAdditionallyDrawn.size() > 0) {
214  glTranslated(0, 0, -.01);
216  for (std::map<GUIGlObject*, int>::iterator i = myAdditionallyDrawn.begin(); i != myAdditionallyDrawn.end(); ++i) {
217  (i->first)->drawGLAdditional(this, *myVisualizationSettings);
218  }
220  glTranslated(0, 0, .01);
221  }
222  glPopMatrix();
223  /*
224  // draw legends
225  glMatrixMode(GL_MODELVIEW);
226  glLoadIdentity();
227  glTranslated(1.-.2, 1.-.5, 0.);
228  glScaled(.2, .5, 1.);
229  GUIColoringSchemesMap<GUILane> &sm = GUIViewTraffic::getLaneSchemesMap(); //!!!
230  sm.getColorer(myVisualizationSettings->laneEdgeMode)->drawLegend();
231  */
232  return hits2;
233 }
234 
235 
236 void
238  myTrackedID = id;
239 }
240 
241 
242 void
244  myTrackedID = -1;
245 }
246 
247 
248 int
250  return myTrackedID;
251 }
252 
253 
254 void
257  const std::vector<MSTrafficLightLogic*>& logics = tlsControl.getAllLogics();
258  MSTrafficLightLogic* minTll = 0;
259  SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity();
260  for (std::vector<MSTrafficLightLogic*>::const_iterator i = logics.begin(); i != logics.end(); ++i) {
261  // get the logic
262  MSTrafficLightLogic* tll = (*i);
263  if (tlsControl.isActive(tll)) {
264  // get the links
265  const MSTrafficLightLogic::LaneVector& lanes = tll->getLanesAt(0);
266  if (lanes.size() > 0) {
267  const Position& endPos = lanes[0]->getShape().back();
268  if (endPos.distanceTo(pos) < minDist) {
269  minDist = endPos.distanceTo(pos);
270  minTll = tll;
271  }
272  }
273  }
274  }
275  if (minTll != 0) {
276  const MSTLLogicControl::TLSLogicVariants& vars = tlsControl.get(minTll->getID());
277  const std::vector<MSTrafficLightLogic*> logics = vars.getAllLogics();
278  if (logics.size() > 1) {
280  for (unsigned int i = 0; i < logics.size() - 1; ++i) {
281  if (minTll->getProgramID() == logics[i]->getProgramID()) {
282  l = (MSSimpleTrafficLightLogic*) logics[i + 1];
283  tlsControl.switchTo(minTll->getID(), l->getProgramID());
284  }
285  }
286  if (l == logics[0]) {
287  tlsControl.switchTo(minTll->getID(), l->getProgramID());
288  }
290  update();
291  }
292  }
293 }
294 
295 
296 SUMOTime
299 }
300 
301 
302 GUILane*
304  if (makeCurrent()) {
305  unsigned int id = getObjectUnderCursor();
306  if (id != 0) {
308  if (o != 0) {
309  return dynamic_cast<GUILane*>(o);
310  }
311  }
312  makeNonCurrent();
313  }
314  return 0;
315 }
316 
317 long
318 GUIViewTraffic::onCmdCloseLane(FXObject*, FXSelector, void*) {
319  GUILane* lane = getLaneUnderCursor();
320  if (lane != 0) {
321  lane->closeTraffic();
323  update();
324  }
325  return 1;
326 }
327 
328 
329 long
330 GUIViewTraffic::onCmdCloseEdge(FXObject*, FXSelector, void*) {
331  GUILane* lane = getLaneUnderCursor();
332  if (lane != 0) {
333  dynamic_cast<GUIEdge*>(&lane->getEdge())->closeTraffic(lane);
335  update();
336  }
337  return 1;
338 }
339 
340 long
341 GUIViewTraffic::onCmdAddRerouter(FXObject*, FXSelector, void*) {
342  GUILane* lane = getLaneUnderCursor();
343  if (lane != 0) {
344  dynamic_cast<GUIEdge*>(&lane->getEdge())->addRerouter();
346  update();
347  }
348  return 1;
349 }
350 
351 /****************************************************************************/
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
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:461
Locate vehicle - button.
Definition: GUIAppEnum.h:167
GUICompleteSchemeStorage gSchemeStorage
long onCmdCloseLane(FXObject *, FXSelector, void *)
interaction with the simulation
long long int SUMOTime
Definition: SUMOTime.h:43
Locate person - button.
Definition: GUIAppEnum.h:169
const SUMOReal SUMO_const_laneWidth
Definition: StdDefs.h:49
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:528
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:171
void closeTraffic(bool rebuildAllowed=true)
close this lane for traffic
Definition: GUILane.cpp:1012
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:175
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:162
void lock()
grant exclusive access to the simulation state
Definition: GUINet.cpp:522
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:221
GUIDialog_ViewSettings * myVisualizationChanger
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:255
bool isGaming() const
return whether the gui is in gaming mode
Definition: GUIMainWindow.h:84
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:123
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&#39;s width (temporary, used for a single view)
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:70
A class that stores and controls tls and switching of their programs.
std::vector< MSTrafficLightLogic * > getAllLogics() const
Locate addtional structure - button.
Definition: GUIAppEnum.h:173
A road/street connecting two junctions (gui-version)
Definition: GUIEdge.h:62
const std::string & getID() const
Returns the id.
Definition: Named.h:65
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:506
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
long onCmdAddRerouter(FXObject *, FXSelector, void *)
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:369
Locate edge - button.
Definition: GUIAppEnum.h:165
long onCmdCloseEdge(FXObject *, FXSelector, void *)
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.
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
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:163
std::string getCurrentScheme() const
Returns the name of the currently chosen scheme.
FXDEFMAP(GUIViewTraffic) GUIViewTrafficMap[]
A single child window which contains a view of the simulation area.
FXbool makeCurrent()
A reimplementation due to some internal reasons.
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:91
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:177
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:214
static const bool gUseMesoSim
Definition: MSGlobals.h:102
const std::string & getProgramID() const
Returns this tl-logic&#39;s id.
SUMOReal ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:130
void unblockObject(GUIGlID id)
Marks an object as unblocked.
std::vector< MSTrafficLightLogic * > getAllLogics() const
Returns a vector which contains all logics.
GUIGlID getObjectUnderCursor()
returns the id of the object under the cursor using GL_SELECT
GUIGlObject * getObjectBlocking(GUIGlID id)
Returns the object from the container locking it.
static FXIcon * getIcon(GUIIcon which)
void stopTrack()
Stops vehicle tracking.
GUILane * getLaneUnderCursor()
FXPopup * getLocatorPopup()