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-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>
29 #include <utils/gui/div/GLHelper.h>
32 
33 #include "GNEContainerStop.h"
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
38 
39 GNEContainerStop::GNEContainerStop(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) :
40  GNEStoppingPlace(id, viewNet, GLO_CONTAINER_STOP, SUMO_TAG_CONTAINER_STOP, lane, startPos, endPos, name, friendlyPosition, blockMovement),
41  myLines(lines) {
42 }
43 
44 
46 
47 
48 void
50  // first check if object has to be removed from grid (SUMOTree)
51  if (updateGrid) {
53  }
54 
55  // Get value of option "lefthand"
56  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
57 
58  // Update common geometry of stopping place
60 
61  // Obtain a copy of the shape
62  PositionVector tmpShape = myGeometry.shape;
63 
64  // Move shape to side
65  tmpShape.move2side(1.5 * offsetSign);
66 
67  // Get position of the sign
68  mySignPos = tmpShape.getLineCenter();
69 
70  // Set block icon position
72 
73  // Set block icon rotation, and using their rotation for sign
75 
76  // last step is to check if object has to be added into grid (SUMOTree) again
77  if (updateGrid) {
79  }
80 }
81 
82 
83 void
85  // obtain circle resolution
86  int circleResolution = getCircleResolution(s);
87  // Obtain exaggeration of the draw
88  const double exaggeration = s.addSize.getExaggeration(s, this);
89  // Start drawing adding an gl identificator
90  glPushName(getGlID());
91  // Add a draw matrix
92  glPushMatrix();
93  // Start with the drawing of the area traslating matrix to origin
94  glTranslated(0, 0, getType());
95  // Set color of the base
98  } else {
100  }
101  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
103  // Check if the distance is enought to draw details and if is being drawn for selecting
104  if (s.drawForSelecting) {
105  // only draw circle depending of distance between sign and mouse cursor
107  // Add a draw matrix for details
108  glPushMatrix();
109  // Start drawing sign traslating matrix to signal position
110  glTranslated(mySignPos.x(), mySignPos.y(), 0);
111  // scale matrix depending of the exaggeration
112  glScaled(exaggeration, exaggeration, 1);
113  // set color
115  // Draw circle
116  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
117  // pop draw matrix
118  glPopMatrix();
119  }
120  } else if (s.scale * exaggeration >= 10) {
121  // Add a draw matrix for details
122  glPushMatrix();
123  // Iterate over every line
124  for (int i = 0; i < (int)myLines.size(); ++i) {
125  // push a new matrix for every line
126  glPushMatrix();
127  // Rotate and traslaste
128  glTranslated(mySignPos.x(), mySignPos.y(), 0);
129  glRotated(-1 * myBlockIcon.rotation, 0, 0, 1);
130  // draw line with a color depending of the selection status
132  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, s.selectionColor, 0, FONS_ALIGN_LEFT);
133  } else {
134  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, s.SUMO_color_containerStop, 0, FONS_ALIGN_LEFT);
135  }
136  // pop matrix for every line
137  glPopMatrix();
138  }
139  // Start drawing sign traslating matrix to signal position
140  glTranslated(mySignPos.x(), mySignPos.y(), 0);
141  // scale matrix depending of the exaggeration
142  glScaled(exaggeration, exaggeration, 1);
143  // Set color of the externe circle
146  } else {
148  }
149  // Draw circle
150  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
151  // Traslate to front
152  glTranslated(0, 0, .1);
153  // Set color of the inner circle
156  } else {
158  }
159  // draw another circle in the same position, but a little bit more small
160  GLHelper::drawFilledCircle(myCircleInWidth, circleResolution);
161  // If the scale * exageration is equal or more than 4.5, draw H
162  if (s.scale * exaggeration >= 4.5) {
165  } else {
167  }
168  }
169  // pop draw matrix
170  glPopMatrix();
171  // Show Lock icon depending of the Edit mode
172  myBlockIcon.draw();
173  }
174  // pop draw matrix
175  glPopMatrix();
176  // Draw name if isn't being drawn for selecting
177  if (!s.drawForSelecting) {
178  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
179  }
180  // check if dotted contour has to be drawn
181  if (!s.drawForSelecting && (myViewNet->getDottedAC() == this)) {
183  }
184  // Pop name
185  glPopName();
186 }
187 
188 
189 std::string
191  switch (key) {
192  case SUMO_ATTR_ID:
193  return getAdditionalID();
194  case SUMO_ATTR_LANE:
195  return myLane->getID();
196  case SUMO_ATTR_STARTPOS:
197  return toString(myStartPosition);
198  case SUMO_ATTR_ENDPOS:
199  return myEndPosition;
200  case SUMO_ATTR_NAME:
201  return myAdditionalName;
204  case SUMO_ATTR_LINES:
205  return joinToString(myLines, " ");
207  return toString(myBlockMovement);
208  case GNE_ATTR_SELECTED:
210  case GNE_ATTR_GENERIC:
211  return getGenericParametersStr();
212  default:
213  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
214  }
215 }
216 
217 
218 void
219 GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
220  if (value == getAttribute(key)) {
221  return; //avoid needless changes, later logic relies on the fact that attributes have changed
222  }
223  switch (key) {
224  case SUMO_ATTR_ID:
225  case SUMO_ATTR_LANE:
226  case SUMO_ATTR_STARTPOS:
227  case SUMO_ATTR_ENDPOS:
228  case SUMO_ATTR_NAME:
230  case SUMO_ATTR_LINES:
232  case GNE_ATTR_SELECTED:
233  case GNE_ATTR_GENERIC:
234  undoList->p_add(new GNEChange_Attribute(this, key, value));
235  break;
236  default:
237  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
238  }
239 }
240 
241 
242 bool
243 GNEContainerStop::isValid(SumoXMLAttr key, const std::string& value) {
244  switch (key) {
245  case SUMO_ATTR_ID:
246  return isValidAdditionalID(value);
247  case SUMO_ATTR_LANE:
248  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
249  return true;
250  } else {
251  return false;
252  }
253  case SUMO_ATTR_STARTPOS:
254  if (value.empty()) {
255  return true;
256  } else {
257  if (canParse<double>(value)) {
258  if (canParse<double>(myEndPosition)) {
259  // Check that new start Position is smaller that end position
260  return (parse<double>(value) < parse<double>(myEndPosition));
261  } else {
262  return true;
263  }
264  } else {
265  return false;
266  }
267  }
268  case SUMO_ATTR_ENDPOS:
269  if (value.empty()) {
270  return true;
271  } else {
272  if (canParse<double>(value)) {
273  if (canParse<double>(myStartPosition)) {
274  // Check that new start Position is smaller that end position
275  return (parse<double>(myStartPosition) < parse<double>(value));
276  } else {
277  return true;
278  }
279  } else {
280  return false;
281  }
282  }
283  case SUMO_ATTR_NAME:
286  return canParse<bool>(value);
287  case SUMO_ATTR_LINES:
288  return canParse<std::vector<std::string> >(value);
290  return canParse<bool>(value);
291  case GNE_ATTR_SELECTED:
292  return canParse<bool>(value);
293  case GNE_ATTR_GENERIC:
294  return isGenericParametersValid(value);
295  default:
296  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
297  }
298 }
299 
300 // ===========================================================================
301 // private
302 // ===========================================================================
303 
304 void
305 GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value) {
306  switch (key) {
307  case SUMO_ATTR_ID:
308  changeAdditionalID(value);
309  break;
310  case SUMO_ATTR_LANE:
311  myLane = changeLane(myLane, value);
312  break;
313  case SUMO_ATTR_STARTPOS:
314  myStartPosition = value;
315  break;
316  case SUMO_ATTR_ENDPOS:
317  myEndPosition = value;
318  break;
319  case SUMO_ATTR_NAME:
320  myAdditionalName = value;
321  break;
323  myFriendlyPosition = parse<bool>(value);
324  break;
325  case SUMO_ATTR_LINES:
326  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
327  break;
329  myBlockMovement = parse<bool>(value);
330  break;
331  case GNE_ATTR_SELECTED:
332  if (parse<bool>(value)) {
334  } else {
336  }
337  break;
338  case GNE_ATTR_GENERIC:
340  break;
341  default:
342  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
343  }
344  // Update Geometry after setting a new attribute (but avoided for certain attributes)
345  if((key != SUMO_ATTR_ID) && (key != GNE_ATTR_GENERIC) && (key != GNE_ATTR_SELECTED)) {
346  updateGeometry(true);
347  }
348 }
349 
350 /****************************************************************************/
a containerStop
~GNEContainerStop()
Destructor.
double scale
information about a lane&#39;s width (temporary, used for a single view)
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.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
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
GNEContainerStop(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.
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
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
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
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
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
std::string getAttribute(SumoXMLAttr key) const
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
void updateGeometry(bool updateGrid)
update pre-computed geometry information
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
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
static const RGBColor SUMO_color_containerStop_sign
color for containerStop signs
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.
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
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
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
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) ...
static const double myCircleWidth
circle width resolution for all stopping places
static const RGBColor SUMO_color_containerStop
color for containerStops
std::vector< double > shapeLengths
The lengths of the single shape parts.
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
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
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
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 setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
GNENet * getNet() const
get the net object
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) ...
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
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