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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // A class for visualizing chargingStation geometry (adapted from GUILaneWrapper)
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <string>
24 #include <iostream>
25 #include <utility>
30 #include <utils/common/ToString.h>
31 #include <utils/geom/GeomHelper.h>
36 #include <utils/gui/div/GLHelper.h>
44 #include <netedit/GNEUndoList.h>
45 #include <netedit/GNENet.h>
47 #include <netedit/GNEViewNet.h>
48 #include <netedit/GNEViewParent.h>
49 
50 #include "GNEChargingStation.h"
51 
52 // ===========================================================================
53 // member method definitions
54 // ===========================================================================
55 
56 GNEChargingStation::GNEChargingStation(const std::string& id, GNELane* lane, GNEViewNet* viewNet, const std::string& startPos, const std::string& endPos, const std::string& name,
57  double chargingPower, double efficiency, bool chargeInTransit, const double chargeDelay, bool friendlyPosition, bool blockMovement) :
58  GNEStoppingPlace(id, viewNet, GLO_CHARGING_STATION, SUMO_TAG_CHARGING_STATION, lane, startPos, endPos, name, friendlyPosition, blockMovement),
59  myChargingPower(chargingPower),
60  myEfficiency(efficiency),
61  myChargeInTransit(chargeInTransit),
62  myChargeDelay(chargeDelay) {
63 }
64 
65 
67 
68 
69 void
71  // first check if object has to be removed from grid (SUMOTree)
72  if (updateGrid) {
74  }
75 
76  // Get value of option "lefthand"
77  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
78 
79  // Update common geometry of stopping place
81 
82  // Obtain a copy of the shape
83  PositionVector tmpShape = myShape;
84 
85  // Move shape to side
86  tmpShape.move2side(1.5 * offsetSign);
87 
88  // Get position of the sign
89  mySignPos = tmpShape.getLineCenter();
90 
91  // Set block icon position
93 
94  // Set block icon rotation, and using their rotation for sign
96 
97  // last step is to check if object has to be added into grid (SUMOTree) again
98  if (updateGrid) {
100  }
101 }
102 
103 
104 void
106  // obtain circle resolution
107  int circleResolution = getCircleResolution(s);
108  // Get exaggeration
109  const double exaggeration = s.addSize.getExaggeration(s);
110  // Push name
111  glPushName(getGlID());
112  // Push base matrix
113  glPushMatrix();
114  // Traslate matrix
115  glTranslated(0, 0, getType());
116  // Set Color
119  } else {
121  }
122  // Draw base
124  // Check if the distance is enought to draw details and if is being drawn for selecting
125  if (s.drawForSelecting) {
126  // only draw circle depending of distance between sign and mouse cursor
128  // Add a draw matrix for details
129  glPushMatrix();
130  // Start drawing sign traslating matrix to signal position
131  glTranslated(mySignPos.x(), mySignPos.y(), 0);
132  // scale matrix depending of the exaggeration
133  glScaled(exaggeration, exaggeration, 1);
134  // set color
136  // Draw circle
137  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
138  // pop draw matrix
139  glPopMatrix();
140  }
141  } else if (s.scale * exaggeration >= 10) {
142  // Push matrix for details
143  glPushMatrix();
144  // push a new matrix for charging power
145  glPushMatrix();
146  // draw line with a color depending of the selection status
149  } else {
151  }
152  // pop matrix for charging power
153  glPopMatrix();
154  // Set position over sign
155  glTranslated(mySignPos.x(), mySignPos.y(), 0);
156  // Scale matrix
157  glScaled(exaggeration, exaggeration, 1);
158  // Set base color
161  } else {
163  }
164  // Draw extern
165  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
166  // Move to top
167  glTranslated(0, 0, .1);
168  // Set sign color
171  } else {
173  }
174  // Draw internt sign
175  GLHelper::drawFilledCircle(myCircleInWidth, circleResolution);
176  // Draw sign 'C'
177  if (s.scale * exaggeration >= 4.5) {
180  } else {
182  }
183  }
184  // Pop sign matrix
185  glPopMatrix();
186  // Draw icon
188  }
189  // Pop base matrix
190  glPopMatrix();
191  // Draw name if isn't being drawn for selecting
192  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
193  if (s.addFullName.show && (myAdditionalName != "") && !s.drawForSelecting) {
195  }
196  // check if dotted contour has to be drawn
197  if (!s.drawForSelecting && (myViewNet->getACUnderCursor() == this)) {
199  }
200  // Pop name matrix
201  glPopName();
202 }
203 
204 
205 std::string
207  switch (key) {
208  case SUMO_ATTR_ID:
209  return getAdditionalID();
210  case SUMO_ATTR_LANE:
211  return myLane->getID();
212  case SUMO_ATTR_STARTPOS:
213  return toString(myStartPosition);
214  case SUMO_ATTR_ENDPOS:
215  return myEndPosition;
216  case SUMO_ATTR_NAME:
217  return myAdditionalName;
221  return toString(myChargingPower);
223  return toString(myEfficiency);
225  return toString(myChargeInTransit);
227  return toString(myChargeDelay);
229  return toString(myBlockMovement);
230  case GNE_ATTR_SELECTED:
232  case GNE_ATTR_GENERIC:
233  return getGenericParametersStr();
234  default:
235  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
236  }
237 }
238 
239 
240 void
241 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
242  if (value == getAttribute(key)) {
243  return; //avoid needless changes, later logic relies on the fact that attributes have changed
244  }
245  switch (key) {
246  case SUMO_ATTR_ID:
247  case SUMO_ATTR_LANE:
248  case SUMO_ATTR_STARTPOS:
249  case SUMO_ATTR_ENDPOS:
250  case SUMO_ATTR_NAME:
257  case GNE_ATTR_SELECTED:
258  case GNE_ATTR_GENERIC:
259  undoList->p_add(new GNEChange_Attribute(this, key, value));
260  break;
261  default:
262  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
263  }
264 }
265 
266 
267 bool
268 GNEChargingStation::isValid(SumoXMLAttr key, const std::string& value) {
269  switch (key) {
270  case SUMO_ATTR_ID:
271  return isValidAdditionalID(value);
272  case SUMO_ATTR_LANE:
273  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
274  return true;
275  } else {
276  return false;
277  }
278  case SUMO_ATTR_STARTPOS:
279  if (value.empty()) {
280  return true;
281  } else {
282  if (canParse<double>(value)) {
283  if (canParse<double>(myEndPosition)) {
284  // Check that new start Position is smaller that end position
285  return (parse<double>(value) < parse<double>(myEndPosition));
286  } else {
287  return true;
288  }
289  } else {
290  return false;
291  }
292  }
293  case SUMO_ATTR_ENDPOS:
294  if (value.empty()) {
295  return true;
296  } else {
297  if (canParse<double>(value)) {
298  if (canParse<double>(myStartPosition)) {
299  // Check that new start Position is smaller that end position
300  return (parse<double>(myStartPosition) < parse<double>(value));
301  } else {
302  return true;
303  }
304  } else {
305  return false;
306  }
307  }
308  case SUMO_ATTR_NAME:
311  return canParse<bool>(value);
313  return (canParse<double>(value) && parse<double>(value) >= 0);
315  return (canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1);
317  return canParse<bool>(value);
319  return (canParse<double>(value) && parse<double>(value) >= 0);
321  return canParse<bool>(value);
322  case GNE_ATTR_SELECTED:
323  return canParse<bool>(value);
324  case GNE_ATTR_GENERIC:
325  return isGenericParametersValid(value);
326  default:
327  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
328  }
329 }
330 
331 // ===========================================================================
332 // private
333 // ===========================================================================
334 
335 void
336 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value) {
337  switch (key) {
338  case SUMO_ATTR_ID:
339  changeAdditionalID(value);
340  break;
341  case SUMO_ATTR_LANE:
342  myLane = changeLane(myLane, value);
343  break;
344  case SUMO_ATTR_STARTPOS:
345  myStartPosition = value;
346  break;
347  case SUMO_ATTR_ENDPOS:
348  myEndPosition = value;
349  break;
350  case SUMO_ATTR_NAME:
351  myAdditionalName = value;
352  break;
354  myFriendlyPosition = parse<bool>(value);
355  break;
357  myChargingPower = parse<double>(value);
358  break;
360  myEfficiency = parse<double>(value);
361  break;
363  myChargeInTransit = parse<bool>(value);
364  break;
366  myChargeDelay = parse<double>(value);
367  break;
369  myBlockMovement = parse<bool>(value);
370  break;
371  case GNE_ATTR_SELECTED:
372  if (parse<bool>(value)) {
374  } else {
376  }
377  break;
378  case GNE_ATTR_GENERIC:
380  break;
381  default:
382  throw InvalidArgument(toString(getTag()) + "attribute '" + toString(key) + "' not allowed");
383  }
384  // After setting attribute always update Geometry
385  updateGeometry(true);
386 }
387 
388 
389 /****************************************************************************/
const GNEAttributeCarrier * getACUnderCursor() const
get AttributeCarrier under cursor
double scale
information about a lane&#39;s width (temporary, used for a single view)
void setBlockIconRotation(GNELane *additionalLane=nullptr)
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 drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition: GLHelper.cpp:178
GUIVisualizationTextSettings addName
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
static const RGBColor SUMO_color_chargingStation_sign
color for chargingStation sign
a chargingStation
Stores the information about how to visualize structures.
Allow/disallow charge in transit in Charging Stations.
static const double myCircleWidthSquared
squared circle width resolution for all stopping places
double y() const
Returns the y-position.
Definition: Position.h:61
static const double myCircleInWidth
inner circle width resolution for all stopping places
double x() const
Returns the x-position.
Definition: Position.h:56
static const RGBColor SUMO_color_chargingStation
color for chargingStations
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, int align=0, double width=-1)
Definition: GLHelper.cpp:611
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
bool myFriendlyPosition
Flag for friendly position.
std::string myStartPosition
The relative start position this stopping place is located at (optional, if empty takes 0) ...
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void updateGeometry(bool updateGrid)
update pre-computed geometry information
static const double myCircleInText
text inner circle width resolution for all stopping places
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
std::vector< double > myShapeRotations
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:344
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
double myEfficiency
efficiency of the charge
Position getLineCenter() const
get line center
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:105
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void drawLockIcon(double size=0.5) const
draw lock icon
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:573
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
A list of positions.
double scaledSize(double scale, double constFactor=0.1) const
std::string myAdditionalName
name of additional
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1175
double distanceSquaredTo(const Position &p2) const
returns the square of the distance to another position
Definition: Position.h:238
GNELane * myLane
The lane in which this lane is placed.
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
block movement of a graphic element
std::vector< double > myShapeLengths
The lengths of the shape parts.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
~GNEChargingStation()
Destructor.
GNEChargingStation(const std::string &id, GNELane *lane, GNEViewNet *viewNet, const std::string &startPos, const std::string &endPos, const std::string &name, double chargingPower, double efficiency, bool chargeInTransit, const double chargeDelay, bool friendlyPosition, bool blockMovement)
Constructor of charging station.
const std::string getID() const
function to support debugging
bool myChargeInTransit
enable or disable charge in transit
void move2side(double amount)
move position vector to side using certain ammount
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
static const double myCircleWidth
circle width resolution for all stopping places
double myChargingPower
Charging power pro timestep.
void setStoppingPlaceGeometry(double movingToSide)
set geometry common to all stopping places
static void drawShapeDottedContour(const int type, const PositionVector &shape, const double width)
draw a dotted contour around the given Non closed shape with certain width
Definition: GLHelper.cpp:471
GUIVisualizationTextSettings addFullName
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
element is selected
static int getCircleResolution(const GUIVisualizationSettings &settings)
function to calculate circle resolution for all circles drawn in drawGL(...) functions ...
std::string getGenericParametersStr() const
return generic parameters in string format
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
double myChargeDelay
delay in the starting of charge
GNENet * getNet() const
get the net object
GUIGlID getGlID() const
Returns the numerical id of the object.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
std::string getAttribute(SumoXMLAttr key) const
Eficiency of the charge in Charging Stations.
Position getPositionInformation() const
Returns the cursor&#39;s x/y position within the network.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
std::string myEndPosition
The position this stopping place is located at (optional, if empty takes the lane lenght) ...
static const RGBColor selectionColor
Definition: GNENet.h:96
empty max
Delay in the charge of charging stations.
Position mySignPos
The position of the sign.
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1168
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1074
double myBlockIconRotation
The rotation of the block icon.
GNELane * changeLane(GNELane *oldLane, const std::string &newLaneID)
change lane of additional
Position myBlockIconPosition
position of the block icon
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
SumoXMLTag getTag() const
get XML Tag assigned to this object