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#include <config.h>
21
25#include <netedit/GNENet.h>
30
31#include "GNEStoppingPlace.h"
32
33// ===========================================================================
34// member method definitions
35// ===========================================================================
36
38 GNEAdditional("", net, "", tag, ""),
39 myMoveElementLaneDouble(new GNEMoveElementLaneDouble(this, SUMO_ATTR_STARTPOS, myStartPosOverLane,
40 SUMO_ATTR_ENDPOS, myEndPosPosOverLane, myFriendlyPosition)) {
41}
42
43
44GNEStoppingPlace::GNEStoppingPlace(const std::string& id, GNENet* net, const std::string& filename,
45 SumoXMLTag tag, GNELane* lane, const double startPos, const double endPos,
46 const std::string& name, bool friendlyPosition, const RGBColor& color,
47 const double angle, const Parameterised::Map& parameters) :
48 GNEAdditional(id, net, filename, tag, name),
49 Parameterised(parameters),
50 myStartPosOverLane(startPos),
51 myEndPosPosOverLane(endPos),
52 myFriendlyPosition(friendlyPosition),
53 myColor(color),
54 myAngle(angle),
55 myMoveElementLaneDouble(new GNEMoveElementLaneDouble(this, SUMO_ATTR_STARTPOS, myStartPosOverLane,
56 SUMO_ATTR_ENDPOS, myEndPosPosOverLane, myFriendlyPosition)) {
57 // set parents
58 setParent<GNELane*>(lane);
59}
60
61
65
66
71
72
75 return this;
76}
77
78
79const Parameterised*
81 return this;
82}
83
84
85bool
87 // only movement problems
89}
90
91
92std::string
94 // only movement problems
96}
97
98
99void
101 // only movement problems
103}
104
105
106bool
108 // get edit modes
109 const auto& editModes = myNet->getViewNet()->getEditModes();
110 // check if we're in move mode
111 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
113 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
114 // only move the first element
116 } else {
117 return false;
118 }
119}
120
121
126
127
128void
130 // nothing to do
131}
132
133
134void
135GNEStoppingPlace::splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) {
136 // first check tat both network elements are lanes and originalElement correspond to stoppingPlace lane
137 if ((originalElement->getTagProperty()->getTag() == SUMO_TAG_LANE) &&
138 (newElement->getTagProperty()->getTag() == SUMO_TAG_LANE) &&
139 (getParentLanes().front() == originalElement)) {
140 // check if we have to change additional lane depending of split position
142 // calculate middle position
143 const double middlePosition = ((myEndPosPosOverLane - myStartPosOverLane) / 2.0) + myStartPosOverLane;
144 // four cases:
145 if (splitPosition < myStartPosOverLane) {
146 // change lane
147 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
148 // now adjust start and end position
149 setAttribute(SUMO_ATTR_STARTPOS, toString(myStartPosOverLane - splitPosition), undoList);
150 setAttribute(SUMO_ATTR_ENDPOS, toString(myEndPosPosOverLane - splitPosition), undoList);
151 } else if ((splitPosition > myStartPosOverLane) && (splitPosition < middlePosition)) {
152 // change lane
153 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
154 // now adjust start and end position
155 setAttribute(SUMO_ATTR_STARTPOS, "0", undoList);
156 setAttribute(SUMO_ATTR_ENDPOS, toString(myEndPosPosOverLane - splitPosition), undoList);
157 } else if ((splitPosition > middlePosition) && (splitPosition < myEndPosPosOverLane)) {
158 // only adjust end position
159 setAttribute(SUMO_ATTR_ENDPOS, toString(splitPosition), undoList);
160 } else if ((splitPosition > myEndPosPosOverLane)) {
161 // nothing to do
162 }
163 } else if ((myStartPosOverLane != INVALID_DOUBLE) && (splitPosition < myStartPosOverLane)) {
164 // change lane
165 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
166 // now adjust start position
167 setAttribute(SUMO_ATTR_STARTPOS, toString(myEndPosPosOverLane - splitPosition), undoList);
168 } else if ((myEndPosPosOverLane != INVALID_DOUBLE) && (splitPosition < myEndPosPosOverLane)) {
169 // change lane
170 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
171 // now adjust end position
172 setAttribute(SUMO_ATTR_ENDPOS, toString(myEndPosPosOverLane - splitPosition), undoList);
173 }
174 }
175}
176
177
178std::string
180 return getParentLanes().front()->getID();
181}
182
183
184void
186 // write common additional attributes
188 // write move atributes
190 // color (if defined)
191 if (getAttribute(SUMO_ATTR_COLOR).size() > 0) {
193 }
194 // angle (if defined)
195 if (myAngle != 0) {
197 }
198}
199
200
201std::string
203 switch (key) {
204 case SUMO_ATTR_ID:
205 return getMicrosimID();
206 case SUMO_ATTR_NAME:
207 return myAdditionalName;
208 case SUMO_ATTR_COLOR:
210 return "";
211 } else {
212 return toString(myColor);
213 }
214 case SUMO_ATTR_ANGLE:
215 return toString(myAngle);
216 default:
218 }
219}
220
221
222double
224 switch (key) {
225 case SUMO_ATTR_ANGLE:
226 return myAngle;
227 default:
229 }
230}
231
232
237
238
239void
240GNEStoppingPlace::setStoppingPlaceAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
241 switch (key) {
242 case SUMO_ATTR_ID:
243 case SUMO_ATTR_NAME:
244 case SUMO_ATTR_COLOR:
245 case SUMO_ATTR_ANGLE:
246 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
247 break;
248 default:
249 myMoveElementLaneDouble->setMovingAttribute(key, value, undoList);
250 break;
251 }
252}
253
254
255bool
256GNEStoppingPlace::isStoppingPlaceValid(SumoXMLAttr key, const std::string& value) const {
257 switch (key) {
258 case SUMO_ATTR_ID:
261 } else {
262 return isValidAdditionalID(value);
263 }
264 case SUMO_ATTR_NAME:
266 case SUMO_ATTR_COLOR:
267 if (value.empty()) {
268 return true;
269 } else {
270 return canParse<RGBColor>(value);
271 }
272 case SUMO_ATTR_ANGLE:
273 if (value.empty()) {
274 return true;
275 } else {
276 return canParse<double>(value);
277 }
278 default:
280 }
281}
282
283
284void
286 switch (key) {
287 case SUMO_ATTR_ID:
288 // update microsimID
289 setAdditionalID(value);
290 break;
291 case SUMO_ATTR_LANE:
292 // set hier because GNEHierarchicalElement is a template
294 break;
295 case SUMO_ATTR_NAME:
296 myAdditionalName = value;
297 break;
298 case SUMO_ATTR_COLOR:
299 if (value.empty()) {
301 } else {
302 myColor = GNEAttributeCarrier::parse<RGBColor>(value);
303 }
304 break;
305 case SUMO_ATTR_ANGLE:
306 if (value.empty()) {
307 myAngle = 0;
308 } else {
309 myAngle = GNEAttributeCarrier::parse<double>(value);
310 }
311 break;
312 // special attributes used during creation or edition
314 // set hier because GNEHierarchicalElement is a template
316 break;
317 default:
319 break;
320 }
321}
322
323
324void
326 if (getParentLanes().empty() || getParentLanes().front() == nullptr) {
327 // may happen during initialization
328 return;
329 }
330 // Get value of option "lefthand"
331 const bool lefthandAttr = hasAttribute(SUMO_ATTR_LEFTHAND) && parse<bool>(getAttribute(SUMO_ATTR_LEFTHAND));
332 const double offsetSign = OptionsCont::getOptions().getBool("lefthand") != lefthandAttr ? -1 : 1;
333
334 // obtain laneShape
335 PositionVector laneShape = getParentLanes().front()->getLaneShape();
336
337 // Move shape to side
338 laneShape.move2side(movingToSide * offsetSign);
339
340 // Cut shape using as delimitators fixed start position and fixed end position
342}
343
344
349
350
355
356
357bool
359 switch (key) {
361 if (isTemplate()) {
362 return true;
363 } else {
365 }
366 case GNE_ATTR_SIZE:
367 if (isTemplate()) {
368 return true;
369 } else {
371 }
372 default:
373 return true;
374 }
375}
376
377
378std::string
380 return getTagStr() + ": " + getID();
381}
382
383
384std::string
388
389
390void
391GNEStoppingPlace::drawLines(const GUIVisualizationSettings::Detail d, const std::vector<std::string>& lines, const RGBColor& color) const {
392 // only draw in level 1
394 // calculate middle point
395 const double middlePoint = (myAdditionalGeometry.getShape().length2D() * 0.5);
396 // calculate rotation
397 const double rot = (myAdditionalGeometry.getShape().size() <= 1) ? 0 : myAdditionalGeometry.getShape().rotationDegreeAtOffset(middlePoint);
398 // Iterate over every line
399 for (int i = 0; i < (int)lines.size(); ++i) {
400 // push a new matrix for every line
402 // translate
403 glTranslated(mySymbolPosition.x(), mySymbolPosition.y(), 0);
404 // rotate over lane
406 // draw line with a color depending of the selection status
407 if (drawUsingSelectColor()) {
408 GLHelper::drawText(lines[i].c_str(), Position(1.2, (double)i), .1, 1.f, color, 0, FONS_ALIGN_LEFT);
409 } else {
410 GLHelper::drawText(lines[i].c_str(), Position(1.2, (double)i), .1, 1.f, color, 0, FONS_ALIGN_LEFT);
411 }
412 // pop matrix for every line
414 }
415 }
416}
417
418
419void
421 const RGBColor& baseColor, const RGBColor& signColor, const std::string& word) const {
422 // only draw in level 2
424 // calculate middle point
425 const double middlePoint = (myAdditionalGeometry.getShape().length2D() * 0.5);
426 // calculate rotation
427 const double rotSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
428 const double rot = (myAdditionalGeometry.getShape().size() <= 1) ? 0 : myAdditionalGeometry.getShape().rotationDegreeAtOffset(middlePoint) - 180. * rotSign;
429 // push matrix
431 // Start drawing sign traslating matrix to signal position
432 glTranslated(mySymbolPosition.x(), mySymbolPosition.y(), 0);
433 // rotate over lane
435 // scale matrix depending of the exaggeration
436 glScaled(exaggeration, exaggeration, 1);
437 // set color
438 GLHelper::setColor(baseColor);
439 // Draw circle
441 // continue depending of rectangle selection
443 // Traslate to front
444 glTranslated(0, 0, .1);
445 // set color
446 GLHelper::setColor(signColor);
447 // draw another circle in the same position, but a little bit more small
449 // draw H depending of detailSettings
451 }
452 // pop draw matrix
454 }
455}
456
457
458void
460 const double width, const double exaggeration, const bool movingGeometryPoints) const {
461 // check if we're calculating the contour or the moving geometry points
462 if (movingGeometryPoints) {
466 }
467 if (movingGeometryPoints && (myEndPosPosOverLane != INVALID_DOUBLE)) {
470 }
471 } else {
472 // don't exaggerate contour
474 nullptr, getParentLanes().front()->getParentEdge());
476 exaggeration, getParentLanes().front()->getParentEdge());
477 }
478}
479
480/****************************************************************************/
@ 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
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)
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
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 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