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-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//
19/****************************************************************************/
20#include <config.h>
21
24#include <netedit/GNENet.h>
28
29#include "GNEAccess.h"
31
32// ===========================================================================
33// member method definitions
34// ===========================================================================
35
41
42
43GNEAccess::GNEAccess(GNEAdditional* busStop, GNELane* lane, const double pos, const std::string& specialPos,
44 const bool friendlyPos, const double length, const Parameterised::Map& parameters) :
45 GNEAdditional(busStop, SUMO_TAG_ACCESS, ""),
46 Parameterised(parameters),
47 myPosOverLane(pos),
48 myFriendlyPos(friendlyPos),
50 GNEMoveElementLaneSingle::PositionType::SINGLE)),
51 mySpecialPosition(specialPos),
52 myLength(length) {
53 // set parents
56 // update centering boundary without updating grid
58}
59
60
64
65
70
71
74 return this;
75}
76
77
78const Parameterised*
80 return this;
81}
82
83
84void
86 // set start position
87 double fixedPositionOverLane;
88 if (myPosOverLane < 0) {
89 fixedPositionOverLane = 0;
90 } else if (myPosOverLane > getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength()) {
91 fixedPositionOverLane = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
92 } else {
93 fixedPositionOverLane = myPosOverLane;
94 }
95 // update geometry
96 myAdditionalGeometry.updateGeometry(getParentLanes().front()->getLaneShape(), fixedPositionOverLane * getParentLanes().front()->getLengthGeometryFactor(), myMoveElementLaneSingle->myMovingLateralOffset);
97}
98
99
102 return myAdditionalGeometry.getShape().getPolygonCenter();
103}
104
105
106void
107GNEAccess::updateCenteringBoundary(const bool /*updateGrid*/) {
108 // nothing to update
109}
110
111
112void
113GNEAccess::splitEdgeGeometry(const double splitPosition, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* newElement, GNEUndoList* undoList) {
114 if (splitPosition < myPosOverLane) {
115 // change lane
116 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
117 // now adjust start position
118 setAttribute(SUMO_ATTR_POSITION, toString(myPosOverLane - splitPosition), undoList);
119 }
120}
121
122
123bool
125 // with friendly position enabled position are "always fixed"
126 if (myFriendlyPos) {
127 return true;
128 } else {
130 return (myPosOverLane >= 0) && (myPosOverLane <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
131 } else {
132 return false;
133 }
134 }
135}
136
137
138void
140 device.openTag(SUMO_TAG_ACCESS);
141 // write common additional attributes
143 // write move attributes
144 myMoveElementLaneSingle->writeMoveAttributes(device);
145 // write specific attributes
146 if (myLength != -1) {
148 }
149 device.closeTag();
150}
151
152
153bool
155 // only movement problems
156 return myMoveElementLaneSingle->isMoveElementValid();
157}
158
159
160std::string
162 // only movement problems
163 return myMoveElementLaneSingle->getMovingProblem();
164}
165
166
167void
169 // only movement problems
170 myMoveElementLaneSingle->fixMovingProblem();
171}
172
173
174bool
176 // get edit modes
177 const auto& editModes = myNet->getViewNet()->getEditModes();
178 // check if we're in move mode
179 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
180 !myNet->getViewNet()->getEditNetworkElementShapes().getEditedNetworkElement() &&
181 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
182 // only move the first element
183 return myNet->getViewNet()->getViewObjectsSelector().getGUIGlObjectFront() == this;
184 } else {
185 return false;
186 }
187}
188
189
190GNEEdge*
192 return getParentLanes().front()->getParentEdge();
193}
194
195
196std::string
198 return getParentAdditionals().at(0)->getID();
199}
200
201
202void
204 // first check if additional has to be drawn
205 if (myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
206 // Obtain exaggeration
207 const double accessExaggeration = getExaggeration(s);
208 // adjust radius depending of mode and distance to mouse position
209 double radius = 0.5;
210 if (myNet->getViewNet()->getEditModes().isCurrentSupermodeNetwork() &&
211 myNet->getViewNet()->getPositionInformation().distanceSquaredTo2D(myAdditionalGeometry.getShape().front()) < 1) {
212 radius = 1;
213 }
214 // get detail level
215 const auto d = s.getDetailLevel(1);
216 // draw geometry only if we'rent in drawForObjectUnderCursor mode
218 // get color
219 RGBColor accessColor;
220 if (drawUsingSelectColor()) {
222 } else if (!getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR).empty()) {
224 } else if (getParentAdditionals().front()->getTagProperty()->getTag() == SUMO_TAG_CONTAINER_STOP) {
225 accessColor = s.colorSettings.containerStopColor;
226 } else {
227 accessColor = s.colorSettings.busStopColor;
228 }
229 // draw parent and child lines
230 drawParentChildLines(s, accessColor);
231 // push layer matrix
233 // translate to front
235 // set color
236 GLHelper::setColor(accessColor);
237 // translate to geometry position
238 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
239 // draw circle
240 GLHelper::drawFilledCircleDetailled(d, radius * accessExaggeration);
241 // pop layer matrix
243 // draw lock icon
244 GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().front(), accessExaggeration, 0.3);
245 // draw dotted contour
246 myAdditionalContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidthSmall, true);
247 }
248 // calculate contour
249 myAdditionalContour.calculateContourCircleShape(s, d, this, myAdditionalGeometry.getShape().front(), radius, getType(),
250 accessExaggeration, getParentLanes().front()->getParentEdge());
251 }
252}
253
254
255std::string
257 switch (key) {
258 case SUMO_ATTR_ID:
259 return getParentAdditionals().front()->getID();
262 return mySpecialPosition;
263 } else {
264 return myMoveElementLaneSingle->getMovingAttribute(key);
265 }
266 case SUMO_ATTR_LENGTH:
267 if (myLength == -1) {
268 return "";
269 } else {
270 return toString(myLength);
271 }
272 case GNE_ATTR_PARENT:
273 if (isTemplate()) {
274 return "";
275 } else {
276 return getParentAdditionals().at(0)->getID();
277 }
279 return "";
280 default:
281 return myMoveElementLaneSingle->getMovingAttribute(key);
282 }
283}
284
285
286double
288 return myMoveElementLaneSingle->getMovingAttributeDouble(key);
289}
290
291
294 return myMoveElementLaneSingle->getMovingAttributePosition(key);
295}
296
297
302
303
304void
305GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
306 switch (key) {
307 case SUMO_ATTR_LENGTH:
308 case GNE_ATTR_PARENT:
310 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
311 break;
312 default:
313 myMoveElementLaneSingle->setMovingAttribute(key, value, undoList);
314 break;
315 }
316}
317
318
319bool
320GNEAccess::isValid(SumoXMLAttr key, const std::string& value) {
321 switch (key) {
322 case SUMO_ATTR_LANE: {
323 // check lane
324 if (!myMoveElementLaneSingle->isMovingAttributeValid(key, value)) {
325 return false;
326 } else {
327 // check if exist another access for the same parent in the given edge
328 const auto lane = myNet->getAttributeCarriers()->retrieveLane(value);
329 return GNEAdditionalHandler::accessExists(getParentAdditionals().at(0), lane->getParentEdge());
330 }
331 }
333 if (value.empty() || (value == "random") || (value == "doors") || (value == "carriage")) {
334 return true;
335 } else {
336 return myMoveElementLaneSingle->isMovingAttributeValid(key, value);
337 }
338 case SUMO_ATTR_LENGTH:
339 if (canParse<double>(value)) {
340 const double valueDouble = parse<double>(value);
341 return (valueDouble == -1) || (valueDouble >= 0);
342 } else {
343 return false;
344 }
345 case GNE_ATTR_PARENT:
346 return (myNet->getAttributeCarriers()->retrieveAdditionals(NamespaceIDs::busStops, value, false) != nullptr);
347 default:
348 return myMoveElementLaneSingle->isMovingAttributeValid(key, value);
349 }
350}
351
352
353std::string
355 return getTagStr();
356}
357
358
359std::string
361 return getTagStr() + ": " + getParentLanes().front()->getParentEdge()->getID();
362}
363
364// ===========================================================================
365// private
366// ===========================================================================
367
368void
369GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value) {
370 switch (key) {
371 case SUMO_ATTR_LANE:
373 break;
375 if (value.empty()) {
376 myPosOverLane = 0;
377 } else if (value == "random" || value == "doors" || value == "carriage") {
380 } else {
381 myMoveElementLaneSingle->setMovingAttribute(key, value);
382 }
383 break;
384 case SUMO_ATTR_LENGTH:
385 if (value.empty()) {
386 myLength = myTagProperty->getDefaultDoubleValue(key);
387 } else {
389 }
390 break;
391 case GNE_ATTR_PARENT:
392 if (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_BUS_STOP, value, false) != nullptr) {
394 } else if (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_TRAIN_STOP, value, false) != nullptr) {
396 } else {
398 }
399 break;
402 break;
403 default:
404 myMoveElementLaneSingle->setMovingAttribute(key, value);
405 break;
406 }
407}
408
409/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ GLO_ACCESS
a Acces
const std::string invalid_return< std::string >::value
@ 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:46
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:653
static void popMatrix()
pop matrix
Definition GLHelper.cpp:135
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:538
static void pushMatrix()
push matrix
Definition GLHelper.cpp:122
std::string getParentName() const override
Returns the name (ID) of the parent object.
~GNEAccess()
Destructor.
Definition GNEAccess.cpp:61
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this access
Definition GNEAccess.cpp:67
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:36
bool myFriendlyPos
friendly position
Definition GNEAccess.h:189
void updateGeometry() override
update pre-computed geometry information
Definition GNEAccess.cpp:85
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:73
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
GNEAdditional(const std::string &id, GNENet *net, const std::string &filename, SumoXMLTag tag, const std::string &additionalName)
Constructor.
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)
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc....
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
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
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
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
void setParent(ParentType parent)
edit parent and childrens without maintain integrity (use carefully)
const GNEHierarchicalContainerParents< GNELane * > & getParentLanes() const
get parent lanes
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
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 & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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
Parameterised()
Default constructor.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
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