Eclipse SUMO - Simulation of Urban MObility
GNEParkingArea.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 park at (GNE version)
19 /****************************************************************************/
20 #include <netedit/GNENet.h>
21 #include <netedit/GNEUndoList.h>
22 #include <netedit/GNEViewNet.h>
24 #include <utils/gui/div/GLHelper.h>
28 
29 #include "GNEParkingArea.h"
30 
31 
32 // ===========================================================================
33 // method definitions
34 // ===========================================================================
35 
36 GNEParkingArea::GNEParkingArea(const std::string& id, GNELane* lane, GNENet* net, const double startPos, const double endPos, const int parametersSet,
37  const std::string& name, bool friendlyPosition, int roadSideCapacity, bool onRoad, double width, const std::string& length, double angle, bool blockMovement) :
38  GNEStoppingPlace(id, net, GLO_PARKING_AREA, SUMO_TAG_PARKING_AREA, lane, startPos, endPos, parametersSet, name, friendlyPosition, blockMovement),
39  myRoadSideCapacity(roadSideCapacity),
40  myOnRoad(onRoad),
41  myWidth(width),
42  myLength(length),
43  myAngle(angle) {
44  // update centering boundary without updating grid
46 }
47 
48 
50 
51 
52 void
54  // Get value of option "lefthand"
55  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
56 
57  // Update common geometry of stopping place
58  setStoppingPlaceGeometry(getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) / 2 + myWidth);
59 
60  // Obtain a copy of the shape
62 
63  // Move shape to side
64  tmpShape.move2side(1.5 * offsetSign);
65 
66  // Get position of the sign
67  mySignPos = tmpShape.getLineCenter();
68 }
69 
70 
71 void
73  // Obtain exaggeration of the draw
74  const double parkingAreaExaggeration = s.addSize.getExaggeration(s, this);
75  // first check if additional has to be drawn
76  if (s.drawAdditionals(parkingAreaExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
77  // check if boundary has to be drawn
78  if (s.drawBoundaries) {
80  }
81  // declare colors
82  RGBColor baseColor, signColor;
83  // set colors
84  if (mySpecialColor) {
85  baseColor = *mySpecialColor;
86  signColor = baseColor.changedBrightness(-32);
87  } else if (drawUsingSelectColor()) {
89  signColor = baseColor.changedBrightness(-32);
90  } else {
93  }
94  // Start drawing adding an gl identificator
95  glPushName(getGlID());
96  // Add a draw matrix
97  glPushMatrix();
98  // translate to front
100  // set base color
101  GLHelper::setColor(baseColor);
102  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
104  // draw detail
105  if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, parkingAreaExaggeration)) {
106  // draw sign
107  drawSign(s, parkingAreaExaggeration, baseColor, signColor, "P");
108  // draw lock icon
109  GNEViewNetHelper::LockIcon::drawLockIcon(this, myAdditionalGeometry, parkingAreaExaggeration, 0, 0, true);
110  }
111  // pop draw matrix
112  glPopMatrix();
113  // Pop name
114  glPopName();
115  // Draw additional ID
116  drawAdditionalID(s);
117  // draw additional name
119  // check if dotted contours has to be drawn
122  }
123  if (s.drawDottedContour() || myNet->getViewNet()->getFrontAttributeCarrier() == this) {
125  }
126  // draw child spaces
127  for (const auto& parkingSpace : getChildAdditionals()) {
128  parkingSpace->drawGL(s);
129  }
130  // draw child demand elements
131  for (const auto& demandElement : getChildDemandElements()) {
132  if (!demandElement->getTagProperty().isPlacedInRTree()) {
133  demandElement->drawGL(s);
134  }
135  }
136  }
137 }
138 
139 
140 std::string
142  switch (key) {
143  case SUMO_ATTR_ID:
144  return getID();
145  case SUMO_ATTR_LANE:
146  return getParentLanes().front()->getID();
147  case SUMO_ATTR_STARTPOS:
149  return toString(myStartPosition);
150  } else {
151  return "";
152  }
153  case SUMO_ATTR_ENDPOS:
155  return toString(myEndPosition);
156  } else {
157  return "";
158  }
159  case SUMO_ATTR_NAME:
160  return myAdditionalName;
165  case SUMO_ATTR_ONROAD:
166  return toString(myOnRoad);
167  case SUMO_ATTR_WIDTH:
168  return toString(myWidth);
169  case SUMO_ATTR_LENGTH:
170  return myLength;
171  case SUMO_ATTR_ANGLE:
172  return toString(myAngle);
174  return toString(myBlockMovement);
175  case GNE_ATTR_SELECTED:
177  case GNE_ATTR_PARAMETERS:
178  return getParametersStr();
179  default:
180  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
181  }
182 }
183 
184 
185 void
186 GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
187  if (value == getAttribute(key)) {
188  return; //avoid needless changes, later logic relies on the fact that attributes have changed
189  }
190  switch (key) {
191  case SUMO_ATTR_ID:
192  case SUMO_ATTR_LANE:
193  case SUMO_ATTR_STARTPOS:
194  case SUMO_ATTR_ENDPOS:
195  case SUMO_ATTR_NAME:
198  case SUMO_ATTR_ONROAD:
199  case SUMO_ATTR_WIDTH:
200  case SUMO_ATTR_LENGTH:
201  case SUMO_ATTR_ANGLE:
203  case GNE_ATTR_SELECTED:
204  case GNE_ATTR_PARAMETERS:
205  undoList->p_add(new GNEChange_Attribute(this, key, value));
206  break;
207  default:
208  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
209  }
210 }
211 
212 
213 bool
214 GNEParkingArea::isValid(SumoXMLAttr key, const std::string& value) {
215  switch (key) {
216  case SUMO_ATTR_ID:
217  return isValidAdditionalID(value);
218  case SUMO_ATTR_LANE:
219  if (myNet->retrieveLane(value, false) != nullptr) {
220  return true;
221  } else {
222  return false;
223  }
224  case SUMO_ATTR_STARTPOS:
225  if (value.empty()) {
226  return true;
227  } else if (canParse<double>(value)) {
228  return SUMORouteHandler::isStopPosValid(parse<double>(value), myEndPosition, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
229  } else {
230  return false;
231  }
232  case SUMO_ATTR_ENDPOS:
233  if (value.empty()) {
234  return true;
235  } else if (canParse<double>(value)) {
236  return SUMORouteHandler::isStopPosValid(myStartPosition, parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
237  } else {
238  return false;
239  }
240  case SUMO_ATTR_NAME:
243  return canParse<bool>(value);
245  return canParse<double>(value) && (parse<double>(value) >= 0);
246  case SUMO_ATTR_ONROAD:
247  return canParse<bool>(value);
248  case SUMO_ATTR_WIDTH:
249  return canParse<double>(value) && (parse<double>(value) > 0);
250  case SUMO_ATTR_LENGTH:
251  if (value.empty()) {
252  return true;
253  } else {
254  return canParse<double>(value) && (parse<double>(value) > 0);
255  }
256  case SUMO_ATTR_ANGLE:
257  return canParse<double>(value);
259  return canParse<bool>(value);
260  case GNE_ATTR_SELECTED:
261  return canParse<bool>(value);
262  case GNE_ATTR_PARAMETERS:
263  return Parameterised::areParametersValid(value);
264  default:
265  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
266  }
267 }
268 
269 // ===========================================================================
270 // private
271 // ===========================================================================
272 
273 void
274 GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value) {
275  switch (key) {
276  case SUMO_ATTR_ID:
277  myNet->getAttributeCarriers()->updateID(this, value);
278  // Change IDs of all parking Spaces
279  for (const auto& parkingSpace : getChildAdditionals()) {
280  parkingSpace->setMicrosimID(getID());
281  }
282  break;
283  case SUMO_ATTR_LANE:
285  break;
286  case SUMO_ATTR_STARTPOS:
287  if (!value.empty()) {
288  myStartPosition = parse<double>(value);
290  } else {
292  }
293  // update boundary
295  break;
296  case SUMO_ATTR_ENDPOS:
297  if (!value.empty()) {
298  myEndPosition = parse<double>(value);
300  } else {
302  }
303  // update boundary
305  break;
306  case SUMO_ATTR_NAME:
307  myAdditionalName = value;
308  break;
310  myFriendlyPosition = parse<bool>(value);
311  break;
313  myRoadSideCapacity = parse<int>(value);
314  break;
315  case SUMO_ATTR_ONROAD:
316  myOnRoad = parse<bool>(value);
317  break;
318  case SUMO_ATTR_WIDTH:
319  myWidth = parse<double>(value);
320  // update boundary
322  break;
323  case SUMO_ATTR_LENGTH:
324  myLength = value;
325  break;
326  case SUMO_ATTR_ANGLE:
327  myAngle = parse<double>(value);
328  break;
330  myBlockMovement = parse<bool>(value);
331  break;
332  case GNE_ATTR_SELECTED:
333  if (parse<bool>(value)) {
335  } else {
337  }
338  break;
339  case GNE_ATTR_PARAMETERS:
340  setParametersStr(value);
341  break;
342  default:
343  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
344  }
345 }
346 
347 
348 /****************************************************************************/
const int STOPPINGPLACE_STARTPOS_SET
const int STOPPINGPLACE_ENDPOS_SET
@ GLO_PARKING_AREA
a ParkingArea
@ SUMO_TAG_PARKING_AREA
A parking area.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_STARTPOS
@ 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_ANGLE
@ SUMO_ATTR_ROADSIDE_CAPACITY
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_ONROAD
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_ID
@ SUMO_ATTR_WIDTH
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:647
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
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
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
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
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
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
std::string getAttribute(SumoXMLAttr key) const
std::string myLength
Length of Parking Area (by default (endPos - startPos) / roadsideCapacity.
~GNEParkingArea()
Destructor.
double myAngle
Angle of Parking Area.
double myWidth
width of Parking Area
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
bool myOnRoad
Whether vehicles stay on the road.
GNEParkingArea(const std::string &id, GNELane *lane, GNENet *net, const double startPos, const double endPos, const int parametersSet, const std::string &name, bool friendlyPosition, int roadSideCapacity, bool onRoad, double width, const std::string &length, double angle, 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
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
int myRoadSideCapacity
roadside capacity of Parking Area
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool myFriendlyPosition
Flag for friendly position.
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.
Stores the information about how to visualize structures.
bool drawBoundaries
enable or disable draw boundaries
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 parkingAreaColorSign
color for parkingArea sign
static const RGBColor parkingAreaColor
color for parkingAreas