Eclipse 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-2019 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>
30 #include <utils/gui/div/GLHelper.h>
33 
34 #include "GNEContainerStop.h"
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 
40 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) :
41  GNEStoppingPlace(id, viewNet, GLO_CONTAINER_STOP, SUMO_TAG_CONTAINER_STOP, lane, startPos, endPos, name, friendlyPosition, blockMovement),
42  myLines(lines) {
43 }
44 
45 
47 
48 
49 void
51  // Get value of option "lefthand"
52  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
53 
54  // Update common geometry of stopping place
55  setStoppingPlaceGeometry(getLaneParents().front()->getParentEdge().getNBEdge()->getLaneWidth(getLaneParents().front()->getIndex()) / 2);
56 
57  // Obtain a copy of the shape
58  PositionVector tmpShape = myGeometry.shape;
59 
60  // Move shape to side
61  tmpShape.move2side(1.5 * offsetSign);
62 
63  // Get position of the sign
64  mySignPos = tmpShape.getLineCenter();
65 
66  // Set block icon position
68 
69  // Set block icon rotation, and using their rotation for sign
71 }
72 
73 
76  return myGeometry.shape.getBoxBoundary().grow(10);
77 }
78 
79 
80 void
82  // Obtain exaggeration of the draw
83  const double exaggeration = s.addSize.getExaggeration(s, this);
84  // Start drawing adding an gl identificator
85  glPushName(getGlID());
86  // Add a draw matrix
87  glPushMatrix();
88  // Start with the drawing of the area traslating matrix to origin
89  glTranslated(0, 0, getType());
90  // Set color of the base
91  if (drawUsingSelectColor()) {
93  } else {
95  }
96  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
98  // Check if the distance is enought to draw details and if is being drawn for selecting
99  if (s.drawForSelecting) {
100  // only draw circle depending of distance between sign and mouse cursor
102  // Add a draw matrix for details
103  glPushMatrix();
104  // Start drawing sign traslating matrix to signal position
105  glTranslated(mySignPos.x(), mySignPos.y(), 0);
106  // scale matrix depending of the exaggeration
107  glScaled(exaggeration, exaggeration, 1);
108  // set color
110  // Draw circle
112  // pop draw matrix
113  glPopMatrix();
114  }
115  } else if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, exaggeration)) {
116  // Add a draw matrix for details
117  glPushMatrix();
118  // Iterate over every line
119  for (int i = 0; i < (int)myLines.size(); ++i) {
120  // push a new matrix for every line
121  glPushMatrix();
122  // Rotate and traslaste
123  glTranslated(mySignPos.x(), mySignPos.y(), 0);
124  glRotated(-1 * myBlockIcon.rotation, 0, 0, 1);
125  // draw line with a color depending of the selection status
126  if (drawUsingSelectColor()) {
127  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, s.colorSettings.selectionColor, 0, FONS_ALIGN_LEFT);
128  } else {
129  GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, s.colorSettings.containerStop, 0, FONS_ALIGN_LEFT);
130  }
131  // pop matrix for every line
132  glPopMatrix();
133  }
134  // Start drawing sign traslating matrix to signal position
135  glTranslated(mySignPos.x(), mySignPos.y(), 0);
136  // scale matrix depending of the exaggeration
137  glScaled(exaggeration, exaggeration, 1);
138  // Set color of the externe circle
139  if (drawUsingSelectColor()) {
141  } else {
143  }
144  // Draw circle
146  // Traslate to front
147  glTranslated(0, 0, .1);
148  // Set color of the inner circle
149  if (drawUsingSelectColor()) {
151  } else {
153  }
154  // draw another circle in the same position, but a little bit more small
156  // draw text depending of detail settings
157  if (s.drawDetail(s.detailSettings.stoppingPlaceText, exaggeration)) {
158  if (drawUsingSelectColor()) {
160  } else {
162  }
163  }
164  // pop draw matrix
165  glPopMatrix();
166  // Show Lock icon depending of the Edit mode
167  myBlockIcon.drawIcon(s, exaggeration);
168  }
169  // pop draw matrix
170  glPopMatrix();
171  // Draw name if isn't being drawn for selecting
172  if (!s.drawForSelecting) {
174  }
175  // check if dotted contour has to be drawn
176  if (myViewNet->getDottedAC() == this) {
178  }
179  // Pop name
180  glPopName();
181  // draw demand element children
182  for (const auto& i : getDemandElementChildren()) {
183  if (!i->getTagProperty().isPlacedInRTree()) {
184  i->drawGL(s);
185  }
186  }
187 }
188 
189 
190 std::string
192  switch (key) {
193  case SUMO_ATTR_ID:
194  return getAdditionalID();
195  case SUMO_ATTR_LANE:
196  return getLaneParents().front()->getID();
197  case SUMO_ATTR_STARTPOS:
198  return toString(myStartPosition);
199  case SUMO_ATTR_ENDPOS:
200  return myEndPosition;
201  case SUMO_ATTR_NAME:
202  return myAdditionalName;
205  case SUMO_ATTR_LINES:
206  return joinToString(myLines, " ");
208  return toString(myBlockMovement);
209  case GNE_ATTR_SELECTED:
211  case GNE_ATTR_GENERIC:
212  return getGenericParametersStr();
213  default:
214  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
215  }
216 }
217 
218 
219 void
220 GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
221  if (value == getAttribute(key)) {
222  return; //avoid needless changes, later logic relies on the fact that attributes have changed
223  }
224  switch (key) {
225  case SUMO_ATTR_ID:
226  case SUMO_ATTR_LANE:
227  case SUMO_ATTR_STARTPOS:
228  case SUMO_ATTR_ENDPOS:
229  case SUMO_ATTR_NAME:
231  case SUMO_ATTR_LINES:
233  case GNE_ATTR_SELECTED:
234  case GNE_ATTR_GENERIC:
235  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
236  break;
237  default:
238  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
239  }
240 }
241 
242 
243 bool
244 GNEContainerStop::isValid(SumoXMLAttr key, const std::string& value) {
245  switch (key) {
246  case SUMO_ATTR_ID:
247  return isValidAdditionalID(value);
248  case SUMO_ATTR_LANE:
249  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
250  return true;
251  } else {
252  return false;
253  }
254  case SUMO_ATTR_STARTPOS:
255  if (value.empty()) {
256  return true;
257  } else if (canParse<double>(value)) {
258  return checkStoppinPlacePosition(value, myEndPosition, getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength(), myFriendlyPosition);
259  } else {
260  return false;
261  }
262  case SUMO_ATTR_ENDPOS:
263  if (value.empty()) {
264  return true;
265  } else if (canParse<double>(value)) {
266  return checkStoppinPlacePosition(myStartPosition, value, getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength(), myFriendlyPosition);
267  } else {
268  return false;
269  }
270  case SUMO_ATTR_NAME:
273  return canParse<bool>(value);
274  case SUMO_ATTR_LINES:
275  return canParse<std::vector<std::string> >(value);
277  return canParse<bool>(value);
278  case GNE_ATTR_SELECTED:
279  return canParse<bool>(value);
280  case GNE_ATTR_GENERIC:
281  return isGenericParametersValid(value);
282  default:
283  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
284  }
285 }
286 
287 // ===========================================================================
288 // private
289 // ===========================================================================
290 
291 void
292 GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value) {
293  switch (key) {
294  case SUMO_ATTR_ID:
295  changeAdditionalID(value);
296  break;
297  case SUMO_ATTR_LANE:
298  changeLaneParents(this, value);
299  break;
300  case SUMO_ATTR_STARTPOS:
301  myStartPosition = value;
302  break;
303  case SUMO_ATTR_ENDPOS:
304  myEndPosition = value;
305  break;
306  case SUMO_ATTR_NAME:
307  myAdditionalName = value;
308  break;
310  myFriendlyPosition = parse<bool>(value);
311  break;
312  case SUMO_ATTR_LINES:
313  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
314  break;
316  myBlockMovement = parse<bool>(value);
317  break;
318  case GNE_ATTR_SELECTED:
319  if (parse<bool>(value)) {
321  } else {
323  }
324  break;
325  case GNE_ATTR_GENERIC:
327  break;
328  default:
329  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
330  }
331 }
332 
333 /****************************************************************************/
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:182
GUIVisualizationTextSettings addName
std::vector< double > shapeRotations
The rotations of the single shape parts.
Definition: GNEAdditional.h:74
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
Stores the information about how to visualize structures.
static const double myCircleWidthSquared
squared circle width resolution for all stopping places
static const RGBColor containerStop_sign
color for containerStop signs
double y() const
Returns the y-position.
Definition: Position.h:62
static const double myCircleInWidth
inner circle width resolution for all stopping places
static const double stoppingPlaceText
details for stopping place texts
Position getPositionInView() const
Returns position of additional in view.
static bool checkStoppinPlacePosition(const std::string &startPosStr, const std::string &endPosStr, const double laneLength, const bool friendlyPos)
check if the position of an stoppingPlace over a lane is valid (without modifications) ...
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:668
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
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:46
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.
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
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:348
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
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
Position getLineCenter() const
get line center
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
double rotation
The rotation of the block icon.
const std::vector< GNEDemandElement * > & getDemandElementChildren() const
return vector of demand elements that have as Parent this edge (For example, Calibrators) ...
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
int getCircleResolution() const
function to calculate circle resolution for all circles drawn in drawGL(...) functions ...
GUIVisualizationSizeSettings addSize
static const RGBColor containerStop
color for containerStops
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:48
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
PositionVector shape
The shape of the additional element.
Definition: GNEAdditional.h:68
void updateGeometry()
update pre-computed geometry information
RGBColor selectionColor
basic selection color
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
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
const std::vector< GNELane * > & getLaneParents() const
get lanes of VSS
block movement of a graphic element
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
static void drawShapeDottedContourAroundShape(const GUIVisualizationSettings &s, 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:461
static const double myCircleWidth
circle width resolution for all stopping places
std::vector< double > shapeLengths
The lengths of the single shape parts.
Definition: GNEAdditional.h:77
GUIVisualizationDetailSettings detailSettings
detail settings
void changeLaneParents(GNEShape *elementChild, const std::string &newLaneIDs)
change edge parents of a shape
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
Definition: GNEViewNet.cpp:939
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
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
Definition: GNEViewNet.cpp:927
GUIGlID getGlID() const
Returns the numerical id of the object.
static const double stoppingPlaceDetails
details for stopping places
Position getPositionInformation() const
Returns the cursor&#39;s x/y position within the network.
GUIVisualizationColorSettings colorSettings
color settings
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
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.
void drawIcon(const GUIVisualizationSettings &s, const double exaggeration, const double size=0.5) const
draw lock icon
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
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1179
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:247
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry() function)