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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // A class for visualizing chargingStation geometry (adapted from GUILaneWrapper)
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include <string>
30 #include <iostream>
31 #include <utility>
36 #include <utils/common/ToString.h>
37 #include <utils/geom/GeomHelper.h>
43 #include <utils/gui/div/GLHelper.h>
48 
49 #include "GNEChargingStation.h"
50 #include "GNELane.h"
51 #include "GNEEdge.h"
52 #include "GNEJunction.h"
53 #include "GNEUndoList.h"
54 #include "GNENet.h"
55 #include "GNEChange_Attribute.h"
56 #include "GNEViewNet.h"
57 
58 
59 // ===========================================================================
60 // member method definitions
61 // ===========================================================================
62 
63 GNEChargingStation::GNEChargingStation(const std::string& id, GNELane* lane, GNEViewNet* viewNet, double startPos, double endPos, const std::string& name,
64  double chargingPower, double efficiency, bool chargeInTransit, const double chargeDelay, bool friendlyPosition) :
65  GNEStoppingPlace(id, viewNet, SUMO_TAG_CHARGING_STATION, ICON_CHARGINGSTATION, lane, startPos, endPos, name, friendlyPosition),
66  myChargingPower(chargingPower),
67  myEfficiency(efficiency),
68  myChargeInTransit(chargeInTransit),
69  myChargeDelay(chargeDelay) {
70 }
71 
72 
74 
75 
76 void
78  // Get value of option "lefthand"
79  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
80 
81  // Update common geometry of stopping place
83 
84  // Obtain a copy of the shape
85  PositionVector tmpShape = myShape;
86 
87  // Move shape to side
88  tmpShape.move2side(1.5 * offsetSign);
89 
90  // Get position of the sign
91  mySignPos = tmpShape.getLineCenter();
92 
93  // Set block icon position
95 
96  // Set block icon rotation, and using their rotation for sign
98 
99  // Refresh element (neccesary to avoid grabbing problems)
100  myViewNet->getNet()->refreshElement(this);
101 }
102 
103 
104 void
106  // Write additional
107  device.openTag(getTag());
108  device.writeAttr(SUMO_ATTR_ID, getID());
109  device.writeAttr(SUMO_ATTR_LANE, myLane->getID());
112  if (myName.empty() == false) {
114  }
120  // Close tag
121  device.closeTag();
122 }
123 
124 
125 double
127  return myChargingPower;
128 }
129 
130 
131 double
133  return myEfficiency;
134 }
135 
136 
137 bool
139  return myChargeInTransit;
140 }
141 
142 
143 double
145  return myChargeDelay;
146 }
147 
148 
149 void
151  if (chargingPower > 0) {
152  myChargingPower = chargingPower;
153  } else {
154  throw InvalidArgument("Value of charging Power must be greater than 0");
155  }
156 }
157 
158 
159 void
161  if (efficiency >= 0 && efficiency <= 1) {
162  myEfficiency = efficiency;
163  } else {
164  throw InvalidArgument("Value of efficiency must be between 0 and 1");
165  }
166 }
167 
168 
169 void
171  myChargeInTransit = chargeInTransit;
172 }
173 
174 
175 void
177  if (chargeDelay < 0) {
178  throw InvalidArgument("Value of chargeDelay cannot be negative");
179  }
180  myChargeDelay = chargeDelay;
181 }
182 
183 
184 void
186  // Push name
187  glPushName(getGlID());
188 
189  // Push base matrix
190  glPushMatrix();
191 
192  // Traslate matrix
193  glTranslated(0, 0, getType());
194 
195  // Set Color
196  if (isAdditionalSelected()) {
198  } else {
199  GLHelper::setColor(RGBColor(114, 210, 252));
200  }
201 
202  // Get exaggeration
203  const double exaggeration = s.addSize.getExaggeration(s);
204 
205  // Draw base
207 
208  // draw details unless zoomed out to far
209  if (s.scale * exaggeration >= 10) {
210  // Push matrix for details
211  glPushMatrix();
212 
213  // push a new matrix for charging power
214  glPushMatrix();
215 
216  // draw line with a color depending of the selection status
217  if (isAdditionalSelected()) {
219  } else {
220  GLHelper::drawText((toString(myChargingPower) + " W").c_str(), mySignPos + Position(1.2, 0), .1, 1.f, RGBColor(114, 210, 252), myBlockIconRotation, FONS_ALIGN_LEFT);
221  }
222 
223  // pop matrix for charging power
224  glPopMatrix();
225 
226  // Set position over sign
227  glTranslated(mySignPos.x(), mySignPos.y(), 0);
228 
229  // Define number of points (for efficiency)
230  int noPoints = 9;
231 
232  // If the scale * exaggeration is more than 25, recalculate number of points
233  if (s.scale * exaggeration > 25) {
234  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
235  }
236 
237  // Scale matrix
238  glScaled(exaggeration, exaggeration, 1);
239 
240  // Set base color
241  if (isAdditionalSelected()) {
243  } else {
244  GLHelper::setColor(RGBColor(114, 210, 252));
245  }
246 
247  // Draw extern
248  GLHelper::drawFilledCircle((double) 1.1, noPoints);
249 
250  // Move to top
251  glTranslated(0, 0, .1);
252 
253  // Set sign color
254  if (isAdditionalSelected()) {
256  } else {
257  GLHelper::setColor(RGBColor(255, 235, 0));
258  }
259  // Draw internt sign
260  GLHelper::drawFilledCircle((double) 0.9, noPoints);
261 
262  // Draw sign 'C'
263  if (s.scale * exaggeration >= 4.5) {
264  if (isAdditionalSelected()) {
266  } else {
267  GLHelper::drawText("C", Position(), .1, 1.6, RGBColor(114, 210, 252, 255), myBlockIconRotation);
268  }
269  }
270  // Pop sign matrix
271  glPopMatrix();
272 
273  // Draw icon
275  }
276 
277  // Pop base matrix
278  glPopMatrix();
279 
280  // Pop name matrix
281  glPopName();
282 
283  // Draw name
284  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
285  if (s.addFullName.show && myName != "") {
287  }
288 }
289 
290 
291 std::string
293  switch (key) {
294  case SUMO_ATTR_ID:
295  return getAdditionalID();
296  case SUMO_ATTR_LANE:
297  return myLane->getID();
298  case SUMO_ATTR_STARTPOS:
300  case SUMO_ATTR_ENDPOS:
302  case SUMO_ATTR_NAME:
303  return myName;
307  return toString(myChargingPower);
309  return toString(myEfficiency);
311  return toString(myChargeInTransit);
313  return toString(myChargeDelay);
315  return toString(myBlocked);
316  default:
317  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
318  }
319 }
320 
321 
322 void
323 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
324  if (value == getAttribute(key)) {
325  return; //avoid needless changes, later logic relies on the fact that attributes have changed
326  }
327  switch (key) {
328  case SUMO_ATTR_ID:
329  case SUMO_ATTR_LANE:
330  case SUMO_ATTR_STARTPOS:
331  case SUMO_ATTR_ENDPOS:
332  case SUMO_ATTR_NAME:
339  undoList->p_add(new GNEChange_Attribute(this, key, value));
340  break;
341  default:
342  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
343  }
344 }
345 
346 
347 bool
348 GNEChargingStation::isValid(SumoXMLAttr key, const std::string& value) {
349  switch (key) {
350  case SUMO_ATTR_ID:
351  return isValidAdditionalID(value);
352  case SUMO_ATTR_LANE:
353  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
354  return true;
355  } else {
356  return false;
357  }
358  case SUMO_ATTR_STARTPOS:
359  if (canParse<double>(value)) {
360  // Check that new start Position is smaller that end position
361  return ((parse<double>(value) / myLane->getLaneParametricLength()) < myEndPosRelative);
362  } else {
363  return false;
364  }
365  case SUMO_ATTR_ENDPOS:
366  if (canParse<double>(value)) {
367  // Check that new end Position is larger that end position
368  return ((parse<double>(value) / myLane->getLaneParametricLength()) > myStartPosRelative);
369  } else {
370  return false;
371  }
372  case SUMO_ATTR_NAME:
373  return true;
375  return canParse<bool>(value);
377  return (canParse<double>(value) && parse<double>(value) >= 0);
379  return (canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1);
381  return canParse<bool>(value);
383  return (canParse<double>(value) && parse<double>(value) >= 0);
385  return canParse<bool>(value);
386  default:
387  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
388  }
389 }
390 
391 // ===========================================================================
392 // private
393 // ===========================================================================
394 
395 void
396 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value) {
397  switch (key) {
398  case SUMO_ATTR_ID:
399  changeAdditionalID(value);
400  break;
401  case SUMO_ATTR_LANE:
402  myLane = changeLane(myLane, value);
403  break;
404  case SUMO_ATTR_STARTPOS:
405  myStartPosRelative = parse<double>(value) / myLane->getLaneParametricLength();
406  break;
407  case SUMO_ATTR_ENDPOS:
408  myEndPosRelative = parse<double>(value) / myLane->getLaneParametricLength();
409  break;
410  case SUMO_ATTR_NAME:
411  myName = value;
412  break;
414  myFriendlyPosition = parse<bool>(value);
415  break;
417  myChargingPower = parse<double>(value);
418  break;
420  myEfficiency = parse<double>(value);
421  break;
423  myChargeInTransit = parse<bool>(value);
424  break;
426  myChargeDelay = parse<double>(value);
427  break;
429  myBlocked = parse<bool>(value);
430  break;
431  default:
432  throw InvalidArgument(toString(getTag()) + "attribute '" + toString(key) + "' not allowed");
433  }
434  // After setting attribute always update Geometry
435  updateGeometry();
436 }
437 
438 
439 /****************************************************************************/
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
double scale
information about a lane&#39;s width (temporary, used for a single view)
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:183
GUIVisualizationTextSettings addName
bool getChargeInTransit()
Returns the value of charge in transit of the chargingStation.
double getEfficiency()
Returns the charging efficiency of the chargingStation.
void refreshElement(GUIGlObject *o)
refreshes boundary information for o and update
Definition: GNENet.cpp:1082
const std::string & getAdditionalID() const
returns Additional ID
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
Stores the information about how to visualize structures.
Allow/disallow charge in transit in Charging Stations.
double y() const
Returns the y-position.
Definition: Position.h:67
double getAbsoluteEndPosition() const
get absolute end Position
double x() const
Returns the x-position.
Definition: Position.h:62
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:487
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:53
bool myFriendlyPosition
Flag for friendly position.
void setEfficiency(double efficiency)
Set a new efficiency in the charging station.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
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:350
void changeAdditionalID(const std::string &newID)
change ID of additional
double myEfficiency
efficiency of the charge
Position getLineCenter() const
get line center
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
void setChargeInTransit(bool chargeInTransit)
Enable or disable charge in transit in the charging station.
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:116
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:701
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:55
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:449
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
A list of positions.
GNELane * myLane
The lane in which this lane is placed.
friend class GNEChange_Attribute
declare friend class
double getChargeDelay()
Returns the charge delay of the chargingStation.
double getChargingPower()
Returns the charging power of the chargingStation.
block movement of a graphic element
void updateGeometry()
update pre-computed geometry information
T MIN2(T a, T b)
Definition: StdDefs.h:67
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.
const std::string getID() const
function to support debugging
void setChargeDelay(double chargeDelay)
Set a new charge delay in the charging station.
bool myChargeInTransit
enable or disable charge in transit
void move2side(double amount)
move position vector to side using certain ammount
double myChargingPower
Charging power pro timestep.
std::string myName
name of stoppingPlace
GNEChargingStation(const std::string &id, GNELane *lane, GNEViewNet *viewNet, double startPos, double endPos, const std::string &name, double chargingPower, double efficiency, bool chargeInTransit, const double chargeDelay, bool friendlyPosition)
Constructor of charging station.
bool myBlocked
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
GUIVisualizationTextSettings addFullName
double myEndPosRelative
The relative [0,1] end position this stopping place is located at.
double myStartPosRelative
The relative [0,1] start position this stopping place is located at.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void setBlockIconRotation(GNELane *additionalLane=NULL)
void setChargingPower(double chargingPower)
Set a new charging power in the charging station.
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.
void setStoppingPlaceGeometry()
set geometry common to all stopping places
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in all GNEAttributeCarriers.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
Eficiency of the charge in Charging Stations.
bool closeTag()
Closes the most recently opened tag.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
bool isAdditionalSelected() const
static const RGBColor selectionColor
Definition: GNENet.h:107
empty max
Delay in the charge of charging stations.
Position mySignPos
The position of the sign.
double getAbsoluteStartPosition() const
get absolute start Position
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1000
double myBlockIconRotation
The rotation of the block icon.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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