LCOV - code coverage report
Current view: top level - src/traci-server - TraCIServerAPI_Polygon.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 91.2 % 57 52
Test Date: 2026-07-26 16:30:20 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2002-2026 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    TraCIServerAPI_Polygon.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Laura Bieker
      17              : /// @author  Michael Behrisch
      18              : /// @author  Jakob Erdmann
      19              : /// @author  Christoph Sommer
      20              : /// @author  Gregor Laemmel
      21              : /// @date    Sept 2002
      22              : ///
      23              : // APIs for getting/setting polygon values via TraCI
      24              : /****************************************************************************/
      25              : #include <config.h>
      26              : 
      27              : #include <utils/common/StdDefs.h>
      28              : #include <microsim/MSNet.h>
      29              : #include <utils/shapes/ShapeContainer.h>
      30              : #include <libsumo/Polygon.h>
      31              : #include <libsumo/Helper.h>
      32              : #include <libsumo/StorageHelper.h>
      33              : #include <libsumo/TraCIConstants.h>
      34              : #include "TraCIServerAPI_Polygon.h"
      35              : 
      36              : 
      37              : // ===========================================================================
      38              : // method definitions
      39              : // ===========================================================================
      40              : bool
      41          262 : TraCIServerAPI_Polygon::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
      42              :                                    tcpip::Storage& outputStorage) {
      43          262 :     std::string warning = ""; // additional description for response
      44              :     // variable
      45          262 :     int variable = inputStorage.readUnsignedByte();
      46          262 :     if (variable != libsumo::VAR_TYPE && variable != libsumo::VAR_COLOR && variable != libsumo::VAR_SHAPE && variable != libsumo::VAR_FILL
      47          234 :             && variable != libsumo::VAR_WIDTH && variable != libsumo::VAR_MOVE_TO
      48          130 :             && variable != libsumo::ADD && variable != libsumo::REMOVE && variable != libsumo::VAR_PARAMETER) {
      49            0 :         return server.writeErrorStatusCmd(libsumo::CMD_SET_POLYGON_VARIABLE,
      50            0 :                                           "Change Polygon State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
      51              :     }
      52              :     // id
      53          262 :     std::string id = inputStorage.readString();
      54              :     try {
      55              :         // process
      56          262 :         switch (variable) {
      57              :             case libsumo::VAR_TYPE:
      58            6 :                 libsumo::Polygon::setType(id, StoHelp::readTypedString(inputStorage, "The type must be given as a string."));
      59            4 :                 break;
      60              :             case libsumo::VAR_COLOR:
      61            9 :                 libsumo::Polygon::setColor(id, StoHelp::readTypedColor(inputStorage, "The color must be given using an according type."));
      62            7 :                 break;
      63              :             case libsumo::VAR_SHAPE:
      64            7 :                 libsumo::Polygon::setShape(id, StoHelp::readTypedPolygon(inputStorage, "The shape must be given using an according type."));
      65            5 :                 break;
      66              :             case libsumo::VAR_FILL:
      67           16 :                 libsumo::Polygon::setFilled(id, StoHelp::readTypedInt(inputStorage, "'fill' must be defined using an integer.") != 0);
      68            4 :                 break;
      69              :             case libsumo::VAR_WIDTH:
      70           12 :                 libsumo::Polygon::setLineWidth(id, StoHelp::readTypedDouble(inputStorage, "'lineWidth' must be defined using a double."));
      71            4 :                 break;
      72              :             case libsumo::VAR_HEIGHT:
      73              :                 libsumo::Polygon::setHeight(id, StoHelp::readTypedDouble(inputStorage, "'height' must be defined using a double."));
      74              :                 break;
      75              :             case libsumo::ADD: {
      76          107 :                 const int parameterCount = StoHelp::readCompound(inputStorage, -1, "A compound object is needed for adding a new polygon.");
      77          107 :                 if (parameterCount != 5 && parameterCount != 6) {
      78            0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Adding a polygon needs five to six parameters.", outputStorage);
      79              :                 }
      80          107 :                 const std::string type = StoHelp::readTypedString(inputStorage, "The type must be given as a string.");
      81          107 :                 const libsumo::TraCIColor col = StoHelp::readTypedColor(inputStorage, "The second polygon parameter must be the color.");
      82          107 :                 const bool fill = StoHelp::readBool(inputStorage, "The third polygon parameter must be 'fill' encoded as ubyte.");
      83          107 :                 const int layer = StoHelp::readTypedInt(inputStorage, "The fourth polygon parameter must be the layer encoded as int.");
      84          110 :                 const libsumo::TraCIPositionVector tp = StoHelp::readTypedPolygon(inputStorage, "The fifth polygon parameter must be the shape.");
      85              :                 double lineWidth = 1.;
      86          107 :                 if (parameterCount == 6) {
      87          215 :                     lineWidth = StoHelp::readTypedDouble(inputStorage, "The sixth polygon parameter must be the lineWidth encoded as double.");
      88              :                 }
      89          107 :                 libsumo::Polygon::add(id, tp, col, fill, type, layer, lineWidth);
      90              :             }
      91          104 :             break;
      92          100 :             case libsumo::VAR_ADD_DYNAMICS: {
      93          100 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
      94            0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_POLYGON_VARIABLE, "A compound object is needed for adding dynamics to a polygon.", outputStorage);
      95              :                 }
      96          100 :                 int itemNo = inputStorage.readInt();
      97          100 :                 if (itemNo != 5) {
      98            0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Adding polygon dynamics needs four parameters.", outputStorage);
      99              :                 }
     100          100 :                 const std::string trackedID = StoHelp::readTypedString(inputStorage, "The first parameter for adding polygon dynamics must be ID of the tracked object as a string ('' to disregard tracking).");
     101          138 :                 const std::vector<double> timeSpan = StoHelp::readTypedDoubleList(inputStorage, "The second parameter for adding polygon dynamics must be the timespan of the animation (length=0 to disregard animation).");
     102          100 :                 const std::vector<double> alphaSpan = StoHelp::readTypedDoubleList(inputStorage, "The third parameter for adding polygon dynamics must be the alphaSpanStr of the animation (length=0 to disregard alpha animation).");
     103          100 :                 const bool looped = StoHelp::readBool(inputStorage, "The fourth parameter for adding polygon dynamics must be boolean indicating whether the animation should be looped.");
     104          100 :                 const bool rotate = StoHelp::readBool(inputStorage, "The fifth parameter for adding polygon dynamics must be boolean indicating whether the tracking polygon should be rotated.");
     105          100 :                 libsumo::Polygon::addDynamics(id, trackedID, timeSpan, alphaSpan, looped, rotate);
     106          138 :             }
     107           62 :             break;
     108              :             case libsumo::REMOVE: {
     109           19 :                 libsumo::Polygon::remove(id, StoHelp::readTypedInt(inputStorage, "The layer must be given using an int."));
     110              :             }
     111           17 :             break;
     112              :             case libsumo::VAR_PARAMETER: {
     113            4 :                 StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");
     114            4 :                 const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");
     115            4 :                 const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");
     116            4 :                 libsumo::Polygon::setParameter(id, name, value);
     117              :             }
     118            4 :             break;
     119              :             default:
     120              :                 break;
     121              :         }
     122           51 :     } catch (libsumo::TraCIException& e) {
     123           51 :         return server.writeErrorStatusCmd(libsumo::CMD_SET_POLYGON_VARIABLE, e.what(), outputStorage);
     124           51 :     }
     125          211 :     server.writeStatusCmd(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);
     126              :     return true;
     127              : }
     128              : 
     129              : 
     130              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1