SUMO - Simulation of Urban MObility
GNEChargingStation.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A class for visualizing chargingStation geometry (adapted from GUILaneWrapper)
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <string>
31 #include <iostream>
32 #include <utility>
37 #include <utils/common/ToString.h>
38 #include <utils/geom/GeomHelper.h>
45 #include <utils/gui/div/GLHelper.h>
50 
51 #include "GNEChargingStation.h"
52 #include "GNELane.h"
53 #include "GNEEdge.h"
54 #include "GNEJunction.h"
55 #include "GNEUndoList.h"
56 #include "GNENet.h"
57 #include "GNEChange_Attribute.h"
58 #include "GNEViewNet.h"
59 
60 
61 // ===========================================================================
62 // member method definitions
63 // ===========================================================================
64 
65 GNEChargingStation::GNEChargingStation(const std::string& id, GNELane* lane, GNEViewNet* viewNet, double startPos, double endPos, const std::string& name,
66  double chargingPower, double efficiency, bool chargeInTransit, const double chargeDelay, bool friendlyPosition) :
67  GNEStoppingPlace(id, viewNet, SUMO_TAG_CHARGING_STATION, ICON_CHARGINGSTATION, lane, startPos, endPos, name, friendlyPosition),
68  myChargingPower(chargingPower),
69  myEfficiency(efficiency),
70  myChargeInTransit(chargeInTransit),
71  myChargeDelay(chargeDelay) {
72  // When a new additional element is created, updateGeometry() must be called
74 }
75 
76 
78 
79 
80 void
82  // Get value of option "lefthand"
83  double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;
84 
85  // Update common geometry of stopping place
87 
88  // Obtain a copy of the shape
89  PositionVector tmpShape = myShape;
90 
91  // Move shape to side
92  tmpShape.move2side(1.5 * offsetSign);
93 
94  // Get position of the sign
95  mySignPos = tmpShape.getLineCenter();
96 
97  // Set block icon position
99 
100  // Set block icon rotation, and using their rotation for sign
102 
103  // Refresh element (neccesary to avoid grabbing problems)
105 }
106 
107 
108 void
109 GNEChargingStation::writeAdditional(OutputDevice& device, bool volatileOptionsEnabled) const {
110  // Write additional
111  device.openTag(getTag());
112  device.writeAttr(SUMO_ATTR_ID, getID());
113  // Check if another lane ID must be changed if sidewalks.guess option is enabled
114  if (volatileOptionsEnabled && OptionsCont::getOptions().getBool("sidewalks.guess") && (myLane->getParentEdge().getLanes().front()->isRestricted(SVC_PEDESTRIAN) == false)) {
115  // add a new extra lane to edge
117  // write ID (now is different because there are a new lane)
118  device.writeAttr(SUMO_ATTR_LANE, myLane->getID());
119  // undo set extra lane
120  myViewNet->getUndoList()->undo();
121  } else {
122  device.writeAttr(SUMO_ATTR_LANE, myLane->getID());
123  }
126  if (myName.empty() == false) {
128  }
134  if (myBlocked) {
136  }
137  // Close tag
138  device.closeTag();
139 }
140 
141 
142 double
144  return myChargingPower;
145 }
146 
147 
148 double
150  return myEfficiency;
151 }
152 
153 
154 bool
156  return myChargeInTransit;
157 }
158 
159 
160 double
162  return myChargeDelay;
163 }
164 
165 
166 void
168  if (chargingPower > 0) {
169  myChargingPower = chargingPower;
170  } else {
171  throw InvalidArgument("Value of charging Power must be greater than 0");
172  }
173 }
174 
175 
176 void
178  if (efficiency >= 0 && efficiency <= 1) {
179  myEfficiency = efficiency;
180  } else {
181  throw InvalidArgument("Value of efficiency must be between 0 and 1");
182  }
183 }
184 
185 
186 void
188  myChargeInTransit = chargeInTransit;
189 }
190 
191 
192 void
194  if (chargeDelay < 0) {
195  throw InvalidArgument("Value of chargeDelay cannot be negative");
196  }
197  myChargeDelay = chargeDelay;
198 }
199 
200 
201 void
203  // Push name
204  glPushName(getGlID());
205 
206  // Push base matrix
207  glPushMatrix();
208 
209  // Traslate matrix
210  glTranslated(0, 0, getType());
211 
212  // Set Color
213  if (isAdditionalSelected()) {
215  } else {
216  GLHelper::setColor(RGBColor(114, 210, 252));
217  }
218 
219  // Get exaggeration
220  const double exaggeration = s.addSize.getExaggeration(s);
221 
222  // Draw base
224 
225  // draw details unless zoomed out to far
226  if (s.scale * exaggeration >= 10) {
227  // Push sign matrix
228  glPushMatrix();
229 
230  // Set color of the charging power
231  if (isAdditionalSelected()) {
233  } else {
234  GLHelper::setColor(RGBColor(114, 210, 252));
235  }
236 
237  // push charging power matrix
238  glPushMatrix();
239 
240  // Traslate End positionof signal
241  glTranslated(mySignPos.x(), mySignPos.y(), 0);
242 
243  // Rotate 180 (Eje X -> Mirror)
244  glRotated(180, 1, 0, 0);
245 
246  // Rotate again using myBlockIconRotation
247  glRotated(myBlockIconRotation, 0, 0, 1);
248 
249  // Set polygon mode
250  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
251 
252  // set polyfront position on 0,0
253  pfSetPosition(0, 0);
254 
255  // Set polyfront scale to 1
256  pfSetScale(1.f);
257 
258  // traslate matrix
259  glTranslated(1.2, 0, 0);
260 
261  // draw charging power
262  pfDrawString((toString(myChargingPower) + " W").c_str());
263 
264  // pop charging power matrix
265  glPopMatrix();
266 
267  // Set position over sign
268  glTranslated(mySignPos.x(), mySignPos.y(), 0);
269 
270  // Define number of points (for efficiency)
271  int noPoints = 9;
272 
273  // If the scale * exaggeration is more than 25, recalculate number of points
274  if (s.scale * exaggeration > 25) {
275  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
276  }
277 
278  // Scale matrix
279  glScaled(exaggeration, exaggeration, 1);
280 
281  // Set base color
282  if (isAdditionalSelected()) {
284  } else {
285  GLHelper::setColor(RGBColor(114, 210, 252));
286  }
287 
288  // Draw extern
289  GLHelper::drawFilledCircle((double) 1.1, noPoints);
290 
291  // Move to top
292  glTranslated(0, 0, .1);
293 
294  // Set sign color
295  if (isAdditionalSelected()) {
297  } else {
298  GLHelper::setColor(RGBColor(255, 235, 0));
299  }
300  // Draw internt sign
301  GLHelper::drawFilledCircle((double) 0.9, noPoints);
302 
303  // Draw sign 'C'
304  if (s.scale * exaggeration >= 4.5) {
305  if (isAdditionalSelected()) {
307  } else {
308  GLHelper::drawText("C", Position(), .1, 1.6, RGBColor(114, 210, 252, 255), myBlockIconRotation);
309  }
310  }
311  // Pop sign matrix
312  glPopMatrix();
313 
314  // Draw icon
316  }
317 
318  // Pop base matrix
319  glPopMatrix();
320 
321  // Pop name matrix
322  glPopName();
323 
324  // Draw name
325  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
326 }
327 
328 
329 std::string
331  switch (key) {
332  case SUMO_ATTR_ID:
333  return getAdditionalID();
334  case SUMO_ATTR_LANE:
336  case SUMO_ATTR_STARTPOS:
338  case SUMO_ATTR_ENDPOS:
340  case SUMO_ATTR_NAME:
341  return myName;
345  return toString(myChargingPower);
347  return toString(myEfficiency);
349  return toString(myChargeInTransit);
351  return toString(myChargeDelay);
353  return toString(myBlocked);
354  default:
355  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
356  }
357 }
358 
359 
360 void
361 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
362  if (value == getAttribute(key)) {
363  return; //avoid needless changes, later logic relies on the fact that attributes have changed
364  }
365  switch (key) {
366  case SUMO_ATTR_ID:
367  case SUMO_ATTR_LANE:
368  case SUMO_ATTR_STARTPOS:
369  case SUMO_ATTR_ENDPOS:
370  case SUMO_ATTR_NAME:
377  undoList->p_add(new GNEChange_Attribute(this, key, value));
378  break;
379  default:
380  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
381  }
382 }
383 
384 
385 bool
386 GNEChargingStation::isValid(SumoXMLAttr key, const std::string& value) {
387  switch (key) {
388  case SUMO_ATTR_ID:
389  if (isValidID(value) && (myViewNet->getNet()->getAdditional(getTag(), value) == NULL)) {
390  return true;
391  } else {
392  return false;
393  }
394  case SUMO_ATTR_LANE:
395  if (myViewNet->getNet()->retrieveLane(value, false) != NULL) {
396  return true;
397  } else {
398  return false;
399  }
400  case SUMO_ATTR_STARTPOS:
401  if (canParse<double>(value)) {
402  // Check that new start Position is smaller that end position
403  return ((parse<double>(value) / myLane->getLaneParametricLength()) < myEndPosRelative);
404  } else {
405  return false;
406  }
407  case SUMO_ATTR_ENDPOS:
408  if (canParse<double>(value)) {
409  // Check that new end Position is larger that end position
410  return ((parse<double>(value) / myLane->getLaneParametricLength()) > myStartPosRelative);
411  } else {
412  return false;
413  }
414  case SUMO_ATTR_NAME:
415  return true;
417  return canParse<bool>(value);
419  return (canParse<double>(value) && parse<double>(value) >= 0);
421  return (canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1);
423  return canParse<bool>(value);
425  return (canParse<double>(value) && parse<double>(value) >= 0);
427  return canParse<bool>(value);
428  default:
429  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
430  }
431 }
432 
433 // ===========================================================================
434 // private
435 // ===========================================================================
436 
437 void
438 GNEChargingStation::setAttribute(SumoXMLAttr key, const std::string& value) {
439  switch (key) {
440  case SUMO_ATTR_ID:
441  setAdditionalID(value);
442  break;
443  case SUMO_ATTR_LANE:
444  changeLane(value);
445  break;
446  case SUMO_ATTR_STARTPOS:
447  myStartPosRelative = parse<double>(value) / myLane->getLaneParametricLength();
448  updateGeometry();
449  getViewNet()->update();
450  break;
451  case SUMO_ATTR_ENDPOS:
452  myEndPosRelative = parse<double>(value) / myLane->getLaneParametricLength();
453  updateGeometry();
454  getViewNet()->update();
455  break;
456  case SUMO_ATTR_NAME:
457  myName = value;
458  getViewNet()->update();
459  break;
461  myFriendlyPosition = parse<bool>(value);
462  getViewNet()->update();
463  break;
465  myChargingPower = parse<double>(value);
466  break;
468  myEfficiency = parse<double>(value);
469  break;
471  myChargeInTransit = parse<bool>(value);
472  break;
474  myChargeDelay = parse<double>(value);
475  break;
477  myBlocked = parse<bool>(value);
478  getViewNet()->update();
479  break;
480  default:
481  throw InvalidArgument(toString(getTag()) + "attribute '" + toString(key) + "' not allowed");
482  }
483 }
484 
485 
486 /****************************************************************************/
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:261
int pfDrawString(const char *c)
Definition: polyfonts.c:1074
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
void setBlockIconRotation()
double scale
information about a lane&#39;s width (temporary, used for a single view)
is a pedestrian
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:172
GUIVisualizationTextSettings addName
bool getChargeInTransit()
Returns the value of charge in transit of the chargingStation.
double getEfficiency()
Returns the charging efficiency of the chargingStation.
void pfSetScale(double s)
Definition: polyfonts.c:465
double getAbsoluteStartPosition() const
get absolute start Position
double x() const
Returns the x-position.
Definition: Position.h:63
GNELane * myLane
The lane this additional belongs.
Stores the information about how to visualize structures.
Allow/disallow charge in transit in Charging Stations.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
bool isAdditionalSelected() const
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
bool myFriendlyPosition
Flag for friendly position.
void setEfficiency(double efficiency)
Set a new efficiency in the charging station.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void pfSetPosition(double x, double y)
Definition: polyfonts.c:480
std::vector< double > myShapeRotations
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:339
GUIGlID getGlID() const
Returns the numerical id of the object.
double myEfficiency
efficiency of the charge
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void undo()
undo the last command group
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
void setChargeInTransit(bool chargeInTransit)
Enable or disable charge in transit in the charging station.
GNEUndoList * getUndoList() const
get the undoList object
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
static bool isValidID(const std::string &value)
true if value is a valid sumo ID
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
static const RGBColor selectedAdditionalColor
color of selected additionals
Definition: GNENet.h:112
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:438
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1085
const std::string & getAdditionalID() const
returns the ID of additional
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:998
PositionVector myShape
The shape of the additional element.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:958
friend class GNEChange_Attribute
declare friend class
double y() const
Returns the y-position.
Definition: Position.h:68
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:68
std::vector< double > myShapeLengths
The lengths of the shape parts.
~GNEChargingStation()
Destructor.
void setAdditionalID(const std::string &id)
set the ID of additional
const std::string getID() const
function to support debugging
void setChargeDelay(double chargeDelay)
Set a new charge delay in the charging station.
void drawLockIcon(double size=0.5) const
draw lock icon
bool myChargeInTransit
enable or disable charge in transit
void changeLane(const std::string &laneID)
change lane of additional
void move2side(double amount)
move position vector to side using certain ammount
double myChargingPower
Charging power pro timestep.
std::string myName
name of stoppingPlace
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in allGNEAttributeCarrier.
Definition: GNELane.cpp:770
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1680
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) ...
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:599
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in allGNEAttributeCarrier.
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 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
GNENet * getNet() const
get the net object
double myChargeDelay
delay in the starting of charge
Position getLineCenter() const
get line center
void setStoppingPlaceGeometry()
set geometry common to all stopping places
SumoXMLTag getTag() const
get XML Tag assigned to this object
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
Eficiency of the charge in Charging Stations.
bool closeTag()
Closes the most recently opened tag.
static const RGBColor selectionColor
Definition: GNENet.h:103
Delay in the charge of charging stations.
double getAbsoluteEndPosition() const
get absolute end Position
Position mySignPos
The position of the sign.
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)
draw Text with given parameters
Definition: GLHelper.cpp:455
void writeAdditional(OutputDevice &device, bool volatileOptionsEnabled) const
writte additional element into a xml file
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:719
double myBlockIconRotation
The rotation of the block icon.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void duplicateLane(GNELane *lane, GNEUndoList *undoList)
duplicates lane
Definition: GNENet.cpp:544
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 ...