Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/network/GNEEdge.h
185790 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file GNEEdge.h
15
/// @author Jakob Erdmann
16
/// @date Feb 2011
17
///
18
// A road/street connecting two junctions (netedit-version, adapted from GUIEdge)
19
// Basically a container for an NBEdge with drawing and editing capabilities
20
/****************************************************************************/
21
#pragma once
22
#include <config.h>
23
24
#include <netbuild/NBEdge.h>
25
#include <netedit/elements/GNECandidateElement.h>
26
#include <netedit/elements/moving/GNEMoveResult.h>
27
#include <utils/gui/div/GUIDottedGeometry.h>
28
#include <utils/gui/div/GUIGeometry.h>
29
30
#include "GNENetworkElement.h"
31
32
// ===========================================================================
33
// class declarations
34
// ===========================================================================
35
36
class GNEConnection;
37
class GNECrossing;
38
class GNEEdgeTemplate;
39
class GNEEdgeType;
40
class GNEJunction;
41
class GNELane;
42
class GNEMoveElementEdge;
43
class GNEMoveOperation;
44
class GNENet;
45
class GNERouteProbe;
46
47
// ===========================================================================
48
// class definitions
49
// ===========================================================================
50
51
class GNEEdge : public GNENetworkElement, public GNECandidateElement {
52
53
/// @brief Friend class
54
friend class GNEChange_Lane;
55
friend class GNEChange_Connection;
56
friend class GNEMoveElementEdge;
57
58
public:
59
/// @brief Definition of the connection's vector
60
typedef std::vector<GNEConnection*> ConnectionVector;
61
62
/**@brief Constructor
63
* @param[in] net The net to inform about gui updates
64
* @param[in] nbe The represented edge
65
* @param[in] loaded Whether the edge was loaded from a file
66
*/
67
GNEEdge(GNENet* net, NBEdge* nbe, bool wasSplit = false, bool loaded = false);
68
69
/// @brief Destructor.
70
~GNEEdge();
71
72
/// @brief methods to retrieve the elements linked to this edge
73
/// @{
74
75
/// @brief get GNEMoveElement associated with this edge
76
GNEMoveElement* getMoveElement() const override;
77
78
/// @brief get parameters associated with this edge
79
Parameterised* getParameters() override;
80
81
/// @brief get parameters associated with this edge (constant)
82
const Parameterised* getParameters() const override;
83
84
/// @}
85
86
/// @brief get from Junction (only used to increase readability)
87
inline GNEJunction* getFromJunction() const {
88
return getParentJunctions().front();
89
}
90
91
/// @brief get from Junction (only used to increase readability)
92
inline GNEJunction* getToJunction() const {
93
return getParentJunctions().back();
94
}
95
96
/// @brief check if current network element is valid to be written into XML
97
bool isNetworkElementValid() const override;
98
99
/// @brief return a string with the current network element problem
100
std::string getNetworkElementProblem() const override;
101
102
/// @name Functions related with geometry of element
103
/// @{
104
105
/// @brief update pre-computed geometry information
106
void updateGeometry() override;
107
108
/// @brief Returns position of hierarchical element in view
109
Position getPositionInView() const;
110
111
/// @}
112
113
/// @name Function related with contour drawing
114
/// @{
115
116
/// @brief check if draw from contour (green)
117
bool checkDrawFromContour() const override;
118
119
/// @brief check if draw from contour (magenta)
120
bool checkDrawToContour() const override;
121
122
/// @brief check if draw related contour (cyan)
123
bool checkDrawRelatedContour() const override;
124
125
/// @brief check if draw over contour (orange)
126
bool checkDrawOverContour() const override;
127
128
/// @brief check if draw delete contour (pink/white)
129
bool checkDrawDeleteContour() const override;
130
131
/// @brief check if draw delete contour small (pink/white)
132
bool checkDrawDeleteContourSmall() const override;
133
134
/// @brief check if draw select contour (blue)
135
bool checkDrawSelectContour() const override;
136
137
/// @brief check if draw move contour (red)
138
bool checkDrawMoveContour() const override;
139
140
/// @}
141
142
/// @name functions for geometry points
143
/// @{
144
/// @brief check if current edge has custom end points
145
bool hasCustomEndPoints() const;
146
147
/// @brief return true if user clicked over ShapeStart
148
bool clickedOverShapeStart(const Position& pos) const;
149
150
/// @brief return true if user clicked over ShapeEnd
151
bool clickedOverShapeEnd(const Position& pos) const;
152
153
/// @brief return true if user clicked over a Geometry Point
154
bool clickedOverGeometryPoint(const Position& pos) const;
155
/// @}
156
157
/// @brief update edge geometry after junction move
158
void updateJunctionPosition(GNEJunction* junction, const Position& origPos);
159
160
/// @name inherited from GUIGlObject
161
/// @{
162
/**@brief Returns an own popup-menu
163
*
164
* @param[in] app The application needed to build the popup-menu
165
* @param[in] parent The parent window needed to build the popup-menu
166
* @return The built popup-menu
167
* @see GUIGlObject::getPopUpMenu
168
*/
169
GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
170
171
/// @brief return exaggeration associated with this GLObject
172
double getExaggeration(const GUIVisualizationSettings& s) const override;
173
174
/// @brief Returns the boundary to which the view shall be centered in order to show the object
175
Boundary getCenteringBoundary() const override;
176
177
/// @brief update centering boundary (implies change in RTREE)
178
void updateCenteringBoundary(const bool updateGrid);
179
180
/// @brief Returns the street name
181
const std::string getOptionalName() const override;
182
183
/**@brief Draws the object
184
* @param[in] s The settings for the current view (may influence drawing)
185
* @see GUIGlObject::drawGL
186
*/
187
void drawGL(const GUIVisualizationSettings& s) const override;
188
189
/// @brief delete element
190
void deleteGLObject() override;
191
192
/// @brief update GLObject (geometry, ID, etc.)
193
void updateGLObject() override;
194
195
/// @}
196
197
/// @brief returns the internal NBEdge
198
NBEdge* getNBEdge() const;
199
200
/// @brief get opposite edges
201
std::vector<GNEEdge*> getOppositeEdges() const;
202
203
/// @brief makes pos the new geometry endpoint at the appropriate end, or remove current existent endpoint
204
void editEndpoint(Position pos, GNEUndoList* undoList);
205
206
/// @brief restores the endpoint to the junction position at the appropriate end
207
void resetEndpoint(const Position& pos, GNEUndoList* undoList);
208
209
/// @brief restores both endpoint to the junction position at the appropriate end
210
void resetBothEndpoint(GNEUndoList* undoList);
211
212
/// @name inherited from GNEAttributeCarrier
213
/// @{
214
/* @brief method for getting the Attribute of an XML key
215
* @param[in] key The attribute key
216
* @return string with the value associated to key
217
*/
218
std::string getAttribute(SumoXMLAttr key) const override;
219
std::string getAttributeForSelection(SumoXMLAttr key) const override;
220
221
/* @brief method for getting the Attribute of an XML key in double format
222
* @param[in] key The attribute key
223
* @return double with the value associated to key
224
*/
225
double getAttributeDouble(SumoXMLAttr key) const override;
226
227
/* @brief method for getting the Attribute of an XML key in position format
228
* @param[in] key The attribute key
229
* @return position with the value associated to key
230
*/
231
Position getAttributePosition(SumoXMLAttr key) const override;
232
233
/* @brief method for getting the Attribute of an XML key in Position format
234
* @param[in] key The attribute key
235
* @return position with the value associated to key
236
*/
237
PositionVector getAttributePositionVector(SumoXMLAttr key) const override;
238
239
/* @brief method for setting the attribute and letting the object perform additional changes
240
* @param[in] key The attribute key
241
* @param[in] value The new value
242
* @param[in] undoList The undoList on which to register changes
243
*/
244
void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) override;
245
246
/* @brief method for setting the attribute and letting the object perform additional changes
247
* @param[in] key The attribute key
248
* @param[in] value The new value
249
* @param[in] undoList The undoList on which to register changes
250
*/
251
bool isValid(SumoXMLAttr key, const std::string& value) override;
252
253
/* @brief method for check if the value for certain attribute is set
254
* @param[in] key The attribute key
255
*/
256
bool isAttributeEnabled(SumoXMLAttr key) const override;
257
258
/* @brief method for check if the value for certain attribute is computed (for example, due a network recomputing)
259
* @param[in] key The attribute key
260
*/
261
bool isAttributeComputed(SumoXMLAttr key) const override;
262
263
/// @}
264
265
/// @brief set responsibility for deleting internal structures
266
void setResponsible(bool newVal);
267
268
/**@brief update edge geometry and inform the lanes
269
* @param[in] geom The new geometry
270
* @param[in] inner Whether geom is only the inner points
271
*/
272
void setGeometry(PositionVector geom, bool inner);
273
274
/// @brief get front up shape position
275
const Position getFrontUpShapePosition() const;
276
277
/// @brief get front down shape position
278
const Position getFrontDownShapePosition() const;
279
280
/// @brief get back up shape position
281
const Position getBackUpShapePosition() const;
282
283
/// @brief get back down shape position
284
const Position getBackDownShapePosition() const;
285
286
/// @brief remake connections
287
void remakeGNEConnections(bool junctionsReady = false);
288
289
/// @brief copy edge attributes from edgetemplate
290
void copyTemplate(const GNEEdgeTemplate* edgeTemplate, GNEUndoList* undoList);
291
292
/// @brief copy edge attributes from edgeType
293
void copyEdgeType(const GNEEdgeType* edgeType, GNEUndoList* undoList);
294
295
/// @brief returns GLIDs of all lanes
296
std::set<GUIGlID> getLaneGlIDs() const;
297
298
/// @brief returns a reference to the GNEConnection vector
299
const std::vector<GNEConnection*>& getGNEConnections() const;
300
301
/// @brief get GNEConnection if exist, and if not create it if create is enabled
302
GNEConnection* retrieveGNEConnection(int fromLane, NBEdge* to, int toLane, bool createIfNoExist = true);
303
304
/// @brief whether this edge was created from a split
305
bool wasSplit();
306
307
/* @brief compute a splitting position which keeps the resulting edges
308
* straight unless the user clicked near a geometry point */
309
Position getSplitPos(const Position& clickPos);
310
311
/// @brief set edge ID
312
void setEdgeID(const std::string& newID);
313
314
/// @brief check if edge has a restricted lane
315
bool hasRestrictedLane(SUMOVehicleClass vclass) const;
316
317
// @brief the radius in which to register clicks for geometry nodes
318
static const double SNAP_RADIUS;
319
320
// @brief the radius in which to register clicks for geometry nodes (Squared)
321
static const double SNAP_RADIUS_SQUARED;
322
323
/// @brief clear current connections
324
void clearGNEConnections();
325
326
/// @brief obtain relative positions of RouteProbes
327
int getRouteProbeRelativePosition(GNERouteProbe* routeProbe) const;
328
329
/// @brief get GNECrossings vinculated with this Edge
330
std::vector<GNECrossing*> getGNECrossings();
331
332
/// @brief make geometry smooth
333
void smooth(GNEUndoList* undoList);
334
335
/// @brief interpolate z values linear between junctions
336
void straightenElevation(GNEUndoList* undoList);
337
338
/// @brief smooth elevation with regard to adjoining edges
339
void smoothElevation(GNEUndoList* undoList);
340
341
/// @brief return smoothed shape
342
PositionVector smoothShape(const PositionVector& shape, bool forElevation);
343
344
/// @brief return the first lane that allow a vehicle of type vClass (or the first lane, if none was found)
345
GNELane* getLaneByAllowedVClass(const SUMOVehicleClass vClass) const;
346
347
/// @brief return the first lane that disallow a vehicle of type vClass (or the first lane, if none was found)
348
GNELane* getLaneByDisallowedVClass(const SUMOVehicleClass vClass) const;
349
350
// @brief update vehicle spread geometries
351
void updateVehicleSpreadGeometries();
352
353
// @brief update vehicle geometries
354
void updateVehicleStackLabels();
355
356
// @brief update person geometries
357
void updatePersonStackLabels();
358
359
// @brief update vehicle geometries
360
void updateContainerStackLabels();
361
362
/// @brief check if edge makes a convex angle [0 - 180) degrees
363
bool isConvexAngle() const;
364
365
/// @brief check if this edge has predecessors (note: only for vehicles, this function ignore walking areas!)
366
bool hasPredecessors() const;
367
368
/// @brief check if this edge has successors (note: only for vehicles, this function ignore walking areas!)
369
bool hasSuccessors() const;
370
371
/// @brief get reverse edge (if exist)
372
GNEEdge* getReverseEdge() const;
373
374
protected:
375
/// @brief the underlying NBEdge
376
NBEdge* myNBEdge;
377
378
/// @brief vector with the connections of this edge
379
ConnectionVector myGNEConnections;
380
381
/// @brief position used for move Lanes
382
Position myPositionBeforeMoving;
383
384
/// @brief whether we are responsible for deleting myNBNode
385
bool myAmResponsible;
386
387
/// @brief whether this edge was created from a split
388
bool myWasSplit;
389
390
/// @brief modification status of the connections
391
std::string myConnectionStatus;
392
393
private:
394
/// @brief Stack position (used to stack demand elements over edges)
395
class StackPosition : public std::pair<double, double> {
396
397
public:
398
/// @brief constructor
399
StackPosition(const double departPos, const double length);
400
401
/// @brief get begin position
402
double beginPosition() const;
403
404
/// @brief get end position
405
double endPosition() const;
406
};
407
408
/// @brief Stack demand elements
409
class StackDemandElements : public std::pair<StackPosition, std::vector<GNEDemandElement*> > {
410
411
public:
412
/// @brief constructor
413
StackDemandElements(const StackPosition stackedPosition, GNEDemandElement* demandElement);
414
415
/// @brief add demand elment to current StackDemandElements
416
void addDemandElements(GNEDemandElement* demandElement);
417
418
/// @brief get stack position
419
const StackPosition& getStackPosition() const;
420
421
/// @brief get demand elements
422
const std::vector<GNEDemandElement*>& getDemandElements() const;
423
};
424
425
/// @brief move element edge
426
GNEMoveElementEdge* myMoveElementEdge = nullptr;
427
428
/// @brief edge boundary
429
Boundary myEdgeBoundary;
430
431
/// @brief flag to enable/disable update geometry of lanes (used mainly by setNumLanes)
432
bool myUpdateGeometry;
433
434
/// @brief set attribute after validation
435
void setAttribute(SumoXMLAttr key, const std::string& value) override;
436
437
/**@brief changes the number of lanes.
438
* When reducing the number of lanes, higher-numbered lanes are removed first.
439
* When increasing the number of lanes, the last known attributes for a lane
440
* with this number are restored. If none are found the attributes for the
441
* leftmost lane are copied
442
*/
443
void setNumLanes(int numLanes, GNEUndoList* undoList);
444
445
/// @brief update front parent junction
446
void updateFirstParentJunction(const std::string& value);
447
448
/// @brief update last parent junction
449
void updateSecondParentJunction(const std::string& value);
450
451
/// @brief@brief increase number of lanes by one use the given attributes and restore the GNELane
452
void addLane(GNELane* lane, const NBEdge::Lane& laneAttrs, bool recomputeConnections);
453
454
/// @briefdecrease the number of lanes by one. argument is only used to increase robustness (assertions)
455
void removeLane(GNELane* lane, bool recomputeConnections);
456
457
/// @brief adds a connection
458
void addConnection(NBEdge::Connection nbCon, bool selectAfterCreation = false);
459
460
/// @brief removes a connection
461
void removeConnection(NBEdge::Connection nbCon);
462
463
/// @brief remove crossing of junction
464
void removeEdgeFromCrossings(GNEJunction* junction, GNEUndoList* undoList);
465
466
/// @brief change Shape StartPos
467
void setShapeStartPos(const Position& pos);
468
469
/// @brief change Shape EndPos
470
void setShapeEndPos(const Position& pos);
471
472
/// @brief get vehicles a that start over this edge
473
const std::map<const GNELane*, std::vector<GNEDemandElement*> > getVehiclesOverEdgeMap() const;
474
475
/// @brief get persons a that start over this edge
476
const std::map<const GNELane*, std::vector<GNEDemandElement*> > getPersonsOverEdgeMap() const;
477
478
/// @brief get containers a that start over this edge
479
const std::map<const GNELane*, std::vector<GNEDemandElement*> > getContainersOverEdgeMap() const;
480
481
/// @brief draw edge geometry points (note: This function is called by GNELane::drawGL(...)
482
void drawEdgeGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
483
const double layer) const;
484
485
/// @brief draw start extreme geometry point
486
void drawStartGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
487
const double geometryPointRadius, const double layer, const double exaggeration) const;
488
489
/// @brief draw end extreme geometry point
490
void drawEndGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
491
const double geometryPointRadius, const double layer, const double exaggeration) const;
492
493
/// @brief draw edge name
494
void drawEdgeName(const GUIVisualizationSettings& s) const;
495
496
/// @brief draw edgeStopOffset
497
void drawLaneStopOffset(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
498
const double layer) const;
499
500
/// @brief draw edge shape (only one line)
501
void drawEdgeShape(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
502
const double layer) const;
503
504
/// @brief draw children
505
void drawChildrens(const GUIVisualizationSettings& s) const;
506
507
/// @brief calculate contours
508
void calculateEdgeContour(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
509
const double layer) const;
510
511
/// @brief draw TAZElements
512
void drawTAZElements(const GUIVisualizationSettings& s) const;
513
514
/// @brief check if draw big geometry points
515
bool drawBigGeometryPoints() const;
516
517
/// @brief check if given stacked positions are overlapped
518
bool areStackPositionOverlapped(const GNEEdge::StackPosition& vehicleA, const GNEEdge::StackPosition& vehicleB) const;
519
520
/// @brief get geometry point radius
521
double getGeometryPointRadius() const;
522
523
/// @brief invalidated copy constructor
524
GNEEdge(const GNEEdge& s) = delete;
525
526
/// @brief invalidated assignment operator
527
GNEEdge& operator=(const GNEEdge& s) = delete;
528
};
529
530