Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/GNESegment.cpp
169665 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 GNESegment.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Nov 2024
17
///
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
29
GNESegment::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();
44
myPreviousSegment->myNextSegment = this;
45
// use to contour of previous segment
46
myToContour = myPreviousSegment->myToContour;
47
myPreviousSegment->myToContour = nullptr;
48
// update lane index
49
if (myPreviousSegment->myPreviousSegment && myPreviousSegment->myPreviousSegment->myLane) {
50
myLaneIndex = myPreviousSegment->myPreviousSegment->myLaneIndex + 1;
51
} else if (myPreviousSegment->myLane) {
52
myLaneIndex = myPreviousSegment->myLaneIndex + 1;
53
}
54
} else {
55
// this is the first segment, then create both from and to contours
56
myFromContour = new GNEContour();
57
myToContour = new GNEContour();
58
}
59
// add this segment in segments
60
segments.push_back(this);
61
// add segment in laneSegments
62
myPathManager->addSegmentInLaneSegments(this, lane);
63
}
64
65
66
GNESegment::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();
81
myPreviousSegment->myNextSegment = this;
82
// use to contour of previous segment
83
myToContour = myPreviousSegment->myToContour;
84
myPreviousSegment->myToContour = nullptr;
85
// update junction index
86
if (myPreviousSegment->myPreviousSegment && myPreviousSegment->myPreviousSegment->myJunction) {
87
myJunctionIndex = myPreviousSegment->myPreviousSegment->myJunctionIndex + 1;
88
} else if (myPreviousSegment->myJunction) {
89
myJunctionIndex = myPreviousSegment->myJunctionIndex + 1;
90
}
91
} else {
92
// this is the first segment, then create both from and to contours
93
myFromContour = new GNEContour();
94
myToContour = new GNEContour();
95
}
96
// add this segment in segments
97
segments.push_back(this);
98
// add segment in junctionSegments
99
myPathManager->addSegmentInJunctionSegments(this, junction);
100
}
101
102
103
GNESegment::~GNESegment() {
104
// check if we're cleaning all segments
105
if (!myPathManager->myCleaningSegments) {
106
// clear segment from LaneSegments
107
myPathManager->clearSegmentFromJunctionAndLaneSegments(this);
108
// remove references in previous and next segment
109
if (myPreviousSegment) {
110
myPreviousSegment->myNextSegment = nullptr;
111
}
112
if (myNextSegment) {
113
myNextSegment->myPreviousSegment = nullptr;
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
127
GNEContour*
128
GNESegment::getContour() const {
129
return myContour;
130
}
131
132
133
GNEContour*
134
GNESegment::getFromContour() const {
135
return myFromContour;
136
}
137
138
139
GNEContour*
140
GNESegment::getToContour() const {
141
return myToContour;
142
}
143
144
145
GNESegment*
146
GNESegment::getNextSegment() const {
147
return myNextSegment;
148
}
149
150
151
GNESegment*
152
GNESegment::getPreviousSegment() const {
153
return myPreviousSegment;
154
}
155
156
157
bool
158
GNESegment::isFirstSegment() const {
159
return (myPreviousSegment == nullptr);
160
}
161
162
163
bool
164
GNESegment::isLastSegment() const {
165
return (myNextSegment == nullptr);
166
}
167
168
169
GNEPathElement*
170
GNESegment::getPathElement() const {
171
return myPathElement;
172
}
173
174
175
const GNELane*
176
GNESegment::getLane() const {
177
return myLane;
178
}
179
180
181
const GNELane*
182
GNESegment::getPreviousLane() const {
183
if (myPreviousSegment) {
184
return myPreviousSegment->getLane();
185
} else {
186
return nullptr;
187
}
188
}
189
190
191
const GNELane*
192
GNESegment::getNextLane() const {
193
if (myNextSegment) {
194
return myNextSegment->getLane();
195
} else {
196
return nullptr;
197
}
198
}
199
200
201
int
202
GNESegment::getLaneIndex() const {
203
return myLaneIndex;
204
}
205
206
207
const GNEJunction*
208
GNESegment::getJunction() const {
209
return myJunction;
210
}
211
212
213
int
214
GNESegment::getJunctionIndex() const {
215
return myJunctionIndex;
216
}
217
218
219
bool
220
GNESegment::isLabelSegment() const {
221
return myLabelSegment;
222
}
223
224
225
void
226
GNESegment::markSegmentLabel() {
227
myLabelSegment = true;
228
}
229
230
231
GNESegment::GNESegment() :
232
myPathManager(nullptr),
233
myPathElement(nullptr),
234
myLane(nullptr),
235
myJunction(nullptr),
236
myNextSegment(nullptr),
237
myPreviousSegment(nullptr),
238
myLabelSegment(false) {
239
}
240
241
/****************************************************************************/
242
243