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.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // A class for visualizing chargingStation geometry (adapted from GUILaneWrapper)
19 /****************************************************************************/
20 #include <config.h>
21 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
27 #include <utils/gui/div/GLHelper.h>
31 
32 #include "GNEChargingStation.h"
33 
34 // ===========================================================================
35 // member method definitions
36 // ===========================================================================
37 
40  nullptr, 0, 0, "", false, Parameterised::Map()) {
41  // reset default values
43 }
44 
45 
46 GNEChargingStation::GNEChargingStation(const std::string& id, GNELane* lane, GNENet* net, const double startPos, const double endPos,
47  const std::string& name, double chargingPower, double efficiency, bool chargeInTransit, SUMOTime chargeDelay,
48  const std::string& chargeType, const SUMOTime waitingTime, bool friendlyPosition, const Parameterised::Map& parameters) :
50  lane, startPos, endPos, name, friendlyPosition, parameters),
51  myChargingPower(chargingPower),
52  myEfficiency(efficiency),
53  myChargeInTransit(chargeInTransit),
54  myChargeDelay(chargeDelay),
55  myChargeType(chargeType),
56  myWaitingTime(waitingTime) {
57  // update centering boundary without updating grid
59 }
60 
61 
63 
64 
65 void
67  device.openTag(getTagProperty().getTag());
68  device.writeAttr(SUMO_ATTR_ID, getID());
69  if (!myAdditionalName.empty()) {
71  }
72  device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
75  }
78  }
79  if (myFriendlyPosition) {
80  device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
81  }
84  }
87  }
90  }
93  }
96  }
99  }
102  }
103  // write parameters (Always after children to avoid problems with additionals.xsd)
104  writeParams(device);
105  device.closeTag();
106 }
107 
108 
109 void
111  // Get value of option "lefthand"
112  const double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
113 
114  // Update common geometry of stopping place
116 
117  // Obtain a copy of the shape
119 
120  // Move shape to side
122 
123  // Get position of the sign
124  mySignPos = tmpShape.getLineCenter();
125 }
126 
127 
128 void
130  // first check if additional has to be drawn
132  // Obtain exaggeration of the draw
133  const double chargingStationExaggeration = getExaggeration(s);
134  // check if draw moving geometry points
135  const bool movingGeometryPoints = drawMovingGeometryPoints(false);
136  // get detail level
137  const auto d = s.getDetailLevel(chargingStationExaggeration);
138  // draw geometry only if we'rent in drawForObjectUnderCursor mode
139  if (!s.drawForViewObjectsHandler) {
140  // declare colors
141  RGBColor baseColor, signColor;
142  // set colors
143  if (mySpecialColor) {
144  baseColor = *mySpecialColor;
145  signColor = baseColor.changedBrightness(-32);
146  } else if (drawUsingSelectColor()) {
148  signColor = baseColor.changedBrightness(-32);
149  } else {
150  baseColor = s.colorSettings.chargingStationColor;
152  }
153  // draw parent and child lines
155  // Add a layer matrix
157  // translate to front
159  // set base color
160  GLHelper::setColor(baseColor);
161  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
163  // draw charging power and efficiency
164  drawLines(d, {toString(myChargingPower)}, baseColor);
165  // draw sign
166  drawSign(d, chargingStationExaggeration, baseColor, signColor, "C");
167  // draw geometry points
168  if (movingGeometryPoints && (myStartPosition != INVALID_DOUBLE)) {
170  }
171  if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {
173  }
174  // pop layer matrix
176  // draw lock icon
177  GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().getCentroid(), chargingStationExaggeration);
178  // Draw additional ID
179  drawAdditionalID(s);
180  // draw additional name
182  // draw dotted contour
184  // draw dotted contours for geometry points
187  }
188  // draw stoppingPlace children
190  // calculate contour
192  }
193 }
194 
195 
196 std::string
198  switch (key) {
199  case SUMO_ATTR_ID:
200  return getMicrosimID();
201  case SUMO_ATTR_LANE:
202  return getParentLanes().front()->getID();
203  case SUMO_ATTR_STARTPOS:
205  return toString(myStartPosition);
206  } else {
207  return "";
208  }
209  case SUMO_ATTR_ENDPOS:
210  if (myEndPosition != INVALID_DOUBLE) {
211  return toString(myEndPosition);
212  } else {
213  return "";
214  }
215  case SUMO_ATTR_NAME:
216  return myAdditionalName;
220  return toString(myChargingPower);
222  return toString(myEfficiency);
224  return toString(myChargeInTransit);
226  return time2string(myChargeDelay);
228  return myChargeType;
230  return time2string(myWaitingTime);
232  return myParkingAreaID;
233  case GNE_ATTR_SELECTED:
235  case GNE_ATTR_PARAMETERS:
236  return getParametersStr();
238  return "";
239  default:
240  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
241  }
242 }
243 
244 
245 void
246 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
247  switch (key) {
248  case SUMO_ATTR_ID:
249  case SUMO_ATTR_LANE:
250  case SUMO_ATTR_STARTPOS:
251  case SUMO_ATTR_ENDPOS:
252  case SUMO_ATTR_NAME:
261  case GNE_ATTR_SELECTED:
262  case GNE_ATTR_PARAMETERS:
264  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
265  break;
266  default:
267  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
268  }
269 }
270 
271 
272 bool
273 GNEChargingStation::isValid(SumoXMLAttr key, const std::string& value) {
274  switch (key) {
275  case SUMO_ATTR_ID:
276  return isValidAdditionalID(value);
277  case SUMO_ATTR_LANE:
278  if (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr) {
279  return true;
280  } else {
281  return false;
282  }
283  case SUMO_ATTR_STARTPOS:
284  if (value.empty()) {
285  return true;
286  } else if (canParse<double>(value)) {
287  return SUMORouteHandler::isStopPosValid(parse<double>(value), getAttributeDouble(SUMO_ATTR_ENDPOS), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
288  } else {
289  return false;
290  }
291  case SUMO_ATTR_ENDPOS:
292  if (value.empty()) {
293  return true;
294  } else if (canParse<double>(value)) {
295  return SUMORouteHandler::isStopPosValid(getAttributeDouble(SUMO_ATTR_STARTPOS), parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
296  } else {
297  return false;
298  }
299  case SUMO_ATTR_NAME:
302  return canParse<bool>(value);
304  return (canParse<double>(value) && parse<double>(value) >= 0);
306  if (canParse<double>(value)) {
307  const double efficiency = parse<double>(value);
308  return (efficiency >= 0) && (efficiency <= 1);
309  } else {
310  return false;
311  }
313  return canParse<bool>(value);
315  return canParse<SUMOTime>(value) && parse<SUMOTime>(value) >= 0;
316  case SUMO_ATTR_CHARGETYPE: {
317  const auto validValues = myTagProperty.getAttributeProperties(key).getDiscreteValues();
318  return std::find(validValues.begin(), validValues.end(), value) != validValues.end();
319  }
321  return canParse<SUMOTime>(value) && parse<SUMOTime>(value) >= 0;
323  return isValidAdditionalID(value);
324  case GNE_ATTR_SELECTED:
325  return canParse<bool>(value);
326  case GNE_ATTR_PARAMETERS:
327  return areParametersValid(value);
328  default:
329  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
330  }
331 }
332 
333 // ===========================================================================
334 // private
335 // ===========================================================================
336 
337 void
338 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value) {
339  switch (key) {
340  case SUMO_ATTR_ID:
341  // update microsimID
342  setAdditionalID(value);
343  break;
344  case SUMO_ATTR_LANE:
346  break;
347  case SUMO_ATTR_STARTPOS:
348  if (value == "") {
350  } else {
351  myStartPosition = parse<double>(value);
352  }
353  break;
354  case SUMO_ATTR_ENDPOS:
355  if (value == "") {
357  } else {
358  myEndPosition = parse<double>(value);
359  }
360  break;
361  case SUMO_ATTR_NAME:
362  myAdditionalName = value;
363  break;
365  myFriendlyPosition = parse<bool>(value);
366  break;
368  myChargingPower = parse<double>(value);
369  break;
371  myEfficiency = parse<double>(value);
372  break;
374  myChargeInTransit = parse<bool>(value);
375  break;
377  myChargeDelay = parse<SUMOTime>(value);
378  break;
380  myChargeType = value;
381  break;
383  myWaitingTime = parse<SUMOTime>(value);
384  break;
386  myParkingAreaID = value;
387  break;
388  case GNE_ATTR_SELECTED:
389  if (parse<bool>(value)) {
391  } else {
393  }
394  break;
395  case GNE_ATTR_PARAMETERS:
396  setParametersStr(value);
397  break;
399  shiftLaneIndex();
400  break;
401  default:
402  throw InvalidArgument(getTagStr() + "attribute '" + toString(key) + "' not allowed");
403  }
404 }
405 
406 
407 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
@ GLO_CHARGING_STATION
a chargingStation
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ CHARGINGSTATION
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_LANE
@ SUMO_ATTR_WAITINGTIME
@ SUMO_ATTR_PARKING_AREA
@ SUMO_ATTR_CHARGETYPE
Charge type (fuel or electric)
@ SUMO_ATTR_ENDPOS
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_CHARGEINTRANSIT
Allow/disallow charge in transit in Charging Stations.
@ SUMO_ATTR_NAME
@ SUMO_ATTR_CHARGINGPOWER
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_EFFICIENCY
Eficiency of the charge in Charging Stations.
@ SUMO_ATTR_ID
@ SUMO_ATTR_CHARGEDELAY
Delay in the charge of charging stations (different of waiting time)
@ GNE_ATTR_SHIFTLANEINDEX
shift lane index (only used by elements over lanes)
const double INVALID_DOUBLE
invalid double
Definition: StdDefs.h:64
T MIN2(T a, T b)
Definition: StdDefs.h:76
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:654
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
bool isValidAdditionalID(const std::string &value) const
check if a new additional ID is valid
void drawRightGeometryPoint(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false) const
draw right geometry point
void setAdditionalID(const std::string &newID)
set additional ID
GNEContour myAdditionalContour
variable used for draw additional contours
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void drawAdditionalID(const GUIVisualizationSettings &s) const
draw additional ID
void replaceAdditionalParentLanes(const std::string &value)
replace additional parent lanes
void shiftLaneIndex()
shift lane index
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
std::string myAdditionalName
name of additional
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
void drawDemandElementChildren(const GUIVisualizationSettings &s) const
draw demand element children
const RGBColor * mySpecialColor
pointer to special color (used for drawing Additional with a certain color, mainly used for selection...
bool drawMovingGeometryPoints(const bool ignoreShift) const
check if draw additional extrem geometry points
void drawLeftGeometryPoint(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false) const
draw left geometry point
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
void resetDefaultValues()
reset attribute carrier to their default values
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
const std::vector< std::string > & getDiscreteValues() const
get discrete values
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
std::string getAttribute(SumoXMLAttr key) const
std::string myChargeType
charging type
~GNEChargingStation()
Destructor.
std::string myParkingAreaID
parking area ID
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNEChargingStation(GNENet *net)
default Constructor of charging station
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
SUMOTime myChargeDelay
delay in the starting of charge
bool myChargeInTransit
enable or disable charge in transit
double myChargingPower
Charging power pro timestep.
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
double myEfficiency
efficiency of the charge
void updateGeometry()
update pre-computed geometry information
SUMOTime myWaitingTime
waiting time before start charging
void drawDottedContourGeometryPoints(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const PositionVector &shape, const double radius, const double scale, const double lineWidth) const
draw dotted contour for geometry points
Definition: GNEContour.cpp:307
void drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
drawing contour functions
Definition: GNEContour.cpp:265
const std::vector< GNELane * > & getParentLanes() const
get parent lanes
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
GNELane * retrieveLane(const std::string &id, bool hardFail=true, bool checkVolatileChange=false) const
get lane by id
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:122
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2055
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
virtual double getAttributeDouble(SumoXMLAttr key) const
void drawSign(const GUIVisualizationSettings::Detail d, const double exaggeration, const RGBColor &baseColor, const RGBColor &signColor, const std::string &word) const
draw sign
bool myFriendlyPosition
Flag for friendly position.
void drawLines(const GUIVisualizationSettings::Detail d, const std::vector< std::string > &lines, const RGBColor &color) const
draw lines
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
void calculateStoppingPlaceContour(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double width, const bool movingGeometryPoints) const
check object in view
double myEndPosition
The position this stopping place is located at (-1 means empty)
Position mySignPos
The position of the sign.
double myStartPosition
The relative start position this stopping place is located at (-1 means empty)
const GNEAttributeProperties & getAttributeProperties(SumoXMLAttr attr) const
get attribute (throw error if doesn't exist)
const std::string & getDefaultValue(SumoXMLAttr attr) const
return the default value of the attribute of an element
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:727
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
static void drawGeometry(const GUIVisualizationSettings::Detail d, const GUIGeometry &geometry, const double width, double offset=0)
draw geometry
const PositionVector & getShape() const
The shape of the additional element.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:156
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:143
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
Stores the information about how to visualize structures.
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
GUIVisualizationStoppingPlaceSettings stoppingPlaceSettings
StoppingPlace settings.
bool drawForViewObjectsHandler
whether drawing is performed for the purpose of selecting objects in view using ViewObjectsHandler
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:60
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
A list of positions.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain amount
Position getLineCenter() const
get line center
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:200
static bool isStopPosValid(const double startPos, const double endPos, const double laneLength, const double minLength, const bool friendlyPos)
check if start and end position of a stop is valid
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position position, const double exaggeration, const double size=0.5, const double offsetx=0, const double offsety=0)
draw lock icon
static const RGBColor connectionColor
connection color
RGBColor chargingStationColor
color for chargingStations
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
RGBColor chargingStationColorSign
color for chargingStation sign
static const double segmentWidthSmall
width of small dotted contour segments
static const double segmentWidth
width of dotted contour segments
static const double additionalGeometryPointRadius
moving additional geometry point radius
static const double stoppingPlaceSignOffset
busStop offset
static const double chargingStationWidth
chargingStation width