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-2024 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>
23#include <netedit/GNEUndoList.h>
24#include <netedit/GNEViewNet.h>
32
33#include "GNEAccess.h"
35
36// ===========================================================================
37// member method definitions
38// ===========================================================================
39
41 GNEAdditional("", net, GLO_ACCESS, SUMO_TAG_ACCESS, GUIIconSubSys::getIcon(GUIIcon::ACCESS), "", {}, {}, {}, {}, {}, {}),
42 myPositionOverLane(0),
43 myLength(0),
44myFriendlyPosition(false) {
45 // reset default values
46 resetDefaultValues();
47}
48
49
50GNEAccess::GNEAccess(GNEAdditional* busStop, GNELane* lane, GNENet* net, const double pos, const std::string& specialPos,
51 const bool friendlyPos, const double length, const Parameterised::Map& parameters) :
52 GNEAdditional(net, GLO_ACCESS, SUMO_TAG_ACCESS, GUIIconSubSys::getIcon(GUIIcon::ACCESS), "", {}, {}, {lane}, {busStop}, {}, {}),
53Parameterised(parameters),
54myPositionOverLane(pos),
55mySpecialPosition(specialPos),
56myLength(length),
57myFriendlyPosition(friendlyPos) {
58 // update centering boundary without updating grid
59 updateCenteringBoundary(false);
60}
61
62
65
66
69 // return move operation for additional placed over shape
70 return new GNEMoveOperation(this, getParentLanes().front(), myPositionOverLane,
72}
73
74
75void
77 // set start position
78 double fixedPositionOverLane;
79 if (myPositionOverLane < 0) {
80 fixedPositionOverLane = 0;
81 } else if (myPositionOverLane > getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength()) {
82 fixedPositionOverLane = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
83 } else {
84 fixedPositionOverLane = myPositionOverLane;
85 }
86 // update geometry
87 myAdditionalGeometry.updateGeometry(getParentLanes().front()->getLaneShape(), fixedPositionOverLane * getParentLanes().front()->getLengthGeometryFactor(), myMoveElementLateralOffset);
88}
89
90
95
96
97void
98GNEAccess::updateCenteringBoundary(const bool /*updateGrid*/) {
99 // nothing to update
100}
101
102
103void
104GNEAccess::splitEdgeGeometry(const double splitPosition, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* newElement, GNEUndoList* undoList) {
105 if (splitPosition < myPositionOverLane) {
106 // change lane
107 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
108 // now adjust start position
109 setAttribute(SUMO_ATTR_POSITION, toString(myPositionOverLane - splitPosition), undoList);
110 }
111}
112
113
114bool
116 // with friendly position enabled position are "always fixed"
117 if (myFriendlyPosition) {
118 return true;
119 } else {
121 return (myPositionOverLane >= 0) && (myPositionOverLane <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
122 } else {
123 return false;
124 }
125 }
126}
127
128
129void
131 device.openTag(SUMO_TAG_ACCESS);
132 device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
134 if (myLength != -1) {
136 }
137 if (myFriendlyPosition) {
138 device.writeAttr(SUMO_ATTR_FRIENDLY_POS, true);
139 }
140 device.closeTag();
141}
142
143
144bool
146 // with friendly position enabled position is "always fixed"
147 if (myFriendlyPosition) {
148 return true;
149 } else if (myPositionOverLane == INVALID_DOUBLE) {
150 return true;
151 } else {
152 return fabs(myPositionOverLane) <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
153 }
154}
155
156
158 // obtain final length
159 const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
160 // check if detector has a problem
162 return "";
163 } else {
164 // declare variable for error position
165 std::string errorPosition;
166 // check positions over lane
167 if (myPositionOverLane < 0) {
168 errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
169 }
170 if (myPositionOverLane > len) {
171 errorPosition = (toString(SUMO_ATTR_POSITION) + TL(" > lanes's length"));
172 }
173 return errorPosition;
174 }
175}
176
177
179 // declare new position
180 double newPositionOverLane = myPositionOverLane;
181 // declare new length (but unsed in this context)
182 double length = 0;
183 // fix pos and length with fixLanePosition
184 GNEAdditionalHandler::fixLanePosition(newPositionOverLane, length, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
185 // set new position
187}
188
189
190bool
192 // get edit modes
193 const auto& editModes = myNet->getViewNet()->getEditModes();
194 // check if we're in move mode
195 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
197 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
198 // only move the first element
200 } else {
201 return false;
202 }
203}
204
205
206GNEEdge*
208 return getParentLanes().front()->getParentEdge();
209}
210
211
212std::string
214 return getParentAdditionals().at(0)->getID();
215}
216
217
218void
220 // first check if additional has to be drawn
222 // Obtain exaggeration
223 const double accessExaggeration = getExaggeration(s);
224 // adjust radius depending of mode and distance to mouse position
225 double radius = 0.5;
228 radius = 1;
229 }
230 // get detail level
231 const auto d = s.getDetailLevel(1);
232 // draw geometry only if we'rent in drawForObjectUnderCursor mode
234 // get color
235 RGBColor accessColor;
236 if (drawUsingSelectColor()) {
238 } else if (!getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR).empty()) {
239 accessColor = parse<RGBColor>(getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR));
240 } else {
241 accessColor = s.colorSettings.busStopColor;
242 }
243 // draw parent and child lines
244 drawParentChildLines(s, accessColor);
245 // push layer matrix
247 // translate to front
249 // set color
250 GLHelper::setColor(accessColor);
251 // translate to geometry position
252 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
253 // draw circle
254 GLHelper::drawFilledCircleDetailled(d, radius * accessExaggeration);
255 // pop layer matrix
257 // draw lock icon
258 GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().front(), accessExaggeration, 0.3);
259 // draw dotted contour
261 }
262 // calculate contour
264 accessExaggeration, getParentLanes().front()->getParentEdge());
265 }
266}
267
268
269std::string
271 switch (key) {
272 case SUMO_ATTR_ID:
273 return getParentAdditionals().front()->getID();
274 case SUMO_ATTR_LANE:
275 return getParentLanes().front()->getID();
278 return mySpecialPosition;
279 } else {
281 }
282 case SUMO_ATTR_LENGTH:
283 return toString(myLength);
286 case GNE_ATTR_PARENT:
287 if (isTemplate()) {
288 return "";
289 } else {
290 return getParentAdditionals().at(0)->getID();
291 }
293 return getParametersStr();
295 return "";
296 default:
297 return getCommonAttribute(key);
298 }
299}
300
301
302double
304 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
305}
306
307
312
313
314void
315GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
316 switch (key) {
317 case SUMO_ATTR_LANE:
319 case SUMO_ATTR_LENGTH:
321 case GNE_ATTR_PARENT:
324 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
325 break;
326 default:
327 setCommonAttribute(key, value, undoList);
328 break;
329 }
330}
331
332
333bool
334GNEAccess::isValid(SumoXMLAttr key, const std::string& value) {
335 switch (key) {
336 case SUMO_ATTR_LANE: {
337 GNELane* lane = myNet->getAttributeCarriers()->retrieveLane(value, false);
338 if (lane != nullptr) {
339 if (getParentLanes().front()->getParentEdge()->getID() != lane->getParentEdge()->getID()) {
341 } else {
342 return true;
343 }
344 } else {
345 return false;
346 }
347 }
349 if (value.empty() || value == "random" || value == "doors" || value == "carriage") {
350 return true;
351 } else {
352 return canParse<double>(value);
353 }
354 case SUMO_ATTR_LENGTH:
355 if (canParse<double>(value)) {
356 const double valueDouble = parse<double>(value);
357 return (valueDouble == -1) || (valueDouble >= 0);
358 } else {
359 return false;
360 }
362 return canParse<bool>(value);
363 case GNE_ATTR_PARENT:
364 return (myNet->getAttributeCarriers()->retrieveAdditionals(NamespaceIDs::busStops, value, false) != nullptr);
366 return areParametersValid(value);
367 default:
368 return isCommonValid(key, value);
369 }
370}
371
372
373std::string
375 return getTagStr();
376}
377
378
379std::string
381 return getTagStr() + ": " + getParentLanes().front()->getParentEdge()->getID();
382}
383
384// ===========================================================================
385// private
386// ===========================================================================
387
388void
389GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value) {
390 switch (key) {
391 case SUMO_ATTR_LANE:
393 break;
395 if (value.empty()) {
397 } else if (value == "random" || value == "doors" || value == "carriage") {
399 mySpecialPosition = value;
400 } else {
401 myPositionOverLane = parse<double>(value);
402 }
403 break;
404 case SUMO_ATTR_LENGTH:
405 myLength = parse<double>(value);
406 break;
408 myFriendlyPosition = parse<bool>(value);
409 break;
410 case GNE_ATTR_PARENT:
411 if (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_BUS_STOP, value, false) != nullptr) {
413 } else {
415 }
416 break;
418 setParametersStr(value);
419 break;
422 break;
423 default:
424 setCommonAttribute(key, value);
425 break;
426 }
427}
428
429
430void
432 // change both position
433 myPositionOverLane = moveResult.newFirstPos;
434 // set lateral offset
436 // update geometry
438}
439
440
441void
443 // reset lateral offset
445 undoList->begin(this, "position of " + getTagStr());
446 // now adjust start position
447 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
448 // check if lane has to be changed
449 if (moveResult.newFirstLane) {
450 // set new lane
451 setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
452 }
453 // end change attribute
454 undoList->end();
455}
456
457
458/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ GLO_ACCESS
a Acces
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
#define TL(string)
Definition MsgHandler.h:315
@ 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
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ 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: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:63
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:76
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)
Definition GNEAccess.cpp:98
bool myFriendlyPosition
flag to check if friendly position is enabled
Definition GNEAccess.h:178
double getAttributeDouble(SumoXMLAttr key) const
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
GNEMoveOperation * getMoveOperation()
get move operation
Definition GNEAccess.cpp:68
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:40
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:92
std::string mySpecialPosition
position over lane
Definition GNEAccess.h:172
double myLength
Access length.
Definition GNEAccess.h:175
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:169
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
An Element which don't belong to GNENet but has influence in the simulation.
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)
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.
bool isCommonValid(SumoXMLAttr key, const std::string &value)
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
std::string getCommonAttribute(SumoXMLAttr key) const
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 std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const std::vector< 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:196
double myMoveElementLateralOffset
move element lateral offset (used by elements placed over lanes
bool getAllowChangeLane() const
allow change lane
CommonModeOptions * getCommonModeOptions() 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:127
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2163
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.
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
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:281
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