SUMO - Simulation of Urban MObility
GNEBusStop.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A lane area vehicles can halt at (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>
50 
51 #include "GNEBusStop.h"
52 #include "GNELane.h"
53 #include "GNEEdge.h"
54 #include "GNEJunction.h"
55 #include "GNEUndoList.h"
56 #include "GNENet.h"
57 #include "GNEChange_Attribute.h"
58 #include "GNEViewNet.h"
59 
60 // ===========================================================================
61 // method definitions
62 // ===========================================================================
63 
64 GNEBusStop::GNEBusStop(const std::string& id, GNELane* lane, GNEViewNet* viewNet, double startPos, double endPos, const std::string& name, const std::vector<std::string>& lines, bool friendlyPosition) :
65  GNEStoppingPlace(id, viewNet, SUMO_TAG_BUS_STOP, ICON_BUSSTOP, lane, startPos, endPos, name, friendlyPosition),
66  myLines(lines) {
67  // When a new additional element is created, updateGeometry() must be called
69 }
70 
71 
73 
74 
75 void
77  // Get value of option "lefthand"
78  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
79 
80  // Update common geometry of stopping place
82 
83  // Obtain a copy of the shape
84  PositionVector tmpShape = myShape;
85 
86  // Move shape to side
87  tmpShape.move2side(1.5 * offsetSign);
88 
89  // Get position of the sign
90  mySignPos = tmpShape.getLineCenter();
91 
92  // Set block icon position
94 
95  // Set block icon rotation, and using their rotation for sign
97 
98  // Refresh element (neccesary to avoid grabbing problems)
100 }
101 
102 
103 void
104 GNEBusStop::writeAdditional(OutputDevice& device, bool volatileOptionsEnabled) const {
105  // Write parameters
106  device.openTag(getTag());
107  device.writeAttr(SUMO_ATTR_ID, getID());
108  // Check if another lane ID must be changed if sidewalks.guess option is enabled
109  if (volatileOptionsEnabled && OptionsCont::getOptions().getBool("sidewalks.guess") && (myLane->getParentEdge().getLanes().front()->isRestricted(SVC_PEDESTRIAN) == false)) {
110  // add a new extra lane to edge
112  // write ID (now is different because there are a new lane)
113  device.writeAttr(SUMO_ATTR_LANE, myLane->getID());
114  // undo set extra lane
115  myViewNet->getUndoList()->undo();
116  } else {
117  device.writeAttr(SUMO_ATTR_LANE, myLane->getID());
118  }
121  if (myName.empty() == false) {
123  }
125  if (myLines.size() > 0) {
127  }
128  if (myBlocked) {
130  }
131  // Close tag
132  device.closeTag();
133 }
134 
135 
136 const std::vector<std::string>&
138  return myLines;
139 }
140 
141 
142 void
144  // Start drawing adding an gl identificator
145  glPushName(getGlID());
146 
147  // Add a draw matrix
148  glPushMatrix();
149 
150  // Start with the drawing of the area traslating matrix to origin
151  glTranslated(0, 0, getType());
152 
153  // Set color of the base
154  if (isAdditionalSelected()) {
156  } else {
157  GLHelper::setColor(RGBColor(76, 170, 50));
158  }
159 
160  // Obtain exaggeration of the draw
161  const double exaggeration = s.addSize.getExaggeration(s);
162 
163  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
165 
166  // Check if the distance is enought to draw details
167  if (s.scale * exaggeration >= 10) {
168 
169  // Add a draw matrix
170  glPushMatrix();
171 
172  // Set color of the lines
173  if (isAdditionalSelected()) {
175  } else {
176  GLHelper::setColor(RGBColor(76, 170, 50));
177  }
178 
179  // Iterate over every line
180  for (int i = 0; i < (int)myLines.size(); ++i) {
181  // Add a new push matrix
182  glPushMatrix();
183 
184  // Traslate End positionof signal
185  glTranslated(mySignPos.x(), mySignPos.y(), 0);
186 
187  // Rotate 180 (Eje X -> Mirror)
188  glRotated(180, 1, 0, 0);
189 
190  // Rotate again depending of the myBlockIconRotation
191  glRotated(myBlockIconRotation, 0, 0, 1);
192 
193  // Set polygon mode
194  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
195 
196  // set polyfront position ot 0
197  pfSetPosition(0, 0);
198 
199  // Set polyfront scale to 1
200  pfSetScale(1.f);
201 
202  // traslate matrix for every line
203  glTranslated(1.2, -(double)i, 0);
204 
205  // draw line
206  pfDrawString(myLines[i].c_str());
207 
208  // pop matrix
209  glPopMatrix();
210  }
211 
212  // Start drawing sign traslating matrix to signal position
213  glTranslated(mySignPos.x(), mySignPos.y(), 0);
214 
215  // Define number of points (for efficiency)
216  int noPoints = 9;
217 
218  // If the scale * exaggeration is more than 25, recalculate number of points
219  if (s.scale * exaggeration > 25) {
220  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
221  }
222 
223  // scale matrix depending of the exaggeration
224  glScaled(exaggeration, exaggeration, 1);
225 
226  // Set color of the externe circle
227  if (isAdditionalSelected()) {
229  } else {
230  GLHelper::setColor(RGBColor(76, 170, 50));
231  }
232 
233  // Draw circle
234  GLHelper::drawFilledCircle((double) 1.1, noPoints);
235 
236  // Traslate to front
237  glTranslated(0, 0, .1);
238 
239  // Set color of the interne circle
240  if (isAdditionalSelected()) {
242  } else {
243  GLHelper::setColor(RGBColor(255, 235, 0));
244  }
245 
246  // draw another circle in the same position, but a little bit more small
247  GLHelper::drawFilledCircle((double) 0.9, noPoints);
248 
249  // If the scale * exageration is equal or more than 4.5, draw H
250  if (s.scale * exaggeration >= 4.5) {
251  if (isAdditionalSelected()) {
253  } else {
254  GLHelper::drawText("H", Position(), .1, 1.6, RGBColor(76, 170, 50, 255), myBlockIconRotation);
255  }
256  }
257 
258  // pop draw matrix
259  glPopMatrix();
260 
261  // Show Lock icon depending of the Edit mode
262  drawLockIcon();
263  }
264 
265  // pop draw matrix
266  glPopMatrix();
267 
268  // Pop name
269  glPopName();
270 
271  // Draw name
272  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
273 }
274 
275 
276 std::string
278  switch (key) {
279  case SUMO_ATTR_ID:
280  return getAdditionalID();
281  case SUMO_ATTR_LANE:
283  case SUMO_ATTR_STARTPOS:
285  case SUMO_ATTR_ENDPOS:
287  case SUMO_ATTR_NAME:
288  return myName;
291  case SUMO_ATTR_LINES:
292  return joinToString(myLines, " ");
294  return toString(myBlocked);
295  default:
296  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
297  }
298 }
299 
300 
301 void
302 GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
303  if (value == getAttribute(key)) {
304  return; //avoid needless changes, later logic relies on the fact that attributes have changed
305  }
306  switch (key) {
307  case SUMO_ATTR_ID:
308  case SUMO_ATTR_LANE:
309  case SUMO_ATTR_STARTPOS:
310  case SUMO_ATTR_ENDPOS:
311  case SUMO_ATTR_NAME:
313  case SUMO_ATTR_LINES:
315  undoList->p_add(new GNEChange_Attribute(this, key, value));
316  updateGeometry();
317  break;
318  default:
319  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
320  }
321 }
322 
323 
324 bool
325 GNEBusStop::isValid(SumoXMLAttr key, const std::string& value) {
326  switch (key) {
327  case SUMO_ATTR_ID:
328  if (isValidID(value) && (myViewNet->getNet()->getAdditional(getTag(), value) == NULL)) {
329  return true;
330  } else {
331  return false;
332  }
333  case SUMO_ATTR_LANE:
334  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
335  return true;
336  } else {
337  return false;
338  }
339  case SUMO_ATTR_STARTPOS:
340  if (canParse<double>(value)) {
341  // Check that new start Position is smaller that end position
342  return ((parse<double>(value) / myLane->getLaneParametricLength()) < myEndPosRelative);
343  } else {
344  return false;
345  }
346  case SUMO_ATTR_ENDPOS:
347  if (canParse<double>(value)) {
348  // Check that new end Position is larger that end position
349  return ((parse<double>(value) / myLane->getLaneParametricLength()) > myStartPosRelative);
350  } else {
351  return false;
352  }
353  case SUMO_ATTR_NAME:
354  return true;
356  return canParse<bool>(value);
357  case SUMO_ATTR_LINES:
358  return canParse<std::vector<std::string> >(value);
360  return canParse<bool>(value);
361  default:
362  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
363  }
364 }
365 
366 // ===========================================================================
367 // private
368 // ===========================================================================
369 
370 void
371 GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value) {
372  switch (key) {
373  case SUMO_ATTR_ID:
374  setAdditionalID(value);
375  break;
376  case SUMO_ATTR_LANE:
377  changeLane(value);
378  break;
379  case SUMO_ATTR_STARTPOS:
380  myStartPosRelative = parse<double>(value) / myLane->getLaneParametricLength();
381  updateGeometry();
382  getViewNet()->update();
383  break;
384  case SUMO_ATTR_ENDPOS:
385  myEndPosRelative = parse<double>(value) / myLane->getLaneParametricLength();
386  updateGeometry();
387  getViewNet()->update();
388  break;
389  case SUMO_ATTR_NAME:
390  myName = value;
391  getViewNet()->update();
392  break;
394  myFriendlyPosition = parse<bool>(value);
395  getViewNet()->update();
396  break;
397  case SUMO_ATTR_LINES:
398  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
399  getViewNet()->update();
400  break;
402  myBlocked = parse<bool>(value);
403  getViewNet()->update();
404  break;
405  default:
406  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
407  }
408 }
409 
410 
411 /****************************************************************************/
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:261
int pfDrawString(const char *c)
Definition: polyfonts.c:1074
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
void setBlockIconRotation()
double scale
information about a lane&#39;s width (temporary, used for a single view)
is a pedestrian
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:172
GUIVisualizationTextSettings addName
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in allGNEAttributeCarrier.
Definition: GNEBusStop.cpp:277
void pfSetScale(double s)
Definition: polyfonts.c:465
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.
Stores the information about how to visualize structures.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
bool isAdditionalSelected() const
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.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void pfSetPosition(double x, double y)
Definition: polyfonts.c:480
const std::vector< std::string > & getLines() const
get string vector with the lines of the busStop
Definition: GNEBusStop.cpp:137
std::vector< double > myShapeRotations
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:339
GUIGlID getGlID() const
Returns the numerical id of the object.
void undo()
undo the last command group
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
GNEUndoList * getUndoList() const
get the undoList object
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
static bool isValidID(const std::string &value)
true if value is a valid sumo ID
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:112
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEBusStop.cpp:143
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:438
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1085
const std::string & getAdditionalID() const
returns the ID of additional
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.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:958
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:302
friend class GNEChange_Attribute
declare friend class
double y() const
Returns the y-position.
Definition: Position.h:68
void writeAdditional(OutputDevice &device, bool volatileOptionsEnabled) const
writte additional element into a xml file
Definition: GNEBusStop.cpp:104
block movement of a graphic element
T MIN2(T a, T b)
Definition: StdDefs.h:68
std::vector< double > myShapeLengths
The lengths of the shape parts.
void setAdditionalID(const std::string &id)
set the ID of additional
const std::string getID() const
function to support debugging
void drawLockIcon(double size=0.5) const
draw lock icon
void changeLane(const std::string &laneID)
change lane of additional
void move2side(double amount)
move position vector to side using certain ammount
std::string myName
name of stoppingPlace
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
Definition: GNEBusStop.h:124
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in allGNEAttributeCarrier.
Definition: GNELane.cpp:770
~GNEBusStop()
Destructor.
Definition: GNEBusStop.cpp:72
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1680
bool myBlocked
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:599
double myEndPosRelative
The relative [0,1] end position this stopping place is located at.
void updateGeometry()
update pre-computed geometry information
Definition: GNEBusStop.cpp:76
double myStartPosRelative
The relative [0,1] start position this stopping place is located at.
GNEBusStop(const std::string &id, GNELane *lane, GNEViewNet *viewNet, double startPos, double endPos, const std::string &name, const std::vector< std::string > &lines, bool friendlyPosition)
Constructor.
Definition: GNEBusStop.cpp:64
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEBusStop.cpp:325
GNENet * getNet() const
get the net object
Position getLineCenter() const
get line center
void setStoppingPlaceGeometry()
set geometry common to all stopping places
SumoXMLTag getTag() const
get XML Tag assigned to this object
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
static const RGBColor selectionColor
Definition: GNENet.h:103
double getAbsoluteEndPosition() const
get absolute end Position
Position mySignPos
The position of the sign.
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)
draw Text with given parameters
Definition: GLHelper.cpp:455
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:719
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:237
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void duplicateLane(GNELane *lane, GNEUndoList *undoList)
duplicates lane
Definition: GNENet.cpp:544
Position myBlockIconPosition
position of the block icon