LCOV - code coverage report
Current view: top level - src/guisim - GUIParkingArea.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 74 103 71.8 %
Date: 2024-04-27 15:34:54 Functions: 7 10 70.0 %

          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    GUIParkingArea.cpp
      15             : /// @author  Mirco Sturari
      16             : /// @author  Jakob Erdmann
      17             : /// @date    Tue, 19.01.2016
      18             : ///
      19             : // A area where vehicles can park next to the road (gui version)
      20             : /****************************************************************************/
      21             : #include <config.h>
      22             : 
      23             : #include <string>
      24             : #include <foreign/fontstash/fontstash.h>
      25             : #include <gui/GUIApplicationWindow.h>
      26             : #include <gui/GUIGlobals.h>
      27             : #include <guisim/GUIParkingArea.h>
      28             : #include <guisim/GUIVehicle.h>
      29             : #include <microsim/MSEdge.h>
      30             : #include <microsim/MSLane.h>
      31             : #include <microsim/MSNet.h>
      32             : #include <microsim/logging/FunctionBinding.h>
      33             : #include <utils/common/MsgHandler.h>
      34             : #include <utils/common/ToString.h>
      35             : #include <utils/geom/Boundary.h>
      36             : #include <utils/geom/GeomHelper.h>
      37             : #include <utils/geom/PositionVector.h>
      38             : #include <utils/gui/div/GLHelper.h>
      39             : #include <utils/gui/div/GUIGlobalSelection.h>
      40             : #include <utils/gui/div/GUIParameterTableWindow.h>
      41             : #include <utils/gui/globjects/GLIncludes.h>
      42             : #include <utils/gui/globjects/GUIGLObjectPopupMenu.h>
      43             : #include <utils/gui/windows/GUIAppEnum.h>
      44             : 
      45             : #include "GUINet.h"
      46             : #include "GUIEdge.h"
      47             : #include "GUIContainer.h"
      48             : #include "GUIParkingArea.h"
      49             : 
      50             : 
      51             : // ===========================================================================
      52             : // method definitions
      53             : // ===========================================================================
      54         667 : GUIParkingArea::GUIParkingArea(const std::string& id, const std::vector<std::string>& lines, MSLane& lane,
      55             :                                double frompos, double topos, unsigned int capacity,
      56             :                                double width, double length, double angle, const std::string& name,
      57             :                                bool onRoad,
      58             :                                const std::string& departPos,
      59         667 :                                bool lefthand) :
      60             :     MSParkingArea(id, lines, lane, frompos, topos, capacity, width, length, angle, name, onRoad, departPos, lefthand),
      61         667 :     GUIGlObject_AbstractAdd(GLO_PARKING_AREA, id, GUIIconSubSys::getIcon(GUIIcon::PARKINGAREA)) {
      62         667 :     const double offsetSign = MSGlobals::gLefthand ? -1 : 1;
      63         667 :     myShapeRotations.reserve(myShape.size() - 1);
      64         667 :     myShapeLengths.reserve(myShape.size() - 1);
      65         667 :     int e = (int) myShape.size() - 1;
      66        1472 :     for (int i = 0; i < e; ++i) {
      67         805 :         const Position& f = myShape[i];
      68         805 :         const Position& s = myShape[i + 1];
      69         805 :         myShapeLengths.push_back(f.distanceTo(s));
      70         805 :         myShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI);
      71             :     }
      72             :     PositionVector tmp = myShape;
      73         667 :     tmp.move2side((lane.getWidth() + myWidth) * offsetSign);
      74         667 :     mySignPos = tmp.getLineCenter();
      75         667 :     mySignRot = 0;
      76         667 :     if (tmp.length() != 0) {
      77         667 :         mySignRot = myShape.rotationDegreeAtOffset(double((myShape.length() / 2.)));
      78         667 :         mySignRot -= 90;
      79             :     }
      80         667 :     myBoundary = myShape.getBoxBoundary();
      81         667 :     myBoundary.grow(20);
      82         667 : }
      83             : 
      84        2001 : GUIParkingArea::~GUIParkingArea() {}
      85             : 
      86             : 
      87             : GUIGLObjectPopupMenu*
      88           0 : GUIParkingArea::getPopUpMenu(GUIMainWindow& app,
      89             :                              GUISUMOAbstractView& parent) {
      90           0 :     GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
      91           0 :     buildPopupHeader(ret, app);
      92           0 :     buildCenterPopupEntry(ret);
      93           0 :     buildNameCopyPopupEntry(ret);
      94           0 :     buildSelectionPopupEntry(ret);
      95           0 :     buildShowParamsPopupEntry(ret);
      96           0 :     buildPositionCopyEntry(ret, app);
      97           0 :     return ret;
      98             : }
      99             : 
     100             : 
     101             : GUIParameterTableWindow*
     102           0 : GUIParkingArea::getParameterWindow(GUIMainWindow& app,
     103             :                                    GUISUMOAbstractView&) {
     104             :     GUIParameterTableWindow* ret =
     105           0 :         new GUIParameterTableWindow(app, *this);
     106             :     // add items
     107           0 :     ret->mkItem(TL("name"), false, getMyName());
     108           0 :     ret->mkItem(TL("begin position [m]"), false, myBegPos);
     109           0 :     ret->mkItem(TL("end position [m]"), false, myEndPos);
     110           0 :     ret->mkItem(TL("occupancy [#]"), true, getOccupancy());
     111           0 :     ret->mkItem(TL("capacity [#]"), false, getCapacity());
     112           0 :     ret->mkItem(TL("alternatives [#]"), false, getNumAlternatives());
     113             :     // close building
     114           0 :     ret->closeBuilding();
     115           0 :     return ret;
     116             : }
     117             : 
     118             : 
     119             : void
     120        8969 : GUIParkingArea::drawGL(const GUIVisualizationSettings& s) const {
     121        8969 :     GLHelper::pushName(getGlID());
     122        8969 :     GLHelper::pushMatrix();
     123        8969 :     RGBColor grey(177, 184, 186, 171);
     124        8969 :     RGBColor blue(83, 89, 172, 255);
     125        8969 :     RGBColor red(255, 0, 0, 255);
     126        8969 :     RGBColor green(0, 255, 0, 255);
     127             :     // draw the area
     128        8969 :     glTranslated(0, 0, getType());
     129        8969 :     GLHelper::setColor(blue);
     130        8969 :     const double exaggeration = getExaggeration(s);
     131       17938 :     GLHelper::drawBoxLines(myShape, myShapeRotations, myShapeLengths, myWidth / 2. * MIN2(1.0, exaggeration));
     132             :     // draw details unless zoomed out to far
     133        8969 :     if (s.scale * exaggeration >= 1) {
     134             :         // draw the lots
     135        7938 :         glTranslated(0, 0, .1);
     136             :         // calculate shape lengt
     137             :         double ShapeLength = 0;
     138       16155 :         for (const auto& length : myShapeLengths) {
     139        8217 :             ShapeLength += length;
     140             :         }
     141             :         // calculate index Updater
     142        7938 :         int indexUpdater = (int)((double)mySpaceOccupancies.size() / ShapeLength);
     143             :         // check if indexUpdater is 0
     144        7938 :         if (indexUpdater == 0 || (myCapacity != myRoadSideCapacity)) {
     145             :             indexUpdater = 1;
     146             :         }
     147             :         // draw spaceOccupancies
     148       23105 :         for (int i = 0; i < (int)mySpaceOccupancies.size(); i += indexUpdater) {
     149       15167 :             GLHelper::drawSpaceOccupancies(exaggeration, mySpaceOccupancies.at(i).position, mySpaceOccupancies.at(i).rotation,
     150       15167 :                                            mySpaceOccupancies.at(i).width, mySpaceOccupancies.at(i).length, mySpaceOccupancies.at(i).vehicle ? true : false);
     151             :         }
     152        7938 :         GLHelper::setColor(blue);
     153             :         // draw the lines
     154        7938 :         for (size_t i = 0; i != myLines.size(); ++i) {
     155             :             // push a new matrix for every line
     156           0 :             GLHelper::pushMatrix();
     157             :             // traslate and rotate
     158           0 :             glTranslated(mySignPos.x(), mySignPos.y(), 0);
     159           0 :             glRotated(180, 1, 0, 0);
     160           0 :             glRotated(mySignRot, 0, 0, 1);
     161             :             // draw line
     162           0 :             GLHelper::drawText(myLines[i].c_str(), Position(1.2, (double)i), .1, 1.f, RGBColor(76, 170, 50), 0, FONS_ALIGN_LEFT);
     163             :             // pop matrix for every line
     164           0 :             GLHelper::popMatrix();
     165             : 
     166             :         }
     167             :         // draw the sign
     168        7938 :         glTranslated(mySignPos.x(), mySignPos.y(), 0);
     169             :         int noPoints = 9;
     170        7938 :         if (s.scale * exaggeration > 25) {
     171           0 :             noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
     172             :         }
     173        7938 :         glScaled(exaggeration, exaggeration, 1);
     174        7938 :         GLHelper::drawFilledCircle((double) 1.1, noPoints);
     175        7938 :         glTranslated(0, 0, .1);
     176        7938 :         GLHelper::setColor(grey);
     177        7938 :         GLHelper::drawFilledCircle((double) 0.9, noPoints);
     178        7938 :         if (s.drawDetail(10, exaggeration)) {
     179          36 :             GLHelper::drawText("P", Position(), .1, 1.6, blue, mySignRot);
     180             :         }
     181             :     }
     182        8969 :     GLHelper::popMatrix();
     183        8969 :     if (s.addFullName.show(this) && getMyName() != "") {
     184           0 :         GLHelper::drawTextSettings(s.addFullName, getMyName(), mySignPos, s.scale, s.getTextAngle(mySignRot), GLO_MAX - getType());
     185             :     }
     186        8969 :     GLHelper::popName();
     187        8969 :     drawName(getCenteringBoundary().getCenter(), s.scale, s.addName, s.angle);
     188        8969 :     if (myCapacity != myRoadSideCapacity) {
     189             :         // draw parking vehicles (their lane might not be within drawing range. if it is, they are drawn twice)
     190         138 :         myLane.getVehiclesSecure();
     191         353 :         for (const MSBaseVehicle* const v : myLane.getParkingVehicles()) {
     192         215 :             static_cast<const GUIVehicle*>(v)->drawGL(s);
     193             :         }
     194         138 :         myLane.releaseVehicles();
     195             :     }
     196        8969 : }
     197             : 
     198             : void
     199          42 : GUIParkingArea::addLotEntry(double x, double y, double z,
     200             :                             double width, double length,
     201             :                             double angle, double slope) {
     202          42 :     MSParkingArea::addLotEntry(x, y, z, width, length, angle, slope);
     203          42 :     Boundary b;
     204          42 :     b.add(Position(x, y));
     205          42 :     b.grow(MAX2(width, length) + 5);
     206          42 :     myBoundary.add(b);
     207          42 : }
     208             : 
     209             : 
     210             : double
     211        8969 : GUIParkingArea::getExaggeration(const GUIVisualizationSettings& s) const {
     212        8969 :     return s.addSize.getExaggeration(s, this);
     213             : }
     214             : 
     215             : 
     216             : Boundary
     217        9636 : GUIParkingArea::getCenteringBoundary() const {
     218        9636 :     return myBoundary;
     219             : }
     220             : 
     221             : 
     222             : const std::string
     223           0 : GUIParkingArea::getOptionalName() const {
     224           0 :     return myName;
     225             : }
     226             : 
     227             : 
     228             : /****************************************************************************/

Generated by: LCOV version 1.14