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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // A lane area vehicles can halt at (GNE version)
19 /****************************************************************************/
21 #include <netedit/GNENet.h>
22 #include <netedit/GNEUndoList.h>
23 #include <netedit/GNEViewNet.h>
25 #include <utils/gui/div/GLHelper.h>
29 
30 #include "GNEContainerStop.h"
31 
32 // ===========================================================================
33 // method definitions
34 // ===========================================================================
35 
36 GNEContainerStop::GNEContainerStop(const std::string& id, GNELane* lane, GNENet* net, const double startPos, const double endPos, const int parametersSet,
37  const std::string& name, const std::vector<std::string>& lines, bool friendlyPosition, bool blockMovement) :
38  GNEStoppingPlace(id, net, GLO_CONTAINER_STOP, SUMO_TAG_CONTAINER_STOP, lane, startPos, endPos, parametersSet, name, friendlyPosition, blockMovement),
39  myLines(lines) {
40  // update centering boundary without updating grid
42 }
43 
44 
46 
47 
48 void
50  // Get value of option "lefthand"
51  const double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
52 
53  // Update common geometry of stopping place
54  setStoppingPlaceGeometry(getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) / 2);
55 
56  // Obtain a copy of the shape
58 
59  // Move shape to side
61 
62  // Get position of the sign
63  mySignPos = tmpShape.getLineCenter();
64 }
65 
66 
67 void
69  // Obtain exaggeration of the draw
70  const double containerStopExaggeration = s.addSize.getExaggeration(s, this);
71  // first check if additional has to be drawn
72  if (s.drawAdditionals(containerStopExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
73  // declare colors
74  RGBColor baseColor, signColor;
75  // set colors
76  if (mySpecialColor) {
77  baseColor = *mySpecialColor;
78  signColor = baseColor.changedBrightness(-32);
79  } else if (drawUsingSelectColor()) {
81  signColor = baseColor.changedBrightness(-32);
82  } else {
85  }
86  // Start drawing adding an gl identificator
87  glPushName(getGlID());
88  // Add a draw matrix
89  glPushMatrix();
90  // translate to front
92  // set base color
93  GLHelper::setColor(baseColor);
94  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
96  // draw detail
97  if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, containerStopExaggeration)) {
98  // draw lines
99  drawLines(s, myLines, baseColor);
100  // draw sign
101  drawSign(s, containerStopExaggeration, baseColor, signColor, "C");
102  // draw lock icon
103  GNEViewNetHelper::LockIcon::drawLockIcon(this, myAdditionalGeometry, containerStopExaggeration, 0, 0, true);
104  }
105  // pop draw matrix
106  glPopMatrix();
107  // Pop name
108  glPopName();
109  // Draw additional ID
110  drawAdditionalID(s);
111  // draw additional name
113  // check if dotted contours has to be drawn
116  }
117  if (s.drawDottedContour() || myNet->getViewNet()->getFrontAttributeCarrier() == this) {
119  }
120  // draw child demand elements
121  for (const auto& demandElement : getChildDemandElements()) {
122  if (!demandElement->getTagProperty().isPlacedInRTree()) {
123  demandElement->drawGL(s);
124  }
125  }
126  }
127 }
128 
129 
130 std::string
132  switch (key) {
133  case SUMO_ATTR_ID:
134  return getID();
135  case SUMO_ATTR_LANE:
136  return getParentLanes().front()->getID();
137  case SUMO_ATTR_STARTPOS:
139  return toString(myStartPosition);
140  } else {
141  return "";
142  }
143  case SUMO_ATTR_ENDPOS:
145  return toString(myEndPosition);
146  } else {
147  return "";
148  }
149  case SUMO_ATTR_NAME:
150  return myAdditionalName;
153  case SUMO_ATTR_LINES:
154  return joinToString(myLines, " ");
156  return toString(myBlockMovement);
157  case GNE_ATTR_SELECTED:
159  case GNE_ATTR_PARAMETERS:
160  return getParametersStr();
161  default:
162  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
163  }
164 }
165 
166 
167 void
168 GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
169  if (value == getAttribute(key)) {
170  return; //avoid needless changes, later logic relies on the fact that attributes have changed
171  }
172  switch (key) {
173  case SUMO_ATTR_ID:
174  case SUMO_ATTR_LANE:
175  case SUMO_ATTR_STARTPOS:
176  case SUMO_ATTR_ENDPOS:
177  case SUMO_ATTR_NAME:
179  case SUMO_ATTR_LINES:
181  case GNE_ATTR_SELECTED:
182  case GNE_ATTR_PARAMETERS:
183  undoList->p_add(new GNEChange_Attribute(this, key, value));
184  break;
185  default:
186  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
187  }
188 }
189 
190 
191 bool
192 GNEContainerStop::isValid(SumoXMLAttr key, const std::string& value) {
193  switch (key) {
194  case SUMO_ATTR_ID:
195  return isValidAdditionalID(value);
196  case SUMO_ATTR_LANE:
197  if (myNet->retrieveLane(value, false) != nullptr) {
198  return true;
199  } else {
200  return false;
201  }
202  case SUMO_ATTR_STARTPOS:
203  if (value.empty()) {
204  return true;
205  } else if (canParse<double>(value)) {
206  return SUMORouteHandler::isStopPosValid(parse<double>(value), myEndPosition, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
207  } else {
208  return false;
209  }
210  case SUMO_ATTR_ENDPOS:
211  if (value.empty()) {
212  return true;
213  } else if (canParse<double>(value)) {
214  return SUMORouteHandler::isStopPosValid(myStartPosition, parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
215  } else {
216  return false;
217  }
218  case SUMO_ATTR_NAME:
221  return canParse<bool>(value);
222  case SUMO_ATTR_LINES:
223  return canParse<std::vector<std::string> >(value);
225  return canParse<bool>(value);
226  case GNE_ATTR_SELECTED:
227  return canParse<bool>(value);
228  case GNE_ATTR_PARAMETERS:
229  return Parameterised::areParametersValid(value);
230  default:
231  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
232  }
233 }
234 
235 // ===========================================================================
236 // private
237 // ===========================================================================
238 
239 void
240 GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value) {
241  switch (key) {
242  case SUMO_ATTR_ID:
243  myNet->getAttributeCarriers()->updateID(this, value);
244  break;
245  case SUMO_ATTR_LANE:
247  break;
248  case SUMO_ATTR_STARTPOS:
249  if (!value.empty()) {
250  myStartPosition = parse<double>(value);
252  } else {
254  }
255  break;
256  case SUMO_ATTR_ENDPOS:
257  if (!value.empty()) {
258  myEndPosition = parse<double>(value);
260  } else {
262  }
263  break;
264  case SUMO_ATTR_NAME:
265  myAdditionalName = value;
266  break;
268  myFriendlyPosition = parse<bool>(value);
269  break;
270  case SUMO_ATTR_LINES:
271  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
272  break;
274  myBlockMovement = parse<bool>(value);
275  break;
276  case GNE_ATTR_SELECTED:
277  if (parse<bool>(value)) {
279  } else {
281  }
282  break;
283  case GNE_ATTR_PARAMETERS:
284  setParametersStr(value);
285  break;
286  default:
287  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
288  }
289 }
290 
291 
292 /****************************************************************************/
const int STOPPINGPLACE_STARTPOS_SET
const int STOPPINGPLACE_ENDPOS_SET
@ GLO_CONTAINER_STOP
a containerStop
@ SUMO_TAG_CONTAINER_STOP
A container stop.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_LINES
@ SUMO_ATTR_LANE
@ GNE_ATTR_BLOCK_MOVEMENT
block movement of a graphic element
@ SUMO_ATTR_ENDPOS
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_NAME
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_ID
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:250
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
const std::string & getID() const
get ID
GNEGeometry::Geometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void drawAdditionalID(const GUIVisualizationSettings &s) const
draw additional ID
void replaceAdditionalParentLanes(const std::string &value)
replace additional parent lanes
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse)
std::string myAdditionalName
name of additional
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
const RGBColor * mySpecialColor
pointer to special color (used for drawing Additional with a certain color, mainly used for selection...
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
std::string getAttribute(SumoXMLAttr key) const
GNEContainerStop(const std::string &id, GNELane *lane, GNENet *net, const double startPos, const double endPos, const int parametersSet, const std::string &name, const std::vector< std::string > &lines, bool friendlyPosition, bool blockMovement)
Constructor.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void updateGeometry()
update pre-computed geometry information
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
~GNEContainerStop()
Destructor.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
const PositionVector & getShape() const
The shape of the additional element.
const std::vector< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
const std::vector< GNELane * > & getParentLanes() const
get parent lanes
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:45
void updateID(GNEAttributeCarrier *AC, const std::string newID)
update ID
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1337
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool myFriendlyPosition
Flag for friendly position.
void drawLines(const GUIVisualizationSettings &s, const std::vector< std::string > &lines, const RGBColor &color) const
draw lines
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
double myEndPosition
The position this stopping place is located at (optional, if empty takes the lane length)
void drawSign(const GUIVisualizationSettings &s, const double exaggeration, const RGBColor &baseColor, const RGBColor &signColor, const std::string &word) const
draw sign
int myParametersSet
Variable used for set/unset start/endPositions.
Position mySignPos
The position of the sign.
double myStartPosition
The relative start position this stopping place is located at (optional, if empty takes 0)
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:491
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
GUIGlID getGlID() const
Returns the numerical id of the object.
GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings
Stores the information about how to visualize structures.
GUIVisualizationDetailSettings detailSettings
detail settings
GUIVisualizationSizeSettings addSize
bool drawDottedContour() const
check if dotted contour can be drawn
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationStoppingPlaceSettings stoppingPlaceSettings
StoppingPlace settings.
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
A list of positions.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
Position getLineCenter() const
get line center
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:145
static bool isStopPosValid(const double startPos, const double endPos, const double laneLength, const double minLength, const bool friendlyPos)
check if start and end position of a stop is valid
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 drawDottedContourShape(const DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double width, const double exaggeration)
draw dotted contour for the given shape (used by additionals)
static void drawGeometry(const GNEViewNet *viewNet, const Geometry &geometry, const double width)
draw geometry
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GNEAttributeCarrier *AC, const GNEGeometry::Geometry &geometry, const double exaggeration, const double offsetx, const double offsety, const bool overlane, const double size=0.5)
draw lock icon
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double stoppingPlaceDetails
details for stopping places
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
static const RGBColor containerStopColorSign
color for containerStop signs
static const double stoppingPlaceSignOffset
busStop offset
static const RGBColor containerStopColor
color for containerStops
static const double containerStopWidth
containerStop width