LCOV - code coverage report
Current view: top level - src/libtraci - GUI.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 8.5 % 71 6
Test Date: 2024-10-24 15:46:30 Functions: 6.1 % 33 2

            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    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           25 : GUI::getIDList() {
      36           25 :     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            0 : GUI::getZoom(const std::string& viewID) {
      48            0 :     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            0 : GUI::getOffset(const std::string& viewID) {
      60            0 :     return Dom::getPos(libsumo::VAR_VIEW_OFFSET, viewID);
      61              : }
      62              : 
      63              : 
      64              : std::string
      65            0 : GUI::getSchema(const std::string& viewID) {
      66            0 :     return Dom::getString(libsumo::VAR_VIEW_SCHEMA, viewID);
      67              : }
      68              : 
      69              : 
      70              : libsumo::TraCIPositionVector
      71            0 : GUI::getBoundary(const std::string& viewID) {
      72            0 :     return Dom::getPolygon(libsumo::VAR_VIEW_BOUNDARY, viewID);
      73              : }
      74              : 
      75              : 
      76            0 : LIBTRACI_PARAMETER_IMPLEMENTATION(GUI, GUI)
      77              : 
      78              : 
      79              : void
      80            0 : GUI::setZoom(const std::string& viewID, double zoom) {
      81            0 :     Dom::setDouble(libsumo::VAR_VIEW_ZOOM, viewID, zoom);
      82            0 : }
      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            0 : GUI::setOffset(const std::string& viewID, double x, double y) {
      93            0 :     tcpip::Storage content;
      94            0 :     content.writeUnsignedByte(libsumo::POSITION_2D);
      95            0 :     content.writeDouble(x);
      96            0 :     content.writeDouble(y);
      97            0 :     Dom::set(libsumo::VAR_VIEW_OFFSET, viewID, &content);
      98            0 : }
      99              : 
     100              : 
     101              : void
     102            0 : GUI::setSchema(const std::string& viewID, const std::string& schemeName) {
     103            0 :     Dom::setString(libsumo::VAR_VIEW_SCHEMA, viewID, schemeName);
     104            0 : }
     105              : 
     106              : void
     107            0 : GUI::addView(const std::string& viewID, const std::string& schemeName, bool in3D) {
     108            0 :     tcpip::Storage content;
     109              :     StoHelp::writeCompound(content, 2);
     110              :     StoHelp::writeTypedString(content, schemeName);
     111            0 :     StoHelp::writeTypedInt(content, in3D ? 1 : 0);
     112            0 :     Dom::set(libsumo::ADD, viewID, &content);
     113            0 : }
     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            0 : GUI::setBoundary(const std::string& viewID, double xmin, double ymin, double xmax, double ymax) {
     123            0 :     tcpip::Storage content;
     124            0 :     content.writeUnsignedByte(libsumo::TYPE_POLYGON);
     125            0 :     content.writeUnsignedByte(2);
     126            0 :     content.writeDouble(xmin);
     127            0 :     content.writeDouble(ymin);
     128            0 :     content.writeDouble(xmax);
     129            0 :     content.writeDouble(ymax);
     130            0 :     Dom::set(libsumo::VAR_VIEW_BOUNDARY, viewID, &content);
     131            0 : }
     132              : 
     133              : 
     134              : void
     135          100 : GUI::screenshot(const std::string& viewID, const std::string& filename, const int width, const int height) {
     136          100 :     tcpip::Storage content;
     137              :     StoHelp::writeCompound(content, 3);
     138              :     StoHelp::writeTypedString(content, filename);
     139              :     StoHelp::writeTypedInt(content, width);
     140              :     StoHelp::writeTypedInt(content, height);
     141          100 :     Dom::set(libsumo::VAR_SCREENSHOT, viewID, &content);
     142          100 : }
     143              : 
     144              : 
     145              : void
     146            0 : GUI::trackVehicle(const std::string& viewID, const std::string& vehID) {
     147            0 :     Dom::setString(libsumo::VAR_TRACK_VEHICLE, viewID, vehID);
     148            0 : }
     149              : 
     150              : 
     151              : bool
     152            0 : GUI::hasView(const std::string& viewID) {
     153            0 :     return Dom::getInt(libsumo::VAR_HAS_VIEW, viewID) != 0;
     154              : }
     155              : 
     156              : 
     157              : std::string
     158            0 : GUI::getTrackedVehicle(const std::string& viewID) {
     159            0 :     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            0 : GUI::isSelected(const std::string& objID, const std::string& objType) {
     171            0 :     tcpip::Storage content;
     172              :     StoHelp::writeTypedString(content, objType);
     173            0 :     return Dom::getInt(libsumo::VAR_SELECT, objID, &content) != 0;
     174            0 : }
     175              : 
     176              : 
     177              : void
     178            0 : GUI::toggleSelection(const std::string& objID, const std::string& objType) {
     179            0 :     Dom::setString(libsumo::VAR_SELECT, objID, objType);
     180            0 : }
     181              : 
     182              : 
     183            0 : LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(GUI, GUI)
     184              : 
     185              : 
     186              : }
     187              : 
     188              : 
     189              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1