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();
67  myFGShape = myFGShape.getSubpart(frompos, topos);
68  myFGShapeRotations.reserve(myFGShape.size() - 1);
69  myFGShapeLengths.reserve(myFGShape.size() - 1);
70  int e = (int) myFGShape.size() - 1;
71  for (int i = 0; i < e; ++i) {
72  const Position& f = myFGShape[i];
73  const Position& s = myFGShape[i + 1];
74  myFGShapeLengths.push_back(f.distanceTo(s));
75  myFGShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) PI);
76  }
78  tmp.move2side(1.5);
79  myFGSignPos = tmp.getLineCenter();
80  myFGSignRot = 0;
81  if (tmp.length() != 0) {
83  myFGSignRot -= 90;
84  }
85 }
86 
87 
89 }
90 
91 
94  // Create table items
95  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 6);
96 
97  // add items
98  ret->mkItem("begin position [m]", false, myBegPos);
99  ret->mkItem("end position [m]", false, myEndPos);
100  ret->mkItem("charging power [W]", false, myChargingPower);
101  ret->mkItem("charging myEfficiency []", false, myEfficiency);
102  ret->mkItem("charge in transit [true/false]", false, myChargeInTransit);
103  ret->mkItem("charge delay [s]", false, myChargeDelay);
104 
105  // close building
106  ret->closeBuilding();
107  return ret;
108 }
109 
110 
113  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
114  buildPopupHeader(ret, app);
119  buildPositionCopyEntry(ret, false);
120  return ret;
121 }
122 
123 Boundary
126  b.grow(20);
127  return b;
128 }
129 
130 
131 void
133  // Draw Charging Station
134  glPushName(getGlID());
135  glPushMatrix();
136  RGBColor blue(114, 210, 252, 255);
137  RGBColor green(76, 170, 50, 255);
138  RGBColor yellow(255, 235, 0, 255);
139  RGBColor yellowCharge(255, 180, 0, 255);
140 
141  // draw the area depending if the vehicle is charging
142  glTranslated(0, 0, getType());
143 
144  if (myChargingVehicle == true) {
145  GLHelper::setColor(yellowCharge);
146  } else {
147  GLHelper::setColor(blue);
148  }
149  const double exaggeration = s.addSize.getExaggeration(s);
151 
152  // draw details unless zoomed out to far
153  if (s.scale * exaggeration >= 10) {
154 
155  // push charging power matrix
156  glPushMatrix();
157 
158  // Traslate End positionof signal
159  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
160 
161  // Rotate 180 (Eje X -> Mirror)
162  glRotated(180, 1, 0, 0);
163 
164  // Rotate again using myBlockIconRotation
165  glRotated(myFGSignRot, 0, 0, 1);
166 
167  // Set poligon mode
168  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
169 
170  // set polyfront position on 0,0
171  pfSetPosition(0, 0);
172 
173  // Set polyfront scale to 1
174  pfSetScale(1.f);
175 
176  // traslate matrix
177  glTranslated(1.2, 0, 0);
178 
179  // draw charging power
180  pfDrawString((toString(myChargingPower) + " W").c_str());
181 
182  // pop charging power matrix
183  glPopMatrix();
184 
185  // draw the sign
186  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
187  int noPoints = 9;
188  if (s.scale * exaggeration > 25) {
189  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
190  }
191 
192  glScaled(exaggeration, exaggeration, 1);
193  GLHelper::drawFilledCircle((double) 1.1, noPoints);
194  glTranslated(0, 0, .1);
195 
196  GLHelper::setColor(yellow);
197  GLHelper::drawFilledCircle((double) 0.9, noPoints);
198 
199  if (s.scale * exaggeration >= 4.5) {
200  GLHelper::drawText("C", Position(), .1, 1.6, blue, myFGSignRot);
201  }
202 
203  glTranslated(5, 0, 0);
204 
205  }
206  glPopMatrix();
207  glPopName();
208  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
209 }
210 
211 /****************************************************************************/
int pfDrawString(const char *c)
Definition: polyfonts.c:1074
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
PositionVector myFGShape
The shape.
a lane speed trigger,
double scale
information about a lane&#39;s width (temporary, used for a single view)
~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.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:68
double x() const
Returns the x-position.
Definition: Position.h:63
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:426
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:340
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
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.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
Position getLineCenter() const
get line center
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
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.
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:439
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
T MIN2(T a, T b)
Definition: StdDefs.h:64
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:234
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void move2side(double amount)
move position vector to side using certain ammount
Position myFGSignPos
The position of the sign.
const double myBegPos
The begin position this bus stop is located at.
int myChargeDelay
Charge Delay.
double length() const
Returns the length.
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.
GUIGlID getGlID() const
Returns the numerical id of the object.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:240
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
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:456
std::vector< double > myFGShapeLengths
The lengths of the shape parts.
double myFGSignRot
The rotation of the sign.
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
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.