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 /****************************************************************************/
15 // A lane area vehicles can halt 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>
26 #include <utils/gui/div/GLHelper.h>
28 
29 #include "GNEParkingSpace.h"
30 
31 
32 // ===========================================================================
33 // method definitions
34 // ===========================================================================
35 
36 GNEParkingSpace::GNEParkingSpace(GNEViewNet* viewNet, GNEAdditional* parkingAreaParent, const Position& pos, double width, double length, double angle, bool blockMovement) :
37  GNEAdditional(parkingAreaParent, viewNet, GLO_PARKING_SPACE, SUMO_TAG_PARKING_SPACE, "", blockMovement,
38 {}, {}, {}, {parkingAreaParent}, {}, {}, {}, {}, {}, {}),
39 myPosition(pos),
40 myWidth(width),
41 myLength(length),
42 myAngle(angle) {
43 }
44 
45 
47 
48 
49 void
51  // restore old position, apply offset and update Geometry
53  myPosition.add(offset);
54  // filtern position using snap to active grid
57 }
58 
59 
60 void
62  // commit new position allowing undo/redo
63  undoList->p_begin("position of " + getTagStr());
65  undoList->p_end();
66 }
67 
68 
69 void
71  // Nothing to update
72 }
73 
74 
77  return myPosition;
78 }
79 
80 
83  // Return Boundary depending if myMovingGeometryBoundary is initialised (important for move geometry)
86  } else {
87  // calculate shape using a Position vector as reference
88  PositionVector boundaryShape({
89  {-(myWidth / 2), 0},
90  { (myWidth / 2), 0},
91  { (myWidth / 2), myLength},
92  {-(myWidth / 2), myLength},
93  });
94  // rotate position vector (note: convert from degree to rads
95  boundaryShape.rotate2D(myAngle * PI / 180.0);
96  // move to space position
97  boundaryShape.add(myPosition);
98  // return boundary associated to boundaryShape
99  return boundaryShape.getBoxBoundary().grow(5);
100  }
101 }
102 
103 
104 std::string
106  return getAdditionalParents().at(0)->getMicrosimID();
107 }
108 
109 
110 void
112  // Set initial values
113  const double exaggeration = s.addSize.getExaggeration(s, this);
114  // check if boundary has to be drawn
115  if (s.drawBoundaries) {
117  }
118  // push name and matrix
119  glPushName(getGlID());
120  glPushMatrix();
121  // Traslate matrix and draw green contour
122  glTranslated(myPosition.x(), myPosition.y(), getType() + 0.1);
123  glRotated(myAngle, 0, 0, 1);
124  // only drawn small box if isn't being drawn for selecting
125  if (!s.drawForSelecting) {
126  // Set Color depending of selection
127  if (drawUsingSelectColor()) {
129  } else {
131  }
132  GLHelper::drawBoxLine(Position(0, myLength + 0.05), 0, myLength + 0.1, (myWidth / 2) + 0.05);
133  }
134  // Traslate matrix and draw blue innen
135  glTranslated(0, 0, 0.1);
136  // Set Color depending of selection
137  if (drawUsingSelectColor()) {
139  } else {
141  }
143  // Traslate matrix and draw lock icon if isn't being drawn for selecting
144  glTranslated(0, myLength / 2, 0.1);
145  myBlockIcon.drawIcon(s, exaggeration);
146  // pop draw matrix
147  glPopMatrix();
148  // check if dotted contour has to be drawn
149  if (myViewNet->getDottedAC() == this) {
151  }
152  // pop name
153  glPopName();
154 }
155 
156 
157 std::string
159  switch (key) {
160  case SUMO_ATTR_ID:
161  return getAdditionalID();
162  case SUMO_ATTR_POSITION:
163  return toString(myPosition);
164  case SUMO_ATTR_WIDTH:
165  return toString(myWidth);
166  case SUMO_ATTR_LENGTH:
167  return toString(myLength);
168  case SUMO_ATTR_ANGLE:
169  return toString(myAngle);
171  return toString(myBlockMovement);
172  case GNE_ATTR_PARENT:
173  return getAdditionalParents().at(0)->getID();
174  case GNE_ATTR_SELECTED:
176  case GNE_ATTR_GENERIC:
177  return getGenericParametersStr();
178  default:
179  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
180  }
181 }
182 
183 
184 void
185 GNEParkingSpace::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
186  if (value == getAttribute(key)) {
187  return; //avoid needless changes, later logic relies on the fact that attributes have changed
188  }
189  switch (key) {
190  case SUMO_ATTR_ID:
191  case SUMO_ATTR_POSITION:
192  case SUMO_ATTR_WIDTH:
193  case SUMO_ATTR_LENGTH:
194  case SUMO_ATTR_ANGLE:
196  case GNE_ATTR_PARENT:
197  case GNE_ATTR_SELECTED:
198  case GNE_ATTR_GENERIC:
199  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
200  break;
201  default:
202  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
203  }
204 }
205 
206 
207 bool
208 GNEParkingSpace::isValid(SumoXMLAttr key, const std::string& value) {
209  switch (key) {
210  case SUMO_ATTR_ID:
211  return isValidAdditionalID(value);
212  case SUMO_ATTR_POSITION:
213  return canParse<Position>(value);
214  case SUMO_ATTR_WIDTH:
215  return canParse<double>(value) && (parse<double>(value) > 0);
216  case SUMO_ATTR_LENGTH:
217  return canParse<double>(value) && (parse<double>(value) > 0);
218  case SUMO_ATTR_ANGLE:
219  return canParse<double>(value);
221  return canParse<bool>(value);
222  case GNE_ATTR_PARENT:
223  return (myViewNet->getNet()->retrieveAdditional(SUMO_TAG_PARKING_AREA, value, false) != nullptr);
224  case GNE_ATTR_SELECTED:
225  return canParse<bool>(value);
226  case GNE_ATTR_GENERIC:
227  return isGenericParametersValid(value);
228  default:
229  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
230  }
231 }
232 
233 
234 std::string
236  return getTagStr();
237 }
238 
239 
240 std::string
242  return getTagStr() + ": " + getAttribute(SUMO_ATTR_POSITION);
243 }
244 
245 // ===========================================================================
246 // private
247 // ===========================================================================
248 
249 void
250 GNEParkingSpace::setAttribute(SumoXMLAttr key, const std::string& value) {
251  switch (key) {
252  case SUMO_ATTR_ID:
253  changeAdditionalID(value);
254  break;
255  case SUMO_ATTR_POSITION:
257  myPosition = parse<Position>(value);
259  break;
260  case SUMO_ATTR_WIDTH:
262  myWidth = parse<double>(value);
264  break;
265  case SUMO_ATTR_LENGTH:
267  myLength = parse<double>(value);
269  break;
270  case SUMO_ATTR_ANGLE:
272  myAngle = parse<double>(value);
274  break;
276  myBlockMovement = parse<bool>(value);
277  break;
278  case GNE_ATTR_PARENT:
279  changeAdditionalParent(this, value, 0);
280  break;
281  case GNE_ATTR_SELECTED:
282  if (parse<bool>(value)) {
284  } else {
286  }
287  break;
288  case GNE_ATTR_GENERIC:
290  break;
291  default:
292  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
293  }
294 }
295 
296 
297 /****************************************************************************/
GUIGlObject::getType
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.cpp:181
GNEParkingSpace::myPosition
Position myPosition
position of Parking Space in view
Definition: GNEParkingSpace.h:122
GNEParkingSpace::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEParkingSpace.cpp:76
SUMO_ATTR_ANGLE
Definition: SUMOXMLDefinitions.h:791
GNENet::retrieveAdditional
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:2133
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
GNEParkingSpace::~GNEParkingSpace
~GNEParkingSpace()
Destructor.
Definition: GNEParkingSpace.cpp:46
GNEAdditional::setGenericParametersStr
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
Definition: GNEAdditional.cpp:704
GNEAdditional::getAdditionalID
const std::string & getAdditionalID() const
Definition: GNEAdditional.cpp:578
SUMO_ATTR_LENGTH
Definition: SUMOXMLDefinitions.h:394
GNEAdditional::AdditionalMove::movingGeometryBoundary
Boundary movingGeometryBoundary
boundary used during moving of elements (to avoid insertion in RTREE
Definition: GNEAdditional.h:326
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:80
GNEHierarchicalElementParents::changeAdditionalParent
void changeAdditionalParent(GNEShape *shapeTobeChanged, const std::string &newAdditionalParentID, int additionalParentIndex)
change additional parent of a shape
Definition: GNEHierarchicalElementParents.cpp:480
GUIVisualizationSettings::drawBoundaries
bool drawBoundaries
enable or disable draw boundaries
Definition: GUIVisualizationSettings.h:629
GNENet::removeGLObjectFromGrid
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1279
PositionVector::rotate2D
void rotate2D(double angle)
Definition: PositionVector.cpp:1460
GNEParkingSpace::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNEParkingSpace.cpp:61
GNEParkingSpace::GNEParkingSpace
GNEParkingSpace(GNEViewNet *viewNet, GNEAdditional *parkingAreaParent, const Position &pos, double width, double length, double angle, bool blockMovement)
Constructor.
Definition: GNEParkingSpace.cpp:36
GNEAttributeCarrier::isGenericParametersValid
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
Definition: GNEAttributeCarrier.cpp:1354
GNEViewNet
Definition: GNEViewNet.h:43
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
GLHelper.h
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:604
PositionVector
A list of positions.
Definition: PositionVector.h:46
SUMO_TAG_PARKING_SPACE
A parking space for a single vehicle within a parking area.
Definition: SUMOXMLDefinitions.h:110
GNEAdditional::unselectAttributeCarrier
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Definition: GNEAdditional.cpp:634
GNEAdditional::myBlockIcon
BlockIcon myBlockIcon
variable BlockIcon
Definition: GNEAdditional.h:380
GNEParkingSpace::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEParkingSpace.cpp:235
GLHelper::setColor
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
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:194
GNEAdditional::myMove
AdditionalMove myMove
variable AdditionalMove
Definition: GNEAdditional.h:371
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:365
GLHelper::drawBoundary
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:812
GLO_PARKING_SPACE
a ParkingSpace
Definition: GUIGlObjectTypes.h:70
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:132
GNEViewNet::getNet
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
GNEAdditional::isAttributeCarrierSelected
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
Definition: GNEAdditional.cpp:650
GUIVisualizationColorSettings::selectedAdditionalColor
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
Definition: GUIVisualizationSettings.h:148
GNEParkingSpace::myWidth
double myWidth
width of Parking Space
Definition: GNEParkingSpace.h:125
GNEParkingSpace.h
GNEAdditional::selectAttributeCarrier
void selectAttributeCarrier(bool changeFlag=true)
Definition: GNEAdditional.cpp:619
GNEViewNet.h
SUMO_ATTR_WIDTH
Definition: SUMOXMLDefinitions.h:387
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:150
GNEViewNet::getDottedAC
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
Definition: GNEViewNet.cpp:939
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
SUMO_TAG_PARKING_AREA
A parking area.
Definition: SUMOXMLDefinitions.h:108
GNEParkingSpace::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNEParkingSpace.cpp:70
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:555
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
Position::x
double x() const
Returns the x-position.
Definition: Position.h:57
GNEParkingSpace::myLength
double myLength
Lenght of Parking Space.
Definition: GNEParkingSpace.h:128
GNEAdditional::myBlockMovement
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse)
Definition: GNEAdditional.h:377
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:185
SUMO_ATTR_POSITION
Definition: SUMOXMLDefinitions.h:658
GUIVisualizationSettings::colorSettings
GUIVisualizationColorSettings colorSettings
color settings
Definition: GUIVisualizationSettings.h:649
GLIncludes.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GNE_ATTR_GENERIC
generic attribute
Definition: SUMOXMLDefinitions.h:986
GNEAdditional::BlockIcon::drawIcon
void drawIcon(const GUIVisualizationSettings &s, const double exaggeration, const double size=0.5) const
draw lock icon
Definition: GNEAdditional.cpp:518
GNENet::addGLObjectIntoGrid
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1273
Position::y
double y() const
Returns the y-position.
Definition: Position.h:62
GNEHierarchicalElementParents::getAdditionalParents
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parent this edge (For example, Calibrators)
Definition: GNEHierarchicalElementParents.cpp:86
InvalidArgument
Definition: UtilExceptions.h:57
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
GNEAdditional::getGenericParametersStr
std::string getGenericParametersStr() const
return generic parameters in string format
Definition: GNEAdditional.cpp:678
GNE_ATTR_BLOCK_MOVEMENT
block movement of a graphic element
Definition: SUMOXMLDefinitions.h:978
GNEParkingSpace::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEParkingSpace.cpp:111
GNEAdditional::drawUsingSelectColor
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
Definition: GNEAdditional.cpp:656
GNEParkingSpace::myAngle
double myAngle
Angle of Parking Space.
Definition: GNEParkingSpace.h:131
GNEParkingSpace::getAttribute
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEParkingSpace.cpp:158
GUIVisualizationColorSettings::parkingSpaceInnen
static const RGBColor parkingSpaceInnen
color for parkingArea innen
Definition: GUIVisualizationSettings.h:205
GNEParkingSpace::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEParkingSpace.cpp:82
GUIVisualizationSettings::addSize
GUIVisualizationSizeSettings addSize
Definition: GUIVisualizationSettings.h:580
GNEParkingSpace::getParentName
std::string getParentName() const
Returns the name of the parent object (if any)
Definition: GNEParkingSpace.cpp:105
Position::add
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:127
Boundary::isInitialised
bool isInitialised() const
check if Boundary is Initialised
Definition: Boundary.cpp:217
GNE_ATTR_SELECTED
element is selected
Definition: SUMOXMLDefinitions.h:968
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1165
GNEUndoList
Definition: GNEUndoList.h:49
GUIVisualizationColorSettings::parkingSpace
static const RGBColor parkingSpace
color for parkingArea sign
Definition: GUIVisualizationSettings.h:202
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:346
GNEAdditional::isValidAdditionalID
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Definition: GNEAdditional.cpp:584
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:73
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:373
GNEAdditional::AdditionalMove::originalViewPosition
Position originalViewPosition
value for saving first original position over lane before moving
Definition: GNEAdditional.h:329
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:208
GNEParkingSpace::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEParkingSpace.cpp:50
GNEChange_Attribute.h
GNENet.h
GNEParkingSpace::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEParkingSpace.cpp:241
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
parent of an additional element
Definition: SUMOXMLDefinitions.h:984
GUIVisualizationSettings::drawForSelecting
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
Definition: GUIVisualizationSettings.h:635