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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
29 #include <utils/gui/div/GLHelper.h>
31 
32 #include "GNEAccess.h"
33 #include "GNEAdditionalHandler.h"
34 
35 // ===========================================================================
36 // member method definitions
37 // ===========================================================================
38 
39 GNEAccess::GNEAccess(GNEAdditional* busStop, GNELane* lane, GNEViewNet* viewNet, const std::string& pos, const std::string& length, bool friendlyPos, bool blockMovement) :
40  GNEAdditional(busStop, viewNet, GLO_ACCESS, SUMO_TAG_ACCESS, "", blockMovement,
41 {}, {lane}, {}, {busStop}, {}, {}, {}, {}, {}, {}),
42 myPositionOverLane(pos),
43 myLength(length),
44 myFriendlyPosition(friendlyPos) {
45 }
46 
47 
49 }
50 
51 
52 void
54  // Calculate new position using old position
55  Position newPosition = myMove.originalViewPosition;
56  newPosition.add(offset);
57  // filtern position using snap to active grid
58  newPosition = myViewNet->snapToActiveGrid(newPosition);
59  myPositionOverLane = toString(getLaneParents().front()->getGeometry().shape.nearest_offset_to_point2D(newPosition, false));
60  // Update geometry
62 }
63 
64 
65 void
67  if (!myBlockMovement) {
68  // commit new position allowing undo/redo
69  undoList->p_begin("position of " + getTagStr());
71  undoList->p_end();
72  }
73 }
74 
75 
76 void
78  // Clear all containers
80 
81  // Get shape of lane parent
82  myGeometry.shape = getLaneParents().front()->getGeometry().shape;
83 
84  // set start position
85  double fixedPositionOverLane;
86  if (!canParse<double>(myPositionOverLane)) {
87  fixedPositionOverLane = getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength();
88  } else if (parse<double>(myPositionOverLane) < 0) {
89  fixedPositionOverLane = 0;
90  } else if (parse<double>(myPositionOverLane) > getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength()) {
91  fixedPositionOverLane = getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength();
92  } else {
93  fixedPositionOverLane = parse<double>(myPositionOverLane);
94  }
95  // obtain position
96  myGeometry.shape[0] = getLaneParents().front()->getGeometry().shape.positionAtOffset(fixedPositionOverLane * getLaneParents().front()->getLengthGeometryFactor());
97 
98  // Save rotation (angle) of the vector constructed by points f and s
99  myGeometry.shapeRotations.push_back(getLaneParents().front()->getGeometry().shape.rotationDegreeAtOffset(fixedPositionOverLane) * -1);
100 
101  // Set block icon position
103 
104  // Set offset of the block icon
105  myBlockIcon.offset = Position(-1, 0);
106 
107  // Set block icon rotation, and using their rotation for logo
109 }
110 
111 
112 Position
114  if (!canParse<double>(myPositionOverLane)) {
115  return getLaneParents().front()->getGeometry().shape.front();
116  } else {
117  double posOverLane = parse<double>(myPositionOverLane);
118  if (posOverLane < 0) {
119  return getLaneParents().front()->getGeometry().shape.front();
120  } else if (posOverLane > getLaneParents().front()->getGeometry().shape.length()) {
121  return getLaneParents().front()->getGeometry().shape.back();
122  } else {
123  return getLaneParents().front()->getGeometry().shape.positionAtOffset(posOverLane);
124  }
125  }
126 }
127 
128 
129 Boundary
131  return myGeometry.shape.getBoxBoundary().grow(10);
132 }
133 
134 
135 bool
137  // with friendly position enabled position are "always fixed"
138  if (myFriendlyPosition) {
139  return true;
140  } else {
141  if (canParse<double>(myPositionOverLane)) {
142  return (parse<double>(myPositionOverLane) >= 0) && ((parse<double>(myPositionOverLane)) <= getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength());
143  } else {
144  return false;
145  }
146  }
147 }
148 
149 
150 GNEEdge&
152  return getLaneParents().front()->getParentEdge();
153 }
154 
155 
156 std::string
158  return getAdditionalParents().at(0)->getID();
159 }
160 
161 
162 void
164  // Obtain exaggeration of the draw
165  const double exaggeration = s.addSize.getExaggeration(s, this);
166  // Start drawing adding an gl identificator
167  glPushName(getGlID());
168  // push matrix
169  glPushMatrix();
170  // set color depending of selection
171  if (drawUsingSelectColor()) {
173  } else {
175  }
176  glTranslated(myGeometry.shape[0].x(), myGeometry.shape[0].y(), GLO_ACCESS);
177  // draw circle
178  if (s.drawForSelecting) {
179  GLHelper::drawFilledCircle((double) 0.5 * exaggeration, 8);
180  } else {
181  std::vector<Position> vertices = GLHelper::drawFilledCircleReturnVertices((double) 0.5 * exaggeration, 16);
182  // check if dotted contour has to be drawn
183  if (myViewNet->getDottedAC() == this) {
185  }
186  }
187  // pop matrix
188  glPopMatrix();
189  // pop gl identficador
190  glPopName();
191 }
192 
193 
194 std::string
196  switch (key) {
197  case SUMO_ATTR_ID:
198  return getAdditionalID();
199  case SUMO_ATTR_LANE:
200  return getLaneParents().front()->getID();
201  case SUMO_ATTR_POSITION:
203  case SUMO_ATTR_LENGTH:
204  return toString(myLength);
208  return toString(myBlockMovement);
209  case GNE_ATTR_PARENT:
210  return getAdditionalParents().at(0)->getID();
211  case GNE_ATTR_SELECTED:
213  case GNE_ATTR_GENERIC:
214  return getGenericParametersStr();
215  default:
216  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
217  }
218 }
219 
220 
221 void
222 GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
223  if (value == getAttribute(key)) {
224  return; //avoid needless changes, later logic relies on the fact that attributes have changed
225  }
226  switch (key) {
227  case SUMO_ATTR_ID:
228  case SUMO_ATTR_LANE:
229  case SUMO_ATTR_POSITION:
230  case SUMO_ATTR_LENGTH:
233  case GNE_ATTR_SELECTED:
234  case GNE_ATTR_GENERIC:
235  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
236  break;
237  default:
238  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
239  }
240 }
241 
242 
243 bool
244 GNEAccess::isValid(SumoXMLAttr key, const std::string& value) {
245  switch (key) {
246  case SUMO_ATTR_ID:
247  return isValidAdditionalID(value);
248  case SUMO_ATTR_LANE: {
249  GNELane* lane = myViewNet->getNet()->retrieveLane(value, false);
250  if (lane != nullptr) {
251  if (getLaneParents().front()->getParentEdge().getID() != lane->getParentEdge().getID()) {
253  } else {
254  return true;
255  }
256  } else {
257  return false;
258  }
259  }
260  case SUMO_ATTR_POSITION:
261  if (value.empty()) {
262  return true;
263  } else {
264  return canParse<double>(value);
265  }
266  case SUMO_ATTR_LENGTH:
267  if (value.empty()) {
268  return true;
269  } else {
270  return (canParse<double>(value) && (parse<double>(value) >= 0));
271  }
273  return canParse<bool>(value);
275  return canParse<bool>(value);
276  case GNE_ATTR_SELECTED:
277  return canParse<bool>(value);
278  case GNE_ATTR_GENERIC:
279  return isGenericParametersValid(value);
280  default:
281  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
282  }
283 }
284 
285 
286 std::string
288  return getTagStr();
289 }
290 
291 
292 std::string
294  return getTagStr() + ": " + getLaneParents().front()->getParentEdge().getID();
295 }
296 
297 // ===========================================================================
298 // private
299 // ===========================================================================
300 
301 void
302 GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value) {
303  switch (key) {
304  case SUMO_ATTR_ID:
305  changeAdditionalID(value);
306  break;
307  case SUMO_ATTR_LANE:
308  changeLaneParents(this, value);
309  break;
310  case SUMO_ATTR_POSITION:
311  myPositionOverLane = value;
312  break;
313  case SUMO_ATTR_LENGTH:
314  myLength = value;
315  break;
317  myFriendlyPosition = parse<bool>(value);
318  break;
320  myBlockMovement = parse<bool>(value);
321  break;
322  case GNE_ATTR_SELECTED:
323  if (parse<bool>(value)) {
325  } else {
327  }
328  break;
329  case GNE_ATTR_GENERIC:
331  break;
332  default:
333  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
334  }
335 }
336 
337 /****************************************************************************/
GUIGlObject::getType
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.cpp:181
GNEAdditional::BlockIcon::position
Position position
position of the block icon
Definition: GNEAdditional.h:351
GNEAccess::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEAccess.cpp:163
GUIVisualizationColorSettings::busStop
static const RGBColor busStop
color for busStops
Definition: GUIVisualizationSettings.h:175
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
GNEAdditional::setGenericParametersStr
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
Definition: GNEAdditional.cpp:704
GNEAdditional::getAdditionalID
const std::string & getAdditionalID() const
Definition: GNEAdditional.cpp:578
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1187
SUMO_ATTR_LENGTH
Definition: SUMOXMLDefinitions.h:394
GNEAdditional::AdditionalGeometry::shape
PositionVector shape
The shape of the additional element.
Definition: GNEAdditional.h:68
GNEAccess::~GNEAccess
~GNEAccess()
Destructor.
Definition: GNEAccess.cpp:48
GNEAdditional::BlockIcon::setRotation
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry() function)
Definition: GNEAdditional.cpp:502
GNEAccess::getEdge
GNEEdge & getEdge() const
get edge in which this Access is placed
Definition: GNEAccess.cpp:151
GNEUndoList::p_end
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
Definition: GNEUndoList.cpp:80
GNEAccess::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEAccess.cpp:130
GNEAdditional::AdditionalGeometry::shapeRotations
std::vector< double > shapeRotations
The rotations of the single shape parts.
Definition: GNEAdditional.h:74
GNEAttributeCarrier::isGenericParametersValid
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
Definition: GNEAttributeCarrier.cpp:1354
GNEAccess::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNEAccess.cpp:77
GNEViewNet
Definition: GNEViewNet.h:43
GNEAccess::myPositionOverLane
std::string myPositionOverLane
position over lane
Definition: GNEAccess.h:129
GNEAccess::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEAccess.cpp:113
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
GLHelper.h
SUMO_ATTR_LANE
Definition: SUMOXMLDefinitions.h:635
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:604
GNEAdditional::unselectAttributeCarrier
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Definition: GNEAdditional.cpp:634
GNEAdditional::myBlockIcon
BlockIcon myBlockIcon
variable BlockIcon
Definition: GNEAdditional.h:380
GLHelper::setColor
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
GNEAccess::getParentName
std::string getParentName() const
Returns the name of the parent object (if any)
Definition: GNEAccess.cpp:157
PositionVector::getBoxBoundary
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Definition: PositionVector.cpp:382
GLO_ACCESS
a Acces
Definition: GUIGlObjectTypes.h:98
GUISUMOAbstractView::snapToActiveGrid
Position snapToActiveGrid(const Position &pos, bool snapXY=true) const
Returns a position that is mapped to the closest grid point if the grid is active.
Definition: GUISUMOAbstractView.cpp:194
GNEAdditional::myMove
AdditionalMove myMove
variable AdditionalMove
Definition: GNEAdditional.h:371
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:365
GNEEdge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
GNEAttributeCarrier::GNEChange_Attribute
friend class GNEChange_Attribute
declare friend class
Definition: GNEAttributeCarrier.h:57
GNEHierarchicalElementParents::getLaneParents
const std::vector< GNELane * > & getLaneParents() const
get lanes of VSS
Definition: GNEHierarchicalElementParents.cpp:182
GNEUndoList::p_add
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Definition: GNEUndoList.cpp:132
GNEViewNet::getNet
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
GLHelper::drawFilledCircle
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:348
GNEAccess::myLength
std::string myLength
Acces lenght.
Definition: GNEAccess.h:132
GNEAdditional::isAttributeCarrierSelected
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
Definition: GNEAdditional.cpp:650
GNEAccess::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEAccess.cpp:287
GUIVisualizationColorSettings::selectedAdditionalColor
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
Definition: GUIVisualizationSettings.h:148
GNEAccess.h
GNEAdditional::selectAttributeCarrier
void selectAttributeCarrier(bool changeFlag=true)
Definition: GNEAdditional.cpp:619
GLHelper::drawFilledCircleReturnVertices
static std::vector< Position > drawFilledCircleReturnVertices(double width, int steps=8)
Draws a filled circle around (0,0) returning circle vertex.
Definition: GLHelper.cpp:354
GNEViewNet.h
GNEAdditionalHandler.h
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:150
GNEViewNet::getDottedAC
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
Definition: GNEViewNet.cpp:939
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
GNELane::getParentEdge
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1292
GLHelper::drawShapeDottedContourAroundClosedShape
static void drawShapeDottedContourAroundClosedShape(const GUIVisualizationSettings &s, const int type, const PositionVector &shape)
draw a dotted contour around the given closed shape with certain width
Definition: GLHelper.cpp:496
GNEAdditional::AdditionalGeometry::clearGeometry
void clearGeometry()
reset geometry
Definition: GNEAdditional.cpp:53
GNEAccess::setAttribute
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:222
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
GNEEdge.h
GNEAccess::myFriendlyPosition
bool myFriendlyPosition
flag to check if friendly position is enabled
Definition: GNEAccess.h:135
GNEAdditional::myBlockMovement
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse)
Definition: GNEAdditional.h:377
GNEAdditionalHandler::accessCanBeCreated
static bool accessCanBeCreated(GNEAdditional *busStopParent, GNEEdge &edge)
check if a GNEAccess can be created in a certain Edge
Definition: GNEAdditionalHandler.cpp:1009
SUMO_ATTR_FRIENDLY_POS
Definition: SUMOXMLDefinitions.h:762
GNELane.h
SUMO_ATTR_POSITION
Definition: SUMOXMLDefinitions.h:658
GUIVisualizationSettings::colorSettings
GUIVisualizationColorSettings colorSettings
color settings
Definition: GUIVisualizationSettings.h:649
GNEAccess::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEAccess.cpp:53
GLIncludes.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GNE_ATTR_GENERIC
generic attribute
Definition: SUMOXMLDefinitions.h:986
GNEAccess::GNEAccess
GNEAccess(GNEAdditional *busStop, GNELane *lane, GNEViewNet *viewNet, const std::string &pos, const std::string &length, bool friendlyPos, bool blockMovement)
Constructor.
Definition: GNEAccess.cpp:39
GNEHierarchicalElementParents::getAdditionalParents
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parent this edge (For example, Calibrators)
Definition: GNEHierarchicalElementParents.cpp:86
InvalidArgument
Definition: UtilExceptions.h:57
GNEAdditional::getGenericParametersStr
std::string getGenericParametersStr() const
return generic parameters in string format
Definition: GNEAdditional.cpp:678
GNE_ATTR_BLOCK_MOVEMENT
block movement of a graphic element
Definition: SUMOXMLDefinitions.h:978
GNEAdditional::drawUsingSelectColor
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
Definition: GNEAdditional.cpp:656
GNEAccess::isAccessPositionFixed
bool isAccessPositionFixed() const
check if Position of Access is fixed
Definition: GNEAccess.cpp:136
GNEHierarchicalElementParents::changeLaneParents
void changeLaneParents(GNEShape *elementChild, const std::string &newLaneIDs)
change edge parents of a shape
Definition: GNEHierarchicalElementParents.cpp:460
GNEAccess::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEAccess.cpp:293
GNEAdditional::myGeometry
AdditionalGeometry myGeometry
geometry to be precomputed in updateGeometry(...)
Definition: GNEAdditional.h:368
GNENet::retrieveLane
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1179
config.h
GUIVisualizationSettings::addSize
GUIVisualizationSizeSettings addSize
Definition: GUIVisualizationSettings.h:580
Position::add
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:127
GNE_ATTR_SELECTED
element is selected
Definition: SUMOXMLDefinitions.h:968
Boundary::grow
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1165
GNEUndoList
Definition: GNEUndoList.h:49
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:346
SUMO_TAG_ACCESS
An access point for a train stop.
Definition: SUMOXMLDefinitions.h:104
PositionVector::getLineCenter
Position getLineCenter() const
get line center
Definition: PositionVector.cpp:466
GNEAdditional::isValidAdditionalID
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Definition: GNEAdditional.cpp:584
GNEUndoList::p_begin
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:73
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:373
GNEAdditional::AdditionalMove::originalViewPosition
Position originalViewPosition
value for saving first original position over lane before moving
Definition: GNEAdditional.h:329
GNEAccess::getAttribute
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEAccess.cpp:195
GNEAdditional::AdditionalMove::firstOriginalLanePosition
std::string firstOriginalLanePosition
value for saving first original position over lane before moving
Definition: GNEAdditional.h:332
GNELane
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
GNEAccess::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNEAccess.cpp:66
GNEChange_Attribute.h
GNENet.h
GUIVisualizationSizeSettings::getExaggeration
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
Definition: GUIVisualizationSettings.cpp:212
GNEAdditional::BlockIcon::offset
Position offset
The offSet of the block icon.
Definition: GNEAdditional.h:354
GNEAccess::isValid
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEAccess.cpp:244
GNEUndoList.h
GNE_ATTR_PARENT
parent of an additional element
Definition: SUMOXMLDefinitions.h:984
GUIVisualizationSettings::drawForSelecting
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
Definition: GUIVisualizationSettings.h:635