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 /****************************************************************************/
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
std::string getAttribute(SumoXMLAttr key) const
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.
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:127
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
GNEParkingSpace(GNEViewNet *viewNet, GNEAdditional *parkingAreaParent, const Position &pos, double width, double length, double angle, bool blockMovement)
Constructor.
Stores the information about how to visualize structures.
void changeAdditionalParent(GNEShape *shapeTobeChanged, const std::string &newAdditionalParentID, int additionalParentIndex)
change additional parent of a shape
double y() const
Returns the y-position.
Definition: Position.h:62
double myLength
Lenght of Parking Space.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
double x() const
Returns the x-position.
Definition: Position.h:57
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
BlockIcon myBlockIcon
variable BlockIcon
Position originalViewPosition
value for saving first original position over lane before moving
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
Numbers representing SUMO-XML - attributes.
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
A parking space for a single vehicle within a parking area.
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
AdditionalMove myMove
variable AdditionalMove
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:2133
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
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
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
Definition: GNEUndoList.cpp:80
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
A list of positions.
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)
block movement of a graphic element
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
a ParkingSpace
double myWidth
width of Parking Space
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
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 getPositionInView() const
Returns position of additional in view.
void rotate2D(double angle)
double myAngle
Angle of Parking Space.
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
static const RGBColor parkingSpace
color for parkingArea sign
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
Definition: GNEViewNet.cpp:939
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
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
std::string getGenericParametersStr() const
return generic parameters in string format
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
GUIGlID getGlID() const
Returns the numerical id of the object.
GUIVisualizationColorSettings colorSettings
color settings
void updateGeometry()
update pre-computed geometry information
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.
parent of an additional element
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:136
void drawIcon(const GUIVisualizationSettings &s, const double exaggeration, const double size=0.5) const
draw lock icon
void add(double xoff, double yoff, double zoff)
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
std::string getParentName() const
Returns the name of the parent object (if any)
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1273
bool drawBoundaries
enable or disable draw boundaries
static const RGBColor parkingSpaceInnen
color for parkingArea innen
~GNEParkingSpace()
Destructor.
Position myPosition
position of Parking Space in view