Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
run/GNERunNetgenerateDialog.cpp
Go to the documentation of this file.
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/****************************************************************************/
18// Dialog for running tools
19/****************************************************************************/
20
23
25
26// ============================================-===============================
27// member method definitions
28// ===========================================================================
29
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
43
44
45void
47 // nothing to do
48}
49
50
51std::string
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
96long
97GNERunNetgenerateDialog::onCmdBack(FXObject*, FXSelector, void*) {
98 // close run dialog and open tool dialog
100 return myApplicationWindow->handle(this, FXSEL(SEL_COMMAND, MID_GNE_NETGENERATE), nullptr);
101}
102
103
104long
105GNERunNetgenerateDialog::onCmdAccept(FXObject*, FXSelector, void*) {
106 // close run dialog and call postprocessing
108 // abort tool
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/****************************************************************************/
@ MID_GNE_NETGENERATE
netgenerate dialog
Definition GUIAppEnum.h:763
@ MID_GNE_POSTPROCESSINGNETGENERATE
postprocesing netgenerate
Definition GUIAppEnum.h:777
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
#define TL(string)
Definition MsgHandler.h:304
The main window of Netedit.
GNEExternalRunner * getExternalRunner() const
get external runner
GNEApplicationWindow * myApplicationWindow
FOX needs this.
Definition GNEDialog.h:146
void openDialog(FXWindow *focusableElement=nullptr)
open dialog
long closeDialogCanceling()
close dialog declining the changes
void runTool(GNERunDialog *runDialog)
run tool called from dialog
void abort()
abort running
void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)
run internal test
bool myError
flag to check if there is an error
GNERunNetgenerateDialog(GNEApplicationWindow *applicationWindow, const OptionsCont *netgenerateOptions)
Constructor.
long onCmdAccept(FXObject *, FXSelector, void *)
event after press close button
long onCmdBack(FXObject *, FXSelector, void *)
event after press back button
std::string getRunCommand() const
get run command
const OptionsCont * myNetgenerateOptions
netgenerate options
dialog arguments, used for certain modal dialogs that can not be edited using tab
A storage for options typed value containers)
Definition OptionsCont.h:89
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
std::string getValueString(const std::string &name) const
Returns the string-value of the named option (all options)
std::vector< std::string > getSubTopicsEntries(const std::string &subtopic) const
return the list of entries for the given subtopic
static std::string escapeShell(const std::string &orig)
Escape special characters with backslash.