SUMO - Simulation of Urban MObility
GNEContainerStop.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 "GNEContainerStop.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 GNEContainerStop::GNEContainerStop(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_CONTAINER_STOP, ICON_CONTAINERSTOP, 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(83, 89, 172));
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(83, 89, 172), 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(83, 89, 172));
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 inner circle
203  if (isAdditionalSelected()) {
205  } else {
206  GLHelper::setColor(RGBColor(177, 184, 186, 171));
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("C", Position(), .1, 1.6, RGBColor(83, 89, 172, 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  // Draw name
232  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
233 
234  // Pop name
235  glPopName();
236 }
237 
238 
239 std::string
241  switch (key) {
242  case SUMO_ATTR_ID:
243  return getAdditionalID();
244  case SUMO_ATTR_LANE:
245  return myLane->getID();
246  case SUMO_ATTR_STARTPOS:
248  case SUMO_ATTR_ENDPOS:
250  case SUMO_ATTR_NAME:
251  return myName;
254  case SUMO_ATTR_LINES:
255  return joinToString(myLines, " ");
257  return toString(myBlocked);
258  default:
259  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
260  }
261 }
262 
263 
264 void
265 GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
266  if (value == getAttribute(key)) {
267  return; //avoid needless changes, later logic relies on the fact that attributes have changed
268  }
269  switch (key) {
270  case SUMO_ATTR_ID:
271  case SUMO_ATTR_LANE:
272  case SUMO_ATTR_STARTPOS:
273  case SUMO_ATTR_ENDPOS:
274  case SUMO_ATTR_NAME:
276  case SUMO_ATTR_LINES:
278  undoList->p_add(new GNEChange_Attribute(this, key, value));
279  break;
280  default:
281  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
282  }
283 }
284 
285 
286 bool
287 GNEContainerStop::isValid(SumoXMLAttr key, const std::string& value) {
288  switch (key) {
289  case SUMO_ATTR_ID:
290  return isValidAdditionalID(value);
291  case SUMO_ATTR_LANE:
292  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
293  return true;
294  } else {
295  return false;
296  }
297  case SUMO_ATTR_STARTPOS:
298  if (canParse<double>(value)) {
299  // Check that new start Position is smaller that end position
300  return ((parse<double>(value) / myLane->getLaneParametricLength()) < myEndPosRelative);
301  } else {
302  return false;
303  }
304  case SUMO_ATTR_ENDPOS:
305  if (canParse<double>(value)) {
306  // Check that new end Position is larger that end position
307  return ((parse<double>(value) / myLane->getLaneParametricLength()) > myStartPosRelative);
308  } else {
309  return false;
310  }
311  case SUMO_ATTR_NAME:
312  return true;
314  return canParse<bool>(value);
315  case SUMO_ATTR_LINES:
316  return canParse<std::vector<std::string> >(value);
318  return canParse<bool>(value);
319  default:
320  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
321  }
322 }
323 
324 // ===========================================================================
325 // private
326 // ===========================================================================
327 
328 void
329 GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value) {
330  switch (key) {
331  case SUMO_ATTR_ID:
332  changeAdditionalID(value);
333  break;
334  case SUMO_ATTR_LANE:
335  myLane = changeLane(myLane, value);
336  break;
337  case SUMO_ATTR_STARTPOS:
338  myStartPosRelative = parse<double>(value) / myLane->getLaneParametricLength();
339  break;
340  case SUMO_ATTR_ENDPOS:
341  myEndPosRelative = parse<double>(value) / myLane->getLaneParametricLength();
342  break;
343  case SUMO_ATTR_NAME:
344  myName = value;
345  break;
347  myFriendlyPosition = parse<bool>(value);
348  break;
349  case SUMO_ATTR_LINES:
350  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
351  break;
353  myBlocked = parse<bool>(value);
354  break;
355  default:
356  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
357  }
358  // After setting attribute always update Geometry
359  updateGeometry();
360 }
361 
362 /****************************************************************************/
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:260
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
~GNEContainerStop()
Destructor.
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
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void refreshElement(GUIGlObject *o)
refreshes boundary information for o and update
Definition: GNENet.cpp:1082
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
double getAbsoluteStartPosition() const
get absolute start Position
double x() const
Returns the x-position.
Definition: Position.h:62
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
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
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.
std::vector< double > myShapeRotations
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:350
GUIGlID getGlID() const
Returns the numerical id of the object.
void changeAdditionalID(const std::string &newID)
change ID of additional
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in all GNEAttributeCarriers.
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:116
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
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
const std::string & getAdditionalID() const
returns Additional ID
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
void updateGeometry()
update pre-computed geometry information
A list of positions.
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
GNELane * myLane
The lane in which this lane is placed.
friend class GNEChange_Attribute
declare friend class
double y() const
Returns the y-position.
Definition: Position.h:67
block movement of a graphic element
const std::vector< std::string > & getLines() const
get string vector with the lines of the busStop
T MIN2(T a, T b)
Definition: StdDefs.h:67
std::vector< double > myShapeLengths
The lengths of the shape parts.
const std::string getID() const
function to support debugging
void drawLockIcon(double size=0.5) const
draw lock icon
void move2side(double amount)
move position vector to side using certain ammount
std::string myName
name of stoppingPlace
bool myBlocked
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
double myEndPosRelative
The relative [0,1] end position this stopping place is located at.
double myStartPosRelative
The relative [0,1] start position this stopping place is located at.
void setBlockIconRotation(GNELane *additionalLane=NULL)
GNENet * getNet() const
get the net object
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
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:70
bool closeTag()
Closes the most recently opened tag.
GNEContainerStop(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.
static const RGBColor selectionColor
Definition: GNENet.h:107
double getAbsoluteEndPosition() const
get absolute end Position
Position mySignPos
The position of the sign.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:701
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