SUMO - Simulation of Urban MObility
GNEConnection.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A class for visualizing connections between lanes
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <string>
32 #include <iostream>
33 #include <utility>
34 #include <time.h>
40 #include <utils/common/ToString.h>
45 #include <utils/gui/div/GLHelper.h>
47 
48 #include "GNEConnection.h"
49 #include "GNEJunction.h"
50 #include "GNEEdge.h"
51 #include "GNELane.h"
52 #include "GNENet.h"
53 #include "GNEChange_Attribute.h"
54 #include "GNEUndoList.h"
55 #include "GNEViewNet.h"
56 #include "GNEInternalLane.h"
57 
58 #ifdef CHECK_MEMORY_LEAKS
59 #include <foreign/nvwa/debug_new.h>
60 #endif // CHECK_MEMORY_LEAKS
61 
62 
63 
64 // ===========================================================================
65 // static member definitions
66 // ===========================================================================
67 int NUM_POINTS = 5;
68 
69 // ===========================================================================
70 // method definitions
71 // ===========================================================================
72 
74  GNENetElement(from->getNet(), from->getMicrosimID() + " -> " + to->getMicrosimID(),
76  myFromLane(from),
77  myToLane(to),
78  myLinkState(LINKSTATE_TL_OFF_NOSIGNAL),
79  myDrawConnection(true) {
80  // geometry will be updated later
81 }
82 
83 
85 
86 
87 void
89  // Clear containers
90  myShapeRotations.clear();
91  myShapeLengths.clear();
92  // Get shape of from and to lanes
94  PositionVector laneShapeFrom;
95  if ((int)getEdgeFrom()->getNBEdge()->getLanes().size() > nbCon.fromLane) {
96  laneShapeFrom = getEdgeFrom()->getNBEdge()->getLanes().at(nbCon.fromLane).shape;
97  } else {
98  return;
99  }
100  PositionVector laneShapeTo;
101  if ((int)nbCon.toEdge->getLanes().size() > nbCon.toLane) {
102  laneShapeTo = nbCon.toEdge->getLanes().at(nbCon.toLane).shape;
103  } else {
104  return;
105  }
106  // Calculate shape of connection depending of the size of Junction shape
107  if (getEdgeFrom()->getNBEdge()->getToNode()->getShape().area() > 4) { // value obtanied from GNEJunction::drawgl
108  // Calculate shape using a smooth shape
110  laneShapeFrom,
111  laneShapeTo,
112  NUM_POINTS, getEdgeFrom()->getNBEdge()->getTurnDestination() == nbCon.toEdge,
113  (SUMOReal) 5. * (SUMOReal) getEdgeFrom()->getNBEdge()->getNumLanes(),
114  (SUMOReal) 5. * (SUMOReal) nbCon.toEdge->getNumLanes());
115 
116  } else {
117  myShape.clear();
118  myShape.push_back(laneShapeFrom.positionAtOffset(laneShapeFrom.length() - 1));
119  myShape.push_back(laneShapeTo.positionAtOffset(1));
120  }
121 
122  // Obtain lenghts and shape rotations
123  int segments = (int) myShape.size() - 1;
124  if (segments >= 0) {
125  myShapeRotations.reserve(segments);
126  myShapeLengths.reserve(segments);
127  for (int i = 0; i < segments; ++i) {
128  const Position& f = myShape[i];
129  const Position& s = myShape[i + 1];
130  myShapeLengths.push_back(f.distanceTo2D(s));
131  myShapeRotations.push_back((SUMOReal) atan2((s.x() - f.x()), (f.y() - s.y())) * (SUMOReal) 180.0 / (SUMOReal) PI);
132  }
133  }
134 }
135 
136 
137 Boundary
139  return myShape.getBoxBoundary();
140 }
141 
142 
143 GNEEdge*
145  return &(myFromLane->getParentEdge());
146 }
147 
148 
149 GNEEdge*
151  return &(myToLane->getParentEdge());
152 }
153 
154 
155 GNELane*
157  return myFromLane;
158 }
159 
160 
161 GNELane*
163  return myToLane;
164 }
165 
166 
167 int
169  return myFromLane->getIndex();
170 }
171 
172 
173 int
175  return myToLane->getIndex();
176 }
177 
178 
182 }
183 
184 
187  return NBConnection(getEdgeFrom()->getNBEdge(), getFromLaneIndex(),
188  getEdgeTo()->getNBEdge(), getToLaneIndex(),
189  (int)getNBEdgeConnection().tlLinkNo);
190 }
191 
192 
193 LinkState
195  return myLinkState;
196 }
197 
198 
199 void
203  nbCon.toEdge,
204  nbCon.fromLane,
205  nbCon.toLane,
206  nbCon.mayDefinitelyPass,
207  nbCon.tlID);
208 }
209 
210 
211 bool
213  return myDrawConnection;
214 }
215 
216 
217 void
218 GNEConnection::setDrawConnection(bool drawConnection) {
219  myDrawConnection = drawConnection;
220 }
221 
222 
225  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
226  buildPopupHeader(ret, app);
230  buildPositionCopyEntry(ret, false);
231  // let the GNEViewNet store the popup position
232  (dynamic_cast<GNEViewNet&>(parent)).markPopupPosition();
233  return ret;
234 }
235 
236 
239  // Currently ignored before implementation to avoid warnings
240  UNUSED_PARAMETER(app);
241  UNUSED_PARAMETER(parent);
242  return NULL;
243 }
244 
245 
246 Boundary
248  return Boundary();
249 }
250 
251 
252 void
254  // Check if connection must be drawed
256  // Push draw matrix 1
257  glPushMatrix();
258  // Push name
259  glPushName(getGlID());
260  // Traslate matrix
261  glTranslated(0, 0, GLO_JUNCTION + 0.1); // must draw on top of junction
262  // Set color
264  // override with special colors (unless the color scheme is based on selection)
266  } else {
267  // Set color depending of the link state
269  }
270  // draw connection checking whether it is not too small
271  if (s.scale < 1.) {
272  // If it's small, dra a simple line
274  } else {
275  // draw a list of lines
277  }
278  // Pop name
279  glPopName();
280  // Pop draw matrix 1
281  glPopMatrix();
282  }
283 }
284 
285 
286 std::string
288  if (key == SUMO_ATTR_ID) {
289  // used by GNEReferenceCounter
290  // @note: may be called for connections without a valid nbCon reference
291  return getMicrosimID();
292  }
294  switch (key) {
295  case SUMO_ATTR_FROM:
296  return getEdgeFrom()->getID();
297  case SUMO_ATTR_TO:
298  return nbCon.toEdge->getID();
299  case SUMO_ATTR_FROM_LANE:
300  return toString(nbCon.toLane);
301  case SUMO_ATTR_TO_LANE:
302  return toString(nbCon.toLane);
303  case SUMO_ATTR_PASS:
304  return toString(nbCon.mayDefinitelyPass);
306  return toString(nbCon.keepClear);
307  case SUMO_ATTR_CONTPOS:
308  return toString(nbCon.contPos);
310  return toString(!getEdgeFrom()->getNBEdge()->mayBeTLSControlled(nbCon.fromLane, nbCon.toEdge, nbCon.toLane));
312  return toString(nbCon.visibility);
313  default:
314  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
315  }
316 }
317 
318 
319 void
320 GNEConnection::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
321  switch (key) {
322  case SUMO_ATTR_FROM:
323  case SUMO_ATTR_TO:
324  case SUMO_ATTR_FROM_LANE:
325  case SUMO_ATTR_TO_LANE:
326  case SUMO_ATTR_PASS:
328  case SUMO_ATTR_CONTPOS:
331  // no special handling
332  undoList->p_add(new GNEChange_Attribute(this, key, value));
333  break;
334  default:
335  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
336  }
337 }
338 
339 
340 bool
341 GNEConnection::isValid(SumoXMLAttr key, const std::string& value) {
342  // Currently ignored before implementation to avoid warnings
343  switch (key) {
344  case SUMO_ATTR_FROM:
345  case SUMO_ATTR_TO:
346  case SUMO_ATTR_FROM_LANE:
347  case SUMO_ATTR_TO_LANE:
348  return false;
349  case SUMO_ATTR_PASS:
350  return canParse<bool>(value);
352  return canParse<bool>(value);
353  case SUMO_ATTR_CONTPOS:
354  return canParse<SUMOReal>(value);
356  return false; // XXX see #2599
357  //return canParse<bool>(value);
359  return isPositive<SUMOReal>(value);
360  default:
361  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
362  }
363 }
364 
365 
366 void
367 GNEConnection::setAttribute(SumoXMLAttr key, const std::string& value) {
369  switch (key) {
370  case SUMO_ATTR_PASS:
371  nbCon.mayDefinitelyPass = parse<bool>(value);
372  break;
374  nbCon.keepClear = parse<bool>(value);
375  break;
376  /*
377  case SUMO_ATTR_UNCONTROLLED:
378  // XXX see @2599
379  break;
380  */
381  case SUMO_ATTR_CONTPOS:
382  nbCon.contPos = parse<SUMOReal>(value);
383  break;
385  nbCon.visibility = parse<SUMOReal>(value);
386  break;
387  default:
388  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
389  }
390 }
391 
392 
393 /****************************************************************************/
int NUM_POINTS
void updateGeometry()
update pre-computed geometry information
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:157
int getFromLaneIndex() const
get lane index of the incoming lane
int toLane
The lane the connections yields in.
Definition: NBEdge.h:182
bool isValid(SumoXMLAttr key, const std::string &value)
Whether vehicles must keep the junction clear.
GNENet * myNet
the net to inform about updates
int getToLaneIndex() const
get lane index of the outgoing lane
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
NBEdge * toEdge
The edge the connections yields in.
Definition: NBEdge.h:179
bool myDrawConnection
Enable or disable draw connection.
Boundary getBoundary() const
Returns the street&#39;s geometry.
void setDrawConnection(bool drawConnection)
enable or disable draw connection
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:559
Stores the information about how to visualize structures.
connectio between two lanes
a connection
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
foe visibility distance of a link
static RGBColor colorForLinksState(FXuint state)
return the color for each linkstate
static void drawBoxLines(const PositionVector &geom, const std::vector< SUMOReal > &rots, const std::vector< SUMOReal > &lengths, SUMOReal width, int cornerDetail=0, SUMOReal offset=0)
Draws thick lines.
Definition: GLHelper.cpp:176
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
Definition: NBEdge.h:191
GNELane * myFromLane
incoming lane of this connection
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
GNEEdge * getEdgeFrom() const
get the name of the edge the vehicles leave
The link is controlled by a tls which is off, not blinking, may pass.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used, also builds an entry for copying the geo-position.
std::vector< SUMOReal > myShapeRotations
int getIndex() const
returns the index of the lane
Definition: GNELane.cpp:659
GUIGlID getGlID() const
Returns the numerical id of the object.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:38
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
GNELane * getLaneFrom() const
get lane of the incoming lane
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
bool keepClear
whether the junction must be kept clear when using this connection
Definition: NBEdge.h:194
NBConnection getNBConnection() const
get NBConnection
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
const std::string & getID() const
Returns the id.
Definition: Named.h:66
std::vector< SUMOReal > myShapeLengths
The lengths of the shape parts.
PositionVector myShape
the shape of the connection
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
GNEEdge * getEdgeTo() const
get the name of the edge the vehicles may reach when leaving "from"
#define PI
Definition: polyfonts.c:61
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:443
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1027
LinkState myLinkState
Linkstate.
std::string tlID
The id of the traffic light that controls this connection.
Definition: NBEdge.h:185
int fromLane
The lane the connections starts at.
Definition: NBEdge.h:176
GNEConnection(GNELane *from, GNELane *to)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
friend class GNEChange_Attribute
declare friend class
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:402
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
SUMOReal contPos
custom position for internal junction on this connection
Definition: NBEdge.h:197
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
LinkState getLinkState() const
get LinkState
GNELane * myToLane
outgoing lane of this connection
LinkState getLinkState(const NBEdge *incoming, NBEdge *outgoing, int fromLane, int toLane, bool mayDefinitelyPass, const std::string &tlID) const
get link state
Definition: NBNode.cpp:1617
~GNEConnection()
Destructor.
GUIColorer junctionColorer
The junction colorer.
bool getDrawConnection() const
get Draw connection
const std::string getID() const
function to support debugging
NBEdge::Connection & getNBEdgeConnection() const
get Edge::Connection
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:54
SUMOReal length() const
Returns the length.
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:423
PositionVector computeSmoothShape(const PositionVector &begShape, const PositionVector &endShape, int numPoints, bool isTurnaround, SUMOReal extrapolateBeg, SUMOReal extrapolateEnd, NBNode *recordError=0) const
Compute a smooth curve between the given geometries.
Definition: NBNode.cpp:465
bool showConnections()
show connections over junctions
Definition: GNEViewNet.cpp:357
static const RGBColor selectedConnectionColor
color of selected connection
Definition: GNENet.h:102
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
The popup menu of a globject.
GNELane * getLaneTo() const
get lane of the outgoing lane
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
SUMOReal distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:250
static void drawLine(const Position &beg, SUMOReal rot, SUMOReal visLength)
Draws a thin line.
Definition: GLHelper.cpp:269
SumoXMLTag getTag() const
get XML Tag assigned to this object
#define SUMOReal
Definition: config.h:208
void updateLinkState()
recompute cached myLinkState
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:258
std::string getAttribute(SumoXMLAttr key) const
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
GUISelectedStorage gSelected
A global holder of selected objects.
A window containing a gl-object&#39;s parameter.
Connection & getConnectionRef(int fromLane, const NBEdge *to, int toLane)
Returns reference to the specified connection This method goes through "myConnections" and returns th...
Definition: NBEdge.cpp:962
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1114
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
SUMOReal visibility
custom foe visiblity for connection
Definition: NBEdge.h:200
a junction