Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/network/GNEJunction.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 GNEJunction.h
15
/// @author Jakob Erdmann
16
/// @date Feb 2011
17
///
18
// A class for visualizing and editing junctions in netedit (adapted from
19
// GUIJunctionWrapper)
20
/****************************************************************************/
21
#pragma once
22
#include <config.h>
23
24
#include <netbuild/NBNode.h>
25
#include <netedit/elements/GNECandidateElement.h>
26
#include <netedit/elements/moving/GNEMoveResult.h>
27
#include <utils/gui/globjects/GUIPolygon.h>
28
29
#include "GNENetworkElement.h"
30
31
// ===========================================================================
32
// class declarations
33
// ===========================================================================
34
35
class GNEConnection;
36
class GNECrossing;
37
class GNEEdge;
38
class GNEInternalLane;
39
class GNEMoveElementJunction;
40
class GNEMoveOperation;
41
class GNENet;
42
class GNEWalkingArea;
43
class NBTrafficLightDefinition;
44
45
// ===========================================================================
46
// class definitions
47
// ===========================================================================
48
49
class GNEJunction : public GNENetworkElement, public GNECandidateElement {
50
51
/// @brief Declare friend class
52
friend class GNEChange_TLS;
53
friend class GNEChange_Crossing;
54
friend class GNEMoveElementJunction;
55
56
public:
57
/**@brief Constructor
58
* @param[in] net The net to inform about gui updates
59
* @param[in] nbn The represented node
60
* @param[in] loaded Whether the junction was loaded from a file
61
*/
62
GNEJunction(GNENet* net, NBNode* nbn, bool loaded = false);
63
64
/// @brief Destructor
65
~GNEJunction();
66
67
/// @brief methods to retrieve the elements linked to this junction
68
/// @{
69
70
/// @brief get GNEMoveElement associated with this junction
71
GNEMoveElement* getMoveElement() const override;
72
73
/// @brief get parameters associated with this junction
74
Parameterised* getParameters() override;
75
76
/// @brief get parameters associated with this junction (constant)
77
const Parameterised* getParameters() const override;
78
79
/// @}
80
81
/// @name Functions related with geometry of element
82
/// @{
83
/// @brief get junction shape
84
const PositionVector& getJunctionShape() const;
85
86
/// @brief update pre-computed geometry information (including crossings)
87
void updateGeometry() override;
88
89
/// @brief update pre-computed geometry information without modifying netbuild structures
90
// @note: using an extra function because updateGeometry overrides an abstract virtual function
91
void updateGeometryAfterNetbuild(bool rebuildNBNodeCrossings = false);
92
93
/// @brief Returns position of hierarchical element in view
94
Position getPositionInView() const;
95
96
/// @}
97
98
/// @name Function related with contour drawing
99
/// @{
100
101
/// @brief check if draw from contour (green)
102
bool checkDrawFromContour() const override;
103
104
/// @brief check if draw from contour (magenta)
105
bool checkDrawToContour() const override;
106
107
/// @brief check if draw related contour (cyan)
108
bool checkDrawRelatedContour() const override;
109
110
/// @brief check if draw over contour (orange)
111
bool checkDrawOverContour() const override;
112
113
/// @brief check if draw delete contour (pink/white)
114
bool checkDrawDeleteContour() const override;
115
116
/// @brief check if draw delete contour small (pink/white)
117
bool checkDrawDeleteContourSmall() const override;
118
119
/// @brief check if draw select contour (blue)
120
bool checkDrawSelectContour() const override;
121
122
/// @brief check if draw move contour (red)
123
bool checkDrawMoveContour() const override;
124
125
/// @}
126
127
/// @name inherited from GUIGlObject
128
/// @{
129
/**@brief Returns an own popup-menu
130
*
131
* @param[in] app The application needed to build the popup-menu
132
* @param[in] parent The parent window needed to build the popup-menu
133
* @return The built popup-menu
134
* @see GUIGlObject::getPopUpMenu
135
*/
136
GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
137
138
/// @brief return exaggeration associated with this GLObject
139
double getExaggeration(const GUIVisualizationSettings& s) const override;
140
141
/// @brief Returns the boundary to which the view shall be centered in order to show the object
142
Boundary getCenteringBoundary() const override;
143
144
/// @brief update centering boundary (implies change in RTREE)
145
void updateCenteringBoundary(const bool updateGrid);
146
147
/**@brief Draws the object
148
* @param[in] s The settings for the current view (may influence drawing)
149
* @see GUIGlObject::drawGL
150
*/
151
void drawGL(const GUIVisualizationSettings& s) const override;
152
153
/// @brief delete element
154
void deleteGLObject() override;
155
156
/// @brief update GLObject (geometry, ID, etc.)
157
void updateGLObject() override;
158
/// @}
159
160
/// @brief Return net build node
161
NBNode* getNBNode() const;
162
163
/// @brief return GNEJunction neighbours
164
std::vector<GNEJunction*> getJunctionNeighbours() const;
165
166
/// @brief add incoming GNEEdge
167
void addIncomingGNEEdge(GNEEdge* edge);
168
169
/// @brief add outgoing GNEEdge
170
void addOutgoingGNEEdge(GNEEdge* edge);
171
172
/// @brief remove incoming GNEEdge
173
void removeIncomingGNEEdge(GNEEdge* edge);
174
175
/// @brief remove outgoing GNEEdge
176
void removeOutgoingGNEEdge(GNEEdge* edge);
177
178
/// @brief Returns incoming GNEEdges
179
const std::vector<GNEEdge*>& getGNEIncomingEdges() const;
180
181
/// @brief Returns incoming GNEEdges
182
const std::vector<GNEEdge*>& getGNEOutgoingEdges() const;
183
184
/// @brief Returns GNECrossings
185
const std::vector<GNECrossing*>& getGNECrossings() const;
186
187
/// @brief Returns GNEWalkingAreas
188
const std::vector<GNEWalkingArea*>& getGNEWalkingAreas() const;
189
190
/// @brief Returns all GNEConnections vinculated with this junction
191
std::vector<GNEConnection*> getGNEConnections() const;
192
193
/// @brief marks as first junction in createEdge-mode
194
void markAsCreateEdgeSource();
195
196
/// @brief removes mark as first junction in createEdge-mode
197
void unMarkAsCreateEdgeSource();
198
199
/// @brief notify the junction of being selected in tls-mode. (used to control drawing)
200
void selectTLS(bool selected);
201
202
/// @name inherited from GNEAttributeCarrier
203
/// @{
204
/* @brief method for getting the Attribute of an XML key
205
* @param[in] key The attribute key
206
* @return string with the value associated to key
207
*/
208
std::string getAttribute(SumoXMLAttr key) const override;
209
210
/* @brief method for getting the Attribute of an XML key in double format
211
* @param[in] key The attribute key
212
* @return double with the value associated to key
213
*/
214
double getAttributeDouble(SumoXMLAttr key) const override;
215
216
/* @brief method for getting the Attribute of an XML key in position format
217
* @param[in] key The attribute key
218
* @return position with the value associated to key
219
*/
220
Position getAttributePosition(SumoXMLAttr key) const override;
221
222
/* @brief method for getting the Attribute of an XML key in Position format
223
* @param[in] key The attribute key
224
* @return position with the value associated to key
225
*/
226
PositionVector getAttributePositionVector(SumoXMLAttr key) const override;
227
228
/* @brief method for setting the attribute and letting the object perform additional changes
229
* @param[in] key The attribute key
230
* @param[in] value The new value
231
* @param[in] undoList The undoList on which to register changes
232
*/
233
void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) override;
234
235
/* @brief method for checking if the key and their correspond attribute are valids
236
* @param[in] key The attribute key
237
* @param[in] value The value associated to key key
238
* @return true if the value is valid, false in other case
239
*/
240
bool isValid(SumoXMLAttr key, const std::string& value) override;
241
242
/* @brief method for check if the value for certain attribute is set
243
* @param[in] key The attribute key
244
*/
245
bool isAttributeEnabled(SumoXMLAttr key) const override;
246
247
/* @brief method for check if the value for certain attribute is computed (for example, due a network recomputing)
248
* @param[in] key The attribute key
249
*/
250
bool isAttributeComputed(SumoXMLAttr key) const override;
251
252
/// @}
253
254
/// @brief set responsibility for deleting internal structures
255
void setResponsible(bool newVal);
256
257
/* @brief notify junction that one of its edges has changed its shape, and
258
* therefore the junction shape is no longer valid */
259
void invalidateShape();
260
261
/* @brief update validity of this junctions logic
262
* if the logic is invalidated, existing connections are removed via undo-list
263
* so that the previous state can be restored
264
* also calls invalidateTLS
265
* @param[in] valid The new validity of the junction
266
* @note: this should always be called with an active command group
267
*/
268
void setLogicValid(bool valid, GNEUndoList* undoList, const std::string& status = FEATURE_GUESSED);
269
270
/// @brief remove all connections from the given edge
271
void removeConnectionsFrom(GNEEdge* edge, GNEUndoList* undoList, bool updateTLS, int lane = -1);
272
273
/// @brief remove all connections to the given edge
274
void removeConnectionsTo(GNEEdge* edge, GNEUndoList* undoList, bool updateTLS, int lane = -1);
275
276
/// @brief prevent re-guessing connections at this junction
277
void markAsModified(GNEUndoList* undoList);
278
279
/* @brief invalidates loaded or edited TLS
280
* @param[in] deletedConnection If a valid connection is given a replacement def with this connection removed
281
* but all other information intact will be computed instead of guessing a new tlDef
282
* @note: this should always be called with an active command group
283
*/
284
void invalidateTLS(GNEUndoList* undoList,
285
const NBConnection& deletedConnection = NBConnection::InvalidConnection,
286
const NBConnection& addedConnection = NBConnection::InvalidConnection);
287
288
/// @brief replace one edge by another in all tls connections
289
void replaceIncomingConnections(GNEEdge* which, GNEEdge* by, GNEUndoList* undoList);
290
291
/// @brief removes the given edge from all pedestrian crossings
292
void removeEdgeFromCrossings(GNEEdge* edge, GNEUndoList* undoList);
293
294
/// @brief whether this junction has a valid logic
295
bool isLogicValid();
296
297
/// @brief get GNECrossing if exist, and if not create it if create is enabled
298
GNECrossing* retrieveGNECrossing(NBNode::Crossing* NBNodeCrossing, bool createIfNoExist = true);
299
300
/// @brief get GNEWalkingArea if exist, and if not create it if create is enabled
301
GNEWalkingArea* retrieveGNEWalkingArea(const std::string& NBNodeWalkingAreaID, bool createIfNoExist = true);
302
303
/// @brief mark connections as deprecated
304
void markConnectionsDeprecated(bool includingNeighbours);
305
306
/// @brief set junction Type (using undo/redo)
307
void setJunctionType(const std::string& value, GNEUndoList* undoList);
308
309
/// @brief clear walking areas
310
void clearWalkingAreas();
311
312
/// @brief rebuilds WalkingAreas objects for this junction
313
void rebuildGNEWalkingAreas();
314
315
/// @brief add internal lane
316
void addInternalLane(const GNEInternalLane* internalLane);
317
318
/// @brief remove internal lane
319
void removeInternalLane(const GNEInternalLane* internalLane);
320
321
protected:
322
/// @brief move element junction
323
GNEMoveElementJunction* myMoveElementJunction = nullptr;
324
325
/// @brief A reference to the represented junction
326
NBNode* myNBNode;
327
328
/// @brief edge boundary
329
Boundary myJunctionBoundary;
330
331
/// @brief drawing toggle (used to avoid double draws)
332
int* myDrawingToggle;
333
334
/// @brief variable used for draw circle contours
335
GNEContour myCircleContour;
336
337
/// @brief vector with the (child) incomings GNEEdges vinculated with this junction
338
std::vector<GNEEdge*> myGNEIncomingEdges;
339
340
/// @brief vector with the (child) outgoings GNEEdges vinculated with this junction
341
std::vector<GNEEdge*> myGNEOutgoingEdges;
342
343
/// @brief the built crossing objects
344
std::vector<GNECrossing*> myGNECrossings;
345
346
/// @brief the built walkingArea objects
347
std::vector<GNEWalkingArea*> myGNEWalkingAreas;
348
349
/// @brief internal lanes related placed in this junction
350
std::vector<const GNEInternalLane*> myInternalLanes;
351
352
/// @brief whether this junction is the first junction for a newly creatededge
353
/// @see GNEApplicationWindow::createEdgeSource)
354
bool myAmCreateEdgeSource = false;
355
356
/// @brief modification status of the junction logic (all connections across this junction)
357
std::string myLogicStatus;
358
359
/// @brief whether we are responsible for deleting myNBNode
360
bool myAmResponsible = false;
361
362
/// @brief whether this junctions logic is valid
363
bool myHasValidLogic;
364
365
/// @brief whether this junction is selected in tls-mode
366
bool myAmTLSSelected = false;
367
368
/// @brief whether this junction probably should have some connections but doesn't
369
bool myColorForMissingConnections = false;
370
371
/// @brief An object that stores the shape and its tesselation
372
mutable TesselatedPolygon myTesselation;
373
374
/// @brief exaggeration used in tesselation
375
mutable double myExaggeration = 1;
376
377
private:
378
/// @brief check if draw junction as bubble
379
bool drawAsBubble(const GUIVisualizationSettings& s, const double junctionShapeArea) const;
380
381
/// @brief draw junction as bubble
382
void drawJunctionAsBubble(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
383
const double exaggeration) const;
384
385
/// @brief draw junction as bubble
386
void drawJunctionAsShape(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
387
const double exaggeration) const;
388
389
/// @brief draw junction center (only in move mode)
390
void drawJunctionCenter(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d) const;
391
392
/// @brief draw TLS icon
393
void drawTLSIcon(const GUIVisualizationSettings& s) const;
394
395
/// @brief draw elevation
396
void drawElevation(const GUIVisualizationSettings& s) const;
397
398
/// @brief draw junction name
399
void drawJunctionName(const GUIVisualizationSettings& s) const;
400
401
/// @brief draw junction childs
402
void drawJunctionChildren(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d) const;
403
404
/// @brief calculate contour
405
void calculateJunctioncontour(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
406
const double exaggeration, const bool drawBubble) const;
407
408
/// @brief method for setting the attribute and nothing else (used in GNEChange_Attribute)
409
void setAttribute(SumoXMLAttr key, const std::string& value) override;
410
411
/**@brief reposition the node at pos without updating GRID and informs the edges
412
* @param[in] pos The new position
413
* @note: those operations are not added to the undoList.
414
*/
415
void moveJunctionGeometry(const Position& pos, const bool updateEdgeBoundaries);
416
417
/// @brief sets junction color depending on circumstances
418
RGBColor setColor(const GUIVisualizationSettings& s, bool bubble) const;
419
420
/// @brief determines color value
421
double getColorValue(const GUIVisualizationSettings& s, int activeScheme) const override;
422
423
/// @brief compute whether this junction probably should have some connections but doesn't
424
void checkMissingConnections();
425
426
/// @brief adds a traffic light
427
void addTrafficLight(NBTrafficLightDefinition* tlDef, bool forceInsert);
428
429
/// @brief removes a traffic light
430
void removeTrafficLight(NBTrafficLightDefinition* tlDef);
431
432
/// @brief rebuilds crossing objects for this junction
433
void rebuildGNECrossings(bool rebuildNBNodeCrossings = true);
434
435
/// @brief remove the given connections from all traffic light definitions of this junction
436
void removeTLSConnections(std::vector<NBConnection>& connections, GNEUndoList* undoList);
437
438
/// @brief temporarily mirror coordinates in lefthand network to compute correct crossing geometries
439
void mirrorXLeftHand();
440
441
/// @brief build TLS operations contextual menu
442
void buildTLSOperations(GUISUMOAbstractView& parent, GUIGLObjectPopupMenu* ret, const int numSelectedJunctions);
443
444
/// @brief Invalidated copy constructor.
445
GNEJunction(const GNEJunction&) = delete;
446
447
/// @brief Invalidated assignment operator.
448
GNEJunction& operator=(const GNEJunction&) = delete;
449
};
450
451