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-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 lane area vehicles can halt at (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>
36 #include <utils/common/ToString.h>
37 #include <utils/geom/GeomHelper.h>
43 #include <utils/gui/div/GLHelper.h>
48 
49 #include "GNEBusStop.h"
50 #include "GNELane.h"
51 #include "GNEEdge.h"
52 #include "GNEJunction.h"
53 #include "GNEUndoList.h"
54 #include "GNENet.h"
55 #include "GNEChange_Attribute.h"
56 #include "GNEViewNet.h"
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
61 
62 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) :
63  GNEStoppingPlace(id, viewNet, SUMO_TAG_BUS_STOP, ICON_BUSSTOP, lane, startPos, endPos, name, friendlyPosition),
64  myLines(lines) {
65 }
66 
67 
69 
70 
71 void
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  // Refresh element (neccesary to avoid grabbing problems)
96 }
97 
98 
99 void
101  // Write parameters
102  device.openTag(getTag());
103  device.writeAttr(SUMO_ATTR_ID, getID());
104  device.writeAttr(SUMO_ATTR_LANE, myLane->getID());
107  if (myName.empty() == false) {
109  }
111  if (myLines.size() > 0) {
113  }
114  // Close tag
115  device.closeTag();
116 }
117 
118 
119 const std::vector<std::string>&
121  return myLines;
122 }
123 
124 
125 void
127  // Start drawing adding an gl identificator
128  glPushName(getGlID());
129 
130  // Add a draw matrix
131  glPushMatrix();
132 
133  // Start with the drawing of the area traslating matrix to origin
134  glTranslated(0, 0, getType());
135 
136  // Set color of the base
137  if (isAdditionalSelected()) {
139  } else {
140  GLHelper::setColor(RGBColor(76, 170, 50));
141  }
142 
143  // Obtain exaggeration of the draw
144  const double exaggeration = s.addSize.getExaggeration(s);
145 
146  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
148 
149  // Check if the distance is enought to draw details
150  if (s.scale * exaggeration >= 10) {
151 
152  // Add a draw matrix for details
153  glPushMatrix();
154 
155  // Iterate over every line
156  for (int i = 0; i < (int)myLines.size(); ++i) {
157  // push a new matrix for every line
158  glPushMatrix();
159 
160  // Rotate and traslaste
161  glTranslated(mySignPos.x(), mySignPos.y(), 0);
162  glRotated(-1 * myBlockIconRotation, 0, 0, 1);
163 
164  // draw line with a color depending of the selection status
165  if (isAdditionalSelected()) {
166  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, myViewNet->getNet()->selectionColor, 0, FONS_ALIGN_LEFT);
167  } else {
168  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, RGBColor(76, 170, 50), 0, FONS_ALIGN_LEFT);
169  }
170 
171  // pop matrix for every line
172  glPopMatrix();
173  }
174 
175  // Start drawing sign traslating matrix to signal position
176  glTranslated(mySignPos.x(), mySignPos.y(), 0);
177 
178  // Define number of points (for efficiency)
179  int noPoints = 9;
180 
181  // If the scale * exaggeration is more than 25, recalculate number of points
182  if (s.scale * exaggeration > 25) {
183  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
184  }
185 
186  // scale matrix depending of the exaggeration
187  glScaled(exaggeration, exaggeration, 1);
188 
189  // Set color of the externe circle
190  if (isAdditionalSelected()) {
192  } else {
193  GLHelper::setColor(RGBColor(76, 170, 50));
194  }
195 
196  // Draw circle
197  GLHelper::drawFilledCircle((double) 1.1, noPoints);
198 
199  // Traslate to front
200  glTranslated(0, 0, .1);
201 
202  // Set color of the interne circle
203  if (isAdditionalSelected()) {
205  } else {
206  GLHelper::setColor(RGBColor(255, 235, 0));
207  }
208 
209  // draw another circle in the same position, but a little bit more small
210  GLHelper::drawFilledCircle((double) 0.9, noPoints);
211 
212  // If the scale * exageration is equal or more than 4.5, draw H
213  if (s.scale * exaggeration >= 4.5) {
214  if (isAdditionalSelected()) {
216  } else {
217  GLHelper::drawText("H", Position(), .1, 1.6, RGBColor(76, 170, 50, 255), myBlockIconRotation);
218  }
219  }
220 
221  // pop draw matrix
222  glPopMatrix();
223 
224  // Show Lock icon depending of the Edit mode
225  drawLockIcon();
226  }
227 
228  // pop draw matrix
229  glPopMatrix();
230 
231  // Pop name
232  glPopName();
233 
234  // Draw name
235  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
236  if (s.addFullName.show && myName != "") {
238  }
239 }
240 
241 
242 std::string
244  switch (key) {
245  case SUMO_ATTR_ID:
246  return getAdditionalID();
247  case SUMO_ATTR_LANE:
248  return myLane->getID();
249  case SUMO_ATTR_STARTPOS:
251  case SUMO_ATTR_ENDPOS:
253  case SUMO_ATTR_NAME:
254  return myName;
257  case SUMO_ATTR_LINES:
258  return joinToString(myLines, " ");
260  return toString(myBlocked);
261  default:
262  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
263  }
264 }
265 
266 
267 void
268 GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
269  if (value == getAttribute(key)) {
270  return; //avoid needless changes, later logic relies on the fact that attributes have changed
271  }
272  switch (key) {
273  case SUMO_ATTR_ID:
274  case SUMO_ATTR_LANE:
275  case SUMO_ATTR_STARTPOS:
276  case SUMO_ATTR_ENDPOS:
277  case SUMO_ATTR_NAME:
279  case SUMO_ATTR_LINES:
281  undoList->p_add(new GNEChange_Attribute(this, key, value));
282  break;
283  default:
284  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
285  }
286 }
287 
288 
289 bool
290 GNEBusStop::isValid(SumoXMLAttr key, const std::string& value) {
291  switch (key) {
292  case SUMO_ATTR_ID:
293  return isValidAdditionalID(value);
294  case SUMO_ATTR_LANE:
295  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
296  return true;
297  } else {
298  return false;
299  }
300  case SUMO_ATTR_STARTPOS:
301  if (canParse<double>(value)) {
302  // Check that new start Position is smaller that end position
303  return ((parse<double>(value) / myLane->getLaneParametricLength()) < myEndPosRelative);
304  } else {
305  return false;
306  }
307  case SUMO_ATTR_ENDPOS:
308  if (canParse<double>(value)) {
309  // Check that new end Position is larger that end position
310  return ((parse<double>(value) / myLane->getLaneParametricLength()) > myStartPosRelative);
311  } else {
312  return false;
313  }
314  case SUMO_ATTR_NAME:
315  return true;
317  return canParse<bool>(value);
318  case SUMO_ATTR_LINES:
319  return canParse<std::vector<std::string> >(value);
321  return canParse<bool>(value);
322  default:
323  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
324  }
325 }
326 
327 // ===========================================================================
328 // private
329 // ===========================================================================
330 
331 void
332 GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value) {
333  switch (key) {
334  case SUMO_ATTR_ID:
335  changeAdditionalID(value);
336  break;
337  case SUMO_ATTR_LANE:
338  myLane = changeLane(myLane, value);
339  break;
340  case SUMO_ATTR_STARTPOS:
341  myStartPosRelative = parse<double>(value) / myLane->getLaneParametricLength();
342  break;
343  case SUMO_ATTR_ENDPOS:
344  myEndPosRelative = parse<double>(value) / myLane->getLaneParametricLength();
345  break;
346  case SUMO_ATTR_NAME:
347  myName = value;
348  break;
350  myFriendlyPosition = parse<bool>(value);
351  break;
352  case SUMO_ATTR_LINES:
353  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
354  break;
356  myBlocked = parse<bool>(value);
357  break;
358  default:
359  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
360  }
361  // After setting attribute always update Geometry
362  updateGeometry();
363 }
364 
365 
366 /****************************************************************************/
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
double scale
information about a lane&#39;s width (temporary, used for a single view)
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:183
GUIVisualizationTextSettings addName
void refreshElement(GUIGlObject *o)
refreshes boundary information for o and update
Definition: GNENet.cpp:1082
const std::string & getAdditionalID() const
returns Additional ID
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:67
double getAbsoluteEndPosition() const
get absolute end Position
double x() const
Returns the x-position.
Definition: Position.h:62
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:487
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.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
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:350
void changeAdditionalID(const std::string &newID)
change ID of additional
Position getLineCenter() const
get line center
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
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
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
Definition: GNEBusStop.cpp:100
GUIVisualizationSizeSettings addSize
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:116
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:701
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:55
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:449
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
A list of positions.
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:268
GNELane * myLane
The lane in which this lane is placed.
friend class GNEChange_Attribute
declare friend class
block movement of a graphic element
T MIN2(T a, T b)
Definition: StdDefs.h:67
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
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:115
~GNEBusStop()
Destructor.
Definition: GNEBusStop.cpp:68
const std::vector< std::string > & getLines() const
get string vector with the lines of the busStop
Definition: GNEBusStop.cpp:120
bool myBlocked
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in all GNEAttributeCarriers.
Definition: GNEBusStop.cpp:243
GUIVisualizationTextSettings addFullName
double myEndPosRelative
The relative [0,1] end position this stopping place is located at.
void updateGeometry()
update pre-computed geometry information
Definition: GNEBusStop.cpp:72
double myStartPosRelative
The relative [0,1] start position this stopping place is located at.
void setBlockIconRotation(GNELane *additionalLane=NULL)
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:62
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEBusStop.cpp:290
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEBusStop.cpp:126
GNENet * getNet() const
get the net object
GUIGlID getGlID() const
Returns the numerical id of the object.
void setStoppingPlaceGeometry()
set geometry common to all stopping places
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
bool isAdditionalSelected() const
static const RGBColor selectionColor
Definition: GNENet.h:107
empty max
Position mySignPos
The position of the sign.
double getAbsoluteStartPosition() const
get absolute start Position
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1000
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:236
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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