Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/additional/GNEContainerStop.cpp
169684 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 GNEContainerStop.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jun 2016
17
///
18
// A lane area vehicles can halt at (GNE version)
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
#include <netedit/GNETagProperties.h>
23
#include <netedit/changes/GNEChange_Attribute.h>
24
#include <utils/gui/div/GLHelper.h>
25
#include <utils/options/OptionsCont.h>
26
#include <utils/vehicle/SUMORouteHandler.h>
27
28
#include "GNEContainerStop.h"
29
30
// ===========================================================================
31
// method definitions
32
// ===========================================================================
33
34
GNEContainerStop::GNEContainerStop(GNENet* net) :
35
GNEStoppingPlace(net, SUMO_TAG_CONTAINER_STOP) {
36
}
37
38
39
GNEContainerStop::GNEContainerStop(const std::string& id, GNENet* net, const std::string& filename, GNELane* lane, const double startPos, const double endPos,
40
const std::string& name, const std::vector<std::string>& lines, const int containerCapacity, const double parkingLength,
41
const RGBColor& color, const bool friendlyPosition, const double angle, const Parameterised::Map& parameters) :
42
GNEStoppingPlace(id, net, filename, SUMO_TAG_CONTAINER_STOP, lane, startPos, endPos, name, friendlyPosition, color, angle, parameters),
43
myLines(lines),
44
myContainerCapacity(containerCapacity),
45
myParkingLength(parkingLength) {
46
// update centering boundary without updating grid
47
updateCenteringBoundary(false);
48
}
49
50
51
GNEContainerStop::~GNEContainerStop() {}
52
53
54
void
55
GNEContainerStop::writeAdditional(OutputDevice& device) const {
56
device.openTag(getTagProperty()->getTag());
57
// write common attributes
58
writeStoppingPlaceAttributes(device);
59
// write specific attributes
60
if (getAttribute(SUMO_ATTR_LINES) != myTagProperty->getDefaultStringValue(SUMO_ATTR_LINES)) {
61
device.writeAttr(SUMO_ATTR_LINES, toString(myLines));
62
}
63
if (myContainerCapacity != myTagProperty->getDefaultIntValue(SUMO_ATTR_CONTAINER_CAPACITY)) {
64
device.writeAttr(SUMO_ATTR_CONTAINER_CAPACITY, myContainerCapacity);
65
}
66
if (myParkingLength != myTagProperty->getDefaultDoubleValue(SUMO_ATTR_PARKING_LENGTH)) {
67
device.writeAttr(SUMO_ATTR_PARKING_LENGTH, myParkingLength);
68
}
69
// write all access
70
for (const auto& access : getChildAdditionals()) {
71
access->writeAdditional(device);
72
}
73
// write parameters (Always after children to avoid problems with additionals.xsd)
74
writeParams(device);
75
device.closeTag();
76
}
77
78
79
void
80
GNEContainerStop::updateGeometry() {
81
// Get value of option "lefthand"
82
const double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
83
// Update common geometry of stopping place
84
setStoppingPlaceGeometry(getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) / 2);
85
// Obtain a copy of the shape
86
PositionVector tmpShape = myAdditionalGeometry.getShape();
87
// move entire shape and update
88
tmpShape.move2side(2 * offsetSign);
89
myAdditionalGeometry.updateGeometry(tmpShape);
90
// Move shape to side
91
tmpShape.move2side(myNet->getViewNet()->getVisualisationSettings().stoppingPlaceSettings.stoppingPlaceSignOffset * offsetSign);
92
// Get position of the sign
93
mySymbolPosition = tmpShape.getLineCenter();
94
}
95
96
97
void
98
GNEContainerStop::drawGL(const GUIVisualizationSettings& s) const {
99
// first check if additional has to be drawn
100
if (myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
101
// Obtain exaggeration of the draw
102
const double containerStopExaggeration = getExaggeration(s);
103
// check if draw moving geometry points
104
const bool movingGeometryPoints = drawMovingGeometryPoints(false);
105
// get detail level
106
const auto d = s.getDetailLevel(containerStopExaggeration);
107
// draw geometry only if we'rent in drawForObjectUnderCursor mode
108
if (s.checkDrawAdditional(d, isAttributeCarrierSelected())) {
109
// declare colors
110
RGBColor baseColor, signColor;
111
// set colors
112
if (mySpecialColor) {
113
baseColor = *mySpecialColor;
114
signColor = baseColor.changedBrightness(-32);
115
} else if (drawUsingSelectColor()) {
116
baseColor = s.colorSettings.selectedAdditionalColor;
117
signColor = baseColor.changedBrightness(-32);
118
} else if (myColor != RGBColor::INVISIBLE) {
119
baseColor = myColor;
120
signColor = s.colorSettings.containerStopColorSign;
121
} else {
122
baseColor = s.colorSettings.containerStopColor;
123
signColor = s.colorSettings.containerStopColorSign;
124
}
125
// draw parent and child lines
126
drawParentChildLines(s, s.additionalSettings.connectionColor);
127
// Add a layer matrix
128
GLHelper::pushMatrix();
129
// translate to front
130
drawInLayer(GLO_CONTAINER_STOP);
131
// set base color
132
GLHelper::setColor(baseColor);
133
// Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
134
GUIGeometry::drawGeometry(d, myAdditionalGeometry, s.stoppingPlaceSettings.containerStopWidth * MIN2(1.0, containerStopExaggeration));
135
// draw lines
136
drawLines(d, myLines, baseColor);
137
// draw sign
138
drawSign(s, d, containerStopExaggeration, baseColor, signColor, "C");
139
// draw geometry points
140
if (movingGeometryPoints && (myStartPosition != INVALID_DOUBLE)) {
141
drawLeftGeometryPoint(s, d, myAdditionalGeometry.getShape().front(), myAdditionalGeometry.getShapeRotations().front(), baseColor);
142
}
143
if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {
144
drawRightGeometryPoint(s, d, myAdditionalGeometry.getShape().back(), myAdditionalGeometry.getShapeRotations().back(), baseColor);
145
}
146
// pop layer matrix
147
GLHelper::popMatrix();
148
// draw lock icon
149
GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().getCentroid(), containerStopExaggeration);
150
// Draw additional ID
151
drawAdditionalID(s);
152
// draw additional name
153
drawAdditionalName(s);
154
// draw dotted contours
155
if (movingGeometryPoints) {
156
myAdditionalContour.drawDottedContourGeometryPoints(s, d, this, myAdditionalGeometry.getShape(), s.neteditSizeSettings.additionalGeometryPointRadius,
157
1, s.dottedContourSettings.segmentWidthSmall);
158
} else {
159
myAdditionalContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
160
mySymbolContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidthSmall, true);
161
}
162
}
163
// draw demand element children
164
drawDemandElementChildren(s);
165
// calculate contours
166
calculateStoppingPlaceContour(s, d, s.stoppingPlaceSettings.containerStopWidth, containerStopExaggeration, movingGeometryPoints);
167
}
168
}
169
170
171
std::string
172
GNEContainerStop::getAttribute(SumoXMLAttr key) const {
173
switch (key) {
174
175
case SUMO_ATTR_LINES:
176
return joinToString(myLines, " ");
177
case SUMO_ATTR_CONTAINER_CAPACITY:
178
return toString(myContainerCapacity);
179
case SUMO_ATTR_PARKING_LENGTH:
180
return toString(myParkingLength);
181
default:
182
return getStoppingPlaceAttribute(this, key);
183
}
184
}
185
186
187
double
188
GNEContainerStop::getAttributeDouble(SumoXMLAttr key) const {
189
return getStoppingPlaceAttributeDouble(key);
190
}
191
192
193
void
194
GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
195
switch (key) {
196
case SUMO_ATTR_LINES:
197
case SUMO_ATTR_CONTAINER_CAPACITY:
198
case SUMO_ATTR_PARKING_LENGTH:
199
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
200
break;
201
default:
202
setStoppingPlaceAttribute(key, value, undoList);
203
break;
204
}
205
}
206
207
208
bool
209
GNEContainerStop::isValid(SumoXMLAttr key, const std::string& value) {
210
switch (key) {
211
case SUMO_ATTR_LINES:
212
return true;
213
case SUMO_ATTR_CONTAINER_CAPACITY:
214
return canParse<int>(value) && (parse<int>(value) >= 0);
215
case SUMO_ATTR_PARKING_LENGTH:
216
return canParse<double>(value) && (parse<double>(value) >= 0);
217
default:
218
return isStoppingPlaceValid(key, value);
219
}
220
}
221
222
// ===========================================================================
223
// private
224
// ===========================================================================
225
226
void
227
GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value) {
228
switch (key) {
229
case SUMO_ATTR_LINES:
230
myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
231
break;
232
case SUMO_ATTR_CONTAINER_CAPACITY:
233
myContainerCapacity = GNEAttributeCarrier::parse<int>(value);
234
break;
235
case SUMO_ATTR_PARKING_LENGTH:
236
if (value.empty()) {
237
myParkingLength = myTagProperty->getDefaultDoubleValue(key);
238
} else {
239
myParkingLength = GNEAttributeCarrier::parse<double>(value);
240
}
241
break;
242
default:
243
setStoppingPlaceAttribute(this, key, value);
244
break;
245
}
246
}
247
248
249
/****************************************************************************/
250
251