Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/run/GNERunDialog.cpp
193674 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 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,
46
GUIIcon titleIcon, const bool closeIfSucess) :
47
GNEDialog(applicationWindow, name, titleIcon, DialogType::RUN, GNEDialog::Buttons::RERUN_BACK_OK,
48
OpenType::MODAL, GNEDialog::ResizeMode::RESIZABLE, 640, 480),
49
myCloseIfSucess(closeIfSucess) {
50
// build the thread - io
51
myThreadEvent.setTarget(this);
52
myThreadEvent.setSelector(ID_LOADTHREAD_EVENT);
53
// create header frame
54
auto headerFrame = new FXHorizontalFrame(myContentFrame, GUIDesignHorizontalFrame);
55
// adjust padding
56
headerFrame->setPadLeft(0);
57
headerFrame->setPadRight(0);
58
GUIDesigns::buildFXButton(headerFrame, "", "", + TL("Save output"), GUIIconSubSys::getIcon(GUIIcon::SAVE),
59
this, MID_GNE_BUTTON_SAVE, GUIDesignButtonIcon);
60
new FXLabel(headerFrame, TL("Console output"), nullptr, GUIDesignLabelThick(JUSTIFY_LEFT));
61
// create text
62
auto textFrame = new FXVerticalFrame(myContentFrame, GUIDesignFrameThick);
63
myText = new FXText(textFrame, 0, 0, (TEXT_READONLY | LAYOUT_FILL_X | LAYOUT_FILL_Y));
64
// set styled
65
myText->setHiliteStyles(GUIMessageWindow::getStyles());
66
myText->setStyled(true);
67
// update dialog button
68
updateDialogButtons();
69
}
70
71
72
GNERunDialog::~GNERunDialog() {}
73
74
75
void
76
GNERunDialog::addEvent(GUIEvent* event, const bool signal) {
77
// add event to queue
78
myEvents.push_back(event);
79
// signal thread event
80
if (signal) {
81
myThreadEvent.signal();
82
}
83
}
84
85
86
long
87
GNERunDialog::onCmdAbort(FXObject*, FXSelector, void*) {
88
// abort external runner
89
myApplicationWindow->getExternalRunner()->abort();
90
// hide dialog
91
return closeDialogCanceling();
92
}
93
94
95
long
96
GNERunDialog::onCmdRun(FXObject*, FXSelector, void*) {
97
if (myApplicationWindow->getExternalRunner()->isRunning()) {
98
// abort external runner
99
myApplicationWindow->getExternalRunner()->abort();
100
} else {
101
// add line and info
102
std::string line = "--------------------Rerun--------------------\n";
103
myText->appendStyledText(line.c_str(), (int)line.length(), 1, TRUE);
104
myText->layout();
105
myText->update();
106
myWarning = false;
107
myError = false;
108
// update dialog button before running
109
updateDialogButtons();
110
// abort external runner
111
myApplicationWindow->getExternalRunner()->runTool(this);
112
}
113
return 1;
114
}
115
116
117
long
118
GNERunDialog::onCmdSaveLog(FXObject*, FXSelector, void*) {
119
// create fileDialog
120
const GNEFileDialog saveLogFileDialog(myApplicationWindow, this,
121
TL("tool log file"),
122
SUMOXMLDefinitions::TXTFileExtensions.getStrings(),
123
GNEFileDialog::OpenMode::SAVE,
124
GNEFileDialog::ConfigType::NETEDIT);
125
// check that file is valid
126
if (saveLogFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
127
OutputDevice& dev = OutputDevice::getDevice(saveLogFileDialog.getFilename());
128
dev << myText->getText().text();
129
dev.close();
130
}
131
return 1;
132
}
133
134
135
long
136
GNERunDialog::onThreadEvent(FXObject*, FXSelector, void*) {
137
bool toolFinished = false;
138
while (!myEvents.empty()) {
139
// get the next event
140
GUIEvent* e = myEvents.top();
141
myEvents.pop();
142
// process
143
FXint style = -1;
144
switch (e->getOwnType()) {
145
case GUIEventType::TOOL_ENDED:
146
toolFinished = true;
147
break;
148
case GUIEventType::MESSAGE_OCCURRED:
149
style = 1;
150
break;
151
case GUIEventType::OUTPUT_OCCURRED:
152
style = 2;
153
break;
154
case GUIEventType::WARNING_OCCURRED:
155
style = 4;
156
myWarning = true;
157
break;
158
case GUIEventType::ERROR_OCCURRED:
159
style = 3;
160
myError = true;
161
break;
162
default:
163
break;
164
}
165
if (style >= 0) {
166
GUIEvent_Message* ec = static_cast<GUIEvent_Message*>(e);
167
myText->appendStyledText(ec->getMsg().c_str(), (int)ec->getMsg().length(), style, TRUE);
168
myText->layout();
169
myText->update();
170
}
171
delete e;
172
}
173
if (toolFinished) {
174
// analyze output to update flags
175
if (myText->getText().find("Warning") != -1) {
176
myWarning = true;
177
}
178
if (myText->getText().find("Error") != -1) {
179
myError = true;
180
}
181
// check if automatically close dialog
182
if (myCloseIfSucess && !myWarning && !myError) {
183
return onCmdAccept(nullptr, 0, nullptr);
184
}
185
}
186
updateDialogButtons();
187
return 1;
188
}
189
190
191
void
192
GNERunDialog::updateDialogButtons() {
193
// update buttons
194
if (myApplicationWindow->getExternalRunner()->isRunning()) {
195
// update run button
196
myRunButton->setText(TL("Abort"));
197
myRunButton->setTipText(TL("Abort running"));
198
myRunButton->setIcon(GUIIconSubSys::getIcon(GUIIcon::STOP));
199
// disable buttons
200
myBackButton->disable();
201
myAcceptButton->disable();
202
} else {
203
// update run button
204
myRunButton->setText(TL("Rerun"));
205
myRunButton->setTipText(TL("Rerun tool"));
206
myRunButton->setIcon(GUIIconSubSys::getIcon(GUIIcon::START));
207
// enable buttons
208
myBackButton->enable();
209
myAcceptButton->enable();
210
}
211
// update dialog
212
GNEDialog::update();
213
}
214
215
/****************************************************************************/
216
217