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 #include <config.h>
22 
23 #include <string>
24 #include <iostream>
25 #include <utility>
30 #include <utils/common/ToString.h>
31 #include <utils/geom/GeomHelper.h>
36 #include <utils/gui/div/GLHelper.h>
44 #include <netedit/GNEUndoList.h>
45 #include <netedit/GNENet.h>
47 #include <netedit/GNEViewNet.h>
48 #include <netedit/GNEViewParent.h>
49 
50 #include "GNEParkingArea.h"
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 
57 GNEParkingArea::GNEParkingArea(const std::string& id, GNELane* lane, GNEViewNet* viewNet, const std::string& startPos, const std::string& endPos, const std::string& name,
58  bool friendlyPosition, int roadSideCapacity, double width, const std::string& length, double angle, bool blockMovement) :
59  GNEStoppingPlace(id, viewNet, GLO_PARKING_AREA, SUMO_TAG_PARKING_AREA, lane, startPos, endPos, name, friendlyPosition, blockMovement),
60  myRoadSideCapacity(roadSideCapacity),
61  myWidth(width),
62  myLength(length),
63  myAngle(angle) {
64 }
65 
66 
68 
69 
70 void
72  // first check if object has to be removed from grid (SUMOTree)
73  if (updateGrid) {
75  }
76 
77  // Get value of option "lefthand"
78  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
79 
80  // Update common geometry of stopping place
82 
83  // Obtain a copy of the shape
84  PositionVector tmpShape = myShape;
85 
86  // Move shape to side
87  tmpShape.move2side(1.5 * offsetSign);
88 
89  // Get position of the sign
90  mySignPos = tmpShape.getLineCenter();
91 
92  // Set block icon position
94 
95  // Set block icon rotation, and using their rotation for sign
97 
98  // last step is to check if object has to be added into grid (SUMOTree) again
99  if (updateGrid) {
101  }
102 }
103 
104 
105 void
107  // obtain circle resolution
108  int circleResolution = getCircleResolution(s);
109  // Obtain exaggeration of the draw
110  const double exaggeration = s.addSize.getExaggeration(s);
111  // Push name
112  glPushName(getGlID());
113  // Push base matrix
114  glPushMatrix();
115  // Traslate matrix
116  glTranslated(0, 0, getType());
117  // Set Color
120  } else {
121  GLHelper::setColor(RGBColor(83, 89, 172, 255));
122  }
123  // Draw base
125  // Check if the distance is enought to draw details and if is being drawn for selecting
126  if (s.drawForSelecting) {
127  // only draw circle depending of distance between sign and mouse cursor
129  // Add a draw matrix for details
130  glPushMatrix();
131  // Start drawing sign traslating matrix to signal position
132  glTranslated(mySignPos.x(), mySignPos.y(), 0);
133  // scale matrix depending of the exaggeration
134  glScaled(exaggeration, exaggeration, 1);
135  // set color
137  // Draw circle
138  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
139  // pop draw matrix
140  glPopMatrix();
141  }
142  } else if (s.scale * exaggeration >= 10) {
143  // Push matrix for details
144  glPushMatrix();
145  // Set position over sign
146  glTranslated(mySignPos.x(), mySignPos.y(), 0);
147  // Scale matrix
148  glScaled(exaggeration, exaggeration, 1);
149  // Set base color
152  } else {
153  GLHelper::setColor(RGBColor(83, 89, 172, 255));
154  }
155  // Draw extern
156  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
157  // Move to top
158  glTranslated(0, 0, .1);
159  // Set sign color
162  } else {
163  GLHelper::setColor(RGBColor(177, 184, 186, 171));
164  }
165  // Draw internt sign
166  GLHelper::drawFilledCircle(myCircleInWidth, circleResolution);
167  // Draw sign 'C'
168  if (s.scale * exaggeration >= 4.5) {
171  } else {
172  GLHelper::drawText("P", Position(), .1, myCircleInText, RGBColor(83, 89, 172, 255), myBlockIconRotation);
173  }
174  }
175  // Pop sign matrix
176  glPopMatrix();
177  // Draw icon
179  }
180  // Pop base matrix
181  glPopMatrix();
182  // Draw name if isn't being drawn for selecting
183  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
184  if (s.addFullName.show && (myAdditionalName != "") && !s.drawForSelecting) {
186  }
187  // check if dotted contour has to be drawn
188  if (!s.drawForSelecting && (myViewNet->getACUnderCursor() == this)) {
190  }
191  // Pop name matrix
192  glPopName();
193 }
194 
195 
196 std::string
198  switch (key) {
199  case SUMO_ATTR_ID:
200  return getAdditionalID();
201  case SUMO_ATTR_LANE:
202  return myLane->getID();
203  case SUMO_ATTR_STARTPOS:
204  return toString(myStartPosition);
205  case SUMO_ATTR_ENDPOS:
206  return myEndPosition;
207  case SUMO_ATTR_NAME:
208  return myAdditionalName;
213  case SUMO_ATTR_WIDTH:
214  return toString(myWidth);
215  case SUMO_ATTR_LENGTH:
216  return myLength;
217  case SUMO_ATTR_ANGLE:
218  return toString(myAngle);
220  return toString(myBlockMovement);
221  case GNE_ATTR_SELECTED:
223  case GNE_ATTR_GENERIC:
224  return getGenericParametersStr();
225  default:
226  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
227  }
228 }
229 
230 
231 void
232 GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
233  if (value == getAttribute(key)) {
234  return; //avoid needless changes, later logic relies on the fact that attributes have changed
235  }
236  switch (key) {
237  case SUMO_ATTR_ID: {
238  // change ID of Entry
239  undoList->p_add(new GNEChange_Attribute(this, key, value));
240  // Change Ids of all Parking Spaces
241  for (auto i : myAdditionalChilds) {
243  }
244  break;
245  }
246  case SUMO_ATTR_LANE:
247  case SUMO_ATTR_STARTPOS:
248  case SUMO_ATTR_ENDPOS:
249  case SUMO_ATTR_NAME:
252  case SUMO_ATTR_WIDTH:
253  case SUMO_ATTR_LENGTH:
254  case SUMO_ATTR_ANGLE:
256  case GNE_ATTR_SELECTED:
257  case GNE_ATTR_GENERIC:
258  undoList->p_add(new GNEChange_Attribute(this, key, value));
259  break;
260  default:
261  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
262  }
263 }
264 
265 
266 bool
267 GNEParkingArea::isValid(SumoXMLAttr key, const std::string& value) {
268  switch (key) {
269  case SUMO_ATTR_ID:
270  return isValidAdditionalID(value);
271  case SUMO_ATTR_LANE:
272  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
273  return true;
274  } else {
275  return false;
276  }
277  case SUMO_ATTR_STARTPOS:
278  if (value.empty()) {
279  return true;
280  } else {
281  if (canParse<double>(value)) {
282  if (canParse<double>(myEndPosition)) {
283  // Check that new start Position is smaller that end position
284  return (parse<double>(value) < parse<double>(myEndPosition));
285  } else {
286  return true;
287  }
288  } else {
289  return false;
290  }
291  }
292  case SUMO_ATTR_ENDPOS:
293  if (value.empty()) {
294  return true;
295  } else {
296  if (canParse<double>(value)) {
297  if (canParse<double>(myStartPosition)) {
298  // Check that new start Position is smaller that end position
299  return (parse<double>(myStartPosition) < parse<double>(value));
300  } else {
301  return true;
302  }
303  } else {
304  return false;
305  }
306  }
307  case SUMO_ATTR_NAME:
310  return canParse<bool>(value);
312  return canParse<double>(value) && (parse<double>(value) >= 0);
313  case SUMO_ATTR_WIDTH:
314  return canParse<double>(value) && (parse<double>(value) >= 0);
315  case SUMO_ATTR_LENGTH:
316  if (value.empty()) {
317  return true;
318  } else {
319  return canParse<double>(value) && (parse<double>(value) >= 0);
320  }
321  case SUMO_ATTR_ANGLE:
322  return canParse<double>(value);
324  return canParse<bool>(value);
325  case GNE_ATTR_SELECTED:
326  return canParse<bool>(value);
327  case GNE_ATTR_GENERIC:
328  return isGenericParametersValid(value);
329  default:
330  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
331  }
332 }
333 
334 // ===========================================================================
335 // private
336 // ===========================================================================
337 
338 void
339 GNEParkingArea::setAttribute(SumoXMLAttr key, const std::string& value) {
340  switch (key) {
341  case SUMO_ATTR_ID:
342  changeAdditionalID(value);
343  break;
344  case SUMO_ATTR_LANE:
345  myLane = changeLane(myLane, value);
346  break;
347  case SUMO_ATTR_STARTPOS:
348  myStartPosition = value;
349  break;
350  case SUMO_ATTR_ENDPOS:
351  myEndPosition = value;
352  break;
353  case SUMO_ATTR_NAME:
354  myAdditionalName = value;
355  break;
357  myFriendlyPosition = parse<bool>(value);
358  break;
360  myRoadSideCapacity = parse<int>(value);
361  break;
362  case SUMO_ATTR_WIDTH:
363  myWidth = parse<double>(value);
364  break;
365  case SUMO_ATTR_LENGTH:
366  myLength = value;
367  break;
368  case SUMO_ATTR_ANGLE:
369  myAngle = parse<double>(value);
370  break;
372  myBlockMovement = parse<bool>(value);
373  break;
374  case GNE_ATTR_SELECTED:
375  if (parse<bool>(value)) {
377  } else {
379  }
380  break;
381  case GNE_ATTR_GENERIC:
383  break;
384  default:
385  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
386  }
387  // After setting attribute always update Geometry
388  updateGeometry(true);
389 }
390 
391 
392 /****************************************************************************/
double myAngle
Angle of Parking Area.
const GNEAttributeCarrier * getACUnderCursor() const
get AttributeCarrier under cursor
double scale
information about a lane&#39;s width (temporary, used for a single view)
void setBlockIconRotation(GNELane *additionalLane=nullptr)
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
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:61
static const double myCircleInWidth
inner circle width resolution for all stopping places
double x() const
Returns the x-position.
Definition: Position.h:56
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
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.
std::vector< double > myShapeRotations
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
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:697
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
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:1230
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
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:1167
double distanceSquaredTo(const Position &p2) const
returns the square of the distance to another position
Definition: Position.h:238
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
std::vector< double > myShapeLengths
The lengths of the shape parts.
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
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:525
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
GUIVisualizationTextSettings addFullName
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
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.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
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) ...
static const RGBColor selectionColor
Definition: GNENet.h:96
empty max
Position mySignPos
The position of the sign.
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:586
double myWidth
width of Parking Area
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1160
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1066
double myBlockIconRotation
The rotation of the block icon.
GNELane * changeLane(GNELane *oldLane, const std::string &newLaneID)
change lane of additional
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, double width, const std::string &length, double angle, bool blockMovement)
Constructor.
Position myBlockIconPosition
position of the block icon
SumoXMLTag getTag() const
get XML Tag assigned to this object