LCOV - code coverage report
Current view: top level - src/libtraci - Polygon.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 64 64
Test Date: 2024-10-24 15:46:30 Functions: 85.2 % 27 23

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2017-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    Polygon.cpp
      15              : /// @author  Gregor Laemmel
      16              : /// @date    15.03.2017
      17              : ///
      18              : // C++ TraCI client API implementation
      19              : /****************************************************************************/
      20              : #include <config.h>
      21              : 
      22              : #define LIBTRACI 1
      23              : #include "Domain.h"
      24              : #include <libsumo/Polygon.h>
      25              : #include <libsumo/StorageHelper.h>
      26              : 
      27              : 
      28              : namespace libtraci {
      29              : 
      30              : typedef Domain<libsumo::CMD_GET_POLYGON_VARIABLE, libsumo::CMD_SET_POLYGON_VARIABLE> Dom;
      31              : 
      32              : // ===========================================================================
      33              : // static member definitions
      34              : // ===========================================================================
      35              : std::vector<std::string>
      36           67 : Polygon::getIDList() {
      37          133 :     return Dom::getStringVector(libsumo::TRACI_ID_LIST, "");
      38              : }
      39              : 
      40              : 
      41              : int
      42           33 : Polygon::getIDCount() {
      43           66 :     return Dom::getInt(libsumo::ID_COUNT, "");
      44              : }
      45              : 
      46              : 
      47              : std::string
      48           23 : Polygon::getType(const std::string& polygonID) {
      49           23 :     return Dom::getString(libsumo::VAR_TYPE, polygonID);
      50              : }
      51              : 
      52              : 
      53              : libsumo::TraCIPositionVector
      54         2026 : Polygon::getShape(const std::string& polygonID) {
      55         2026 :     return Dom::getPolygon(libsumo::VAR_SHAPE, polygonID);
      56              : }
      57              : 
      58              : 
      59              : bool
      60           23 : Polygon::getFilled(const std::string& polygonID) {
      61           23 :     return Dom::getInt(libsumo::VAR_FILL, polygonID) != 0;
      62              : }
      63              : 
      64              : 
      65              : double
      66            2 : Polygon::getLineWidth(const std::string& polygonID) {
      67            2 :     return Dom::getDouble(libsumo::VAR_WIDTH, polygonID);
      68              : }
      69              : 
      70              : 
      71              : libsumo::TraCIColor
      72           24 : Polygon::getColor(const std::string& polygonID) {
      73           24 :     return Dom::getCol(libsumo::VAR_COLOR, polygonID);
      74              : }
      75              : 
      76              : 
      77            3 : LIBTRACI_PARAMETER_IMPLEMENTATION(Polygon, POLYGON)
      78              : 
      79              : 
      80              : void
      81            1 : Polygon::setType(const std::string& polygonID, const std::string& polygonType) {
      82            1 :     Dom::setString(libsumo::VAR_TYPE, polygonID, polygonType);
      83            1 : }
      84              : 
      85              : 
      86              : void
      87            1 : Polygon::setShape(const std::string& polygonID, const libsumo::TraCIPositionVector& shape) {
      88            1 :     tcpip::Storage content;
      89            1 :     StoHelp::writePolygon(content, shape);
      90            2 :     return Dom::set(libsumo::VAR_SHAPE, polygonID, &content);
      91            1 : }
      92              : 
      93              : 
      94              : void
      95            2 : Polygon::setColor(const std::string& polygonID, const libsumo::TraCIColor& c) {
      96            2 :     Dom::setCol(libsumo::VAR_COLOR, polygonID, c);
      97            2 : }
      98              : 
      99              : 
     100              : void
     101           37 : Polygon::add(const std::string& polygonID, const libsumo::TraCIPositionVector& shape, const libsumo::TraCIColor& color, bool fill, const std::string& polygonType, int layer, double lineWidth) {
     102           37 :     tcpip::Storage content;
     103              :     StoHelp::writeCompound(content, 6);
     104              :     StoHelp::writeTypedString(content, polygonType);
     105           37 :     content.writeUnsignedByte(libsumo::TYPE_COLOR);
     106           37 :     content.writeUnsignedByte(color.r);
     107           37 :     content.writeUnsignedByte(color.g);
     108           37 :     content.writeUnsignedByte(color.b);
     109           37 :     content.writeUnsignedByte(color.a);
     110           37 :     content.writeUnsignedByte(libsumo::TYPE_UBYTE);
     111           37 :     content.writeUnsignedByte(fill);
     112              :     StoHelp::writeTypedInt(content, layer);
     113           37 :     StoHelp::writePolygon(content, shape);
     114              :     StoHelp::writeTypedDouble(content, lineWidth);
     115           37 :     Dom::set(libsumo::ADD, polygonID, &content);
     116           37 : }
     117              : 
     118              : 
     119              : void
     120           35 : Polygon::addDynamics(const std::string& polygonID, const std::string& trackedObjectID, const std::vector<double>& timeSpan, const std::vector<double>& alphaSpan, bool looped, bool rotate) {
     121           35 :     tcpip::Storage content;
     122              :     StoHelp::writeCompound(content, 5);
     123              :     StoHelp::writeTypedString(content, trackedObjectID);
     124           35 :     content.writeUnsignedByte(libsumo::TYPE_DOUBLELIST);
     125           35 :     content.writeInt((int)timeSpan.size());
     126          155 :     for (const double d : timeSpan) {
     127          120 :         content.writeDouble(d);
     128              :     }
     129           35 :     content.writeUnsignedByte(libsumo::TYPE_DOUBLELIST);
     130           35 :     content.writeInt((int)alphaSpan.size());
     131          131 :     for (const double d : alphaSpan) {
     132           96 :         content.writeDouble(d);
     133              :     }
     134           35 :     content.writeUnsignedByte(libsumo::TYPE_UBYTE);
     135           35 :     content.writeUnsignedByte(looped);
     136           35 :     content.writeUnsignedByte(libsumo::TYPE_UBYTE);
     137           35 :     content.writeUnsignedByte(rotate);
     138           35 :     Dom::set(libsumo::VAR_ADD_DYNAMICS, polygonID, &content);
     139           35 : }
     140              : 
     141              : 
     142              : void
     143            7 : Polygon::remove(const std::string& polygonID, int layer) {
     144            7 :     Dom::setInt(libsumo::REMOVE, polygonID, layer);
     145            7 : }
     146              : 
     147              : 
     148              : void
     149            1 : Polygon::setFilled(std::string polygonID, bool filled) {
     150            1 :     Dom::setInt(libsumo::VAR_FILL, polygonID, filled);
     151            1 : }
     152              : 
     153              : 
     154              : void
     155            1 : Polygon::setLineWidth(std::string polygonID, double lineWidth) {
     156            1 :     Dom::setDouble(libsumo::VAR_WIDTH, polygonID, lineWidth);
     157            1 : }
     158              : 
     159              : 
     160         8142 : LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(Polygon, POLYGON)
     161              : 
     162              : 
     163              : }
     164              : 
     165              : 
     166              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1