LCOV - code coverage report
Current view: top level - src/traci-server/lib - TraCI_VehicleType.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 167 167 100.0 %
Date: 2017-11-11 03:29:50 Functions: 49 49 100.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
       3             : // Copyright (C) 2017-2017 German Aerospace Center (DLR) and others.
       4             : /****************************************************************************/
       5             : //
       6             : //   This program and the accompanying materials
       7             : //   are made available under the terms of the Eclipse Public License v2.0
       8             : //   which accompanies this distribution, and is available at
       9             : //   http://www.eclipse.org/legal/epl-v20.html
      10             : //
      11             : /****************************************************************************/
      12             : /// @file    TraCI_VehicleType.cpp
      13             : /// @author  Gregor Laemmel
      14             : /// @date    04.04.2017
      15             : /// @version $Id$
      16             : ///
      17             : // C++ TraCI client API implementation
      18             : /****************************************************************************/
      19             : 
      20             : 
      21             : // ===========================================================================
      22             : // included modules
      23             : // ===========================================================================
      24             : #ifdef _MSC_VER
      25             : #include <windows_config.h>
      26             : #else
      27             : #include <config.h>
      28             : #endif
      29             : 
      30             : #include <microsim/MSNet.h>
      31             : #include <microsim/MSVehicleControl.h>
      32             : #include <utils/emissions/PollutantsInterface.h>
      33             : #include <utils/xml/SUMOVehicleParserHelper.h>
      34             : #include "TraCI_VehicleType.h"
      35             : #include "TraCI.h"
      36             : 
      37             : 
      38             : // ===========================================================================
      39             : // method definitions
      40             : // ===========================================================================
      41          30 : std::vector<std::string> TraCI_VehicleType::getIDList() {
      42          30 :     std::vector<std::string> ids;
      43          30 :     MSNet::getInstance()->getVehicleControl().insertVTypeIDs(ids);
      44          30 :     return ids;
      45             : }
      46             : 
      47             : 
      48          49 : double TraCI_VehicleType::getLength(const std::string& typeID) {
      49          49 :     MSVehicleType* v = getVType(typeID);
      50          49 :     return v->getLength();
      51             : }
      52             : 
      53             : 
      54          43 : double TraCI_VehicleType::getMaxSpeed(const std::string& typeID) {
      55          43 :     MSVehicleType* v = getVType(typeID);
      56          43 :     return v->getMaxSpeed();
      57             : }
      58             : 
      59          54 : double TraCI_VehicleType::getActionStepLength(const std::string& typeID) {
      60          54 :     MSVehicleType* v = getVType(typeID);
      61          54 :     return v->getActionStepLengthSecs();
      62             : }
      63             : 
      64          12 : double TraCI_VehicleType::getSpeedFactor(const std::string& typeID) {
      65          12 :     MSVehicleType* v = getVType(typeID);
      66          12 :     return v->getSpeedFactor().getParameter()[0];
      67             : }
      68           6 : double TraCI_VehicleType::getSpeedDeviation(const std::string& typeID) {
      69           6 :     MSVehicleType* v = getVType(typeID);
      70           6 :     return v->getSpeedFactor().getParameter()[1];
      71             : }
      72         740 : double TraCI_VehicleType::getAccel(const std::string& typeID) {
      73         742 :     MSVehicleType* v = getVType(typeID);
      74         738 :     return v->getCarFollowModel().getMaxAccel();
      75             : }
      76          40 : double TraCI_VehicleType::getDecel(const std::string& typeID) {
      77          40 :     MSVehicleType* v = getVType(typeID);
      78          40 :     return v->getCarFollowModel().getMaxDecel();
      79             : }
      80          41 : double TraCI_VehicleType::getEmergencyDecel(const std::string& typeID) {
      81          41 :     MSVehicleType* v = getVType(typeID);
      82          41 :     return v->getCarFollowModel().getEmergencyDecel();
      83             : }
      84          41 : double TraCI_VehicleType::getApparentDecel(const std::string& typeID) {
      85          41 :     MSVehicleType* v = getVType(typeID);
      86          41 :     return v->getCarFollowModel().getApparentDecel();
      87             : }
      88          50 : double TraCI_VehicleType::getImperfection(const std::string& typeID) {
      89          50 :     MSVehicleType* v = getVType(typeID);
      90          50 :     return v->getCarFollowModel().getImperfection();
      91             : }
      92          40 : double TraCI_VehicleType::getTau(const std::string& typeID) {
      93          40 :     MSVehicleType* v = getVType(typeID);
      94          40 :     return v->getCarFollowModel().getHeadwayTime();
      95             : }
      96          34 : std::string TraCI_VehicleType::getVehicleClass(const std::string& typeID) {
      97          34 :     MSVehicleType* v = getVType(typeID);
      98          34 :     return toString(v->getVehicleClass());
      99             : }
     100          52 : std::string TraCI_VehicleType::getEmissionClass(const std::string& typeID) {
     101          52 :     MSVehicleType* v = getVType(typeID);
     102          52 :     return PollutantsInterface::getName(v->getEmissionClass());
     103             : }
     104          29 : std::string TraCI_VehicleType::getShapeClass(const std::string& typeID) {
     105          29 :     MSVehicleType* v = getVType(typeID);
     106          29 :     return getVehicleShapeName(v->getGuiShape());
     107             : }
     108          46 : double TraCI_VehicleType::getMinGap(const std::string& typeID) {
     109          46 :     MSVehicleType* v = getVType(typeID);
     110          46 :     return v->getMinGap();
     111             : }
     112          47 : double TraCI_VehicleType::getWidth(const std::string& typeID) {
     113          47 :     MSVehicleType* v = getVType(typeID);
     114          47 :     return v->getWidth();
     115             : }
     116          23 : double TraCI_VehicleType::getHeight(const std::string& typeID) {
     117          23 :     MSVehicleType* v = getVType(typeID);
     118          23 :     return v->getHeight();
     119             : }
     120           8 : TraCIColor TraCI_VehicleType::getColor(const std::string& typeID) {
     121           8 :     MSVehicleType* v = getVType(typeID);
     122           8 :     return TraCI::makeTraCIColor(v->getColor());
     123             : }
     124          19 : double TraCI_VehicleType::getMinGapLat(const std::string& typeID) {
     125          19 :     MSVehicleType* v = getVType(typeID);
     126          19 :     return v->getMinGapLat();
     127             : }
     128          19 : double TraCI_VehicleType::getMaxSpeedLat(const std::string& typeID) {
     129          19 :     MSVehicleType* v = getVType(typeID);
     130          19 :     return v->getMaxSpeedLat();
     131             : }
     132          19 : std::string TraCI_VehicleType::getLateralAlignment(const std::string& typeID) {
     133          19 :     MSVehicleType* v = getVType(typeID);
     134          19 :     return toString(v->getPreferredLateralAlignment());
     135             : }
     136             : 
     137             : 
     138             : std::string
     139           6 : TraCI_VehicleType::getParameter(const std::string& typeID, const std::string& key) {
     140           6 :     MSVehicleType* v = getVType(typeID);
     141           6 :     return v->getParameter().getParameter(key, "");
     142             : }
     143             : 
     144             : 
     145          23 : void TraCI_VehicleType::setLength(const std::string& typeID, double length)  {
     146          23 :     MSVehicleType* v = getVType(typeID);
     147          23 :     v->setLength(length);
     148          23 : }
     149          17 : void TraCI_VehicleType::setMaxSpeed(const std::string& typeID, double speed)  {
     150          17 :     MSVehicleType* v = getVType(typeID);
     151          17 :     v->setMaxSpeed(speed);
     152          17 : }
     153           9 : void TraCI_VehicleType::setActionStepLength(const std::string& typeID, double actionStepLength, bool resetActionOffset)  {
     154           9 :     MSVehicleType* v = getVType(typeID);
     155           9 :     v->setActionStepLength(SUMOVehicleParserHelper::processActionStepLength(actionStepLength), resetActionOffset);
     156           9 : }
     157           9 : void TraCI_VehicleType::setVehicleClass(const std::string& typeID, const std::string& clazz)  {
     158           9 :     MSVehicleType* v = getVType(typeID);
     159           9 :     v->setVClass(getVehicleClassID(clazz));
     160           9 : }
     161           6 : void TraCI_VehicleType::setSpeedFactor(const std::string& typeID, double factor)  {
     162           6 :     MSVehicleType* v = getVType(typeID);
     163           6 :     v->setSpeedFactor(factor);
     164           6 : }
     165           3 : void TraCI_VehicleType::setSpeedDeviation(const std::string& typeID, double deviation)  {
     166           3 :     MSVehicleType* v = getVType(typeID);
     167           3 :     v->setSpeedDeviation(deviation);
     168           3 : }
     169          10 : void TraCI_VehicleType::setEmissionClass(const std::string& typeID, const std::string& clazz)  {
     170          10 :     MSVehicleType* v = getVType(typeID);
     171          10 :     v->setEmissionClass(PollutantsInterface::getClassByName(clazz));
     172          10 : }
     173           7 : void TraCI_VehicleType::setShapeClass(const std::string& typeID, const std::string& shapeClass)  {
     174           7 :     MSVehicleType* v = getVType(typeID);
     175           7 :     v->setShape(getVehicleShapeID(shapeClass));
     176           7 : }
     177          17 : void TraCI_VehicleType::setWidth(const std::string& typeID, double width)  {
     178          17 :     MSVehicleType* v = getVType(typeID);
     179          17 :     v->setWidth(width);
     180          17 : }
     181          10 : void TraCI_VehicleType::setHeight(const std::string& typeID, double height)  {
     182          10 :     MSVehicleType* v = getVType(typeID);
     183          10 :     v->setHeight(height);
     184          10 : }
     185          16 : void TraCI_VehicleType::setMinGap(const std::string& typeID, double minGap)  {
     186          16 :     MSVehicleType* v = getVType(typeID);
     187          16 :     v->setMinGap(minGap);
     188          16 : }
     189          16 : void TraCI_VehicleType::setAccel(const std::string& typeID, double accel)  {
     190          16 :     MSVehicleType* v = getVType(typeID);
     191          16 :     v->getCarFollowModel().setMaxAccel(accel);
     192          16 : }
     193          12 : void TraCI_VehicleType::setDecel(const std::string& typeID, double decel)  {
     194          12 :     MSVehicleType* v = getVType(typeID);
     195          12 :     v->getCarFollowModel().setMaxDecel(decel);
     196          12 : }
     197          12 : void TraCI_VehicleType::setEmergencyDecel(const std::string& typeID, double decel)  {
     198          12 :     MSVehicleType* v = getVType(typeID);
     199          12 :     v->getCarFollowModel().setEmergencyDecel(decel);
     200          12 : }
     201          12 : void TraCI_VehicleType::setApparentDecel(const std::string& typeID, double decel)  {
     202          12 :     MSVehicleType* v = getVType(typeID);
     203          12 :     v->getCarFollowModel().setApparentDecel(decel);
     204          12 : }
     205          15 : void TraCI_VehicleType::setImperfection(const std::string& typeID, double imperfection)  {
     206          15 :     MSVehicleType* v = getVType(typeID);
     207          15 :     v->getCarFollowModel().setImperfection(imperfection);
     208          15 : }
     209          12 : void TraCI_VehicleType::setTau(const std::string& typeID, double tau)  {
     210          12 :     MSVehicleType* v = getVType(typeID);
     211          12 :     v->getCarFollowModel().setHeadwayTime(tau);
     212          12 : }
     213           7 : void TraCI_VehicleType::setColor(const std::string& typeID, const TraCIColor& c)  {
     214           7 :     MSVehicleType* v = getVType(typeID);
     215           7 :     v->setColor(TraCI::makeRGBColor(c));
     216             : 
     217           7 : }
     218           3 : void TraCI_VehicleType::setMinGapLat(const std::string& typeID, double minGapLat)  {
     219           3 :     MSVehicleType* v = getVType(typeID);
     220           3 :     v->setMinGapLat(minGapLat);
     221           3 : }
     222           3 : void TraCI_VehicleType::setMaxSpeedLat(const std::string& typeID, double speed)  {
     223           3 :     MSVehicleType* v = getVType(typeID);
     224           3 :     v->setMaxSpeedLat(speed);
     225           3 : }
     226           3 : void TraCI_VehicleType::setLateralAlignment(const std::string& typeID, const std::string& latAlignment)  {
     227           3 :     MSVehicleType* v = getVType(typeID);
     228           3 :     v->setPreferredLateralAlignment(SUMOXMLDefinitions::LateralAlignments.get(latAlignment));
     229           3 : }
     230           4 : void TraCI_VehicleType::copy(const std::string& origTypeID, const std::string& newTypeID)  {
     231           4 :     getVType(origTypeID)->duplicateType(newTypeID, true);
     232           4 : }
     233           3 : void TraCI_VehicleType::setParameter(const std::string& typeID, const std::string& name, const std::string& value) {
     234           3 :     MSVehicleType* v = getVType(typeID);
     235           3 :     ((SUMOVTypeParameter&) v->getParameter()).setParameter(name, value);
     236           3 : }
     237        1647 : MSVehicleType* TraCI_VehicleType::getVType(std::string id) {
     238        1647 :     MSVehicleType* t = MSNet::getInstance()->getVehicleControl().getVType(id);
     239        1647 :     if (t == 0) {
     240           2 :         throw TraCIException("Vehicle type '" + id + "' is not known");
     241             :     }
     242        1645 :     return t;
     243       43554 : }

Generated by: LCOV version 1.12