LCOV - code coverage report
Current view: top level - src/guisim - GUIChargingStation.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 46.5 % 99 46
Test Date: 2024-11-22 15:46:21 Functions: 63.6 % 11 7

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2024 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          248 : 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          248 :                                        const std::string& chargeType, SUMOTime waitingTime) :
      59              :     MSChargingStation(id, lane, frompos, topos, name, chargingPower, efficiency, chargeInTransit, chargeDelay, chargeType, waitingTime),
      60          248 :     GUIGlObject_AbstractAdd(GLO_CHARGING_STATION, id, GUIIconSubSys::getIcon(GUIIcon::CHARGINGSTATION)) {
      61          248 :     initAppearance(lane, frompos, topos);
      62          248 : }
      63              : 
      64              : 
      65            0 : GUIChargingStation::GUIChargingStation(const std::string& id, MSParkingArea* parkingArea, const std::string& name,
      66              :                                        double chargingPower, double efficiency, bool chargeInTransit, SUMOTime chargeDelay,
      67            0 :                                        const std::string& chargeType, SUMOTime waitingTime) :
      68              :     MSChargingStation(id, parkingArea, name, chargingPower, efficiency, chargeInTransit, chargeDelay, chargeType, waitingTime),
      69            0 :     GUIGlObject_AbstractAdd(GLO_CHARGING_STATION, id, GUIIconSubSys::getIcon(GUIIcon::CHARGINGSTATION)) {
      70            0 :     initAppearance(const_cast<MSLane&>(parkingArea->getLane()), parkingArea->getBeginLanePosition(), parkingArea->getEndLanePosition());
      71            0 : }
      72              : 
      73              : 
      74          496 : GUIChargingStation::~GUIChargingStation() {
      75          496 : }
      76              : 
      77              : 
      78              : GUIParameterTableWindow*
      79            0 : GUIChargingStation::getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView&) {
      80              :     // Create table items
      81            0 :     GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
      82              :     // add items
      83            0 :     ret->mkItem(TL("name"), false, getMyName());
      84            0 :     ret->mkItem(TL("begin position [m]"), false, myBegPos);
      85            0 :     ret->mkItem(TL("end position [m]"), false, myEndPos);
      86            0 :     ret->mkItem(TL("stopped vehicles [#]"), true, new FunctionBinding<GUIChargingStation, int>(this, &MSStoppingPlace::getStoppedVehicleNumber));
      87            0 :     ret->mkItem(TL("last free pos [m]"), true, new FunctionBinding<GUIChargingStation, double>(this, &MSStoppingPlace::getLastFreePos));
      88            0 :     ret->mkItem(TL("charging power [W]"), false, myChargingPower);
      89            0 :     ret->mkItem(TL("charging efficiency [#]"), false, myEfficiency);
      90            0 :     ret->mkItem(TL("charge in transit [true/false]"), false, myChargeInTransit);
      91            0 :     ret->mkItem(TL("charge delay [s]"), false, STEPS2TIME(myChargeDelay));
      92            0 :     ret->mkItem(TL("charge type"), false, myChargeType);
      93            0 :     ret->mkItem(TL("waiting time [s]"), false, STEPS2TIME(myWaitingTime));
      94              :     // close building
      95            0 :     ret->closeBuilding();
      96            0 :     return ret;
      97              : }
      98              : 
      99              : 
     100              : GUIGLObjectPopupMenu*
     101            0 : GUIChargingStation::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {
     102            0 :     GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
     103            0 :     buildPopupHeader(ret, app);
     104            0 :     buildCenterPopupEntry(ret);
     105            0 :     buildNameCopyPopupEntry(ret);
     106            0 :     buildSelectionPopupEntry(ret);
     107            0 :     buildShowParamsPopupEntry(ret);
     108            0 :     buildPositionCopyEntry(ret, app);
     109            0 :     return ret;
     110              : }
     111              : 
     112              : 
     113              : double
     114         8276 : GUIChargingStation::getExaggeration(const GUIVisualizationSettings& s) const {
     115         8276 :     return s.addSize.getExaggeration(s, this);
     116              : }
     117              : 
     118              : 
     119              : Boundary
     120         8772 : GUIChargingStation::getCenteringBoundary() const {
     121         8772 :     Boundary b = myFGShape.getBoxBoundary();
     122         8772 :     b.grow(20);
     123         8772 :     return b;
     124            0 : }
     125              : 
     126              : 
     127              : void
     128         8276 : GUIChargingStation::drawGL(const GUIVisualizationSettings& s) const {
     129              :     // Draw Charging Station
     130         8276 :     GLHelper::pushName(getGlID());
     131         8276 :     GLHelper::pushMatrix();
     132              : 
     133              :     // draw the area depending if the vehicle is charging
     134         8276 :     glTranslated(0, 0, getType());
     135              : 
     136              :     // set color depending if charging station is charging
     137         8276 :     if (myChargingVehicle) {
     138          126 :         GLHelper::setColor(s.colorSettings.chargingStationColorCharge);
     139              :     } else {
     140         8150 :         GLHelper::setColor(s.colorSettings.chargingStationColor);
     141              :     }
     142         8276 :     const double exaggeration = getExaggeration(s);
     143         8276 :     GLHelper::drawBoxLines(myFGShape, myFGShapeRotations, myFGShapeLengths, MIN2(1.0, exaggeration));
     144              : 
     145              :     // draw details unless zoomed out to far
     146         8276 :     if (s.drawDetail(10, exaggeration)) {
     147              :         // push charging power matrix
     148            0 :         GLHelper::pushMatrix();
     149              :         // translate and rotate
     150            0 :         const double rotSign = MSGlobals::gLefthand ? 1 : -1;
     151            0 :         const double lineAngle = s.getTextAngle(myFGSignRot);
     152            0 :         glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
     153            0 :         glRotated(-lineAngle, 0, 0, 1);
     154              :         // draw charging power
     155            0 :         const double textOffset = s.flippedTextAngle(rotSign * myFGSignRot) ? -0.5 : -0.1;
     156            0 :         GLHelper::drawText((toString(myChargingPower) + " W").c_str(), Position(1.2, textOffset), .1, 1.f, s.colorSettings.chargingStationColor, 0, FONS_ALIGN_LEFT);
     157              :         // pop charging power matrix
     158            0 :         GLHelper::popMatrix();
     159              : 
     160            0 :         GLHelper::pushMatrix();
     161              :         // draw the sign
     162            0 :         glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
     163              :         int noPoints = 9;
     164            0 :         if (s.scale * exaggeration > 25) {
     165            0 :             noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
     166              :         }
     167              : 
     168            0 :         glScaled(exaggeration, exaggeration, 1);
     169            0 :         GLHelper::drawFilledCircle((double) 1.1, noPoints);
     170            0 :         glTranslated(0, 0, .1);
     171              : 
     172            0 :         GLHelper::setColor(s.colorSettings.chargingStationColorSign);
     173            0 :         GLHelper::drawFilledCircle((double) 0.9, noPoints);
     174            0 :         GLHelper::drawText("C", Position(), .1, 1.6, s.colorSettings.chargingStationColor, myFGSignRot);
     175              : 
     176            0 :         glTranslated(5, 0, 0);
     177            0 :         GLHelper::popMatrix();
     178              : 
     179              :     }
     180         8276 :     if (s.addFullName.show(this) && getMyName() != "") {
     181            0 :         GLHelper::drawTextSettings(s.addFullName, getMyName(), myFGSignPos, s.scale, s.getTextAngle(myFGSignRot), GLO_MAX - getType());
     182              :     }
     183         8276 :     GLHelper::popMatrix();
     184         8276 :     GLHelper::popName();
     185         8276 :     drawName(getCenteringBoundary().getCenter(), s.scale, s.addName, s.angle);
     186         8276 : }
     187              : 
     188              : 
     189              : void
     190          248 : GUIChargingStation::initAppearance(MSLane& lane, double frompos, double topos) {
     191              :     myFGShape = lane.getShape();
     192          496 :     myFGShape = myFGShape.getSubpart(
     193              :                     lane.interpolateLanePosToGeometryPos(frompos),
     194              :                     lane.interpolateLanePosToGeometryPos(topos));
     195          248 :     myFGShapeRotations.reserve(myFGShape.size() - 1);
     196          248 :     myFGShapeLengths.reserve(myFGShape.size() - 1);
     197          248 :     int e = (int)myFGShape.size() - 1;
     198          502 :     for (int i = 0; i < e; ++i) {
     199          254 :         const Position& f = myFGShape[i];
     200          254 :         const Position& s = myFGShape[i + 1];
     201          254 :         myFGShapeLengths.push_back(f.distanceTo(s));
     202          254 :         myFGShapeRotations.push_back((double)atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double)M_PI);
     203              :     }
     204              :     PositionVector tmp = myFGShape;
     205          248 :     const double rotSign = MSGlobals::gLefthand ? -1 : 1;
     206          248 :     tmp.move2side(1.5 * rotSign);
     207          248 :     myFGSignPos = tmp.getLineCenter();
     208          248 :     myFGSignRot = 0;
     209          248 :     if (tmp.length() != 0) {
     210          248 :         myFGSignRot = myFGShape.rotationDegreeAtOffset(double((myFGShape.length() / 2.)));
     211          248 :         myFGSignRot -= 90 * rotSign;
     212              :     }
     213          248 : }
     214              : 
     215              : 
     216              : const std::string
     217            0 : GUIChargingStation::getOptionalName() const {
     218            0 :     return myName;
     219              : }
     220              : 
     221              : 
     222              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1