SUMO - Simulation of Urban MObility
GUIChargingStation.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // A lane area vehicles can halt at (gui-version)
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
38 #include <utils/geom/Boundary.h>
39 #include <utils/gui/div/GLHelper.h>
40 #include <utils/common/ToString.h>
41 #include <microsim/MSNet.h>
42 #include <microsim/MSLane.h>
43 #include <microsim/MSEdge.h>
44 #include "GUINet.h"
45 #include "GUIEdge.h"
46 #include "GUIPerson.h"
47 #include "GUIChargingStation.h"
50 #include <gui/GUIGlobals.h>
56 #include <utils/geom/GeomHelper.h>
58 
59 #ifdef CHECK_MEMORY_LEAKS
60 #include <foreign/nvwa/debug_new.h>
61 #endif // CHECK_MEMORY_LEAKS
62 
63 
64 // ===========================================================================
65 // method definitions
66 // ===========================================================================
67 GUIChargingStation::GUIChargingStation(const std::string& id, MSLane& lane, SUMOReal frompos, SUMOReal topos, SUMOReal chargingPower, SUMOReal efficiency, bool chargeInTransit, int chargeDelay) :
68  MSChargingStation(id, lane, frompos, topos, chargingPower, efficiency, chargeInTransit, chargeDelay),
69  GUIGlObject_AbstractAdd("chargingStation", GLO_TRIGGER, id) {
70  myFGShape = lane.getShape();
71  myFGShape = myFGShape.getSubpart(frompos, topos);
72  myFGShapeRotations.reserve(myFGShape.size() - 1);
73  myFGShapeLengths.reserve(myFGShape.size() - 1);
74  int e = (int) myFGShape.size() - 1;
75  for (int i = 0; i < e; ++i) {
76  const Position& f = myFGShape[i];
77  const Position& s = myFGShape[i + 1];
78  myFGShapeLengths.push_back(f.distanceTo(s));
79  myFGShapeRotations.push_back((SUMOReal) atan2((s.x() - f.x()), (f.y() - s.y())) * (SUMOReal) 180.0 / (SUMOReal) PI);
80  }
82  tmp.move2side(1.5);
83  myFGSignPos = tmp.getLineCenter();
84  myFGSignRot = 0;
85  if (tmp.length() != 0) {
87  myFGSignRot -= 90;
88  }
89 }
90 
91 
93 }
94 
95 
98  // Create table items
99  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 6);
100 
101  // add items
102  ret->mkItem("begin position [m]", false, myBegPos);
103  ret->mkItem("end position [m]", false, myEndPos);
104  ret->mkItem("charging power [W]", false, myChargingPower);
105  ret->mkItem("charging myEfficiency []", false, myEfficiency);
106  ret->mkItem("charge in transit [true/false]", false, myChargeInTransit);
107  ret->mkItem("charge delay [s]", false, myChargeDelay);
108 
109  // close building
110  ret->closeBuilding();
111  return ret;
112 }
113 
114 
117  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
118  buildPopupHeader(ret, app);
123  buildPositionCopyEntry(ret, false);
124  return ret;
125 }
126 
127 Boundary
130  b.grow(20);
131  return b;
132 }
133 
134 
135 void
137  // Draw Charging Station
138  glPushName(getGlID());
139  glPushMatrix();
140  RGBColor blue(114, 210, 252, 255);
141  RGBColor green(76, 170, 50, 255);
142  RGBColor yellow(255, 235, 0, 255);
143  RGBColor yellowCharge(255, 180, 0, 255);
144 
145  // draw the area depending if the vehicle is charging
146  glTranslated(0, 0, getType());
147 
148  if (myChargingVehicle == true) {
149  GLHelper::setColor(yellowCharge);
150  } else {
151  GLHelper::setColor(blue);
152  }
153  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
155 
156  // draw details unless zoomed out to far
157  if (s.scale * exaggeration >= 10) {
158 
159  // push charging power matrix
160  glPushMatrix();
161 
162  // Traslate End positionof signal
163  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
164 
165  // Rotate 180 (Eje X -> Mirror)
166  glRotated(180, 1, 0, 0);
167 
168  // Rotate again using myBlockIconRotation
169  glRotated(myFGSignRot, 0, 0, 1);
170 
171  // Set poligon mode
172  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
173 
174  // set polyfront position on 0,0
175  pfSetPosition(0, 0);
176 
177  // Set polyfront scale to 1
178  pfSetScale(1.f);
179 
180  // traslate matrix
181  glTranslated(1.2, 0, 0);
182 
183  // draw charging power
184  pfDrawString((toString(myChargingPower) + " W").c_str());
185 
186  // pop charging power matrix
187  glPopMatrix();
188 
189  // draw the sign
190  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
191  int noPoints = 9;
192  if (s.scale * exaggeration > 25) {
193  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
194  }
195 
196  glScaled(exaggeration, exaggeration, 1);
197  GLHelper::drawFilledCircle((SUMOReal) 1.1, noPoints);
198  glTranslated(0, 0, .1);
199 
200  GLHelper::setColor(yellow);
201  GLHelper::drawFilledCircle((SUMOReal) 0.9, noPoints);
202 
203  if (s.scale * exaggeration >= 4.5) {
204  GLHelper::drawText("C", Position(), .1, 1.6, blue, myFGSignRot);
205  }
206 
207  glTranslated(5, 0, 0);
208 
209  }
210  glPopMatrix();
211  glPopName();
212  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
213 }
214 
215 /****************************************************************************/
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
draw name of item
SUMOReal myChargingPower
Charging station&#39;s charging power.
int pfDrawString(const char *c)
Definition: polyfonts.c:1074
PositionVector myFGShape
The shape.
a lane speed trigger,
~GUIChargingStation()
Destructor.
GUIVisualizationTextSettings addName
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:221
SUMOReal length() const
Returns the length.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Stores the information about how to visualize structures.
void pfSetPosition(SUMOReal x, SUMOReal y)
Definition: polyfonts.c:480
static void drawBoxLines(const PositionVector &geom, const std::vector< SUMOReal > &rots, const std::vector< SUMOReal > &lengths, SUMOReal width, int cornerDetail=0, SUMOReal offset=0)
Draws thick lines.
Definition: GLHelper.cpp:176
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:427
SUMOReal myEfficiency
Efficiency of the charging station.
static void drawText(const std::string &text, const Position &pos, const SUMOReal layer, const SUMOReal size, const RGBColor &col=RGBColor::BLACK, const SUMOReal angle=0)
draw Text with given parameters
Definition: GLHelper.cpp:460
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
const SUMOReal myEndPos
The end position this bus stop is located at.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used, also builds an entry for copying the geo-position.
const SUMOReal myBegPos
The begin position this bus stop is located at.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
Position getLineCenter() const
get line center
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
static void drawFilledCircle(SUMOReal width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:344
GUIChargingStation(const std::string &id, MSLane &lane, SUMOReal frompos, SUMOReal topos, SUMOReal chargingPower, SUMOReal efficiency, bool chargeInTransit, int chargeDelay)
Constructor.
bool myChargingVehicle
Check if in the current TimeStep chargingStation is charging a vehicle.
GUIVisualizationSizeSettings addSize
#define PI
Definition: polyfonts.c:61
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:443
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
SUMOReal myFGSignRot
The rotation of the sign.
std::vector< SUMOReal > myFGShapeLengths
The lengths of the shape parts.
PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const
get subpart of a position vector
T MIN2(T a, T b)
Definition: StdDefs.h:69
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Position myFGSignPos
The position of the sign.
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
Definition: Boundary.cpp:232
int myChargeDelay
Charge Delay.
void pfSetScale(SUMOReal s)
Definition: polyfonts.c:465
bool myChargeInTransit
Allow charge in transit.
The popup menu of a globject.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
GUIGlID getGlID() const
Returns the numerical id of the object.
void move2side(SUMOReal amount)
move position vector to side using certain ammount
#define SUMOReal
Definition: config.h:213
SUMOReal getExaggeration(const GUIVisualizationSettings &s, SUMOReal factor=20) const
return the drawing size including exaggeration and constantSize values
std::vector< SUMOReal > myFGShapeRotations
The rotations of the shape parts.
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
void closeBuilding()
Closes the building of the table.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
A window containing a gl-object&#39;s parameter.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.