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
23#include <netedit/GNENet.h>
27
28#include "GNEAccess.h"
30
31// ===========================================================================
32// member method definitions
33// ===========================================================================
34
36 GNEAdditional("", net, "", SUMO_TAG_ACCESS, ""),
37 myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
38 GNEMoveElementLaneSingle::PositionType::SINGLE)) {
39}
40
41
42GNEAccess::GNEAccess(GNEAdditional* busStop, GNELane* lane, const double pos, const std::string& specialPos,
43 const bool friendlyPos, const double length, const Parameterised::Map& parameters) :
44 GNEAdditional(busStop, SUMO_TAG_ACCESS, ""),
45 Parameterised(parameters),
46 myPosOverLane(pos),
47 myFriendlyPos(friendlyPos),
48 myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
49 GNEMoveElementLaneSingle::PositionType::SINGLE)),
50 mySpecialPosition(specialPos),
51 myLength(length) {
52 // set parents
53 setParent<GNELane*>(lane);
54 setParent<GNEAdditional*>(busStop);
55 // update centering boundary without updating grid
57}
58
59
63
64
69
70
73 return this;
74}
75
76
77const Parameterised*
79 return this;
80}
81
82
83void
85 // set start position
86 double fixedPositionOverLane;
87 if (myPosOverLane < 0) {
88 fixedPositionOverLane = 0;
89 } else if (myPosOverLane > getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength()) {
90 fixedPositionOverLane = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
91 } else {
92 fixedPositionOverLane = myPosOverLane;
93 }
94 // update geometry
95 myAdditionalGeometry.updateGeometry(getParentLanes().front()->getLaneShape(), fixedPositionOverLane * getParentLanes().front()->getLengthGeometryFactor(), myMoveElementLaneSingle->myMovingLateralOffset);
96}
97
98
103
104
105void
106GNEAccess::updateCenteringBoundary(const bool /*updateGrid*/) {
107 // nothing to update
108}
109
110
111void
112GNEAccess::splitEdgeGeometry(const double splitPosition, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* newElement, GNEUndoList* undoList) {
113 if (splitPosition < myPosOverLane) {
114 // change lane
115 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
116 // now adjust start position
117 setAttribute(SUMO_ATTR_POSITION, toString(myPosOverLane - splitPosition), undoList);
118 }
119}
120
121
122bool
124 // with friendly position enabled position are "always fixed"
125 if (myFriendlyPos) {
126 return true;
127 } else {
129 return (myPosOverLane >= 0) && (myPosOverLane <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
130 } else {
131 return false;
132 }
133 }
134}
135
136
137void
139 device.openTag(SUMO_TAG_ACCESS);
140 // write common additional attributes
142 // write move attributes
144 // write specific attributes
145 if (myLength != -1) {
147 }
148 device.closeTag();
149}
150
151
152bool
154 // only movement problems
156}
157
158
159std::string
161 // only movement problems
163}
164
165
166void
168 // only movement problems
170}
171
172
173bool
175 // get edit modes
176 const auto& editModes = myNet->getViewNet()->getEditModes();
177 // check if we're in move mode
178 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
180 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
181 // only move the first element
183 } else {
184 return false;
185 }
186}
187
188
189GNEEdge*
191 return getParentLanes().front()->getParentEdge();
192}
193
194
195std::string
197 return getParentAdditionals().at(0)->getID();
198}
199
200
201void
203 // first check if additional has to be drawn
205 // Obtain exaggeration
206 const double accessExaggeration = getExaggeration(s);
207 // adjust radius depending of mode and distance to mouse position
208 double radius = 0.5;
211 radius = 1;
212 }
213 // get detail level
214 const auto d = s.getDetailLevel(1);
215 // draw geometry only if we'rent in drawForObjectUnderCursor mode
217 // get color
218 RGBColor accessColor;
219 if (drawUsingSelectColor()) {
221 } else if (!getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR).empty()) {
222 accessColor = parse<RGBColor>(getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR));
223 } else if (getParentAdditionals().front()->getTagProperty()->getTag() == SUMO_TAG_CONTAINER_STOP) {
224 accessColor = s.colorSettings.containerStopColor;
225 } else {
226 accessColor = s.colorSettings.busStopColor;
227 }
228 // draw parent and child lines
229 drawParentChildLines(s, accessColor);
230 // push layer matrix
232 // translate to front
234 // set color
235 GLHelper::setColor(accessColor);
236 // translate to geometry position
237 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
238 // draw circle
239 GLHelper::drawFilledCircleDetailled(d, radius * accessExaggeration);
240 // pop layer matrix
242 // draw lock icon
243 GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().front(), accessExaggeration, 0.3);
244 // draw dotted contour
246 }
247 // calculate contour
249 accessExaggeration, getParentLanes().front()->getParentEdge());
250 }
251}
252
253
254std::string
256 switch (key) {
257 case SUMO_ATTR_ID:
258 return getParentAdditionals().front()->getID();
261 return mySpecialPosition;
262 } else {
264 }
265 case SUMO_ATTR_LENGTH:
266 if (myLength == -1) {
267 return "";
268 } else {
269 return toString(myLength);
270 }
271 case GNE_ATTR_PARENT:
272 if (isTemplate()) {
273 return "";
274 } else {
275 return getParentAdditionals().at(0)->getID();
276 }
278 return "";
279 default:
281 }
282}
283
284
285double
289
290
295
296
301
302
303void
304GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
305 switch (key) {
306 case SUMO_ATTR_LENGTH:
307 case GNE_ATTR_PARENT:
309 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
310 break;
311 default:
312 myMoveElementLaneSingle->setMovingAttribute(key, value, undoList);
313 break;
314 }
315}
316
317
318bool
319GNEAccess::isValid(SumoXMLAttr key, const std::string& value) {
320 switch (key) {
321 case SUMO_ATTR_LANE: {
322 // check lane
324 return false;
325 } else {
326 // check if exist another access for the same parent in the given edge
327 const auto lane = myNet->getAttributeCarriers()->retrieveLane(value);
328 return GNEAdditionalHandler::accessExists(getParentAdditionals().at(0), lane->getParentEdge());
329 }
330 }
332 if (value.empty() || (value == "random") || (value == "doors") || (value == "carriage")) {
333 return true;
334 } else {
336 }
337 case SUMO_ATTR_LENGTH:
338 if (canParse<double>(value)) {
339 const double valueDouble = parse<double>(value);
340 return (valueDouble == -1) || (valueDouble >= 0);
341 } else {
342 return false;
343 }
344 case GNE_ATTR_PARENT:
345 return (myNet->getAttributeCarriers()->retrieveAdditionals(NamespaceIDs::busStops, value, false) != nullptr);
346 default:
348 }
349}
350
351
352std::string
354 return getTagStr();
355}
356
357
358std::string
360 return getTagStr() + ": " + getParentLanes().front()->getParentEdge()->getID();
361}
362
363// ===========================================================================
364// private
365// ===========================================================================
366
367void
368GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value) {
369 switch (key) {
370 case SUMO_ATTR_LANE:
372 break;
374 if (value.empty()) {
375 myPosOverLane = 0;
376 } else if (value == "random" || value == "doors" || value == "carriage") {
378 mySpecialPosition = value;
379 } else {
381 }
382 break;
383 case SUMO_ATTR_LENGTH:
384 if (value.empty()) {
386 } else {
387 myLength = parse<double>(value);
388 }
389 break;
390 case GNE_ATTR_PARENT:
391 if (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_BUS_STOP, value, false) != nullptr) {
393 } else if (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_TRAIN_STOP, value, false) != nullptr) {
395 } else {
397 }
398 break;
401 break;
402 default:
404 break;
405 }
406}
407
408/****************************************************************************/
@ 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: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
~GNEAccess()
Destructor.
Definition GNEAccess.cpp:60
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this access
Definition GNEAccess.cpp:66
std::string getParentName() const
Returns the name (ID) of the parent object.
Position getAttributePosition(SumoXMLAttr key) const override
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
GNEMoveElementLaneSingle * myMoveElementLaneSingle
move element lane single
Definition GNEAccess.h:192
double getAttributeDouble(SumoXMLAttr key) const override
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
std::string getAttribute(SumoXMLAttr key) const override
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
bool isAccessPositionFixed() const
check if Position of Access is fixed
double myPosOverLane
position over lane
Definition GNEAccess.h:186
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
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:35
Position getPositionInView() const
Returns position of additional in view.
bool myFriendlyPos
friendly position
Definition GNEAccess.h:189
void updateGeometry() override
update pre-computed geometry information
Definition GNEAccess.cpp:84
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
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
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
Parameterised * getParameters() override
get parameters associated with this access
Definition GNEAccess.cpp:72
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
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
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
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.
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.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:144
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
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 & 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
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