Eclipse SUMO - Simulation of Urban MObility
GNEAccess.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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>
25 #include <netedit/GNEViewParent.h>
28 #include <utils/gui/div/GLHelper.h>
31 
32 #include "GNEAccess.h"
33 #include "GNEAdditionalHandler.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),
43 myFriendlyPosition(false) {
44  // reset default values
45  resetDefaultValues();
46 }
47 
48 
49 GNEAccess::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}, {}, {}),
52 Parameterised(parameters),
53 myPositionOverLane(pos),
54 myLength(length),
55 myFriendlyPosition(friendlyPos) {
56  // update centering boundary without updating grid
57  updateCenteringBoundary(false);
58 }
59 
60 
62 }
63 
64 
67  // return move operation for additional placed over shape
68  return new GNEMoveOperation(this, getParentLanes().front(), myPositionOverLane,
70 }
71 
72 
73 void
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 
94 }
95 
96 
97 void
98 GNEAccess::updateCenteringBoundary(const bool /*updateGrid*/) {
100  // add center
102  // grow
104 }
105 
106 
107 void
108 GNEAccess::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 
118 bool
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 
133 void
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 
148 GNEEdge*
150  return getParentLanes().front()->getParentEdge();
151 }
152 
153 
154 std::string
156  return getParentAdditionals().at(0)->getID();
157 }
158 
159 
160 void
162  // Obtain exaggeration
163  const double accessExaggeration = getExaggeration(s);
164  // declare width
165  const double radius = 0.5;
166  // first check if additional has to be drawn
167  if (s.drawAdditionals(accessExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
168  // get color
169  RGBColor color;
170  if (drawUsingSelectColor()) {
172  } else if (!getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR).empty()) {
173  color = parse<RGBColor>(getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR));
174  } else {
175  color = s.colorSettings.busStopColor;
176  }
177  // draw parent and child lines
178  drawParentChildLines(s, color);
179  // Start drawing adding an gl identificator
181  // push layer matrix
183  // translate to front
185  // set color
186  GLHelper::setColor(color);
187  // translate to geometry position
188  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
189  // draw circle
191  GLHelper::drawFilledCircle(radius * accessExaggeration, 8);
192  } else {
193  GLHelper::drawFilledCircle(radius * accessExaggeration, 16);
194  }
195  // pop layer matrix
197  // pop gl identificator
199  // check if mouse is over access
200  mouseWithinGeometry(myAdditionalGeometry.getShape().front(), (radius * accessExaggeration));
201  // draw lock icon
202  GNEViewNetHelper::LockIcon::drawLockIcon(this, getType(), myAdditionalGeometry.getShape().front(), accessExaggeration, 0.3);
203  // inspect contour
206  }
207  // front element contour
208  if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
210  }
211  // delete contour
212  if (myNet->getViewNet()->drawDeleteContour(this, this)) {
214  }
215  // select contour
216  if (myNet->getViewNet()->drawSelectContour(this, this)) {
218  }
219  }
220 }
221 
222 
223 std::string
225  switch (key) {
226  case SUMO_ATTR_ID:
227  return getParentAdditionals().front()->getID();
228  case SUMO_ATTR_LANE:
229  return getParentLanes().front()->getID();
230  case SUMO_ATTR_POSITION:
232  case SUMO_ATTR_LENGTH:
233  return toString(myLength);
236  case GNE_ATTR_PARENT:
237  return getParentAdditionals().at(0)->getID();
238  case GNE_ATTR_SELECTED:
240  case GNE_ATTR_PARAMETERS:
241  return getParametersStr();
243  return "";
244  default:
245  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
246  }
247 }
248 
249 
250 double
252  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
253 }
254 
255 
256 const Parameterised::Map&
258  return getParametersMap();
259 }
260 
261 
262 void
263 GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
264  switch (key) {
265  case SUMO_ATTR_LANE:
266  case SUMO_ATTR_POSITION:
267  case SUMO_ATTR_LENGTH:
269  case GNE_ATTR_PARENT:
270  case GNE_ATTR_SELECTED:
271  case GNE_ATTR_PARAMETERS:
273  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
274  break;
275  default:
276  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
277  }
278 }
279 
280 
281 bool
282 GNEAccess::isValid(SumoXMLAttr key, const std::string& value) {
283  switch (key) {
284  case SUMO_ATTR_LANE: {
285  GNELane* lane = myNet->getAttributeCarriers()->retrieveLane(value, false);
286  if (lane != nullptr) {
287  if (getParentLanes().front()->getParentEdge()->getID() != lane->getParentEdge()->getID()) {
289  } else {
290  return true;
291  }
292  } else {
293  return false;
294  }
295  }
296  case SUMO_ATTR_POSITION:
297  if (value.empty()) {
298  return true;
299  } else {
300  return canParse<double>(value);
301  }
302  case SUMO_ATTR_LENGTH:
303  if (canParse<double>(value)) {
304  const double valueDouble = parse<double>(value);
305  return (valueDouble == -1) || (valueDouble >= 0);
306  } else {
307  return false;
308  }
310  return canParse<bool>(value);
311  case GNE_ATTR_PARENT:
312  return ((myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_BUS_STOP, value, false) != nullptr) ||
313  (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_TRAIN_STOP, value, false) != nullptr));
314  case GNE_ATTR_SELECTED:
315  return canParse<bool>(value);
316  case GNE_ATTR_PARAMETERS:
317  return areParametersValid(value);
318  default:
319  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
320  }
321 }
322 
323 
324 std::string
326  return getTagStr();
327 }
328 
329 
330 std::string
332  return getTagStr() + ": " + getParentLanes().front()->getParentEdge()->getID();
333 }
334 
335 // ===========================================================================
336 // private
337 // ===========================================================================
338 
339 void
340 GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value) {
341  switch (key) {
342  case SUMO_ATTR_LANE:
344  break;
345  case SUMO_ATTR_POSITION:
346  myPositionOverLane = parse<double>(value);
347  break;
348  case SUMO_ATTR_LENGTH:
349  myLength = parse<double>(value);
350  break;
352  myFriendlyPosition = parse<bool>(value);
353  break;
354  case GNE_ATTR_PARENT:
355  if (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_BUS_STOP, value, false) != nullptr) {
357  } else {
359  }
360  break;
361  case GNE_ATTR_SELECTED:
362  if (parse<bool>(value)) {
364  } else {
366  }
367  break;
368  case GNE_ATTR_PARAMETERS:
369  setParametersStr(value);
370  break;
372  shiftLaneIndex();
373  break;
374  default:
375  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
376  }
377 }
378 
379 
380 void
382  // change both position
383  myPositionOverLane = moveResult.newFirstPos;
384  // set lateral offset
386  // update geometry
387  updateGeometry();
388 }
389 
390 
391 void
392 GNEAccess::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {
393  // reset lateral offset
395  undoList->begin(GUIIcon::ACCESS, "position of " + getTagStr());
396  // now adjust start position
397  setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
398  // check if lane has to be changed
399  if (moveResult.newFirstLane) {
400  // set new lane
401  setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
402  }
403  // end change attribute
404  undoList->end();
405 }
406 
407 
408 /****************************************************************************/
@ GLO_ACCESS
a Acces
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ 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 of the parent object (if any)
Definition: GNEAccess.cpp:155
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
Definition: GNEAccess.cpp:282
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNEAccess.cpp:108
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
Definition: GNEAccess.cpp:381
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
Definition: GNEAccess.cpp:134
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEAccess.cpp:325
void updateGeometry()
update pre-computed geometry information
Definition: GNEAccess.cpp:74
bool isAccessPositionFixed() const
check if Position of Access is fixed
Definition: GNEAccess.cpp:119
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:148
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNEAccess.cpp:251
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Definition: GNEAccess.cpp:392
GNEMoveOperation * getMoveOperation()
get move operation
Definition: GNEAccess.cpp:66
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEAccess.cpp:331
GNEEdge * getEdge() const
get edge in which this Access is placed
Definition: GNEAccess.cpp:149
GNEAccess(GNENet *net)
Default constructor.
Definition: GNEAccess.cpp:39
const Parameterised::Map & getACParametersMap() const
get parameters map
Definition: GNEAccess.cpp:257
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEAccess.cpp:224
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEAccess.cpp:92
double myLength
Access length.
Definition: GNEAccess.h:145
double myPositionOverLane
position over lane
Definition: GNEAccess.h:142
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
Definition: GNEAccess.cpp:263
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEAccess.cpp:161
static bool accessCanBeCreated(GNEAdditional *busStopParent, GNEEdge *edge)
check if a GNEAccess can be created in a certain Edge
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:48
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:124
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:132
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
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
Definition: GNEViewNet.cpp:656
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
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
Definition: GUIGeometry.cpp:58
void mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:154
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:102
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.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
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.
Definition: Parameterised.h:41
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
Definition: Parameterised.h:45
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
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