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-2023 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>
31
32#include "GNEAccess.h"
34
35// ===========================================================================
36// member method definitions
37// ===========================================================================
38
40 GNEAdditional("", net, GLO_ACCESS, SUMO_TAG_ACCESS, GUIIconSubSys::getIcon(GUIIcon::ACCESS), "", {}, {}, {}, {}, {}, {}),
41 myPositionOverLane(0),
42 myLength(0),
43myFriendlyPosition(false) {
44 // reset default values
45 resetDefaultValues();
46}
47
48
49GNEAccess::GNEAccess(GNEAdditional* busStop, GNELane* lane, GNENet* net, double pos, const double length, bool friendlyPos,
50 const Parameterised::Map& parameters) :
51 GNEAdditional(net, GLO_ACCESS, SUMO_TAG_ACCESS, GUIIconSubSys::getIcon(GUIIcon::ACCESS), "", {}, {}, {lane}, {busStop}, {}, {}),
52Parameterised(parameters),
53myPositionOverLane(pos),
54myLength(length),
55myFriendlyPosition(friendlyPos) {
56 // update centering boundary without updating grid
57 updateCenteringBoundary(false);
58}
59
60
63
64
67 // return move operation for additional placed over shape
68 return new GNEMoveOperation(this, getParentLanes().front(), myPositionOverLane,
70}
71
72
73void
75 // set start position
76 double fixedPositionOverLane;
77 if (myPositionOverLane == -1) {
78 fixedPositionOverLane = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
79 } else 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*/) {
100 // add center
102 // grow
104}
105
106
107void
108GNEAccess::splitEdgeGeometry(const double splitPosition, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* newElement, GNEUndoList* undoList) {
109 if (splitPosition < myPositionOverLane) {
110 // change lane
111 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
112 // now adjust start position
113 setAttribute(SUMO_ATTR_POSITION, toString(myPositionOverLane - splitPosition), undoList);
114 }
115}
116
117
118bool
120 // with friendly position enabled position are "always fixed"
121 if (myFriendlyPosition) {
122 return true;
123 } else {
124 if (myPositionOverLane != -1) {
125 return (myPositionOverLane >= 0) && (myPositionOverLane <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
126 } else {
127 return false;
128 }
129 }
130}
131
132
133void
135 device.openTag(SUMO_TAG_ACCESS);
136 device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
138 if (myLength != -1) {
140 }
141 if (myFriendlyPosition) {
142 device.writeAttr(SUMO_ATTR_FRIENDLY_POS, true);
143 }
144 device.closeTag();
145}
146
147
148bool
150 // with friendly position enabled position is "always fixed"
151 if (myFriendlyPosition) {
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 lenght (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
192GNEEdge*
194 return getParentLanes().front()->getParentEdge();
195}
196
197
198std::string
200 return getParentAdditionals().at(0)->getID();
201}
202
203
204void
206 // Obtain exaggeration
207 const double accessExaggeration = getExaggeration(s);
208 // first check if additional has to be drawn
209 if (s.drawAdditionals(accessExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
210 // get color
211 RGBColor accessColor;
212 if (drawUsingSelectColor()) {
214 } else if (!getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR).empty()) {
215 accessColor = parse<RGBColor>(getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR));
216 } else {
217 accessColor = s.colorSettings.busStopColor;
218 }
219 // avoid draw invisible elements
220 if (accessColor.alpha() != 0) {
221 // get distance squared between mouse and access
222 const double distanceSquared = getPositionInView().distanceSquaredTo2D(myNet->getViewNet()->getPositionInformation());
223 // declare radius
224 const double radius = (distanceSquared <= 1) ? 1 : 0.5;
225 // draw parent and child lines
226 drawParentChildLines(s, accessColor);
227 // Start drawing adding an gl identificator
229 // push layer matrix
231 // translate to front
233 // set color
234 GLHelper::setColor(accessColor);
235 // translate to geometry position
236 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
237 // draw circle
239 GLHelper::drawFilledCircle(radius * accessExaggeration, 8);
240 } else {
241 GLHelper::drawFilledCircle(radius * accessExaggeration, 16);
242 }
243 // pop layer matrix
245 // pop gl identificator
247 // check if mouse is over access
248 mouseWithinGeometry(myAdditionalGeometry.getShape().front(), (radius * accessExaggeration));
249 // draw lock icon
250 GNEViewNetHelper::LockIcon::drawLockIcon(this, getType(), myAdditionalGeometry.getShape().front(), accessExaggeration, 0.3);
251 }
252 // inspect contour
255 }
256 // front element contour
257 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
259 }
260 // delete contour
261 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
263 }
264 // select contour
265 if (myNet->getViewNet()->drawSelectContour(this, this)) {
267 }
268 }
269}
270
271
272std::string
274 switch (key) {
275 case SUMO_ATTR_ID:
276 return getParentAdditionals().front()->getID();
277 case SUMO_ATTR_LANE:
278 return getParentLanes().front()->getID();
281 case SUMO_ATTR_LENGTH:
282 return toString(myLength);
285 case GNE_ATTR_PARENT:
286 return getParentAdditionals().at(0)->getID();
290 return getParametersStr();
292 return "";
293 default:
294 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
295 }
296}
297
298
299double
301 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
302}
303
304
309
310
311void
312GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
313 switch (key) {
314 case SUMO_ATTR_LANE:
316 case SUMO_ATTR_LENGTH:
318 case GNE_ATTR_PARENT:
322 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
323 break;
324 default:
325 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
326 }
327}
328
329
330bool
331GNEAccess::isValid(SumoXMLAttr key, const std::string& value) {
332 switch (key) {
333 case SUMO_ATTR_LANE: {
334 GNELane* lane = myNet->getAttributeCarriers()->retrieveLane(value, false);
335 if (lane != nullptr) {
336 if (getParentLanes().front()->getParentEdge()->getID() != lane->getParentEdge()->getID()) {
338 } else {
339 return true;
340 }
341 } else {
342 return false;
343 }
344 }
346 if (value.empty()) {
347 return true;
348 } else {
349 return canParse<double>(value);
350 }
351 case SUMO_ATTR_LENGTH:
352 if (canParse<double>(value)) {
353 const double valueDouble = parse<double>(value);
354 return (valueDouble == -1) || (valueDouble >= 0);
355 } else {
356 return false;
357 }
359 return canParse<bool>(value);
360 case GNE_ATTR_PARENT:
361 return ((myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_BUS_STOP, value, false) != nullptr) ||
362 (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_TRAIN_STOP, value, false) != nullptr));
364 return canParse<bool>(value);
366 return areParametersValid(value);
367 default:
368 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
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 myPositionOverLane = parse<double>(value);
396 break;
397 case SUMO_ATTR_LENGTH:
398 myLength = parse<double>(value);
399 break;
401 myFriendlyPosition = parse<bool>(value);
402 break;
403 case GNE_ATTR_PARENT:
404 if (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_BUS_STOP, value, false) != nullptr) {
406 } else {
408 }
409 break;
411 if (parse<bool>(value)) {
413 } else {
415 }
416 break;
418 setParametersStr(value);
419 break;
422 break;
423 default:
424 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
425 }
426}
427
428
429void
431 // change both position
432 myPositionOverLane = moveResult.newFirstPos;
433 // set lateral offset
435 // update geometry
437}
438
439
440void
442 // reset lateral offset
444 undoList->begin(GUIIcon::ACCESS, "position of " + getTagStr());
445 // now adjust start position
446 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
447 // check if lane has to be changed
448 if (moveResult.newFirstLane) {
449 // set new lane
450 setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
451 }
452 // end change attribute
453 undoList->end();
454}
455
456
457/****************************************************************************/
@ GLO_ACCESS
a Acces
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
#define TL(string)
Definition MsgHandler.h:287
@ 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)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition Boundary.cpp:78
void reset()
Resets the boundary.
Definition Boundary.cpp:66
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:300
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:583
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition GLHelper.cpp:498
static void pushName(unsigned int name)
push Name
Definition GLHelper.cpp:139
static void popMatrix()
pop matrix
Definition GLHelper.cpp:130
static void popName()
pop Name
Definition GLHelper.cpp:148
static void pushMatrix()
push matrix
Definition GLHelper.cpp:117
~GNEAccess()
Destructor.
Definition GNEAccess.cpp:61
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:74
bool isAdditionalValid() const
check if current additional is valid to be writed into XML (must be reimplemented in all detector chi...
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:167
double getAttributeDouble(SumoXMLAttr key) const
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
GNEMoveOperation * getMoveOperation()
get move operation
Definition GNEAccess.cpp:66
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:39
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
double myLength
Access length.
Definition GNEAccess.h:164
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:161
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
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
Boundary myAdditionalBoundary
Additional Boundary.
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
friend class GNEChange_Attribute
declare friend class
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
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:118
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.
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:120
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2030
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...
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool drawSelectContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw select contour
bool drawDeleteContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw delete contour
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
GNEViewParent * getViewParent() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
GNEMoveFrame * getMoveFrame() const
get frame for move elements
static void drawDottedContourCircle(const GUIVisualizationSettings &s, const DottedContourType type, const Position &pos, const double radius, const double exaggeration)
draw dotted contour for the given Position and radius (used by Juctions and POIs)
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 mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
GUIGlID getGlID() const
Returns the numerical id of the object.
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
Stores the information about how to visualize structures.
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationColorSettings colorSettings
color settings
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:259
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition RGBColor.cpp:92
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position viewPosition, 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