Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GNERunPythonToolDialog.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// Dialog for running tools
19/****************************************************************************/
20
26
28
29// ===========================================================================
30// Defines
31// ===========================================================================
32
33#define MARGIN 4
34
35// ===========================================================================
36// FOX callback mapping
37// ===========================================================================
38
50
51// Object implementation
52FXIMPLEMENT(GNERunPythonToolDialog, FXDialogBox, GNERunPythonToolDialogMap, ARRAYNUMBER(GNERunPythonToolDialogMap))
53
54// ============================================-===============================
55// member method definitions
56// ===========================================================================
57
59 FXDialogBox(GNEApp->getApp(), "Tool", GUIDesignAuxiliarDialogBoxResizable),
60 myGNEApp(GNEApp) {
61 // build the thread - io
62 myThreadEvent.setTarget(this);
63 myThreadEvent.setSelector(ID_LOADTHREAD_EVENT);
64 // create run tool
65 myRunTool = new GNERunPythonTool(this, myEvents, myThreadEvent);
66 // set icon
68 // create content frame
69 auto contentFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
70 // create header frame
71 auto headerFrame = new FXHorizontalFrame(contentFrame, GUIDesignHorizontalFrame);
72 // adjust padding
73 headerFrame->setPadLeft(0);
74 headerFrame->setPadRight(0);
75 GUIDesigns::buildFXButton(headerFrame, "", "", + TL("Save output"),
77 new FXLabel(headerFrame, TL("Console output"), nullptr, GUIDesignLabelThick(JUSTIFY_LEFT));
78 // create text
79 auto textFrame = new FXVerticalFrame(contentFrame, GUIDesignFrameThick);
80 myText = new FXText(textFrame, 0, 0, (TEXT_READONLY | LAYOUT_FILL_X | LAYOUT_FILL_Y));
81 // set styled
82 myText->setHiliteStyles(GUIMessageWindow::getStyles());
83 myText->setStyled(true);
84 // create buttons Abort, rerun and back
85 auto buttonsFrame = new FXHorizontalFrame(contentFrame, GUIDesignHorizontalFrame);
86 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
87 myAbortButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Abort"), "", TL("abort running"),
89 myRerunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Rerun"), "", TL("rerun tool"),
91 myBackButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Back"), "", TL("back to tool dialog"),
93 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
94 // add separator
95 new FXSeparator(contentFrame);
96 // create button ok
97 buttonsFrame = new FXHorizontalFrame(contentFrame, GUIDesignHorizontalFrame);
98 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
99 myCloseButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Close"), "", TL("close dialog"),
101 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
102 // resize
103 resize(640, 480);
104}
105
106
108
109
114
115
116void
118 // set title
119 setTitle((tool->getToolName() + " output").c_str());
120 // refresh APP
121 getApp()->refresh();
122 // clear text
123 myText->setText("");
124 // show dialog
125 FXDialogBox::show(PLACEMENT_SCREEN);
126 // set tool
127 myPythonTool = tool;
128 // run tool
129 myRunTool->runTool(tool);
130}
131
132
133void
135 // update buttons
136 if (myRunTool->isRunning()) {
137 myAbortButton->enable();
138 myRerunButton->disable();
139 myBackButton->disable();
140 myCloseButton->disable();
141 } else {
142 myAbortButton->disable();
143 myRerunButton->enable();
144 myBackButton->enable();
145 myCloseButton->enable();
146 }
147 // update dialog
148 FXDialogBox::update();
149}
150
151
152long
153GNERunPythonToolDialog::onCmdSaveLog(FXObject*, FXSelector, void*) {
154 // get log file
155 const auto logFile = GNEApplicationWindowHelper::saveToolLog(this);
156 // check that file is valid
157 if (logFile.size() > 0) {
159 dev << myText->getText().text();
160 dev.close();
161 }
162 return 1;
163}
164
165
166long
167GNERunPythonToolDialog::onCmdAbort(FXObject*, FXSelector, void*) {
168 // abort tool
170 return 1;
171}
172
173
174long
175GNERunPythonToolDialog::onCmdRerun(FXObject*, FXSelector, void*) {
176 // add line and info
177 std::string line("-------------------------------------------\n");
178 myText->appendStyledText(line.c_str(), (int)line.length(), 4, TRUE);
179 myText->appendStyledText("rerun tool\n", 1, TRUE);
180 myText->layout();
181 myText->update();
182 // run tool
184 return 1;
185}
186
187
188long
189GNERunPythonToolDialog::onCmdBack(FXObject*, FXSelector, void*) {
190 // close runTool dialog and open tool dialog
191 onCmdClose(nullptr, 0, nullptr);
192 return myGNEApp->handle(myPythonTool->getMenuCommand(), FXSEL(SEL_COMMAND, MID_GNE_OPENPYTHONTOOLDIALOG), nullptr);
193}
194
195
196long
197GNERunPythonToolDialog::onCmdClose(FXObject* obj, FXSelector, void*) {
198 // abort tool
200 // check if we're closing using "close" button
201 if (obj == myCloseButton) {
202 // execute post processing
203 myGNEApp->handle(myPythonTool->getMenuCommand(), FXSEL(SEL_COMMAND, MID_GNE_POSTPROCESSINGPYTHONTOOL), nullptr);
204 }
205 // hide dialog
206 hide();
207 return 1;
208}
209
210long
211GNERunPythonToolDialog::onThreadEvent(FXObject*, FXSelector, void*) {
212 while (!myEvents.empty()) {
213 // get the next event
214 GUIEvent* e = myEvents.top();
215 myEvents.pop();
216 // process
217 FXint style = -1;
218 switch (e->getOwnType()) {
220 break;
222 style = 1;
223 break;
225 style = 2;
226 break;
228 style = 3;
229 break;
230 default:
231 break;
232 }
233 if (style >= 0) {
234 GUIEvent_Message* ec = static_cast<GUIEvent_Message*>(e);
235 myText->appendStyledText(ec->getMsg().c_str(), (int)ec->getMsg().length(), style, TRUE);
236 myText->layout();
237 myText->update();
238 }
239 delete e;
240 updateDialog();
241 }
242 return 1;
243}
244
245
247 myGNEApp(nullptr) {
248}
249
250/****************************************************************************/
FXDEFMAP(GNERunPythonToolDialog) GNERunPythonToolDialogMap[]
@ MID_GNE_OPENPYTHONTOOLDIALOG
call tool
Definition GUIAppEnum.h:755
@ MID_GNE_POSTPROCESSINGPYTHONTOOL
call tool for post processing
Definition GUIAppEnum.h:759
@ MID_GNE_BUTTON_RERUN
rerun button
@ MID_GNE_BUTTON_ABORT
abort button
@ MID_GNE_BUTTON_SAVE
save button
@ ID_LOADTHREAD_EVENT
The loading thread.
Definition GUIAppEnum.h:346
@ MID_GNE_BUTTON_BACK
back button
@ MID_GNE_BUTTON_ACCEPT
accept button
#define GUIDesignFrameThick
Thick frame extended over frame parent.
Definition GUIDesigns.h:325
#define GUIDesignButtonIcon
button only with icon
Definition GUIDesigns.h:91
#define GUIDesignButtonAccept
Accept Button.
Definition GUIDesigns.h:156
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:399
#define GUIDesignLabelThick(justify)
label extended over frame with thick and with text justify to left
Definition GUIDesigns.h:249
#define GUIDesignAuxiliarDialogBoxResizable
design for standard dialog box (for example, about dialog)
Definition GUIDesigns.h:611
#define GUIDesignButtonReset
Reset Button.
Definition GUIDesigns.h:165
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition GUIDesigns.h:390
#define GUIDesignHorizontalFrame
Horizontal frame extended over frame parent with padding and spacing.
Definition GUIDesigns.h:328
@ MESSAGE_OCCURRED
send when a message occured
@ ERROR_OCCURRED
send when a error occured
@ OUTPUT_OCCURRED
send when a tool produces output
@ TOOL_ENDED
send when a tool finishes
@ SAVE
save icons
#define TL(string)
Definition MsgHandler.h:305
The main window of Netedit.
const std::string & getToolName() const
get tool name
FXMenuCommand * getMenuCommand() const
get menu command
Abstract dialog for tools.
GNEPythonTool * myPythonTool
tool
FXButton * myRerunButton
rerun button
void updateDialog()
update toolDialog
GNEApplicationWindow * myGNEApp
pointer to GNEApplicationWindow
long onCmdRerun(FXObject *, FXSelector, void *)
event after press rerun button
long onCmdBack(FXObject *, FXSelector, void *)
event after press back button
GNEApplicationWindow * getGNEApp() const
get to GNEApplicationWindow
FXButton * myCloseButton
close button
long onThreadEvent(FXObject *, FXSelector, void *)
called when the thread signals an event
GNERunPythonTool * myRunTool
thread for running tool
long onCmdSaveLog(FXObject *, FXSelector, void *)
event after press save button
FXButton * myBackButton
back button
long onCmdAbort(FXObject *, FXSelector, void *)
event after press abort button
void runTool(GNEPythonTool *tool)
run tool (this open windows)
MFXSynchQue< GUIEvent * > myEvents
List of received events.
long onCmdClose(FXObject *, FXSelector, void *)
event after press close button
FXButton * myAbortButton
abort button
Abstract dialog for tools.
bool isRunning() const
check if tool is running
void abortTool()
abort tool running
void runTool(const GNEPythonTool *tool)
run tool
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.
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.
@ SEL_THREAD_EVENT
Definition fxexdefs.h:173
@ SEL_THREAD
Definition fxexdefs.h:155
static std::string saveToolLog(FXWindow *window)
open tool file dialog