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 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
27 #include <utils/gui/div/GLHelper.h>
29 
30 #include "GNEParkingSpace.h"
31 
32 
33 // ===========================================================================
34 // method definitions
35 // ===========================================================================
36 
37 GNEParkingSpace::GNEParkingSpace(GNEViewNet* viewNet, GNEAdditional* parkingAreaParent, const Position &pos, double width, double length, double angle, bool blockMovement) :
38  GNEAdditional(parkingAreaParent, viewNet, GLO_PARKING_SPACE, SUMO_TAG_PARKING_SPACE, "", blockMovement),
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
56  updateGeometry(false);
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  // first check if object has to be removed from grid (SUMOTree)
72  if (updateGrid) {
74  }
75  // Clear all containers
77  // set new position
78  myGeometry.shape.push_back(myPosition);
79  // last step is to check if object has to be added into grid (SUMOTree) again
80  if (updateGrid) {
82  }
83 }
84 
85 
88  return myPosition;
89 }
90 
91 
92 std::string
95 }
96 
97 
98 void
100  // push name and matrix
101  glPushName(getGlID());
102  glPushMatrix();
103  // Traslate matrix and draw green contour
104  glTranslated(myPosition.x(), myPosition.y(), getType() + 0.1);
105  glRotated(myAngle, 0, 0, 1);
106  // only drawn small box if isn't being drawn for selecting
107  if (!s.drawForSelecting) {
108  // Set Color depending of selection
111  } else {
112  GLHelper::setColor(RGBColor(0, 255, 0, 255));
113  }
114  GLHelper::drawBoxLine(Position(0, myLength + 0.05), 0, myLength + 0.1, (myWidth / 2) + 0.05);
115  }
116  // Traslate matrix and draw blue innen
117  glTranslated(0, 0, 0.1);
118  // Set Color depending of selection
121  } else {
122  GLHelper::setColor(RGBColor(255, 200, 200, 255));
123  }
125  // Traslate matrix and draw lock icon if isn't being drawn for selecting
126  if (!s.drawForSelecting) {
127  glTranslated(0, myLength / 2, 0.1);
128  myBlockIcon.draw();
129  }
130  // pop draw matrix
131  glPopMatrix();
132  // check if dotted contour has to be drawn
133  if (!s.drawForSelecting && (myViewNet->getDottedAC() == this)) {
135  }
136 
137  // pop name
138  glPopName();
139 }
140 
141 
142 std::string
144  switch (key) {
145  case SUMO_ATTR_ID:
146  return getAdditionalID();
147  case SUMO_ATTR_POSITION:
148  return toString(myPosition);
149  case SUMO_ATTR_WIDTH:
150  return toString(myWidth);
151  case SUMO_ATTR_LENGTH:
152  return toString(myLength);
153  case SUMO_ATTR_ANGLE:
154  return toString(myAngle);
156  return toString(myBlockMovement);
157  case GNE_ATTR_PARENT:
158  return myFirstAdditionalParent->getID();
159  case GNE_ATTR_SELECTED:
161  case GNE_ATTR_GENERIC:
162  return getGenericParametersStr();
163  default:
164  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
165  }
166 }
167 
168 
169 void
170 GNEParkingSpace::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
171  if (value == getAttribute(key)) {
172  return; //avoid needless changes, later logic relies on the fact that attributes have changed
173  }
174  switch (key) {
175  case SUMO_ATTR_ID:
176  case SUMO_ATTR_POSITION:
177  case SUMO_ATTR_WIDTH:
178  case SUMO_ATTR_LENGTH:
179  case SUMO_ATTR_ANGLE:
181  case GNE_ATTR_PARENT:
182  case GNE_ATTR_SELECTED:
183  case GNE_ATTR_GENERIC:
184  undoList->p_add(new GNEChange_Attribute(this, key, value));
185  break;
186  default:
187  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
188  }
189 }
190 
191 
192 bool
193 GNEParkingSpace::isValid(SumoXMLAttr key, const std::string& value) {
194  switch (key) {
195  case SUMO_ATTR_ID:
196  return isValidAdditionalID(value);
197  case SUMO_ATTR_POSITION:
198  return canParse<Position>(value);
199  case SUMO_ATTR_WIDTH:
200  return canParse<double>(value) && (parse<double>(value) >= 0);
201  case SUMO_ATTR_LENGTH:
202  return canParse<double>(value) && (parse<double>(value) >= 0);
203  case SUMO_ATTR_ANGLE:
204  return canParse<double>(value);
206  return canParse<bool>(value);
207  case GNE_ATTR_PARENT:
208  return (myViewNet->getNet()->retrieveAdditional(SUMO_TAG_PARKING_AREA, value, false) != nullptr);
209  case GNE_ATTR_SELECTED:
210  return canParse<bool>(value);
211  case GNE_ATTR_GENERIC:
212  return isGenericParametersValid(value);
213  default:
214  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
215  }
216 }
217 
218 
219 std::string
221  return getTagStr();
222 }
223 
224 
225 std::string
227  return getTagStr() + ": " + getAttribute(SUMO_ATTR_POSITION);
228 }
229 
230 // ===========================================================================
231 // private
232 // ===========================================================================
233 
234 void
235 GNEParkingSpace::setAttribute(SumoXMLAttr key, const std::string& value) {
236  switch (key) {
237  case SUMO_ATTR_ID:
238  changeAdditionalID(value);
239  break;
240  case SUMO_ATTR_POSITION:
241  myPosition = parse<Position>(value);
242  break;
243  case SUMO_ATTR_WIDTH:
244  myWidth = parse<double>(value);
245  break;
246  case SUMO_ATTR_LENGTH:
247  myLength = parse<double>(value);
248  break;
249  case SUMO_ATTR_ANGLE:
250  myAngle = parse<double>(value);
251  break;
253  myBlockMovement = parse<bool>(value);
254  break;
255  case GNE_ATTR_PARENT:
257  break;
258  case GNE_ATTR_SELECTED:
259  if (parse<bool>(value)) {
261  } else {
263  }
264  break;
265  case GNE_ATTR_GENERIC:
267  break;
268  default:
269  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
270  }
271  // Update Geometry after setting a new attribute (but avoided for certain attributes)
272  if((key != SUMO_ATTR_ID) && (key != GNE_ATTR_GENERIC) && (key != GNE_ATTR_SELECTED)) {
273  updateGeometry(true);
274  }
275 }
276 
277 
278 /****************************************************************************/
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
std::string getAttribute(SumoXMLAttr key) const
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
returns Additional ID
GNEParkingSpace(GNEViewNet *viewNet, GNEAdditional *parkingAreaParent, const Position &pos, double width, double length, double angle, bool blockMovement)
Constructor.
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:62
Position snapToActiveGrid(const Position &pos) const
Returns a position that is mapped to the closest grid point if the grid is active.
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
void clearGeometry()
reset geometry
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.
void updateGeometry(bool updateGrid)
update pre-computed geometry information
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
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:1785
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
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: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
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
PositionVector shape
The shape of the additional element.
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:1160
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
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:48
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
AdditionalGeometry myGeometry
geometry to be precomputed in updateGeometry(...)
const std::string & getTagStr() const
get tag assigned to this object in string format
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
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:1153
GNEAdditional * myFirstAdditionalParent
pointer to first Additional parent
~GNEParkingSpace()
Destructor.
void draw(double size=0.5) const
draw lock icon
Position myPosition
position of Parking Space in view