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-2022 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 
37  GNEStoppingPlace("", net, GLO_CONTAINER_STOP, SUMO_TAG_CONTAINER_STOP, nullptr, 0, 0, "", false, std::map<std::string, std::string>()),
38  myContainerCapacity(0),
39  myParkingLength(0),
40  myColor(RGBColor::BLACK) {
41  // reset default values
43 }
44 
45 
46 GNEContainerStop::GNEContainerStop(const std::string& id, GNELane* lane, GNENet* net, const double startPos, const double endPos,
47  const std::string& name, const std::vector<std::string>& lines, int containerCapacity, double parkingLength, const RGBColor& color,
48  bool friendlyPosition, const std::map<std::string, std::string>& parameters) :
49  GNEStoppingPlace(id, net, GLO_CONTAINER_STOP, SUMO_TAG_CONTAINER_STOP, lane, startPos, endPos, name, friendlyPosition, parameters),
50  myLines(lines),
51  myContainerCapacity(containerCapacity),
52  myParkingLength(parkingLength),
53  myColor(color) {
54  // update centering boundary without updating grid
56 }
57 
58 
60 
61 
62 void
64  device.openTag(getTagProperty().getTag());
65  device.writeAttr(SUMO_ATTR_ID, getID());
66  if (!myAdditionalName.empty()) {
68  }
69  device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
72  }
75  }
76  if (myFriendlyPosition) {
77  device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
78  }
81  }
84  }
87  }
88  if (getAttribute(SUMO_ATTR_COLOR).size() > 0) {
90  }
91  // write parameters (Always after children to avoid problems with additionals.xsd)
92  writeParams(device);
93  device.closeTag();
94 }
95 
96 
97 void
99  // Get value of option "lefthand"
100  const double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
101  // Update common geometry of stopping place
102  setStoppingPlaceGeometry(getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) / 2);
103  // Obtain a copy of the shape
105  // move entire shape and update
106  tmpShape.move2side(2);
108  // Move shape to side
110  // Get position of the sign
111  mySignPos = tmpShape.getLineCenter();
112 }
113 
114 
115 void
117  // Obtain exaggeration of the draw
118  const double containerStopExaggeration = getExaggeration(s);
119  // first check if additional has to be drawn
121  // check exaggeration
122  if (s.drawAdditionals(containerStopExaggeration)) {
123  // declare colors
124  RGBColor baseColor, signColor;
125  // set colors
126  if (mySpecialColor) {
127  baseColor = *mySpecialColor;
128  signColor = baseColor.changedBrightness(-32);
129  } else if (drawUsingSelectColor()) {
131  signColor = baseColor.changedBrightness(-32);
132  } else if (myColor.isValid()) {
133  baseColor = myColor;
135  } else {
136  baseColor = s.colorSettings.containerStopColor;
138  }
139  // draw parent and child lines
141  // Start drawing adding an gl identificator
143  // Add a layer matrix
145  // translate to front
147  // set base color
148  GLHelper::setColor(baseColor);
149  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
151  // draw detail
152  if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, containerStopExaggeration)) {
153  // draw lines
154  drawLines(s, myLines, baseColor);
155  // draw sign
156  drawSign(s, containerStopExaggeration, baseColor, signColor, "C");
157  }
158  // draw geometry points
161  }
162  if (myEndPosition != INVALID_DOUBLE) {
164  }
165  // pop layer matrix
167  // Pop name
169  // draw lock icon
171  // check if dotted contours has to be drawn
174  containerStopExaggeration, 1, 1);
175  }
176  if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
178  containerStopExaggeration, 1, 1);
179  }
180  // draw child demand elements
181  for (const auto& demandElement : getChildDemandElements()) {
182  if (!demandElement->getTagProperty().isPlacedInRTree()) {
183  demandElement->drawGL(s);
184  }
185  }
186  }
187  // Draw additional ID
188  drawAdditionalID(s);
189  // draw additional name
191  }
192 }
193 
194 
195 std::string
197  switch (key) {
198  case SUMO_ATTR_ID:
199  return getID();
200  case SUMO_ATTR_LANE:
201  return getParentLanes().front()->getID();
202  case SUMO_ATTR_STARTPOS:
204  return toString(myStartPosition);
205  } else {
206  return "";
207  }
208  case SUMO_ATTR_ENDPOS:
209  if (myEndPosition != INVALID_DOUBLE) {
210  return toString(myEndPosition);
211  } else {
212  return "";
213  }
214  case SUMO_ATTR_NAME:
215  return myAdditionalName;
218  case SUMO_ATTR_LINES:
219  return joinToString(myLines, " ");
223  return toString(myParkingLength);
224  case SUMO_ATTR_COLOR:
225  if (!myColor.isValid()) {
226  return "";
227  } else {
228  return toString(myColor);
229  }
230  case GNE_ATTR_SELECTED:
232  case GNE_ATTR_PARAMETERS:
233  return getParametersStr();
235  return "";
236  default:
237  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
238  }
239 }
240 
241 
242 void
243 GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
244  switch (key) {
245  case SUMO_ATTR_ID:
246  case SUMO_ATTR_LANE:
247  case SUMO_ATTR_STARTPOS:
248  case SUMO_ATTR_ENDPOS:
249  case SUMO_ATTR_NAME:
251  case SUMO_ATTR_LINES:
254  case SUMO_ATTR_COLOR:
255  case GNE_ATTR_SELECTED:
256  case GNE_ATTR_PARAMETERS:
258  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
259  break;
260  default:
261  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
262  }
263 }
264 
265 
266 bool
267 GNEContainerStop::isValid(SumoXMLAttr key, const std::string& value) {
268  switch (key) {
269  case SUMO_ATTR_ID:
270  return isValidAdditionalID(value);
271  case SUMO_ATTR_LANE:
272  if (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr) {
273  return true;
274  } else {
275  return false;
276  }
277  case SUMO_ATTR_STARTPOS:
278  if (value.empty()) {
279  return true;
280  } else if (canParse<double>(value)) {
281  return SUMORouteHandler::isStopPosValid(parse<double>(value), getAttributeDouble(SUMO_ATTR_ENDPOS), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
282  } else {
283  return false;
284  }
285  case SUMO_ATTR_ENDPOS:
286  if (value.empty()) {
287  return true;
288  } else if (canParse<double>(value)) {
289  return SUMORouteHandler::isStopPosValid(getAttributeDouble(SUMO_ATTR_STARTPOS), parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
290  } else {
291  return false;
292  }
293  case SUMO_ATTR_NAME:
296  return canParse<bool>(value);
297  case SUMO_ATTR_LINES:
298  return canParse<std::vector<std::string> >(value);
300  return canParse<int>(value) && (parse<int>(value) > 0 || parse<int>(value) == -1);
302  return canParse<double>(value) && (parse<double>(value) >= 0);
303  case SUMO_ATTR_COLOR:
304  if (value.empty()) {
305  return true;
306  } else {
307  return canParse<RGBColor>(value);
308  }
309  case GNE_ATTR_SELECTED:
310  return canParse<bool>(value);
311  case GNE_ATTR_PARAMETERS:
312  return Parameterised::areParametersValid(value);
313  default:
314  throw InvalidArgument(getTagStr() + " 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  // update microsimID
327  setMicrosimID(value);
328  // enable save demand elements if there are stops
329  for (const auto& stop : getChildDemandElements()) {
330  if (stop->getTagProperty().isStop() || stop->getTagProperty().isStopPerson()) {
332  }
333  }
334  break;
335  case SUMO_ATTR_LANE:
337  break;
338  case SUMO_ATTR_STARTPOS:
339  if (value == "") {
341  } else {
342  myStartPosition = parse<double>(value);
343  }
344  break;
345  case SUMO_ATTR_ENDPOS:
346  if (value == "") {
348  } else {
349  myEndPosition = parse<double>(value);
350  }
351  break;
352  case SUMO_ATTR_NAME:
353  myAdditionalName = value;
354  break;
356  myFriendlyPosition = parse<bool>(value);
357  break;
358  case SUMO_ATTR_LINES:
359  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
360  break;
362  myContainerCapacity = GNEAttributeCarrier::parse<int>(value);
363  break;
365  myParkingLength = GNEAttributeCarrier::parse<double>(value);
366  break;
367  case SUMO_ATTR_COLOR:
368  if (value.empty()) {
369  myColor.setValid(false);
370  } else {
371  myColor = GNEAttributeCarrier::parse<RGBColor>(value);
372  }
373  break;
374  case GNE_ATTR_SELECTED:
375  if (parse<bool>(value)) {
377  } else {
379  }
380  break;
381  case GNE_ATTR_PARAMETERS:
382  setParametersStr(value);
383  break;
385  shiftLaneIndex();
386  break;
387  default:
388  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
389  }
390 }
391 
392 
393 /****************************************************************************/
@ 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
@ SUMO_ATTR_PARKING_LENGTH
@ SUMO_ATTR_ENDPOS
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_CONTAINER_CAPACITY
@ SUMO_ATTR_NAME
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ GNE_ATTR_SHIFTLANEINDEX
shift lane index (only used by elements over lanes)
const double INVALID_DOUBLE
Definition: StdDefs.h:63
T MIN2(T a, T b)
Definition: StdDefs.h:74
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:269
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:507
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void popName()
pop Name
Definition: GLHelper.cpp:141
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
static void drawRightGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor)
draw right geometry point
const std::string & getID() const
get ID
GUIGeometry 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
void shiftLaneIndex()
shift lane index
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration asociated with this GLObject
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
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
static void drawLeftGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor)
draw left geometry point
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
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
void resetDefaultValues()
reset attribute carrier to their default values
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
int myContainerCapacity
maximum number of container that can wait at this stop
RGBColor myColor
RGB color.
GNEContainerStop(GNENet *net)
default constructor
std::string getAttribute(SumoXMLAttr key) const
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
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.
double myParkingLength
custom space for vehicles that park at this stop
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
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:46
GNELane * retrieveLane(const std::string &id, bool hardFail=true, bool checkVolatileChange=false) const
get lane by id
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:125
void requireSaveDemandElements(bool value)
inform that demand elements has to be saved
Definition: GNENet.cpp:2058
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
virtual double getAttributeDouble(SumoXMLAttr key) const
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 (-1 means empty)
void drawSign(const GUIVisualizationSettings &s, const double exaggeration, const RGBColor &baseColor, const RGBColor &signColor, const std::string &word) const
draw sign
Position mySignPos
The position of the sign.
double myStartPosition
The relative start position this stopping place is located at (-1 means empty)
const std::string & getDefaultValue(SumoXMLAttr attr) const
return the default value of the attribute of an element
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:537
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
static void drawDottedContourShape(const DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double width, const double exaggeration, const bool drawFirstExtrem, const bool drawLastExtrem, const double lineWidth=-1)
draw dotted contour for the given shape (used by additionals)
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
static void drawGeometry(const GUIVisualizationSettings &s, const Position &mousePos, const GUIGeometry &geometry, const double width, double offset=0)
draw geometry
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape)
update entire geometry
Definition: GUIGeometry.cpp:58
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
GUIGlID getGlID() const
Returns the numerical id of the object.
GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings
Position getPositionInformation() const
Returns the cursor's x/y position within the network.
Stores the information about how to visualize structures.
GUIVisualizationDetailSettings detailSettings
detail settings
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...
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
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 storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static bool areParametersValid(const std::string &value, bool report=false, 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"
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
void setValid(const bool value)
set valid
Definition: RGBColor.cpp:114
bool isValid() const
check if RGBColor is valid
Definition: RGBColor.cpp:120
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:197
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 std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position viewPosition, const double exaggeration, const double size=0.5, const double offsetx=0, const double offsety=0)
draw lock icon
static const RGBColor connectionColor
connection color
RGBColor containerStopColor
color for containerStops
RGBColor containerStopColorSign
color for containerStop signs
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double stoppingPlaceDetails
details for stopping places
static const double stoppingPlaceSignOffset
busStop offset
static const double containerStopWidth
containerStop width