LCOV - code coverage report
Current view: top level - src/netwrite - NWFrame.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 96.5 % 113 109
Test Date: 2025-11-13 15:38:19 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2025 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    NWFrame.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @date    Tue, 20 Nov 2001
      19              : ///
      20              : // Sets and checks options for netwrite
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : 
      24              : #include <string>
      25              : #include <utils/options/Option.h>
      26              : #include <utils/options/OptionsCont.h>
      27              : #include <utils/common/MsgHandler.h>
      28              : #include <utils/common/SystemFrame.h>
      29              : #include <utils/common/SysUtils.h>
      30              : #include <utils/iodevices/OutputDevice.h>
      31              : #include <netbuild/NBNetBuilder.h>
      32              : #include "NWFrame.h"
      33              : #include "NWWriter_SUMO.h"
      34              : #include "NWWriter_Amitran.h"
      35              : #include "NWWriter_MATSim.h"
      36              : #include "NWWriter_XML.h"
      37              : #include "NWWriter_OpenDrive.h"
      38              : #include "NWWriter_DlrNavteq.h"
      39              : 
      40              : // ===========================================================================
      41              : // static members
      42              : // ===========================================================================
      43              : 
      44              : // ===========================================================================
      45              : // method definitions
      46              : // ===========================================================================
      47              : 
      48              : void
      49         2153 : NWFrame::fillOptions(OptionsCont& oc, bool forNetgen) {
      50              :     // register options
      51         2153 :     oc.doRegister("output-file", 'o', new Option_FileName());
      52         4306 :     oc.addSynonyme("output-file", "sumo-output");
      53         4306 :     oc.addSynonyme("output-file", "output");
      54         4306 :     oc.addDescription("output-file", "Output", TL("The generated net will be written to FILE"));
      55              : 
      56         2153 :     oc.doRegister("plain-output-prefix", 'p', new Option_FileName());
      57         4306 :     oc.addSynonyme("plain-output-prefix", "plain-output");
      58         4306 :     oc.addSynonyme("plain-output-prefix", "plain");
      59         4306 :     oc.addDescription("plain-output-prefix", "Output", TL("Prefix of files to write plain xml nodes, edges and connections to"));
      60              : 
      61         2153 :     oc.doRegister("plain-output.lanes", new Option_Bool(false));
      62         4306 :     oc.addDescription("plain-output.lanes", "Output", TL("Write all lanes and their attributes even when they are not customized"));
      63              : 
      64         2153 :     oc.doRegister("junctions.join-output", new Option_FileName());
      65         4306 :     oc.addDescription("junctions.join-output", "Output",
      66              :                       "Writes information about joined junctions to FILE (can be loaded as additional node-file to reproduce joins");
      67              : 
      68         4306 :     oc.doRegister("prefix", new Option_String(""));
      69         4306 :     oc.addDescription("prefix", "Output", TL("Defines a prefix for edge and junction IDs"));
      70              : 
      71         4306 :     oc.doRegister("prefix.junction", new Option_String(""));
      72         4306 :     oc.addDescription("prefix.junction", "Output", TL("Defines a prefix for junction IDs"));
      73              : 
      74         4306 :     oc.doRegister("prefix.edge", new Option_String(""));
      75         4306 :     oc.addDescription("prefix.edge", "Output", TL("Defines a prefix for edge IDs"));
      76              : 
      77              : #ifdef PROJ_API_FILE
      78         2153 :     if (!forNetgen) {
      79         2033 :         oc.doRegister("proj.plain-geo", new Option_Bool(false));
      80         4066 :         oc.addDescription("proj.plain-geo", "Projection", TL("Write geo coordinates in plain-xml"));
      81              :     }
      82              : #endif // PROJ_API_FILE
      83              : 
      84         2153 :     oc.doRegister("amitran-output", new Option_FileName());
      85         4306 :     oc.addDescription("amitran-output", "Output", TL("The generated net will be written to FILE using Amitran format"));
      86              : 
      87         2153 :     oc.doRegister("matsim-output", new Option_FileName());
      88         4306 :     oc.addDescription("matsim-output", "Output", TL("The generated net will be written to FILE using MATSim format"));
      89              : 
      90         2153 :     oc.doRegister("opendrive-output", new Option_FileName());
      91         4306 :     oc.addDescription("opendrive-output", "Output", TL("The generated net will be written to FILE using OpenDRIVE format"));
      92              : 
      93         2153 :     oc.doRegister("dlr-navteq-output", new Option_FileName());
      94         4306 :     oc.addDescription("dlr-navteq-output", "Output", TL("The generated net will be written to dlr-navteq files with the given PREFIX"));
      95              : 
      96         4306 :     oc.doRegister("dlr-navteq.version", new Option_String("6.5"));
      97         4306 :     oc.addDescription("dlr-navteq.version", "Output", TL("The dlr-navteq output format version to write"));
      98              : 
      99         2153 :     oc.doRegister("dlr-navteq.precision", new Option_Integer(2));
     100         4306 :     oc.addDescription("dlr-navteq.precision", "Output", TL("The network coordinates are written with the specified level of output precision"));
     101              : 
     102         2153 :     oc.doRegister("output.street-names", new Option_Bool(false));
     103         4306 :     oc.addDescription("output.street-names", "Output", TL("Street names will be included in the output (if available)"));
     104              : 
     105         2153 :     oc.doRegister("output.original-names", new Option_Bool(false));
     106         4306 :     oc.addDescription("output.original-names", "Output", TL("Writes original names, if given, as parameter"));
     107              : 
     108         2153 :     oc.doRegister("output.removed-nodes", new Option_Bool(false));
     109         4306 :     oc.addDescription("output.removed-nodes", "Output", TL("Writes IDs of nodes remove with --geometry.remove into edge param"));
     110              : 
     111         2153 :     oc.doRegister("street-sign-output", new Option_FileName());
     112         4306 :     oc.addDescription("street-sign-output", "Output", TL("Writes street signs as POIs to FILE"));
     113              : 
     114         2153 :     if (!forNetgen) {
     115         2033 :         oc.doRegister("ptstop-output", new Option_FileName());
     116         4066 :         oc.addDescription("ptstop-output", "Output", TL("Writes public transport stops to FILE"));
     117         2033 :         oc.doRegister("ptline-output", new Option_FileName());
     118         4066 :         oc.addDescription("ptline-output", "Output", TL("Writes public transport lines to FILE"));
     119         2033 :         oc.doRegister("ptline-clean-up", new Option_Bool(false));
     120         4066 :         oc.addDescription("ptline-clean-up", "Output", TL("Clean-up pt stops that are not served by any line"));
     121              : 
     122         2033 :         oc.doRegister("parking-output", new Option_FileName());
     123         4066 :         oc.addDescription("parking-output", "Output", TL("Writes parking areas to FILE"));
     124              : 
     125         2033 :         oc.doRegister("railway.topology.output", new Option_FileName());
     126         4066 :         oc.addDescription("railway.topology.output", "Output", TL("Analyze topology of the railway network"));
     127              : 
     128         2033 :         oc.doRegister("polygon-output", new Option_FileName());
     129         4066 :         oc.addSynonyme("polygon-output", "taz-output");
     130         4066 :         oc.addDescription("polygon-output", "Output", TL("Write shapes that are embedded in the network input and that are not supported by polyconvert (OpenDRIVE)"));
     131              :     }
     132              : 
     133              :     // register opendrive options
     134         2153 :     oc.doRegister("opendrive-output.straight-threshold", new Option_Float(0.00000001)); // matching the angular output precision in NWWriter_OpenDrive
     135         4306 :     oc.addDescription("opendrive-output.straight-threshold", "Output", TL("Builds parameterized curves whenever the angular change between straight segments exceeds FLOAT degrees"));
     136              : 
     137         2153 :     if (!forNetgen) {
     138         2033 :         oc.doRegister("opendrive-output.lefthand-left", new Option_Bool(false));
     139         4066 :         oc.addDescription("opendrive-output.lefthand-left", "Output", TL("Write lanes in lefthand networks on the left side (positive indices)"));
     140              : 
     141         2033 :         oc.doRegister("opendrive-output.shape-match-dist", new Option_Float(-1));
     142         4066 :         oc.addDescription("opendrive-output.shape-match-dist", "Output", TL("Match loaded shapes to the closest edge within FLOAT and export as road objects"));
     143              :     }
     144         2153 : }
     145              : 
     146              : 
     147              : bool
     148         2129 : NWFrame::checkOptions(OptionsCont& oc) {
     149              :     bool ok = true;
     150              :     // check whether the output is valid and can be build
     151         4258 :     if (!oc.isSet("output-file")
     152         2748 :             && !oc.isSet("plain-output-prefix")
     153         2694 :             && !oc.isSet("amitran-output")
     154         2693 :             && !oc.isSet("matsim-output")
     155         2691 :             && !oc.isSet("opendrive-output")
     156         3301 :             && !oc.isSet("dlr-navteq-output")) {
     157          537 :         std::string net = "net.net.xml";
     158         1074 :         if (oc.isSet("configuration-file")) {
     159           16 :             net = FileHelpers::getConfigurationRelative(oc.getString("configuration-file"), net);
     160              :         }
     161         1074 :         oc.setDefault("output-file", net);
     162              :     }
     163              :     // some outputs need internal lanes
     164         2162 :     if (oc.isSet("opendrive-output") && oc.getBool("no-internal-links")) {
     165            0 :         WRITE_ERROR(TL("OpenDRIVE export needs internal links computation."));
     166              :         ok = false;
     167              :     }
     168         2162 :     if (oc.isSet("opendrive-output") && oc.isDefault("no-internal-links")) {
     169           64 :         oc.setDefault("no-internal-links", "false");
     170              :     }
     171         2162 :     if (oc.isSet("opendrive-output") && oc.isDefault("rectangular-lane-cut")) {
     172           66 :         oc.setDefault("rectangular-lane-cut", "true");
     173              :     }
     174         2195 :     if (oc.isSet("opendrive-output") && !oc.getBool("rectangular-lane-cut")) {
     175            0 :         WRITE_WARNING(TL("OpenDRIVE cannot represent oblique lane cuts and should use option 'rectangular-lane-cut'."));
     176              :     }
     177         2140 :     if (oc.isSet("dlr-navteq-output") && oc.isDefault("numerical-ids")) {
     178           10 :         oc.setDefault("numerical-ids", "true");
     179              :     }
     180         2140 :     if (oc.isSet("dlr-navteq-output") && oc.isDefault("osm.all-attributes")) {
     181           22 :         oc.setDefault("osm.all-attributes", "true");
     182           22 :         oc.setDefault("osm.extra-attributes", "bridge,tunnel,layer,postal_code,maxheight,maxwidth,maxweight,surface");
     183              :     }
     184         4240 :     if (oc.exists("ptline-output") && oc.isSet("ptline-output") && !oc.isSet("ptstop-output")) {
     185            0 :         WRITE_ERROR(TL("public transport lines output requires 'ptstop-output' to be set"));
     186              :         ok = false;
     187              :     }
     188         4154 :     if (oc.exists("ptline-clean-up") && oc.getBool("ptline-clean-up") && !oc.isSet("ptline-output")) {
     189            0 :         WRITE_WARNING(TL("'ptline-clean-up' only works in conjunction with 'ptline-output'. Ignoring invalid option."));
     190              :     }
     191         4258 :     if (oc.isDefault("prefix.junction")) {
     192         6384 :         oc.setDefault("prefix.junction", oc.getString("prefix"));
     193              :     }
     194         4258 :     if (oc.isDefault("prefix.edge")) {
     195         6384 :         oc.setDefault("prefix.edge", oc.getString("prefix"));
     196              :     }
     197              : 
     198         2129 :     return ok;
     199              : }
     200              : 
     201              : 
     202              : void
     203         1810 : NWFrame::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
     204         3620 :     const long before = PROGRESS_BEGIN_TIME_MESSAGE(TL("Writing network"));
     205         1810 :     NWWriter_SUMO::writeNetwork(oc, nb);
     206         1807 :     NWWriter_Amitran::writeNetwork(oc, nb);
     207         1807 :     NWWriter_MATSim::writeNetwork(oc, nb);
     208         1807 :     NWWriter_OpenDrive::writeNetwork(oc, nb);
     209         1807 :     NWWriter_DlrNavteq::writeNetwork(oc, nb);
     210         3789 :     NWWriter_XML::writeNetwork(oc, oc.isSet("plain-output-prefix") ? oc.getString("plain-output-prefix") : "", nb);
     211         1805 :     PROGRESS_TIME_MESSAGE(before);
     212         1805 : }
     213              : 
     214              : 
     215              : void
     216        74215 : NWFrame::writePositionLong(const Position& pos, OutputDevice& dev) {
     217        74215 :     dev.writeAttr(SUMO_ATTR_X, pos.x());
     218        74215 :     dev.writeAttr(SUMO_ATTR_Y, pos.y());
     219        74215 :     if (pos.z() != 0) {
     220          747 :         dev.writeAttr(SUMO_ATTR_Z, pos.z());
     221              :     }
     222        74215 : }
     223              : 
     224              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1