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 
59 
60 // ===========================================================================
61 // static member definitions
62 // ===========================================================================
63 int NUM_POINTS = 5;
64 
65 // ===========================================================================
66 // method definitions
67 // ===========================================================================
68 
70  GNENetElement(from->getNet(), "from" + from->getMicrosimID() + "to" + to->getMicrosimID(),
72  myFromLane(from),
73  myToLane(to),
74  myLinkState(LINKSTATE_TL_OFF_NOSIGNAL) {
75  // geometry will be updated later
76 }
77 
78 
80 
81 
82 void
84  // Clear containers
85  myShapeRotations.clear();
86  myShapeLengths.clear();
87  // Get shape of from and to lanes
89  PositionVector laneShapeFrom;
90  if ((int)getEdgeFrom()->getNBEdge()->getLanes().size() > nbCon.fromLane) {
91  laneShapeFrom = getEdgeFrom()->getNBEdge()->getLanes().at(nbCon.fromLane).shape;
92  } else {
93  return;
94  }
95  PositionVector laneShapeTo;
96  if ((int)nbCon.toEdge->getLanes().size() > nbCon.toLane) {
97  laneShapeTo = nbCon.toEdge->getLanes().at(nbCon.toLane).shape;
98  } else {
99  return;
100  }
101  // Calculate shape of connection depending of the size of Junction shape
102  if (getEdgeFrom()->getNBEdge()->getToNode()->getShape().area() > 4) { // value obtanied from GNEJunction::drawgl
103  // Calculate shape using a smooth shape
105  laneShapeFrom,
106  laneShapeTo,
107  NUM_POINTS, getEdgeFrom()->getNBEdge()->getTurnDestination() == nbCon.toEdge,
108  (double) 5. * (double) getEdgeFrom()->getNBEdge()->getNumLanes(),
109  (double) 5. * (double) nbCon.toEdge->getNumLanes());
110 
111  } else {
112  myShape.clear();
113  myShape.push_back(laneShapeFrom.positionAtOffset(laneShapeFrom.length() - 1));
114  myShape.push_back(laneShapeTo.positionAtOffset(1));
115  }
116 
117  // Obtain lengths and shape rotations
118  int segments = (int) myShape.size() - 1;
119  if (segments >= 0) {
120  myShapeRotations.reserve(segments);
121  myShapeLengths.reserve(segments);
122  for (int i = 0; i < segments; ++i) {
123  const Position& f = myShape[i];
124  const Position& s = myShape[i + 1];
125  myShapeLengths.push_back(f.distanceTo2D(s));
126  myShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double)M_PI);
127  }
128  }
129 }
130 
131 
132 Boundary
134  return myShape.getBoxBoundary();
135 }
136 
137 
138 GNEEdge*
140  return &(myFromLane->getParentEdge());
141 }
142 
143 
144 GNEEdge*
146  return &(myToLane->getParentEdge());
147 }
148 
149 
150 GNELane*
152  return myFromLane;
153 }
154 
155 
156 GNELane*
158  return myToLane;
159 }
160 
161 
162 int
164  return myFromLane->getIndex();
165 }
166 
167 
168 int
170  return myToLane->getIndex();
171 }
172 
173 
177 }
178 
179 
182  return NBConnection(getEdgeFrom()->getNBEdge(), getFromLaneIndex(),
183  getEdgeTo()->getNBEdge(), getToLaneIndex(),
184  (int)getNBEdgeConnection().tlLinkNo);
185 }
186 
187 
188 void
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 
214  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
215  buildPopupHeader(ret, app);
219  buildPositionCopyEntry(ret, false);
220  // let the GNEViewNet store the popup position
221  (dynamic_cast<GNEViewNet&>(parent)).markPopupPosition();
222  return ret;
223 }
224 
225 
228  // Currently ignored before implementation to avoid warnings
229  UNUSED_PARAMETER(app);
230  UNUSED_PARAMETER(parent);
231  return NULL;
232 }
233 
234 
235 Boundary
238  b.grow(20);
239  return b;
240 }
241 
242 
243 void
245  // Check if connection must be drawed
246  if (myNet->getViewNet()->showConnections()) {
247  // Push draw matrix 1
248  glPushMatrix();
249  // Push name
250  glPushName(getGlID());
251  // Traslate matrix
252  glTranslated(0, 0, GLO_JUNCTION + 0.1); // must draw on top of junction
253  // Set color
255  // override with special colors (unless the color scheme is based on selection)
257  } else {
258  // Set color depending of the link state
260  }
261  // draw connection checking whether it is not too small
262  if (s.scale < 1.) {
263  // If it's small, dra a simple line
265  } else {
266  // draw a list of lines
268  }
269  // Pop name
270  glPopName();
271  // Pop draw matrix 1
272  glPopMatrix();
273  }
274 }
275 
276 
277 std::string
279  if (key == SUMO_ATTR_ID) {
280  // used by GNEReferenceCounter
281  // @note: may be called for connections without a valid nbCon reference
282  return getMicrosimID();
283  }
285  switch (key) {
286  case SUMO_ATTR_FROM:
287  return getEdgeFrom()->getID();
288  case SUMO_ATTR_TO:
289  return nbCon.toEdge->getID();
290  case SUMO_ATTR_FROM_LANE:
291  return toString(nbCon.toLane);
292  case SUMO_ATTR_TO_LANE:
293  return toString(nbCon.toLane);
294  case SUMO_ATTR_PASS:
295  return toString(nbCon.mayDefinitelyPass);
297  return toString(nbCon.keepClear);
298  case SUMO_ATTR_CONTPOS:
299  return toString(nbCon.contPos);
301  return toString(nbCon.uncontrolled);
303  return toString(nbCon.visibility);
304  default:
305  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
306  }
307 }
308 
309 
310 void
311 GNEConnection::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
312  switch (key) {
313  case SUMO_ATTR_FROM:
314  case SUMO_ATTR_TO:
315  case SUMO_ATTR_FROM_LANE:
316  case SUMO_ATTR_TO_LANE:
317  case SUMO_ATTR_PASS:
319  case SUMO_ATTR_CONTPOS:
322  // no special handling
323  undoList->p_add(new GNEChange_Attribute(this, key, value));
324  break;
325  default:
326  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
327  }
328 }
329 
330 
331 bool
332 GNEConnection::isValid(SumoXMLAttr key, const std::string& value) {
333  // Currently ignored before implementation to avoid warnings
334  switch (key) {
335  case SUMO_ATTR_FROM:
336  case SUMO_ATTR_TO:
337  case SUMO_ATTR_FROM_LANE:
338  case SUMO_ATTR_TO_LANE:
339  return false;
340  case SUMO_ATTR_PASS:
341  return canParse<bool>(value);
343  return canParse<bool>(value);
344  case SUMO_ATTR_CONTPOS:
345  return canParse<double>(value);
347  return canParse<bool>(value);
349  return canParse<double>(value) && isPositive<double>(value);
350  default:
351  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
352  }
353 }
354 
355 
356 void
357 GNEConnection::setAttribute(SumoXMLAttr key, const std::string& value) {
359  switch (key) {
360  case SUMO_ATTR_PASS:
361  nbCon.mayDefinitelyPass = parse<bool>(value);
362  break;
364  nbCon.keepClear = parse<bool>(value);
365  break;
367  nbCon.uncontrolled = parse<bool>(value);
368  break;
369  case SUMO_ATTR_CONTPOS:
370  nbCon.contPos = parse<double>(value);
371  break;
373  nbCon.visibility = parse<double>(value);
374  break;
375  default:
376  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
377  }
378 }
379 
380 
381 /****************************************************************************/
int NUM_POINTS
void updateGeometry()
update pre-computed geometry information
std::vector< double > myShapeLengths
The lengths of the shape parts.
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:165
int getFromLaneIndex() const
get lane index of the incoming lane
int toLane
The lane the connections yields in.
Definition: NBEdge.h:191
double scale
information about a lane&#39;s width (temporary, used for a single view)
bool isValid(SumoXMLAttr key, const std::string &value)
Whether vehicles must keep the junction clear.
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:250
GNENet * myNet
the net to inform about updates
static void drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition: GLHelper.cpp:172
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:188
Boundary getBoundary() const
Returns the street&#39;s geometry.
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:571
double x() const
Returns the x-position.
Definition: Position.h:63
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
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:200
GNELane * myFromLane
incoming lane of this connection
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
double visibility
custom foe visiblity for connection
Definition: NBEdge.h:209
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)
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.
int getIndex() const
returns the index of the lane
Definition: GNELane.cpp:701
GUIGlID getGlID() const
Returns the numerical id of the object.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:40
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
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:203
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
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"
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
void updateID()
update internal ID of Connection
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:438
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1085
std::vector< double > myShapeRotations
LinkState myLinkState
Linkstate.
std::string tlID
The id of the traffic light that controls this connection.
Definition: NBEdge.h:194
int fromLane
The lane the connections starts at.
Definition: NBEdge.h:185
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
double y() const
Returns the y-position.
Definition: Position.h:68
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:414
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
double length() const
Returns the 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:1606
~GNEConnection()
Destructor.
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:302
GUIColorer junctionColorer
The junction colorer.
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:265
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:58
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:435
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
#define M_PI
Definition: odrSpiral.cpp:40
PositionVector computeSmoothShape(const PositionVector &begShape, const PositionVector &endShape, int numPoints, bool isTurnaround, double extrapolateBeg, double extrapolateEnd, NBNode *recordError=0) const
Compute a smooth curve between the given geometries.
Definition: NBNode.cpp:451
bool showConnections()
show connections over junctions
Definition: GNEViewNet.cpp:310
static const RGBColor selectedConnectionColor
color of selected connection
Definition: GNENet.h:109
double contPos
custom position for internal junction on this connection
Definition: NBEdge.h:206
bool uncontrolled
check if Connection is uncontrolled
Definition: NBEdge.h:245
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.
SumoXMLTag getTag() const
get XML Tag assigned to this object
void updateLinkState()
recompute cached myLinkState
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:306
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in allGNEAttributeCarrier.
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:1049
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1519
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
a junction