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

          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          45 : PCTypeDefHandler::PCTypeDefHandler(OptionsCont& oc, PCTypeMap& con) :
      41             :     SUMOSAXHandler(),
      42          45 :     myOptions(oc),
      43          45 :     myContainer(con),
      44          90 :     myOverwriteType(!oc.isDefault("type"))
      45          45 : {}
      46             : 
      47             : 
      48          45 : PCTypeDefHandler::~PCTypeDefHandler() {}
      49             : 
      50             : 
      51             : void
      52        1311 : PCTypeDefHandler::myStartElement(int element,
      53             :                                  const SUMOSAXAttributes& attrs) {
      54        1311 :     if (element == SUMO_TAG_POLYTYPE) {
      55        1282 :         bool ok = true;
      56             :         // get the id, report an error if not given or empty...
      57        1282 :         std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
      58        1282 :         if (!ok) {
      59             :             return;
      60             :         }
      61        2564 :         const std::string icon = attrs.getOpt<std::string>(SUMO_ATTR_ICON, id.c_str(), ok, myOptions.getString("icon"));
      62        2564 :         const double layer = attrs.getOpt<double>(SUMO_ATTR_LAYER, id.c_str(), ok, myOptions.getFloat("layer"));
      63        1282 :         const bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, id.c_str(), ok, false);
      64        1282 :         PCTypeMap::Filltype allowFill = myOptions.getBool("fill") ? PCTypeMap::FILL : PCTypeMap::NOFILL;
      65        1282 :         if (attrs.hasAttribute(SUMO_ATTR_FILL)) {
      66         502 :             const std::string allowFillS = attrs.get<std::string>(SUMO_ATTR_FILL, id.c_str(), ok);
      67         502 :             if (allowFillS == "force") {
      68             :                 allowFill = PCTypeMap::FORCE;
      69             :             } else {
      70         134 :                 allowFill = StringUtils::toBool(allowFillS) ? PCTypeMap::FILL : PCTypeMap::NOFILL;
      71             :             }
      72             :         }
      73        3846 :         const std::string type = attrs.getOpt<std::string>(SUMO_ATTR_NAME, id.c_str(), ok, myOverwriteType ? myOptions.getString("type") : id);
      74        2564 :         const std::string prefix = attrs.getOpt<std::string>(SUMO_ATTR_PREFIX, id.c_str(), ok, myOptions.getString("prefix"));
      75        2564 :         const std::string color = attrs.getOpt<std::string>(SUMO_ATTR_COLOR, id.c_str(), ok, myOptions.getString("color"));
      76        1282 :         const double angle = attrs.getOpt<double>(SUMO_ATTR_ANGLE, id.c_str(), ok, Shape::DEFAULT_ANGLE);
      77        1282 :         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        1282 :         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 1.14