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-2018 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  myLane(lane),
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);
60  // Update geometry
61  updateGeometry(false);
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
77 GNEAccess::updateGeometry(bool updateGrid) {
78  // first check if object has to be removed from grid (SUMOTree)
79  if (updateGrid) {
81  }
82 
83  // Clear all containers
85 
86  // Get shape of lane parent
88 
89  // set start position
90  double fixedPositionOverLane;
91  if (!canParse<double>(myPositionOverLane)) {
92  fixedPositionOverLane = myLane->getParentEdge().getNBEdge()->getFinalLength();
93  } else if (parse<double>(myPositionOverLane) < 0) {
94  fixedPositionOverLane = 0;
95  } else if (parse<double>(myPositionOverLane) > myLane->getParentEdge().getNBEdge()->getFinalLength()) {
96  fixedPositionOverLane = myLane->getParentEdge().getNBEdge()->getFinalLength();
97  } else {
98  fixedPositionOverLane = parse<double>(myPositionOverLane);
99  }
100  // obtain position
101  myGeometry.shape[0] = myLane->getShape().positionAtOffset(fixedPositionOverLane * myLane->getLengthGeometryFactor());
102 
103  // Save rotation (angle) of the vector constructed by points f and s
104  myGeometry.shapeRotations.push_back(myLane->getShape().rotationDegreeAtOffset(fixedPositionOverLane) * -1);
105 
106  // Set block icon position
108 
109  // Set offset of the block icon
110  myBlockIcon.offset = Position(-1, 0);
111 
112  // Set block icon rotation, and using their rotation for logo
114 
115  // last step is to check if object has to be added into grid (SUMOTree) again
116  if (updateGrid) {
118  }
119 }
120 
121 
122 Position
124  if (!canParse<double>(myPositionOverLane)) {
125  return myLane->getShape().front();
126  } else {
127  double posOverLane = parse<double>(myPositionOverLane);
128  if (posOverLane < 0) {
129  return myLane->getShape().front();
130  } else if (posOverLane > myLane->getShape().length()) {
131  return myLane->getShape().back();
132  } else {
133  return myLane->getShape().positionAtOffset(posOverLane);
134  }
135  }
136 }
137 
138 
139 bool
141  // with friendly position enabled position are "always fixed"
142  if (myFriendlyPosition) {
143  return true;
144  } else {
145  if (canParse<double>(myPositionOverLane)) {
146  return (parse<double>(myPositionOverLane) >= 0) && ((parse<double>(myPositionOverLane)) <= myLane->getParentEdge().getNBEdge()->getFinalLength());
147  } else {
148  return false;
149  }
150  }
151 }
152 
153 
154 GNEEdge&
156  return myLane->getParentEdge();
157 }
158 
159 
160 std::string
162  return myFirstAdditionalParent->getID();
163 }
164 
165 
166 void
168  // Obtain exaggeration of the draw
169  const double exaggeration = s.addSize.getExaggeration(s, this);
170  // Start drawing adding an gl identificator
171  glPushName(getGlID());
172  // push matrix
173  glPushMatrix();
174  // set color depending of selection
175  if (mySelected) {
177  } else {
179  }
180  glTranslated(myGeometry.shape[0].x(), myGeometry.shape[0].y(), GLO_ACCESS);
181  // draw circle
182  if (s.drawForSelecting) {
183  GLHelper::drawFilledCircle((double) 0.5 * exaggeration, 8);
184  } else {
185  std::vector<Position> vertices = GLHelper::drawFilledCircleReturnVertices((double) 0.5 * exaggeration, 16);
186  // check if dotted contour has to be drawn
187  if (myViewNet->getDottedAC() == this) {
189  }
190  }
191  // pop matrix
192  glPopMatrix();
193  // pop gl identficador
194  glPopName();
195 }
196 
197 
198 std::string
200  switch (key) {
201  case SUMO_ATTR_ID:
202  return getAdditionalID();
203  case SUMO_ATTR_LANE:
204  return myLane->getID();
205  case SUMO_ATTR_POSITION:
207  case SUMO_ATTR_LENGTH:
208  return toString(myLength);
212  return toString(myBlockMovement);
213  case GNE_ATTR_PARENT:
214  return myFirstAdditionalParent->getID();
215  case GNE_ATTR_SELECTED:
217  case GNE_ATTR_GENERIC:
218  return getGenericParametersStr();
219  default:
220  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
221  }
222 }
223 
224 
225 void
226 GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
227  if (value == getAttribute(key)) {
228  return; //avoid needless changes, later logic relies on the fact that attributes have changed
229  }
230  switch (key) {
231  case SUMO_ATTR_ID:
232  case SUMO_ATTR_LANE:
233  case SUMO_ATTR_POSITION:
234  case SUMO_ATTR_LENGTH:
237  case GNE_ATTR_SELECTED:
238  case GNE_ATTR_GENERIC:
239  undoList->p_add(new GNEChange_Attribute(this, key, value));
240  break;
241  default:
242  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
243  }
244 }
245 
246 
247 bool
248 GNEAccess::isValid(SumoXMLAttr key, const std::string& value) {
249  switch (key) {
250  case SUMO_ATTR_ID:
251  return isValidAdditionalID(value);
252  case SUMO_ATTR_LANE: {
253  GNELane* lane = myViewNet->getNet()->retrieveLane(value, false);
254  if (lane != nullptr) {
255  if (myLane->getParentEdge().getID() != lane->getParentEdge().getID()) {
257  } else {
258  return true;
259  }
260  } else {
261  return false;
262  }
263  }
264  case SUMO_ATTR_POSITION:
265  if (value.empty()) {
266  return true;
267  } else {
268  return canParse<double>(value);
269  }
270  case SUMO_ATTR_LENGTH:
271  if (value.empty()) {
272  return true;
273  } else {
274  return (canParse<double>(value) && (parse<double>(value) >= 0));
275  }
277  return canParse<bool>(value);
279  return canParse<bool>(value);
280  case GNE_ATTR_SELECTED:
281  return canParse<bool>(value);
282  case GNE_ATTR_GENERIC:
283  return isGenericParametersValid(value);
284  default:
285  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
286  }
287 }
288 
289 
290 std::string
292  return getTagStr();
293 }
294 
295 
296 std::string
298  return getTagStr() + ": " + myLane->getParentEdge().getID();
299 }
300 
301 // ===========================================================================
302 // private
303 // ===========================================================================
304 
305 void
306 GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value) {
307  switch (key) {
308  case SUMO_ATTR_ID:
309  changeAdditionalID(value);
310  break;
311  case SUMO_ATTR_LANE:
312  myLane = changeLane(myLane, value);
313  break;
314  case SUMO_ATTR_POSITION:
315  myPositionOverLane = value;
316  break;
317  case SUMO_ATTR_LENGTH:
318  myLength = value;
319  break;
321  myFriendlyPosition = parse<bool>(value);
322  break;
324  myBlockMovement = parse<bool>(value);
325  break;
326  case GNE_ATTR_SELECTED:
327  if (parse<bool>(value)) {
329  } else {
331  }
332  break;
333  case GNE_ATTR_GENERIC:
335  break;
336  default:
337  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
338  }
339  // Update Geometry after setting a new attribute (but avoided for certain attributes)
340  if((key != SUMO_ATTR_ID) && (key != GNE_ATTR_GENERIC) && (key != GNE_ATTR_SELECTED)) {
341  updateGeometry(true);
342  }
343 }
344 
345 /****************************************************************************/
bool mySelected
boolean to check if this AC is selected (instead of GUIGlObjectStorage)
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEAccess.cpp:297
std::vector< double > shapeRotations
The rotations of the single shape parts.
bool isAccessPositionFixed() const
check if Position of Access is fixed
Definition: GNEAccess.cpp:140
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
returns Additional ID
Stores the information about how to visualize structures.
GNEEdge & getEdge() const
get edge in which this Access is placed
Definition: GNEAccess.cpp:155
Position offset
The offSet of the block icon.
Position snapToActiveGrid(const Position &pos) const
Returns a position that is mapped to the closest grid point if the grid is active.
void updateGeometry(bool updateGrid)
update pre-computed geometry information
Definition: GNEAccess.cpp:77
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:47
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.
GNELane * myLane
lane in which this Access is placed
Definition: GNEAccess.h:126
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:226
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:344
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEAccess.cpp:291
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:167
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:49
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:573
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1260
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.
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1160
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
static std::vector< Position > drawFilledCircleReturnVertices(double width, int steps=8)
Draws a filled circle around (0,0) returning circle vertex.
Definition: GLHelper.cpp:350
block movement of a graphic element
double getLengthGeometryFactor() const
get lenght geometry factor
Definition: GNELane.cpp:1317
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEAccess.cpp:123
GNEAccess(GNEAdditional *busStop, GNELane *lane, GNEViewNet *viewNet, const std::string &pos, const std::string &length, bool friendlyPos, bool blockMovement)
Constructor.
Definition: GNEAccess.cpp:39
const std::string getID() const
function to support debugging
static const RGBColor SUMO_color_busStop
color for busStops
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition: NBEdge.cpp:3575
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) ...
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
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:669
double length() const
Returns the length.
static void drawShapeDottedContour(const int type, const PositionVector &shape, const double width)
draw a dotted contour around the given Non closed shape with certain width
Definition: GLHelper.cpp:471
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
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:248
GNENet * getNet() const
get the net object
std::string myPositionOverLane
position over lane
Definition: GNEAccess.h:129
GUIGlID getGlID() const
Returns the numerical id of the object.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
parent of an additional element
~GNEAccess()
Destructor.
Definition: GNEAccess.cpp:48
std::string firstOriginalLanePosition
value for saving first original position over lane before moving
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:613
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:161
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
An access point for a train stop.
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1153
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEAccess.cpp:199
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1059
GNEAdditional * myFirstAdditionalParent
pointer to first Additional parent
GNELane * changeLane(GNELane *oldLane, const std::string &newLaneID)
change lane of additional
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry(bool updateGrid) function) ...