Path: blob/main/src/netedit/dialogs/run/GNERunNetgenerateDialog.cpp
193896 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GNERunNetgenerateDialog.cpp14/// @author Pablo Alvarez Lopez15/// @date Mar 202316///17// Dialog for running tools18/****************************************************************************/1920#include <netedit/GNEApplicationWindow.h>21#include <netedit/GNEExternalRunner.h>2223#include "GNERunNetgenerateDialog.h"2425// ============================================-===============================26// member method definitions27// ===========================================================================2829GNERunNetgenerateDialog::GNERunNetgenerateDialog(GNEApplicationWindow* applicationWindow,30const OptionsCont* netgenerateOptions) :31GNERunDialog(applicationWindow, TL("Running netgenerate results"), GUIIcon::NETGENERATE,32netgenerateOptions->getBool("close-dialog-automatic")),33myNetgenerateOptions(netgenerateOptions) {34// run tool35applicationWindow->getExternalRunner()->runTool(this);36// open modal dialog37openDialog();38}394041GNERunNetgenerateDialog::~GNERunNetgenerateDialog() {}424344void45GNERunNetgenerateDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {46// nothing to do47}484950std::string51GNERunNetgenerateDialog::getRunCommand() const {52// set command53#ifdef WIN3254const std::string exePath = "netgenerate.exe";55#else56const std::string exePath = "netgenerate";57#endif58const char* sumoHomeEnv = getenv("SUMO_HOME");59std::string sumoHome = "";60if (sumoHomeEnv != nullptr && sumoHomeEnv != std::string("")) {61sumoHome = std::string(sumoHomeEnv);62// harmonise slash63if (sumoHome.back() == '\\') {64sumoHome = sumoHome.substr(0, sumoHome.size() - 1);65}66// prevent double quotes67if (sumoHome.front() == '"') {68sumoHome.erase(sumoHome.begin());69}70if (sumoHome.size() > 0 && sumoHome.back() == '"') {71sumoHome.pop_back();72}73sumoHome += "/bin/";74}75// quote to handle spaces. note that this differs from GNEPythonTool because the python interpreter is a bit smarter76// when handling quoted parts within a path77std::string runCommand = "\"" + sumoHome + exePath + "\"";7879// iterate over all topics80for (const auto& topic : myNetgenerateOptions->getSubTopics()) {81// ignore configuration82if (topic != "Configuration") {83const std::vector<std::string> entries = myNetgenerateOptions->getSubTopicsEntries(topic);84for (const auto& entry : entries) {85if (!myNetgenerateOptions->isDefault(entry) && (entry != "close-dialog-automatic")) {86runCommand += " --" + entry + " \"" + StringUtils::escapeShell(myNetgenerateOptions->getValueString(entry)) + "\" ";87}88}89}90}91return runCommand;92}939495long96GNERunNetgenerateDialog::onCmdBack(FXObject*, FXSelector, void*) {97// close run dialog and open tool dialog98closeDialogCanceling();99return myApplicationWindow->handle(this, FXSEL(SEL_COMMAND, MID_GNE_NETGENERATE), nullptr);100}101102103long104GNERunNetgenerateDialog::onCmdAccept(FXObject*, FXSelector, void*) {105// close run dialog and call postprocessing106closeDialogCanceling();107// abort tool108myApplicationWindow->getExternalRunner()->abort();109// reset text110myText->setText("", 0);111// call postprocessing dialog112if (myError) {113return 1;114} else {115// don't run this again116myError = true;117return myApplicationWindow->handle(this, FXSEL(SEL_COMMAND, MID_GNE_POSTPROCESSINGNETGENERATE), nullptr);118}119}120121/****************************************************************************/122123124