Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEAccess.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//
19/****************************************************************************/
20#include <config.h>
21
24#include <netedit/GNENet.h>
28
29#include "GNEAccess.h"
31
32// ===========================================================================
33// member method definitions
34// ===========================================================================
35
36#ifdef _MSC_VER
37#pragma warning(push)
38#pragma warning(disable: 4355) // mask warning about "this" in initializers
39#endif
42 myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
43 GNEMoveElementLaneSingle::PositionType::SINGLE)) {
44}
45
46
47GNEAccess::GNEAccess(GNEAdditional* busStop, GNELane* lane, const double pos, const std::string& specialPos,
48 const bool friendlyPos, const double length, const Parameterised::Map& parameters) :
49 GNEAdditional(busStop, SUMO_TAG_ACCESS, ""),
50 Parameterised(parameters),
51 myPosOverLane(pos),
52 myFriendlyPos(friendlyPos),
53 myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
54 GNEMoveElementLaneSingle::PositionType::SINGLE)),
55 mySpecialPosition(specialPos),
56 myLength(length) {
57 // set parents
58 setParent<GNELane*>(lane);
59 setParent<GNEAdditional*>(busStop);
60 // update centering boundary without updating grid
62}
63#ifdef _MSC_VER
64#pragma warning(pop)
65#endif
66
67
71
72
77
78
81 return this;
82}
83
84
85const Parameterised*
87 return this;
88}
89
90
91void
93 // set start position
94 double fixedPositionOverLane;
95 if (myPosOverLane < 0) {
96 fixedPositionOverLane = 0;
97 } else if (myPosOverLane > getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength()) {
98 fixedPositionOverLane = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
99 } else {
100 fixedPositionOverLane = myPosOverLane;
101 }
102 // update geometry
103 myAdditionalGeometry.updateGeometry(getParentLanes().front()->getLaneShape(), fixedPositionOverLane * getParentLanes().front()->getLengthGeometryFactor(), myMoveElementLaneSingle->myMovingLateralOffset);
104}
105
106
111
112
113void
114GNEAccess::updateCenteringBoundary(const bool /*updateGrid*/) {
115 // nothing to update
116}
117
118
119void
120GNEAccess::splitEdgeGeometry(const double splitPosition, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* newElement, GNEUndoList* undoList) {
121 if (splitPosition < myPosOverLane) {
122 // change lane
123 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
124 // now adjust start position
125 setAttribute(SUMO_ATTR_POSITION, toString(myPosOverLane - splitPosition), undoList);
126 }
127}
128
129
130bool
132 // with friendly position enabled position are "always fixed"
133 if (myFriendlyPos) {
134 return true;
135 } else {
137 return (myPosOverLane >= 0) && (myPosOverLane <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
138 } else {
139 return false;
140 }
141 }
142}
143
144
145void
147 device.openTag(SUMO_TAG_ACCESS);
148 // write common additional attributes
150 // write move attributes
152 // write specific attributes
153 if (myLength != -1) {
155 }
156 device.closeTag();
157}
158
159
160bool
162 // only movement problems
164}
165
166
167std::string
169 // only movement problems
171}
172
173
174void
176 // only movement problems
178}
179
180
181bool
183 // get edit modes
184 const auto& editModes = myNet->getViewNet()->getEditModes();
185 // check if we're in move mode
186 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
188 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
189 // only move the first element
191 } else {
192 return false;
193 }
194}
195
196
197GNEEdge*
199 return getParentLanes().front()->getParentEdge();
200}
201
202
203std::string
205 return getParentAdditionals().at(0)->getID();
206}
207
208
209void
211 // first check if additional has to be drawn
213 // Obtain exaggeration
214 const double accessExaggeration = getExaggeration(s);
215 // adjust radius depending of mode and distance to mouse position
216 double radius = 0.5;
219 radius = 1;
220 }
221 // get detail level
222 const auto d = s.getDetailLevel(1);
223 // draw geometry only if we'rent in drawForObjectUnderCursor mode
225 // get color
226 RGBColor accessColor;
227 if (drawUsingSelectColor()) {
229 } else if (!getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR).empty()) {
230 accessColor = parse<RGBColor>(getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR));
231 } else if (getParentAdditionals().front()->getTagProperty()->getTag() == SUMO_TAG_CONTAINER_STOP) {
232 accessColor = s.colorSettings.containerStopColor;
233 } else {
234 accessColor = s.colorSettings.busStopColor;
235 }
236 // draw parent and child lines
237 drawParentChildLines(s, accessColor);
238 // push layer matrix
240 // translate to front
242 // set color
243 GLHelper::setColor(accessColor);
244 // translate to geometry position
245 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
246 // draw circle
247 GLHelper::drawFilledCircleDetailled(d, radius * accessExaggeration);
248 // pop layer matrix
250 // draw lock icon
251 GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().front(), accessExaggeration, 0.3);
252 // draw dotted contour
254 }
255 // calculate contour
257 accessExaggeration, getParentLanes().front()->getParentEdge());
258 }
259}
260
261
262std::string
264 switch (key) {
265 case SUMO_ATTR_ID:
266 return getParentAdditionals().front()->getID();
269 return mySpecialPosition;
270 } else {
272 }
273 case SUMO_ATTR_LENGTH:
274 if (myLength == -1) {
275 return "";
276 } else {
277 return toString(myLength);
278 }
279 case GNE_ATTR_PARENT:
280 if (isTemplate()) {
281 return "";
282 } else {
283 return getParentAdditionals().at(0)->getID();
284 }
286 return "";
287 default:
289 }
290}
291
292
293double
297
298
303
304
309
310
311void
312GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
313 switch (key) {
314 case SUMO_ATTR_LENGTH:
315 case GNE_ATTR_PARENT:
317 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
318 break;
319 default:
320 myMoveElementLaneSingle->setMovingAttribute(key, value, undoList);
321 break;
322 }
323}
324
325
326bool
327GNEAccess::isValid(SumoXMLAttr key, const std::string& value) {
328 switch (key) {
329 case SUMO_ATTR_LANE: {
330 // check lane
332 return false;
333 } else {
334 // check if exist another access for the same parent in the given edge
335 const auto lane = myNet->getAttributeCarriers()->retrieveLane(value);
336 return GNEAdditionalHandler::accessExists(getParentAdditionals().at(0), lane->getParentEdge());
337 }
338 }
340 if (value.empty() || (value == "random") || (value == "doors") || (value == "carriage")) {
341 return true;
342 } else {
344 }
345 case SUMO_ATTR_LENGTH:
346 if (canParse<double>(value)) {
347 const double valueDouble = parse<double>(value);
348 return (valueDouble == -1) || (valueDouble >= 0);
349 } else {
350 return false;
351 }
352 case GNE_ATTR_PARENT:
353 return (myNet->getAttributeCarriers()->retrieveAdditionals(NamespaceIDs::busStops, value, false) != nullptr);
354 default:
356 }
357}
358
359
360std::string
362 return getTagStr();
363}
364
365
366std::string
368 return getTagStr() + ": " + getParentLanes().front()->getParentEdge()->getID();
369}
370
371// ===========================================================================
372// private
373// ===========================================================================
374
375void
376GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value) {
377 switch (key) {
378 case SUMO_ATTR_LANE:
380 break;
382 if (value.empty()) {
383 myPosOverLane = 0;
384 } else if (value == "random" || value == "doors" || value == "carriage") {
386 mySpecialPosition = value;
387 } else {
389 }
390 break;
391 case SUMO_ATTR_LENGTH:
392 if (value.empty()) {
394 } else {
395 myLength = parse<double>(value);
396 }
397 break;
398 case GNE_ATTR_PARENT:
399 if (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_BUS_STOP, value, false) != nullptr) {
401 } else if (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_TRAIN_STOP, value, false) != nullptr) {
403 } else {
405 }
406 break;
409 break;
410 default:
412 break;
413 }
414}
415
416/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ GLO_ACCESS
a Acces
@ SUMO_TAG_ACCESS
An access point for a train stop.
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_TRAIN_STOP
A train stop (alias for bus stop)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LANE
@ GNE_ATTR_PARENT
parent of an additional element
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
@ 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
std::string getParentName() const override
Returns the name (ID) of the parent object.
~GNEAccess()
Destructor.
Definition GNEAccess.cpp:68
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this access
Definition GNEAccess.cpp:74
Position getPositionInView() const override
Returns position of additional in view.
Position getAttributePosition(SumoXMLAttr key) const override
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
void fixAdditionalProblem() override
fix additional problem (must be reimplemented in all detector children)
GNEMoveElementLaneSingle * myMoveElementLaneSingle
move element lane single
Definition GNEAccess.h:192
double getAttributeDouble(SumoXMLAttr key) const override
std::string getAttribute(SumoXMLAttr key) const override
std::string getAdditionalProblem() const override
return a string with the current additional problem (must be reimplemented in all detector children)
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
bool isAccessPositionFixed() const
check if Position of Access is fixed
double myPosOverLane
position over lane
Definition GNEAccess.h:186
bool checkDrawMoveContour() const override
check if draw move contour (red)
GNEEdge * getEdge() const
get edge in which this Access is placed
GNEAccess(GNENet *net)
Default constructor.
Definition GNEAccess.cpp:40
bool myFriendlyPos
friendly position
Definition GNEAccess.h:189
void updateGeometry() override
update pre-computed geometry information
Definition GNEAccess.cpp:92
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
std::string mySpecialPosition
position over lane
Definition GNEAccess.h:195
double myLength
Access length.
Definition GNEAccess.h:198
bool isValid(SumoXMLAttr key, const std::string &value) override
Parameterised * getParameters() override
get parameters associated with this access
Definition GNEAccess.cpp:80
bool isAdditionalValid() const override
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
static bool accessExists(const GNEAdditional *stoppingPlaceParent, const GNEEdge *edge)
check if a GNEAccess can be created in the given edge
double getExaggeration(const GUIVisualizationSettings &s) const override
return exaggeration associated with this GLObject
void replaceAdditionalParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace additional parent
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
void writeAdditionalAttributes(OutputDevice &device) const
write common additional attributes
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
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.
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * myNet
pointer to net
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 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)
bool drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
draw dotted contours (basics, select, delete, inspect...)
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const GNEHierarchicalContainerParents< GNELane * > & getParentLanes() const
get parent lanes
double myMovingLateralOffset
move element lateral offset
bool isMoveElementValid() const
check if current moving element is valid to be written into XML
double getMovingAttributeDouble(SumoXMLAttr key) const override
get moving attribute double
std::string getMovingProblem() const
return a string with the current moving problem
std::string getMovingAttribute(SumoXMLAttr key) const override
get moving attribute
void setMovingAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
set moving attribute (using undo-list)
bool isMovingAttributeValid(SumoXMLAttr key, const std::string &value) const override
check if the given moving attribute is valid
void writeMoveAttributes(OutputDevice &device) const
write move attributes
Position getMovingAttributePosition(SumoXMLAttr key) const override
get moving attribute position
void fixMovingProblem()
fix moving problem
GNELane * retrieveLane(const std::string &id, bool hardFail=true, bool checkVolatileChange=false) const
get lane by id
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
GNEAdditional * retrieveAdditionals(const std::vector< SumoXMLTag > types, const std::string &id, bool hardFail=true) const
Returns the named additional.
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:174
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
double getDefaultDoubleValue(SumoXMLAttr attr) const
get default double value
const GUIGlObject * getGUIGlObjectFront() const
get front GUIGLObject or a pointer to nullptr
bool isCurrentlyMovingElements() const
check if an element is being moved
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
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
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape)
update entire geometry
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
Stores the information about how to visualize structures.
bool checkDrawAdditional(Detail d, const bool selected) const
check if draw additionals
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
static const std::vector< SumoXMLTag > busStops
busStops namespace
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
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 distanceSquaredTo2D(const Position &p2) const
returns the square of the distance to another position (Only using x and y positions)
Definition Position.h:278
A list of positions.
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
bool showAdditionals() const
check if additionals has to be drawn
bool isCurrentSupermodeNetwork() const
@check if current supermode is Network
GNENetworkElement * getEditedNetworkElement() const
pointer to edited network element
static void drawLockIcon(const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position position, const double exaggeration, const double size=0.5, const double offsetx=0, const double offsety=0)
draw lock icon
RGBColor containerStopColor
color for containerStops
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
RGBColor busStopColor
color for busStops
static const double segmentWidthSmall
width of small dotted contour segments