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/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
26 #include <netedit/GNEViewNet.h>
27 #include <netedit/GNEViewParent.h>
30 #include <utils/gui/div/GLHelper.h>
32 
33 #include "GNEAccess.h"
34 #include "GNEAdditionalHandler.h"
35 
36 // ===========================================================================
37 // member method definitions
38 // ===========================================================================
39 
42 {}, {}, {}, {}, {}, {}, {}, {},
43 std::map<std::string, std::string>()),
44  myPositionOverLane(0),
45  myLength(0),
46 myFriendlyPosition(false) {
47  // reset default values
48  resetDefaultValues();
49 }
50 
51 
52 GNEAccess::GNEAccess(GNEAdditional* busStop, GNELane* lane, GNENet* net, double pos, const double length, bool friendlyPos,
53  const std::map<std::string, std::string>& parameters) :
55 {}, {}, {lane}, {busStop}, {}, {}, {}, {},
56 parameters),
57 myPositionOverLane(pos),
58 myLength(length),
59 myFriendlyPosition(friendlyPos) {
60  // update centering boundary without updating grid
61  updateCenteringBoundary(false);
62 }
63 
64 
66 }
67 
68 
71  // return move operation for additional placed over shape
72  return new GNEMoveOperation(this, getParentLanes().front(), myPositionOverLane,
74 }
75 
76 
77 void
79  // set start position
80  double fixedPositionOverLane;
81  if (myPositionOverLane == -1) {
82  fixedPositionOverLane = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
83  } else if (myPositionOverLane < 0) {
84  fixedPositionOverLane = 0;
85  } else if (myPositionOverLane > getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength()) {
86  fixedPositionOverLane = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
87  } else {
88  fixedPositionOverLane = myPositionOverLane;
89  }
90  // update geometry
91  myAdditionalGeometry.updateGeometry(getParentLanes().front()->getLaneShape(), fixedPositionOverLane * getParentLanes().front()->getLengthGeometryFactor(), myMoveElementLateralOffset);
92 }
93 
94 
98 }
99 
100 
101 void
102 GNEAccess::updateCenteringBoundary(const bool /*updateGrid*/) {
104  // add center
106  // grow
108 }
109 
110 
111 void
112 GNEAccess::splitEdgeGeometry(const double splitPosition, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* newElement, GNEUndoList* undoList) {
113  if (splitPosition < myPositionOverLane) {
114  // change lane
115  setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
116  // now adjust start position
117  setAttribute(SUMO_ATTR_POSITION, toString(myPositionOverLane - splitPosition), undoList);
118  }
119 }
120 
121 
122 bool
124  // with friendly position enabled position are "always fixed"
125  if (myFriendlyPosition) {
126  return true;
127  } else {
128  if (myPositionOverLane != -1) {
129  return (myPositionOverLane >= 0) && (myPositionOverLane <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
130  } else {
131  return false;
132  }
133  }
134 }
135 
136 
137 void
139  device.openTag(SUMO_TAG_ACCESS);
140  device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
142  if (myLength != -1) {
144  }
145  if (myFriendlyPosition) {
146  device.writeAttr(SUMO_ATTR_FRIENDLY_POS, true);
147  }
148  device.closeTag();
149 }
150 
151 
152 GNEEdge*
154  return getParentLanes().front()->getParentEdge();
155 }
156 
157 
158 std::string
160  return getParentAdditionals().at(0)->getID();
161 }
162 
163 
164 void
166  // Obtain exaggeration
167  const double accessExaggeration = getExaggeration(s);
168  // declare width
169  const double radius = 0.5;
170  // first check if additional has to be drawn
171  if (s.drawAdditionals(accessExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
172  // get color
173  RGBColor color;
174  if (drawUsingSelectColor()) {
176  } else if (!getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR).empty()) {
177  color = parse<RGBColor>(getParentAdditionals().front()->getAttribute(SUMO_ATTR_COLOR));
178  } else {
179  color = s.colorSettings.busStopColor;
180  }
181  // draw parent and child lines
182  drawParentChildLines(s, color);
183  // Start drawing adding an gl identificator
185  // push layer matrix
187  // translate to front
189  // set color
190  GLHelper::setColor(color);
191  // translate to geometry position
192  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
193  // draw circle
195  GLHelper::drawFilledCircle(radius * accessExaggeration, 8);
196  } else {
197  GLHelper::drawFilledCircle(radius * accessExaggeration, 16);
198  }
199  // pop layer matrix
201  // pop gl identficador
203  // draw lock icon
204  GNEViewNetHelper::LockIcon::drawLockIcon(this, getType(), myAdditionalGeometry.getShape().front(), accessExaggeration, 0.3);
205  // check if dotted contours has to be drawn
208  }
209  if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
211  }
212  }
213 }
214 
215 
216 std::string
218  switch (key) {
219  case SUMO_ATTR_ID:
220  return getParentAdditionals().front()->getID();
221  case SUMO_ATTR_LANE:
222  return getParentLanes().front()->getID();
223  case SUMO_ATTR_POSITION:
225  case SUMO_ATTR_LENGTH:
226  return toString(myLength);
229  case GNE_ATTR_PARENT:
230  return getParentAdditionals().at(0)->getID();
231  case GNE_ATTR_SELECTED:
233  case GNE_ATTR_PARAMETERS:
234  return getParametersStr();
236  return "";
237  default:
238  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
239  }
240 }
241 
242 
243 double
245  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
246 }
247 
248 
249 void
250 GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
251  switch (key) {
252  case SUMO_ATTR_LANE:
253  case SUMO_ATTR_POSITION:
254  case SUMO_ATTR_LENGTH:
256  case GNE_ATTR_SELECTED:
257  case GNE_ATTR_PARAMETERS:
259  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
260  break;
261  default:
262  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
263  }
264 }
265 
266 
267 bool
268 GNEAccess::isValid(SumoXMLAttr key, const std::string& value) {
269  switch (key) {
270  case SUMO_ATTR_LANE: {
271  GNELane* lane = myNet->getAttributeCarriers()->retrieveLane(value, false);
272  if (lane != nullptr) {
273  if (getParentLanes().front()->getParentEdge()->getID() != lane->getParentEdge()->getID()) {
275  } else {
276  return true;
277  }
278  } else {
279  return false;
280  }
281  }
282  case SUMO_ATTR_POSITION:
283  if (value.empty()) {
284  return true;
285  } else {
286  return canParse<double>(value);
287  }
288  case SUMO_ATTR_LENGTH:
289  if (canParse<double>(value)) {
290  const double valueDouble = parse<double>(value);
291  return (valueDouble == -1) || (valueDouble >= 0);
292  } else {
293  return false;
294  }
296  return canParse<bool>(value);
297  case GNE_ATTR_SELECTED:
298  return canParse<bool>(value);
299  case GNE_ATTR_PARAMETERS:
300  return Parameterised::areParametersValid(value);
301  default:
302  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
303  }
304 }
305 
306 
307 bool
309  return true;
310 }
311 
312 
313 std::string
315  return getTagStr();
316 }
317 
318 
319 std::string
321  return getTagStr() + ": " + getParentLanes().front()->getParentEdge()->getID();
322 }
323 
324 // ===========================================================================
325 // private
326 // ===========================================================================
327 
328 void
329 GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value) {
330  switch (key) {
331  case SUMO_ATTR_LANE:
333  break;
334  case SUMO_ATTR_POSITION:
335  myPositionOverLane = parse<double>(value);
336  break;
337  case SUMO_ATTR_LENGTH:
338  myLength = parse<double>(value);
339  break;
341  myFriendlyPosition = parse<bool>(value);
342  break;
343  case GNE_ATTR_SELECTED:
344  if (parse<bool>(value)) {
346  } else {
348  }
349  break;
350  case GNE_ATTR_PARAMETERS:
351  setParametersStr(value);
352  break;
354  shiftLaneIndex();
355  break;
356  default:
357  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
358  }
359 }
360 
361 
362 void
364  // change both position
365  myPositionOverLane = moveResult.newFirstPos;
366  // set lateral offset
368  // update geometry
369  updateGeometry();
370 }
371 
372 
373 void
374 GNEAccess::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {
375  // reset lateral offset
377  undoList->begin(GUIIcon::ACCESS, "position of " + getTagStr());
378  // now adjust start position
379  setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
380  // check if lane has to be changed
381  if (moveResult.newFirstLane) {
382  // set new lane
383  setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
384  }
385  // end change attribute
386  undoList->end();
387 }
388 
389 
390 /****************************************************************************/
@ GLO_ACCESS
a Acces
@ SUMO_TAG_ACCESS
An access point for a train 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:77
void reset()
Resets the boundary.
Definition: Boundary.cpp:65
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:507
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:431
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void popName()
pop Name
Definition: GLHelper.cpp:141
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
~GNEAccess()
Destructor.
Definition: GNEAccess.cpp:65
std::string getParentName() const
Returns the name of the parent object (if any)
Definition: GNEAccess.cpp:159
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEAccess.cpp:268
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNEAccess.cpp:112
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
Definition: GNEAccess.cpp:363
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
Definition: GNEAccess.cpp:138
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEAccess.cpp:314
void updateGeometry()
update pre-computed geometry information
Definition: GNEAccess.cpp:78
bool isAccessPositionFixed() const
check if Position of Access is fixed
Definition: GNEAccess.cpp:123
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
Definition: GNEAccess.cpp:102
bool myFriendlyPosition
flag to check if friendly position is enabled
Definition: GNEAccess.h:150
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNEAccess.cpp:244
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Definition: GNEAccess.cpp:374
GNEMoveOperation * getMoveOperation()
get move operation
Definition: GNEAccess.cpp:70
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEAccess.cpp:320
GNEEdge * getEdge() const
get edge in which this Access is placed
Definition: GNEAccess.cpp:153
GNEAccess(GNENet *net)
Default constructor.
Definition: GNEAccess.cpp:40
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEAccess.cpp:217
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEAccess.cpp:96
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNEAccess.cpp:308
double myLength
Access length.
Definition: GNEAccess.h:147
double myPositionOverLane
position over lane
Definition: GNEAccess.h:144
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:250
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEAccess.cpp:165
static bool accessCanBeCreated(GNEAdditional *busStopParent, GNEEdge *edge)
check if a GNEAccess can be created in a certain Edge
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
const std::string & getID() const
get ID
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 asociated 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
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 arent edge
Definition: GNELane.cpp:113
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
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:1964
const std::string & getID() const
get ID
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:537
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
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 DottedContourType type, const GUIVisualizationSettings &s, 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
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
GUIGlID getGlID() const
Returns the numerical id of the object.
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:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
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|....
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"
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