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-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/****************************************************************************/
18// A abstract class to define common parameters of lane area in which vehicles can halt (GNE version)
19/****************************************************************************/
20
24#include <netedit/GNENet.h>
29
30#include "GNEStoppingPlace.h"
31
32// ===========================================================================
33// member method definitions
34// ===========================================================================
35
37 GNEAdditional("", net, "", tag, ""),
38 myMoveElementLaneDouble(new GNEMoveElementLaneDouble(this, SUMO_ATTR_STARTPOS, myStartPosOverLane,
39 SUMO_ATTR_ENDPOS, myEndPosPosOverLane, myFriendlyPosition)) {
40}
41
42
43GNEStoppingPlace::GNEStoppingPlace(const std::string& id, GNENet* net, const std::string& filename,
44 SumoXMLTag tag, GNELane* lane, const double startPos, const double endPos,
45 const std::string& name, bool friendlyPosition, const RGBColor& color,
46 const double angle, const Parameterised::Map& parameters) :
47 GNEAdditional(id, net, filename, tag, name),
48 Parameterised(parameters),
49 myStartPosOverLane(startPos),
50 myEndPosPosOverLane(endPos),
51 myFriendlyPosition(friendlyPosition),
52 myColor(color),
53 myAngle(angle),
54 myMoveElementLaneDouble(new GNEMoveElementLaneDouble(this, SUMO_ATTR_STARTPOS, myStartPosOverLane,
55 SUMO_ATTR_ENDPOS, myEndPosPosOverLane, myFriendlyPosition)) {
56 // set parents
57 setParent<GNELane*>(lane);
58}
59
60
64
65
70
71
74 return this;
75}
76
77
78const Parameterised*
80 return this;
81}
82
83
84bool
86 // only movement problems
88}
89
90
91std::string
93 // only movement problems
95}
96
97
98void
100 // only movement problems
102}
103
104
105bool
107 // get edit modes
108 const auto& editModes = myNet->getViewNet()->getEditModes();
109 // check if we're in move mode
110 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
112 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
113 // only move the first element
115 } else {
116 return false;
117 }
118}
119
120
125
126
127void
129 // nothing to do
130}
131
132
133void
134GNEStoppingPlace::splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) {
135 // first check tat both network elements are lanes and originalElement correspond to stoppingPlace lane
136 if ((originalElement->getTagProperty()->getTag() == SUMO_TAG_LANE) &&
137 (newElement->getTagProperty()->getTag() == SUMO_TAG_LANE) &&
138 (getParentLanes().front() == originalElement)) {
139 // check if we have to change additional lane depending of split position
141 // calculate middle position
142 const double middlePosition = ((myEndPosPosOverLane - myStartPosOverLane) / 2.0) + myStartPosOverLane;
143 // four cases:
144 if (splitPosition < myStartPosOverLane) {
145 // change lane
146 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
147 // now adjust start and end position
148 setAttribute(SUMO_ATTR_STARTPOS, toString(myStartPosOverLane - splitPosition), undoList);
149 setAttribute(SUMO_ATTR_ENDPOS, toString(myEndPosPosOverLane - splitPosition), undoList);
150 } else if ((splitPosition > myStartPosOverLane) && (splitPosition < middlePosition)) {
151 // change lane
152 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
153 // now adjust start and end position
154 setAttribute(SUMO_ATTR_STARTPOS, "0", undoList);
155 setAttribute(SUMO_ATTR_ENDPOS, toString(myEndPosPosOverLane - splitPosition), undoList);
156 } else if ((splitPosition > middlePosition) && (splitPosition < myEndPosPosOverLane)) {
157 // only adjust end position
158 setAttribute(SUMO_ATTR_ENDPOS, toString(splitPosition), undoList);
159 } else if ((splitPosition > myEndPosPosOverLane)) {
160 // nothing to do
161 }
162 } else if ((myStartPosOverLane != INVALID_DOUBLE) && (splitPosition < myStartPosOverLane)) {
163 // change lane
164 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
165 // now adjust start position
166 setAttribute(SUMO_ATTR_STARTPOS, toString(myEndPosPosOverLane - splitPosition), undoList);
167 } else if ((myEndPosPosOverLane != INVALID_DOUBLE) && (splitPosition < myEndPosPosOverLane)) {
168 // change lane
169 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
170 // now adjust end position
171 setAttribute(SUMO_ATTR_ENDPOS, toString(myEndPosPosOverLane - splitPosition), undoList);
172 }
173 }
174}
175
176
177std::string
179 return getParentLanes().front()->getID();
180}
181
182
183void
185 // write common additional attributes
187 // write move atributes
189 // color (if defined)
190 if (getAttribute(SUMO_ATTR_COLOR).size() > 0) {
192 }
193 // angle (if defined)
194 if (myAngle != 0) {
196 }
197}
198
199
200std::string
202 switch (key) {
203 case SUMO_ATTR_ID:
204 return getMicrosimID();
205 case SUMO_ATTR_NAME:
206 return myAdditionalName;
207 case SUMO_ATTR_COLOR:
209 return "";
210 } else {
211 return toString(myColor);
212 }
213 case SUMO_ATTR_ANGLE:
214 return toString(myAngle);
215 default:
217 }
218}
219
220
221double
223 switch (key) {
224 case SUMO_ATTR_ANGLE:
225 return myAngle;
226 default:
228 }
229}
230
231
236
237
238void
239GNEStoppingPlace::setStoppingPlaceAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
240 switch (key) {
241 case SUMO_ATTR_ID:
242 case SUMO_ATTR_NAME:
243 case SUMO_ATTR_COLOR:
244 case SUMO_ATTR_ANGLE:
245 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
246 break;
247 default:
248 myMoveElementLaneDouble->setMovingAttribute(key, value, undoList);
249 break;
250 }
251}
252
253
254bool
255GNEStoppingPlace::isStoppingPlaceValid(SumoXMLAttr key, const std::string& value) const {
256 switch (key) {
257 case SUMO_ATTR_ID:
260 } else {
261 return isValidAdditionalID(value);
262 }
263 case SUMO_ATTR_NAME:
265 case SUMO_ATTR_COLOR:
266 if (value.empty()) {
267 return true;
268 } else {
269 return canParse<RGBColor>(value);
270 }
271 case SUMO_ATTR_ANGLE:
272 if (value.empty()) {
273 return true;
274 } else {
275 return canParse<double>(value);
276 }
277 default:
279 }
280}
281
282
283void
285 switch (key) {
286 case SUMO_ATTR_ID:
287 // update microsimID
288 setAdditionalID(value);
289 break;
290 case SUMO_ATTR_LANE:
291 // set hier because GNEHierarchicalElement is a template
293 break;
294 case SUMO_ATTR_NAME:
295 myAdditionalName = value;
296 break;
297 case SUMO_ATTR_COLOR:
298 if (value.empty()) {
300 } else {
301 myColor = GNEAttributeCarrier::parse<RGBColor>(value);
302 }
303 break;
304 case SUMO_ATTR_ANGLE:
305 if (value.empty()) {
306 myAngle = 0;
307 } else {
308 myAngle = GNEAttributeCarrier::parse<double>(value);
309 }
310 break;
311 // special attributes used during creation or edition
313 // set hier because GNEHierarchicalElement is a template
315 break;
316 default:
318 break;
319 }
320}
321
322
323void
325 if (getParentLanes().empty() || getParentLanes().front() == nullptr) {
326 // may happen during initialization
327 return;
328 }
329 // Get value of option "lefthand"
330 const bool lefthandAttr = hasAttribute(SUMO_ATTR_LEFTHAND) && parse<bool>(getAttribute(SUMO_ATTR_LEFTHAND));
331 const double offsetSign = OptionsCont::getOptions().getBool("lefthand") != lefthandAttr ? -1 : 1;
332
333 // obtain laneShape
334 PositionVector laneShape = getParentLanes().front()->getLaneShape();
335
336 // Move shape to side
337 laneShape.move2side(movingToSide * offsetSign);
338
339 // Cut shape using as delimitators fixed start position and fixed end position
341}
342
343
348
349
354
355
356bool
358 switch (key) {
360 if (isTemplate()) {
361 return true;
362 } else {
364 }
365 case GNE_ATTR_SIZE:
366 if (isTemplate()) {
367 return true;
368 } else {
370 }
371 default:
372 return true;
373 }
374}
375
376
377std::string
379 return getTagStr() + ": " + getID();
380}
381
382
383std::string
387
388
389void
390GNEStoppingPlace::drawLines(const GUIVisualizationSettings::Detail d, const std::vector<std::string>& lines, const RGBColor& color) const {
391 // only draw in level 1
393 // calculate middle point
394 const double middlePoint = (myAdditionalGeometry.getShape().length2D() * 0.5);
395 // calculate rotation
396 const double rot = (myAdditionalGeometry.getShape().size() <= 1) ? 0 : myAdditionalGeometry.getShape().rotationDegreeAtOffset(middlePoint);
397 // Iterate over every line
398 for (int i = 0; i < (int)lines.size(); ++i) {
399 // push a new matrix for every line
401 // translate
402 glTranslated(mySymbolPosition.x(), mySymbolPosition.y(), 0);
403 // rotate over lane
405 // draw line with a color depending of the selection status
406 if (drawUsingSelectColor()) {
407 GLHelper::drawText(lines[i].c_str(), Position(1.2, (double)i), .1, 1.f, color, 0, FONS_ALIGN_LEFT);
408 } else {
409 GLHelper::drawText(lines[i].c_str(), Position(1.2, (double)i), .1, 1.f, color, 0, FONS_ALIGN_LEFT);
410 }
411 // pop matrix for every line
413 }
414 }
415}
416
417
418void
420 const RGBColor& baseColor, const RGBColor& signColor, const std::string& word) const {
421 // only draw in level 2
423 // calculate middle point
424 const double middlePoint = (myAdditionalGeometry.getShape().length2D() * 0.5);
425 // calculate rotation
426 const double rotSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
427 const double rot = (myAdditionalGeometry.getShape().size() <= 1) ? 0 : myAdditionalGeometry.getShape().rotationDegreeAtOffset(middlePoint) - 180. * rotSign;
428 // push matrix
430 // Start drawing sign traslating matrix to signal position
431 glTranslated(mySymbolPosition.x(), mySymbolPosition.y(), 0);
432 // rotate over lane
434 // scale matrix depending of the exaggeration
435 glScaled(exaggeration, exaggeration, 1);
436 // set color
437 GLHelper::setColor(baseColor);
438 // Draw circle
440 // continue depending of rectangle selection
442 // Traslate to front
443 glTranslated(0, 0, .1);
444 // set color
445 GLHelper::setColor(signColor);
446 // draw another circle in the same position, but a little bit more small
448 // draw H depending of detailSettings
450 }
451 // pop draw matrix
453 }
454}
455
456
457void
459 const double width, const double exaggeration, const bool movingGeometryPoints) const {
460 // check if we're calculating the contour or the moving geometry points
461 if (movingGeometryPoints) {
465 }
466 if (movingGeometryPoints && (myEndPosPosOverLane != INVALID_DOUBLE)) {
469 }
470 } else {
471 // don't exaggerate contour
473 nullptr, getParentLanes().front()->getParentEdge());
475 exaggeration, getParentLanes().front()->getParentEdge());
476 }
477}
478
479/****************************************************************************/
@ 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:46
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
const std::string getID() const
get ID (all Attribute Carriers have one)
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
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)
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool isStoppingPlaceValid(SumoXMLAttr key, const std::string &value) const
void setStoppingPlaceAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
double myEndPosPosOverLane
The end position over lane.
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this stoppingPlace
void writeStoppingPlaceAttributes(OutputDevice &device) const
write common stoppingPlace attributes
Position getPositionInView() const
Returns position of additional in view.
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
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
void drawLines(const GUIVisualizationSettings::Detail d, const std::vector< std::string > &lines, const RGBColor &color) const
draw lines
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Position mySymbolPosition
The position of the sign.
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
double myStartPosOverLane
The start position over lane.
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
bool isAttributeEnabled(SumoXMLAttr key) const
GNEContour mySymbolContour
circle contour
Position getStoppingPlaceAttributePosition(SumoXMLAttr key) const
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
std::string getParentName() const
Returns the name of the parent object (if any)
bool checkDrawMoveContour() const override
check if draw move contour (red)
std::string getStoppingPlaceAttribute(SumoXMLAttr key) const
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 SumoXMLAttr attr, const T &val)
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:198
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