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 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
29 #include <utils/gui/div/GLHelper.h>
32 
33 #include "GNEChargingStation.h"
34 
35 // ===========================================================================
36 // member method definitions
37 // ===========================================================================
38 
39 GNEChargingStation::GNEChargingStation(const std::string& id, GNELane* lane, GNEViewNet* viewNet, const std::string& startPos, const std::string& endPos, const std::string& name,
40  double chargingPower, double efficiency, bool chargeInTransit, const double chargeDelay, bool friendlyPosition, bool blockMovement) :
41  GNEStoppingPlace(id, viewNet, GLO_CHARGING_STATION, SUMO_TAG_CHARGING_STATION, lane, startPos, endPos, name, friendlyPosition, blockMovement),
42  myChargingPower(chargingPower),
43  myEfficiency(efficiency),
44  myChargeInTransit(chargeInTransit),
45  myChargeDelay(chargeDelay) {
46 }
47 
48 
50 
51 
52 void
54  // first check if object has to be removed from grid (SUMOTree)
55  if (updateGrid) {
57  }
58 
59  // Get value of option "lefthand"
60  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
61 
62  // Update common geometry of stopping place
64 
65  // Obtain a copy of the shape
66  PositionVector tmpShape = myGeometry.shape;
67 
68  // Move shape to side
69  tmpShape.move2side(1.5 * offsetSign);
70 
71  // Get position of the sign
72  mySignPos = tmpShape.getLineCenter();
73 
74  // Set block icon position
76 
77  // Set block icon rotation, and using their rotation for sign
79 
80  // last step is to check if object has to be added into grid (SUMOTree) again
81  if (updateGrid) {
83  }
84 }
85 
86 
87 void
89  // obtain circle resolution
90  int circleResolution = getCircleResolution(s);
91  // Get exaggeration
92  const double exaggeration = s.addSize.getExaggeration(s, this);
93  // Push name
94  glPushName(getGlID());
95  // Push base matrix
96  glPushMatrix();
97  // Traslate matrix
98  glTranslated(0, 0, getType());
99  // Set Color
102  } else {
104  }
105  // Draw base
107  // Check if the distance is enought to draw details and if is being drawn for selecting
108  if (s.drawForSelecting) {
109  // only draw circle depending of distance between sign and mouse cursor
111  // Add a draw matrix for details
112  glPushMatrix();
113  // Start drawing sign traslating matrix to signal position
114  glTranslated(mySignPos.x(), mySignPos.y(), 0);
115  // scale matrix depending of the exaggeration
116  glScaled(exaggeration, exaggeration, 1);
117  // set color
119  // Draw circle
120  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
121  // pop draw matrix
122  glPopMatrix();
123  }
124  } else if (s.scale * exaggeration >= 10) {
125  // Push matrix for details
126  glPushMatrix();
127  // push a new matrix for charging power
128  glPushMatrix();
129  // draw line with a color depending of the selection status
132  } else {
134  }
135  // pop matrix for charging power
136  glPopMatrix();
137  // Set position over sign
138  glTranslated(mySignPos.x(), mySignPos.y(), 0);
139  // Scale matrix
140  glScaled(exaggeration, exaggeration, 1);
141  // Set base color
144  } else {
146  }
147  // Draw extern
148  GLHelper::drawFilledCircle(myCircleWidth, circleResolution);
149  // Move to top
150  glTranslated(0, 0, .1);
151  // Set sign color
154  } else {
156  }
157  // Draw internt sign
158  GLHelper::drawFilledCircle(myCircleInWidth, circleResolution);
159  // Draw sign 'C'
160  if (s.scale * exaggeration >= 4.5) {
163  } else {
165  }
166  }
167  // Pop sign matrix
168  glPopMatrix();
169  // Draw icon
170  myBlockIcon.draw();
171  }
172  // Pop base matrix
173  glPopMatrix();
174  // Draw name if isn't being drawn for selecting
175  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
176  if (s.addFullName.show && (myAdditionalName != "") && !s.drawForSelecting) {
178  }
179  // check if dotted contour has to be drawn
180  if (!s.drawForSelecting && (myViewNet->getDottedAC() == this)) {
182  }
183  // Pop name matrix
184  glPopName();
185 }
186 
187 
188 std::string
190  switch (key) {
191  case SUMO_ATTR_ID:
192  return getAdditionalID();
193  case SUMO_ATTR_LANE:
194  return myLane->getID();
195  case SUMO_ATTR_STARTPOS:
196  return toString(myStartPosition);
197  case SUMO_ATTR_ENDPOS:
198  return myEndPosition;
199  case SUMO_ATTR_NAME:
200  return myAdditionalName;
204  return toString(myChargingPower);
206  return toString(myEfficiency);
208  return toString(myChargeInTransit);
210  return toString(myChargeDelay);
212  return toString(myBlockMovement);
213  case GNE_ATTR_SELECTED:
215  case GNE_ATTR_GENERIC:
216  return getGenericParametersStr();
217  default:
218  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
219  }
220 }
221 
222 
223 void
224 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
225  if (value == getAttribute(key)) {
226  return; //avoid needless changes, later logic relies on the fact that attributes have changed
227  }
228  switch (key) {
229  case SUMO_ATTR_ID:
230  case SUMO_ATTR_LANE:
231  case SUMO_ATTR_STARTPOS:
232  case SUMO_ATTR_ENDPOS:
233  case SUMO_ATTR_NAME:
240  case GNE_ATTR_SELECTED:
241  case GNE_ATTR_GENERIC:
242  undoList->p_add(new GNEChange_Attribute(this, key, value));
243  break;
244  default:
245  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
246  }
247 }
248 
249 
250 bool
251 GNEChargingStation::isValid(SumoXMLAttr key, const std::string& value) {
252  switch (key) {
253  case SUMO_ATTR_ID:
254  return isValidAdditionalID(value);
255  case SUMO_ATTR_LANE:
256  if (myViewNet->getNet()->retrieveLane(value, false) != nullptr) {
257  return true;
258  } else {
259  return false;
260  }
261  case SUMO_ATTR_STARTPOS:
262  if (value.empty()) {
263  return true;
264  } else {
265  if (canParse<double>(value)) {
266  if (canParse<double>(myEndPosition)) {
267  // Check that new start Position is smaller that end position
268  return (parse<double>(value) < parse<double>(myEndPosition));
269  } else {
270  return true;
271  }
272  } else {
273  return false;
274  }
275  }
276  case SUMO_ATTR_ENDPOS:
277  if (value.empty()) {
278  return true;
279  } else {
280  if (canParse<double>(value)) {
281  if (canParse<double>(myStartPosition)) {
282  // Check that new start Position is smaller that end position
283  return (parse<double>(myStartPosition) < parse<double>(value));
284  } else {
285  return true;
286  }
287  } else {
288  return false;
289  }
290  }
291  case SUMO_ATTR_NAME:
294  return canParse<bool>(value);
296  return (canParse<double>(value) && parse<double>(value) >= 0);
298  return (canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1);
300  return canParse<bool>(value);
302  return (canParse<double>(value) && parse<double>(value) >= 0);
304  return canParse<bool>(value);
305  case GNE_ATTR_SELECTED:
306  return canParse<bool>(value);
307  case GNE_ATTR_GENERIC:
308  return isGenericParametersValid(value);
309  default:
310  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
311  }
312 }
313 
314 // ===========================================================================
315 // private
316 // ===========================================================================
317 
318 void
319 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value) {
320  switch (key) {
321  case SUMO_ATTR_ID:
322  changeAdditionalID(value);
323  break;
324  case SUMO_ATTR_LANE:
325  myLane = changeLane(myLane, value);
326  break;
327  case SUMO_ATTR_STARTPOS:
328  myStartPosition = value;
329  break;
330  case SUMO_ATTR_ENDPOS:
331  myEndPosition = value;
332  break;
333  case SUMO_ATTR_NAME:
334  myAdditionalName = value;
335  break;
337  myFriendlyPosition = parse<bool>(value);
338  break;
340  myChargingPower = parse<double>(value);
341  break;
343  myEfficiency = parse<double>(value);
344  break;
346  myChargeInTransit = parse<bool>(value);
347  break;
349  myChargeDelay = parse<double>(value);
350  break;
352  myBlockMovement = parse<bool>(value);
353  break;
354  case GNE_ATTR_SELECTED:
355  if (parse<bool>(value)) {
357  } else {
359  }
360  break;
361  case GNE_ATTR_GENERIC:
363  break;
364  default:
365  throw InvalidArgument(getTagStr() + "attribute '" + toString(key) + "' not allowed");
366  }
367  // Update Geometry after setting a new attribute (but avoided for certain attributes)
368  if((key != SUMO_ATTR_ID) && (key != GNE_ATTR_GENERIC) && (key != GNE_ATTR_SELECTED)) {
369  updateGeometry(true);
370  }
371 }
372 
373 
374 /****************************************************************************/
double scale
information about a lane&#39;s width (temporary, used for a single view)
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
std::vector< double > shapeRotations
The rotations of the single shape parts.
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:62
static const double myCircleInWidth
inner circle width resolution for all stopping places
double x() const
Returns the x-position.
Definition: Position.h:57
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
Position position
position of the block icon
BlockIcon myBlockIcon
variable BlockIcon
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)
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
double rotation
The rotation of the block icon.
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
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
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
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
PositionVector shape
The shape of the additional element.
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:1160
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
RGBColor selectionColor
NETEDIT special colors.
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.
std::vector< double > shapeLengths
The lengths of the single shape parts.
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
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
GUIVisualizationTextSettings addFullName
AdditionalGeometry myGeometry
geometry to be precomputed in updateGeometry(...)
const std::string & getTagStr() const
get tag assigned to this object in string format
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
double distanceSquaredTo2D(const Position &p2) const
returns the square of the distance to another position (Only using x and y positions) ...
Definition: Position.h:249
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.
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) ...
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
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1153
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1059
GNELane * changeLane(GNELane *oldLane, const std::string &newLaneID)
change lane of additional
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry(bool updateGrid) function) ...
void draw(double size=0.5) const
draw lock icon
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...