LCOV - code coverage report
Current view: top level - src/polyconvert - PCLoaderXML.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 89.7 % 39 35
Test Date: 2024-11-20 15:55:46 Functions: 66.7 % 6 4

            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    PCLoaderXML.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Christoph Sommer
      18              : /// @author  Michael Behrisch
      19              : /// @date    Thu, 02.11.2006
      20              : ///
      21              : // A reader for polygons and pois stored in XML-format
      22              : /****************************************************************************/
      23              : #include <config.h>
      24              : 
      25              : #include <string>
      26              : #include <map>
      27              : #include <fstream>
      28              : #include <utils/options/OptionsCont.h>
      29              : #include <utils/options/Option.h>
      30              : #include <utils/common/MsgHandler.h>
      31              : #include <utils/common/FileHelpers.h>
      32              : #include <utils/common/RGBColor.h>
      33              : #include <utils/common/StdDefs.h>
      34              : #include <utils/common/SysUtils.h>
      35              : #include <polyconvert/PCPolyContainer.h>
      36              : #include <utils/geom/GeomHelper.h>
      37              : #include <utils/geom/Boundary.h>
      38              : #include <utils/geom/Position.h>
      39              : #include <utils/geom/GeoConvHelper.h>
      40              : #include <utils/xml/XMLSubSys.h>
      41              : #include <utils/geom/GeomConvHelper.h>
      42              : #include <utils/xml/SUMOXMLDefinitions.h>
      43              : #include "PCLoaderXML.h"
      44              : 
      45              : 
      46              : // ===========================================================================
      47              : // method definitions
      48              : // ===========================================================================
      49              : // ---------------------------------------------------------------------------
      50              : // static interface
      51              : // ---------------------------------------------------------------------------
      52              : void
      53           43 : PCLoaderXML::loadIfSet(OptionsCont& oc, PCPolyContainer& toFill,
      54              :                        PCTypeMap& tm) {
      55           86 :     if (!oc.isSet("xml-files")) {
      56           32 :         return;
      57              :     }
      58           11 :     PCLoaderXML handler(toFill, tm, oc);
      59              :     // parse file(s)
      60           22 :     std::vector<std::string> files = oc.getStringVector("xml");
      61           21 :     for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
      62           22 :         if (!FileHelpers::isReadable(*file)) {
      63            0 :             throw ProcessError(TLF("Could not open xml-file '%'.", *file));
      64              :         }
      65           33 :         const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing XML from '" + *file + "'");
      66           11 :         if (!XMLSubSys::runParser(handler, *file)) {
      67            1 :             throw ProcessError();
      68              :         }
      69           10 :         PROGRESS_TIME_MESSAGE(before);
      70              :     }
      71           11 : }
      72              : 
      73              : 
      74              : 
      75              : // ---------------------------------------------------------------------------
      76              : // handler methods
      77              : // ---------------------------------------------------------------------------
      78           11 : PCLoaderXML::PCLoaderXML(PCPolyContainer& toFill,
      79           11 :                          PCTypeMap& tm, OptionsCont& oc)
      80              :     : ShapeHandler("xml-poi-definition", toFill),
      81           22 :       myTypeMap(tm), myOptions(oc) {}
      82              : 
      83              : 
      84           11 : PCLoaderXML::~PCLoaderXML() {}
      85              : 
      86              : 
      87              : void
      88           29 : PCLoaderXML::myStartElement(int element,
      89              :                             const SUMOSAXAttributes& attrs) {
      90           29 :     if (element != SUMO_TAG_POI && element != SUMO_TAG_POLY) {
      91           11 :         return;
      92              :     }
      93           18 :     bool ok = true;
      94              :     // get the id, report an error if not given or empty...
      95           18 :     std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
      96           18 :     std::string type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok, myOptions.getString("type"));
      97           18 :     if (!ok) {
      98              :         return;
      99              :     }
     100              :     // patch the values
     101           18 :     bool discard = myOptions.getBool("discard");
     102           18 :     if (myTypeMap.has(type)) {
     103            0 :         const PCTypeMap::TypeDef& def = myTypeMap.get(type);
     104            0 :         discard = def.discard;
     105            0 :         setDefaults(def.prefix, def.color, def.icon, def.layer, def.allowFill != PCTypeMap::Filltype::NOFILL);
     106              :     } else {
     107           90 :         setDefaults(myOptions.getString("prefix"), RGBColor::parseColor(myOptions.getString("color")),
     108           72 :                     myOptions.getString("icon"), myOptions.getFloat("layer"), myOptions.getBool("fill"));
     109              :     }
     110           18 :     if (!discard) {
     111           18 :         if (element == SUMO_TAG_POI) {
     112           18 :             addPOI(attrs, myOptions.isInStringVector("prune.keep-list", id), true);
     113              :         }
     114           18 :         if (element == SUMO_TAG_POLY) {
     115           18 :             addPoly(attrs, myOptions.isInStringVector("prune.keep-list", id), true);
     116              :         }
     117              :     }
     118              : }
     119              : 
     120              : 
     121              : Position
     122            1 : PCLoaderXML::getLanePos(const std::string& poiID, const std::string& laneID, double lanePos, bool friendlyPos, double lanePosLat) {
     123            1 :     static_cast<PCPolyContainer&>(myShapeContainer).addLanePos(poiID, laneID, lanePos, friendlyPos, lanePosLat);
     124            1 :     return Position::INVALID;
     125              : }
     126              : 
     127              : 
     128              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1