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 <string>
24 #include <iostream>
25 #include <utility>
26 #include <netbuild/NBEdge.h>
30 #include <utils/common/ToString.h>
31 #include <utils/geom/GeomHelper.h>
36 #include <utils/gui/div/GLHelper.h>
42 #include <netedit/GNEViewNet.h>
43 #include <netedit/GNEUndoList.h>
44 #include <netedit/GNENet.h>
47 #include <netedit/GNEViewParent.h>
48 
49 #include "GNEAccess.h"
50 #include "GNEBusStop.h"
51 #include "GNEAdditionalHandler.h"
52 
53 // ===========================================================================
54 // member method definitions
55 // ===========================================================================
56 
57 GNEAccess::GNEAccess(GNEAdditional* busStop, GNELane* lane, GNEViewNet* viewNet, const std::string& pos, const std::string& length, bool friendlyPos, bool blockMovement) :
58  GNEAdditional(busStop, viewNet, GLO_ACCESS, SUMO_TAG_ACCESS, "", blockMovement),
59  myLane(lane),
60  myPositionOverLane(pos),
61  myLength(length),
62  myFriendlyPosition(friendlyPos) {
63 }
64 
65 
67 }
68 
69 
70 void
71 GNEAccess::moveGeometry(const Position& oldPos, const Position& offset) {
72  // Calculate new position using old position
73  Position newPosition = oldPos;
74  newPosition.add(offset);
76  // Update geometry
77  updateGeometry(false);
78 }
79 
80 
81 void
83  if (!myBlockMovement) {
84  // restore old position before commit new position
85  double originalPosOverLane = myLane->getShape().nearest_offset_to_point2D(oldPos, false);
86  // commit new position allowing undo/redo
87  undoList->p_begin("position of " + toString(getTag()));
88  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, myPositionOverLane, true, toString(originalPosOverLane)));
89  undoList->p_end();
90  }
91 }
92 
93 
94 void
95 GNEAccess::updateGeometry(bool updateGrid) {
96  // first check if object has to be removed from grid (SUMOTree)
97  if (updateGrid) {
99  }
100 
101  // Clear all containers
102  myShapeRotations.clear();
103  myShapeLengths.clear();
104 
105  // Get shape of lane parent
106  myShape = myLane->getShape();
107 
108  // set start position
109  double fixedPositionOverLane;
110  if (!canParse<double>(myPositionOverLane)) {
111  fixedPositionOverLane = myLane->getParentEdge().getNBEdge()->getFinalLength();
112  } else if (parse<double>(myPositionOverLane) < 0) {
113  fixedPositionOverLane = 0;
114  } else if (parse<double>(myPositionOverLane) > myLane->getParentEdge().getNBEdge()->getFinalLength()) {
115  fixedPositionOverLane = myLane->getParentEdge().getNBEdge()->getFinalLength();
116  } else {
117  fixedPositionOverLane = parse<double>(myPositionOverLane);
118  }
119  // obtain position
120  myShape[0] = myLane->getShape().positionAtOffset(fixedPositionOverLane * myLane->getLengthGeometryFactor());
121 
122  // Save rotation (angle) of the vector constructed by points f and s
123  myShapeRotations.push_back(myLane->getShape().rotationDegreeAtOffset(fixedPositionOverLane) * -1);
124 
125  // Set block icon position
126  myBlockIconPosition = myShape.getLineCenter();
127 
128  // Set offset of the block icon
129  myBlockIconOffset = Position(-1, 0);
130 
131  // Set block icon rotation, and using their rotation for logo
133 
134  // last step is to check if object has to be added into grid (SUMOTree) again
135  if (updateGrid) {
137  }
138 }
139 
140 
141 Position
143  if (!canParse<double>(myPositionOverLane)) {
144  return myLane->getShape().front();
145  } else {
146  double posOverLane = parse<double>(myPositionOverLane);
147  if (posOverLane < 0) {
148  return myLane->getShape().front();
149  } else if (posOverLane > myLane->getShape().length()) {
150  return myLane->getShape().back();
151  } else {
152  return myLane->getShape().positionAtOffset(posOverLane);
153  }
154  }
155 }
156 
157 
158 bool
160  // with friendly position enabled position are "always fixed"
161  if (myFriendlyPosition) {
162  return true;
163  } else {
164  if (canParse<double>(myPositionOverLane)) {
165  return (parse<double>(myPositionOverLane) >= 0) && ((parse<double>(myPositionOverLane)) <= myLane->getParentEdge().getNBEdge()->getFinalLength());
166  } else {
167  return false;
168  }
169  }
170 }
171 
172 
173 GNEEdge&
175  return myLane->getParentEdge();
176 }
177 
178 
179 std::string
181  return myFirstAdditionalParent->getID();
182 }
183 
184 
185 void
187  // Obtain exaggeration of the draw
188  const double exaggeration = s.addSize.getExaggeration(s);
189  // Start drawing adding an gl identificator
190  glPushName(getGlID());
191  // push matrix
192  glPushMatrix();
193  // set color depending of selection
194  if (mySelected) {
196  } else {
198  }
199  glTranslated(myShape[0].x(), myShape[0].y(), GLO_ACCESS);
200  // draw circle
201  if (s.drawForSelecting) {
202  GLHelper::drawFilledCircle((double) 0.5 * exaggeration, 8);
203  } else {
204  std::vector<Position> vertices = GLHelper::drawFilledCircleReturnVertices((double) 0.5 * exaggeration, 16);
205  // check if dotted contour has to be drawn
206  if (myViewNet->getACUnderCursor() == this) {
208  }
209  }
210  // pop matrix
211  glPopMatrix();
212  // pop gl identficador
213  glPopName();
214 }
215 
216 
217 std::string
219  switch (key) {
220  case SUMO_ATTR_ID:
221  return getAdditionalID();
222  case SUMO_ATTR_LANE:
223  return myLane->getID();
224  case SUMO_ATTR_POSITION:
226  case SUMO_ATTR_LENGTH:
227  return toString(myLength);
231  return toString(myBlockMovement);
232  case GNE_ATTR_PARENT:
233  return myFirstAdditionalParent->getID();
234  case GNE_ATTR_SELECTED:
236  case GNE_ATTR_GENERIC:
237  return getGenericParametersStr();
238  default:
239  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
240  }
241 }
242 
243 
244 void
245 GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
246  if (value == getAttribute(key)) {
247  return; //avoid needless changes, later logic relies on the fact that attributes have changed
248  }
249  switch (key) {
250  case SUMO_ATTR_ID:
251  case SUMO_ATTR_LANE:
252  case SUMO_ATTR_POSITION:
253  case SUMO_ATTR_LENGTH:
256  case GNE_ATTR_SELECTED:
257  case GNE_ATTR_GENERIC:
258  undoList->p_add(new GNEChange_Attribute(this, key, value));
259  break;
260  default:
261  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
262  }
263 }
264 
265 
266 bool
267 GNEAccess::isValid(SumoXMLAttr key, const std::string& value) {
268  switch (key) {
269  case SUMO_ATTR_ID:
270  return isValidAdditionalID(value);
271  case SUMO_ATTR_LANE: {
272  GNELane* lane = myViewNet->getNet()->retrieveLane(value, false);
273  if (lane != nullptr) {
274  if (myLane->getParentEdge().getID() != lane->getParentEdge().getID()) {
276  } else {
277  return true;
278  }
279  } else {
280  return false;
281  }
282  }
283  case SUMO_ATTR_POSITION:
284  if (value.empty()) {
285  return true;
286  } else {
287  return canParse<double>(value);
288  }
289  case SUMO_ATTR_LENGTH:
290  if (value.empty()) {
291  return true;
292  } else {
293  return (canParse<double>(value) && (parse<double>(value) >= 0));
294  }
296  return canParse<bool>(value);
298  return canParse<bool>(value);
299  case GNE_ATTR_SELECTED:
300  return canParse<bool>(value);
301  case GNE_ATTR_GENERIC:
302  return isGenericParametersValid(value);
303  default:
304  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
305  }
306 }
307 
308 
309 std::string
311  return toString(getTag());
312 }
313 
314 
315 std::string
317  return toString(getTag()) + ": " + myLane->getParentEdge().getID();
318 }
319 
320 // ===========================================================================
321 // private
322 // ===========================================================================
323 
324 void
325 GNEAccess::setAttribute(SumoXMLAttr key, const std::string& value) {
326  switch (key) {
327  case SUMO_ATTR_ID:
328  changeAdditionalID(value);
329  break;
330  case SUMO_ATTR_LANE:
331  myLane = changeLane(myLane, value);
332  break;
333  case SUMO_ATTR_POSITION:
334  myPositionOverLane = value;
335  break;
336  case SUMO_ATTR_LENGTH:
337  myLength = value;
338  break;
340  myFriendlyPosition = parse<bool>(value);
341  break;
343  myBlockMovement = parse<bool>(value);
344  break;
345  case GNE_ATTR_SELECTED:
346  if (parse<bool>(value)) {
348  } else {
350  }
351  break;
352  case GNE_ATTR_GENERIC:
354  break;
355  default:
356  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
357  }
358  // After setting attribute always update Geometry
359  updateGeometry(true);
360 }
361 
362 /****************************************************************************/
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.
const GNEAttributeCarrier * getACUnderCursor() const
get AttributeCarrier under cursor
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEAccess.cpp:316
void setBlockIconRotation(GNELane *additionalLane=nullptr)
bool isAccessPositionFixed() const
check if Position of Access is fixed
Definition: GNEAccess.cpp:159
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:126
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:174
void updateGeometry(bool updateGrid)
update pre-computed geometry information
Definition: GNEAccess.cpp:95
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
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:78
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
GNELane * myLane
lane in which this Access is placed
Definition: GNEAccess.h:129
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:245
std::vector< double > myShapeRotations
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:310
std::string myLength
Acces lenght.
Definition: GNEAccess.h:135
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
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:186
bool myFriendlyPosition
flag to check if friendly position is enabled
Definition: GNEAccess.h:138
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:105
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:1298
PositionVector myShape
The shape of the additional element.
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:85
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
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:1175
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
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEAccess.cpp:71
block movement of a graphic element
double getLengthGeometryFactor() const
get lenght geometry factor
Definition: GNELane.cpp:1355
std::vector< double > myShapeLengths
The lengths of the shape parts.
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEAccess.cpp:142
GNEAccess(GNEAdditional *busStop, GNELane *lane, GNEViewNet *viewNet, const std::string &pos, const std::string &length, bool friendlyPos, bool blockMovement)
Constructor.
Definition: GNEAccess.cpp:57
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:3543
static bool accessCanBeCreated(GNEAdditional *busStopParent, GNEEdge &edge)
check if a GNEAccess can be created in a certain Edge
Position myBlockIconOffset
The offSet of the block icon.
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
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:679
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:53
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
Definition: GNEAccess.cpp:82
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:267
GNENet * getNet() const
get the net object
std::string myPositionOverLane
position over lane
Definition: GNEAccess.h:132
GUIGlID getGlID() const
Returns the numerical id of the object.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
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:66
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:586
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
std::string getParentName() const
Returns the name of the parent object (if any)
Definition: GNEAccess.cpp:180
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:1168
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEAccess.cpp:218
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1074
GNEAdditional * myFirstAdditionalParent
pointer to first Addititional parent
GNELane * changeLane(GNELane *oldLane, const std::string &newLaneID)
change lane of additional
Position myBlockIconPosition
position of the block icon
SumoXMLTag getTag() const
get XML Tag assigned to this object