Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/guisim/GUIChargingStation.cpp
193716 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file GUIChargingStation.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @author Tamas Kurczveil
19
/// @author Pablo Alvarez Lopez
20
/// @author Mirko Barthauer
21
/// @date 20-12-13
22
///
23
// A lane area vehicles can halt at (gui-version)
24
/****************************************************************************/
25
#include <config.h>
26
27
#include <foreign/fontstash/fontstash.h>
28
#include <gui/GUIApplicationWindow.h>
29
#include <gui/GUIGlobals.h>
30
#include <microsim/MSEdge.h>
31
#include <microsim/MSLane.h>
32
#include <microsim/MSNet.h>
33
#include <microsim/MSParkingArea.h>
34
#include <microsim/logging/FunctionBinding.h>
35
#include <utils/common/MsgHandler.h>
36
#include <utils/common/ToString.h>
37
#include <utils/geom/Boundary.h>
38
#include <utils/geom/GeomHelper.h>
39
#include <utils/geom/PositionVector.h>
40
#include <utils/gui/div/GLHelper.h>
41
#include <utils/gui/div/GUIGlobalSelection.h>
42
#include <utils/gui/div/GUIParameterTableWindow.h>
43
#include <utils/gui/globjects/GLIncludes.h>
44
#include <utils/gui/globjects/GUIGLObjectPopupMenu.h>
45
#include <utils/gui/windows/GUIAppEnum.h>
46
47
#include "GUINet.h"
48
#include "GUIEdge.h"
49
#include "GUIPerson.h"
50
#include "GUIChargingStation.h"
51
52
53
// ===========================================================================
54
// method definitions
55
// ===========================================================================
56
GUIChargingStation::GUIChargingStation(const std::string& id, MSLane& lane, double frompos, double topos, const std::string& name,
57
double chargingPower, double totalPower, double efficiency, bool chargeInTransit, SUMOTime chargeDelay,
58
const std::string& chargeType, SUMOTime waitingTime) :
59
MSChargingStation(id, lane, frompos, topos, name, chargingPower, totalPower, efficiency, chargeInTransit, chargeDelay, chargeType, waitingTime),
60
GUIGlObject_AbstractAdd(GLO_CHARGING_STATION, id, GUIIconSubSys::getIcon(GUIIcon::CHARGINGSTATION)) {
61
initAppearance(lane, frompos, topos);
62
}
63
64
65
GUIChargingStation::GUIChargingStation(const std::string& id, MSParkingArea* parkingArea, const std::string& name,
66
double chargingPower, double totalPower, double efficiency, bool chargeInTransit, SUMOTime chargeDelay,
67
const std::string& chargeType, SUMOTime waitingTime) :
68
MSChargingStation(id, parkingArea, name, chargingPower, totalPower, efficiency, chargeInTransit, chargeDelay, chargeType, waitingTime),
69
GUIGlObject_AbstractAdd(GLO_CHARGING_STATION, id, GUIIconSubSys::getIcon(GUIIcon::CHARGINGSTATION)) {
70
initAppearance(const_cast<MSLane&>(parkingArea->getLane()), parkingArea->getBeginLanePosition(), parkingArea->getEndLanePosition());
71
}
72
73
74
GUIChargingStation::~GUIChargingStation() {
75
}
76
77
78
GUIParameterTableWindow*
79
GUIChargingStation::getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView&) {
80
// Create table items
81
GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
82
// add items
83
ret->mkItem(TL("name"), false, getMyName());
84
ret->mkItem(TL("begin position [m]"), false, myBegPos);
85
ret->mkItem(TL("end position [m]"), false, myEndPos);
86
ret->mkItem(TL("stopped vehicles [#]"), true, new FunctionBinding<GUIChargingStation, int>(this, &MSStoppingPlace::getStoppedVehicleNumber));
87
ret->mkItem(TL("last free pos [m]"), true, new FunctionBinding<GUIChargingStation, double>(this, &MSStoppingPlace::getLastFreePos));
88
ret->mkItem(TL("charging power [W]"), false, myNominalChargingPower);
89
ret->mkItem(TL("total charging power [W]"), false, myTotalChargingPower);
90
ret->mkItem(TL("charging efficiency [#]"), false, myEfficiency);
91
ret->mkItem(TL("charge in transit [true/false]"), false, myChargeInTransit);
92
ret->mkItem(TL("charge delay [s]"), false, STEPS2TIME(myChargeDelay));
93
ret->mkItem(TL("charge type"), false, chargeTypeToString(myChargeType));
94
ret->mkItem(TL("waiting time [s]"), false, STEPS2TIME(myWaitingTime));
95
// close building
96
ret->closeBuilding();
97
return ret;
98
}
99
100
101
GUIGLObjectPopupMenu*
102
GUIChargingStation::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {
103
GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
104
buildPopupHeader(ret, app);
105
buildCenterPopupEntry(ret);
106
buildNameCopyPopupEntry(ret);
107
buildSelectionPopupEntry(ret);
108
buildShowParamsPopupEntry(ret);
109
buildPositionCopyEntry(ret, app);
110
return ret;
111
}
112
113
114
double
115
GUIChargingStation::getExaggeration(const GUIVisualizationSettings& s) const {
116
return s.addSize.getExaggeration(s, this);
117
}
118
119
120
Boundary
121
GUIChargingStation::getCenteringBoundary() const {
122
Boundary b = myFGShape.getBoxBoundary();
123
b.grow(20);
124
return b;
125
}
126
127
128
void
129
GUIChargingStation::drawGL(const GUIVisualizationSettings& s) const {
130
// Draw Charging Station
131
GLHelper::pushName(getGlID());
132
GLHelper::pushMatrix();
133
134
// draw the area depending if the vehicle is charging
135
glTranslated(0, 0, getType());
136
137
138
139
// set color depending if charging station is charging
140
RGBColor csColor = (myChargingVehicle) ? s.colorSettings.chargingStationColorCharge : s.colorSettings.chargingStationColor;
141
GLHelper::setColor(csColor);
142
143
const double exaggeration = getExaggeration(s);
144
145
if (myParkingArea != nullptr) {
146
// draw space background with charging station colors
147
const std::vector<MSParkingArea::LotSpaceDefinition>& spaces = myParkingArea->getSpaceOccupancies();
148
for (const auto& space : spaces) {
149
// draw box lines
150
GLHelper::drawBoxLine(space.position, space.rotation - 180., space.length, 0.5 * space.width);
151
}
152
153
// redraw spaces from parking area
154
GLHelper::pushMatrix();
155
glTranslated(0, 0, .1);
156
for (const auto& space : spaces) {
157
GLHelper::drawSpaceOccupancies(exaggeration, space.position, space.rotation,
158
space.width, space.length, space.vehicle ? true : false);
159
}
160
GLHelper::popMatrix();
161
} else {
162
GLHelper::drawBoxLines(myFGShape, myFGShapeRotations, myFGShapeLengths, MIN2(1.0, exaggeration));
163
}
164
165
// reset color because it may have changed due to redrawing occupied spaces
166
GLHelper::setColor(csColor);
167
168
// draw details unless zoomed out to far
169
if (s.drawDetail(10, exaggeration)) {
170
// push charging power matrix
171
GLHelper::pushMatrix();
172
// translate and rotate
173
const double rotSign = MSGlobals::gLefthand ? 1 : -1;
174
const double lineAngle = s.getTextAngle(myFGSignRot);
175
glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0.2);
176
glRotated(-lineAngle, 0, 0, 1);
177
// draw charging power
178
const double textOffset = s.flippedTextAngle(rotSign * myFGSignRot) ? -0.5 : -0.1;
179
GLHelper::drawText((toString(myNominalChargingPower) + " W").c_str(), Position(1.2, textOffset), .1, 1.f, s.colorSettings.chargingStationColor, 0, FONS_ALIGN_LEFT);
180
// pop charging power matrix
181
GLHelper::popMatrix();
182
183
GLHelper::pushMatrix();
184
// draw the sign
185
glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0.2);
186
int noPoints = 9;
187
if (s.scale * exaggeration > 25) {
188
noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
189
}
190
191
glScaled(exaggeration, exaggeration, 1);
192
GLHelper::drawFilledCircle((double) 1.1, noPoints);
193
glTranslated(0, 0, .1);
194
195
GLHelper::setColor(s.colorSettings.chargingStationColorSign);
196
GLHelper::drawFilledCircle((double) 0.9, noPoints);
197
GLHelper::drawText("C", Position(), .1, 1.6, s.colorSettings.chargingStationColor, myFGSignRot);
198
199
//glTranslated(5, 0, 0);
200
GLHelper::popMatrix();
201
202
}
203
if (s.addFullName.show(this) && getMyName() != "") {
204
GLHelper::drawTextSettings(s.addFullName, getMyName(), myFGSignPos, s.scale, s.getTextAngle(myFGSignRot), GLO_MAX - getType());
205
}
206
GLHelper::popMatrix();
207
GLHelper::popName();
208
drawName(getCenteringBoundary().getCenter(), s.scale, s.addName, s.angle);
209
}
210
211
212
void
213
GUIChargingStation::initAppearance(MSLane& lane, double frompos, double topos) {
214
myFGShape = lane.getShape();
215
myFGShape = myFGShape.getSubpart(
216
lane.interpolateLanePosToGeometryPos(frompos),
217
lane.interpolateLanePosToGeometryPos(topos));
218
myFGShapeRotations.reserve(myFGShape.size() - 1);
219
myFGShapeLengths.reserve(myFGShape.size() - 1);
220
int e = (int)myFGShape.size() - 1;
221
for (int i = 0; i < e; ++i) {
222
const Position& f = myFGShape[i];
223
const Position& s = myFGShape[i + 1];
224
myFGShapeLengths.push_back(f.distanceTo(s));
225
myFGShapeRotations.push_back((double)atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double)M_PI);
226
}
227
PositionVector tmp = (myParkingArea != nullptr) ? myParkingArea->getShape() : myFGShape;
228
const double rotSign = MSGlobals::gLefthand ? -1 : 1;
229
const double offset = (myParkingArea != nullptr) ? lane.getWidth() : 1.5;
230
tmp.move2side(offset * rotSign);
231
myFGSignPos = tmp.getLineCenter();
232
myFGSignRot = 0;
233
if (tmp.length() != 0) {
234
myFGSignRot = myFGShape.rotationDegreeAtOffset(double((tmp.length() / 2.)));
235
myFGSignRot -= 90 * rotSign;
236
}
237
}
238
239
240
const std::string
241
GUIChargingStation::getOptionalName() const {
242
return myName;
243
}
244
245
246
/****************************************************************************/
247
248