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,
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),
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
73
74
75void
76GNERunDialog::addEvent(GUIEvent* event, const bool signal) {
77 // add event to queue
78 myEvents.push_back(event);
79 // signal thread event
80 if (signal) {
82 }
83}
84
85
86long
87GNERunDialog::onCmdAbort(FXObject*, FXSelector, void*) {
88 // abort external runner
90 // hide dialog
91 return closeDialogCanceling();
92}
93
94
95long
96GNERunDialog::onCmdRun(FXObject*, FXSelector, void*) {
98 // abort external runner
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
110 // abort external runner
112 }
113 return 1;
114}
115
116
117long
118GNERunDialog::onCmdSaveLog(FXObject*, FXSelector, void*) {
119 // create fileDialog
120 const auto saveLogFileDialog = GNEFileDialog(this, myApplicationWindow,
121 TL("tool log file"),
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
135long
136GNERunDialog::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()) {
146 toolFinished = true;
147 break;
149 style = 1;
150 break;
152 style = 2;
153 break;
155 style = 4;
156 myWarning = true;
157 break;
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 }
187 return 1;
188}
189
190
191void
193 // update buttons
195 // update run button
196 myRunButton->setText(TL("Abort"));
197 myRunButton->setTipText(TL("Abort running"));
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"));
207 // enable buttons
208 myBackButton->enable();
209 myAcceptButton->enable();
210 }
211 // update dialog
212 GNEDialog::update();
213}
214
215/****************************************************************************/
DialogType
FXDEFMAP(GNERunDialog) GNERunDialogMap[]
@ MID_GNE_BUTTON_SAVE
save button
@ ID_LOADTHREAD_EVENT
The loading thread.
Definition GUIAppEnum.h:348
#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
@ WARNING_OCCURRED
send when a warning occurred
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:146
FXButton * myAcceptButton
accept button
Definition GNEDialog.h:155
OpenType
Open dialog type.
Definition GNEDialog.h:58
FXButton * myBackButton
back button
Definition GNEDialog.h:170
FXButton * myRunButton
run button
Definition GNEDialog.h:167
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
virtual long onCmdAccept(FXObject *, FXSelector, void *)=0
event after press close button
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
void addEvent(GUIEvent *event, const bool signal)
add event in the queue
long onCmdAbort(FXObject *, FXSelector, void *)
event after press abort button
bool myWarning
flag to check if there is a warning
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.
const bool myCloseIfSucess
flag to close dialog automatically if sucess
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