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-2016 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(),
75  std::string(":") + from->getMicrosimID() + "->" + to->getMicrosimID(),
77  myFromLane(from),
78  myToLane(to),
79  myLinkState(LINKSTATE_TL_OFF_NOSIGNAL),
80  myDrawConnection(true) {
81  // geometry will be updated later
82 }
83 
84 
86 
87 
88 void
90  // Clear containers
91  myShapeRotations.clear();
92  myShapeLengths.clear();
93  // Get shape of from and to lanes
95  PositionVector laneShapeFrom;
96  if ((int)getEdgeFrom()->getNBEdge()->getLanes().size() > nbCon.fromLane) {
97  laneShapeFrom = getEdgeFrom()->getNBEdge()->getLanes().at(nbCon.fromLane).shape;
98  } else {
99  return;
100  }
101  PositionVector laneShapeTo;
102  if ((int)nbCon.toEdge->getLanes().size() > nbCon.toLane) {
103  laneShapeTo = nbCon.toEdge->getLanes().at(nbCon.toLane).shape;
104  } else {
105  return;
106  }
107  // Calculate shape of connection depending of the size of Junction shape
108  if (getEdgeFrom()->getNBEdge()->getToNode()->getShape().area() > 4) { // value obtanied from GNEJunction::drawgl
109  // Calculate shape using a smooth shape
111  laneShapeFrom,
112  laneShapeTo,
113  NUM_POINTS, getEdgeFrom()->getNBEdge()->getTurnDestination() == nbCon.toEdge,
114  (SUMOReal) 5. * (SUMOReal) getEdgeFrom()->getNBEdge()->getNumLanes(),
115  (SUMOReal) 5. * (SUMOReal) nbCon.toEdge->getNumLanes());
116 
117  } else {
118  myShape.clear();
119  myShape.push_back(laneShapeFrom.positionAtOffset(laneShapeFrom.length() - 1));
120  myShape.push_back(laneShapeTo.positionAtOffset(1));
121  }
122 
123  // Obtain lenghts and shape rotations
124  int segments = (int) myShape.size() - 1;
125  if (segments >= 0) {
126  myShapeRotations.reserve(segments);
127  myShapeLengths.reserve(segments);
128  for (int i = 0; i < segments; ++i) {
129  const Position& f = myShape[i];
130  const Position& s = myShape[i + 1];
131  myShapeLengths.push_back(f.distanceTo2D(s));
132  myShapeRotations.push_back((SUMOReal) atan2((s.x() - f.x()), (f.y() - s.y())) * (SUMOReal) 180.0 / (SUMOReal) PI);
133  }
134  }
135 }
136 
137 
138 Boundary
140  return myShape.getBoxBoundary();
141 }
142 
143 
144 GNEEdge*
146  return &(myFromLane->getParentEdge());
147 }
148 
149 
150 GNEEdge*
152  return &(myToLane->getParentEdge());
153 }
154 
155 
156 GNELane*
158  return myFromLane;
159 }
160 
161 
162 GNELane*
164  return myToLane;
165 }
166 
167 
168 int
170  return myFromLane->getIndex();
171 }
172 
173 
174 int
176  return myToLane->getIndex();
177 }
178 
179 
183 }
184 
185 
188  return NBConnection(getEdgeFrom()->getNBEdge(), getFromLaneIndex(),
189  getEdgeTo()->getNBEdge(), getToLaneIndex(),
190  (int)getNBEdgeConnection().tlLinkNo);
191 }
192 
193 
194 LinkState
196  return myLinkState;
197 }
198 
199 
200 void
204  nbCon.toEdge,
205  nbCon.fromLane,
206  nbCon.toLane,
207  nbCon.mayDefinitelyPass,
208  nbCon.tlID);
209 }
210 
211 
212 bool
214  return myDrawConnection;
215 }
216 
217 
218 void
219 GNEConnection::setDrawConnection(bool drawConnection) {
220  myDrawConnection = drawConnection;
221 }
222 
223 
226  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
227  buildPopupHeader(ret, app);
231  buildPositionCopyEntry(ret, false);
232  // let the GNEViewNet store the popup position
233  (dynamic_cast<GNEViewNet&>(parent)).markPopupPosition();
234  return ret;
235 }
236 
237 
240  // Currently ignored before implementation to avoid warnings
241  UNUSED_PARAMETER(app);
242  UNUSED_PARAMETER(parent);
243  return NULL;
244 }
245 
246 
247 Boundary
249  return Boundary();
250 }
251 
252 
253 void
255  // Check if connection must be drawed
257  // Push draw matrix 1
258  glPushMatrix();
259  // Push name
260  glPushName(getGlID());
261  // Traslate matrix
262  glTranslated(0, 0, GLO_JUNCTION + 0.1); // must draw on top of junction
263  // Set color
265  // override with special colors (unless the color scheme is based on selection)
267  } else {
268  // Set color depending of the link state
270  }
271  // draw connection checking whether it is not too small
272  if (s.scale < 1.) {
273  // If it's small, dra a simple line
275  } else {
276  // draw a list of lines
278  }
279  // Pop name
280  glPopName();
281  // Pop draw matrix 1
282  glPopMatrix();
283  }
284 }
285 
286 
287 std::string
289  if (key == SUMO_ATTR_ID) {
290  // used by GNEReferenceCounter
291  // @note: may be called for connections without a valid nbCon reference
292  return getMicrosimID();
293  }
295  switch (key) {
296  case SUMO_ATTR_FROM:
297  return getEdgeFrom()->getID();
298  case SUMO_ATTR_TO:
299  return nbCon.toEdge->getID();
300  case SUMO_ATTR_FROM_LANE:
301  return toString(nbCon.toLane);
302  case SUMO_ATTR_TO_LANE:
303  return toString(nbCon.toLane);
304  case SUMO_ATTR_PASS:
305  return toString(nbCon.mayDefinitelyPass);
307  return toString(nbCon.keepClear);
308  case SUMO_ATTR_CONTPOS:
309  return toString(nbCon.contPos);
311  return toString(!getEdgeFrom()->getNBEdge()->mayBeTLSControlled(nbCon.fromLane, nbCon.toEdge, nbCon.toLane));
313  return toString(nbCon.visibility);
314  default:
315  throw InvalidArgument("connection attribute '" + toString(key) + "' not allowed");
316  }
317 }
318 
319 
320 void
321 GNEConnection::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
322  switch (key) {
323  case SUMO_ATTR_FROM:
324  case SUMO_ATTR_TO:
325  case SUMO_ATTR_FROM_LANE:
326  case SUMO_ATTR_TO_LANE:
327  case SUMO_ATTR_PASS:
329  case SUMO_ATTR_CONTPOS:
332  // no special handling
333  undoList->p_add(new GNEChange_Attribute(this, key, value));
334  break;
335  default:
336  throw InvalidArgument("connection attribute '" + toString(key) + "' not allowed");
337  }
338 }
339 
340 
341 bool
342 GNEConnection::isValid(SumoXMLAttr key, const std::string& value) {
343  // Currently ignored before implementation to avoid warnings
344  switch (key) {
345  case SUMO_ATTR_FROM:
346  case SUMO_ATTR_TO:
347  case SUMO_ATTR_FROM_LANE:
348  case SUMO_ATTR_TO_LANE:
349  return false;
350  case SUMO_ATTR_PASS:
351  return canParse<bool>(value);
353  return canParse<bool>(value);
354  case SUMO_ATTR_CONTPOS:
355  return canParse<SUMOReal>(value);
357  return false; // XXX see #2599
358  //return canParse<bool>(value);
360  return isPositive<SUMOReal>(value);
361  default:
362  throw InvalidArgument("connection attribute '" + toString(key) + "' not allowed");
363  }
364 }
365 
366 
367 void
368 GNEConnection::setAttribute(SumoXMLAttr key, const std::string& value) {
370  switch (key) {
371  case SUMO_ATTR_PASS:
372  nbCon.mayDefinitelyPass = parse<bool>(value);
373  break;
375  nbCon.keepClear = parse<bool>(value);
376  break;
377  /*
378  case SUMO_ATTR_UNCONTROLLED:
379  // XXX see @2599
380  break;
381  */
382  case SUMO_ATTR_CONTPOS:
383  nbCon.contPos = parse<SUMOReal>(value);
384  break;
386  nbCon.visibility = parse<SUMOReal>(value);
387  break;
388  default:
389  throw InvalidArgument("connection attribute '" + toString(key) + "' not allowed");
390  }
391 }
392 
393 
394 /****************************************************************************/
int NUM_POINTS
void updateGeometry()
update pre-computed geometry information
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:157
LinkState getLinkState(const NBEdge *incoming, NBEdge *outgoing, int fromLane, int toLane, bool mayDefinitelyPass, const std::string &tlID) const
Definition: NBNode.cpp:1619
int toLane
The lane the connections yields in.
Definition: NBEdge.h:178
bool isValid(SumoXMLAttr key, const std::string &value)
Whether vehicles must keep the junction clear.
GNENet * myNet
the net to inform about updates
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:175
bool myDrawConnection
Enable or disable draw connection.
LinkState getLinkState() const
get LinkState
SUMOReal length() const
Returns the length.
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:475
void setDrawConnection(bool drawConnection)
enable or disable draw connection
Stores the information about how to visualize structures.
bool getDrawConnection() const
get Draw connection
a connection
foe visibility distance of a link
static RGBColor colorForLinksState(FXuint state)
return the color for each linkstate
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
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:55
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:552
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
Definition: NBEdge.h:187
GNELane * myFromLane
incoming lane of this connection
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
const std::string & getID() const
Returns the id.
Definition: Named.h:66
The link is controlled by a tls which is off, not blinking, may pass.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
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
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
GNEEdge * getEdgeTo() const
get the name of the edge the vehicles may reach when leaving "from"
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
SUMOReal distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:232
bool keepClear
whether the junction must be kept clear when using this connection
Definition: NBEdge.h:190
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
NBEdge::Connection & getNBEdgeConnection() const
get Edge::Connection
std::vector< SUMOReal > myShapeLengths
The lengths of the shape parts.
int getFromLaneIndex() const
get lane index of the incoming lane
int getToLaneIndex() const
get lane index of the outgoing lane
PositionVector myShape
the shape of the connection
int getIndex() const
returns the index of the lane
Definition: GNELane.cpp:663
#define PI
Definition: polyfonts.c:61
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
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:1061
LinkState myLinkState
Linkstate.
std::string tlID
The id of the traffic light that controls this connection.
Definition: NBEdge.h:181
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:395
int fromLane
The lane the connections starts at.
Definition: NBEdge.h:172
GNEConnection(GNELane *from, GNELane *to)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
GNELane * getLaneTo() const
get lane of the outgoing lane
A list of positions.
GNEEdge * getEdgeFrom() const
get the name of the edge the vehicles leave
friend class GNEChange_Attribute
declare friend class
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:193
Boundary getBoundary() const
Returns the street&#39;s geometry.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
GNELane * myToLane
outgoing lane of this connection
~GNEConnection()
Destructor.
GUIColorer junctionColorer
The junction colorer.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
const std::string getID() const
function to support debugging
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:55
NBConnection getNBConnection() const
get NBConnection
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
bool showConnections()
show connections over junctions
Definition: GNEViewNet.cpp:328
static const RGBColor selectedConnectionColor
color of selected connection
Definition: GNENet.h:102
The popup menu of a globject.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
std::string getAttribute(SumoXMLAttr key) const
GUIGlID getGlID() const
Returns the numerical id of the object.
static void drawLine(const Position &beg, SUMOReal rot, SUMOReal visLength)
Draws a thin line.
Definition: GLHelper.cpp:269
#define SUMOReal
Definition: config.h:213
void updateLinkState()
recompute cached myLinkState
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:261
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
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:938
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:416
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1082
SUMOReal visibility
custom foe visiblity for connection
Definition: NBEdge.h:196
a junction