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 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
31 #include <utils/gui/div/GLHelper.h>
32 #include <utils/geom/GeomHelper.h>
33 
34 #include "GNEBusStop.h"
35 #include "GNEAccess.h"
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 
41 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) :
42  GNEStoppingPlace(id, viewNet, GLO_BUS_STOP, SUMO_TAG_BUS_STOP, lane, startPos, endPos, name, friendlyPosition, blockMovement),
43  myLines(lines) {
44 }
45 
46 
48 
49 
50 void
51 GNEBusStop::updateGeometry(bool updateGrid) {
52  // first check if object has to be removed from grid (SUMOTree)
53  if (updateGrid) {
55  }
56 
57  // Get value of option "lefthand"
58  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
59 
60  // Update common geometry of stopping place
62 
63  // Obtain a copy of the shape
64  PositionVector tmpShape = myGeometry.shape;
65 
66  // Move shape to side
67  tmpShape.move2side(1.5 * offsetSign);
68 
69  // Get position of the sign
70  mySignPos = tmpShape.getLineCenter();
71 
72  // Set block icon position
74 
75  // Set block icon rotation, and using their rotation for sign
77 
78  // last step is to check if object has to be added into grid (SUMOTree) again
79  if (updateGrid) {
81  }
82 }
83 
84 
85 void
87  // obtain circle resolution
88  int circleResolution = getCircleResolution(s);
89  // Obtain exaggeration of the draw
90  const double exaggeration = s.addSize.getExaggeration(s, this);
91  // Start drawing adding an gl identificator
92  glPushName(getGlID());
93  // Add a draw matrix
94  glPushMatrix();
95  // Start with the drawing of the area traslating matrix to origin
96  glTranslated(0, 0, getType());
97  // Set color of the base
100  } else {
102  }
103  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
105  // Check if the distance is enought to draw details and if is being drawn for selecting
106  if (s.drawForSelecting) {
107  // only draw circle depending of distance between sign and mouse cursor
109  // Add a draw matrix for details
110  glPushMatrix();
111  // Start drawing sign traslating matrix to signal position
112  glTranslated(mySignPos.x(), mySignPos.y(), 0);
113  // scale matrix depending of the exaggeration
114  glScaled(exaggeration, exaggeration, 1);
115  // set color
117  // Draw circle
118  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
119  // pop draw matrix
120  glPopMatrix();
121  }
122  } else if (s.scale * exaggeration >= 10) {
123  // draw lines between BusStops and Acces
124  for (auto i : myAdditionalChilds) {
125  GLHelper::drawBoxLine(i->getShape()[0], RAD2DEG(mySignPos.angleTo2D(i->getShape()[0])) - 90, mySignPos.distanceTo2D(i->getShape()[0]), .05);
126  }
127  // Add a draw matrix for details
128  glPushMatrix();
129  // Iterate over every line
130  for (int i = 0; i < (int)myLines.size(); ++i) {
131  // push a new matrix for every line
132  glPushMatrix();
133  // Rotate and traslaste
134  glTranslated(mySignPos.x(), mySignPos.y(), 0);
135  glRotated(-1 * myBlockIcon.rotation, 0, 0, 1);
136  // draw line with a color depending of the selection status
138  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, s.selectionColor, 0, FONS_ALIGN_LEFT);
139  } else {
140  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, s.SUMO_color_busStop, 0, FONS_ALIGN_LEFT);
141  }
142  // pop matrix for every line
143  glPopMatrix();
144  }
145  // Start drawing sign traslating matrix to signal position
146  glTranslated(mySignPos.x(), mySignPos.y(), 0);
147  // scale matrix depending of the exaggeration
148  glScaled(exaggeration, exaggeration, 1);
149  // Set color of the externe circle
152  } else {
154  }
155  // Draw circle
156  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
157  // Traslate to front
158  glTranslated(0, 0, .1);
159  // Set color of the interne circle
162  } else {
164  }
165  // draw another circle in the same position, but a little bit more small
166  GLHelper::drawFilledCircle(myCircleInWidth, circleResolution);
167  // If the scale * exageration is equal or more than 4.5, draw H
168  if (s.scale * exaggeration >= 4.5) {
171  } else {
173  }
174  }
175  // pop draw matrix
176  glPopMatrix();
177  // Show Lock icon depending of the Edit mode
178  myBlockIcon.draw();
179  }
180  // pop draw matrix
181  glPopMatrix();
182  // Draw name if isn't being drawn for selecting
183  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
184  if (s.addFullName.show && (myAdditionalName != "") && !s.drawForSelecting) {
186  }
187  // check if dotted contour has to be drawn
188  if (!s.drawForSelecting && (myViewNet->getDottedAC() == this)) {
190  }
191  // Pop name
192  glPopName();
193 }
194 
195 
196 std::string
198  switch (key) {
199  case SUMO_ATTR_ID:
200  return getAdditionalID();
201  case SUMO_ATTR_LANE:
202  return myLane->getID();
203  case SUMO_ATTR_STARTPOS:
204  return toString(myStartPosition);
205  case SUMO_ATTR_ENDPOS:
206  return myEndPosition;
207  case SUMO_ATTR_NAME:
208  return myAdditionalName;
211  case SUMO_ATTR_LINES:
212  return joinToString(myLines, " ");
214  return toString(myBlockMovement);
215  case GNE_ATTR_SELECTED:
217  case GNE_ATTR_GENERIC:
218  return getGenericParametersStr();
219  default:
220  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
221  }
222 }
223 
224 
225 void
226 GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
227  if (value == getAttribute(key)) {
228  return; //avoid needless changes, later logic relies on the fact that attributes have changed
229  }
230  switch (key) {
231  case SUMO_ATTR_ID: {
232  // change ID of BusStop
233  undoList->p_add(new GNEChange_Attribute(this, key, value));
234  // Change Ids of all Acces childs
235  for (auto i : myAdditionalChilds) {
236  i->setAttribute(SUMO_ATTR_ID, generateAdditionalChildID(SUMO_TAG_ACCESS), undoList);
237  }
238  break;
239  }
240  case SUMO_ATTR_LANE:
241  case SUMO_ATTR_STARTPOS:
242  case SUMO_ATTR_ENDPOS:
243  case SUMO_ATTR_NAME:
245  case SUMO_ATTR_LINES:
247  case GNE_ATTR_SELECTED:
248  case GNE_ATTR_GENERIC:
249  undoList->p_add(new GNEChange_Attribute(this, key, value));
250  break;
251  default:
252  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
253  }
254 }
255 
256 
257 bool
258 GNEBusStop::isValid(SumoXMLAttr key, const std::string& value) {
259  switch (key) {
260  case SUMO_ATTR_ID:
261  return isValidAdditionalID(value);
262  case SUMO_ATTR_LANE:
263  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
264  return true;
265  } else {
266  return false;
267  }
268  case SUMO_ATTR_STARTPOS:
269  if (value.empty()) {
270  return true;
271  } else {
272  if (canParse<double>(value)) {
273  if (canParse<double>(myEndPosition)) {
274  // Check that new start Position is smaller that end position
275  return (parse<double>(value) < parse<double>(myEndPosition));
276  } else {
277  return true;
278  }
279  } else {
280  return false;
281  }
282  }
283  case SUMO_ATTR_ENDPOS:
284  if (value.empty()) {
285  return true;
286  } else {
287  if (canParse<double>(value)) {
288  if (canParse<double>(myStartPosition)) {
289  // Check that new start Position is smaller that end position
290  return (parse<double>(myStartPosition) < parse<double>(value));
291  } else {
292  return true;
293  }
294  } else {
295  return false;
296  }
297  }
298  case SUMO_ATTR_NAME:
301  return canParse<bool>(value);
302  case SUMO_ATTR_LINES:
303  return canParse<std::vector<std::string> >(value);
305  return canParse<bool>(value);
306  case GNE_ATTR_SELECTED:
307  return canParse<bool>(value);
308  case GNE_ATTR_GENERIC:
309  return isGenericParametersValid(value);
310  default:
311  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
312  }
313 }
314 
315 // ===========================================================================
316 // private
317 // ===========================================================================
318 
319 void
320 GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value) {
321  switch (key) {
322  case SUMO_ATTR_ID:
323  changeAdditionalID(value);
324  break;
325  case SUMO_ATTR_LANE:
326  myLane = changeLane(myLane, value);
327  break;
328  case SUMO_ATTR_STARTPOS:
329  myStartPosition = value;
330  break;
331  case SUMO_ATTR_ENDPOS:
332  myEndPosition = value;
333  break;
334  case SUMO_ATTR_NAME:
335  myAdditionalName = value;
336  break;
338  myFriendlyPosition = parse<bool>(value);
339  break;
340  case SUMO_ATTR_LINES:
341  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
342  break;
344  myBlockMovement = parse<bool>(value);
345  break;
346  case GNE_ATTR_SELECTED:
347  if (parse<bool>(value)) {
349  } else {
351  }
352  break;
353  case GNE_ATTR_GENERIC:
355  break;
356  default:
357  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
358  }
359  // Update Geometry after setting a new attribute (but avoided for certain attributes)
360  if((key != SUMO_ATTR_ID) && (key != GNE_ATTR_GENERIC) && (key != GNE_ATTR_SELECTED)) {
361  updateGeometry(true);
362  }
363 }
364 
365 /****************************************************************************/
double scale
information about a lane&#39;s width (temporary, used for a single view)
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
std::vector< double > shapeRotations
The rotations of the single shape parts.
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:244
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:62
static const double myCircleInWidth
inner circle width resolution for all stopping places
double x() const
Returns the x-position.
Definition: Position.h:57
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:254
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Position position
position of the block icon
BlockIcon myBlockIcon
variable BlockIcon
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)
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:41
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
double rotation
The rotation of the block icon.
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:757
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
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:1260
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
PositionVector shape
The shape of the additional element.
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:1160
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:226
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
RGBColor selectionColor
NETEDIT special colors.
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< double > shapeLengths
The lengths of the single shape parts.
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
Definition: GNEBusStop.h:94
~GNEBusStop()
Destructor.
Definition: GNEBusStop.cpp:47
double getLaneWidth() const
Returns the default width of lanes of this edge.
Definition: NBEdge.h:530
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
void updateGeometry(bool updateGrid)
update pre-computed geometry information
Definition: GNEBusStop.cpp:51
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEBusStop.cpp:197
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
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
GUIVisualizationTextSettings addFullName
AdditionalGeometry myGeometry
geometry to be precomputed in updateGeometry(...)
const std::string & getTagStr() const
get tag assigned to this object in string format
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:258
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
double distanceSquaredTo2D(const Position &p2) const
returns the square of the distance to another position (Only using x and y positions) ...
Definition: Position.h:249
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEBusStop.cpp:86
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.
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) ...
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:613
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
An access point for a train stop.
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1153
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1059
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:237
GNELane * changeLane(GNELane *oldLane, const std::string &newLaneID)
change lane of additional
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry(bool updateGrid) function) ...
void draw(double size=0.5) const
draw lock icon