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 // get detail level
225 const auto d = s.getDetailLevel(1);
226 // draw geometry only if we'rent in drawForObjectUnderCursor mode
228 // radius depends if mouse is over element
229 const double radius = gViewObjectsHandler.isObjectSelected(this) ? 1 : 0.5;
230 // get color
231 RGBColor accessColor;
232 if (drawUsingSelectColor()) {
234 } else if (!getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR).empty()) {
235 accessColor = parse<RGBColor>(getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR));
236 } else {
237 accessColor = s.colorSettings.busStopColor;
238 }
239 // draw parent and child lines
240 drawParentChildLines(s, accessColor);
241 // push layer matrix
243 // translate to front
245 // set color
246 GLHelper::setColor(accessColor);
247 // translate to geometry position
248 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
249 // draw circle
251 // pop layer matrix
253 // draw lock icon
254 GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().front(), accessExaggeration, 0.3);
255 // draw dotted contour
257 }
258 // calculate contour
259 myAdditionalContour.calculateContourCircleShape(s, d, this, myAdditionalGeometry.getShape().front(), 1, getType(), accessExaggeration);
260 }
261}
262
263
264std::string
266 switch (key) {
267 case SUMO_ATTR_ID:
268 return getParentAdditionals().front()->getID();
269 case SUMO_ATTR_LANE:
270 return getParentLanes().front()->getID();
273 return mySpecialPosition;
274 } else {
276 }
277 case SUMO_ATTR_LENGTH:
278 return toString(myLength);
281 case GNE_ATTR_PARENT:
282 return getParentAdditionals().at(0)->getID();
286 return getParametersStr();
288 return "";
289 default:
290 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
291 }
292}
293
294
295double
297 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
298}
299
300
305
306
307void
308GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
309 switch (key) {
310 case SUMO_ATTR_LANE:
312 case SUMO_ATTR_LENGTH:
314 case GNE_ATTR_PARENT:
318 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
319 break;
320 default:
321 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
322 }
323}
324
325
326bool
327GNEAccess::isValid(SumoXMLAttr key, const std::string& value) {
328 switch (key) {
329 case SUMO_ATTR_LANE: {
330 GNELane* lane = myNet->getAttributeCarriers()->retrieveLane(value, false);
331 if (lane != nullptr) {
332 if (getParentLanes().front()->getParentEdge()->getID() != lane->getParentEdge()->getID()) {
334 } else {
335 return true;
336 }
337 } else {
338 return false;
339 }
340 }
342 if (value.empty() || value == "random" || value == "doors" || value == "carriage") {
343 return true;
344 } else {
345 return canParse<double>(value);
346 }
347 case SUMO_ATTR_LENGTH:
348 if (canParse<double>(value)) {
349 const double valueDouble = parse<double>(value);
350 return (valueDouble == -1) || (valueDouble >= 0);
351 } else {
352 return false;
353 }
355 return canParse<bool>(value);
356 case GNE_ATTR_PARENT:
357 return (myNet->getAttributeCarriers()->retrieveAdditionals(NamespaceIDs::busStops, value, false) != nullptr);
359 return canParse<bool>(value);
361 return areParametersValid(value);
362 default:
363 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
364 }
365}
366
367
368std::string
370 return getTagStr();
371}
372
373
374std::string
376 return getTagStr() + ": " + getParentLanes().front()->getParentEdge()->getID();
377}
378
379// ===========================================================================
380// private
381// ===========================================================================
382
383void
384GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value) {
385 switch (key) {
386 case SUMO_ATTR_LANE:
388 break;
390 if (value.empty()) {
392 } else if (value == "random" || value == "doors" || value == "carriage") {
394 mySpecialPosition = value;
395 } else {
396 myPositionOverLane = parse<double>(value);
397 }
398 break;
399 case SUMO_ATTR_LENGTH:
400 myLength = parse<double>(value);
401 break;
403 myFriendlyPosition = parse<bool>(value);
404 break;
405 case GNE_ATTR_PARENT:
406 if (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_BUS_STOP, value, false) != nullptr) {
408 } else {
410 }
411 break;
413 if (parse<bool>(value)) {
415 } else {
417 }
418 break;
420 setParametersStr(value);
421 break;
424 break;
425 default:
426 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
427 }
428}
429
430
431void
433 // change both position
434 myPositionOverLane = moveResult.newFirstPos;
435 // set lateral offset
437 // update geometry
439}
440
441
442void
444 // reset lateral offset
446 undoList->begin(this, "position of " + getTagStr());
447 // now adjust start position
448 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
449 // check if lane has to be changed
450 if (moveResult.newFirstLane) {
451 // set new lane
452 setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
453 }
454 // end change attribute
455 undoList->end();
456}
457
458
459/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ GLO_ACCESS
a Acces
GUIViewObjectsHandler gViewObjectsHandler
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_SELECTED
element is selected
@ 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:654
static void popMatrix()
pop matrix
Definition GLHelper.cpp:130
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:539
static void pushMatrix()
push matrix
Definition GLHelper.cpp:117
~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 (instead of GUIGlObjectStorage)
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
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
calculate contour (circle elements)
void 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:125
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2147
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 attribute carrier 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
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
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.
bool isObjectSelected(const GUIGlObject *GLObject) const
check if element was already selected
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
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
bool showAdditionals() const
check if additionals has to be drawn
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