Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/guisim/GUIChargingStation.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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 efficiency, bool chargeInTransit, SUMOTime chargeDelay,
58
const std::string& chargeType, SUMOTime waitingTime) :
59
MSChargingStation(id, lane, frompos, topos, name, chargingPower, 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 efficiency, bool chargeInTransit, SUMOTime chargeDelay,
67
const std::string& chargeType, SUMOTime waitingTime) :
68
MSChargingStation(id, parkingArea, name, chargingPower, 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, myChargingPower);
89
ret->mkItem(TL("charging efficiency [#]"), false, myEfficiency);
90
ret->mkItem(TL("charge in transit [true/false]"), false, myChargeInTransit);
91
ret->mkItem(TL("charge delay [s]"), false, STEPS2TIME(myChargeDelay));
92
ret->mkItem(TL("charge type"), false, chargeTypeToString(myChargeType));
93
ret->mkItem(TL("waiting time [s]"), false, STEPS2TIME(myWaitingTime));
94
// close building
95
ret->closeBuilding();
96
return ret;
97
}
98
99
100
GUIGLObjectPopupMenu*
101
GUIChargingStation::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {
102
GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
103
buildPopupHeader(ret, app);
104
buildCenterPopupEntry(ret);
105
buildNameCopyPopupEntry(ret);
106
buildSelectionPopupEntry(ret);
107
buildShowParamsPopupEntry(ret);
108
buildPositionCopyEntry(ret, app);
109
return ret;
110
}
111
112
113
double
114
GUIChargingStation::getExaggeration(const GUIVisualizationSettings& s) const {
115
return s.addSize.getExaggeration(s, this);
116
}
117
118
119
Boundary
120
GUIChargingStation::getCenteringBoundary() const {
121
Boundary b = myFGShape.getBoxBoundary();
122
b.grow(20);
123
return b;
124
}
125
126
127
void
128
GUIChargingStation::drawGL(const GUIVisualizationSettings& s) const {
129
// Draw Charging Station
130
GLHelper::pushName(getGlID());
131
GLHelper::pushMatrix();
132
133
// draw the area depending if the vehicle is charging
134
glTranslated(0, 0, getType());
135
136
137
138
// set color depending if charging station is charging
139
RGBColor csColor = (myChargingVehicle)? s.colorSettings.chargingStationColorCharge : s.colorSettings.chargingStationColor;
140
GLHelper::setColor(csColor);
141
142
const double exaggeration = getExaggeration(s);
143
144
if(myParkingArea != nullptr) {
145
// draw space background with charging station colors
146
const std::vector<MSParkingArea::LotSpaceDefinition>& spaces = myParkingArea->getSpaceOccupancies();
147
for(const auto& space : spaces) {
148
// draw box lines
149
GLHelper::drawBoxLine(space.position, space.rotation - 180., space.length, 0.5 * space.width);
150
}
151
152
// redraw spaces from parking area
153
GLHelper::pushMatrix();
154
glTranslated(0, 0, .1);
155
for(const auto& space : spaces) {
156
GLHelper::drawSpaceOccupancies(exaggeration, space.position, space.rotation,
157
space.width, space.length, space.vehicle ? true : false);
158
}
159
GLHelper::popMatrix();
160
} else {
161
GLHelper::drawBoxLines(myFGShape, myFGShapeRotations, myFGShapeLengths, MIN2(1.0, exaggeration));
162
}
163
164
// reset color because it may have changed due to redrawing occupied spaces
165
GLHelper::setColor(csColor);
166
167
// draw details unless zoomed out to far
168
if (s.drawDetail(10, exaggeration)) {
169
// push charging power matrix
170
GLHelper::pushMatrix();
171
// translate and rotate
172
const double rotSign = MSGlobals::gLefthand ? 1 : -1;
173
const double lineAngle = s.getTextAngle(myFGSignRot);
174
glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0.2);
175
glRotated(-lineAngle, 0, 0, 1);
176
// draw charging power
177
const double textOffset = s.flippedTextAngle(rotSign * myFGSignRot) ? -0.5 : -0.1;
178
GLHelper::drawText((toString(myChargingPower) + " W").c_str(), Position(1.2, textOffset), .1, 1.f, s.colorSettings.chargingStationColor, 0, FONS_ALIGN_LEFT);
179
// pop charging power matrix
180
GLHelper::popMatrix();
181
182
GLHelper::pushMatrix();
183
// draw the sign
184
glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0.2);
185
int noPoints = 9;
186
if (s.scale * exaggeration > 25) {
187
noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
188
}
189
190
glScaled(exaggeration, exaggeration, 1);
191
GLHelper::drawFilledCircle((double) 1.1, noPoints);
192
glTranslated(0, 0, .1);
193
194
GLHelper::setColor(s.colorSettings.chargingStationColorSign);
195
GLHelper::drawFilledCircle((double) 0.9, noPoints);
196
GLHelper::drawText("C", Position(), .1, 1.6, s.colorSettings.chargingStationColor, myFGSignRot);
197
198
//glTranslated(5, 0, 0);
199
GLHelper::popMatrix();
200
201
}
202
if (s.addFullName.show(this) && getMyName() != "") {
203
GLHelper::drawTextSettings(s.addFullName, getMyName(), myFGSignPos, s.scale, s.getTextAngle(myFGSignRot), GLO_MAX - getType());
204
}
205
GLHelper::popMatrix();
206
GLHelper::popName();
207
drawName(getCenteringBoundary().getCenter(), s.scale, s.addName, s.angle);
208
}
209
210
211
void
212
GUIChargingStation::initAppearance(MSLane& lane, double frompos, double topos) {
213
myFGShape = lane.getShape();
214
myFGShape = myFGShape.getSubpart(
215
lane.interpolateLanePosToGeometryPos(frompos),
216
lane.interpolateLanePosToGeometryPos(topos));
217
myFGShapeRotations.reserve(myFGShape.size() - 1);
218
myFGShapeLengths.reserve(myFGShape.size() - 1);
219
int e = (int)myFGShape.size() - 1;
220
for (int i = 0; i < e; ++i) {
221
const Position& f = myFGShape[i];
222
const Position& s = myFGShape[i + 1];
223
myFGShapeLengths.push_back(f.distanceTo(s));
224
myFGShapeRotations.push_back((double)atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double)M_PI);
225
}
226
PositionVector tmp = (myParkingArea != nullptr) ? myParkingArea->getShape() : myFGShape;
227
const double rotSign = MSGlobals::gLefthand ? -1 : 1;
228
const double offset = (myParkingArea != nullptr)? lane.getWidth() : 1.5;
229
tmp.move2side(offset * rotSign);
230
myFGSignPos = tmp.getLineCenter();
231
myFGSignRot = 0;
232
if (tmp.length() != 0) {
233
myFGSignRot = myFGShape.rotationDegreeAtOffset(double((tmp.length() / 2.)));
234
myFGSignRot -= 90 * rotSign;
235
}
236
}
237
238
239
const std::string
240
GUIChargingStation::getOptionalName() const {
241
return myName;
242
}
243
244
245
/****************************************************************************/
246
247