Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/run/GNERunDialog.cpp
169685 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 GNERunDialog.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Aug 2025
17
///
18
// Abstract dialog for running tools
19
/****************************************************************************/
20
21
#include <netedit/GNEApplicationWindow.h>
22
#include <netedit/GNEExternalRunner.h>
23
#include <utils/gui/div/GUIDesigns.h>
24
#include <utils/gui/events/GUIEvent_Message.h>
25
26
#include "GNERunDialog.h"
27
28
// ===========================================================================
29
// FOX callback mapping
30
// ===========================================================================
31
32
FXDEFMAP(GNERunDialog) GNERunDialogMap[] = {
33
FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_SAVE, GNERunDialog::onCmdSaveLog),
34
FXMAPFUNC(FXEX::SEL_THREAD_EVENT, ID_LOADTHREAD_EVENT, GNERunDialog::onThreadEvent),
35
FXMAPFUNC(FXEX::SEL_THREAD, ID_LOADTHREAD_EVENT, GNERunDialog::onThreadEvent)
36
};
37
38
// Object implementation
39
FXIMPLEMENT_ABSTRACT(GNERunDialog, GNEDialog, GNERunDialogMap, ARRAYNUMBER(GNERunDialogMap))
40
41
// ============================================-===============================
42
// member method definitions
43
// ===========================================================================
44
45
GNERunDialog::GNERunDialog(GNEApplicationWindow* applicationWindow, const std::string& name, GUIIcon titleIcon) :
46
GNEDialog(applicationWindow, name, titleIcon, DialogType::RUN, GNEDialog::Buttons::RERUN_BACK_CLOSE,
47
OpenType::MODAL, GNEDialog::ResizeMode::RESIZABLE, 640, 480) {
48
// build the thread - io
49
myThreadEvent.setTarget(this);
50
myThreadEvent.setSelector(ID_LOADTHREAD_EVENT);
51
// create header frame
52
auto headerFrame = new FXHorizontalFrame(myContentFrame, GUIDesignHorizontalFrame);
53
// adjust padding
54
headerFrame->setPadLeft(0);
55
headerFrame->setPadRight(0);
56
GUIDesigns::buildFXButton(headerFrame, "", "", + TL("Save output"), GUIIconSubSys::getIcon(GUIIcon::SAVE),
57
this, MID_GNE_BUTTON_SAVE, GUIDesignButtonIcon);
58
new FXLabel(headerFrame, TL("Console output"), nullptr, GUIDesignLabelThick(JUSTIFY_LEFT));
59
// create text
60
auto textFrame = new FXVerticalFrame(myContentFrame, GUIDesignFrameThick);
61
myText = new FXText(textFrame, 0, 0, (TEXT_READONLY | LAYOUT_FILL_X | LAYOUT_FILL_Y));
62
// set styled
63
myText->setHiliteStyles(GUIMessageWindow::getStyles());
64
myText->setStyled(true);
65
// update dialog button
66
updateDialogButtons();
67
}
68
69
70
GNERunDialog::~GNERunDialog() {}
71
72
73
void
74
GNERunDialog::addEvent(GUIEvent* event, const bool signal) {
75
// add event to queue
76
myEvents.push_back(event);
77
// signal thread event
78
if (signal) {
79
myThreadEvent.signal();
80
}
81
}
82
83
84
long
85
GNERunDialog::onCmdAbort(FXObject*, FXSelector, void*) {
86
// abort external runner
87
myApplicationWindow->getExternalRunner()->abort();
88
// hide dialog
89
return closeDialogCanceling();
90
}
91
92
93
long
94
GNERunDialog::onCmdRun(FXObject*, FXSelector, void*) {
95
if (myApplicationWindow->getExternalRunner()->isRunning()) {
96
// abort external runner
97
myApplicationWindow->getExternalRunner()->abort();
98
} else {
99
// add line and info
100
std::string line("-------------------------------------------\n");
101
myText->appendStyledText(line.c_str(), (int)line.length(), 4, TRUE);
102
myText->appendStyledText("rerun tool\n", 1, TRUE);
103
myText->layout();
104
myText->update();
105
myError = false;
106
// abort external runner
107
myApplicationWindow->getExternalRunner()->runTool(this);
108
}
109
// update dialog button
110
updateDialogButtons();
111
return 1;
112
}
113
114
115
long
116
GNERunDialog::onCmdAccept(FXObject*, FXSelector, void*) {
117
// close run dialog and call postprocessing
118
closeDialogAccepting();
119
// reset text
120
myText->setText("", 0);
121
// call postprocessing dialog depending of myError
122
if (myError) {
123
return 1;
124
} else {
125
// don't run this again
126
myError = true;
127
return myApplicationWindow->handle(this, FXSEL(SEL_COMMAND, MID_GNE_POSTPROCESSINGNETGENERATE), nullptr);
128
}
129
}
130
131
132
long
133
GNERunDialog::onCmdSaveLog(FXObject*, FXSelector, void*) {
134
// create fileDialog
135
const auto saveLogFileDialog = GNEFileDialog(myApplicationWindow,
136
TL("tool log file"),
137
SUMOXMLDefinitions::TXTFileExtensions.getStrings(),
138
GNEFileDialog::OpenMode::SAVE,
139
GNEFileDialog::ConfigType::NETEDIT);
140
// check that file is valid
141
if (saveLogFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
142
OutputDevice& dev = OutputDevice::getDevice(saveLogFileDialog.getFilename());
143
dev << myText->getText().text();
144
dev.close();
145
}
146
return 1;
147
}
148
149
150
long
151
GNERunDialog::onThreadEvent(FXObject*, FXSelector, void*) {
152
bool toolFinished = false;
153
while (!myEvents.empty()) {
154
// get the next event
155
GUIEvent* e = myEvents.top();
156
myEvents.pop();
157
// process
158
FXint style = -1;
159
switch (e->getOwnType()) {
160
case GUIEventType::TOOL_ENDED:
161
toolFinished = true;
162
break;
163
case GUIEventType::MESSAGE_OCCURRED:
164
style = 1;
165
break;
166
case GUIEventType::OUTPUT_OCCURRED:
167
style = 2;
168
break;
169
case GUIEventType::ERROR_OCCURRED:
170
style = 3;
171
myError = true;
172
break;
173
default:
174
break;
175
}
176
if (style >= 0) {
177
GUIEvent_Message* ec = static_cast<GUIEvent_Message*>(e);
178
myText->appendStyledText(ec->getMsg().c_str(), (int)ec->getMsg().length(), style, TRUE);
179
myText->layout();
180
myText->update();
181
}
182
delete e;
183
}
184
if (toolFinished) {
185
// check if close dialog immediately after running
186
if (myText->getText().find("Error") != -1) {
187
myError = true;
188
} else if ((myText->getText().find("Success") != -1) && (myText->getText().find("Warning") == -1)) {
189
//onCmdClose(nullptr, 0, nullptr);
190
}
191
}
192
updateDialogButtons();
193
return 1;
194
}
195
196
197
void
198
GNERunDialog::updateDialogButtons() {
199
// update buttons
200
if (myApplicationWindow->getExternalRunner()->isRunning()) {
201
// update run button
202
myRunButton->setText(TL("Abort"));
203
myRunButton->setTipText(TL("Abort running"));
204
myRunButton->setIcon(GUIIconSubSys::getIcon(GUIIcon::STOP));
205
// disable buttons
206
myBackButton->disable();
207
myAcceptButton->disable();
208
} else {
209
// update run button
210
myRunButton->setText(TL("Rerun"));
211
myRunButton->setTipText(TL("Rerun tool"));
212
myRunButton->setIcon(GUIIconSubSys::getIcon(GUIIcon::START));
213
// enable buttons
214
myBackButton->enable();
215
myAcceptButton->enable();
216
}
217
// update dialog
218
GNEDialog::update();
219
}
220
221
/****************************************************************************/
222
223