SUMO - Simulation of Urban MObility
GNEBusStop.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 lane area vehicles can halt at (GNE version)
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <string>
24 #include <iostream>
25 #include <utility>
30 #include <utils/common/ToString.h>
31 #include <utils/geom/GeomHelper.h>
36 #include <utils/gui/div/GLHelper.h>
44 #include <netedit/GNEUndoList.h>
45 #include <netedit/GNENet.h>
47 #include <netedit/GNEViewNet.h>
48 #include <netedit/GNEViewParent.h>
49 
50 #include "GNEBusStop.h"
51 #include "GNEAccess.h"
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 
57 GNEBusStop::GNEBusStop(const std::string& id, GNELane* lane, GNEViewNet* viewNet, const std::string& startPos, const std::string& endPos, const std::string& name, const std::vector<std::string>& lines, bool friendlyPosition, bool blockMovement) :
58  GNEStoppingPlace(id, viewNet, GLO_BUS_STOP, SUMO_TAG_BUS_STOP, lane, startPos, endPos, name, friendlyPosition, blockMovement),
59  myLines(lines) {
60 }
61 
62 
64 
65 
66 void
67 GNEBusStop::updateGeometry(bool updateGrid) {
68  // first check if object has to be removed from grid (SUMOTree)
69  if (updateGrid) {
71  }
72 
73  // Get value of option "lefthand"
74  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
75 
76  // Update common geometry of stopping place
78 
79  // Obtain a copy of the shape
80  PositionVector tmpShape = myShape;
81 
82  // Move shape to side
83  tmpShape.move2side(1.5 * offsetSign);
84 
85  // Get position of the sign
86  mySignPos = tmpShape.getLineCenter();
87 
88  // Set block icon position
90 
91  // Set block icon rotation, and using their rotation for sign
93 
94  // last step is to check if object has to be added into grid (SUMOTree) again
95  if (updateGrid) {
97  }
98 }
99 
100 
101 void
103  // obtain circle resolution
104  int circleResolution = getCircleResolution(s);
105  // Obtain exaggeration of the draw
106  const double exaggeration = s.addSize.getExaggeration(s);
107  // Start drawing adding an gl identificator
108  glPushName(getGlID());
109  // Add a draw matrix
110  glPushMatrix();
111  // Start with the drawing of the area traslating matrix to origin
112  glTranslated(0, 0, getType());
113  // Set color of the base
116  } else {
118  }
119  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
121  // Check if the distance is enought to draw details and if is being drawn for selecting
122  if (s.drawForSelecting) {
123  // only draw circle depending of distance between sign and mouse cursor
125  // Add a draw matrix for details
126  glPushMatrix();
127  // Start drawing sign traslating matrix to signal position
128  glTranslated(mySignPos.x(), mySignPos.y(), 0);
129  // scale matrix depending of the exaggeration
130  glScaled(exaggeration, exaggeration, 1);
131  // set color
133  // Draw circle
134  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
135  // pop draw matrix
136  glPopMatrix();
137  }
138  } else if (s.scale * exaggeration >= 10) {
139  // draw lines between BusStops and Acces
140  for (auto i : myAdditionalChilds) {
141  GLHelper::drawBoxLine(i->getShape()[0], RAD2DEG(mySignPos.angleTo2D(i->getShape()[0])) - 90, mySignPos.distanceTo2D(i->getShape()[0]), .05);
142  }
143  // Add a draw matrix for details
144  glPushMatrix();
145  // Iterate over every line
146  for (int i = 0; i < (int)myLines.size(); ++i) {
147  // push a new matrix for every line
148  glPushMatrix();
149  // Rotate and traslaste
150  glTranslated(mySignPos.x(), mySignPos.y(), 0);
151  glRotated(-1 * myBlockIconRotation, 0, 0, 1);
152  // draw line with a color depending of the selection status
154  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, myViewNet->getNet()->selectionColor, 0, FONS_ALIGN_LEFT);
155  } else {
156  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, s.SUMO_color_busStop, 0, FONS_ALIGN_LEFT);
157  }
158  // pop matrix for every line
159  glPopMatrix();
160  }
161  // Start drawing sign traslating matrix to signal position
162  glTranslated(mySignPos.x(), mySignPos.y(), 0);
163  // scale matrix depending of the exaggeration
164  glScaled(exaggeration, exaggeration, 1);
165  // Set color of the externe circle
168  } else {
170  }
171  // Draw circle
172  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
173  // Traslate to front
174  glTranslated(0, 0, .1);
175  // Set color of the interne circle
178  } else {
180  }
181  // draw another circle in the same position, but a little bit more small
182  GLHelper::drawFilledCircle(myCircleInWidth, circleResolution);
183  // If the scale * exageration is equal or more than 4.5, draw H
184  if (s.scale * exaggeration >= 4.5) {
187  } else {
189  }
190  }
191  // pop draw matrix
192  glPopMatrix();
193  // Show Lock icon depending of the Edit mode
194  drawLockIcon();
195  }
196  // pop draw matrix
197  glPopMatrix();
198  // Draw name if isn't being drawn for selecting
199  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
200  if (s.addFullName.show && (myAdditionalName != "") && !s.drawForSelecting) {
202  }
203  // check if dotted contour has to be drawn
204  if (!s.drawForSelecting && (myViewNet->getACUnderCursor() == this)) {
206  }
207  // Pop name
208  glPopName();
209 }
210 
211 
212 std::string
214  switch (key) {
215  case SUMO_ATTR_ID:
216  return getAdditionalID();
217  case SUMO_ATTR_LANE:
218  return myLane->getID();
219  case SUMO_ATTR_STARTPOS:
220  return toString(myStartPosition);
221  case SUMO_ATTR_ENDPOS:
222  return myEndPosition;
223  case SUMO_ATTR_NAME:
224  return myAdditionalName;
227  case SUMO_ATTR_LINES:
228  return joinToString(myLines, " ");
230  return toString(myBlockMovement);
231  case GNE_ATTR_SELECTED:
233  case GNE_ATTR_GENERIC:
234  return getGenericParametersStr();
235  default:
236  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
237  }
238 }
239 
240 
241 void
242 GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
243  if (value == getAttribute(key)) {
244  return; //avoid needless changes, later logic relies on the fact that attributes have changed
245  }
246  switch (key) {
247  case SUMO_ATTR_ID: {
248  // change ID of BusStop
249  undoList->p_add(new GNEChange_Attribute(this, key, value));
250  // Change Ids of all Acces childs
251  for (auto i : myAdditionalChilds) {
252  i->setAttribute(SUMO_ATTR_ID, generateAdditionalChildID(SUMO_TAG_ACCESS), undoList);
253  }
254  break;
255  }
256  case SUMO_ATTR_LANE:
257  case SUMO_ATTR_STARTPOS:
258  case SUMO_ATTR_ENDPOS:
259  case SUMO_ATTR_NAME:
261  case SUMO_ATTR_LINES:
263  case GNE_ATTR_SELECTED:
264  case GNE_ATTR_GENERIC:
265  undoList->p_add(new GNEChange_Attribute(this, key, value));
266  break;
267  default:
268  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
269  }
270 }
271 
272 
273 bool
274 GNEBusStop::isValid(SumoXMLAttr key, const std::string& value) {
275  switch (key) {
276  case SUMO_ATTR_ID:
277  return isValidAdditionalID(value);
278  case SUMO_ATTR_LANE:
279  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
280  return true;
281  } else {
282  return false;
283  }
284  case SUMO_ATTR_STARTPOS:
285  if (value.empty()) {
286  return true;
287  } else {
288  if (canParse<double>(value)) {
289  if (canParse<double>(myEndPosition)) {
290  // Check that new start Position is smaller that end position
291  return (parse<double>(value) < parse<double>(myEndPosition));
292  } else {
293  return true;
294  }
295  } else {
296  return false;
297  }
298  }
299  case SUMO_ATTR_ENDPOS:
300  if (value.empty()) {
301  return true;
302  } else {
303  if (canParse<double>(value)) {
304  if (canParse<double>(myStartPosition)) {
305  // Check that new start Position is smaller that end position
306  return (parse<double>(myStartPosition) < parse<double>(value));
307  } else {
308  return true;
309  }
310  } else {
311  return false;
312  }
313  }
314  case SUMO_ATTR_NAME:
317  return canParse<bool>(value);
318  case SUMO_ATTR_LINES:
319  return canParse<std::vector<std::string> >(value);
321  return canParse<bool>(value);
322  case GNE_ATTR_SELECTED:
323  return canParse<bool>(value);
324  case GNE_ATTR_GENERIC:
325  return isGenericParametersValid(value);
326  default:
327  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
328  }
329 }
330 
331 // ===========================================================================
332 // private
333 // ===========================================================================
334 
335 void
336 GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value) {
337  switch (key) {
338  case SUMO_ATTR_ID:
339  changeAdditionalID(value);
340  break;
341  case SUMO_ATTR_LANE:
342  myLane = changeLane(myLane, value);
343  break;
344  case SUMO_ATTR_STARTPOS:
345  myStartPosition = value;
346  break;
347  case SUMO_ATTR_ENDPOS:
348  myEndPosition = value;
349  break;
350  case SUMO_ATTR_NAME:
351  myAdditionalName = value;
352  break;
354  myFriendlyPosition = parse<bool>(value);
355  break;
356  case SUMO_ATTR_LINES:
357  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
358  break;
360  myBlockMovement = parse<bool>(value);
361  break;
362  case GNE_ATTR_SELECTED:
363  if (parse<bool>(value)) {
365  } else {
367  }
368  break;
369  case GNE_ATTR_GENERIC:
371  break;
372  default:
373  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
374  }
375  // After setting attribute always update Geometry
376  updateGeometry(true);
377 }
378 
379 /****************************************************************************/
const GNEAttributeCarrier * getACUnderCursor() const
get AttributeCarrier under cursor
double scale
information about a lane&#39;s width (temporary, used for a single view)
void setBlockIconRotation(GNELane *additionalLane=nullptr)
static const RGBColor SUMO_color_busStop_sign
color for busStops signs
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name) ...
static void drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition: GLHelper.cpp:178
GUIVisualizationTextSettings addName
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:243
Stores the information about how to visualize structures.
static const double myCircleWidthSquared
squared circle width resolution for all stopping places
double y() const
Returns the y-position.
Definition: Position.h:61
static const double myCircleInWidth
inner circle width resolution for all stopping places
double x() const
Returns the x-position.
Definition: Position.h:56
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, int align=0, double width=-1)
Definition: GLHelper.cpp:611
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position ...
Definition: Position.h:253
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
bool myFriendlyPosition
Flag for friendly position.
std::string myStartPosition
The relative start position this stopping place is located at (optional, if empty takes 0) ...
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
static const double myCircleInText
text inner circle width resolution for all stopping places
#define RAD2DEG(x)
Definition: GeomHelper.h:39
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
std::vector< double > myShapeRotations
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:344
GNEBusStop(const std::string &id, GNELane *lane, GNEViewNet *viewNet, const std::string &startPos, const std::string &endPos, const std::string &name, const std::vector< std::string > &lines, bool friendlyPosition, bool blockMovement)
Constructor.
Definition: GNEBusStop.cpp:57
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
Position getLineCenter() const
get line center
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
int getIndex() const
returns the index of the lane
Definition: GNELane.cpp:697
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.
void drawLockIcon(double size=0.5) const
draw lock icon
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
a busStop
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:1230
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
A list of positions.
double scaledSize(double scale, double constFactor=0.1) const
std::string myAdditionalName
name of additional
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:1167
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
Definition: GNEBusStop.cpp:242
double distanceSquaredTo(const Position &p2) const
returns the square of the distance to another position
Definition: Position.h:238
GNELane * myLane
The lane in which this lane is placed.
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
block movement of a graphic element
std::vector< double > myShapeLengths
The lengths of the shape parts.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
const std::string getID() const
function to support debugging
static const RGBColor SUMO_color_busStop
color for busStops
void move2side(double amount)
move position vector to side using certain ammount
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
std::vector< GNEAdditional * > myAdditionalChilds
vector with the Additional childs
static const double myCircleWidth
circle width resolution for all stopping places
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
Definition: GNEBusStop.h:102
~GNEBusStop()
Destructor.
Definition: GNEBusStop.cpp:63
double getLaneWidth() const
Returns the default width of lanes of this edge.
Definition: NBEdge.h:525
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
void updateGeometry(bool updateGrid)
update pre-computed geometry information
Definition: GNEBusStop.cpp:67
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEBusStop.cpp:213
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
GUIVisualizationTextSettings addFullName
element is selected
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEBusStop.cpp:274
static int getCircleResolution(const GUIVisualizationSettings &settings)
function to calculate circle resolution for all circles drawn in drawGL(...) functions ...
std::string getGenericParametersStr() const
return generic parameters in string format
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEBusStop.cpp:102
GNENet * getNet() const
get the net object
std::string generateAdditionalChildID(SumoXMLTag childTag)
gererate a new ID for an additional child
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
Position getPositionInformation() const
Returns the cursor&#39;s x/y position within the network.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
std::string myEndPosition
The position this stopping place is located at (optional, if empty takes the lane lenght) ...
static const RGBColor selectionColor
Definition: GNENet.h:96
empty max
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:132
Position mySignPos
The position of the sign.
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:586
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
An access point for a train stop.
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1160
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1066
double myBlockIconRotation
The rotation of the block icon.
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:230
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