Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNESegment.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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/****************************************************************************/
18// GNESegment used in Path Manager
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
22
23#include "GNESegment.h"
24
25// ===========================================================================
26// member method definitions
27// ===========================================================================
28
29GNESegment::GNESegment(GNEPathManager* pathManager, GNEPathElement* element, const GNELane* lane, std::vector<GNESegment*>& segments) :
30 myPathManager(pathManager),
31 myPathElement(element),
32 myLane(lane),
33 myJunction(nullptr),
34 myNextSegment(nullptr),
35 myPreviousSegment(nullptr),
36 myLabelSegment(false),
37 myContour(new GNEContour),
38 myFromContour(nullptr),
39 myToContour(nullptr) {
40 // set previous segment
41 if (segments.size() > 0) {
42 // set previous segment
43 myPreviousSegment = segments.back();
45 // use to contour of previous segment
48 // update lane index
51 } else if (myPreviousSegment->myLane) {
53 }
54 } else {
55 // this is the first segment, then create both from and to contours
57 myToContour = new GNEContour();
58 }
59 // add this segment in segments
60 segments.push_back(this);
61 // add segment in laneSegments
63}
64
65
66GNESegment::GNESegment(GNEPathManager* pathManager, GNEPathElement* element, const GNEJunction* junction, std::vector<GNESegment*>& segments) :
67 myPathManager(pathManager),
68 myPathElement(element),
69 myLane(nullptr),
70 myJunction(junction),
71 myNextSegment(nullptr),
72 myPreviousSegment(nullptr),
73 myLabelSegment(false),
74 myContour(new GNEContour),
75 myFromContour(nullptr),
76 myToContour(nullptr) {
77 // set previous segment
78 if (segments.size() > 0) {
79 // set previous segment
80 myPreviousSegment = segments.back();
82 // use to contour of previous segment
85 // update junction index
88 } else if (myPreviousSegment->myJunction) {
90 }
91 } else {
92 // this is the first segment, then create both from and to contours
94 myToContour = new GNEContour();
95 }
96 // add this segment in segments
97 segments.push_back(this);
98 // add segment in junctionSegments
100}
101
102
104 // check if we're cleaning all segments
106 // clear segment from LaneSegments
108 // remove references in previous and next segment
109 if (myPreviousSegment) {
111 }
112 if (myNextSegment) {
114 }
115 }
116 // delete contours
117 delete myContour;
118 if (myFromContour) {
119 delete myFromContour;
120 }
121 if (myToContour) {
122 delete myToContour;
123 }
124}
125
126
129 return myContour;
130}
131
132
135 return myFromContour;
136}
137
138
141 return myToContour;
142}
143
144
147 return myNextSegment;
148}
149
150
155
156
157bool
159 return (myPreviousSegment == nullptr);
160}
161
162
163bool
165 return (myNextSegment == nullptr);
166}
167
168
171 return myPathElement;
172}
173
174
175const GNELane*
177 return myLane;
178}
179
180
181const GNELane*
183 if (myPreviousSegment) {
184 return myPreviousSegment->getLane();
185 } else {
186 return nullptr;
187 }
188}
189
190
191const GNELane*
193 if (myNextSegment) {
194 return myNextSegment->getLane();
195 } else {
196 return nullptr;
197 }
198}
199
200
201int
203 return myLaneIndex;
204}
205
206
207const GNEJunction*
209 return myJunction;
210}
211
212
213int
217
218
219bool
223
224
225void
229
230
232 myPathManager(nullptr),
233 myPathElement(nullptr),
234 myLane(nullptr),
235 myJunction(nullptr),
236 myNextSegment(nullptr),
237 myPreviousSegment(nullptr),
238 myLabelSegment(false) {
239}
240
241/****************************************************************************/
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
void addSegmentInLaneSegments(GNESegment *segment, const GNELane *lane)
add segments int laneSegments (called by GNESegment constructor)
bool myCleaningSegments
flag for clear segments quickly
void clearSegmentFromJunctionAndLaneSegments(GNESegment *segment)
clear segments from junction and lane Segments (called by GNESegment destructor)
void addSegmentInJunctionSegments(GNESegment *segment, const GNEJunction *junction)
add segments int junctionSegments (called by GNESegment constructor)
const GNELane * getLane() const
get lane associated with this segment
void markSegmentLabel()
mark segment as middle segment
GNEContour * myContour
contour associated with segment
Definition GNESegment.h:142
const GNEJunction * getJunction() const
get junction associated with this segment
GNESegment * getPreviousSegment() const
get previous segment
GNESegment * myNextSegment
pointer to next segment
Definition GNESegment.h:133
bool myLabelSegment
flag for check if this segment is a label segment
Definition GNESegment.h:139
const GNELane * getNextLane() const
get next lane
GNEContour * myToContour
to contour, used for moving elements (only in the last segment)
Definition GNESegment.h:148
const GNELane * getPreviousLane() const
get previous lane
GNEContour * myFromContour
from contour, used for moving elements (only in the first segment)
Definition GNESegment.h:145
int myJunctionIndex
junction index
Definition GNESegment.h:130
GNESegment * myPreviousSegment
pointer to previous segment
Definition GNESegment.h:136
GNESegment * getNextSegment() const
functions related with the other paht segments
GNEContour * getFromContour() const
get from contour associated with segment (only if this is the first path segment)
const GNEJunction * myJunction
junction associated with this segment
Definition GNESegment.h:124
int getJunctionIndex() const
get lane index
GNEPathElement * getPathElement() const
bool isFirstSegment() const
check if segment is the first path's segment
const GNELane * myLane
lane associated with this segment
Definition GNESegment.h:121
GNESegment()
default constructor
GNEContour * getContour() const
int myLaneIndex
lane index
Definition GNESegment.h:127
int getLaneIndex() const
get lane index
GNEPathManager * myPathManager
pointer to path manager
Definition GNESegment.h:115
bool isLastSegment() const
check if segment is the last path's segment
GNEPathElement * myPathElement
path element associated with this segment
Definition GNESegment.h:118
bool isLabelSegment() const
check if segment is label segment
~GNESegment()
destructor
GNEContour * getToContour() const
get to contour associated with segment (only if this is the last path segment)