SUMO - Simulation of Urban MObility
GNEContainerStop.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
10 // Copyright (C) 2001-2013 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>
49 
50 #include "GNEContainerStop.h"
51 #include "GNELane.h"
52 #include "GNEEdge.h"
53 #include "GNEJunction.h"
54 #include "GNEUndoList.h"
55 #include "GNENet.h"
56 #include "GNEChange_Attribute.h"
57 #include "GNEViewNet.h"
58 
59 #ifdef CHECK_MEMORY_LEAKS
60 #include <foreign/nvwa/debug_new.h>
61 #endif // CHECK_MEMORY_LEAKS
62 
63 // ===========================================================================
64 // method definitions
65 // ===========================================================================
66 
67 GNEContainerStop::GNEContainerStop(const std::string& id, GNELane* lane, GNEViewNet* viewNet, SUMOReal startPos, SUMOReal endPos, const std::vector<std::string>& lines, bool blocked) :
68  GNEStoppingPlace(id, viewNet, SUMO_TAG_CONTAINER_STOP, lane, startPos, endPos, blocked),
69  myLines(lines) {
70  // When a new additional element is created, updateGeometry() must be called
72  // Set colors
73  myBaseColor = RGBColor(83, 89, 172, 255);
74  myBaseColorSelected = RGBColor(103, 109, 192, 255);
75  mySignColor = RGBColor(177, 184, 186, 171);
76  mySignColorSelected = RGBColor(197, 204, 206, 171);
77  myTextColor = RGBColor(83, 89, 172, 255);
78  myTextColorSelected = RGBColor(103, 109, 192, 255);
79 }
80 
81 
83 
84 
85 void
87  // Clear all containers
88  myShapeRotations.clear();
89  myShapeLengths.clear();
90 
91  // Get value of option "lefthand"
92  SUMOReal offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
93 
94  // Get shape of lane parent
95  myShape = myLane->getShape();
96 
97  // Move shape to side
98  myShape.move2side(1.65 * offsetSign);
99 
100  // Cut shape using as delimitators from start position and end position
102 
103  // Get number of parts of the shape
104  int numberOfSegments = (int) myShape.size() - 1;
105 
106  // If number of segments is more than 0
107  if (numberOfSegments >= 0) {
108 
109  // Reserve memory (To improve efficiency)
110  myShapeRotations.reserve(numberOfSegments);
111  myShapeLengths.reserve(numberOfSegments);
112 
113  // For every part of the shape
114  for (int i = 0; i < numberOfSegments; ++i) {
115 
116  // Obtain first position
117  const Position& f = myShape[i];
118 
119  // Obtain next position
120  const Position& s = myShape[i + 1];
121 
122  // Save distance between position into myShapeLengths
123  myShapeLengths.push_back(f.distanceTo(s));
124 
125  // Save rotation (angle) of the vector constructed by points f and s
126  myShapeRotations.push_back((SUMOReal) atan2((s.x() - f.x()), (f.y() - s.y())) * (SUMOReal) 180.0 / (SUMOReal) PI);
127  }
128  }
129 
130  // Obtain a copy of the shape
131  PositionVector tmpShape = myShape;
132 
133  // Move shape to side
134  tmpShape.move2side(1.5 * offsetSign);
135 
136  // Get position of the sign
137  mySignPos = tmpShape.getLineCenter();
138 
139  // Set block icon position
141 
142  // Set block icon rotation, and using their rotation for sign
144 }
145 
146 
147 void
148 GNEContainerStop::writeAdditional(OutputDevice& device, const std::string&) {
149  // Write parameters
150  device.openTag(getTag());
151  device.writeAttr(SUMO_ATTR_ID, getID());
152  device.writeAttr(SUMO_ATTR_LANE, myLane->getID());
155  if (myLines.size() > 0) {
157  }
158  // Close tag
159  device.closeTag();
160 }
161 
162 
163 std::vector<std::string>
165  return myLines;
166 }
167 
168 
169 void
171  // Start drawing adding an gl identificator
172  glPushName(getGlID());
173 
174  // Add a draw matrix
175  glPushMatrix();
176 
177  // Start with the drawing of the area traslating matrix to origin
178  glTranslated(0, 0, getType());
179 
180  // Set color of the base
181  if (isAdditionalSelected()) {
183  } else {
185  }
186 
187  // Obtain exaggeration of the draw
188  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
189 
190  // Draw the area using shape, shapeRotations, shapeLenghts and value of exaggeration
192 
193  // Check if the distance is enought to draw details
194  if (s.scale * exaggeration >= 10) {
195 
196  // Add a draw matrix
197  glPushMatrix();
198 
199  // Obtain rotation of the sing depeding of the option "lefthand"
200  SUMOReal rotSign = OptionsCont::getOptions().getBool("lefthand");
201 
202  // Set color of the lines
203  if (isAdditionalSelected()) {
205  } else {
207  }
208 
209  // Iterate over every line
210  for (int i = 0; i != myLines.size(); ++i) {
211  // Add a new push matrix
212  glPushMatrix();
213 
214  // Traslate End positionof signal
215  glTranslated(mySignPos.x(), mySignPos.y(), 0);
216 
217  // Rotate 180 (Eje X -> Mirror)
218  glRotated(180, 1, 0, 0);
219 
220  // Rotate again depending of the option rotSign
221  glRotated(rotSign * myBlockIconRotation, 0, 0, 1);
222 
223  // Set poligon mode
224  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
225 
226  // set polyfront position ot 0
227  pfSetPosition(0, 0);
228 
229  // Set polyfront scale to 1
230  pfSetScale(1.f);
231 
232  // traslate matrix for every line
233  glTranslated(1.2, -(double)i, 0);
234 
235  // draw line
236  pfDrawString(myLines[i].c_str());
237 
238  // pop matrix
239  glPopMatrix();
240  }
241 
242  // Start drawing sign traslating matrix to signal position
243  glTranslated(mySignPos.x(), mySignPos.y(), 0);
244 
245  // Define nš points (for efficiency)
246  int noPoints = 9;
247 
248  // If the scale * exaggeration is more than 25, recalculate nš points
249  if (s.scale * exaggeration > 25) {
250  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
251  }
252 
253  // scale matrix depending of the exaggeration
254  glScaled(exaggeration, exaggeration, 1);
255 
256  // Draw green circle
257  GLHelper::drawFilledCircle((SUMOReal) 1.1, noPoints);
258 
259  // Traslate to front
260  glTranslated(0, 0, .1);
261 
262  // Set color of the lines
263  if (isAdditionalSelected()) {
265  } else {
267  }
268 
269  // draw another circle in the same position, but a little bit more small
270  GLHelper::drawFilledCircle((SUMOReal) 0.9, noPoints);
271 
272  // If the scale * exageration is equal or more than 4.5, draw H
273  if (s.scale * exaggeration >= 4.5) {
274  if (isAdditionalSelected()) {
276  } else {
278  }
279  }
280 
281  // pop draw matrix
282  glPopMatrix();
283 
284  // Show Lock icon depending of the Edit mode
285  drawLockIcon();
286  }
287 
288  // pop draw matrix
289  glPopMatrix();
290 
291  // Draw name
292  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
293 
294  // Pop name
295  glPopName();
296 }
297 
298 
299 std::string
301  switch (key) {
302  case SUMO_ATTR_ID:
303  return getAdditionalID();
304  case SUMO_ATTR_LANE:
306  case SUMO_ATTR_STARTPOS:
307  return toString(myStartPos);
308  case SUMO_ATTR_ENDPOS:
309  return toString(myEndPos);
310  case SUMO_ATTR_LINES:
311  return joinToString(myLines, " ");
312  default:
313  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
314  }
315 }
316 
317 
318 void
319 GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
320  if (value == getAttribute(key)) {
321  return; //avoid needless changes, later logic relies on the fact that attributes have changed
322  }
323  switch (key) {
324  case SUMO_ATTR_ID:
325  case SUMO_ATTR_LANE:
326  case SUMO_ATTR_STARTPOS:
327  case SUMO_ATTR_ENDPOS:
328  case SUMO_ATTR_LINES:
329  undoList->p_add(new GNEChange_Attribute(this, key, value));
330  updateGeometry();
331  break;
332  default:
333  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
334  }
335 }
336 
337 
338 bool
339 GNEContainerStop::isValid(SumoXMLAttr key, const std::string& value) {
340  switch (key) {
341  case SUMO_ATTR_ID:
342  if (myViewNet->getNet()->getAdditional(getTag(), value) == NULL) {
343  return true;
344  } else {
345  return false;
346  }
347  case SUMO_ATTR_LANE:
348  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
349  return true;
350  } else {
351  return false;
352  }
353  case SUMO_ATTR_STARTPOS:
354  return (canParse<SUMOReal>(value) && parse<SUMOReal>(value) >= 0 && parse<SUMOReal>(value) < (myEndPos - 1));
355  case SUMO_ATTR_ENDPOS:
356  return (canParse<SUMOReal>(value) && parse<SUMOReal>(value) >= 1 && parse<SUMOReal>(value) > myStartPos);
357  case SUMO_ATTR_LINES:
358  return isValidStringVector(value);
359  default:
360  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
361  }
362 }
363 
364 // ===========================================================================
365 // private
366 // ===========================================================================
367 
368 void
369 GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value) {
370  switch (key) {
371  case SUMO_ATTR_ID:
372  setAdditionalID(value);
373  break;
374  case SUMO_ATTR_LANE:
376  break;
377  case SUMO_ATTR_STARTPOS:
378  myStartPos = parse<SUMOReal>(value);
379  updateGeometry();
380  getViewNet()->update();
381  break;
382  case SUMO_ATTR_ENDPOS:
383  myEndPos = parse<SUMOReal>(value);
384  updateGeometry();
385  getViewNet()->update();
386  break;
387  case SUMO_ATTR_LINES:
388  myLines.clear();
390  getViewNet()->update();
391  break;
392  default:
393  throw InvalidArgument(toString(getType()) + " attribute '" + toString(key) + "' not allowed");
394  }
395 }
396 
397 /****************************************************************************/
SUMOReal getExaggeration(const GUIVisualizationSettings &s, SUMOReal factor=20) const
return the drawing size including exaggeration and constantSize values
std::vector< std::string > getLines() const
get string vector with the lines of the busStop
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:257
int pfDrawString(const char *c)
Definition: polyfonts.c:1074
~GNEContainerStop()
Destructor.
GUIVisualizationTextSettings addName
bool isValid(SumoXMLAttr key, const std::string &value)
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
RGBColor myTextColorSelected
Text color selected (Default blue)
void pfSetPosition(SUMOReal x, SUMOReal y)
Definition: polyfonts.c:480
static void drawBoxLines(const PositionVector &geom, const std::vector< SUMOReal > &rots, const std::vector< SUMOReal > &lengths, SUMOReal width, int cornerDetail=0, SUMOReal offset=0)
Draws thick lines.
Definition: GLHelper.cpp:176
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:221
static void drawText(const std::string &text, const Position &pos, const SUMOReal layer, const SUMOReal size, const RGBColor &col=RGBColor::BLACK, const SUMOReal angle=0)
draw Text with given parameters
Definition: GLHelper.cpp:460
SUMOReal myEndPos
The end position this stopping place is located at.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
GUIGlID getGlID() const
Returns the numerical id of the object.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
RGBColor myBaseColorSelected
base color selected (Default blue)
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
static void drawFilledCircle(SUMOReal width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:344
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
static void parseStringVector(const std::string &def, std::vector< std::string > &into)
Splits the given string.
std::string getAttribute(SumoXMLAttr key) const
#define PI
Definition: polyfonts.c:61
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
std::vector< SUMOReal > myShapeLengths
The lengths of the shape parts.
SUMOReal myBlockIconRotation
The rotation of the block icon.
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:443
const std::string & getAdditionalID() const
returns the ID of additional
SUMOReal getPositionRelativeToParametricLenght(SUMOReal position) const
Definition: GNELane.cpp:530
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
void updateGeometry()
update pre-computed geometry information
RGBColor mySignColor
sign color (Default yellow)
A list of positions.
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:658
void setBlockIconRotation(GNELane *lane=NULL)
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
GNELane * myLane
The lane this stopping place belongs.
friend class GNEChange_Attribute
declare friend class
RGBColor myTextColor
Text color (Default cyan)
void drawLockIcon(SUMOReal size=0.5) const
draw lock icon
SUMOReal myStartPos
The start position this stopping place is located at.
T MIN2(T a, T b)
Definition: StdDefs.h:69
void setAdditionalID(const std::string &id)
set the ID of additional
const std::string getID() const
function to support debugging
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
draw name of item
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
std::string getAttribute(SumoXMLAttr key) const
Definition: GNELane.cpp:601
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1093
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:456
void changeLane(GNELane *newLane)
change lane of stopping place
static bool isValidStringVector(const std::string &value)
true if value is a valid string vector
void pfSetScale(SUMOReal s)
Definition: polyfonts.c:465
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
RGBColor myBaseColor
base color (Default green)
std::vector< SUMOReal > myShapeRotations
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:845
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
Position getLineCenter() const
get line center
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:188
SumoXMLTag getTag() const
get Tag assigned to this object
void move2side(SUMOReal amount)
move position vector to side using certain ammount
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:213
GNEContainerStop(const std::string &id, GNELane *lane, GNEViewNet *viewNet, SUMOReal startPos, SUMOReal endPos, const std::vector< std::string > &lines, bool blocked)
Constructor.
Position mySignPos
The position of the sign.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const
get subpart of a position vector
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
RGBColor mySignColorSelected
sign selected color (Default blue)
void writeAdditional(OutputDevice &device, const std::string &)
writte additional element into a xml file
Position myBlockIconPosition
position of the block icon