Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
tools/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
23#include <netedit/tools/GNERunPythonTool.h>
26
28
29// ===========================================================================
30// Defines
31// ===========================================================================
32
33#define MARGIN 4
34
35// ===========================================================================
36// FOX callback mapping
37// ===========================================================================
38
48
49// Object implementation
50FXIMPLEMENT(GNERunPythonToolDialog, GNEDialog, GNERunPythonToolDialogMap, ARRAYNUMBER(GNERunPythonToolDialogMap))
51
52// ============================================-===============================
53// member method definitions
54// ===========================================================================
55
57 GNEDialog(applicationWindow, TL("Python Tool"), GUIIcon::TOOL_PYTHON,
58 GNEDialog::Buttons::ABORT_RERUN_BACK_CLOSE,
59 OpenType::MODAL, ResizeMode::RESIZABLE, 640, 480) {
60 // build the thread - io
61 myThreadEvent.setTarget(this);
62 myThreadEvent.setSelector(ID_LOADTHREAD_EVENT);
63 // create run tool
64 myRunTool = new GNERunPythonTool(this, myEvents, myThreadEvent);
65 // create header frame
66 auto headerFrame = new FXHorizontalFrame(myContentFrame, GUIDesignHorizontalFrame);
67 // adjust padding
68 headerFrame->setPadLeft(0);
69 headerFrame->setPadRight(0);
70 GUIDesigns::buildFXButton(headerFrame, "", "", + TL("Save output"),
72 new FXLabel(headerFrame, TL("Console output"), nullptr, GUIDesignLabelThick(JUSTIFY_LEFT));
73 // create text
74 auto textFrame = new FXVerticalFrame(myContentFrame, GUIDesignFrameThick);
75 myText = new FXText(textFrame, 0, 0, (TEXT_READONLY | LAYOUT_FILL_X | LAYOUT_FILL_Y));
76 // set styled
77 myText->setHiliteStyles(GUIMessageWindow::getStyles());
78 myText->setStyled(true);
79 // set title
80 setTitle((tool->getToolName() + " output").c_str());
81 // refresh APP
82 getApp()->refresh();
83 // clear text
84 myText->setText("");
85 // show dialog
86 GNEDialog::show(PLACEMENT_SCREEN);
87 // set tool
88 myPythonTool = tool;
89 // open modal dialog
90 openDialog();
91 // run tool
92 myRunTool->runTool(tool);
93}
94
95
97
98
99void
101 // finish
102}
103
104
105void
107 // update buttons
108 /*
109 if (myRunTool->isRunning()) {
110 myAbortButton->enable();
111 myRerunButton->disable();
112 myBackButton->disable();
113 myCloseButton->disable();
114 } else {
115 myAbortButton->disable();
116 myRerunButton->enable();
117 myBackButton->enable();
118 myCloseButton->enable();
119 }
120 */
121 // update dialog
122 GNEDialog::update();
123}
124
125
126long
127GNERunPythonToolDialog::onCmdSaveLog(FXObject*, FXSelector, void*) {
128 // get log file
129 const auto logFile = GNEApplicationWindowHelper::saveToolLog(this);
130 // check that file is valid
131 if (logFile.size() > 0) {
133 dev << myText->getText().text();
134 dev.close();
135 }
136 return 1;
137}
138
139
140long
141GNERunPythonToolDialog::onCmdAbort(FXObject*, FXSelector, void*) {
142 // abort tool
143 myRunTool->abortTool();
144 return 1;
145}
146
147
148long
149GNERunPythonToolDialog::onCmdRerun(FXObject*, FXSelector, void*) {
150 // add line and info
151 std::string line("-------------------------------------------\n");
152 myText->appendStyledText(line.c_str(), (int)line.length(), 4, TRUE);
153 myText->appendStyledText("rerun tool\n", 1, TRUE);
154 myText->layout();
155 myText->update();
156 // run tool
157 myRunTool->runTool(myPythonTool);
158 return 1;
159}
160
161
162long
163GNERunPythonToolDialog::onCmdBack(FXObject*, FXSelector, void*) {
164 // close runTool dialog and open tool dialog
165 onCmdClose(nullptr, 0, nullptr);
166 return myApplicationWindow->handle(myPythonTool->getMenuCommand(), FXSEL(SEL_COMMAND, MID_GNE_OPENPYTHONTOOLDIALOG), nullptr);
167}
168
169
170long
171GNERunPythonToolDialog::onCmdCancel(FXObject* obj, FXSelector, void*) {
172 // abort tool
173 myRunTool->abortTool();
174 // hide dialog
175 hide();
176 return 1;
177}
178
179
180long
181GNERunPythonToolDialog::onCmdAccept(FXObject* obj, FXSelector, void*) {
182 // abort tool
183 myRunTool->abortTool();
184 // execute post processing
186 // hide dialog
187 hide();
188 return 1;
189}
190
191
192long
193GNERunPythonToolDialog::onThreadEvent(FXObject*, FXSelector, void*) {
194 while (!myEvents.empty()) {
195 // get the next event
196 GUIEvent* e = myEvents.top();
197 myEvents.pop();
198 // process
199 FXint style = -1;
200 switch (e->getOwnType()) {
202 break;
204 style = 1;
205 break;
207 style = 2;
208 break;
210 style = 3;
211 break;
212 default:
213 break;
214 }
215 if (style >= 0) {
216 GUIEvent_Message* ec = static_cast<GUIEvent_Message*>(e);
217 myText->appendStyledText(ec->getMsg().c_str(), (int)ec->getMsg().length(), style, TRUE);
218 myText->layout();
219 myText->update();
220 }
221 delete e;
222 updateDialog();
223 }
224 return 1;
225}
226
227/****************************************************************************/
@ MID_GNE_OPENPYTHONTOOLDIALOG
call tool
Definition GUIAppEnum.h:757
@ MID_GNE_POSTPROCESSINGPYTHONTOOL
call tool for post processing
Definition GUIAppEnum.h:761
@ 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:348
@ MID_GNE_BUTTON_BACK
back button
#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.
GNEApplicationWindow * myApplicationWindow
FOX needs this.
Definition GNEDialog.h:143
const std::string & getToolName() const
get tool name
FXMenuCommand * getMenuCommand() const
get menu command
void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)
run internal test
long onCmdRerun(FXObject *, FXSelector, void *)
event after press rerun button
long onCmdBack(FXObject *, FXSelector, void *)
event after press back button
GNERunPythonToolDialog(GNEApplicationWindow *applicationWindow, GNEPythonTool *pythonTool)
Constructor.
long onThreadEvent(FXObject *, FXSelector, void *)
called when the thread signals an event
GNERunPythonTool * myRunTool
thread for running tool
const GNEPythonTool * myPythonTool
python tool to run
long onCmdSaveLog(FXObject *, FXSelector, void *)
event after press save button
long onCmdAbort(FXObject *, FXSelector, void *)
event after press abort button
MFXSynchQue< GUIEvent * > myEvents
List of received events.
long onCmdAccept(FXObject *, FXSelector, void *)
event after press close button
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
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.
dialog arguments, used for certain modal dialogs that can not be edited using tab
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
FXDEFMAP(GNERunPythonToolDialog) GNERunPythonToolDialogMap[]