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  mySymbolPosition = 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
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(s, 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 contours
183  if (movingGeometryPoints) {
186  } else {
189  }
190  }
191  // draw demand element children
193  // calculate contours
194  calculateStoppingPlaceContour(s, d, s.stoppingPlaceSettings.chargingStationWidth, chargingStationExaggeration, movingGeometryPoints);
195  }
196 }
197 
198 
199 std::string
201  switch (key) {
202  case SUMO_ATTR_ID:
203  return getMicrosimID();
204  case SUMO_ATTR_LANE:
205  return getParentLanes().front()->getID();
206  case SUMO_ATTR_STARTPOS:
208  return toString(myStartPosition);
209  } else {
210  return "";
211  }
212  case SUMO_ATTR_ENDPOS:
213  if (myEndPosition != INVALID_DOUBLE) {
214  return toString(myEndPosition);
215  } else {
216  return "";
217  }
218  case SUMO_ATTR_NAME:
219  return myAdditionalName;
223  return toString(myChargingPower);
225  return toString(myEfficiency);
227  return toString(myChargeInTransit);
229  return time2string(myChargeDelay);
231  return myChargeType;
233  return time2string(myWaitingTime);
235  return myParkingAreaID;
236  case GNE_ATTR_SELECTED:
238  case GNE_ATTR_PARAMETERS:
239  return getParametersStr();
241  return "";
242  default:
243  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
244  }
245 }
246 
247 
248 void
249 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
250  switch (key) {
251  case SUMO_ATTR_ID:
252  case SUMO_ATTR_LANE:
253  case SUMO_ATTR_STARTPOS:
254  case SUMO_ATTR_ENDPOS:
255  case SUMO_ATTR_NAME:
264  case GNE_ATTR_SELECTED:
265  case GNE_ATTR_PARAMETERS:
267  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
268  break;
269  default:
270  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
271  }
272 }
273 
274 
275 bool
276 GNEChargingStation::isValid(SumoXMLAttr key, const std::string& value) {
277  switch (key) {
278  case SUMO_ATTR_ID:
279  return isValidAdditionalID(value);
280  case SUMO_ATTR_LANE:
281  if (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr) {
282  return true;
283  } else {
284  return false;
285  }
286  case SUMO_ATTR_STARTPOS:
287  if (value.empty()) {
288  return true;
289  } else if (canParse<double>(value)) {
290  return SUMORouteHandler::isStopPosValid(parse<double>(value), getAttributeDouble(SUMO_ATTR_ENDPOS), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
291  } else {
292  return false;
293  }
294  case SUMO_ATTR_ENDPOS:
295  if (value.empty()) {
296  return true;
297  } else if (canParse<double>(value)) {
298  return SUMORouteHandler::isStopPosValid(getAttributeDouble(SUMO_ATTR_STARTPOS), parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
299  } else {
300  return false;
301  }
302  case SUMO_ATTR_NAME:
305  return canParse<bool>(value);
307  return (canParse<double>(value) && parse<double>(value) >= 0);
309  if (canParse<double>(value)) {
310  const double efficiency = parse<double>(value);
311  return (efficiency >= 0) && (efficiency <= 1);
312  } else {
313  return false;
314  }
316  return canParse<bool>(value);
318  return canParse<SUMOTime>(value) && parse<SUMOTime>(value) >= 0;
319  case SUMO_ATTR_CHARGETYPE: {
320  const auto validValues = myTagProperty.getAttributeProperties(key).getDiscreteValues();
321  return std::find(validValues.begin(), validValues.end(), value) != validValues.end();
322  }
324  return canParse<SUMOTime>(value) && parse<SUMOTime>(value) >= 0;
326  return isValidAdditionalID(value);
327  case GNE_ATTR_SELECTED:
328  return canParse<bool>(value);
329  case GNE_ATTR_PARAMETERS:
330  return areParametersValid(value);
331  default:
332  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
333  }
334 }
335 
336 // ===========================================================================
337 // private
338 // ===========================================================================
339 
340 void
341 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value) {
342  switch (key) {
343  case SUMO_ATTR_ID:
344  // update microsimID
345  setAdditionalID(value);
346  break;
347  case SUMO_ATTR_LANE:
349  break;
350  case SUMO_ATTR_STARTPOS:
351  if (value == "") {
353  } else {
354  myStartPosition = parse<double>(value);
355  }
356  break;
357  case SUMO_ATTR_ENDPOS:
358  if (value == "") {
360  } else {
361  myEndPosition = parse<double>(value);
362  }
363  break;
364  case SUMO_ATTR_NAME:
365  myAdditionalName = value;
366  break;
368  myFriendlyPosition = parse<bool>(value);
369  break;
371  myChargingPower = parse<double>(value);
372  break;
374  myEfficiency = parse<double>(value);
375  break;
377  myChargeInTransit = parse<bool>(value);
378  break;
380  myChargeDelay = parse<SUMOTime>(value);
381  break;
383  myChargeType = value;
384  break;
386  myWaitingTime = parse<SUMOTime>(value);
387  break;
389  myParkingAreaID = value;
390  break;
391  case GNE_ATTR_SELECTED:
392  if (parse<bool>(value)) {
394  } else {
396  }
397  break;
398  case GNE_ATTR_PARAMETERS:
399  setParametersStr(value);
400  break;
402  shiftLaneIndex();
403  break;
404  default:
405  throw InvalidArgument(getTagStr() + "attribute '" + toString(key) + "' not allowed");
406  }
407 }
408 
409 
410 /****************************************************************************/
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:123
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2136
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
virtual double getAttributeDouble(SumoXMLAttr key) const
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
void calculateStoppingPlaceContour(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double width, const double exaggeration, const bool movingGeometryPoints) const
check object in view
bool myFriendlyPosition
Flag for friendly position.
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.
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
double myEndPosition
The position this stopping place is located at (-1 means empty)
GNEContour mySymbolContour
circle contour
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:747
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.
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.
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