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-2020 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>
26 #include <utils/gui/div/GLHelper.h>
28 
29 #include "GNEAccess.h"
30 #include "GNEAdditionalHandler.h"
31 
32 // ===========================================================================
33 // member method definitions
34 // ===========================================================================
35 
36 GNEAccess::GNEAccess(GNEAdditional* busStop, GNELane* lane, GNENet* net, double pos, const std::string& length, bool friendlyPos, bool blockMovement) :
37  GNEAdditional(net, GLO_ACCESS, SUMO_TAG_ACCESS, "", blockMovement,
38 {}, {}, {lane}, {busStop}, {}, {}, {}, {}),
39 myPositionOverLane(pos),
40 myLength(length),
41 myFriendlyPosition(friendlyPos) {
42  // update centering boundary without updating grid
43  updateCenteringBoundary(false);
44 }
45 
46 
48 }
49 
50 
52 GNEAccess::getMoveOperation(const double /*shapeOffset*/) {
53  // check conditions
54  if (myBlockMovement) {
55  // element blocked, then nothing to move
56  return nullptr;
57  } else {
58  // return move operation for additional placed over shape
59  return new GNEMoveOperation(this, getParentLanes().front(), {myPositionOverLane});
60  }
61 }
62 
63 
64 void
66  // set start position
67  double fixedPositionOverLane;
68  if (myPositionOverLane == -1) {
69  fixedPositionOverLane = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
70  } else if (myPositionOverLane < 0) {
71  fixedPositionOverLane = 0;
72  } else if (myPositionOverLane > getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength()) {
73  fixedPositionOverLane = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
74  } else {
75  fixedPositionOverLane = myPositionOverLane;
76  }
77  // update geometry
78  myAdditionalGeometry.updateGeometry(getParentLanes().front(), fixedPositionOverLane * getParentLanes().front()->getLengthGeometryFactor());
79 }
80 
81 
82 void
83 GNEAccess::updateCenteringBoundary(const bool /*updateGrid*/) {
84  // now update geometry
86  // add shape boundary
88  // grow
89  myBoundary.grow(10);
90 }
91 
92 
93 void
94 GNEAccess::splitEdgeGeometry(const double splitPosition, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* newElement, GNEUndoList* undoList) {
95  if (splitPosition < myPositionOverLane) {
96  // change lane
97  setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
98  // now adjust start position
99  setAttribute(SUMO_ATTR_POSITION, toString(myPositionOverLane - splitPosition), undoList);
100  }
101 }
102 
103 
104 bool
106  // with friendly position enabled position are "always fixed"
107  if (myFriendlyPosition) {
108  return true;
109  } else {
110  if (myPositionOverLane != -1) {
111  return (myPositionOverLane >= 0) && (myPositionOverLane <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
112  } else {
113  return false;
114  }
115  }
116 }
117 
118 
119 GNEEdge*
121  return getParentLanes().front()->getParentEdge();
122 }
123 
124 
125 std::string
127  return getParentAdditionals().at(0)->getID();
128 }
129 
130 
131 void
133  // Obtain exaggeration
134  const double accessExaggeration = s.addSize.getExaggeration(s, this);
135  // declare width
136  const double radius = 0.5;
137  // first check if additional has to be drawn
138  if (s.drawAdditionals(accessExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
139  // Start drawing adding an gl identificator
140  glPushName(getGlID());
141  // push layer matrix
142  glPushMatrix();
143  // translate to front
145  // set color depending of selection
146  if (drawUsingSelectColor()) {
148  } else {
150  }
151  // translate to geometry position
152  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
153  // draw circle
155  GLHelper::drawFilledCircle(radius * accessExaggeration, 8);
156  } else {
157  GLHelper::drawFilledCircle(radius * accessExaggeration, 16);
158  }
159  // draw lock icon
160  GNEViewNetHelper::LockIcon::drawLockIcon(this, myAdditionalGeometry, accessExaggeration, 0, 0, true, 0.3);
161  // pop layer matrix
162  glPopMatrix();
163  // pop gl identficador
164  glPopName();
165  // check if dotted contours has to be drawn
168  }
169  if (s.drawDottedContour() || myNet->getViewNet()->getFrontAttributeCarrier() == this) {
171  }
172  }
173 }
174 
175 
176 std::string
178  switch (key) {
179  case SUMO_ATTR_ID:
180  return getParentAdditionals().front()->getID();
181  case SUMO_ATTR_LANE:
182  return getParentLanes().front()->getID();
183  case SUMO_ATTR_POSITION:
185  case SUMO_ATTR_LENGTH:
186  return toString(myLength);
190  return toString(myBlockMovement);
191  case GNE_ATTR_PARENT:
192  return getParentAdditionals().at(0)->getID();
193  case GNE_ATTR_SELECTED:
195  case GNE_ATTR_PARAMETERS:
196  return getParametersStr();
197  default:
198  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
199  }
200 }
201 
202 
203 double
205  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
206 }
207 
208 
209 void
210 GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
211  if (value == getAttribute(key)) {
212  return; //avoid needless changes, later logic relies on the fact that attributes have changed
213  }
214  switch (key) {
215  case SUMO_ATTR_LANE:
216  case SUMO_ATTR_POSITION:
217  case SUMO_ATTR_LENGTH:
220  case GNE_ATTR_SELECTED:
221  case GNE_ATTR_PARAMETERS:
222  undoList->p_add(new GNEChange_Attribute(this, key, value));
223  break;
224  default:
225  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
226  }
227 }
228 
229 
230 bool
231 GNEAccess::isValid(SumoXMLAttr key, const std::string& value) {
232  switch (key) {
233  case SUMO_ATTR_LANE: {
234  GNELane* lane = myNet->retrieveLane(value, false);
235  if (lane != nullptr) {
236  if (getParentLanes().front()->getParentEdge()->getID() != lane->getParentEdge()->getID()) {
238  } else {
239  return true;
240  }
241  } else {
242  return false;
243  }
244  }
245  case SUMO_ATTR_POSITION:
246  if (value.empty()) {
247  return true;
248  } else {
249  return canParse<double>(value);
250  }
251  case SUMO_ATTR_LENGTH:
252  if (value.empty()) {
253  return true;
254  } else {
255  return (canParse<double>(value) && (parse<double>(value) >= 0));
256  }
258  return canParse<bool>(value);
260  return canParse<bool>(value);
261  case GNE_ATTR_SELECTED:
262  return canParse<bool>(value);
263  case GNE_ATTR_PARAMETERS:
264  return Parameterised::areParametersValid(value);
265  default:
266  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
267  }
268 }
269 
270 
271 bool
273  return true;
274 }
275 
276 
277 std::string
279  return getTagStr();
280 }
281 
282 
283 std::string
285  return getTagStr() + ": " + getParentLanes().front()->getParentEdge()->getID();
286 }
287 
288 // ===========================================================================
289 // private
290 // ===========================================================================
291 
292 void
293 GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value) {
294  switch (key) {
295  case SUMO_ATTR_LANE:
297  break;
298  case SUMO_ATTR_POSITION:
299  myPositionOverLane = parse<double>(value);
300  break;
301  case SUMO_ATTR_LENGTH:
302  myLength = value;
303  break;
305  myFriendlyPosition = parse<bool>(value);
306  break;
308  myBlockMovement = parse<bool>(value);
309  break;
310  case GNE_ATTR_SELECTED:
311  if (parse<bool>(value)) {
313  } else {
315  }
316  break;
317  case GNE_ATTR_PARAMETERS:
318  setParametersStr(value);
319  break;
320  default:
321  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
322  }
323 }
324 
325 
326 void
328  // change both position
329  myPositionOverLane = moveResult.shapeToUpdate.front().x();
330  // update geometry
331  updateGeometry();
332 }
333 
334 
335 void
336 GNEAccess::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {
337  undoList->p_begin("position of " + getTagStr());
338  // now adjust start position
339  setAttribute(SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front().x()), undoList);
340  undoList->p_end();
341 }
342 
343 
344 /****************************************************************************/
@ 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_BLOCK_MOVEMENT
block movement of a graphic element
@ 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_ID
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
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:446
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:347
~GNEAccess()
Destructor.
Definition: GNEAccess.cpp:47
std::string getParentName() const
Returns the name of the parent object (if any)
Definition: GNEAccess.cpp:126
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEAccess.cpp:231
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
Definition: GNEAccess.cpp:52
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNEAccess.cpp:94
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
Definition: GNEAccess.cpp:327
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEAccess.cpp:278
void updateGeometry()
update pre-computed geometry information
Definition: GNEAccess.cpp:65
bool isAccessPositionFixed() const
check if Position of Access is fixed
Definition: GNEAccess.cpp:105
GNEAccess(GNEAdditional *busStop, GNELane *lane, GNENet *net, double pos, const std::string &length, bool friendlyPos, bool blockMovement)
Constructor.
Definition: GNEAccess.cpp:36
std::string myLength
Acces length.
Definition: GNEAccess.h:134
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
Definition: GNEAccess.cpp:83
bool myFriendlyPosition
flag to check if friendly position is enabled
Definition: GNEAccess.h:137
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNEAccess.cpp:204
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Definition: GNEAccess.cpp:336
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEAccess.cpp:284
GNEEdge * getEdge() const
get edge in which this Access is placed
Definition: GNEAccess.cpp:120
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEAccess.cpp:177
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNEAccess.cpp:272
double myPositionOverLane
position over lane
Definition: GNEAccess.h:131
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:210
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEAccess.cpp:132
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:47
const std::string & getID() const
get ID
GNEGeometry::Geometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void replaceAdditionalParentLanes(const std::string &value)
replace additional parent lanes
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse)
Boundary myBoundary
Additional Boundary.
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:49
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
update geometry shape
Definition: GNEGeometry.cpp:81
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:45
GNEEdge * getParentEdge() const
get arent edge
Definition: GNELane.cpp:111
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1337
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
const std::string & getID() const
get ID
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:71
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
Definition: GNEUndoList.cpp:78
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:491
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
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
GUIVisualizationSizeSettings addSize
bool drawDottedContour() const
check if dotted contour can be drawn
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationStoppingPlaceSettings stoppingPlaceSettings
StoppingPlace settings.
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, 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".
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
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)
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GNEAttributeCarrier *AC, const GNEGeometry::Geometry &geometry, const double exaggeration, const double offsetx, const double offsety, const bool overlane, const double size=0.5)
draw lock icon
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
static const RGBColor busStopColor
color for busStops