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-2020 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 /****************************************************************************/
21 #include <netedit/GNENet.h>
22 #include <netedit/GNEUndoList.h>
23 #include <netedit/GNEViewNet.h>
25 #include <utils/gui/div/GLHelper.h>
29 
30 #include "GNEChargingStation.h"
31 
32 // ===========================================================================
33 // member method definitions
34 // ===========================================================================
35 
36 GNEChargingStation::GNEChargingStation(const std::string& id, GNELane* lane, GNENet* net, const double startPos, const double endPos, const int parametersSet,
37  const std::string& name, double chargingPower, double efficiency, bool chargeInTransit, SUMOTime chargeDelay, bool friendlyPosition, bool blockMovement) :
38  GNEStoppingPlace(id, net, GLO_CHARGING_STATION, SUMO_TAG_CHARGING_STATION, lane, startPos, endPos, parametersSet, name, friendlyPosition, blockMovement),
39  myChargingPower(chargingPower),
40  myEfficiency(efficiency),
41  myChargeInTransit(chargeInTransit),
42  myChargeDelay(chargeDelay) {
43  // update centering boundary without updating grid
45 }
46 
47 
49 
50 
51 void
53  // Get value of option "lefthand"
54  const double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
55 
56  // Update common geometry of stopping place
58 
59  // Obtain a copy of the shape
61 
62  // Move shape to side
64 
65  // Get position of the sign
66  mySignPos = tmpShape.getLineCenter();
67 }
68 
69 
70 void
72  // Obtain exaggeration of the draw
73  const double chargingStationExaggeration = s.addSize.getExaggeration(s, this);
74  // first check if additional has to be drawn
75  if (s.drawAdditionals(chargingStationExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
76  // declare colors
77  RGBColor baseColor, signColor;
78  // set colors
79  if (mySpecialColor) {
80  baseColor = *mySpecialColor;
81  signColor = baseColor.changedBrightness(-32);
82  } else if (drawUsingSelectColor()) {
84  signColor = baseColor.changedBrightness(-32);
85  } else {
88  }
89  // Start drawing adding an gl identificator
90  glPushName(getGlID());
91  // Add a draw matrix
92  glPushMatrix();
93  // translate to front
95  // set base color
96  GLHelper::setColor(baseColor);
97  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
99  // draw detail
100  if (s.drawDetail(s.detailSettings.stoppingPlaceDetails, chargingStationExaggeration)) {
101  // draw charging power and efficiency
102  drawLines(s, {toString(myChargingPower)}, baseColor);
103  // draw sign
104  drawSign(s, chargingStationExaggeration, baseColor, signColor, "C");
105  // draw lock icon
106  GNEViewNetHelper::LockIcon::drawLockIcon(this, myAdditionalGeometry, chargingStationExaggeration, 0, 0, true);
107  }
108  // pop draw matrix
109  glPopMatrix();
110  // Pop name
111  glPopName();
112  // Draw additional ID
113  drawAdditionalID(s);
114  // draw additional name
116  // check if dotted contours has to be drawn
119  }
120  if (s.drawDottedContour() || myNet->getViewNet()->getFrontAttributeCarrier() == this) {
122  }
123  // draw child demand elements
124  for (const auto& demandElement : getChildDemandElements()) {
125  if (!demandElement->getTagProperty().isPlacedInRTree()) {
126  demandElement->drawGL(s);
127  }
128  }
129  }
130 }
131 
132 
133 std::string
135  switch (key) {
136  case SUMO_ATTR_ID:
137  return getID();
138  case SUMO_ATTR_LANE:
139  return getParentLanes().front()->getID();
140  case SUMO_ATTR_STARTPOS:
142  return toString(myStartPosition);
143  } else {
144  return "";
145  }
146  case SUMO_ATTR_ENDPOS:
148  return toString(myEndPosition);
149  } else {
150  return "";
151  }
152  case SUMO_ATTR_NAME:
153  return myAdditionalName;
157  return toString(myChargingPower);
159  return toString(myEfficiency);
161  return toString(myChargeInTransit);
163  return time2string(myChargeDelay);
165  return toString(myBlockMovement);
166  case GNE_ATTR_SELECTED:
168  case GNE_ATTR_PARAMETERS:
169  return getParametersStr();
170  default:
171  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
172  }
173 }
174 
175 
176 void
177 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
178  if (value == getAttribute(key)) {
179  return; //avoid needless changes, later logic relies on the fact that attributes have changed
180  }
181  switch (key) {
182  case SUMO_ATTR_ID:
183  case SUMO_ATTR_LANE:
184  case SUMO_ATTR_STARTPOS:
185  case SUMO_ATTR_ENDPOS:
186  case SUMO_ATTR_NAME:
193  case GNE_ATTR_SELECTED:
194  case GNE_ATTR_PARAMETERS:
195  undoList->p_add(new GNEChange_Attribute(this, key, value));
196  break;
197  default:
198  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
199  }
200 }
201 
202 
203 bool
204 GNEChargingStation::isValid(SumoXMLAttr key, const std::string& value) {
205  switch (key) {
206  case SUMO_ATTR_ID:
207  return isValidAdditionalID(value);
208  case SUMO_ATTR_LANE:
209  if (myNet->retrieveLane(value, false) != nullptr) {
210  return true;
211  } else {
212  return false;
213  }
214  case SUMO_ATTR_STARTPOS:
215  if (value.empty()) {
216  return true;
217  } else if (canParse<double>(value)) {
218  return SUMORouteHandler::isStopPosValid(parse<double>(value), myEndPosition, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
219  } else {
220  return false;
221  }
222  case SUMO_ATTR_ENDPOS:
223  if (value.empty()) {
224  return true;
225  } else if (canParse<double>(value)) {
226  return SUMORouteHandler::isStopPosValid(myStartPosition, parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, myFriendlyPosition);
227  } else {
228  return false;
229  }
230  case SUMO_ATTR_NAME:
233  return canParse<bool>(value);
235  return (canParse<double>(value) && parse<double>(value) >= 0);
237  return (canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1);
239  return canParse<bool>(value);
241  return canParse<SUMOTime>(value);
243  return canParse<bool>(value);
244  case GNE_ATTR_SELECTED:
245  return canParse<bool>(value);
246  case GNE_ATTR_PARAMETERS:
247  return Parameterised::areParametersValid(value);
248  default:
249  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
250  }
251 }
252 
253 // ===========================================================================
254 // private
255 // ===========================================================================
256 
257 void
258 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value) {
259  switch (key) {
260  case SUMO_ATTR_ID:
261  myNet->getAttributeCarriers()->updateID(this, value);
262  break;
263  case SUMO_ATTR_LANE:
265  break;
266  case SUMO_ATTR_STARTPOS:
267  if (!value.empty()) {
268  myStartPosition = parse<double>(value);
270  } else {
272  }
273  break;
274  case SUMO_ATTR_ENDPOS:
275  if (!value.empty()) {
276  myEndPosition = parse<double>(value);
278  } else {
280  }
281  break;
282  case SUMO_ATTR_NAME:
283  myAdditionalName = value;
284  break;
286  myFriendlyPosition = parse<bool>(value);
287  break;
289  myChargingPower = 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  myBlockMovement = parse<bool>(value);
302  break;
303  case GNE_ATTR_SELECTED:
304  if (parse<bool>(value)) {
306  } else {
308  }
309  break;
310  case GNE_ATTR_PARAMETERS:
311  setParametersStr(value);
312  break;
313  default:
314  throw InvalidArgument(getTagStr() + "attribute '" + toString(key) + "' not allowed");
315  }
316 }
317 
318 
319 /****************************************************************************/
const int STOPPINGPLACE_STARTPOS_SET
const int STOPPINGPLACE_ENDPOS_SET
@ GLO_CHARGING_STATION
a chargingStation
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
long long int SUMOTime
Definition: SUMOTime.h:31
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_LANE
@ GNE_ATTR_BLOCK_MOVEMENT
block movement of a graphic element
@ 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.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
const std::string & getID() const
get ID
GNEGeometry::Geometry 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
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse)
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...
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
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
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
std::string getAttribute(SumoXMLAttr key) const
~GNEChargingStation()
Destructor.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNEChargingStation(const std::string &id, GNELane *lane, GNENet *net, const double startPos, const double endPos, const int parametersSet, const std::string &name, double chargingPower, double efficiency, bool chargeInTransit, SUMOTime chargeDelay, bool friendlyPosition, bool blockMovement)
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.
double myEfficiency
efficiency of the charge
void updateGeometry()
update pre-computed geometry information
const PositionVector & getShape() const
The shape of the additional element.
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:45
void updateID(GNEAttributeCarrier *AC, const std::string newID)
update ID
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1337
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
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 (optional, if empty takes the lane length)
void drawSign(const GUIVisualizationSettings &s, const double exaggeration, const RGBColor &baseColor, const RGBColor &signColor, const std::string &word) const
draw sign
int myParametersSet
Variable used for set/unset start/endPositions.
Position mySignPos
The position of the sign.
double myStartPosition
The relative start position this stopping place is located at (optional, if empty takes 0)
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:491
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
GUIGlID getGlID() const
Returns the numerical id of the object.
GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings
Stores the information about how to visualize structures.
GUIVisualizationDetailSettings detailSettings
detail settings
GUIVisualizationSizeSettings addSize
bool drawDottedContour() const
check if dotted contour can be drawn
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...
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:58
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
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"
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
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:145
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 void drawDottedContourShape(const DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double width, const double exaggeration)
draw dotted contour for the given shape (used by additionals)
static void drawGeometry(const GNEViewNet *viewNet, const Geometry &geometry, const double width)
draw geometry
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GNEAttributeCarrier *AC, const GNEGeometry::Geometry &geometry, const double exaggeration, const double offsetx, const double offsety, const bool overlane, const double size=0.5)
draw lock icon
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double stoppingPlaceDetails
details for stopping places
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
static const double stoppingPlaceSignOffset
busStop offset
static const RGBColor chargingStationColor
color for chargingStations
static const RGBColor chargingStationColorSign
color for chargingStation sign
static const double chargingStationWidth
chargingStation width