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-2017 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 
60 // ===========================================================================
61 // method definitions
62 // ===========================================================================
63 GUIChargingStation::GUIChargingStation(const std::string& id, MSLane& lane, double frompos, double topos, double chargingPower, double efficiency, bool chargeInTransit, int chargeDelay) :
64  MSChargingStation(id, lane, frompos, topos, chargingPower, efficiency, chargeInTransit, chargeDelay),
65  GUIGlObject_AbstractAdd("chargingStation", GLO_TRIGGER, id) {
66  myFGShape = lane.getShape();
68  lane.interpolateLanePosToGeometryPos(frompos),
70  myFGShapeRotations.reserve(myFGShape.size() - 1);
71  myFGShapeLengths.reserve(myFGShape.size() - 1);
72  int e = (int) myFGShape.size() - 1;
73  for (int i = 0; i < e; ++i) {
74  const Position& f = myFGShape[i];
75  const Position& s = myFGShape[i + 1];
76  myFGShapeLengths.push_back(f.distanceTo(s));
77  myFGShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI);
78  }
80  tmp.move2side(1.5);
81  myFGSignPos = tmp.getLineCenter();
82  myFGSignRot = 0;
83  if (tmp.length() != 0) {
85  myFGSignRot -= 90;
86  }
87 }
88 
89 
91 }
92 
93 
96  // Create table items
97  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 6);
98 
99  // add items
100  ret->mkItem("begin position [m]", false, myBegPos);
101  ret->mkItem("end position [m]", false, myEndPos);
102  ret->mkItem("charging power [W]", false, myChargingPower);
103  ret->mkItem("charging myEfficiency []", false, myEfficiency);
104  ret->mkItem("charge in transit [true/false]", false, myChargeInTransit);
105  ret->mkItem("charge delay [s]", false, myChargeDelay);
106 
107  // close building
108  ret->closeBuilding();
109  return ret;
110 }
111 
112 
115  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
116  buildPopupHeader(ret, app);
121  buildPositionCopyEntry(ret, false);
122  return ret;
123 }
124 
125 Boundary
128  b.grow(20);
129  return b;
130 }
131 
132 
133 void
135  // Draw Charging Station
136  glPushName(getGlID());
137  glPushMatrix();
138  RGBColor blue(114, 210, 252, 255);
139  RGBColor green(76, 170, 50, 255);
140  RGBColor yellow(255, 235, 0, 255);
141  RGBColor yellowCharge(255, 180, 0, 255);
142 
143  // draw the area depending if the vehicle is charging
144  glTranslated(0, 0, getType());
145 
146  if (myChargingVehicle == true) {
147  GLHelper::setColor(yellowCharge);
148  } else {
149  GLHelper::setColor(blue);
150  }
151  const double exaggeration = s.addSize.getExaggeration(s);
153 
154  // draw details unless zoomed out to far
155  if (s.scale * exaggeration >= 10) {
156 
157  // push charging power matrix
158  glPushMatrix();
159 
160  // Traslate End positionof signal
161  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
162 
163  // Rotate 180 (Eje X -> Mirror)
164  glRotated(180, 1, 0, 0);
165 
166  // Rotate again using myBlockIconRotation
167  glRotated(myFGSignRot, 0, 0, 1);
168 
169  // Set polygon mode
170  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
171 
172  // set polyfront position on 0,0
173  pfSetPosition(0, 0);
174 
175  // Set polyfront scale to 1
176  pfSetScale(1.f);
177 
178  // traslate matrix
179  glTranslated(1.2, 0, 0);
180 
181  // draw charging power
182  pfDrawString((toString(myChargingPower) + " W").c_str());
183 
184  // pop charging power matrix
185  glPopMatrix();
186 
187  // draw the sign
188  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
189  int noPoints = 9;
190  if (s.scale * exaggeration > 25) {
191  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
192  }
193 
194  glScaled(exaggeration, exaggeration, 1);
195  GLHelper::drawFilledCircle((double) 1.1, noPoints);
196  glTranslated(0, 0, .1);
197 
198  GLHelper::setColor(yellow);
199  GLHelper::drawFilledCircle((double) 0.9, noPoints);
200 
201  if (s.scale * exaggeration >= 4.5) {
202  GLHelper::drawText("C", Position(), .1, 1.6, blue, myFGSignRot);
203  }
204 
205  glTranslated(5, 0, 0);
206 
207  }
208  glPopMatrix();
209  glPopName();
210  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
211 }
212 
213 /****************************************************************************/
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
PositionVector myFGShape
The shape.
a lane speed trigger,
double scale
information about a lane&#39;s width (temporary, used for a single view)
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
~GUIChargingStation()
Destructor.
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
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
void pfSetScale(double s)
Definition: polyfonts.c:465
std::vector< double > myFGShapeRotations
The rotations of the shape parts.
const double myEndPos
The end position this bus stop is located at.
double x() const
Returns the x-position.
Definition: Position.h:63
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Stores the information about how to visualize structures.
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:442
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void pfSetPosition(double x, double y)
Definition: polyfonts.c:480
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:339
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.
GUIGlID getGlID() const
Returns the numerical id of the object.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
bool myChargingVehicle
Check if in the current TimeStep chargingStation is charging a vehicle.
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
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
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
double y() const
Returns the y-position.
Definition: Position.h:68
double length() const
Returns the length.
T MIN2(T a, T b)
Definition: StdDefs.h:68
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:302
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void move2side(double amount)
move position vector to side using certain ammount
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:240
Position myFGSignPos
The position of the sign.
const double myBegPos
The begin position this bus stop is located at.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
int myChargeDelay
Charge Delay.
#define M_PI
Definition: odrSpiral.cpp:40
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.
double myEfficiency
Efficiency of the charging station.
Position getLineCenter() const
get line center
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:426
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
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
std::vector< double > myFGShapeLengths
The lengths of the shape parts.
double myFGSignRot
The rotation of the sign.
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
GUIChargingStation(const std::string &id, MSLane &lane, double frompos, double topos, double chargingPower, double efficiency, bool chargeInTransit, int chargeDelay)
Constructor.
A window containing a gl-object&#39;s parameter.
double myChargingPower
Charging station&#39;s charging power.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.