Eclipse SUMO - Simulation of Urban MObility
GNEParkingSpace.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 /****************************************************************************/
14 // A lane area vehicles can halt at (GNE version)
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 
21 #include <netedit/GNENet.h>
22 #include <netedit/GNEUndoList.h>
23 #include <netedit/GNEViewNet.h>
25 #include <utils/gui/div/GLHelper.h>
27 
28 #include "GNEParkingSpace.h"
29 
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
34 
35 GNEParkingSpace::GNEParkingSpace(GNEViewNet* viewNet, GNEAdditional* parkingAreaParent, const Position& pos, double width, double length, double angle, bool blockMovement) :
36  GNEAdditional(parkingAreaParent, viewNet, GLO_PARKING_SPACE, SUMO_TAG_PARKING_SPACE, "", blockMovement, {}, {}, {}, {parkingAreaParent}, {}, {}, {}, {}, {}, {}),
37  myPosition(pos),
38  myWidth(width),
39  myLength(length),
40 myAngle(angle) {
41 }
42 
43 
45 
46 
47 void
49  // restore old position, apply offset and update Geometry
51  myPosition.add(offset);
52  // filtern position using snap to active grid
55 }
56 
57 
58 void
60  // commit new position allowing undo/redo
61  undoList->p_begin("position of " + getTagStr());
63  undoList->p_end();
64 }
65 
66 
67 void
69  // Nothing to update
70 }
71 
72 
75  return myPosition;
76 }
77 
78 
81  // Return Boundary depending if myMovingGeometryBoundary is initialised (important for move geometry)
84  } else {
85  // calculate shape using a Position vector as reference
86  PositionVector boundaryShape({
87  {-(myWidth / 2), 0},
88  { (myWidth / 2), 0},
89  { (myWidth / 2), myLength},
90  {-(myWidth / 2), myLength},
91  });
92  // rotate position vector (note: convert from degree to rads
93  boundaryShape.rotate2D(myAngle * PI / 180.0);
94  // move to space position
95  boundaryShape.add(myPosition);
96  // return boundary associated to boundaryShape
97  return boundaryShape.getBoxBoundary().grow(5);
98  }
99 }
100 
101 
102 void
103 GNEParkingSpace::splitEdgeGeometry(const double /*splitPosition*/, const GNENetElement* /*originalElement*/, const GNENetElement* /*newElement*/, GNEUndoList* /*undoList*/) {
104  // geometry of this element cannot be splitted
105 }
106 
107 
108 std::string
110  return getParentAdditionals().at(0)->getMicrosimID();
111 }
112 
113 
114 void
116  // Set initial values
117  const double exaggeration = s.addSize.getExaggeration(s, this);
118  // first check if additional has to be drawn
119  if (s.drawAdditionals(exaggeration)) {
120  // check if boundary has to be drawn
121  if (s.drawBoundaries) {
123  }
124  // push name and matrix
125  glPushName(getGlID());
126  glPushMatrix();
127  // Traslate matrix and draw green contour
128  glTranslated(myPosition.x(), myPosition.y(), getType() + 0.1);
129  glRotated(myAngle, 0, 0, 1);
130  // only drawn small box if isn't being drawn for selecting
131  if (!s.drawForRectangleSelection) {
132  // Set Color depending of selection
133  if (drawUsingSelectColor()) {
135  } else {
137  }
138  GLHelper::drawBoxLine(Position(0, myLength + 0.05), 0, myLength + 0.1, (myWidth / 2) + 0.05);
139  }
140  // Traslate matrix and draw blue innen
141  glTranslated(0, 0, 0.1);
142  // Set Color depending of selection
143  if (drawUsingSelectColor()) {
145  } else {
147  }
149  // Traslate matrix and draw lock icon if isn't being drawn for selecting
150  glTranslated(0, myLength / 2, 0.1);
151  myBlockIcon.drawIcon(s, exaggeration);
152  // pop draw matrix
153  glPopMatrix();
154  // check if dotted contour has to be drawn
155  if (myViewNet->getDottedAC() == this) {
157  }
158  // pop name
159  glPopName();
160  }
161 }
162 
163 
164 std::string
166  switch (key) {
167  case SUMO_ATTR_ID:
168  return getAdditionalID();
169  case SUMO_ATTR_POSITION:
170  return toString(myPosition);
171  case SUMO_ATTR_WIDTH:
172  return toString(myWidth);
173  case SUMO_ATTR_LENGTH:
174  return toString(myLength);
175  case SUMO_ATTR_ANGLE:
176  return toString(myAngle);
178  return toString(myBlockMovement);
179  case GNE_ATTR_PARENT:
180  return getParentAdditionals().at(0)->getID();
181  case GNE_ATTR_SELECTED:
183  case GNE_ATTR_PARAMETERS:
184  return getParametersStr();
185  default:
186  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
187  }
188 }
189 
190 
191 double
193  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
194 }
195 
196 
197 void
198 GNEParkingSpace::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
199  if (value == getAttribute(key)) {
200  return; //avoid needless changes, later logic relies on the fact that attributes have changed
201  }
202  switch (key) {
203  case SUMO_ATTR_ID:
204  case SUMO_ATTR_POSITION:
205  case SUMO_ATTR_WIDTH:
206  case SUMO_ATTR_LENGTH:
207  case SUMO_ATTR_ANGLE:
209  case GNE_ATTR_PARENT:
210  case GNE_ATTR_SELECTED:
211  case GNE_ATTR_PARAMETERS:
212  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
213  break;
214  default:
215  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
216  }
217 }
218 
219 
220 bool
221 GNEParkingSpace::isValid(SumoXMLAttr key, const std::string& value) {
222  switch (key) {
223  case SUMO_ATTR_ID:
224  return isValidAdditionalID(value);
225  case SUMO_ATTR_POSITION:
226  return canParse<Position>(value);
227  case SUMO_ATTR_WIDTH:
228  return canParse<double>(value) && (parse<double>(value) > 0);
229  case SUMO_ATTR_LENGTH:
230  return canParse<double>(value) && (parse<double>(value) > 0);
231  case SUMO_ATTR_ANGLE:
232  return canParse<double>(value);
234  return canParse<bool>(value);
235  case GNE_ATTR_PARENT:
236  return (myViewNet->getNet()->retrieveAdditional(SUMO_TAG_PARKING_AREA, value, false) != nullptr);
237  case GNE_ATTR_SELECTED:
238  return canParse<bool>(value);
239  case GNE_ATTR_PARAMETERS:
240  return Parameterised::areParametersValid(value);
241  default:
242  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
243  }
244 }
245 
246 
247 bool
249  return true;
250 }
251 
252 
253 std::string
255  return getTagStr();
256 }
257 
258 
259 std::string
261  return getTagStr() + ": " + getAttribute(SUMO_ATTR_POSITION);
262 }
263 
264 // ===========================================================================
265 // private
266 // ===========================================================================
267 
268 void
269 GNEParkingSpace::setAttribute(SumoXMLAttr key, const std::string& value) {
270  switch (key) {
271  case SUMO_ATTR_ID:
272  changeAdditionalID(value);
273  break;
274  case SUMO_ATTR_POSITION:
276  myPosition = parse<Position>(value);
278  break;
279  case SUMO_ATTR_WIDTH:
281  myWidth = parse<double>(value);
283  break;
284  case SUMO_ATTR_LENGTH:
286  myLength = parse<double>(value);
288  break;
289  case SUMO_ATTR_ANGLE:
291  myAngle = parse<double>(value);
293  break;
295  myBlockMovement = parse<bool>(value);
296  break;
297  case GNE_ATTR_PARENT:
298  replaceParentAdditional(this, value, 0);
299  break;
300  case GNE_ATTR_SELECTED:
301  if (parse<bool>(value)) {
303  } else {
305  }
306  break;
307  case GNE_ATTR_PARAMETERS:
308  setParametersStr(value);
309  break;
310  default:
311  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
312  }
313 }
314 
315 
316 /****************************************************************************/
GUIGlObject::getType
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.cpp:180
GNEParkingSpace::myPosition
Position myPosition
position of Parking Space in view
Definition: GNEParkingSpace.h:135
GNEParkingSpace::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEParkingSpace.cpp:74
SUMO_ATTR_ANGLE
@ SUMO_ATTR_ANGLE
Definition: SUMOXMLDefinitions.h:794
GNENet::retrieveAdditional
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:2183
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
Parameterised::getParametersStr
std::string getParametersStr() const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
Definition: Parameterised.cpp:112
GNEParkingSpace::splitEdgeGeometry
void splitEdgeGeometry(const double splitPosition, const GNENetElement *originalElement, const GNENetElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNEParkingSpace.cpp:103
GNEParkingSpace::~GNEParkingSpace
~GNEParkingSpace()
Destructor.
Definition: GNEParkingSpace.cpp:44
GNEAdditional::getAdditionalID
const std::string & getAdditionalID() const
Definition: GNEAdditional.cpp:476
SUMO_ATTR_LENGTH
@ SUMO_ATTR_LENGTH
Definition: SUMOXMLDefinitions.h:393
GNEAdditional::AdditionalMove::movingGeometryBoundary
Boundary movingGeometryBoundary
boundary used during moving of elements (to avoid insertion in RTREE
Definition: GNEAdditional.h:288
GNEUndoList::p_end
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
Definition: GNEUndoList.cpp:79
GUIVisualizationSettings::drawForRectangleSelection
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
Definition: GUIVisualizationSettings.h:647
GUIVisualizationSettings::drawBoundaries
bool drawBoundaries
enable or disable draw boundaries
Definition: GUIVisualizationSettings.h:638
GNENet::removeGLObjectFromGrid
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1328
PositionVector::rotate2D
void rotate2D(double angle)
Definition: PositionVector.cpp:1503
GNEParkingSpace::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNEParkingSpace.cpp:59
GNEParkingSpace::GNEParkingSpace
GNEParkingSpace(GNEViewNet *viewNet, GNEAdditional *parkingAreaParent, const Position &pos, double width, double length, double angle, bool blockMovement)
Constructor.
Definition: GNEParkingSpace.cpp:35
GNEViewNet
Definition: GNEViewNet.h:42
SUMO_ATTR_ID
@ SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
GLHelper.h
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:502
PositionVector
A list of positions.
Definition: PositionVector.h:45
SUMO_TAG_PARKING_SPACE
@ SUMO_TAG_PARKING_SPACE
A parking space for a single vehicle within a parking area.
Definition: SUMOXMLDefinitions.h:109
GNEAdditional::unselectAttributeCarrier
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Definition: GNEAdditional.cpp:532
GNEAdditional::myBlockIcon
BlockIcon myBlockIcon
variable BlockIcon
Definition: GNEAdditional.h:353
GNEParkingSpace::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEParkingSpace.cpp:254
GLHelper::setColor
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:621
GUISUMOAbstractView::snapToActiveGrid
Position snapToActiveGrid(const Position &pos, bool snapXY=true) const
Returns a position that is mapped to the closest grid point if the grid is active.
Definition: GUISUMOAbstractView.cpp:196
GNEAdditional::myMove
AdditionalMove myMove
variable AdditionalMove
Definition: GNEAdditional.h:344
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:335
GLHelper::drawBoundary
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:817
GLO_PARKING_SPACE
@ GLO_PARKING_SPACE
a ParkingSpace
Definition: GUIGlObjectTypes.h:69
GNEAttributeCarrier::GNEChange_Attribute
friend class GNEChange_Attribute
declare friend class
Definition: GNEAttributeCarrier.h:57
GNEUndoList::p_add
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Definition: GNEUndoList.cpp:131
GNEViewNet::getNet
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:1014
GNEHierarchicalParentElements::getParentAdditionals
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
Definition: GNEHierarchicalParentElements.cpp:85
GNEAdditional::isAttributeCarrierSelected
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
Definition: GNEAdditional.cpp:548
GUIVisualizationColorSettings::selectedAdditionalColor
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
Definition: GUIVisualizationSettings.h:147
GNEParkingSpace::myWidth
double myWidth
width of Parking Space
Definition: GNEParkingSpace.h:138
GNEParkingSpace.h
GNEAdditional::selectAttributeCarrier
void selectAttributeCarrier(bool changeFlag=true)
Definition: GNEAdditional.cpp:517
GNEViewNet.h
SUMO_ATTR_WIDTH
@ SUMO_ATTR_WIDTH
Definition: SUMOXMLDefinitions.h:386
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:149
GNEViewNet::getDottedAC
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
Definition: GNEViewNet.cpp:1026
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
SUMO_TAG_PARKING_AREA
@ SUMO_TAG_PARKING_AREA
A parking area.
Definition: SUMOXMLDefinitions.h:107
GNEParkingSpace::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNEParkingSpace.cpp:68
GNE_ATTR_PARAMETERS
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
Definition: SUMOXMLDefinitions.h:989
GLHelper::drawShapeDottedContourRectangle
static void drawShapeDottedContourRectangle(const GUIVisualizationSettings &s, const int type, const Position &center, const double width, const double height, const double rotation=0, const double offsetX=0, const double offsetY=0)
draw a dotted contour around the given Position with certain width and height
Definition: GLHelper.cpp:560
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
Position::x
double x() const
Returns the x-position.
Definition: Position.h:56
GNEParkingSpace::myLength
double myLength
Length of Parking Space.
Definition: GNEParkingSpace.h:141
GNENetElement
Definition: GNENetElement.h:43
GNEAdditional::myBlockMovement
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse)
Definition: GNEAdditional.h:350
GNEHierarchicalParentElements::replaceParentAdditional
void replaceParentAdditional(GNEShape *shapeTobeChanged, const std::string &newParentAdditionalID, int additionalParentIndex)
replace the parent additional of a shape
Definition: GNEHierarchicalParentElements.cpp:489
GNEParkingSpace::setAttribute
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
Definition: GNEParkingSpace.cpp:198
SUMO_ATTR_POSITION
@ SUMO_ATTR_POSITION
Definition: SUMOXMLDefinitions.h:660
GUIVisualizationSettings::colorSettings
GUIVisualizationColorSettings colorSettings
color settings
Definition: GUIVisualizationSettings.h:677
Parameterised::setParametersStr
void setParametersStr(const std::string &paramsString)
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
Definition: Parameterised.cpp:139
GLIncludes.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
GNEAdditional::BlockIcon::drawIcon
void drawIcon(const GUIVisualizationSettings &s, const double exaggeration, const double size=0.5) const
draw lock icon
Definition: GNEAdditional.cpp:416
GNENet::addGLObjectIntoGrid
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1322
Position::y
double y() const
Returns the y-position.
Definition: Position.h:61
Parameterised::areParametersValid
static bool areParametersValid(const std::string &value, bool report=false)
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
Definition: Parameterised.cpp:166
InvalidArgument
Definition: UtilExceptions.h:56
GLHelper::drawBoxLine
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:136
GNE_ATTR_BLOCK_MOVEMENT
@ GNE_ATTR_BLOCK_MOVEMENT
block movement of a graphic element
Definition: SUMOXMLDefinitions.h:981
GNEParkingSpace::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEParkingSpace.cpp:115
GUIVisualizationSettings::drawAdditionals
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
Definition: GUIVisualizationSettings.cpp:1663
GNEAdditional::drawUsingSelectColor
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
Definition: GNEAdditional.cpp:554
GNEParkingSpace::myAngle
double myAngle
Angle of Parking Space.
Definition: GNEParkingSpace.h:144
GNEParkingSpace::getAttribute
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEParkingSpace.cpp:165
GUIVisualizationColorSettings::parkingSpaceInnen
static const RGBColor parkingSpaceInnen
color for parkingArea innen
Definition: GUIVisualizationSettings.h:204
GNEParkingSpace::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEParkingSpace.cpp:80
GUIVisualizationSettings::addSize
GUIVisualizationSizeSettings addSize
Definition: GUIVisualizationSettings.h:589
GNEParkingSpace::getParentName
std::string getParentName() const
Returns the name of the parent object (if any)
Definition: GNEParkingSpace.cpp:109
GNEParkingSpace::isAttributeEnabled
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNEParkingSpace.cpp:248
Position::add
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:126
Boundary::isInitialised
bool isInitialised() const
check if Boundary is Initialised
Definition: Boundary.cpp:216
GNE_ATTR_SELECTED
@ GNE_ATTR_SELECTED
element is selected
Definition: SUMOXMLDefinitions.h:971
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1267
GNEUndoList
Definition: GNEUndoList.h:48
GUIVisualizationColorSettings::parkingSpace
static const RGBColor parkingSpace
color for parkingArea sign
Definition: GUIVisualizationSettings.h:201
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:345
GNEAdditional::isValidAdditionalID
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Definition: GNEAdditional.cpp:482
GNEUndoList::p_begin
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:72
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:372
GNEAdditional::AdditionalMove::originalViewPosition
Position originalViewPosition
value for saving first original position over lane before moving
Definition: GNEAdditional.h:291
GNEParkingSpace::getAttributeDouble
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNEParkingSpace.cpp:192
GNEParkingSpace::isValid
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEParkingSpace.cpp:221
GNEParkingSpace::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEParkingSpace.cpp:48
GNEChange_Attribute.h
GNENet.h
GNEParkingSpace::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEParkingSpace.cpp:260
GUIVisualizationSizeSettings::getExaggeration
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
Definition: GUIVisualizationSettings.cpp:212
GNEUndoList.h
GNE_ATTR_PARENT
@ GNE_ATTR_PARENT
parent of an additional element
Definition: SUMOXMLDefinitions.h:987