#include <config.h>
#ifdef HAVE_VERSION_H
#include <version.h>
#endif
#include <iostream>
#include <string>
#include <netimport/NIFrame.h>
#include <netimport/NILoader.h>
#include <netbuild/NBFrame.h>
#include <netbuild/NBNetBuilder.h>
#include <netwrite/NWFrame.h>
#include <utils/options/OptionsIO.h>
#include <utils/options/OptionsCont.h>
#include <utils/common/UtilExceptions.h>
#include <utils/common/RandHelper.h>
#include <utils/common/SystemFrame.h>
#include <utils/common/MsgHandler.h>
#include <utils/distribution/DistributionCont.h>
#include <utils/xml/XMLSubSys.h>
#include <utils/iodevices/OutputDevice.h>
#include <utils/geom/GeoConvHelper.h>
void
fillOptions() {
OptionsCont& oc = OptionsCont::getOptions();
oc.addCallExample("-c <CONFIGURATION>", "generate net with options read from file");
oc.addCallExample("-n ./nodes.xml -e ./edges.xml -v -t ./owntypes.xml",
"generate net with given nodes, edges, and edge types doing verbose output");
SystemFrame::addConfigurationOptions(oc);
oc.addOptionSubTopic("Input");
oc.addOptionSubTopic("Output");
GeoConvHelper::addProjectionOptions(oc);
oc.addOptionSubTopic("Processing");
oc.addOptionSubTopic("Building Defaults");
oc.addOptionSubTopic("TLS Building");
oc.addOptionSubTopic("Ramp Guessing");
oc.addOptionSubTopic("Edge Removal");
oc.addOptionSubTopic("Unregulated Nodes");
oc.addOptionSubTopic("Junctions");
oc.addOptionSubTopic("Pedestrian");
oc.addOptionSubTopic("Bicycle");
oc.addOptionSubTopic("Railway");
oc.addOptionSubTopic("Formats");
NIFrame::fillOptions(oc);
NBFrame::fillOptions(oc, false);
NWFrame::fillOptions(oc, false);
RandHelper::insertRandOptions(oc);
}
bool
checkOptions() {
OptionsCont& oc = OptionsCont::getOptions();
bool ok = NIFrame::checkOptions(oc);
ok &= NBFrame::checkOptions(oc);
ok &= NWFrame::checkOptions(oc);
ok &= SystemFrame::checkOptions(oc);
return ok;
}
int
main(int argc, char** argv) {
OptionsCont& oc = OptionsCont::getOptions();
oc.setApplicationDescription(TL("Network importer / builder for the microscopic, multi-modal traffic simulation SUMO."));
oc.setApplicationName("netconvert", "Eclipse SUMO netconvert " VERSION_STRING);
int ret = 0;
try {
XMLSubSys::init();
fillOptions();
OptionsIO::setArgs(argc, argv);
OptionsIO::getOptions();
if (oc.processMetaOptions(argc < 2)) {
SystemFrame::close();
return 0;
}
if (oc.isSet("edge-files") && !oc.isSet("type-files") && oc.isDefault("ignore-errors.edge-type")) {
oc.setDefault("ignore-errors.edge-type", "true");
}
XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"), "never");
if (oc.isDefault("aggregate-warnings")) {
oc.setDefault("aggregate-warnings", "5");
}
MsgHandler::initOutputOptions();
if (!checkOptions()) {
throw ProcessError();
}
RandHelper::initRandGlobal();
if (!GeoConvHelper::init(oc)) {
throw ProcessError(TL("Could not build projection!"));
}
NBNetBuilder nb;
nb.applyOptions(oc);
NILoader nl(nb);
nl.load(oc);
MsgHandler::getErrorInstance()->clear(oc.getBool("ignore-errors"));
if (MsgHandler::getErrorInstance()->wasInformed()) {
throw ProcessError();
}
nb.compute(oc);
if (MsgHandler::getErrorInstance()->wasInformed()) {
throw ProcessError();
}
nb.getNodeCont().printBuiltNodesStatistics();
NWFrame::writeNetwork(oc, nb);
} catch (const ProcessError& e) {
MsgHandler::getWarningInstance()->clear(false);
MsgHandler::getErrorInstance()->clear(false);
if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
WRITE_ERROR(e.what());
}
MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
ret = 1;
#ifndef _DEBUG
} catch (const std::exception& e) {
MsgHandler::getWarningInstance()->clear(false);
MsgHandler::getErrorInstance()->clear(false);
if (std::string(e.what()) != std::string("")) {
WRITE_ERROR(e.what());
}
MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
ret = 1;
} catch (...) {
MsgHandler::getWarningInstance()->clear(false);
MsgHandler::getErrorInstance()->clear(false);
MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
ret = 1;
#endif
}
DistributionCont::clear();
SystemFrame::close();
if (ret == 0) {
std::cout << "Success." << std::endl;
}
return ret;
}