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