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
22#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
25#include <netedit/GNEViewNet.h>
33
34#include "GNEAccess.h"
36
37// ===========================================================================
38// member method definitions
39// ===========================================================================
40
42 GNEAdditional("", net, "", SUMO_TAG_ACCESS, ""),
43 myPositionOverLane(0),
44 myLength(0),
45 myFriendlyPosition(false) {
46}
47
48
49GNEAccess::GNEAccess(GNEAdditional* busStop, GNELane* lane, const double pos, const std::string& specialPos,
50 const bool friendlyPos, const double length, const Parameterised::Map& parameters) :
51 GNEAdditional(busStop, SUMO_TAG_ACCESS, ""),
52 Parameterised(parameters),
53 myPositionOverLane(pos),
54 mySpecialPosition(specialPos),
55 myLength(length),
56 myFriendlyPosition(friendlyPos) {
57 // set parents
58 setParent<GNELane*>(lane);
59 setParent<GNEAdditional*>(busStop);
60 // update centering boundary without updating grid
62}
63
64
67
68
71 // return move operation for additional placed over shape
72 return new GNEMoveOperation(this, getParentLanes().front(), myPositionOverLane,
74}
75
76
77void
79 // set start position
80 double fixedPositionOverLane;
81 if (myPositionOverLane < 0) {
82 fixedPositionOverLane = 0;
83 } else if (myPositionOverLane > getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength()) {
84 fixedPositionOverLane = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
85 } else {
86 fixedPositionOverLane = myPositionOverLane;
87 }
88 // update geometry
89 myAdditionalGeometry.updateGeometry(getParentLanes().front()->getLaneShape(), fixedPositionOverLane * getParentLanes().front()->getLengthGeometryFactor(), myMoveElementLateralOffset);
90}
91
92
97
98
99void
100GNEAccess::updateCenteringBoundary(const bool /*updateGrid*/) {
101 // nothing to update
102}
103
104
105void
106GNEAccess::splitEdgeGeometry(const double splitPosition, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* newElement, GNEUndoList* undoList) {
107 if (splitPosition < myPositionOverLane) {
108 // change lane
109 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
110 // now adjust start position
111 setAttribute(SUMO_ATTR_POSITION, toString(myPositionOverLane - splitPosition), undoList);
112 }
113}
114
115
116bool
118 // with friendly position enabled position are "always fixed"
119 if (myFriendlyPosition) {
120 return true;
121 } else {
123 return (myPositionOverLane >= 0) && (myPositionOverLane <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
124 } else {
125 return false;
126 }
127 }
128}
129
130
131void
144
145
146bool
148 // with friendly position enabled position is "always fixed"
149 if (myFriendlyPosition) {
150 return true;
151 } else if (myPositionOverLane == INVALID_DOUBLE) {
152 return true;
153 } else {
154 return fabs(myPositionOverLane) <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
155 }
156}
157
158
160 // obtain final length
161 const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
162 // check if detector has a problem
164 return "";
165 } else {
166 // declare variable for error position
167 std::string errorPosition;
168 // check positions over lane
169 if (myPositionOverLane < 0) {
170 errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
171 }
172 if (myPositionOverLane > len) {
173 errorPosition = (toString(SUMO_ATTR_POSITION) + TL(" > lanes's length"));
174 }
175 return errorPosition;
176 }
177}
178
179
181 // declare new position
182 double newPositionOverLane = myPositionOverLane;
183 // declare new length (but unsed in this context)
184 double length = 0;
185 // fix pos and length with fixLanePosition
186 GNEAdditionalHandler::fixLanePosition(newPositionOverLane, length, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
187 // set new position
189}
190
191
192bool
194 // get edit modes
195 const auto& editModes = myNet->getViewNet()->getEditModes();
196 // check if we're in move mode
197 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
199 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
200 // only move the first element
202 } else {
203 return false;
204 }
205}
206
207
208GNEEdge*
210 return getParentLanes().front()->getParentEdge();
211}
212
213
214std::string
216 return getParentAdditionals().at(0)->getID();
217}
218
219
220void
222 // first check if additional has to be drawn
224 // Obtain exaggeration
225 const double accessExaggeration = getExaggeration(s);
226 // adjust radius depending of mode and distance to mouse position
227 double radius = 0.5;
230 radius = 1;
231 }
232 // get detail level
233 const auto d = s.getDetailLevel(1);
234 // draw geometry only if we'rent in drawForObjectUnderCursor mode
236 // get color
237 RGBColor accessColor;
238 if (drawUsingSelectColor()) {
240 } else if (!getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR).empty()) {
241 accessColor = parse<RGBColor>(getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR));
242 } else {
243 accessColor = s.colorSettings.busStopColor;
244 }
245 // draw parent and child lines
246 drawParentChildLines(s, accessColor);
247 // push layer matrix
249 // translate to front
251 // set color
252 GLHelper::setColor(accessColor);
253 // translate to geometry position
254 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
255 // draw circle
256 GLHelper::drawFilledCircleDetailled(d, radius * accessExaggeration);
257 // pop layer matrix
259 // draw lock icon
260 GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().front(), accessExaggeration, 0.3);
261 // draw dotted contour
263 }
264 // calculate contour
266 accessExaggeration, getParentLanes().front()->getParentEdge());
267 }
268}
269
270
271std::string
273 switch (key) {
274 case SUMO_ATTR_ID:
275 return getParentAdditionals().front()->getID();
276 case SUMO_ATTR_LANE:
277 return getParentLanes().front()->getID();
280 return mySpecialPosition;
281 } else {
283 }
284 case SUMO_ATTR_LENGTH:
285 if (myLength == -1) {
286 return "";
287 } else {
288 return toString(myLength);
289 }
292 case GNE_ATTR_PARENT:
293 if (isTemplate()) {
294 return "";
295 } else {
296 return getParentAdditionals().at(0)->getID();
297 }
299 return "";
300 default:
301 return getCommonAttribute(this, key);
302 }
303}
304
305
306double
308 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
309}
310
311
316
317
318void
319GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
320 switch (key) {
321 case SUMO_ATTR_LANE:
323 case SUMO_ATTR_LENGTH:
325 case GNE_ATTR_PARENT:
327 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
328 break;
329 default:
330 setCommonAttribute(key, value, undoList);
331 break;
332 }
333}
334
335
336bool
337GNEAccess::isValid(SumoXMLAttr key, const std::string& value) {
338 switch (key) {
339 case SUMO_ATTR_LANE: {
340 GNELane* lane = myNet->getAttributeCarriers()->retrieveLane(value, false);
341 if (lane != nullptr) {
342 if (getParentLanes().front()->getParentEdge()->getID() != lane->getParentEdge()->getID()) {
344 } else {
345 return true;
346 }
347 } else {
348 return false;
349 }
350 }
352 if (value.empty() || value == "random" || value == "doors" || value == "carriage") {
353 return true;
354 } else {
355 return canParse<double>(value);
356 }
357 case SUMO_ATTR_LENGTH:
358 if (canParse<double>(value)) {
359 const double valueDouble = parse<double>(value);
360 return (valueDouble == -1) || (valueDouble >= 0);
361 } else {
362 return false;
363 }
365 return canParse<bool>(value);
366 case GNE_ATTR_PARENT:
367 return (myNet->getAttributeCarriers()->retrieveAdditionals(NamespaceIDs::busStops, value, false) != nullptr);
368 default:
369 return isCommonValid(key, value);
370 }
371}
372
373
374std::string
376 return getTagStr();
377}
378
379
380std::string
382 return getTagStr() + ": " + getParentLanes().front()->getParentEdge()->getID();
383}
384
385// ===========================================================================
386// private
387// ===========================================================================
388
389void
390GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value) {
391 switch (key) {
392 case SUMO_ATTR_LANE:
394 break;
396 if (value.empty()) {
398 } else if (value == "random" || value == "doors" || value == "carriage") {
400 mySpecialPosition = value;
401 } else {
402 myPositionOverLane = parse<double>(value);
403 }
404 break;
405 case SUMO_ATTR_LENGTH:
406 if (value.empty()) {
408 } else {
409 myLength = parse<double>(value);
410 }
411 break;
413 myFriendlyPosition = parse<bool>(value);
414 break;
415 case GNE_ATTR_PARENT:
416 if (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_BUS_STOP, value, false) != nullptr) {
418 } else {
420 }
421 break;
424 break;
425 default:
426 setCommonAttribute(this, key, value);
427 break;
428 }
429}
430
431
432void
434 // change both position
435 myPositionOverLane = moveResult.newFirstPos;
436 // set lateral offset
438 // update geometry
440}
441
442
443void
445 // reset lateral offset
447 undoList->begin(this, "position of " + getTagStr());
448 // now adjust start position
449 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
450 // check if lane has to be changed
451 if (moveResult.newFirstLane) {
452 // set new lane
453 setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
454 }
455 // end change attribute
456 undoList->end();
457}
458
459
460/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ GLO_ACCESS
a Acces
#define TL(string)
Definition MsgHandler.h:305
@ SUMO_TAG_ACCESS
An access point for a train 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_FRIENDLY_POS
@ 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:64
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
~GNEAccess()
Destructor.
Definition GNEAccess.cpp:65
std::string getParentName() const
Returns the name (ID) of the parent object.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void updateGeometry()
update pre-computed geometry information
Definition GNEAccess.cpp:78
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
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool myFriendlyPosition
flag to check if friendly position is enabled
Definition GNEAccess.h:176
double getAttributeDouble(SumoXMLAttr key) const
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
GNEMoveOperation * getMoveOperation()
get move operation
Definition GNEAccess.cpp:70
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
GNEEdge * getEdge() const
get edge in which this Access is placed
GNEAccess(GNENet *net)
Default constructor.
Definition GNEAccess.cpp:41
const Parameterised::Map & getACParametersMap() const
get parameters map
std::string getAttribute(SumoXMLAttr key) const
Position getPositionInView() const
Returns position of additional in view.
Definition GNEAccess.cpp:94
std::string mySpecialPosition
position over lane
Definition GNEAccess.h:170
double myLength
Access length.
Definition GNEAccess.h:173
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
double myPositionOverLane
position over lane
Definition GNEAccess.h:167
bool checkDrawMoveContour() const
check if draw move contour (red)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
static bool accessCanBeCreated(GNEAdditional *busStopParent, GNEEdge *edge)
check if a GNEAccess can be created in a certain Edge
static bool checkLanePosition(double pos, const double length, const double laneLength, const bool friendlyPos)
check if the given position over a lane is valid
static void fixLanePosition(double &pos, double &length, const double laneLength)
fix given position over lane
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
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
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)
std::string getCommonAttribute(const Parameterised *parameterised, SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
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
GNENet * myNet
pointer to net
bool isCommonValid(SumoXMLAttr key, const std::string &value) const
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...)
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const GNEHierarchicalContainerParents< GNELane * > & getParentLanes() const
get parent lanes
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
GNEEdge * getParentEdge() const
get parent edge
Definition GNELane.cpp:202
double myMoveElementLateralOffset
move element lateral offset (used by elements placed over lanes
bool getAllowChangeLane() const
allow change lane
CommonMoveOptions * getCommonMoveOptions() const
get common mode options
move operation
move result
const GNELane * newFirstLane
new first Lane
double newFirstPos
new first position
double firstLaneOffset
lane offset
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:147
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2195
double getDefaultDoubleValue(SumoXMLAttr attr) const
get default double value
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
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
GNEViewParent * getViewParent() const
get the net object
bool checkOverLockedElement(const GUIGlObject *GLObject, const bool isSelected) const
check if given element is locked (used for drawing select and delete contour)
GNEUndoList * getUndoList() const
get the undoList object
const GNEViewNetHelper::ViewObjectsSelector & getViewObjectsSelector() const
get objects under cursor
GNEMoveFrame * getMoveFrame() const
get frame for move elements
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
const Parameterised::Map & getParametersMap() const
Returns the inner key/value 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
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 selectedAdditionalColor
additional selection color (busStops, Detectors...)
RGBColor busStopColor
color for busStops
static const double segmentWidthSmall
width of small dotted contour segments