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 #include <config.h>
22 
23 #include <string>
24 #include <iostream>
25 #include <utility>
30 #include <utils/common/ToString.h>
31 #include <utils/geom/GeomHelper.h>
36 #include <utils/gui/div/GLHelper.h>
44 #include <netedit/GNEUndoList.h>
45 #include <netedit/GNENet.h>
47 #include <netedit/GNEViewNet.h>
48 #include <netedit/GNEViewParent.h>
49 
50 #include "GNEContainerStop.h"
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 
57 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) :
58  GNEStoppingPlace(id, viewNet, GLO_CONTAINER_STOP, SUMO_TAG_CONTAINER_STOP, lane, startPos, endPos, name, friendlyPosition, blockMovement),
59  myLines(lines) {
60 }
61 
62 
64 
65 
66 void
68  // first check if object has to be removed from grid (SUMOTree)
69  if (updateGrid) {
71  }
72 
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  // last step is to check if object has to be added into grid (SUMOTree) again
95  if (updateGrid) {
97  }
98 }
99 
100 
101 void
103  // obtain circle resolution
104  int circleResolution = getCircleResolution(s);
105  // Obtain exaggeration of the draw
106  const double exaggeration = s.addSize.getExaggeration(s);
107  // Start drawing adding an gl identificator
108  glPushName(getGlID());
109  // Add a draw matrix
110  glPushMatrix();
111  // Start with the drawing of the area traslating matrix to origin
112  glTranslated(0, 0, getType());
113  // Set color of the base
116  } else {
118  }
119  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
121  // Check if the distance is enought to draw details and if is being drawn for selecting
122  if (s.drawForSelecting) {
123  // only draw circle depending of distance between sign and mouse cursor
125  // Add a draw matrix for details
126  glPushMatrix();
127  // Start drawing sign traslating matrix to signal position
128  glTranslated(mySignPos.x(), mySignPos.y(), 0);
129  // scale matrix depending of the exaggeration
130  glScaled(exaggeration, exaggeration, 1);
131  // set color
133  // Draw circle
134  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
135  // pop draw matrix
136  glPopMatrix();
137  }
138  } else if (s.scale * exaggeration >= 10) {
139  // Add a draw matrix for details
140  glPushMatrix();
141  // Iterate over every line
142  for (int i = 0; i < (int)myLines.size(); ++i) {
143  // push a new matrix for every line
144  glPushMatrix();
145  // Rotate and traslaste
146  glTranslated(mySignPos.x(), mySignPos.y(), 0);
147  glRotated(-1 * myBlockIconRotation, 0, 0, 1);
148  // draw line with a color depending of the selection status
150  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, myViewNet->getNet()->selectionColor, 0, FONS_ALIGN_LEFT);
151  } else {
152  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, s.SUMO_color_containerStop, 0, FONS_ALIGN_LEFT);
153  }
154  // pop matrix for every line
155  glPopMatrix();
156  }
157  // Start drawing sign traslating matrix to signal position
158  glTranslated(mySignPos.x(), mySignPos.y(), 0);
159  // scale matrix depending of the exaggeration
160  glScaled(exaggeration, exaggeration, 1);
161  // Set color of the externe circle
164  } else {
166  }
167  // Draw circle
168  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
169  // Traslate to front
170  glTranslated(0, 0, .1);
171  // Set color of the inner circle
174  } else {
176  }
177  // draw another circle in the same position, but a little bit more small
178  GLHelper::drawFilledCircle(myCircleInWidth, circleResolution);
179  // If the scale * exageration is equal or more than 4.5, draw H
180  if (s.scale * exaggeration >= 4.5) {
183  } else {
185  }
186  }
187  // pop draw matrix
188  glPopMatrix();
189  // Show Lock icon depending of the Edit mode
190  drawLockIcon();
191  }
192  // pop draw matrix
193  glPopMatrix();
194  // Draw name if isn't being drawn for selecting
195  if (!s.drawForSelecting) {
196  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
197  }
198  // check if dotted contour has to be drawn
199  if (!s.drawForSelecting && (myViewNet->getACUnderCursor() == this)) {
201  }
202  // Pop name
203  glPopName();
204 }
205 
206 
207 std::string
209  switch (key) {
210  case SUMO_ATTR_ID:
211  return getAdditionalID();
212  case SUMO_ATTR_LANE:
213  return myLane->getID();
214  case SUMO_ATTR_STARTPOS:
215  return toString(myStartPosition);
216  case SUMO_ATTR_ENDPOS:
217  return myEndPosition;
218  case SUMO_ATTR_NAME:
219  return myAdditionalName;
222  case SUMO_ATTR_LINES:
223  return joinToString(myLines, " ");
225  return toString(myBlockMovement);
226  case GNE_ATTR_SELECTED:
228  case GNE_ATTR_GENERIC:
229  return getGenericParametersStr();
230  default:
231  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
232  }
233 }
234 
235 
236 void
237 GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
238  if (value == getAttribute(key)) {
239  return; //avoid needless changes, later logic relies on the fact that attributes have changed
240  }
241  switch (key) {
242  case SUMO_ATTR_ID:
243  case SUMO_ATTR_LANE:
244  case SUMO_ATTR_STARTPOS:
245  case SUMO_ATTR_ENDPOS:
246  case SUMO_ATTR_NAME:
248  case SUMO_ATTR_LINES:
250  case GNE_ATTR_SELECTED:
251  case GNE_ATTR_GENERIC:
252  undoList->p_add(new GNEChange_Attribute(this, key, value));
253  break;
254  default:
255  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
256  }
257 }
258 
259 
260 bool
261 GNEContainerStop::isValid(SumoXMLAttr key, const std::string& value) {
262  switch (key) {
263  case SUMO_ATTR_ID:
264  return isValidAdditionalID(value);
265  case SUMO_ATTR_LANE:
266  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
267  return true;
268  } else {
269  return false;
270  }
271  case SUMO_ATTR_STARTPOS:
272  if (value.empty()) {
273  return true;
274  } else {
275  if (canParse<double>(value)) {
276  if (canParse<double>(myEndPosition)) {
277  // Check that new start Position is smaller that end position
278  return (parse<double>(value) < parse<double>(myEndPosition));
279  } else {
280  return true;
281  }
282  } else {
283  return false;
284  }
285  }
286  case SUMO_ATTR_ENDPOS:
287  if (value.empty()) {
288  return true;
289  } else {
290  if (canParse<double>(value)) {
291  if (canParse<double>(myStartPosition)) {
292  // Check that new start Position is smaller that end position
293  return (parse<double>(myStartPosition) < parse<double>(value));
294  } else {
295  return true;
296  }
297  } else {
298  return false;
299  }
300  }
301  case SUMO_ATTR_NAME:
304  return canParse<bool>(value);
305  case SUMO_ATTR_LINES:
306  return canParse<std::vector<std::string> >(value);
308  return canParse<bool>(value);
309  case GNE_ATTR_SELECTED:
310  return canParse<bool>(value);
311  case GNE_ATTR_GENERIC:
312  return isGenericParametersValid(value);
313  default:
314  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
315  }
316 }
317 
318 // ===========================================================================
319 // private
320 // ===========================================================================
321 
322 void
323 GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value) {
324  switch (key) {
325  case SUMO_ATTR_ID:
326  changeAdditionalID(value);
327  break;
328  case SUMO_ATTR_LANE:
329  myLane = changeLane(myLane, value);
330  break;
331  case SUMO_ATTR_STARTPOS:
332  myStartPosition = value;
333  break;
334  case SUMO_ATTR_ENDPOS:
335  myEndPosition = value;
336  break;
337  case SUMO_ATTR_NAME:
338  myAdditionalName = value;
339  break;
341  myFriendlyPosition = parse<bool>(value);
342  break;
343  case SUMO_ATTR_LINES:
344  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
345  break;
347  myBlockMovement = parse<bool>(value);
348  break;
349  case GNE_ATTR_SELECTED:
350  if (parse<bool>(value)) {
352  } else {
354  }
355  break;
356  case GNE_ATTR_GENERIC:
358  break;
359  default:
360  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
361  }
362  // After setting attribute always update Geometry
363  updateGeometry(true);
364 }
365 
366 /****************************************************************************/
a containerStop
const GNEAttributeCarrier * getACUnderCursor() const
get AttributeCarrier under cursor
~GNEContainerStop()
Destructor.
double scale
information about a lane&#39;s width (temporary, used for a single view)
void setBlockIconRotation(GNELane *additionalLane=nullptr)
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
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:61
static const double myCircleInWidth
inner circle width resolution for all stopping places
double x() const
Returns the x-position.
Definition: Position.h:56
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
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)
std::vector< double > myShapeRotations
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
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:767
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:105
void updateGeometry(bool updateGrid)
update pre-computed geometry information
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: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:1298
static const RGBColor SUMO_color_containerStop_sign
color for containerStop signs
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
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:1175
double distanceSquaredTo(const Position &p2) const
returns the square of the distance to another position
Definition: Position.h:238
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
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
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
double getLaneWidth() const
Returns the default width of lanes of this edge.
Definition: NBEdge.h:528
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
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
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.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
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) ...
static const RGBColor selectionColor
Definition: GNENet.h:96
Position mySignPos
The position of the sign.
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:586
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1168
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1074
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:230
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