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-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 park at (GNE version)
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
29 #include <utils/gui/div/GLHelper.h>
32 
33 #include "GNEParkingArea.h"
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 
40 GNEParkingArea::GNEParkingArea(const std::string& id, GNELane* lane, GNEViewNet* viewNet, const std::string& startPos, const std::string& endPos, const std::string& name,
41  bool friendlyPosition, int roadSideCapacity, bool onRoad, double width, const std::string& length, double angle, bool blockMovement) :
42  GNEStoppingPlace(id, viewNet, GLO_PARKING_AREA, SUMO_TAG_PARKING_AREA, lane, startPos, endPos, name, friendlyPosition, blockMovement),
43  myRoadSideCapacity(roadSideCapacity),
44  myOnRoad(onRoad),
45  myWidth(width),
46  myLength(length),
47  myAngle(angle) {
48 }
49 
50 
52 
53 
54 void
56  // first check if object has to be removed from grid (SUMOTree)
59  }
60 
61  // Get value of option "lefthand"
62  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
63 
64  // Update common geometry of stopping place
65  setStoppingPlaceGeometry(getLaneParents().front()->getParentEdge().getNBEdge()->getLaneWidth(getLaneParents().front()->getIndex()) / 2 + myWidth);
66 
67  // Obtain a copy of the shape
68  PositionVector tmpShape = myGeometry.shape;
69 
70  // Move shape to side
71  tmpShape.move2side(1.5 * offsetSign);
72 
73  // Get position of the sign
74  mySignPos = tmpShape.getLineCenter();
75 
76  // Set block icon position
78 
79  // Set block icon rotation, and using their rotation for sign
81 
82  // last step is to check if object has to be added into grid (SUMOTree) again
85  }
86 }
87 
88 
91  // Return Boundary depending if myMovingGeometryBoundary is initialised (important for move geometry)
94  } else if (myGeometry.shape.size() > 0) {
96  b.grow(myWidth + 1);
97  return b;
98  } else {
99  return Boundary(-0.1, -0.1, 0.1, 0.1);
100  }
101 }
102 
103 
104 void
106  // check if boundary has to be drawn
107  if (s.drawBoundaries) {
109  }
110  // Obtain exaggeration of the draw
111  const double exaggeration = s.addSize.getExaggeration(s, this);
112  // Push name
113  glPushName(getGlID());
114  // Push base matrix
115  glPushMatrix();
116  // Traslate matrix
117  glTranslated(0, 0, getType());
118  // Set Color
119  if (drawUsingSelectColor()) {
121  } else {
123  }
124  // Draw base
126  // Check if the distance is enought to draw details and if is being drawn for selecting
127  if (s.drawForSelecting) {
128  // only draw circle depending of distance between sign and mouse cursor
130  // Add a draw matrix for details
131  glPushMatrix();
132  // Start drawing sign traslating matrix to signal position
133  glTranslated(mySignPos.x(), mySignPos.y(), 0);
134  // scale matrix depending of the exaggeration
135  glScaled(exaggeration, exaggeration, 1);
136  // set color
138  // Draw circle
140  // pop draw matrix
141  glPopMatrix();
142  }
143  } else if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, exaggeration)) {
144  // Push matrix for details
145  glPushMatrix();
146  // Set position over sign
147  glTranslated(mySignPos.x(), mySignPos.y(), 0);
148  // Scale matrix
149  glScaled(exaggeration, exaggeration, 1);
150  // Set base color
151  if (drawUsingSelectColor()) {
153  } else {
155  }
156  // Draw extern
158  // Move to top
159  glTranslated(0, 0, .1);
160  // Set sign color
161  if (drawUsingSelectColor()) {
163  } else {
165  }
166  // Draw internt sign
168  // Draw sign 'C'
169  if (s.drawDetail(s.detailSettings.stoppingPlaceText, exaggeration)) {
170  if (drawUsingSelectColor()) {
172  } else {
174  }
175  }
176  // Pop sign matrix
177  glPopMatrix();
178  // Draw icon
179  myBlockIcon.drawIcon(s, exaggeration);
180  }
181  // Pop base matrix
182  glPopMatrix();
183  // Draw name if isn't being drawn for selecting
185  if (s.addFullName.show && (myAdditionalName != "") && !s.drawForSelecting) {
187  }
188  // check if dotted contour has to be drawn
189  if (myViewNet->getDottedAC() == this) {
191  }
192  // Pop name matrix
193  glPopName();
194  // draw demand element children
195  for (const auto& i : getDemandElementChildren()) {
196  if (!i->getTagProperty().isPlacedInRTree()) {
197  i->drawGL(s);
198  }
199  }
200 }
201 
202 
203 std::string
205  switch (key) {
206  case SUMO_ATTR_ID:
207  return getAdditionalID();
208  case SUMO_ATTR_LANE:
209  return getLaneParents().front()->getID();
210  case SUMO_ATTR_STARTPOS:
211  return toString(myStartPosition);
212  case SUMO_ATTR_ENDPOS:
213  return myEndPosition;
214  case SUMO_ATTR_NAME:
215  return myAdditionalName;
220  case SUMO_ATTR_ONROAD:
221  return toString(myOnRoad);
222  case SUMO_ATTR_WIDTH:
223  return toString(myWidth);
224  case SUMO_ATTR_LENGTH:
225  return myLength;
226  case SUMO_ATTR_ANGLE:
227  return toString(myAngle);
229  return toString(myBlockMovement);
230  case GNE_ATTR_SELECTED:
232  case GNE_ATTR_GENERIC:
233  return getGenericParametersStr();
234  default:
235  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
236  }
237 }
238 
239 
240 void
241 GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
242  if (value == getAttribute(key)) {
243  return; //avoid needless changes, later logic relies on the fact that attributes have changed
244  }
245  switch (key) {
246  case SUMO_ATTR_ID: {
247  // change ID of Entry
248  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
249  // Change Ids of all Parking Spaces
250  for (auto i : getAdditionalChildren()) {
251  i->setAttribute(SUMO_ATTR_ID, generateChildID(SUMO_TAG_PARKING_SPACE), undoList);
252  }
253  break;
254  }
255  case SUMO_ATTR_LANE:
256  case SUMO_ATTR_STARTPOS:
257  case SUMO_ATTR_ENDPOS:
258  case SUMO_ATTR_NAME:
261  case SUMO_ATTR_ONROAD:
262  case SUMO_ATTR_WIDTH:
263  case SUMO_ATTR_LENGTH:
264  case SUMO_ATTR_ANGLE:
266  case GNE_ATTR_SELECTED:
267  case GNE_ATTR_GENERIC:
268  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
269  break;
270  default:
271  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
272  }
273 }
274 
275 
276 bool
277 GNEParkingArea::isValid(SumoXMLAttr key, const std::string& value) {
278  switch (key) {
279  case SUMO_ATTR_ID:
280  return isValidAdditionalID(value);
281  case SUMO_ATTR_LANE:
282  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
283  return true;
284  } else {
285  return false;
286  }
287  case SUMO_ATTR_STARTPOS:
288  if (value.empty()) {
289  return true;
290  } else if (canParse<double>(value)) {
291  return checkStoppinPlacePosition(value, myEndPosition, getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength(), myFriendlyPosition);
292  } else {
293  return false;
294  }
295  case SUMO_ATTR_ENDPOS:
296  if (value.empty()) {
297  return true;
298  } else if (canParse<double>(value)) {
299  return checkStoppinPlacePosition(myStartPosition, value, getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength(), myFriendlyPosition);
300  } else {
301  return false;
302  }
303  case SUMO_ATTR_NAME:
306  return canParse<bool>(value);
308  return canParse<double>(value) && (parse<double>(value) >= 0);
309  case SUMO_ATTR_ONROAD:
310  return canParse<bool>(value);
311  case SUMO_ATTR_WIDTH:
312  return canParse<double>(value) && (parse<double>(value) > 0);
313  case SUMO_ATTR_LENGTH:
314  if (value.empty()) {
315  return true;
316  } else {
317  return canParse<double>(value) && (parse<double>(value) > 0);
318  }
319  case SUMO_ATTR_ANGLE:
320  return canParse<double>(value);
322  return canParse<bool>(value);
323  case GNE_ATTR_SELECTED:
324  return canParse<bool>(value);
325  case GNE_ATTR_GENERIC:
326  return isGenericParametersValid(value);
327  default:
328  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
329  }
330 }
331 
332 // ===========================================================================
333 // private
334 // ===========================================================================
335 
336 void
337 GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value) {
338  switch (key) {
339  case SUMO_ATTR_ID:
340  changeAdditionalID(value);
341  break;
342  case SUMO_ATTR_LANE:
343  changeLaneParents(this, value);
344  break;
345  case SUMO_ATTR_STARTPOS:
347  myStartPosition = value;
349  break;
350  case SUMO_ATTR_ENDPOS:
352  myEndPosition = value;
354  break;
355  case SUMO_ATTR_NAME:
356  myAdditionalName = value;
357  break;
359  myFriendlyPosition = parse<bool>(value);
360  break;
362  myRoadSideCapacity = parse<int>(value);
363  break;
364  case SUMO_ATTR_ONROAD:
365  myOnRoad = parse<bool>(value);
366  break;
367  case SUMO_ATTR_WIDTH:
369  myWidth = parse<double>(value);
371  break;
372  case SUMO_ATTR_LENGTH:
373  myLength = value;
374  break;
375  case SUMO_ATTR_ANGLE:
376  myAngle = parse<double>(value);
377  break;
379  myBlockMovement = parse<bool>(value);
380  break;
381  case GNE_ATTR_SELECTED:
382  if (parse<bool>(value)) {
384  } else {
386  }
387  break;
388  case GNE_ATTR_GENERIC:
390  break;
391  default:
392  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
393  }
394 }
395 
396 
397 /****************************************************************************/
double myAngle
Angle of Parking Area.
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
std::string generateChildID(SumoXMLTag childTag)
gererate a new ID for an element child
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
~GNEParkingArea()
Destructor.
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: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
std::string getAttribute(SumoXMLAttr key) const
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
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)
A parking space for a single vehicle within a parking area.
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
const std::vector< GNEAdditional * > & getAdditionalChildren() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
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.
int myRoadSideCapacity
roadside capacity of Parking Area
AdditionalMove myMove
variable AdditionalMove
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:812
int getCircleResolution() const
function to calculate circle resolution for all circles drawn in drawGL(...) functions ...
GUIVisualizationSizeSettings addSize
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
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
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
RGBColor selectionColor
basic selection color
A list of positions.
double scaledSize(double scale, double constFactor=0.1) const
get scale size
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:1279
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
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
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 const RGBColor parkingAreaSign
color for parkingArea sign
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
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string myLength
Lenght of Parking Area (by default (endPos - startPos) / roadsideCapacity.
GUIVisualizationDetailSettings detailSettings
detail settings
void changeLaneParents(GNEShape *elementChild, const std::string &newLaneIDs)
change edge parents of a shape
void updateGeometry()
update pre-computed geometry information
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
GUIVisualizationTextSettings addFullName
AdditionalGeometry myGeometry
geometry to be precomputed in updateGeometry(...)
static const RGBColor parkingArea
color for parkingAreas
const std::string & getTagStr() const
get tag assigned to this object in string format
Boundary movingGeometryBoundary
boundary used during moving of elements (to avoid insertion in RTREE
element is selected
bool isInitialised() const
check if Boundary is Initialised
Definition: Boundary.cpp:217
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
a ParkingArea
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) ...
empty max
Position mySignPos
The position of the sign.
static const RGBColor busStop
color for busStops
double myWidth
width of Parking Area
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
bool myOnRoad
Whether vehicles stay on the road.
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1273
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1179
bool drawBoundaries
enable or disable draw boundaries
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry() function)
GNEParkingArea(const std::string &id, GNELane *lane, GNEViewNet *viewNet, const std::string &startPos, const std::string &endPos, const std::string &name, bool friendlyPosition, int roadSideCapacity, bool onRoad, double width, const std::string &length, double angle, bool blockMovement)
Constructor.