LCOV - code coverage report
Current view: top level - src/polyconvert - PCTypeDefHandler.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 96.2 % 26 25
Test Date: 2024-12-21 15:45:41 Functions: 75.0 % 4 3

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-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    PCTypeDefHandler.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @date    Thu, 16.03.2006
      19              : ///
      20              : // A handler for loading polygon type maps
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : 
      24              : #include <string>
      25              : #include <utils/options/OptionsCont.h>
      26              : #include <utils/common/MsgHandler.h>
      27              : #include <utils/common/StringTokenizer.h>
      28              : #include <utils/common/RGBColor.h>
      29              : #include <utils/common/UtilExceptions.h>
      30              : #include <utils/xml/SUMOSAXHandler.h>
      31              : #include <utils/xml/SUMOXMLDefinitions.h>
      32              : #include <utils/shapes/Shape.h>
      33              : #include "PCTypeMap.h"
      34              : #include "PCTypeDefHandler.h"
      35              : 
      36              : 
      37              : // ===========================================================================
      38              : // method definitions
      39              : // ===========================================================================
      40           43 : PCTypeDefHandler::PCTypeDefHandler(OptionsCont& oc, PCTypeMap& con) :
      41              :     SUMOSAXHandler(),
      42           43 :     myOptions(oc),
      43           43 :     myContainer(con),
      44           86 :     myOverwriteType(!oc.isDefault("type"))
      45           43 : {}
      46              : 
      47              : 
      48           43 : PCTypeDefHandler::~PCTypeDefHandler() {}
      49              : 
      50              : 
      51              : void
      52         1203 : PCTypeDefHandler::myStartElement(int element,
      53              :                                  const SUMOSAXAttributes& attrs) {
      54         1203 :     if (element == SUMO_TAG_POLYTYPE) {
      55         1176 :         bool ok = true;
      56              :         // get the id, report an error if not given or empty...
      57         1176 :         std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
      58         1176 :         if (!ok) {
      59              :             return;
      60              :         }
      61         1176 :         const std::string icon = attrs.getOpt<std::string>(SUMO_ATTR_ICON, id.c_str(), ok, myOptions.getString("icon"));
      62         2352 :         const double layer = attrs.getOpt<double>(SUMO_ATTR_LAYER, id.c_str(), ok, myOptions.getFloat("layer"));
      63         1176 :         const bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, id.c_str(), ok, false);
      64         1176 :         PCTypeMap::Filltype allowFill = myOptions.getBool("fill") ? PCTypeMap::Filltype::FILL : PCTypeMap::Filltype::NOFILL;
      65         1176 :         if (attrs.hasAttribute(SUMO_ATTR_FILL)) {
      66          460 :             const std::string allowFillS = attrs.get<std::string>(SUMO_ATTR_FILL, id.c_str(), ok);
      67          460 :             if (allowFillS == "force") {
      68              :                 allowFill = PCTypeMap::Filltype::FORCE;
      69              :             } else {
      70          124 :                 allowFill = StringUtils::toBool(allowFillS) ? PCTypeMap::Filltype::FILL : PCTypeMap::Filltype::NOFILL;
      71              :             }
      72              :         }
      73         3528 :         const std::string type = attrs.getOpt<std::string>(SUMO_ATTR_NAME, id.c_str(), ok, myOverwriteType ? myOptions.getString("type") : id);
      74         1176 :         const std::string prefix = attrs.getOpt<std::string>(SUMO_ATTR_PREFIX, id.c_str(), ok, myOptions.getString("prefix"));
      75         1176 :         const std::string color = attrs.getOpt<std::string>(SUMO_ATTR_COLOR, id.c_str(), ok, myOptions.getString("color"));
      76         1176 :         const double angle = attrs.getOpt<double>(SUMO_ATTR_ANGLE, id.c_str(), ok, Shape::DEFAULT_ANGLE);
      77         1176 :         const std::string imgFile = attrs.getOpt<std::string>(SUMO_ATTR_IMGFILE, id.c_str(), ok, Shape::DEFAULT_IMG_FILE);
      78              :         // !!! what about error handling?
      79         1176 :         if (!myContainer.add(id, type, color, prefix, icon, layer, angle, imgFile, discard, allowFill)) {
      80            0 :             WRITE_ERRORF(TL("Could not add polygon type '%' (probably the id is already used)."), id);
      81              :         }
      82              :     }
      83              : }
      84              : 
      85              : 
      86              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1