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
46 const std::string& name, GUIIcon titleIcon) :
47 GNEDialog(applicationWindow, name, titleIcon, GNEDialog::Buttons::RERUN_BACK_CLOSE,
48 OpenType::MODAL, GNEDialog::ResizeMode::RESIZABLE, 640, 480) {
49 // build the thread - io
50 myThreadEvent.setTarget(this);
51 myThreadEvent.setSelector(ID_LOADTHREAD_EVENT);
52 // create header frame
53 auto headerFrame = new FXHorizontalFrame(myContentFrame, GUIDesignHorizontalFrame);
54 // adjust padding
55 headerFrame->setPadLeft(0);
56 headerFrame->setPadRight(0);
57 GUIDesigns::buildFXButton(headerFrame, "", "", + TL("Save output"), GUIIconSubSys::getIcon(GUIIcon::SAVE),
59 new FXLabel(headerFrame, TL("Console output"), nullptr, GUIDesignLabelThick(JUSTIFY_LEFT));
60 // create text
61 auto textFrame = new FXVerticalFrame(myContentFrame, GUIDesignFrameThick);
62 myText = new FXText(textFrame, 0, 0, (TEXT_READONLY | LAYOUT_FILL_X | LAYOUT_FILL_Y));
63 // set styled
64 myText->setHiliteStyles(GUIMessageWindow::getStyles());
65 myText->setStyled(true);
66 // update dialog button
67 updateDialogButtons();
68}
69
70
72
73
74void
75GNERunDialog::addEvent(GUIEvent* event, const bool signal) {
76 // add event to queue
77 myEvents.push_back(event);
78 // signal thread event
79 if (signal) {
81 }
82}
83
84
85long
86GNERunDialog::onCmdAbort(FXObject*, FXSelector, void*) {
87 // abort external runner
89 // hide dialog
90 return closeDialogCanceling();
91}
92
93
94long
95GNERunDialog::onCmdRun(FXObject*, FXSelector, void*) {
97 // abort external runner
99 } else {
100 // add line and info
101 std::string line("-------------------------------------------\n");
102 myText->appendStyledText(line.c_str(), (int)line.length(), 4, TRUE);
103 myText->appendStyledText("rerun tool\n", 1, TRUE);
104 myText->layout();
105 myText->update();
106 myError = false;
107 // abort external runner
109 }
110 // update dialog button
112 return 1;
113}
114
115
116long
117GNERunDialog::onCmdAccept(FXObject*, FXSelector, void*) {
118 // close run dialog and call postprocessing
120 // reset text
121 myText->setText("", 0);
122 // call postprocessing dialog depending of myError
123 if (myError) {
124 return 1;
125 } else {
126 // don't run this again
127 myError = true;
128 return myApplicationWindow->handle(this, FXSEL(SEL_COMMAND, MID_GNE_POSTPROCESSINGNETGENERATE), nullptr);
129 }
130}
131
132
133long
134GNERunDialog::onCmdSaveLog(FXObject*, FXSelector, void*) {
135 // create fileDialog
136 const auto saveLogFileDialog = GNEFileDialog(myApplicationWindow,
137 TL("tool log file"),
141 // check that file is valid
142 if (saveLogFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
143 OutputDevice& dev = OutputDevice::getDevice(saveLogFileDialog.getFilename());
144 dev << myText->getText().text();
145 dev.close();
146 }
147 return 1;
148}
149
150
151long
152GNERunDialog::onThreadEvent(FXObject*, FXSelector, void*) {
153 bool toolFinished = false;
154 while (!myEvents.empty()) {
155 // get the next event
156 GUIEvent* e = myEvents.top();
157 myEvents.pop();
158 // process
159 FXint style = -1;
160 switch (e->getOwnType()) {
162 toolFinished = true;
163 break;
165 style = 1;
166 break;
168 style = 2;
169 break;
171 style = 3;
172 myError = true;
173 break;
174 default:
175 break;
176 }
177 if (style >= 0) {
178 GUIEvent_Message* ec = static_cast<GUIEvent_Message*>(e);
179 myText->appendStyledText(ec->getMsg().c_str(), (int)ec->getMsg().length(), style, TRUE);
180 myText->layout();
181 myText->update();
182 }
183 delete e;
184 }
185 if (toolFinished) {
186 // check if close dialog immediately after running
187 if (myText->getText().find("Error") != -1) {
188 myError = true;
189 } else if ((myText->getText().find("Success") != -1) && (myText->getText().find("Warning") == -1)) {
190 //onCmdClose(nullptr, 0, nullptr);
191 }
192 }
194 return 1;
195}
196
197
198void
200 // update buttons
202 // update run button
203 myRunButton->setText(TL("Abort"));
204 myRunButton->setTipText(TL("Abort running"));
206 // disable buttons
207 myBackButton->disable();
208 myAcceptButton->disable();
209 } else {
210 // update run button
211 myRunButton->setText(TL("Rerun"));
212 myRunButton->setTipText(TL("Rerun tool"));
214 // enable buttons
215 myBackButton->enable();
216 myAcceptButton->enable();
217 }
218 // update dialog
219 GNEDialog::update();
220}
221
222/****************************************************************************/
FXDEFMAP(GNERunDialog) GNERunDialogMap[]
@ MID_GNE_BUTTON_SAVE
save button
@ ID_LOADTHREAD_EVENT
The loading thread.
Definition GUIAppEnum.h:346
@ MID_GNE_POSTPROCESSINGNETGENERATE
postprocesing netgenerate
Definition GUIAppEnum.h:775
#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:305
The main window of Netedit.
GNEExternalRunner * getExternalRunner() const
get external runner
GNEApplicationWindow * myApplicationWindow
FOX needs this.
Definition GNEDialog.h:132
FXButton * myAcceptButton
accept button
Definition GNEDialog.h:138
long closeDialogAccepting()
close dialog accepting the changes
OpenType
Open dialog type.
Definition GNEDialog.h:55
FXButton * myBackButton
back button
Definition GNEDialog.h:153
FXButton * myRunButton
run button
Definition GNEDialog.h:150
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