LCOV - code coverage report
Current view: top level - src/polyconvert - PCNetProjectionLoader.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 86.1 % 36 31
Test Date: 2024-11-20 15:55:46 Functions: 50.0 % 6 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    PCNetProjectionLoader.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @date    Thu, 02.11.2006
      19              : ///
      20              : // A reader for a SUMO network's projection description
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : 
      24              : #include <string>
      25              : #include <map>
      26              : #include <fstream>
      27              : #include <utils/options/OptionsCont.h>
      28              : #include <utils/options/Option.h>
      29              : #include <utils/common/FileHelpers.h>
      30              : #include <utils/common/MsgHandler.h>
      31              : #include <utils/common/RGBColor.h>
      32              : #include <utils/common/StdDefs.h>
      33              : #include <utils/common/SysUtils.h>
      34              : #include <utils/geom/GeomHelper.h>
      35              : #include <utils/geom/Boundary.h>
      36              : #include <utils/geom/Position.h>
      37              : #include <utils/geom/GeoConvHelper.h>
      38              : #include <utils/xml/XMLSubSys.h>
      39              : #include <utils/xml/SUMOXMLDefinitions.h>
      40              : #include <utils/xml/SUMOSAXReader.h>
      41              : #include <utils/geom/GeomConvHelper.h>
      42              : #include <polyconvert/PCPolyContainer.h>
      43              : #include "PCNetProjectionLoader.h"
      44              : 
      45              : 
      46              : // ===========================================================================
      47              : // method definitions
      48              : // ===========================================================================
      49              : // ---------------------------------------------------------------------------
      50              : // static interface
      51              : // ---------------------------------------------------------------------------
      52              : void
      53           11 : PCNetProjectionLoader::load(const std::string& file, double scale) {
      54           22 :     if (!FileHelpers::isReadable(file)) {
      55            0 :         throw ProcessError(TLF("Could not open net-file '%'.", file));
      56              :     }
      57              :     // build handler and parser
      58           11 :     PCNetProjectionLoader handler(scale);
      59           11 :     handler.setFileName(file);
      60           11 :     SUMOSAXReader* parser = XMLSubSys::getSAXReader(handler, true);
      61           33 :     const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing network projection from '" + file + "'");
      62           22 :     if (!parser->parseFirst(file)) {
      63            0 :         delete parser;
      64            0 :         throw ProcessError(TLF("Can not read XML-file '%'.", handler.getFileName()));
      65              :     }
      66              :     // parse
      67           66 :     while (parser->parseNext() && !handler.hasReadAll());
      68              :     // clean up
      69           11 :     PROGRESS_TIME_MESSAGE(before);
      70           11 :     if (!handler.hasReadAll()) {
      71            0 :         throw ProcessError(TL("Could not find projection parameter in net."));
      72              :     }
      73           11 :     delete parser;
      74           11 : }
      75              : 
      76              : 
      77              : // ---------------------------------------------------------------------------
      78              : // handler methods
      79              : // ---------------------------------------------------------------------------
      80           11 : PCNetProjectionLoader::PCNetProjectionLoader(double scale) :
      81              :     SUMOSAXHandler("sumo-network"),
      82           11 :     myFoundLocation(false),
      83           22 :     myScale(scale) {
      84           11 : }
      85              : 
      86              : 
      87           11 : PCNetProjectionLoader::~PCNetProjectionLoader() {}
      88              : 
      89              : 
      90              : void
      91           22 : PCNetProjectionLoader::myStartElement(int element,
      92              :                                       const SUMOSAXAttributes& attrs) {
      93           22 :     if (element != SUMO_TAG_LOCATION) {
      94           11 :         return;
      95              :     }
      96              :     // @todo refactor parsing of location since its duplicated in NLHandler and PCNetProjectionLoader
      97           11 :     myFoundLocation = true;
      98           11 :     PositionVector s = attrs.get<PositionVector>(SUMO_ATTR_NET_OFFSET, nullptr, myFoundLocation);
      99           11 :     Boundary convBoundary = attrs.get<Boundary>(SUMO_ATTR_CONV_BOUNDARY, nullptr, myFoundLocation);
     100           11 :     Boundary origBoundary = attrs.get<Boundary>(SUMO_ATTR_ORIG_BOUNDARY, nullptr, myFoundLocation);
     101           11 :     std::string proj = attrs.get<std::string>(SUMO_ATTR_ORIG_PROJ, nullptr, myFoundLocation);
     102           11 :     if (myFoundLocation) {
     103           11 :         OptionsCont& oc = OptionsCont::getOptions();
     104           22 :         Position networkOffset = s[0] + Position(oc.getFloat("offset.x"), oc.getFloat("offset.y"));
     105           11 :         GeoConvHelper::init(proj, networkOffset, origBoundary, convBoundary, myScale);
     106              :     }
     107           11 : }
     108              : 
     109              : 
     110              : bool
     111            0 : PCNetProjectionLoader::hasReadAll() const {
     112           44 :     return myFoundLocation;
     113              : }
     114              : 
     115              : 
     116              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1