LCOV - code coverage report
Current view: top level - src/microsim/transportables - MSStageMoving.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 90.9 % 44 40
Test Date: 2024-11-21 15:56:26 Functions: 93.3 % 15 14

            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    MSStageMoving.cpp
      15              : /// @author  Melanie Weber
      16              : /// @author  Andreas Kendziorra
      17              : /// @author  Michael Behrisch
      18              : /// @author  Jakob Erdmann
      19              : /// @date    Wed, 1 Jun 2022
      20              : ///
      21              : // The common superclass for modelling walking and tranship
      22              : /****************************************************************************/
      23              : #include <config.h>
      24              : 
      25              : #include <utils/options/OptionsCont.h>
      26              : #include <utils/router/IntermodalEdge.h>
      27              : #include <microsim/MSNet.h>
      28              : #include <microsim/MSEdge.h>
      29              : #include <microsim/MSLane.h>
      30              : #include <microsim/transportables/MSPModel.h>
      31              : #include <microsim/transportables/MSTransportable.h>
      32              : #include <microsim/transportables/MSStageMoving.h>
      33              : 
      34              : 
      35              : /* -------------------------------------------------------------------------
      36              : * MSStageMoving - methods
      37              : * ----------------------------------------------------------------------- */
      38       372112 : MSStageMoving::~MSStageMoving() {
      39       372112 :     if (myPState != nullptr && myPState->isFinished()) {
      40       367707 :         delete myPState;
      41              :     }
      42       372112 : }
      43              : 
      44              : const MSEdge*
      45      5098735 : MSStageMoving::getEdge() const {
      46      5098735 :     if (myCurrentInternalEdge != nullptr) {
      47              :         return myCurrentInternalEdge;
      48              :     } else {
      49      3650861 :         return myRouteStep == myRoute.end() ? nullptr : *myRouteStep;
      50              :     }
      51              : }
      52              : 
      53              : const MSEdge*
      54       154810 : MSStageMoving::getFromEdge() const {
      55       154810 :     return myRoute.front();
      56              : }
      57              : 
      58              : ConstMSEdgeVector
      59       339479 : MSStageMoving::getEdges() const {
      60       339479 :     return myRoute;
      61              : }
      62              : 
      63              : 
      64              : double
      65     11718249 : MSStageMoving::getEdgePos(SUMOTime now) const {
      66     11718249 :     return myPState == nullptr ? myDepartPos : myPState->getEdgePos(now);
      67              : }
      68              : 
      69              : int
      70       359391 : MSStageMoving::getDirection() const {
      71       359391 :     return myPState == nullptr ? MSPModel::UNDEFINED_DIRECTION : myPState->getDirection();
      72              : }
      73              : 
      74              : 
      75              : Position
      76      5190522 : MSStageMoving::getPosition(SUMOTime now) const {
      77      5190522 :     return myPState == nullptr ? Position::INVALID : myPState->getPosition(*this, now);
      78              : }
      79              : 
      80              : double
      81      3227232 : MSStageMoving::getAngle(SUMOTime now) const {
      82      3227232 :     return myPState == nullptr ? 0. : myPState->getAngle(*this, now);
      83              : }
      84              : 
      85              : SUMOTime
      86      9587847 : MSStageMoving::getWaitingTime(SUMOTime) const {
      87      9587847 :     return myPState == nullptr ? 0 : myPState->getWaitingTime();
      88              : }
      89              : 
      90              : double
      91       724769 : MSStageMoving::getSpeed() const {
      92       724769 :     return myPState == nullptr ? 0. : myPState->getSpeed(*this);
      93              : }
      94              : 
      95              : const MSLane*
      96       928303 : MSStageMoving::getLane() const {
      97       928303 :     return myPState == nullptr ? nullptr : myPState->getLane();
      98              : }
      99              : 
     100              : void
     101        10219 : MSStageMoving::setRouteIndex(MSTransportable* const transportable, int routeOffset) {
     102              :     assert(routeOffset >= 0);
     103              :     assert(routeOffset < (int)myRoute.size());
     104        10219 :     getEdge()->removeTransportable(transportable);
     105        10219 :     myRouteStep = myRoute.begin() + routeOffset;
     106        10219 :     getEdge()->addTransportable(transportable);
     107        10219 : }
     108              : 
     109              : void
     110           69 : MSStageMoving::replaceRoute(MSTransportable* const transportable, const ConstMSEdgeVector& edges, int routeOffset) {
     111              :     assert(routeOffset >= 0);
     112              :     assert(routeOffset < (int)edges.size());
     113           69 :     getEdge()->removeTransportable(transportable);
     114           69 :     myRoute = edges;
     115           69 :     myRouteStep = myRoute.begin() + routeOffset;
     116           69 :     getEdge()->addTransportable(transportable);
     117           69 : }
     118              : 
     119              : 
     120              : const MSLane*
     121       214224 : MSStageMoving::checkDepartLane(const MSEdge* edge, SUMOVehicleClass svc, int laneIndex, const std::string& id) {
     122       214224 :     const MSLane* lane = getSidewalk<MSEdge, MSLane>(edge, svc);
     123       214224 :     if (laneIndex > 0) {
     124              :         const std::vector<MSLane*>& departLanes = edge->getLanes();
     125            4 :         if ((int)departLanes.size() <= laneIndex || !departLanes[laneIndex]->allowsVehicleClass(svc)) {
     126            0 :             std::string error = "Invalid departLane '" + toString(laneIndex) + "' for person '" + id + "'";
     127            0 :             if (OptionsCont::getOptions().getBool("ignore-route-errors")) {
     128            0 :                 WRITE_WARNING(error);
     129              :                 return nullptr;
     130              :             } else {
     131            0 :                 throw ProcessError(error);
     132              :             }
     133              :         } else {
     134              :             lane = departLanes[laneIndex];
     135              :         }
     136              :     }
     137              :     return lane;
     138              : }
     139              : 
     140              : 
     141              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1