Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2026 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
25#include <netedit/GNENet.h>
29
30#include "GNEChargingStation.h"
31
32// ===========================================================================
33// member method definitions
34// ===========================================================================
35
39
40
41GNEChargingStation::GNEChargingStation(const std::string& id, GNENet* net, FileBucket* fileBucket, GNELane* lane,
42 const double startPos, const double endPos, const std::string& name, const double chargingPower,
43 const double totalPower, const double efficiency, const bool chargeInTransit, const SUMOTime chargeDelay,
44 const std::string& chargeType, const SUMOTime waitingTime, const std::string& parkingAreaID,
45 const bool friendlyPosition, const Parameterised::Map& parameters) :
46 GNEStoppingPlace(id, net, fileBucket, SUMO_TAG_CHARGING_STATION, lane, startPos, endPos, name, friendlyPosition, RGBColor::INVISIBLE, 0, parameters),
47 myChargingPower(chargingPower),
48 myTotalPower(totalPower),
49 myEfficiency(efficiency),
50 myChargeInTransit(chargeInTransit),
51 myChargeDelay(chargeDelay),
52 myChargeType(chargeType),
53 myWaitingTime(waitingTime),
54 myParkingAreaID(parkingAreaID) {
55 // update centering boundary without updating grid
57}
58
59
61
62
63void
65 device.openTag(getTagProperty()->getTag());
66 // write common attributes
68 // write specific attributes
71 }
74 }
77 }
80 }
83 }
86 }
89 }
92 }
93 // write parameters (Always after children to avoid problems with additionals.xsd)
94 XMLHelpers::writeParams(device, *this);
95 device.closeTag();
96}
97
98
99void
101 // Get value of option "lefthand"
102 const double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
103
104 // Update common geometry of stopping place
106
107 // Obtain a copy of the shape
109
110 // Move shape to side
112
113 // Get position of the sign
114 mySymbolPosition = tmpShape.getLineCenter();
115}
116
117
118void
120 // first check if additional has to be drawn
122 // Obtain exaggeration of the draw
123 const double chargingStationExaggeration = getExaggeration(s);
124 // check if draw moving geometry points
125 const bool movingGeometryPoints = drawMovingGeometryPoints();
126 // get detail level
127 const auto d = s.getDetailLevel(chargingStationExaggeration);
128 // draw geometry only if we'rent in drawForObjectUnderCursor mode
130 // declare colors
131 RGBColor baseColor, signColor;
132 // set colors
133 if (mySpecialColor) {
134 baseColor = *mySpecialColor;
135 signColor = baseColor.changedBrightness(-32);
136 } else if (drawUsingSelectColor()) {
138 signColor = baseColor.changedBrightness(-32);
139 } else {
142 }
143 // draw parent and child lines
145 // Add a layer matrix
147 // translate to front
149 // set base color
150 GLHelper::setColor(baseColor);
151 // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
153 // draw charging power and efficiency
154 drawLines(d, {toString(myChargingPower)}, baseColor);
155 // draw sign
156 drawSign(s, d, chargingStationExaggeration, baseColor, signColor, "C");
157 // draw geometry points
158 if (movingGeometryPoints && (myStartPosOverLane != INVALID_DOUBLE)) {
160 }
161 if (movingGeometryPoints && (myEndPosPosOverLane != INVALID_DOUBLE)) {
163 }
164 // pop layer matrix
166 // draw lock icon
168 // Draw additional ID
170 // draw additional name
172 // draw dotted contours
173 if (movingGeometryPoints) {
176 } else {
179 }
180 }
181 // draw demand element children
183 // calculate contours
184 calculateStoppingPlaceContour(s, d, s.stoppingPlaceSettings.chargingStationWidth, chargingStationExaggeration, movingGeometryPoints);
185 }
186}
187
188
189std::string
191 switch (key) {
195 return toString(myTotalPower);
197 return toString(myEfficiency);
203 return myChargeType;
207 return myParkingAreaID;
208 default:
209 return getStoppingPlaceAttribute(key);
210 }
211}
212
213
214double
216 switch (key) {
218 return myChargingPower;
220 return myTotalPower;
222 return myEfficiency;
223 default:
225 }
226}
227
228
229void
230GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
231 switch (key) {
240 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
241 break;
242 default:
243 setStoppingPlaceAttribute(key, value, undoList);
244 break;
245 }
246}
247
248
249bool
250GNEChargingStation::isValid(SumoXMLAttr key, const std::string& value) {
251 switch (key) {
254 return (canParse<double>(value) && parse<double>(value) >= 0);
256 if (canParse<double>(value)) {
257 const double efficiency = parse<double>(value);
258 return (efficiency >= 0) && (efficiency <= 1);
259 } else {
260 return false;
261 }
263 return canParse<bool>(value);
265 return canParse<SUMOTime>(value) && parse<SUMOTime>(value) >= 0;
268 }
270 return canParse<SUMOTime>(value) && parse<SUMOTime>(value) >= 0;
272 return isValidAdditionalID(value);
273 default:
274 return isStoppingPlaceValid(key, value);
275 }
276}
277
278// ===========================================================================
279// private
280// ===========================================================================
281
282void
283GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value) {
284 switch (key) {
286 myChargingPower = parse<double>(value);
287 break;
289 myTotalPower = parse<double>(value);
290 break;
292 myEfficiency = parse<double>(value);
293 break;
295 myChargeInTransit = parse<bool>(value);
296 break;
298 myChargeDelay = parse<SUMOTime>(value);
299 break;
301 myChargeType = value;
302 break;
304 myWaitingTime = parse<SUMOTime>(value);
305 break;
307 myParkingAreaID = value;
308 break;
309 default:
310 setStoppingPlaceAttribute(key, value);
311 break;
312 }
313}
314
315/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ GLO_CHARGING_STATION
a chargingStation
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:107
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_WAITINGTIME
@ SUMO_ATTR_PARKING_AREA
@ SUMO_ATTR_CHARGETYPE
Charge type (fuel or electric)
@ SUMO_ATTR_CHARGEINTRANSIT
Allow/disallow charge in transit in Charging Stations.
@ SUMO_ATTR_CHARGINGPOWER
@ SUMO_ATTR_EFFICIENCY
Eficiency of the charge in Charging Stations.
@ SUMO_ATTR_TOTALPOWER
total charge in W/s of the Charging Stations
@ SUMO_ATTR_CHARGEDELAY
Delay in the charge of charging stations (different of waiting time)
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:68
T MIN2(T a, T b)
Definition StdDefs.h:80
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
double getExaggeration(const GUIVisualizationSettings &s) const override
return exaggeration associated with this GLObject
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
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 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...
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
bool drawMovingGeometryPoints() const
check if draw moving geometry points
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * myNet
pointer to net
const GNETagProperties * myTagProperty
reference to tagProperty associated with this attribute carrier
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
std::string myChargeType
charging type
double getAttributeDouble(SumoXMLAttr key) const override
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
bool isValid(SumoXMLAttr key, const std::string &value) override
~GNEChargingStation()
Destructor.
std::string myParkingAreaID
parking area ID
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
GNEChargingStation(GNENet *net)
default Constructor of charging station
void updateGeometry() override
update pre-computed geometry information
SUMOTime myChargeDelay
delay in the starting of charge
bool myChargeInTransit
enable or disable charge in transit
std::string getAttribute(SumoXMLAttr key) const override
double myChargingPower
Charging power pro timestep and vehicle.
double myTotalPower
Charging power pro timestep across all charging vehicles.
double myEfficiency
efficiency of the charge
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
bool drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
draw dotted contours (basics, select, delete, inspect...)
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
bool isStoppingPlaceValid(SumoXMLAttr key, const std::string &value) const
void setStoppingPlaceAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
double myEndPosPosOverLane
The end position over lane.
void writeStoppingPlaceAttributes(OutputDevice &device) const
write common stoppingPlace attributes
void drawSign(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double exaggeration, const RGBColor &baseColor, const RGBColor &signColor, const std::string &word) const
draw sign
double getStoppingPlaceAttributeDouble(SumoXMLAttr key) const
void calculateStoppingPlaceContour(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double width, const double exaggeration, const bool movingGeometryPoints) const
check object in view
void drawLines(const GUIVisualizationSettings::Detail d, const std::vector< std::string > &lines, const RGBColor &color) const
draw lines
Position mySymbolPosition
The position of the sign.
double myStartPosOverLane
The start position over lane.
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
GNEContour mySymbolContour
circle contour
std::string getStoppingPlaceAttribute(SumoXMLAttr key) const
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
bool getDefaultBoolValue(SumoXMLAttr attr) const
get default bool value
double getDefaultDoubleValue(SumoXMLAttr attr) const
get default double value
SUMOTime getDefaultTimeValue(SumoXMLAttr attr) const
get default time value
const std::string & getDefaultStringValue(SumoXMLAttr attr) const
default values
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
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.
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
Stores the information about how to visualize structures.
bool checkDrawAdditional(Detail d, const bool selected) const
check if draw additionals
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
GUIVisualizationStoppingPlaceSettings stoppingPlaceSettings
StoppingPlace settings.
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.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
std::map< std::string, std::string > Map
parameters map
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:228
static StringBijection< ChargeType > ChargeTypes
charge type
bool hasString(const std::string &str) const
check if the given string exist
static OutputDevice & writeParams(OutputDevice &device, const Parameterised &params)
write the parameters of the given object as param tags
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