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-12-21 15:45:41 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       402460 : MSStageMoving::~MSStageMoving() {
      39       402460 :     if (myPState != nullptr && myPState->isFinished()) {
      40       398055 :         delete myPState;
      41              :     }
      42       402460 : }
      43              : 
      44              : const MSEdge*
      45      5555816 : MSStageMoving::getEdge() const {
      46      5555816 :     if (myCurrentInternalEdge != nullptr) {
      47              :         return myCurrentInternalEdge;
      48              :     } else {
      49      3955928 :         return myRouteStep == myRoute.end() ? nullptr : *myRouteStep;
      50              :     }
      51              : }
      52              : 
      53              : const MSEdge*
      54       154809 : MSStageMoving::getFromEdge() const {
      55       154809 :     return myRoute.front();
      56              : }
      57              : 
      58              : ConstMSEdgeVector
      59       342714 : MSStageMoving::getEdges() const {
      60       342714 :     return myRoute;
      61              : }
      62              : 
      63              : 
      64              : double
      65     11767237 : MSStageMoving::getEdgePos(SUMOTime now) const {
      66     11767237 :     return myPState == nullptr ? myDepartPos : myPState->getEdgePos(now);
      67              : }
      68              : 
      69              : int
      70       365304 : MSStageMoving::getDirection() const {
      71       365304 :     return myPState == nullptr ? MSPModel::UNDEFINED_DIRECTION : myPState->getDirection();
      72              : }
      73              : 
      74              : 
      75              : Position
      76      4516094 : MSStageMoving::getPosition(SUMOTime now) const {
      77      4516094 :     return myPState == nullptr ? Position::INVALID : myPState->getPosition(*this, now);
      78              : }
      79              : 
      80              : double
      81      2558745 : MSStageMoving::getAngle(SUMOTime now) const {
      82      2558745 :     return myPState == nullptr ? 0. : myPState->getAngle(*this, now);
      83              : }
      84              : 
      85              : SUMOTime
      86     11624207 : MSStageMoving::getWaitingTime(SUMOTime) const {
      87     11624207 :     return myPState == nullptr ? 0 : myPState->getWaitingTime();
      88              : }
      89              : 
      90              : double
      91       730923 : MSStageMoving::getSpeed() const {
      92       730923 :     return myPState == nullptr ? 0. : myPState->getSpeed(*this);
      93              : }
      94              : 
      95              : const MSLane*
      96       935965 : MSStageMoving::getLane() const {
      97       935965 :     return myPState == nullptr ? nullptr : myPState->getLane();
      98              : }
      99              : 
     100              : void
     101        10242 : MSStageMoving::setRouteIndex(MSTransportable* const transportable, int routeOffset) {
     102              :     assert(routeOffset >= 0);
     103              :     assert(routeOffset < (int)myRoute.size());
     104        10242 :     getEdge()->removeTransportable(transportable);
     105        10242 :     myRouteStep = myRoute.begin() + routeOffset;
     106        10242 :     getEdge()->addTransportable(transportable);
     107        10242 : }
     108              : 
     109              : void
     110           70 : MSStageMoving::replaceRoute(MSTransportable* const transportable, const ConstMSEdgeVector& edges, int routeOffset) {
     111              :     assert(routeOffset >= 0);
     112              :     assert(routeOffset < (int)edges.size());
     113           70 :     getEdge()->removeTransportable(transportable);
     114           70 :     myRoute = edges;
     115           70 :     myRouteStep = myRoute.begin() + routeOffset;
     116           70 :     getEdge()->addTransportable(transportable);
     117           70 : }
     118              : 
     119              : 
     120              : const MSLane*
     121       243771 : MSStageMoving::checkDepartLane(const MSEdge* edge, SUMOVehicleClass svc, int laneIndex, const std::string& id) {
     122       243771 :     const MSLane* lane = getSidewalk<MSEdge, MSLane>(edge, svc);
     123       243771 :     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