LCOV - code coverage report
Current view: top level - src - netconvert_main.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 87.1 % 85 74
Test Date: 2024-11-20 15:55:46 Functions: 100.0 % 3 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    netconvert_main.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @date    Tue, 20 Nov 2001
      19              : ///
      20              : // Main for NETCONVERT
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : 
      24              : #ifdef HAVE_VERSION_H
      25              : #include <version.h>
      26              : #endif
      27              : 
      28              : #include <iostream>
      29              : #include <string>
      30              : #include <netimport/NIFrame.h>
      31              : #include <netimport/NILoader.h>
      32              : #include <netbuild/NBFrame.h>
      33              : #include <netbuild/NBNetBuilder.h>
      34              : #include <netwrite/NWFrame.h>
      35              : #include <utils/options/OptionsIO.h>
      36              : #include <utils/options/OptionsCont.h>
      37              : #include <utils/common/UtilExceptions.h>
      38              : #include <utils/common/RandHelper.h>
      39              : #include <utils/common/SystemFrame.h>
      40              : #include <utils/common/MsgHandler.h>
      41              : #include <utils/distribution/DistributionCont.h>
      42              : #include <utils/xml/XMLSubSys.h>
      43              : #include <utils/iodevices/OutputDevice.h>
      44              : #include <utils/geom/GeoConvHelper.h>
      45              : 
      46              : 
      47              : // ===========================================================================
      48              : // method definitions
      49              : // ===========================================================================
      50              : void
      51         1912 : fillOptions() {
      52         1912 :     OptionsCont& oc = OptionsCont::getOptions();
      53         3824 :     oc.addCallExample("-c <CONFIGURATION>", "generate net with options read from file");
      54         3824 :     oc.addCallExample("-n ./nodes.xml -e ./edges.xml -v -t ./owntypes.xml",
      55              :                       "generate net with given nodes, edges, and edge types doing verbose output");
      56              : 
      57              :     // insert options sub-topics
      58         1912 :     SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
      59         1912 :     oc.addOptionSubTopic("Input");
      60         1912 :     oc.addOptionSubTopic("Output");
      61         1912 :     GeoConvHelper::addProjectionOptions(oc);
      62         1912 :     oc.addOptionSubTopic("Processing");
      63         1912 :     oc.addOptionSubTopic("Building Defaults");
      64         1912 :     oc.addOptionSubTopic("TLS Building");
      65         1912 :     oc.addOptionSubTopic("Ramp Guessing");
      66         1912 :     oc.addOptionSubTopic("Edge Removal");
      67         1912 :     oc.addOptionSubTopic("Unregulated Nodes");
      68         1912 :     oc.addOptionSubTopic("Junctions");
      69         1912 :     oc.addOptionSubTopic("Pedestrian");
      70         1912 :     oc.addOptionSubTopic("Bicycle");
      71         1912 :     oc.addOptionSubTopic("Railway");
      72         1912 :     oc.addOptionSubTopic("Formats");
      73              : 
      74         1912 :     NIFrame::fillOptions(oc);
      75         1912 :     NBFrame::fillOptions(oc, false);
      76         1912 :     NWFrame::fillOptions(oc, false);
      77         1912 :     RandHelper::insertRandOptions(oc);
      78         1912 : }
      79              : 
      80              : 
      81              : bool
      82         1898 : checkOptions() {
      83         1898 :     OptionsCont& oc = OptionsCont::getOptions();
      84         1898 :     bool ok = NIFrame::checkOptions(oc);
      85         1898 :     ok &= NBFrame::checkOptions(oc);
      86         1898 :     ok &= NWFrame::checkOptions(oc);
      87         1898 :     ok &= SystemFrame::checkOptions(oc);
      88         1898 :     return ok;
      89              : }
      90              : 
      91              : 
      92              : /* -------------------------------------------------------------------------
      93              :  * main
      94              :  * ----------------------------------------------------------------------- */
      95              : int
      96         1912 : main(int argc, char** argv) {
      97         1912 :     OptionsCont& oc = OptionsCont::getOptions();
      98         1912 :     oc.setApplicationDescription(TL("Network importer / builder for the microscopic, multi-modal traffic simulation SUMO."));
      99         3824 :     oc.setApplicationName("netconvert", "Eclipse SUMO netconvert Version " VERSION_STRING);
     100              :     int ret = 0;
     101              :     try {
     102         1912 :         XMLSubSys::init();
     103         1912 :         fillOptions();
     104         1912 :         OptionsIO::setArgs(argc, argv);
     105         1912 :         OptionsIO::getOptions();
     106         1911 :         if (oc.processMetaOptions(argc < 2)) {
     107           13 :             SystemFrame::close();
     108           13 :             return 0;
     109              :         }
     110         3961 :         if (oc.isSet("edge-files") && !oc.isSet("type-files") && oc.isDefault("ignore-errors.edge-type")) {
     111         1864 :             oc.setDefault("ignore-errors.edge-type", "true");
     112              :         }
     113         5694 :         XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"), "never");
     114         3796 :         if (oc.isDefault("aggregate-warnings")) {
     115         3770 :             oc.setDefault("aggregate-warnings", "5");
     116              :         }
     117         1898 :         MsgHandler::initOutputOptions();
     118         1898 :         if (!checkOptions()) {
     119            4 :             throw ProcessError();
     120              :         }
     121         1894 :         RandHelper::initRandGlobal();
     122              :         // build the projection
     123         1894 :         if (!GeoConvHelper::init(oc)) {
     124            0 :             throw ProcessError(TL("Could not build projection!"));
     125              :         }
     126         1894 :         NBNetBuilder nb;
     127         1894 :         nb.applyOptions(oc);
     128              :         // load data
     129         1884 :         NILoader nl(nb);
     130         1884 :         nl.load(oc);
     131              :         // flush aggregated errors and optionally ignore them
     132         1731 :         MsgHandler::getErrorInstance()->clear(oc.getBool("ignore-errors"));
     133              :         // check whether any errors occurred
     134         1731 :         if (MsgHandler::getErrorInstance()->wasInformed()) {
     135          123 :             throw ProcessError();
     136              :         }
     137         1608 :         nb.compute(oc);
     138              :         // check whether any errors occurred
     139         1607 :         if (MsgHandler::getErrorInstance()->wasInformed()) {
     140            2 :             throw ProcessError();
     141              :         }
     142              :         // report
     143         1605 :         nb.getNodeCont().printBuiltNodesStatistics();
     144         1605 :         NWFrame::writeNetwork(oc, nb);
     145         2471 :     } catch (const ProcessError& e) {
     146          296 :         MsgHandler::getWarningInstance()->clear(false);
     147          296 :         MsgHandler::getErrorInstance()->clear(false);
     148          518 :         if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
     149          222 :             WRITE_ERROR(e.what());
     150              :         }
     151          296 :         MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
     152              :         ret = 1;
     153              : #ifndef _DEBUG
     154          296 :     } catch (const std::exception& e) {
     155            0 :         MsgHandler::getWarningInstance()->clear(false);
     156            0 :         MsgHandler::getErrorInstance()->clear(false);
     157            0 :         if (std::string(e.what()) != std::string("")) {
     158            0 :             WRITE_ERROR(e.what());
     159              :         }
     160            0 :         MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
     161              :         ret = 1;
     162            0 :     } catch (...) {
     163            0 :         MsgHandler::getWarningInstance()->clear(false);
     164            0 :         MsgHandler::getErrorInstance()->clear(false);
     165            0 :         MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
     166              :         ret = 1;
     167              : #endif
     168            0 :     }
     169         1899 :     DistributionCont::clear();
     170         1899 :     SystemFrame::close();
     171              :     // report about ending
     172         1899 :     if (ret == 0) {
     173              :         std::cout << "Success." << std::endl;
     174              :     }
     175              :     return ret;
     176              : }
     177              : 
     178              : 
     179              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1