Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEStoppingPlace.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-2026 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// A abstract class to define common parameters of lane area in which vehicles can halt (GNE version)
19/****************************************************************************/
20#include <config.h>
21
25#include <netedit/GNENet.h>
30
31#include "GNEStoppingPlace.h"
32
33// ===========================================================================
34// member method definitions
35// ===========================================================================
36
37#ifdef _MSC_VER
38#pragma warning(push)
39#pragma warning(disable: 4355) // mask warning about "this" in initializers
40#endif
42 GNEAdditional(net, tag),
43 myMoveElementLaneDouble(new GNEMoveElementLaneDouble(this, SUMO_ATTR_STARTPOS, myStartPosOverLane,
44 SUMO_ATTR_ENDPOS, myEndPosPosOverLane, myFriendlyPosition)) {
45}
46
47
48GNEStoppingPlace::GNEStoppingPlace(const std::string& id, GNENet* net, FileBucket* fileBucket,
49 SumoXMLTag tag, GNELane* lane, const double startPos, const double endPos,
50 const std::string& name, bool friendlyPosition, const RGBColor& color,
51 const double angle, const Parameterised::Map& parameters) :
52 GNEAdditional(id, net, tag, fileBucket, name),
53 Parameterised(parameters),
54 myStartPosOverLane(startPos),
55 myEndPosPosOverLane(endPos),
56 myFriendlyPosition(friendlyPosition),
57 myColor(color),
58 myAngle(angle),
59 myMoveElementLaneDouble(new GNEMoveElementLaneDouble(this, SUMO_ATTR_STARTPOS, myStartPosOverLane,
60 SUMO_ATTR_ENDPOS, myEndPosPosOverLane, myFriendlyPosition)) {
61 // set parents
62 setParent<GNELane*>(lane);
63}
64#ifdef _MSC_VER
65#pragma warning(pop)
66#endif
67
68
72
73
78
79
82 return this;
83}
84
85
86const Parameterised*
88 return this;
89}
90
91
92bool
94 // only movement problems
96}
97
98
99std::string
101 // only movement problems
103}
104
105
106void
108 // only movement problems
110}
111
112
113bool
115 // get edit modes
116 const auto& editModes = myNet->getViewNet()->getEditModes();
117 // check if we're in move mode
118 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
120 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
121 // only move the first element
123 } else {
124 return false;
125 }
126}
127
128
133
134
135void
137 // nothing to do
138}
139
140
141void
142GNEStoppingPlace::splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) {
143 // first check tat both network elements are lanes and originalElement correspond to stoppingPlace lane
144 if ((originalElement->getTagProperty()->getTag() == SUMO_TAG_LANE) &&
145 (newElement->getTagProperty()->getTag() == SUMO_TAG_LANE) &&
146 (getParentLanes().front() == originalElement)) {
147 // check if we have to change additional lane depending of split position
149 // calculate middle position
150 const double middlePosition = ((myEndPosPosOverLane - myStartPosOverLane) / 2.0) + myStartPosOverLane;
151 // four cases:
152 if (splitPosition < myStartPosOverLane) {
153 // change lane
154 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
155 // now adjust start and end position
156 setAttribute(SUMO_ATTR_STARTPOS, toString(myStartPosOverLane - splitPosition), undoList);
157 setAttribute(SUMO_ATTR_ENDPOS, toString(myEndPosPosOverLane - splitPosition), undoList);
158 } else if ((splitPosition > myStartPosOverLane) && (splitPosition < middlePosition)) {
159 // change lane
160 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
161 // now adjust start and end position
162 setAttribute(SUMO_ATTR_STARTPOS, "0", undoList);
163 setAttribute(SUMO_ATTR_ENDPOS, toString(myEndPosPosOverLane - splitPosition), undoList);
164 } else if ((splitPosition > middlePosition) && (splitPosition < myEndPosPosOverLane)) {
165 // only adjust end position
166 setAttribute(SUMO_ATTR_ENDPOS, toString(splitPosition), undoList);
167 } else if ((splitPosition > myEndPosPosOverLane)) {
168 // nothing to do
169 }
170 } else if ((myStartPosOverLane != INVALID_DOUBLE) && (splitPosition < myStartPosOverLane)) {
171 // change lane
172 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
173 // now adjust start position
174 setAttribute(SUMO_ATTR_STARTPOS, toString(myEndPosPosOverLane - splitPosition), undoList);
175 } else if ((myEndPosPosOverLane != INVALID_DOUBLE) && (splitPosition < myEndPosPosOverLane)) {
176 // change lane
177 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
178 // now adjust end position
179 setAttribute(SUMO_ATTR_ENDPOS, toString(myEndPosPosOverLane - splitPosition), undoList);
180 }
181 }
182}
183
184
185std::string
187 return getParentLanes().front()->getID();
188}
189
190
191void
193 // write common additional attributes
195 // write move atributes
197 // color (if defined)
198 if (getAttribute(SUMO_ATTR_COLOR).size() > 0) {
200 }
201 // angle (if defined)
202 if (myAngle != 0) {
204 }
205}
206
207
208std::string
210 switch (key) {
211 case SUMO_ATTR_ID:
212 return getMicrosimID();
213 case SUMO_ATTR_NAME:
214 return myAdditionalName;
215 case SUMO_ATTR_COLOR:
217 return "";
218 } else {
219 return toString(myColor);
220 }
221 case SUMO_ATTR_ANGLE:
222 return toString(myAngle);
223 default:
225 }
226}
227
228
229double
231 switch (key) {
232 case SUMO_ATTR_ANGLE:
233 return myAngle;
234 default:
236 }
237}
238
239
244
245
246void
247GNEStoppingPlace::setStoppingPlaceAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
248 switch (key) {
249 case SUMO_ATTR_ID:
250 case SUMO_ATTR_NAME:
251 case SUMO_ATTR_COLOR:
252 case SUMO_ATTR_ANGLE:
253 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
254 break;
255 default:
256 myMoveElementLaneDouble->setMovingAttribute(key, value, undoList);
257 break;
258 }
259}
260
261
262bool
263GNEStoppingPlace::isStoppingPlaceValid(SumoXMLAttr key, const std::string& value) const {
264 switch (key) {
265 case SUMO_ATTR_ID:
268 } else {
269 return isValidAdditionalID(value);
270 }
271 case SUMO_ATTR_NAME:
273 case SUMO_ATTR_COLOR:
274 if (value.empty()) {
275 return true;
276 } else {
277 return canParse<RGBColor>(value);
278 }
279 case SUMO_ATTR_ANGLE:
280 if (value.empty()) {
281 return true;
282 } else {
283 return canParse<double>(value);
284 }
285 default:
287 }
288}
289
290
291void
293 switch (key) {
294 case SUMO_ATTR_ID:
295 // update microsimID
296 setAdditionalID(value);
297 break;
298 case SUMO_ATTR_LANE:
299 // set hier because GNEHierarchicalElement is a template
301 break;
302 case SUMO_ATTR_NAME:
303 myAdditionalName = value;
304 break;
305 case SUMO_ATTR_COLOR:
306 if (value.empty()) {
308 } else {
309 myColor = GNEAttributeCarrier::parse<RGBColor>(value);
310 }
311 break;
312 case SUMO_ATTR_ANGLE:
313 if (value.empty()) {
314 myAngle = 0;
315 } else {
316 myAngle = GNEAttributeCarrier::parse<double>(value);
317 }
318 break;
319 // special attributes used during creation or edition
321 // set hier because GNEHierarchicalElement is a template
323 break;
324 default:
326 break;
327 }
328}
329
330
331void
333 if (getParentLanes().empty() || getParentLanes().front() == nullptr) {
334 // may happen during initialization
335 return;
336 }
337 // Get value of option "lefthand"
338 const bool lefthandAttr = hasAttribute(SUMO_ATTR_LEFTHAND) && parse<bool>(getAttribute(SUMO_ATTR_LEFTHAND));
339 const double offsetSign = OptionsCont::getOptions().getBool("lefthand") != lefthandAttr ? -1 : 1;
340
341 // obtain laneShape
342 PositionVector laneShape = getParentLanes().front()->getLaneShape();
343
344 // Move shape to side
345 laneShape.move2side(movingToSide * offsetSign);
346
347 // Cut shape using as delimitators fixed start position and fixed end position
349}
350
351
356
357
362
363
364bool
366 switch (key) {
368 if (isTemplate()) {
369 return true;
370 } else {
372 }
373 case GNE_ATTR_SIZE:
374 if (isTemplate()) {
375 return true;
376 } else {
378 }
379 default:
380 return true;
381 }
382}
383
384
385std::string
387 return getTagStr() + ": " + getID();
388}
389
390
391std::string
395
396
397void
398GNEStoppingPlace::drawLines(const GUIVisualizationSettings::Detail d, const std::vector<std::string>& lines, const RGBColor& color) const {
399 // only draw in level 1
401 // calculate middle point
402 const double middlePoint = (myAdditionalGeometry.getShape().length2D() * 0.5);
403 // calculate rotation
404 const double rot = (myAdditionalGeometry.getShape().size() <= 1) ? 0 : myAdditionalGeometry.getShape().rotationDegreeAtOffset(middlePoint);
405 // Iterate over every line
406 for (int i = 0; i < (int)lines.size(); ++i) {
407 // push a new matrix for every line
409 // translate
410 glTranslated(mySymbolPosition.x(), mySymbolPosition.y(), 0);
411 // rotate over lane
413 // draw line with a color depending of the selection status
414 if (drawUsingSelectColor()) {
415 GLHelper::drawText(lines[i].c_str(), Position(1.2, (double)i), .1, 1.f, color, 0, FONS_ALIGN_LEFT);
416 } else {
417 GLHelper::drawText(lines[i].c_str(), Position(1.2, (double)i), .1, 1.f, color, 0, FONS_ALIGN_LEFT);
418 }
419 // pop matrix for every line
421 }
422 }
423}
424
425
426void
428 const RGBColor& baseColor, const RGBColor& signColor, const std::string& word) const {
429 // only draw in level 2
431 // calculate middle point
432 const double middlePoint = (myAdditionalGeometry.getShape().length2D() * 0.5);
433 // calculate rotation
434 const double rotSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
435 const double rot = (myAdditionalGeometry.getShape().size() <= 1) ? 0 : myAdditionalGeometry.getShape().rotationDegreeAtOffset(middlePoint) - 180. * rotSign;
436 // push matrix
438 // Start drawing sign traslating matrix to signal position
439 glTranslated(mySymbolPosition.x(), mySymbolPosition.y(), 0);
440 // rotate over lane
442 // scale matrix depending of the exaggeration
443 glScaled(exaggeration, exaggeration, 1);
444 // set color
445 GLHelper::setColor(baseColor);
446 // Draw circle
448 // continue depending of rectangle selection
450 // Traslate to front
451 glTranslated(0, 0, .1);
452 // set color
453 GLHelper::setColor(signColor);
454 // draw another circle in the same position, but a little bit more small
456 // draw H depending of detailSettings
458 }
459 // pop draw matrix
461 }
462}
463
464
465void
467 const double width, const double exaggeration, const bool movingGeometryPoints) const {
468 // check if we're calculating the contour or the moving geometry points
469 if (movingGeometryPoints) {
473 }
474 if (movingGeometryPoints && (myEndPosPosOverLane != INVALID_DOUBLE)) {
477 }
478 } else {
479 // don't exaggerate contour
481 nullptr, getParentLanes().front()->getParentEdge());
483 exaggeration, getParentLanes().front()->getParentEdge());
484 }
485}
486
487/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_LANE
begin/end of the description of a single lane
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_LANE
@ SUMO_ATTR_ENDPOS
@ GNE_ATTR_SIZE
size (used in stopping places)
@ SUMO_ATTR_LEFTHAND
@ GNE_ATTR_REFERENCE
reference position (used creating stoppingPlaces)
@ SUMO_ATTR_NAME
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ GNE_ATTR_SHIFTLANEINDEX
shift lane index (only used by elements over lanes)
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:68
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:49
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void drawFilledCircleDetailled(const GUIVisualizationSettings::Detail d, const double radius)
Draws a filled circle around (0,0) depending of level of detail.
Definition GLHelper.cpp:534
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, const int align=0, double width=-1)
Definition GLHelper.cpp:742
bool isValidAdditionalID(const std::string &value) const
check if a new additional ID is valid
void setAdditionalID(const std::string &newID)
set additional ID
GNEContour myAdditionalContour
variable used for draw additional contours
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void replaceAdditionalParentLanes(const std::string &value)
replace additional parent lanes
void shiftLaneIndex()
shift lane index
std::string myAdditionalName
name of additional
void writeAdditionalAttributes(OutputDevice &device) const
write common additional attributes
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
const std::string getID() const override
get ID (all Attribute Carriers have one)
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
const std::string & getTagStr() const
get tag assigned to this object in string format
bool isTemplate() const
check if this AC is template
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
Position getCommonAttributePosition(SumoXMLAttr key) const
bool hasAttribute(SumoXMLAttr key) const
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * myNet
pointer to net
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
virtual std::string getAttribute(SumoXMLAttr key) const =0
const GNETagProperties * myTagProperty
reference to tagProperty associated with this attribute carrier
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
void calculateContourExtrudedShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const PositionVector &shape, const double layer, const double extrusionWidth, const double scale, const bool closeFirstExtrem, const bool closeLastExtrem, const double offset, const GNESegment *segment, const GUIGlObject *boundaryParent, const bool addToSelectedObjects=true) const
calculate contour extruded (used in elements formed by a central shape)
void calculateContourLastGeometryPoint(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const PositionVector &shape, const double layer, const double radius, const double scale, const bool forceCalculation=false) const
calculate contour for last geometry point
void calculateContourCircleShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const Position &pos, double radius, const double layer, const double scale, const GUIGlObject *boundaryParent) const
calculate contour (circle elements)
void calculateContourFirstGeometryPoint(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const PositionVector &shape, const double layer, const double radius, const double scale, const bool forceCalculation=false) const
calculate contour for first geometry point
const GNEHierarchicalContainerParents< GNELane * > & getParentLanes() const
get parent lanes
double myMovingLateralOffset
move element lateral offset
std::string getMovingAttribute(SumoXMLAttr key) const override
get moving attribute
void fixMovingProblem()
fix moving problem
Position getMovingAttributePosition(SumoXMLAttr key) const override
get moving attribute position
double getEndFixedPositionOverLane(const bool adjustGeometryFactor) const
get end offset position over lane
double getMovingAttributeDouble(SumoXMLAttr key) const override
get moving attribute double
std::string getMovingProblem() const
return a string with the current moving problem
bool isMovingAttributeValid(SumoXMLAttr key, const std::string &value) const override
check if the given moving attribute is valid
bool isMoveElementValid() const
check if current moving element is valid to be written into XML
double getStartFixedPositionOverLane(const bool adjustGeometryFactor) const
get start offset position over lane
void writeMoveAttributes(OutputDevice &device, const bool writeLength) const
write move attributes
void setMovingAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
set moving attribute (using undo-list)
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
bool isStoppingPlaceValid(SumoXMLAttr key, const std::string &value) const
std::string getParentName() const override
Returns the name of the parent object (if any)
void setStoppingPlaceAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
double myEndPosPosOverLane
The end position over lane.
void fixAdditionalProblem() override
fix additional problem (must be reimplemented in all detector children)
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this stoppingPlace
void writeStoppingPlaceAttributes(OutputDevice &device) const
write common stoppingPlace attributes
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
Position getAttributePosition(SumoXMLAttr key) const override
void drawSign(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double exaggeration, const RGBColor &baseColor, const RGBColor &signColor, const std::string &word) const
draw sign
~GNEStoppingPlace()
Destructor.
GNEMoveElementLaneDouble * myMoveElementLaneDouble
move element lane double
bool isAdditionalValid() const override
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
Parameterised * getParameters() override
get parameters associated with this stoppingPlace
GNEStoppingPlace(GNENet *net, SumoXMLTag tag)
Default constructor.
double getStoppingPlaceAttributeDouble(SumoXMLAttr key) const
RGBColor myColor
RGB color.
void calculateStoppingPlaceContour(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double width, const double exaggeration, const bool movingGeometryPoints) const
check object in view
std::string getAdditionalProblem() const override
return a string with the current additional problem (must be reimplemented in all detector children)
void drawLines(const GUIVisualizationSettings::Detail d, const std::vector< std::string > &lines, const RGBColor &color) const
draw lines
Position mySymbolPosition
The position of the sign.
double myStartPosOverLane
The start position over lane.
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
GNEContour mySymbolContour
circle contour
Position getStoppingPlaceAttributePosition(SumoXMLAttr key) const
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
Position getPositionInView() const override
Returns position of additional in view.
bool isAttributeEnabled(SumoXMLAttr key) const override
bool checkDrawMoveContour() const override
check if draw move contour (red)
std::string getStoppingPlaceAttribute(SumoXMLAttr key) const
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const GUIGlObject * getGUIGlObjectFront() const
get front GUIGLObject or a pointer to nullptr
bool isCurrentlyMovingElements() const
check if an element is being moved
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
const GNEViewNetHelper::EditNetworkElementShapes & getEditNetworkElementShapes() const
get Edit Shape module
bool checkOverLockedElement(const GUIGlObject *GLObject, const bool isSelected) const
check if given element is locked (used for drawing select and delete contour)
const GNEViewNetHelper::ViewObjectsSelector & getViewObjectsSelector() const
get objects under cursor
static void rotateOverLane(const double rot)
rotate over lane (used by Lock icons, detector logos, etc.)
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape)
update entire geometry
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Stores the information about how to visualize structures.
GUIVisualizationStoppingPlaceSettings stoppingPlaceSettings
StoppingPlace settings.
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
static const std::vector< SumoXMLTag > busStops
busStops namespace
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
An upper class for objects with additional parameters.
std::map< std::string, std::string > Map
parameters map
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double x() const
Returns the x-position.
Definition Position.h:52
double y() const
Returns the y-position.
Definition Position.h:57
A list of positions.
double length2D() const
Returns the length.
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain amount
static const RGBColor INVISIBLE
Definition RGBColor.h:202
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
@ FONS_ALIGN_LEFT
Definition fontstash.h:42
GNENetworkElement * getEditedNetworkElement() const
pointer to edited network element
static const double additionalGeometryPointRadius
moving additional geometry point radius
static const double symbolInternalRadius
symbol internal radius
static const double symbolExternalRadius
symbol external radius
static const double symbolInternalTextSize
symbol internal text size