LCOV - code coverage report
Current view: top level - src/libtraci - GUI.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 80.3 % 71 57
Test Date: 2025-11-13 15:38:19 Functions: 57.6 % 33 19

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2017-2025 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    GUI.cpp
      15              : /// @author  Michael Behrisch
      16              : /// @date    07.04.2021
      17              : ///
      18              : // C++ TraCI client API implementation
      19              : /****************************************************************************/
      20              : #include <config.h>
      21              : 
      22              : #define LIBTRACI 1
      23              : #include "Domain.h"
      24              : #include <libsumo/GUI.h>
      25              : 
      26              : 
      27              : namespace libtraci {
      28              : 
      29              : typedef Domain<libsumo::CMD_GET_GUI_VARIABLE, libsumo::CMD_SET_GUI_VARIABLE> Dom;
      30              : 
      31              : // ===========================================================================
      32              : // static member definitions
      33              : // ===========================================================================
      34              : std::vector<std::string>
      35           51 : GUI::getIDList() {
      36           53 :     return Dom::getStringVector(libsumo::TRACI_ID_LIST, "");
      37              : }
      38              : 
      39              : 
      40              : int
      41            0 : GUI::getIDCount() {
      42            0 :     return Dom::getInt(libsumo::ID_COUNT, "");
      43              : }
      44              : 
      45              : 
      46              : double
      47            1 : GUI::getZoom(const std::string& viewID) {
      48            1 :     return Dom::getDouble(libsumo::VAR_VIEW_ZOOM, viewID);
      49              : }
      50              : 
      51              : 
      52              : double
      53            0 : GUI::getAngle(const std::string& viewID) {
      54            0 :     return Dom::getDouble(libsumo::VAR_ANGLE, viewID);
      55              : }
      56              : 
      57              : 
      58              : libsumo::TraCIPosition
      59            1 : GUI::getOffset(const std::string& viewID) {
      60            1 :     return Dom::getPos(libsumo::VAR_VIEW_OFFSET, viewID);
      61              : }
      62              : 
      63              : 
      64              : std::string
      65            1 : GUI::getSchema(const std::string& viewID) {
      66            1 :     return Dom::getString(libsumo::VAR_VIEW_SCHEMA, viewID);
      67              : }
      68              : 
      69              : 
      70              : libsumo::TraCIPositionVector
      71            1 : GUI::getBoundary(const std::string& viewID) {
      72            1 :     return Dom::getPolygon(libsumo::VAR_VIEW_BOUNDARY, viewID);
      73              : }
      74              : 
      75              : 
      76            0 : LIBTRACI_PARAMETER_IMPLEMENTATION(GUI, GUI)
      77              : 
      78              : 
      79              : void
      80            1 : GUI::setZoom(const std::string& viewID, double zoom) {
      81            1 :     Dom::setDouble(libsumo::VAR_VIEW_ZOOM, viewID, zoom);
      82            1 : }
      83              : 
      84              : 
      85              : void
      86            0 : GUI::setAngle(const std::string& viewID, double angle) {
      87            0 :     Dom::setDouble(libsumo::VAR_ANGLE, viewID, angle);
      88            0 : }
      89              : 
      90              : 
      91              : void
      92            1 : GUI::setOffset(const std::string& viewID, double x, double y) {
      93            1 :     tcpip::Storage content;
      94            1 :     content.writeUnsignedByte(libsumo::POSITION_2D);
      95            1 :     content.writeDouble(x);
      96            1 :     content.writeDouble(y);
      97            1 :     Dom::set(libsumo::VAR_VIEW_OFFSET, viewID, &content);
      98            1 : }
      99              : 
     100              : 
     101              : void
     102            2 : GUI::setSchema(const std::string& viewID, const std::string& schemeName) {
     103            2 :     Dom::setString(libsumo::VAR_VIEW_SCHEMA, viewID, schemeName);
     104            2 : }
     105              : 
     106              : void
     107            1 : GUI::addView(const std::string& viewID, const std::string& schemeName, bool in3D) {
     108            1 :     tcpip::Storage content;
     109              :     StoHelp::writeCompound(content, 2);
     110              :     StoHelp::writeTypedString(content, schemeName);
     111            1 :     StoHelp::writeTypedInt(content, in3D ? 1 : 0);
     112            1 :     Dom::set(libsumo::ADD, viewID, &content);
     113            1 : }
     114              : 
     115              : void
     116            0 : GUI::removeView(const std::string& viewID) {
     117            0 :     Dom::set(libsumo::REMOVE, viewID, nullptr);
     118            0 : }
     119              : 
     120              : 
     121              : void
     122            1 : GUI::setBoundary(const std::string& viewID, double xmin, double ymin, double xmax, double ymax) {
     123            1 :     tcpip::Storage content;
     124            1 :     content.writeUnsignedByte(libsumo::TYPE_POLYGON);
     125            1 :     content.writeUnsignedByte(2);
     126            1 :     content.writeDouble(xmin);
     127            1 :     content.writeDouble(ymin);
     128            1 :     content.writeDouble(xmax);
     129            1 :     content.writeDouble(ymax);
     130            1 :     Dom::set(libsumo::VAR_VIEW_BOUNDARY, viewID, &content);
     131            1 : }
     132              : 
     133              : 
     134              : void
     135          102 : GUI::screenshot(const std::string& viewID, const std::string& filename, const int width, const int height) {
     136          102 :     tcpip::Storage content;
     137              :     StoHelp::writeCompound(content, 3);
     138              :     StoHelp::writeTypedString(content, filename);
     139              :     StoHelp::writeTypedInt(content, width);
     140              :     StoHelp::writeTypedInt(content, height);
     141          102 :     Dom::set(libsumo::VAR_SCREENSHOT, viewID, &content);
     142          102 : }
     143              : 
     144              : 
     145              : void
     146            1 : GUI::trackVehicle(const std::string& viewID, const std::string& vehID) {
     147            1 :     Dom::setString(libsumo::VAR_TRACK_VEHICLE, viewID, vehID);
     148            1 : }
     149              : 
     150              : 
     151              : bool
     152            2 : GUI::hasView(const std::string& viewID) {
     153            2 :     return Dom::getInt(libsumo::VAR_HAS_VIEW, viewID) != 0;
     154              : }
     155              : 
     156              : 
     157              : std::string
     158            1 : GUI::getTrackedVehicle(const std::string& viewID) {
     159            1 :     return Dom::getString(libsumo::VAR_TRACK_VEHICLE, viewID);
     160              : }
     161              : 
     162              : 
     163              : void
     164            0 : GUI::track(const std::string& objID, const std::string& viewID) {
     165            0 :     Dom::setString(libsumo::VAR_TRACK_VEHICLE, viewID, objID);
     166            0 : }
     167              : 
     168              : 
     169              : bool
     170            4 : GUI::isSelected(const std::string& objID, const std::string& objType) {
     171            4 :     tcpip::Storage content;
     172              :     StoHelp::writeTypedString(content, objType);
     173            8 :     return Dom::getInt(libsumo::VAR_SELECT, objID, &content) != 0;
     174            4 : }
     175              : 
     176              : 
     177              : void
     178            2 : GUI::toggleSelection(const std::string& objID, const std::string& objType) {
     179            2 :     Dom::setString(libsumo::VAR_SELECT, objID, objType);
     180            2 : }
     181              : 
     182              : 
     183           11 : LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(GUI, GUI)
     184              : 
     185              : 
     186              : }
     187              : 
     188              : 
     189              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1