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-2022 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  myChargingPower(0),
42  myEfficiency(0),
43  myChargeInTransit(0),
44  myChargeDelay(0) {
45  // reset default values
47 }
48 
49 
50 GNEChargingStation::GNEChargingStation(const std::string& id, GNELane* lane, GNENet* net, const double startPos, const double endPos,
51  const std::string& name, double chargingPower, double efficiency, bool chargeInTransit, SUMOTime chargeDelay, bool friendlyPosition,
52  const Parameterised::Map& parameters) :
54  lane, startPos, endPos, name, friendlyPosition, parameters),
55  myChargingPower(chargingPower),
56  myEfficiency(efficiency),
57  myChargeInTransit(chargeInTransit),
58  myChargeDelay(chargeDelay) {
59  // update centering boundary without updating grid
61 }
62 
63 
65 
66 
67 void
69  device.openTag(getTagProperty().getTag());
70  device.writeAttr(SUMO_ATTR_ID, getID());
71  if (!myAdditionalName.empty()) {
73  }
74  device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
77  }
80  }
81  if (myFriendlyPosition) {
82  device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
83  }
86  }
89  }
92  }
95  }
96  // write parameters (Always after children to avoid problems with additionals.xsd)
97  writeParams(device);
98  device.closeTag();
99 }
100 
101 
102 void
104  // Get value of option "lefthand"
105  const double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
106 
107  // Update common geometry of stopping place
109 
110  // Obtain a copy of the shape
112 
113  // Move shape to side
115 
116  // Get position of the sign
117  mySignPos = tmpShape.getLineCenter();
118 }
119 
120 
121 void
123  // Obtain exaggeration of the draw
124  const double chargingStationExaggeration = getExaggeration(s);
125  // first check if additional has to be drawn
127  // check exaggeration
128  if (s.drawAdditionals(chargingStationExaggeration)) {
129  // declare colors
130  RGBColor baseColor, signColor;
131  // set colors
132  if (mySpecialColor) {
133  baseColor = *mySpecialColor;
134  signColor = baseColor.changedBrightness(-32);
135  } else if (drawUsingSelectColor()) {
137  signColor = baseColor.changedBrightness(-32);
138  } else {
139  baseColor = s.colorSettings.chargingStationColor;
141  }
142  // draw parent and child lines
144  // Start drawing adding an gl identificator
146  // Add a layer matrix
148  // translate to front
150  // set base color
151  GLHelper::setColor(baseColor);
152  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
154  // draw detail
155  if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, chargingStationExaggeration)) {
156  // draw charging power and efficiency
157  drawLines(s, {toString(myChargingPower)}, baseColor);
158  // draw sign
159  drawSign(s, chargingStationExaggeration, baseColor, signColor, "C");
160  }
161  // draw geometry points
164  }
165  if (myEndPosition != INVALID_DOUBLE) {
167  }
168  // pop layer matrix
170  // Pop name
172  // draw lock icon
174  // check if mouse is over element
177  // inspect contour
180  chargingStationExaggeration, true, true);
181  }
182  // front element contour
183  if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
185  chargingStationExaggeration, true, true);
186  }
187  // delete contour
188  if (myNet->getViewNet()->drawDeleteContour(this, this)) {
190  chargingStationExaggeration, true, true);
191  }
192  // delete contour
193  if (myNet->getViewNet()->drawSelectContour(this, this)) {
195  chargingStationExaggeration, true, true);
196  }
197  // draw child demand elements
198  for (const auto& demandElement : getChildDemandElements()) {
199  if (!demandElement->getTagProperty().isPlacedInRTree()) {
200  demandElement->drawGL(s);
201  }
202  }
203  }
204  // Draw additional ID
205  drawAdditionalID(s);
206  // draw additional name
208  }
209 }
210 
211 
212 std::string
214  switch (key) {
215  case SUMO_ATTR_ID:
216  return getMicrosimID();
217  case SUMO_ATTR_LANE:
218  return getParentLanes().front()->getID();
219  case SUMO_ATTR_STARTPOS:
221  return toString(myStartPosition);
222  } else {
223  return "";
224  }
225  case SUMO_ATTR_ENDPOS:
226  if (myEndPosition != INVALID_DOUBLE) {
227  return toString(myEndPosition);
228  } else {
229  return "";
230  }
231  case SUMO_ATTR_NAME:
232  return myAdditionalName;
236  return toString(myChargingPower);
238  return toString(myEfficiency);
240  return toString(myChargeInTransit);
242  return time2string(myChargeDelay);
243  case GNE_ATTR_SELECTED:
245  case GNE_ATTR_PARAMETERS:
246  return getParametersStr();
248  return "";
249  default:
250  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
251  }
252 }
253 
254 
255 void
256 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
257  switch (key) {
258  case SUMO_ATTR_ID:
259  case SUMO_ATTR_LANE:
260  case SUMO_ATTR_STARTPOS:
261  case SUMO_ATTR_ENDPOS:
262  case SUMO_ATTR_NAME:
268  case GNE_ATTR_SELECTED:
269  case GNE_ATTR_PARAMETERS:
271  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
272  break;
273  default:
274  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
275  }
276 }
277 
278 
279 bool
280 GNEChargingStation::isValid(SumoXMLAttr key, const std::string& value) {
281  switch (key) {
282  case SUMO_ATTR_ID:
283  return isValidAdditionalID(value);
284  case SUMO_ATTR_LANE:
285  if (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr) {
286  return true;
287  } else {
288  return false;
289  }
290  case SUMO_ATTR_STARTPOS:
291  if (value.empty()) {
292  return true;
293  } else if (canParse<double>(value)) {
294  return SUMORouteHandler::isStopPosValid(parse<double>(value), getAttributeDouble(SUMO_ATTR_ENDPOS), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
295  } else {
296  return false;
297  }
298  case SUMO_ATTR_ENDPOS:
299  if (value.empty()) {
300  return true;
301  } else if (canParse<double>(value)) {
302  return SUMORouteHandler::isStopPosValid(getAttributeDouble(SUMO_ATTR_STARTPOS), parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
303  } else {
304  return false;
305  }
306  case SUMO_ATTR_NAME:
309  return canParse<bool>(value);
311  return (canParse<double>(value) && parse<double>(value) >= 0);
313  return (canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1);
315  return canParse<bool>(value);
317  return canParse<SUMOTime>(value);
318  case GNE_ATTR_SELECTED:
319  return canParse<bool>(value);
320  case GNE_ATTR_PARAMETERS:
321  return areParametersValid(value);
322  default:
323  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
324  }
325 }
326 
327 // ===========================================================================
328 // private
329 // ===========================================================================
330 
331 void
332 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value) {
333  switch (key) {
334  case SUMO_ATTR_ID:
335  // update microsimID
336  setMicrosimID(value);
337  // enable save demand elements if there are stops
338  for (const auto& stop : getChildDemandElements()) {
339  if (stop->getTagProperty().isStop() || stop->getTagProperty().isStopPerson()) {
341  }
342  }
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;
379  case GNE_ATTR_SELECTED:
380  if (parse<bool>(value)) {
382  } else {
384  }
385  break;
386  case GNE_ATTR_PARAMETERS:
387  setParametersStr(value);
388  break;
390  shiftLaneIndex();
391  break;
392  default:
393  throw InvalidArgument(getTagStr() + "attribute '" + toString(key) + "' not allowed");
394  }
395 }
396 
397 
398 /****************************************************************************/
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
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_LANE
@ 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.
@ GNE_ATTR_SHIFTLANEINDEX
shift lane index (only used by elements over lanes)
const double INVALID_DOUBLE
Definition: StdDefs.h:60
T MIN2(T a, T b)
Definition: StdDefs.h:71
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:583
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:139
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void popName()
pop Name
Definition: GLHelper.cpp:148
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
static void drawRightGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false)
draw right geometry point
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
const RGBColor * mySpecialColor
pointer to special color (used for drawing Additional with a certain color, mainly used for selection...
static void drawLeftGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false)
draw left geometry point
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
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
friend class GNEChange_Attribute
declare friend class
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
std::string getAttribute(SumoXMLAttr key) const
~GNEChargingStation()
Destructor.
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
const std::vector< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
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:132
void requireSaveDemandElements(bool value)
inform that demand elements has to be saved
Definition: GNENet.cpp:2083
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
virtual double getAttributeDouble(SumoXMLAttr key) const
static const double myCircleWidth
circle width resolution for all stopping places
bool myFriendlyPosition
Flag for friendly position.
void drawLines(const GUIVisualizationSettings &s, const std::vector< std::string > &lines, const RGBColor &color) const
draw lines
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
double myEndPosition
The position this stopping place is located at (-1 means empty)
void drawSign(const GUIVisualizationSettings &s, const double exaggeration, const RGBColor &baseColor, const RGBColor &signColor, const std::string &word) const
draw sign
Position mySignPos
The position of the sign.
double myStartPosition
The relative start position this stopping place is located at (-1 means empty)
const std::string & getDefaultValue(SumoXMLAttr attr) const
return the default value of the attribute of an element
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:656
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool drawSelectContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw select contour
bool drawDeleteContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw delete contour
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
static void drawDottedContourShape(const GUIVisualizationSettings &s, const DottedContourType type, const PositionVector &shape, const double width, const double exaggeration, const bool drawFirstExtrem, const bool drawLastExtrem)
draw dotted contour for the given shape (used by additionals)
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
static void drawGeometry(const GUIVisualizationSettings &s, const Position &mousePos, const GUIGeometry &geometry, const double width, double offset=0)
draw geometry
const PositionVector & getShape() const
The shape of the additional element.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
void mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:154
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:141
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:102
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
Stores the information about how to visualize structures.
GUIVisualizationDetailSettings detailSettings
detail settings
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationStoppingPlaceSettings stoppingPlaceSettings
StoppingPlace settings.
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
GUIVisualizationAdditionalSettings additionalSettings
Additional 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:59
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:251
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 ammount
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 GNEAttributeCarrier *AC, GUIGlObjectType type, const Position viewPosition, 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 stoppingPlaceDetails
details for stopping places
static const double stoppingPlaceSignOffset
busStop offset
static const double chargingStationWidth
chargingStation width