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-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 // A abstract class to define common parameters of lane area in which vehicles can halt (GNE version)
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
29 
30 #include "GNEStoppingPlace.h"
31 #include "GNEAdditionalHandler.h"
32 
33 // ===========================================================================
34 // static members
35 // ===========================================================================
36 
37 const double GNEStoppingPlace::myCircleWidth = 1.1;
38 const double GNEStoppingPlace::myCircleWidthSquared = 1.21;
39 const double GNEStoppingPlace::myCircleInWidth = 0.9;
40 const double GNEStoppingPlace::myCircleInText = 1.6;
41 
42 // ===========================================================================
43 // member method definitions
44 // ===========================================================================
45 
46 GNEStoppingPlace::GNEStoppingPlace(const std::string& id, GNEViewNet* viewNet, GUIGlObjectType type, SumoXMLTag tag, GNELane* lane, const std::string& startPos, const std::string& endPos, const std::string& name, bool friendlyPosition, bool blockMovement) :
47  GNEAdditional(id, viewNet, type, tag, name, blockMovement),
48  myLane(lane),
49  myStartPosition(startPos),
50  myEndPosition(endPos),
51  myFriendlyPosition(friendlyPosition) {
52 }
53 
54 
56 
57 
58 bool
60  // with friendly position enabled position are "always fixed"
61  if (myFriendlyPosition) {
62  return true;
63  } else {
64  if (myStartPosition.empty() && myEndPosition.empty()) {
65  return true;
66  } else if (myStartPosition.empty()) {
67  return (canParse<double>(myEndPosition) && (parse<double>(myEndPosition) <= myLane->getParentEdge().getNBEdge()->getFinalLength()));
68  } else if (myEndPosition.empty()) {
69  return (canParse<double>(myStartPosition) && (parse<double>(myStartPosition) >= 0));
70  } else {
71  return canParse<double>(myStartPosition) && canParse<double>(myEndPosition) &&
72  (parse<double>(myStartPosition) >= 0) &&
73  (parse<double>(myEndPosition) <= myLane->getParentEdge().getNBEdge()->getFinalLength()) &&
74  ((parse<double>(myEndPosition) - parse<double>(myStartPosition)) >= POSITION_EPS);
75  }
76  }
77 }
78 
79 
80 std::string
82  // declare variables
83  std::string errorStart, separator, errorEnd;
84  // check positions over lane
85  if(canParse<double>(myStartPosition)) {
86  if (parse<double>(myStartPosition) < 0) {
87  errorStart = (toString(SUMO_ATTR_STARTPOS) + " < 0");
88  } else if (parse<double>(myStartPosition) > myLane->getParentEdge().getNBEdge()->getFinalLength()) {
89  errorStart = (toString(SUMO_ATTR_STARTPOS) + " > lanes's length");
90  }
91  }
92  if(canParse<double>(myEndPosition)) {
93  if (parse<double>(myEndPosition) < 0) {
94  errorEnd = (toString(SUMO_ATTR_ENDPOS) + " < 0");
95  } else if (parse<double>(myEndPosition) > myLane->getParentEdge().getNBEdge()->getFinalLength()) {
96  errorEnd = (toString(SUMO_ATTR_ENDPOS) + " > lanes's length");
97  }
98  }
99  // check separator
100  if ((errorStart.size() > 0) && (errorEnd.size() > 0)) {
101  separator = " and ";
102  }
103  return errorStart + separator + errorEnd;
104 }
105 
106 
107 void
109  // declare new start and end position
110  std::string newStartPos = myStartPosition;
111  std::string newEndPos = myEndPosition;
112  // fix start and end positions using fixStoppinPlacePosition (0.01 is used to avoid precision problems)
113  GNEAdditionalHandler::fixStoppinPlacePosition(newStartPos, newEndPos, myLane->getLaneParametricLength() - 0.01, POSITION_EPS + 0.01, true);
114  // set new start and end positions
117 }
118 
119 
120 Position
122  double startPos = canParse<double>(myStartPosition) ? parse<double>(myStartPosition) : 0;
123  double endPos = canParse<double>(myEndPosition) ? parse<double>(myEndPosition) : myLane->getShape().length();
124  if (myStartPosition.empty() && myEndPosition.empty()) {
126  } else if (myStartPosition.empty()) {
127  return myLane->getShape().positionAtOffset(endPos);
128  } else if (myEndPosition.empty()) {
129  return myLane->getShape().positionAtOffset(startPos);
130  } else {
131  return myLane->getShape().positionAtOffset((startPos + endPos) / 2.0);
132  }
133 }
134 
135 
136 void
138  // only move if at leats start or end positions is defined
139  if (!myStartPosition.empty() || !myEndPosition.empty()) {
140  // Calculate new position using old position
141  Position newPosition = myMove.originalViewPosition;
142  newPosition.add(offset);
143  // filtern position using snap to active grid
144  newPosition = myViewNet->snapToActiveGrid(newPosition);
145  double offsetLane = myLane->getShape().nearest_offset_to_point2D(newPosition, false) - myLane->getShape().nearest_offset_to_point2D(myMove.originalViewPosition, false);
146  // check if start position must be moved
147  if (!myStartPosition.empty()) {
148  myStartPosition = toString(parse<double>(myMove.firstOriginalLanePosition) + offsetLane);
149  }
150  // check if start position must be moved
151  if (!myStartPosition.empty()) {
152  myEndPosition = toString(parse<double>(myMove.secondOriginalPosition) + offsetLane);
153  }
154  // Update geometry
155  updateGeometry(false);
156  }
157 }
158 
159 
160 void
162  // only commit geometry moving if at leats start or end positions is defined
163  if (!myStartPosition.empty() || !myEndPosition.empty()) {
164  undoList->p_begin("position of " + getTagStr());
165  if (!myStartPosition.empty()) {
167  }
168  if (!myEndPosition.empty()) {
170  }
171  undoList->p_end();
172  }
173 }
174 
175 
176 GNELane*
178  return myLane;
179 }
180 
181 
182 double
184  if (canParse<double>(myStartPosition)) {
185  return parse<double>(myStartPosition);
186  } else {
187  return 0;
188  }
189 }
190 
191 
192 double
194  if (canParse<double>(myEndPosition)) {
195  return parse<double>(myEndPosition);
196  } else {
197  return myLane->getLaneShapeLength();
198  }
199 }
200 
201 
202 std::string
204  return myLane->getMicrosimID();
205 }
206 
207 
208 void
210  // Clear all containers
212 
213  // Get value of option "lefthand"
214  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
215 
216  // Get shape of lane parent
218 
219  // Move shape to side
220  myGeometry.shape.move2side(movingToSide * offsetSign);
221 
222  // set start position
223  double startPosFixed;
224  if (!canParse<double>(myStartPosition)) {
225  startPosFixed = 0;
226  } else if (parse<double>(myStartPosition) < 0) {
227  startPosFixed = 0;
228  } else if (parse<double>(myStartPosition) > myLane->getParentEdge().getNBEdge()->getFinalLength()) {
229  startPosFixed = myLane->getParentEdge().getNBEdge()->getFinalLength();
230  } else {
231  startPosFixed = parse<double>(myStartPosition);
232  }
233 
234  // set end position
235  double endPosFixed;
236  if (!canParse<double>(myEndPosition)) {
237  endPosFixed = myLane->getParentEdge().getNBEdge()->getFinalLength();
238  } else if (parse<double>(myEndPosition) < 0) {
239  endPosFixed = 0;
240  } else if (parse<double>(myEndPosition) > myLane->getParentEdge().getNBEdge()->getFinalLength()) {
241  endPosFixed = myLane->getParentEdge().getNBEdge()->getFinalLength();
242  } else {
243  endPosFixed = parse<double>(myEndPosition);
244  }
245 
246  // Cut shape using as delimitators fixed start position and fixed end position
248 
249  // Get calculate lenghts and rotations
251 }
252 
253 
254 std::string
256  return getTagStr() + ": " + getID();
257 }
258 
259 
260 std::string
262  return getTagStr();
263 }
264 
265 /****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
static bool fixStoppinPlacePosition(std::string &startPos, std::string &endPos, const double laneLength, const double minLength, const bool friendlyPos)
check if the position of an stoppingPlace over a lane is valid
GUIGlObjectType
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:127
std::string secondOriginalPosition
value for saving second original position over lane before moving
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
static const double myCircleWidthSquared
squared circle width resolution for all stopping places
static const double myCircleInWidth
inner circle width resolution for all stopping places
Position snapToActiveGrid(const Position &pos) const
Returns a position that is mapped to the closest grid point if the grid is active.
Position getPositionInView() const
Returns position of additional in view.
void clearGeometry()
reset geometry
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
bool myFriendlyPosition
Flag for friendly position.
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
std::string myStartPosition
The relative start position this stopping place is located at (optional, if empty takes 0) ...
static const double myCircleInText
text inner circle width resolution for all stopping places
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
std::string getParentName() const
Returns the name of the parent object (if any)
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
method for setting the attribute and letting the object perform additional changes ...
GNELane * getLane() const
get Lane
bool isAdditionalValid() const
check if current additional is valid to be writed into XML (by default true, can be reimplemented in ...
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
AdditionalMove myMove
variable AdditionalMove
double getEndPosition() const
get end Position
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GNEUndoList * getUndoList() const
get the undoList object
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:775
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1260
void fixAdditionalProblem()
fix additional problem
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.
GNELane * myLane
The lane in which this lane is placed.
friend class GNEChange_Attribute
declare friend class
double getLengthGeometryFactor() const
get lenght geometry factor
Definition: GNELane.cpp:1317
#define POSITION_EPS
Definition: config.h:172
GNEStoppingPlace(const std::string &id, GNEViewNet *viewNet, GUIGlObjectType type, SumoXMLTag tag, GNELane *lane, const std::string &startPos, const std::string &endPos, const std::string &name, bool friendlyPosition, bool blockMovement)
Constructor.
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
~GNEStoppingPlace()
Destructor.
const std::string getID() const
function to support debugging
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:786
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition: NBEdge.cpp:3575
void move2side(double amount)
move position vector to side using certain ammount
static const double myCircleWidth
circle width resolution for all stopping places
void calculateShapeRotationsAndLengths()
calculate shape rotations and lenghts
double getStartPosition() const
get start Position
std::string getAdditionalProblem() const
return a string with the current additional problem
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:669
double length() const
Returns the length.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
AdditionalGeometry myGeometry
geometry to be precomputed in updateGeometry(...)
const std::string & getTagStr() const
get tag assigned to this object in string format
virtual void updateGeometry(bool updateGrid)=0
update pre-computed geometry information
std::string myEndPosition
The position this stopping place is located at (optional, if empty takes the lane lenght) ...
std::string firstOriginalLanePosition
value for saving first original position over lane before moving
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:613
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList