Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/run/GNERunNetgenerateDialog.cpp
169684 views
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 GNERunNetgenerateDialog.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Mar 2023
17
///
18
// Dialog for running tools
19
/****************************************************************************/
20
21
#include <netedit/GNEApplicationWindow.h>
22
#include <netedit/GNEExternalRunner.h>
23
24
#include "GNERunNetgenerateDialog.h"
25
26
// ============================================-===============================
27
// member method definitions
28
// ===========================================================================
29
30
GNERunNetgenerateDialog::GNERunNetgenerateDialog(GNEApplicationWindow* applicationWindow, const OptionsCont* netgenerateOptions) :
31
GNERunDialog(applicationWindow, TL("Running netgenerate results"), GUIIcon::NETGENERATE),
32
myNetgenerateOptions(netgenerateOptions) {
33
// run tool
34
applicationWindow->getExternalRunner()->runTool(this);
35
// open modal dialog
36
openDialog();
37
}
38
39
40
GNERunNetgenerateDialog::~GNERunNetgenerateDialog() {}
41
42
43
void
44
GNERunNetgenerateDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {
45
// nothing to do
46
}
47
48
49
std::string
50
GNERunNetgenerateDialog::getRunCommand() const {
51
// set command
52
#ifdef WIN32
53
const std::string exePath = "netgenerate.exe";
54
#else
55
const std::string exePath = "netgenerate";
56
#endif
57
const char* sumoHomeEnv = getenv("SUMO_HOME");
58
std::string sumoHome = "";
59
if (sumoHomeEnv != nullptr && sumoHomeEnv != std::string("")) {
60
sumoHome = std::string(sumoHomeEnv);
61
// harmonise slash
62
if (sumoHome.back() == '\\') {
63
sumoHome = sumoHome.substr(0, sumoHome.size() - 1);
64
}
65
// prevent double quotes
66
if (sumoHome.front() == '"') {
67
sumoHome.erase(sumoHome.begin());
68
}
69
if (sumoHome.size() > 0 && sumoHome.back() == '"') {
70
sumoHome.pop_back();
71
}
72
sumoHome += "/bin/";
73
}
74
// quote to handle spaces. note that this differs from GNEPythonTool because the python interpreter is a bit smarter
75
// when handling quoted parts within a path
76
std::string runCommand = "\"" + sumoHome + exePath + "\"";
77
78
// iterate over all topics
79
for (const auto& topic : myNetgenerateOptions->getSubTopics()) {
80
// ignore configuration
81
if (topic != "Configuration") {
82
const std::vector<std::string> entries = myNetgenerateOptions->getSubTopicsEntries(topic);
83
for (const auto& entry : entries) {
84
if (!myNetgenerateOptions->isDefault(entry)) {
85
runCommand += " --" + entry + " " + myNetgenerateOptions->getValueString(entry);
86
}
87
}
88
}
89
}
90
return runCommand;
91
}
92
93
94
long
95
GNERunNetgenerateDialog::onCmdBack(FXObject*, FXSelector, void*) {
96
// close run dialog and open tool dialog
97
closeDialogCanceling();
98
return myApplicationWindow->handle(this, FXSEL(SEL_COMMAND, MID_GNE_NETGENERATE), nullptr);
99
}
100
101
102
long
103
GNERunNetgenerateDialog::onCmdAccept(FXObject*, FXSelector, void*) {
104
// close run dialog and call postprocessing
105
closeDialogCanceling();
106
// abort tool
107
myApplicationWindow->getExternalRunner()->abort();
108
// reset text
109
myText->setText("", 0);
110
// call postprocessing dialog
111
if (myError) {
112
return 1;
113
} else {
114
// don't run this again
115
myError = true;
116
return myApplicationWindow->handle(this, FXSEL(SEL_COMMAND, MID_GNE_POSTPROCESSINGNETGENERATE), nullptr);
117
}
118
}
119
120
/****************************************************************************/
121
122