SUMO - Simulation of Urban MObility
GNEStoppingPlace.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // A abstract class to define common parameters of lane area in which vehicles can halt (GNE version)
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include <string>
30 #include <iostream>
31 #include <utility>
35 #include <utils/common/ToString.h>
36 #include <utils/geom/GeomHelper.h>
42 #include <utils/gui/div/GLHelper.h>
46 
47 #include "GNEStoppingPlace.h"
48 #include "GNELane.h"
49 #include "GNEEdge.h"
50 #include "GNEJunction.h"
51 #include "GNEUndoList.h"
52 #include "GNENet.h"
53 #include "GNEChange_Attribute.h"
54 #include "GNEViewNet.h"
55 #include "GNEAdditionalHandler.h"
56 
57 
58 // ===========================================================================
59 // member method definitions
60 // ===========================================================================
61 
62 GNEStoppingPlace::GNEStoppingPlace(const std::string& id, GNEViewNet* viewNet, SumoXMLTag tag, GUIIcon icon, GNELane* lane, double startPos, double endPos, const std::string& name, bool friendlyPosition) :
63  GNEAdditional(id, viewNet, tag, icon, true),
64  myLane(lane),
65  myStartPosRelative(startPos / lane->getLaneParametricLength()),
66  myEndPosRelative(endPos / lane->getLaneParametricLength()),
67  myName(name),
68  myFriendlyPosition(friendlyPosition) {
69 }
70 
71 
73 
74 
77  double stoppingPlaceCenterRelative = (myEndPosRelative + myStartPosRelative) / 2.0;
78  return myLane->getShape().positionAtOffset(stoppingPlaceCenterRelative * myLane->getLaneShapeLength());
79 }
80 
81 
82 void
83 GNEStoppingPlace::moveGeometry(const Position& oldPos, const Position& offset) {
84  double halfStoppingPlaceLenghtRelative = (myEndPosRelative - myStartPosRelative) / 2.0;
85  // Calculate new position using old position
86  Position newPosition = oldPos;
87  newPosition.add(offset);
88  double newStoppingPlaceCenter = myLane->getShape().nearest_offset_to_point2D(newPosition, false) / myLane->getLaneShapeLength();
89  // change start position of stopping place
90  myStartPosRelative = newStoppingPlaceCenter - halfStoppingPlaceLenghtRelative;
91  myEndPosRelative = newStoppingPlaceCenter + halfStoppingPlaceLenghtRelative;
92  // Update geometry
94 }
95 
96 
97 void
99  double halfStoppingPlaceLenghtRelative = (myEndPosRelative - myStartPosRelative) / 2.0;
100  double oldStoppingPlaceCenterOffset = myLane->getShape().nearest_offset_to_point2D(oldPos, false) / myLane->getLaneShapeLength();
101  undoList->p_begin("position of " + toString(getTag()));
102  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_STARTPOS, toString(getAbsoluteStartPosition()), true, toString((oldStoppingPlaceCenterOffset - halfStoppingPlaceLenghtRelative) * myLane->getLaneParametricLength())));
103  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_ENDPOS, toString(getAbsoluteEndPosition()), true, toString((oldStoppingPlaceCenterOffset + halfStoppingPlaceLenghtRelative) * myLane->getLaneParametricLength())));
104  undoList->p_end();
105 }
106 
107 
108 GNELane*
110  return myLane;
111 }
112 
113 
114 double
117 }
118 
119 
120 double
123 }
124 
125 
126 bool
128  // with friendly position enabled position are "always fixed"
129  if (myFriendlyPosition) {
130  return true;
131  } else {
132  // floors are needed to avoid precision problems
133  return ((floor(myStartPosRelative * 1000) / 1000) >= 0) &&
134  ((floor(myEndPosRelative * 1000) / 1000) <= 1) &&
136  }
137 }
138 
139 
140 const std::string&
142  return myLane->getMicrosimID();
143 }
144 
145 
146 void
148  // Clear all containers
149  myShapeRotations.clear();
150  myShapeLengths.clear();
151 
152  // Get value of option "lefthand"
153  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
154 
155  // Get shape of lane parent
156  myShape = myLane->getShape();
157 
158  // Move shape to side
159  myShape.move2side(1.65 * offsetSign);
160 
161  // Cut shape using as delimitators fixed start position and fixed end position
162  double startPosFixed = (myStartPosRelative < 0) ? 0 : myStartPosRelative;
163  double endPosFixed = (myEndPosRelative > 1) ? 1 : myEndPosRelative;
164  myShape = myShape.getSubpart(startPosFixed * myShape.length() , endPosFixed * myShape.length());
165 
166  // Get number of parts of the shape
167  int numberOfSegments = (int) myShape.size() - 1;
168 
169  // If number of segments is more than 0
170  if (numberOfSegments >= 0) {
171 
172  // Reserve memory (To improve efficiency)
173  myShapeRotations.reserve(numberOfSegments);
174  myShapeLengths.reserve(numberOfSegments);
175 
176  // For every part of the shape
177  for (int i = 0; i < numberOfSegments; ++i) {
178 
179  // Obtain first position
180  const Position& f = myShape[i];
181 
182  // Obtain next position
183  const Position& s = myShape[i + 1];
184 
185  // Save distance between position into myShapeLengths
186  myShapeLengths.push_back(f.distanceTo(s));
187 
188  // Save rotation (angle) of the vector constructed by points f and s
189  myShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double)M_PI);
190  }
191  }
192 }
193 
194 /****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
bool areStoppingPlacesPositionsFixed() const
check if Position of stoppingPlace are fixed
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:132
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:42
GNEStoppingPlace(const std::string &id, GNEViewNet *viewNet, SumoXMLTag tag, GUIIcon icon, GNELane *lane, double startPos, double endPos, const std::string &name, bool friendlyPosition)
Constructor.
double y() const
Returns the y-position.
Definition: Position.h:67
Position getPositionInView() const
Returns position of additional in view.
double getAbsoluteEndPosition() const
get absolute end Position
double x() const
Returns the x-position.
Definition: Position.h:62
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:53
bool myFriendlyPosition
Flag for friendly position.
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:84
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
std::vector< double > myShapeRotations
GNELane * getLane() const
get Lane
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:701
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
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:91
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
GNELane * myLane
The lane in which this lane is placed.
friend class GNEChange_Attribute
declare friend class
const std::string & getParentName() const
Returns the name of the parent object (if any)
std::vector< double > myShapeLengths
The lengths of the shape parts.
#define POSITION_EPS
Definition: config.h:175
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
~GNEStoppingPlace()
Destructor.
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
double getLaneShapeLength() const
returns the length of the lane&#39;s shape
Definition: GNELane.cpp:712
void move2side(double amount)
move position vector to side using certain ammount
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:599
double length() const
Returns the length.
#define M_PI
Definition: odrSpiral.cpp:40
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:59
double myEndPosRelative
The relative [0,1] end position this stopping place is located at.
double myStartPosRelative
The relative [0,1] start position this stopping place is located at.
virtual void updateGeometry()=0
update pre-computed geometry information
void setStoppingPlaceGeometry()
set geometry common to all stopping places
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:239
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
double getAbsoluteStartPosition() const
get absolute start Position
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
SumoXMLTag getTag() const
get XML Tag assigned to this object