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-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 halt 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>
26 
27 #include "GNEParkingSpace.h"
28 
29 
30 // ===========================================================================
31 // method definitions
32 // ===========================================================================
33 
34 GNEParkingSpace::GNEParkingSpace(GNENet* net, GNEAdditional* parkingAreaParent, const Position& pos, double width, double length, double angle, bool blockMovement) :
36 {}, {}, {}, {parkingAreaParent}, {}, {}, {}, {}),
37 myPosition(pos),
38 myWidth(width),
39 myLength(length),
40 myAngle(angle) {
41  // update centering boundary without updating grid
42  updateCenteringBoundary(false);
43 }
44 
45 
47 
48 
50 GNEParkingSpace::getMoveOperation(const double /*shapeOffset*/) {
51  if (myBlockMovement) {
52  // element blocked, then nothing to move
53  return nullptr;
54  } else {
55  // return move operation for additional placed in view
56  return new GNEMoveOperation(this, myPosition);
57  }
58 }
59 
60 
61 void
64 }
65 
66 
67 void
68 GNEParkingSpace::updateCenteringBoundary(const bool /*updateGrid*/) {
69  // first reset boundary
70  myBoundary.reset();
71  // add position
73  // grow width and lenght
74  if (myWidth > myLength) {
76  } else {
78  }
79  // grow
80  myBoundary.grow(10);
81  // update centering boundary of parent
82  getParentAdditionals().front()->updateCenteringBoundary(true);
83 }
84 
85 
86 void
87 GNEParkingSpace::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
88  // geometry of this element cannot be splitted
89 }
90 
91 
92 std::string
94  return getParentAdditionals().at(0)->getID();
95 }
96 
97 
98 void
100  // Set initial values
101  const double parkingAreaExaggeration = s.addSize.getExaggeration(s, this);
102  // obtain values with exaggeration
103  const double widthExaggeration = myWidth * parkingAreaExaggeration;
104  const double lengthExaggeration = myLength * parkingAreaExaggeration;
105  // first check if additional has to be drawn
106  if (s.drawAdditionals(parkingAreaExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
107  // push name
108  glPushName(getGlID());
109  // push later matrix
110  glPushMatrix();
111  // translate to front
113  // translate to position
114  glTranslated(myPosition.x(), myPosition.y(), 0);
115  // rotate
116  glRotated(myAngle, 0, 0, 1);
117  // only drawn small box if isn't being drawn for selecting
118  if (!s.drawForRectangleSelection) {
119  // Set Color depending of selection
120  if (drawUsingSelectColor()) {
122  } else {
124  }
125  GLHelper::drawBoxLine(Position(0, lengthExaggeration + 0.05), 0, lengthExaggeration + 0.1, (widthExaggeration * 0.5) + 0.05);
126  }
127  // Traslate matrix and draw blue innen
128  glTranslated(0, 0, 0.1);
129  // Set Color depending of selection
130  if (drawUsingSelectColor()) {
132  } else {
134  }
135  GLHelper::drawBoxLine(Position(0, lengthExaggeration), 0, lengthExaggeration, widthExaggeration * 0.5);
136  // Traslate matrix and draw lock icon if isn't being drawn for selecting
137  glTranslated(0, lengthExaggeration * 0.5, 0.1);
138  // draw lock icon
139  GNEViewNetHelper::LockIcon::drawLockIcon(this, myAdditionalGeometry, parkingAreaExaggeration, 0, 0, false);
140  // pop layer matrix
141  glPopMatrix();
142  // pop name
143  glPopName();
144  // Draw additional ID
145  drawAdditionalID(s);
146  // draw additional name
148  // check if dotted contours has to be drawn
150  // draw using drawDottedContourClosedShape
151  GNEGeometry::drawDottedSquaredShape(GNEGeometry::DottedContourType::INSPECT, s, myPosition, lengthExaggeration * 0.5, widthExaggeration * 0.5, lengthExaggeration * 0.5, 0, myAngle, 1);
152  }
153  if (s.drawDottedContour() || myNet->getViewNet()->getFrontAttributeCarrier() == this) {
154  // draw using drawDottedContourClosedShape
155  GNEGeometry::drawDottedSquaredShape(GNEGeometry::DottedContourType::FRONT, s, myPosition, lengthExaggeration * 0.5, widthExaggeration * 0.5, lengthExaggeration * 0.5, 0, myAngle, 1);
156  }
157  }
158 }
159 
160 
161 std::string
163  switch (key) {
164  case SUMO_ATTR_ID:
165  return getID();
166  case SUMO_ATTR_POSITION:
167  return toString(myPosition);
168  case SUMO_ATTR_WIDTH:
169  return toString(myWidth);
170  case SUMO_ATTR_LENGTH:
171  return toString(myLength);
172  case SUMO_ATTR_ANGLE:
173  return toString(myAngle);
175  return toString(myBlockMovement);
176  case GNE_ATTR_PARENT:
177  return getParentAdditionals().at(0)->getID();
178  case GNE_ATTR_SELECTED:
180  case GNE_ATTR_PARAMETERS:
181  return getParametersStr();
182  default:
183  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
184  }
185 }
186 
187 
188 double
190  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
191 }
192 
193 
194 void
195 GNEParkingSpace::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
196  if (value == getAttribute(key)) {
197  return; //avoid needless changes, later logic relies on the fact that attributes have changed
198  }
199  switch (key) {
200  case SUMO_ATTR_POSITION:
201  case SUMO_ATTR_WIDTH:
202  case SUMO_ATTR_LENGTH:
203  case SUMO_ATTR_ANGLE:
205  case GNE_ATTR_PARENT:
206  case GNE_ATTR_SELECTED:
207  case GNE_ATTR_PARAMETERS:
208  undoList->p_add(new GNEChange_Attribute(this, key, value));
209  break;
210  default:
211  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
212  }
213 }
214 
215 
216 bool
217 GNEParkingSpace::isValid(SumoXMLAttr key, const std::string& value) {
218  switch (key) {
219  case SUMO_ATTR_POSITION:
220  return canParse<Position>(value);
221  case SUMO_ATTR_WIDTH:
222  return canParse<double>(value) && (parse<double>(value) > 0);
223  case SUMO_ATTR_LENGTH:
224  return canParse<double>(value) && (parse<double>(value) > 0);
225  case SUMO_ATTR_ANGLE:
226  return canParse<double>(value);
228  return canParse<bool>(value);
229  case GNE_ATTR_PARENT:
230  return (myNet->retrieveAdditional(SUMO_TAG_PARKING_AREA, value, false) != nullptr);
231  case GNE_ATTR_SELECTED:
232  return canParse<bool>(value);
233  case GNE_ATTR_PARAMETERS:
234  return Parameterised::areParametersValid(value);
235  default:
236  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
237  }
238 }
239 
240 
241 bool
243  return true;
244 }
245 
246 
247 std::string
249  return getTagStr();
250 }
251 
252 
253 std::string
255  return getTagStr() + ": " + getAttribute(SUMO_ATTR_POSITION);
256 }
257 
258 // ===========================================================================
259 // private
260 // ===========================================================================
261 
262 void
263 GNEParkingSpace::setAttribute(SumoXMLAttr key, const std::string& value) {
264  switch (key) {
265  case SUMO_ATTR_POSITION:
266  myPosition = parse<Position>(value);
267  // update boundary
269  break;
270  case SUMO_ATTR_WIDTH:
271  myWidth = parse<double>(value);
272  // update boundary
274  break;
275  case SUMO_ATTR_LENGTH:
276  myLength = parse<double>(value);
277  // update boundary
279  break;
280  case SUMO_ATTR_ANGLE:
281  myAngle = parse<double>(value);
282  // update boundary
284  break;
286  myBlockMovement = parse<bool>(value);
287  break;
288  case GNE_ATTR_PARENT:
290  break;
291  case GNE_ATTR_SELECTED:
292  if (parse<bool>(value)) {
294  } else {
296  }
297  break;
298  case GNE_ATTR_PARAMETERS:
299  setParametersStr(value);
300  break;
301  default:
302  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
303  }
304 }
305 
306 
307 void
309  // update position
310  myPosition = moveResult.shapeToUpdate.front();
311  // update geometry
312  updateGeometry();
313 }
314 
315 
316 void
318  undoList->p_begin("position of " + getTagStr());
319  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front())));
320  undoList->p_end();
321 }
322 
323 
324 /****************************************************************************/
@ GLO_PARKING_SPACE
a ParkingSpace
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_PARKING_SPACE
A parking space for a single vehicle within a parking area.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_BLOCK_MOVEMENT
block movement of a graphic element
@ GNE_ATTR_PARENT
parent of an additional element
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_ID
@ SUMO_ATTR_WIDTH
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:77
void reset()
Resets the boundary.
Definition: Boundary.cpp:65
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:135
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const std::string & getID() const
get ID
void replaceAdditionalParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace additional parent
GNEGeometry::Geometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void drawAdditionalID(const GUIVisualizationSettings &s) const
draw additional ID
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse)
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
Boundary myBoundary
Additional Boundary.
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 std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:2316
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNEParkingSpace(GNENet *net, GNEAdditional *parkingAreaParent, const Position &pos, double width, double length, double angle, bool blockMovement)
Constructor.
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
double getAttributeDouble(SumoXMLAttr key) const
std::string getAttribute(SumoXMLAttr key) const
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Position myPosition
position of Parking Space in view
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
double myWidth
width of Parking Space
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
~GNEParkingSpace()
Destructor.
std::string getParentName() const
Returns the name of the parent object (if any)
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
bool isAttributeEnabled(SumoXMLAttr key) const
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
double myLength
Length of Parking Space.
double myAngle
Angle of Parking Space.
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void updateGeometry()
update pre-computed geometry information
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
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:71
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
Definition: GNEUndoList.cpp:78
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 drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
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.
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 point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
static void drawDottedSquaredShape(const DottedContourType type, const GUIVisualizationSettings &s, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration)
draw dotted squared contour (used by additionals and demand elements)
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...)
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
static const RGBColor parkingSpaceColor
color for parkingSpace innen
static const RGBColor parkingSpaceColorContour
color for parkingSpace contour