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-2018 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 #include <config.h>
22 
24 #include <iostream>
25 #include <string>
26 #include <utility>
30 #include <utils/common/ToString.h>
31 #include <utils/geom/GeomHelper.h>
33 #include <utils/gui/div/GLHelper.h>
45 #include <netedit/GNEUndoList.h>
46 #include <netedit/GNEViewNet.h>
47 #include <netedit/GNEViewParent.h>
48 
49 #include <netedit/GNENet.h>
50 #include "GNEParkingArea.h"
51 #include "GNEParkingSpace.h"
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
57 
58 GNEParkingSpace::GNEParkingSpace(GNEViewNet* viewNet, GNEAdditional* parkingAreaParent, double x, double y, double z, double width, double length, double angle, bool blockMovement) :
59  GNEAdditional(parkingAreaParent, viewNet, GLO_PARKING_SPACE, SUMO_TAG_PARKING_SPACE, "", blockMovement),
60  myX(x),
61  myY(y),
62  myZ(z),
63  myWidth(width),
64  myLength(length),
65  myAngle(angle) {
66 }
67 
68 
70 
71 
72 void
73 GNEParkingSpace::moveGeometry(const Position& oldPos, const Position& offset) {
74  // restore old position, apply offset and update Geometry
75  Position pos = oldPos;
76  pos.add(offset);
77  myX = pos.x();
78  myY = pos.y();
79  updateGeometry(false);
80 }
81 
82 
83 void
85  // commit new position allowing undo/redo
86  undoList->p_begin("position of " + toString(getTag()));
87  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_X, toString(myX), true, toString(oldPos.x())));
88  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_Y, toString(myY), true, toString(oldPos.y())));
89  undoList->p_end();
90 }
91 
92 
93 void
95  // first check if object has to be removed from grid (SUMOTree)
96  if (updateGrid) {
98  }
99  // clear shape and set new position
100  myShape.clear();
101  myShape.push_back(Position(myX, myY));
102  // last step is to check if object has to be added into grid (SUMOTree) again
103  if (updateGrid) {
105  }
106 }
107 
108 
109 Position
111  return Position(myX, myY);
112 }
113 
114 
115 std::string
118 }
119 
120 
121 void
123  // push name and matrix
124  glPushName(getGlID());
125  glPushMatrix();
126  // Traslate matrix and draw green contour
127  glTranslated(myX, myY, getType() + 0.1);
128  glRotated(myAngle, 0, 0, 1);
129  // only drawn small box if isn't being drawn for selecting
130  if (!s.drawForSelecting) {
131  // Set Color depending of selection
134  } else {
135  GLHelper::setColor(RGBColor(0, 255, 0, 255));
136  }
137  GLHelper::drawBoxLine(Position(0, myLength + 0.05), 0, myLength + 0.1, (myWidth / 2) + 0.05);
138  }
139  // Traslate matrix and draw blue innen
140  glTranslated(0, 0, 0.1);
141  // Set Color depending of selection
144  } else {
145  GLHelper::setColor(RGBColor(255, 200, 200, 255));
146  }
148  // Traslate matrix and draw lock icon if isn't being drawn for selecting
149  if (!s.drawForSelecting) {
150  glTranslated(0, myLength / 2, 0.1);
151  drawLockIcon();
152  }
153  // pop draw matrix
154  glPopMatrix();
155  // check if dotted contour has to be drawn
156  if (!s.drawForSelecting && (myViewNet->getACUnderCursor() == this)) {
158  }
159 
160  // pop name
161  glPopName();
162 }
163 
164 
165 std::string
167  switch (key) {
168  case SUMO_ATTR_ID:
169  return getAdditionalID();
170  case SUMO_ATTR_X:
171  return toString(myX);
172  case SUMO_ATTR_Y:
173  return toString(myY);
174  case SUMO_ATTR_Z:
175  return toString(myZ);
176  case SUMO_ATTR_WIDTH:
177  return toString(myWidth);
178  case SUMO_ATTR_LENGTH:
179  return toString(myLength);
180  case SUMO_ATTR_ANGLE:
181  return toString(myAngle);
183  return toString(myBlockMovement);
184  case GNE_ATTR_PARENT:
185  return myFirstAdditionalParent->getID();
186  case GNE_ATTR_SELECTED:
188  case GNE_ATTR_GENERIC:
189  return getGenericParametersStr();
190  default:
191  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
192  }
193 }
194 
195 
196 void
197 GNEParkingSpace::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
198  if (value == getAttribute(key)) {
199  return; //avoid needless changes, later logic relies on the fact that attributes have changed
200  }
201  switch (key) {
202  case SUMO_ATTR_ID:
203  case SUMO_ATTR_X:
204  case SUMO_ATTR_Y:
205  case SUMO_ATTR_Z:
206  case SUMO_ATTR_WIDTH:
207  case SUMO_ATTR_LENGTH:
208  case SUMO_ATTR_ANGLE:
210  case GNE_ATTR_PARENT:
211  case GNE_ATTR_SELECTED:
212  case GNE_ATTR_GENERIC:
213  undoList->p_add(new GNEChange_Attribute(this, key, value));
214  break;
215  default:
216  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
217  }
218 }
219 
220 
221 bool
222 GNEParkingSpace::isValid(SumoXMLAttr key, const std::string& value) {
223  switch (key) {
224  case SUMO_ATTR_ID:
225  return isValidAdditionalID(value);
226  case SUMO_ATTR_X:
227  return canParse<double>(value);
228  case SUMO_ATTR_Y:
229  return canParse<double>(value);
230  case SUMO_ATTR_Z:
231  return canParse<double>(value);
232  case SUMO_ATTR_WIDTH:
233  return canParse<double>(value) && (parse<double>(value) >= 0);
234  case SUMO_ATTR_LENGTH:
235  return canParse<double>(value) && (parse<double>(value) >= 0);
236  case SUMO_ATTR_ANGLE:
237  return canParse<double>(value);
239  return canParse<bool>(value);
240  case GNE_ATTR_PARENT:
241  return (myViewNet->getNet()->retrieveAdditional(SUMO_TAG_PARKING_AREA, value, false) != nullptr);
242  case GNE_ATTR_SELECTED:
243  return canParse<bool>(value);
244  case GNE_ATTR_GENERIC:
245  return isGenericParametersValid(value);
246  default:
247  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
248  }
249 }
250 
251 
252 std::string
254  return toString(getTag());
255 }
256 
257 
258 std::string
260  return toString(getTag()) + ": " + getAttribute(SUMO_ATTR_X) + ", " + getAttribute(SUMO_ATTR_Y);
261 }
262 
263 // ===========================================================================
264 // private
265 // ===========================================================================
266 
267 void
268 GNEParkingSpace::setAttribute(SumoXMLAttr key, const std::string& value) {
269  switch (key) {
270  case SUMO_ATTR_ID:
271  changeAdditionalID(value);
272  break;
273  case SUMO_ATTR_X:
274  myX = parse<double>(value);
275  break;
276  case SUMO_ATTR_Y:
277  myY = parse<double>(value);
278  break;
279  case SUMO_ATTR_Z:
280  myZ = parse<double>(value);
281  break;
282  case SUMO_ATTR_WIDTH:
283  myWidth = parse<double>(value);
284  break;
285  case SUMO_ATTR_LENGTH:
286  myLength = parse<double>(value);
287  break;
288  case SUMO_ATTR_ANGLE:
289  myAngle = parse<double>(value);
290  break;
292  myBlockMovement = parse<bool>(value);
293  break;
294  case GNE_ATTR_PARENT:
296  break;
297  case GNE_ATTR_SELECTED:
298  if (parse<bool>(value)) {
300  } else {
302  }
303  break;
304  case GNE_ATTR_GENERIC:
306  break;
307  default:
308  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
309  }
310  // After setting attribute always update Geometry
311  updateGeometry(true);
312 }
313 
314 
315 /****************************************************************************/
const GNEAttributeCarrier * getACUnderCursor() const
get AttributeCarrier under cursor
std::string getAttribute(SumoXMLAttr key) const
double myY
y position of Parking Space
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:126
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
void changeFirstAdditionalParent(const std::string &newAdditionalParentID)
change first additional parent of additional
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:61
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
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
double x() const
Returns the x-position.
Definition: Position.h:56
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
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:78
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void updateGeometry(bool updateGrid)
update pre-computed geometry information
A parking space for a single vehicle within a parking area.
double myX
x position of Parking Space
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:1795
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:105
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void drawLockIcon(double size=0.5) const
draw lock icon
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
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:573
PositionVector myShape
The shape of the additional element.
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:85
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
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:1175
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
block movement of a graphic element
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
const std::string getID() const
function to support debugging
GNEParkingSpace(GNEViewNet *viewNet, GNEAdditional *parkingAreaParent, double x, double y, double z, double width, double length, double angle, bool blockMovement)
Constructor.
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) ...
Position getPositionInView() const
Returns position of additional in view.
double myAngle
Angle of Parking Space.
static void drawShapeDottedContour(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:471
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:53
static const RGBColor selectedConnectionColor
color of selected connection
Definition: GNENet.h:102
element is selected
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string getGenericParametersStr() const
return generic parameters in string format
GNENet * getNet() const
get the net object
GUIGlID getGlID() const
Returns the numerical id of the object.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
parent of an additional element
double myZ
z position of Parking Space
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:132
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)
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1168
GNEAdditional * myFirstAdditionalParent
pointer to first Addititional parent
~GNEParkingSpace()
Destructor.
SumoXMLTag getTag() const
get XML Tag assigned to this object