SUMO - Simulation of Urban MObility
GNEParkingArea.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 park 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>
28 #include <utils/gui/div/GLHelper.h>
31 
32 #include "GNEParkingArea.h"
33 
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
38 
39 GNEParkingArea::GNEParkingArea(const std::string& id, GNELane* lane, GNEViewNet* viewNet, const std::string& startPos, const std::string& endPos, const std::string& name,
40  bool friendlyPosition, int roadSideCapacity, bool onRoad, double width, const std::string& length, double angle, bool blockMovement) :
41  GNEStoppingPlace(id, viewNet, GLO_PARKING_AREA, SUMO_TAG_PARKING_AREA, lane, startPos, endPos, name, friendlyPosition, blockMovement),
42  myRoadSideCapacity(roadSideCapacity),
43  myOnRoad(onRoad),
44  myWidth(width),
45  myLength(length),
46  myAngle(angle) {
47 }
48 
49 
51 
52 
53 void
55  // first check if object has to be removed from grid (SUMOTree)
56  if (updateGrid) {
58  }
59 
60  // Get value of option "lefthand"
61  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
62 
63  // Update common geometry of stopping place
65 
66  // Obtain a copy of the shape
67  PositionVector tmpShape = myGeometry.shape;
68 
69  // Move shape to side
70  tmpShape.move2side(1.5 * offsetSign);
71 
72  // Get position of the sign
73  mySignPos = tmpShape.getLineCenter();
74 
75  // Set block icon position
77 
78  // Set block icon rotation, and using their rotation for sign
80 
81  // last step is to check if object has to be added into grid (SUMOTree) again
82  if (updateGrid) {
84  }
85 }
86 
87 
88 void
90  // obtain circle resolution
91  int circleResolution = getCircleResolution(s);
92  // Obtain exaggeration of the draw
93  const double exaggeration = s.addSize.getExaggeration(s, this);
94  // Push name
95  glPushName(getGlID());
96  // Push base matrix
97  glPushMatrix();
98  // Traslate matrix
99  glTranslated(0, 0, getType());
100  // Set Color
103  } else {
104  GLHelper::setColor(RGBColor(83, 89, 172, 255));
105  }
106  // Draw base
108  // Check if the distance is enought to draw details and if is being drawn for selecting
109  if (s.drawForSelecting) {
110  // only draw circle depending of distance between sign and mouse cursor
112  // Add a draw matrix for details
113  glPushMatrix();
114  // Start drawing sign traslating matrix to signal position
115  glTranslated(mySignPos.x(), mySignPos.y(), 0);
116  // scale matrix depending of the exaggeration
117  glScaled(exaggeration, exaggeration, 1);
118  // set color
120  // Draw circle
121  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
122  // pop draw matrix
123  glPopMatrix();
124  }
125  } else if (s.scale * exaggeration >= 10) {
126  // Push matrix for details
127  glPushMatrix();
128  // Set position over sign
129  glTranslated(mySignPos.x(), mySignPos.y(), 0);
130  // Scale matrix
131  glScaled(exaggeration, exaggeration, 1);
132  // Set base color
135  } else {
136  GLHelper::setColor(RGBColor(83, 89, 172, 255));
137  }
138  // Draw extern
139  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
140  // Move to top
141  glTranslated(0, 0, .1);
142  // Set sign color
145  } else {
146  GLHelper::setColor(RGBColor(177, 184, 186, 171));
147  }
148  // Draw internt sign
149  GLHelper::drawFilledCircle(myCircleInWidth, circleResolution);
150  // Draw sign 'C'
151  if (s.scale * exaggeration >= 4.5) {
154  } else {
155  GLHelper::drawText("P", Position(), .1, myCircleInText, RGBColor(83, 89, 172, 255), myBlockIcon.rotation);
156  }
157  }
158  // Pop sign matrix
159  glPopMatrix();
160  // Draw icon
161  myBlockIcon.draw();
162  }
163  // Pop base matrix
164  glPopMatrix();
165  // Draw name if isn't being drawn for selecting
166  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
167  if (s.addFullName.show && (myAdditionalName != "") && !s.drawForSelecting) {
169  }
170  // check if dotted contour has to be drawn
171  if (!s.drawForSelecting && (myViewNet->getDottedAC() == this)) {
173  }
174  // Pop name matrix
175  glPopName();
176 }
177 
178 
179 std::string
181  switch (key) {
182  case SUMO_ATTR_ID:
183  return getAdditionalID();
184  case SUMO_ATTR_LANE:
185  return myLane->getID();
186  case SUMO_ATTR_STARTPOS:
187  return toString(myStartPosition);
188  case SUMO_ATTR_ENDPOS:
189  return myEndPosition;
190  case SUMO_ATTR_NAME:
191  return myAdditionalName;
196  case SUMO_ATTR_ONROAD:
197  return toString(myOnRoad);
198  case SUMO_ATTR_WIDTH:
199  return toString(myWidth);
200  case SUMO_ATTR_LENGTH:
201  return myLength;
202  case SUMO_ATTR_ANGLE:
203  return toString(myAngle);
205  return toString(myBlockMovement);
206  case GNE_ATTR_SELECTED:
208  case GNE_ATTR_GENERIC:
209  return getGenericParametersStr();
210  default:
211  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
212  }
213 }
214 
215 
216 void
217 GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
218  if (value == getAttribute(key)) {
219  return; //avoid needless changes, later logic relies on the fact that attributes have changed
220  }
221  switch (key) {
222  case SUMO_ATTR_ID: {
223  // change ID of Entry
224  undoList->p_add(new GNEChange_Attribute(this, key, value));
225  // Change Ids of all Parking Spaces
226  for (auto i : myAdditionalChilds) {
228  }
229  break;
230  }
231  case SUMO_ATTR_LANE:
232  case SUMO_ATTR_STARTPOS:
233  case SUMO_ATTR_ENDPOS:
234  case SUMO_ATTR_NAME:
237  case SUMO_ATTR_ONROAD:
238  case SUMO_ATTR_WIDTH:
239  case SUMO_ATTR_LENGTH:
240  case SUMO_ATTR_ANGLE:
242  case GNE_ATTR_SELECTED:
243  case GNE_ATTR_GENERIC:
244  undoList->p_add(new GNEChange_Attribute(this, key, value));
245  break;
246  default:
247  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
248  }
249 }
250 
251 
252 bool
253 GNEParkingArea::isValid(SumoXMLAttr key, const std::string& value) {
254  switch (key) {
255  case SUMO_ATTR_ID:
256  return isValidAdditionalID(value);
257  case SUMO_ATTR_LANE:
258  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
259  return true;
260  } else {
261  return false;
262  }
263  case SUMO_ATTR_STARTPOS:
264  if (value.empty()) {
265  return true;
266  } else {
267  if (canParse<double>(value)) {
268  if (canParse<double>(myEndPosition)) {
269  // Check that new start Position is smaller that end position
270  return (parse<double>(value) < parse<double>(myEndPosition));
271  } else {
272  return true;
273  }
274  } else {
275  return false;
276  }
277  }
278  case SUMO_ATTR_ENDPOS:
279  if (value.empty()) {
280  return true;
281  } else {
282  if (canParse<double>(value)) {
283  if (canParse<double>(myStartPosition)) {
284  // Check that new start Position is smaller that end position
285  return (parse<double>(myStartPosition) < parse<double>(value));
286  } else {
287  return true;
288  }
289  } else {
290  return false;
291  }
292  }
293  case SUMO_ATTR_NAME:
296  return canParse<bool>(value);
298  return canParse<double>(value) && (parse<double>(value) >= 0);
299  case SUMO_ATTR_ONROAD:
300  return canParse<bool>(value);
301  case SUMO_ATTR_WIDTH:
302  return canParse<double>(value) && (parse<double>(value) >= 0);
303  case SUMO_ATTR_LENGTH:
304  if (value.empty()) {
305  return true;
306  } else {
307  return canParse<double>(value) && (parse<double>(value) >= 0);
308  }
309  case SUMO_ATTR_ANGLE:
310  return canParse<double>(value);
312  return canParse<bool>(value);
313  case GNE_ATTR_SELECTED:
314  return canParse<bool>(value);
315  case GNE_ATTR_GENERIC:
316  return isGenericParametersValid(value);
317  default:
318  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
319  }
320 }
321 
322 // ===========================================================================
323 // private
324 // ===========================================================================
325 
326 void
327 GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value) {
328  switch (key) {
329  case SUMO_ATTR_ID:
330  changeAdditionalID(value);
331  break;
332  case SUMO_ATTR_LANE:
333  myLane = changeLane(myLane, value);
334  break;
335  case SUMO_ATTR_STARTPOS:
336  myStartPosition = value;
337  break;
338  case SUMO_ATTR_ENDPOS:
339  myEndPosition = value;
340  break;
341  case SUMO_ATTR_NAME:
342  myAdditionalName = value;
343  break;
345  myFriendlyPosition = parse<bool>(value);
346  break;
348  myRoadSideCapacity = parse<int>(value);
349  break;
350  case SUMO_ATTR_ONROAD:
351  myOnRoad = parse<bool>(value);
352  break;
353  case SUMO_ATTR_WIDTH:
354  myWidth = parse<double>(value);
355  break;
356  case SUMO_ATTR_LENGTH:
357  myLength = value;
358  break;
359  case SUMO_ATTR_ANGLE:
360  myAngle = parse<double>(value);
361  break;
363  myBlockMovement = parse<bool>(value);
364  break;
365  case GNE_ATTR_SELECTED:
366  if (parse<bool>(value)) {
368  } else {
370  }
371  break;
372  case GNE_ATTR_GENERIC:
374  break;
375  default:
376  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
377  }
378  // Update Geometry after setting a new attribute (but avoided for certain attributes)
379  if((key != SUMO_ATTR_ID) && (key != GNE_ATTR_GENERIC) && (key != GNE_ATTR_SELECTED)) {
380  updateGeometry(true);
381  }
382 }
383 
384 
385 /****************************************************************************/
double myAngle
Angle of Parking Area.
double scale
information about a lane&#39;s width (temporary, used for a single view)
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name) ...
static void drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition: GLHelper.cpp:178
GUIVisualizationTextSettings addName
std::vector< double > shapeRotations
The rotations of the single shape parts.
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
~GNEParkingArea()
Destructor.
Stores the information about how to visualize structures.
static const double myCircleWidthSquared
squared circle width resolution for all stopping places
double y() const
Returns the y-position.
Definition: Position.h:62
static const double myCircleInWidth
inner circle width resolution for all stopping places
double x() const
Returns the x-position.
Definition: Position.h:57
std::string getAttribute(SumoXMLAttr key) const
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, int align=0, double width=-1)
Definition: GLHelper.cpp:611
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Position position
position of the block icon
BlockIcon myBlockIcon
variable BlockIcon
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
bool myFriendlyPosition
Flag for friendly position.
std::string myStartPosition
The relative start position this stopping place is located at (optional, if empty takes 0) ...
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
static const double myCircleInText
text inner circle width resolution for all stopping places
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
A parking space for a single vehicle within a parking area.
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:344
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
Position getLineCenter() const
get line center
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
double rotation
The rotation of the block icon.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
int myRoadSideCapacity
roadside capacity of Parking Area
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
int getIndex() const
returns the index of the lane
Definition: GNELane.cpp:757
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
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:573
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1260
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
PositionVector shape
The shape of the additional element.
A list of positions.
double scaledSize(double scale, double constFactor=0.1) const
std::string myAdditionalName
name of additional
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
GNELane * myLane
The lane in which this lane is placed.
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
block movement of a graphic element
RGBColor selectionColor
NETEDIT special colors.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
const std::string getID() const
function to support debugging
static const RGBColor SUMO_color_busStop
color for busStops
void move2side(double amount)
move position vector to side using certain ammount
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
std::vector< GNEAdditional * > myAdditionalChilds
vector with the Additional childs
static const double myCircleWidth
circle width resolution for all stopping places
std::vector< double > shapeLengths
The lengths of the single shape parts.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string myLength
Lenght of Parking Area (by default (endPos - startPos) / roadsideCapacity.
double getLaneWidth() const
Returns the default width of lanes of this edge.
Definition: NBEdge.h:530
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
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
void updateGeometry(bool updateGrid)
update pre-computed geometry information
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
GUIVisualizationTextSettings addFullName
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
static int getCircleResolution(const GUIVisualizationSettings &settings)
function to calculate circle resolution for all circles drawn in drawGL(...) functions ...
std::string getGenericParametersStr() const
return generic parameters in string format
double distanceSquaredTo2D(const Position &p2) const
returns the square of the distance to another position (Only using x and y positions) ...
Definition: Position.h:249
a ParkingArea
GNENet * getNet() const
get the net object
std::string generateAdditionalChildID(SumoXMLTag childTag)
gererate a new ID for an additional child
GUIGlID getGlID() const
Returns the numerical id of the object.
Position getPositionInformation() const
Returns the cursor&#39;s x/y position within the network.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
std::string myEndPosition
The position this stopping place is located at (optional, if empty takes the lane lenght) ...
empty max
Position mySignPos
The position of the sign.
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:613
double myWidth
width of Parking Area
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
bool myOnRoad
Whether vehicles stay on the road.
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1153
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1059
GNELane * changeLane(GNELane *oldLane, const std::string &newLaneID)
change lane of additional
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry(bool updateGrid) function) ...
void draw(double size=0.5) const
draw lock icon
GNEParkingArea(const std::string &id, GNELane *lane, GNEViewNet *viewNet, const std::string &startPos, const std::string &endPos, const std::string &name, bool friendlyPosition, int roadSideCapacity, bool onRoad, double width, const std::string &length, double angle, bool blockMovement)
Constructor.