Eclipse SUMO - Simulation of Urban MObility
GNEChargingStation.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-2019 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 class for visualizing chargingStation geometry (adapted from GUILaneWrapper)
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
30 #include <utils/gui/div/GLHelper.h>
33 
34 #include "GNEChargingStation.h"
35 
36 // ===========================================================================
37 // member method definitions
38 // ===========================================================================
39 
40 GNEChargingStation::GNEChargingStation(const std::string& id, GNELane* lane, GNEViewNet* viewNet, const std::string& startPos, const std::string& endPos, const std::string& name,
41  double chargingPower, double efficiency, bool chargeInTransit, SUMOTime chargeDelay, bool friendlyPosition, bool blockMovement) :
42  GNEStoppingPlace(id, viewNet, GLO_CHARGING_STATION, SUMO_TAG_CHARGING_STATION, lane, startPos, endPos, name, friendlyPosition, blockMovement),
43  myChargingPower(chargingPower),
44  myEfficiency(efficiency),
45  myChargeInTransit(chargeInTransit),
46  myChargeDelay(chargeDelay) {
47 }
48 
49 
51 
52 
53 void
55  // Get value of option "lefthand"
56  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
57 
58  // Update common geometry of stopping place
60 
61  // Obtain a copy of the shape
62  PositionVector tmpShape = myGeometry.shape;
63 
64  // Move shape to side
65  tmpShape.move2side(1.5 * offsetSign);
66 
67  // Get position of the sign
68  mySignPos = tmpShape.getLineCenter();
69 
70  // Set block icon position
72 
73  // Set block icon rotation, and using their rotation for sign
75 }
76 
77 
80  return myGeometry.shape.getBoxBoundary().grow(10);
81 }
82 
83 
84 void
86  // Get exaggeration
87  const double exaggeration = s.addSize.getExaggeration(s, this);
88  // Push name
89  glPushName(getGlID());
90  // Push base matrix
91  glPushMatrix();
92  // Traslate matrix
93  glTranslated(0, 0, getType());
94  // Set Color
95  if (drawUsingSelectColor()) {
97  } else {
99  }
100  // Draw base
102  // Check if the distance is enought to draw details and if is being drawn for selecting
103  if (s.drawForSelecting) {
104  // only draw circle depending of distance between sign and mouse cursor
106  // Add a draw matrix for details
107  glPushMatrix();
108  // Start drawing sign traslating matrix to signal position
109  glTranslated(mySignPos.x(), mySignPos.y(), 0);
110  // scale matrix depending of the exaggeration
111  glScaled(exaggeration, exaggeration, 1);
112  // set color
114  // Draw circle
116  // pop draw matrix
117  glPopMatrix();
118  }
119  } else if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, exaggeration)) {
120  // Push matrix for details
121  glPushMatrix();
122  // draw power depending of detailSettings
123  if (s.drawDetail(s.detailSettings.stoppingPlaceText, exaggeration)) {
124  // push a new matrix for charging power
125  glPushMatrix();
126  // draw line with a color depending of the selection status
127  if (drawUsingSelectColor()) {
129  } else {
131  }
132  // pop matrix for charging power
133  glPopMatrix();
134  }
135  // Set position over sign
136  glTranslated(mySignPos.x(), mySignPos.y(), 0);
137  // Scale matrix
138  glScaled(exaggeration, exaggeration, 1);
139  // Set base color
140  if (drawUsingSelectColor()) {
142  } else {
144  }
145  // Draw extern
147  // Move to top
148  glTranslated(0, 0, .1);
149  // Set sign color
150  if (drawUsingSelectColor()) {
152  } else {
154  }
155  // Draw internt sign
157  // Draw sign 'C' depending of detail settings
158  if (s.drawDetail(s.detailSettings.stoppingPlaceText, exaggeration)) {
159  if (drawUsingSelectColor()) {
161  } else {
163  }
164  }
165  // Pop sign matrix
166  glPopMatrix();
167  // Draw icon
168  myBlockIcon.drawIcon(s, exaggeration);
169  }
170  // Pop base matrix
171  glPopMatrix();
172  // Draw name if isn't being drawn for selecting
174  if (s.addFullName.show && (myAdditionalName != "") && !s.drawForSelecting) {
176  }
177  // check if dotted contour has to be drawn
178  if (myViewNet->getDottedAC() == this) {
180  }
181  // Pop name matrix
182  glPopName();
183  // draw demand element children
184  for (const auto& i : getDemandElementChildren()) {
185  if (!i->getTagProperty().isPlacedInRTree()) {
186  i->drawGL(s);
187  }
188  }
189 }
190 
191 
192 std::string
194  switch (key) {
195  case SUMO_ATTR_ID:
196  return getAdditionalID();
197  case SUMO_ATTR_LANE:
198  return getLaneParents().front()->getID();
199  case SUMO_ATTR_STARTPOS:
200  return toString(myStartPosition);
201  case SUMO_ATTR_ENDPOS:
202  return myEndPosition;
203  case SUMO_ATTR_NAME:
204  return myAdditionalName;
208  return toString(myChargingPower);
210  return toString(myEfficiency);
212  return toString(myChargeInTransit);
214  return time2string(myChargeDelay);
216  return toString(myBlockMovement);
217  case GNE_ATTR_SELECTED:
219  case GNE_ATTR_GENERIC:
220  return getGenericParametersStr();
221  default:
222  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
223  }
224 }
225 
226 
227 void
228 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
229  if (value == getAttribute(key)) {
230  return; //avoid needless changes, later logic relies on the fact that attributes have changed
231  }
232  switch (key) {
233  case SUMO_ATTR_ID:
234  case SUMO_ATTR_LANE:
235  case SUMO_ATTR_STARTPOS:
236  case SUMO_ATTR_ENDPOS:
237  case SUMO_ATTR_NAME:
244  case GNE_ATTR_SELECTED:
245  case GNE_ATTR_GENERIC:
246  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
247  break;
248  default:
249  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
250  }
251 }
252 
253 
254 bool
255 GNEChargingStation::isValid(SumoXMLAttr key, const std::string& value) {
256  switch (key) {
257  case SUMO_ATTR_ID:
258  return isValidAdditionalID(value);
259  case SUMO_ATTR_LANE:
260  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
261  return true;
262  } else {
263  return false;
264  }
265  case SUMO_ATTR_STARTPOS:
266  if (value.empty()) {
267  return true;
268  } else if (canParse<double>(value)) {
269  return checkStoppinPlacePosition(value, myEndPosition, getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength(), myFriendlyPosition);
270  } else {
271  return false;
272  }
273  case SUMO_ATTR_ENDPOS:
274  if (value.empty()) {
275  return true;
276  } else if (canParse<double>(value)) {
277  return checkStoppinPlacePosition(myStartPosition, value, getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength(), myFriendlyPosition);
278  } else {
279  return false;
280  }
281  case SUMO_ATTR_NAME:
284  return canParse<bool>(value);
286  return (canParse<double>(value) && parse<double>(value) >= 0);
288  return (canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1);
290  return canParse<bool>(value);
292  return canParse<SUMOTime>(value);
294  return canParse<bool>(value);
295  case GNE_ATTR_SELECTED:
296  return canParse<bool>(value);
297  case GNE_ATTR_GENERIC:
298  return isGenericParametersValid(value);
299  default:
300  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
301  }
302 }
303 
304 // ===========================================================================
305 // private
306 // ===========================================================================
307 
308 void
309 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value) {
310  switch (key) {
311  case SUMO_ATTR_ID:
312  changeAdditionalID(value);
313  break;
314  case SUMO_ATTR_LANE:
315  changeLaneParents(this, value);
316  break;
317  case SUMO_ATTR_STARTPOS:
318  myStartPosition = value;
319  break;
320  case SUMO_ATTR_ENDPOS:
321  myEndPosition = value;
322  break;
323  case SUMO_ATTR_NAME:
324  myAdditionalName = value;
325  break;
327  myFriendlyPosition = parse<bool>(value);
328  break;
330  myChargingPower = parse<double>(value);
331  break;
333  myEfficiency = parse<double>(value);
334  break;
336  myChargeInTransit = parse<bool>(value);
337  break;
339  myChargeDelay = parse<SUMOTime>(value);
340  break;
342  myBlockMovement = parse<bool>(value);
343  break;
344  case GNE_ATTR_SELECTED:
345  if (parse<bool>(value)) {
347  } else {
349  }
350  break;
351  case GNE_ATTR_GENERIC:
353  break;
354  default:
355  throw InvalidArgument(getTagStr() + "attribute '" + toString(key) + "' not allowed");
356  }
357 }
358 
359 
360 /****************************************************************************/
long long int SUMOTime
Definition: SUMOTime.h:35
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:182
GUIVisualizationTextSettings addName
std::vector< double > shapeRotations
The rotations of the single shape parts.
Definition: GNEAdditional.h:74
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
a chargingStation
Stores the information about how to visualize structures.
static const RGBColor chargingStation
color for chargingStations
Allow/disallow charge in transit in Charging Stations.
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
static const double stoppingPlaceText
details for stopping place texts
Position getPositionInView() const
Returns position of additional in view.
static bool checkStoppinPlacePosition(const std::string &startPosStr, const std::string &endPosStr, const double laneLength, const bool friendlyPos)
check if the position of an stoppingPlace over a lane is valid (without modifications) ...
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
double x() const
Returns the x-position.
Definition: Position.h:57
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:668
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
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:46
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.
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
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)
SUMOTime myChargeDelay
delay in the starting of charge
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:348
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
double myEfficiency
efficiency of the charge
Position getLineCenter() const
get line center
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
double rotation
The rotation of the block icon.
const std::vector< GNEDemandElement * > & getDemandElementChildren() const
return vector of demand elements that have as Parent this edge (For example, Calibrators) ...
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
int getCircleResolution() const
function to calculate circle resolution for all circles drawn in drawGL(...) functions ...
GUIVisualizationSizeSettings addSize
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:48
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
PositionVector shape
The shape of the additional element.
Definition: GNEAdditional.h:68
RGBColor selectionColor
basic selection color
A list of positions.
double scaledSize(double scale, double constFactor=0.1) const
get scale size
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
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
const std::vector< GNELane * > & getLaneParents() const
get lanes of VSS
block movement of a graphic element
void updateGeometry()
update pre-computed geometry information
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
~GNEChargingStation()
Destructor.
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
bool myChargeInTransit
enable or disable charge in transit
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
static void drawShapeDottedContourAroundShape(const GUIVisualizationSettings &s, 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:461
static const double myCircleWidth
circle width resolution for all stopping places
double myChargingPower
Charging power pro timestep.
std::vector< double > shapeLengths
The lengths of the single shape parts.
Definition: GNEAdditional.h:77
GNEChargingStation(const std::string &id, GNELane *lane, GNEViewNet *viewNet, const std::string &startPos, const std::string &endPos, const std::string &name, double chargingPower, double efficiency, bool chargeInTransit, SUMOTime chargeDelay, bool friendlyPosition, bool blockMovement)
Constructor of charging station.
GUIVisualizationDetailSettings detailSettings
detail settings
void changeLaneParents(GNEShape *elementChild, const std::string &newLaneIDs)
change edge parents of a shape
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
Definition: GNEViewNet.cpp:939
GUIVisualizationTextSettings addFullName
AdditionalGeometry myGeometry
geometry to be precomputed in updateGeometry(...)
const std::string & getTagStr() const
get tag assigned to this object in string format
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
element is selected
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
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
static const RGBColor chargingStation_sign
color for chargingStation sign
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
GUIGlID getGlID() const
Returns the numerical id of the object.
std::string getAttribute(SumoXMLAttr key) const
Eficiency of the charge in Charging Stations.
static const double stoppingPlaceDetails
details for stopping places
Position getPositionInformation() const
Returns the cursor&#39;s x/y position within the network.
GUIVisualizationColorSettings colorSettings
color settings
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
std::string myEndPosition
The position this stopping place is located at (optional, if empty takes the lane lenght) ...
empty max
Delay in the charge of charging stations.
Position mySignPos
The position of the sign.
void drawIcon(const GUIVisualizationSettings &s, const double exaggeration, const double size=0.5) const
draw lock icon
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
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1179
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry() function)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...