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}, {}, {}, {}, {}, {}, {}),
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 /****************************************************************************/
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.
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEAccess.cpp:293
std::vector< double > shapeRotations
The rotations of the single shape parts.
Definition: GNEAdditional.h:74
bool isAccessPositionFixed() const
check if Position of Access is fixed
Definition: GNEAccess.cpp:136
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:127
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
Stores the information about how to visualize structures.
GNEEdge & getEdge() const
get edge in which this Access is placed
Definition: GNEAccess.cpp:151
Position offset
The offSet of the block icon.
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Position position
position of the block icon
BlockIcon myBlockIcon
variable BlockIcon
void clearGeometry()
reset geometry
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
Position originalViewPosition
value for saving first original position over lane before moving
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
Numbers representing SUMO-XML - attributes.
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
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
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:348
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEAccess.cpp:287
Position getLineCenter() const
get line center
std::string myLength
Acces lenght.
Definition: GNEAccess.h:132
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
AdditionalMove myMove
variable AdditionalMove
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEAccess.cpp:163
bool myFriendlyPosition
flag to check if friendly position is enabled
Definition: GNEAccess.h:135
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1292
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
Definition: GNEUndoList.cpp:80
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
PositionVector shape
The shape of the additional element.
Definition: GNEAdditional.h:68
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
void updateGeometry()
update pre-computed geometry information
Definition: GNEAccess.cpp:77
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
const std::vector< GNELane * > & getLaneParents() const
get lanes of VSS
static std::vector< Position > drawFilledCircleReturnVertices(double width, int steps=8)
Draws a filled circle around (0,0) returning circle vertex.
Definition: GLHelper.cpp:354
block movement of a graphic element
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
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
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEAccess.cpp:113
GNEAccess(GNEAdditional *busStop, GNELane *lane, GNEViewNet *viewNet, const std::string &pos, const std::string &length, bool friendlyPos, bool blockMovement)
Constructor.
Definition: GNEAccess.cpp:39
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
const std::string getID() const
function to support debugging
static bool accessCanBeCreated(GNEAdditional *busStopParent, GNEEdge &edge)
check if a GNEAccess can be created in a certain Edge
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEAccess.cpp:130
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEAccess.cpp:53
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
void changeLaneParents(GNEShape *elementChild, const std::string &newLaneIDs)
change edge parents of a shape
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
Definition: GNEViewNet.cpp:939
AdditionalGeometry myGeometry
geometry to be precomputed in updateGeometry(...)
const std::string & getTagStr() const
get tag assigned to this object in string format
element is selected
std::string getGenericParametersStr() const
return generic parameters in string format
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEAccess.cpp:244
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
std::string myPositionOverLane
position over lane
Definition: GNEAccess.h:129
GUIGlID getGlID() const
Returns the numerical id of the object.
GUIVisualizationColorSettings colorSettings
color settings
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
parent of an additional element
~GNEAccess()
Destructor.
Definition: GNEAccess.cpp:48
std::string firstOriginalLanePosition
value for saving first original position over lane before moving
static const RGBColor busStop
color for busStops
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
Definition: GNEAccess.cpp:66
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
std::string getParentName() const
Returns the name of the parent object (if any)
Definition: GNEAccess.cpp:157
An access point for a train stop.
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEAccess.cpp:195
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1179
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry() function)