Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNERunDialog.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// Abstract dialog for running tools
19/****************************************************************************/
20
25
26#include "GNERunDialog.h"
27
28// ===========================================================================
29// FOX callback mapping
30// ===========================================================================
31
37
38// Object implementation
39FXIMPLEMENT_ABSTRACT(GNERunDialog, GNEDialog, GNERunDialogMap, ARRAYNUMBER(GNERunDialogMap))
40
41// ============================================-===============================
42// member method definitions
43// ===========================================================================
44
45GNERunDialog::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),
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
71
72
73void
74GNERunDialog::addEvent(GUIEvent* event, const bool signal) {
75 // add event to queue
76 myEvents.push_back(event);
77 // signal thread event
78 if (signal) {
80 }
81}
82
83
84long
85GNERunDialog::onCmdAbort(FXObject*, FXSelector, void*) {
86 // abort external runner
88 // hide dialog
89 return closeDialogCanceling();
90}
91
92
93long
94GNERunDialog::onCmdRun(FXObject*, FXSelector, void*) {
96 // abort external runner
98 } else {
99 // add line and info
100 std::string line = "--------------------Rerun--------------------\n";
101 myText->appendStyledText(line.c_str(), (int)line.length(), 1, TRUE);
102 myText->layout();
103 myText->update();
104 myError = false;
105 // abort external runner
107 }
108 // update dialog button
110 return 1;
111}
112
113
114long
115GNERunDialog::onCmdAccept(FXObject*, FXSelector, void*) {
116 // close run dialog and call postprocessing
118 // reset text
119 myText->setText("", 0);
120 // call postprocessing dialog depending of myError
121 if (myError) {
122 return 1;
123 } else {
124 // don't run this again
125 myError = true;
126 return myApplicationWindow->handle(this, FXSEL(SEL_COMMAND, MID_GNE_POSTPROCESSINGNETGENERATE), nullptr);
127 }
128}
129
130
131long
132GNERunDialog::onCmdSaveLog(FXObject*, FXSelector, void*) {
133 // create fileDialog
134 const auto saveLogFileDialog = GNEFileDialog(myApplicationWindow,
135 TL("tool log file"),
139 // check that file is valid
140 if (saveLogFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
141 OutputDevice& dev = OutputDevice::getDevice(saveLogFileDialog.getFilename());
142 dev << myText->getText().text();
143 dev.close();
144 }
145 return 1;
146}
147
148
149long
150GNERunDialog::onThreadEvent(FXObject*, FXSelector, void*) {
151 bool toolFinished = false;
152 while (!myEvents.empty()) {
153 // get the next event
154 GUIEvent* e = myEvents.top();
155 myEvents.pop();
156 // process
157 FXint style = -1;
158 switch (e->getOwnType()) {
160 toolFinished = true;
161 break;
163 style = 1;
164 break;
166 style = 2;
167 break;
169 style = 3;
170 myError = true;
171 break;
172 default:
173 break;
174 }
175 if (style >= 0) {
176 GUIEvent_Message* ec = static_cast<GUIEvent_Message*>(e);
177 myText->appendStyledText(ec->getMsg().c_str(), (int)ec->getMsg().length(), style, TRUE);
178 myText->layout();
179 myText->update();
180 }
181 delete e;
182 }
183 if (toolFinished) {
184 // check if close dialog immediately after running
185 if (myText->getText().find("Error") != -1) {
186 myError = true;
187 } else if ((myText->getText().find("Success") != -1) && (myText->getText().find("Warning") == -1)) {
188 //onCmdClose(nullptr, 0, nullptr);
189 }
190 }
192 return 1;
193}
194
195
196void
198 // update buttons
200 // update run button
201 myRunButton->setText(TL("Abort"));
202 myRunButton->setTipText(TL("Abort running"));
204 // disable buttons
205 myBackButton->disable();
206 myAcceptButton->disable();
207 } else {
208 // update run button
209 myRunButton->setText(TL("Rerun"));
210 myRunButton->setTipText(TL("Rerun tool"));
212 // enable buttons
213 myBackButton->enable();
214 myAcceptButton->enable();
215 }
216 // update dialog
217 GNEDialog::update();
218}
219
220/****************************************************************************/
DialogType
FXDEFMAP(GNERunDialog) GNERunDialogMap[]
@ MID_GNE_BUTTON_SAVE
save button
@ ID_LOADTHREAD_EVENT
The loading thread.
Definition GUIAppEnum.h:348
@ MID_GNE_POSTPROCESSINGNETGENERATE
postprocesing netgenerate
Definition GUIAppEnum.h:777
#define GUIDesignFrameThick
Thick frame extended over frame parent.
Definition GUIDesigns.h:344
#define GUIDesignButtonIcon
button only with icon
Definition GUIDesigns.h:109
#define GUIDesignLabelThick(justify)
label extended over frame with thick and with text justify to left
Definition GUIDesigns.h:251
#define GUIDesignHorizontalFrame
Horizontal frame extended over frame parent with padding and spacing.
Definition GUIDesigns.h:347
@ MESSAGE_OCCURRED
send when a message occurred
@ ERROR_OCCURRED
send when a error occurred
@ OUTPUT_OCCURRED
send when a tool produces output
@ TOOL_ENDED
send when a tool finishes
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ SAVE
save icons
#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:143
FXButton * myAcceptButton
accept button
Definition GNEDialog.h:149
long closeDialogAccepting()
close dialog accepting the changes
OpenType
Open dialog type.
Definition GNEDialog.h:58
FXButton * myBackButton
back button
Definition GNEDialog.h:164
FXButton * myRunButton
run button
Definition GNEDialog.h:161
long closeDialogCanceling()
close dialog declining the changes
bool isRunning() const
check if is running
void runTool(GNERunDialog *runDialog)
run tool called from dialog
void abort()
abort running
void updateDialogButtons()
update dialog buttons
long onThreadEvent(FXObject *, FXSelector, void *)
called when the thread signals an event
bool myError
flag to check if there is an error
long onCmdSaveLog(FXObject *, FXSelector, void *)
event after press save button
~GNERunDialog()
destructor
virtual long onCmdAccept(FXObject *, FXSelector, void *)=0
event after press close button
void addEvent(GUIEvent *event, const bool signal)
add event in the queue
long onCmdAbort(FXObject *, FXSelector, void *)
event after press abort button
FXEX::MFXThreadEvent myThreadEvent
io-event with the runner thread
FXText * myText
text
long onCmdRun(FXObject *, FXSelector, void *)
event after press rerun button
MFXSynchQue< GUIEvent * > myEvents
List of received events.
static FXButton * buildFXButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXIcon *ic, FXObject *tgt, FXSelector sel, FXuint opts=BUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build button
const std::string & getMsg() const
Returns the message.
GUIEventType getOwnType() const
returns the event type
Definition GUIEvent.h:89
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
static FXHiliteStyle * getStyles()
The text colors used.
void push_back(T what)
Static storage of an output device and its base (abstract) implementation.
void close()
Closes the device and removes it from the dictionary.
static OutputDevice & getDevice(const std::string &name, bool usePrefix=true)
Returns the described OutputDevice.
static StringBijection< TXTFileExtension > TXTFileExtensions
TXT file Extensions.
@ SEL_THREAD_EVENT
Definition fxexdefs.h:173
@ SEL_THREAD
Definition fxexdefs.h:155
Definition json.hpp:4471