SUMO - Simulation of Urban MObility
GNEStoppingPlace.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A abstract class to define common parameters of lane area in which vehicles can halt (GNE version)
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <string>
31 #include <iostream>
32 #include <utility>
37 #include <utils/common/ToString.h>
38 #include <utils/geom/GeomHelper.h>
45 #include <utils/gui/div/GLHelper.h>
49 
50 #include "GNEStoppingPlace.h"
51 #include "GNELane.h"
52 #include "GNEEdge.h"
53 #include "GNEJunction.h"
54 #include "GNEUndoList.h"
55 #include "GNENet.h"
56 #include "GNEChange_Attribute.h"
57 #include "GNEViewNet.h"
58 #include "GNEAdditionalHandler.h"
59 
60 
61 // ===========================================================================
62 // member method definitions
63 // ===========================================================================
64 
65 GNEStoppingPlace::GNEStoppingPlace(const std::string& id, GNEViewNet* viewNet, SumoXMLTag tag, GUIIcon icon, GNELane* lane, double startPos, double endPos, const std::string& name, bool friendlyPosition) :
66  GNEAdditional(id, viewNet, tag, icon),
67  myStartPosRelative(startPos / lane->getLaneParametricLength()),
68  myEndPosRelative(endPos / lane->getLaneParametricLength()),
69  myName(name),
70  myFriendlyPosition(friendlyPosition) {
71  // This additional belongs to a Lane
72  myLane = lane;
73 }
74 
75 
77 }
78 
79 
82  double stoppingPlaceCenter = (myStartPosRelative + myEndPosRelative) / 2 ;
83  return myLane->getShape().positionAtOffset(stoppingPlaceCenter * myLane->getLaneShapeLength());
84 }
85 
86 
87 void
89  // First we need to change the absolute new positions to a relative positions
90  double lenghtDifference = 0;
91  if (myLane->getLaneShapeLength() > 0) {
92  lenghtDifference = myLane->getLaneParametricLength() / myLane->getLaneShapeLength();
93  }
94  double relativePos = newPosition.x() / myLane->getLaneParametricLength() * lenghtDifference;
95  // change start position of stopping place
96  myStartPosRelative += relativePos;
97  myEndPosRelative += relativePos;
98  // Update geometry
100 }
101 
102 
103 void
105  undoList->p_begin("position of " + toString(getTag()));
106  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_STARTPOS, toString(getAbsoluteStartPosition()), true, toString(oldPos.x())));
107  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_ENDPOS, toString(getAbsoluteEndPosition()), true, toString(oldPos.y())));
108  undoList->p_end();
109  // Refresh element
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 /****************************************************************************/
double getLaneShapeLength() const
returns the length of the lane&#39;s shape
Definition: GNELane.cpp:730
bool areStoppingPlacesPositionsFixed() const
check if Position of stoppingPlace are fixed
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(...)
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:43
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 getAbsoluteStartPosition() const
get absolute start Position
double x() const
Returns the x-position.
Definition: Position.h:63
GNELane * myLane
The lane this additional belongs.
void moveGeometry(const Position &newPosition)
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)
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
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:85
std::vector< double > myShapeRotations
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:998
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:92
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
friend class GNEChange_Attribute
declare friend class
double y() const
Returns the y-position.
Definition: Position.h:68
double length() const
Returns the length.
std::vector< double > myShapeLengths
The lengths of the shape parts.
#define POSITION_EPS
Definition: config.h:176
~GNEStoppingPlace()
Destructor.
void move2side(double amount)
move position vector to side using certain ammount
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:240
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:625
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given 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:62
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
GNENet * getNet() const
get the net object
void setStoppingPlaceGeometry()
set geometry common to all stopping places
SumoXMLTag getTag() const
get XML Tag assigned to this object
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
const std::string & getParentName() const
Returns the name of the parent object (if any)
double getAbsoluteEndPosition() const
get absolute end Position
Position getPositionInView() const
Returns position of additional in view.
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:719