Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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, MFXDialogBox, GNERunPythonToolDialogMap, ARRAYNUMBER(GNERunPythonToolDialogMap))
53
54// ============================================-===============================
55// member method definitions
56// ===========================================================================
57
59 MFXDialogBox(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
110void
114
115
120
121
122void
124 // set title
125 setTitle((tool->getToolName() + " output").c_str());
126 // refresh APP
127 getApp()->refresh();
128 // clear text
129 myText->setText("");
130 // show dialog
131 MFXDialogBox::show(PLACEMENT_SCREEN);
132 // set tool
133 myPythonTool = tool;
134 // run tool
135 myRunTool->runTool(tool);
136}
137
138
139void
141 // update buttons
142 if (myRunTool->isRunning()) {
143 myAbortButton->enable();
144 myRerunButton->disable();
145 myBackButton->disable();
146 myCloseButton->disable();
147 } else {
148 myAbortButton->disable();
149 myRerunButton->enable();
150 myBackButton->enable();
151 myCloseButton->enable();
152 }
153 // update dialog
154 MFXDialogBox::update();
155}
156
157
158long
159GNERunPythonToolDialog::onCmdSaveLog(FXObject*, FXSelector, void*) {
160 // get log file
161 const auto logFile = GNEApplicationWindowHelper::saveToolLog(this);
162 // check that file is valid
163 if (logFile.size() > 0) {
165 dev << myText->getText().text();
166 dev.close();
167 }
168 return 1;
169}
170
171
172long
173GNERunPythonToolDialog::onCmdAbort(FXObject*, FXSelector, void*) {
174 // abort tool
176 return 1;
177}
178
179
180long
181GNERunPythonToolDialog::onCmdRerun(FXObject*, FXSelector, void*) {
182 // add line and info
183 std::string line("-------------------------------------------\n");
184 myText->appendStyledText(line.c_str(), (int)line.length(), 4, TRUE);
185 myText->appendStyledText("rerun tool\n", 1, TRUE);
186 myText->layout();
187 myText->update();
188 // run tool
190 return 1;
191}
192
193
194long
195GNERunPythonToolDialog::onCmdBack(FXObject*, FXSelector, void*) {
196 // close runTool dialog and open tool dialog
197 onCmdClose(nullptr, 0, nullptr);
198 return myGNEApp->handle(myPythonTool->getMenuCommand(), FXSEL(SEL_COMMAND, MID_GNE_OPENPYTHONTOOLDIALOG), nullptr);
199}
200
201
202long
203GNERunPythonToolDialog::onCmdClose(FXObject* obj, FXSelector, void*) {
204 // abort tool
206 // check if we're closing using "close" button
207 if (obj == myCloseButton) {
208 // execute post processing
209 myGNEApp->handle(myPythonTool->getMenuCommand(), FXSEL(SEL_COMMAND, MID_GNE_POSTPROCESSINGPYTHONTOOL), nullptr);
210 }
211 // hide dialog
212 hide();
213 return 1;
214}
215
216long
217GNERunPythonToolDialog::onThreadEvent(FXObject*, FXSelector, void*) {
218 while (!myEvents.empty()) {
219 // get the next event
220 GUIEvent* e = myEvents.top();
221 myEvents.pop();
222 // process
223 FXint style = -1;
224 switch (e->getOwnType()) {
226 break;
228 style = 1;
229 break;
231 style = 2;
232 break;
234 style = 3;
235 break;
236 default:
237 break;
238 }
239 if (style >= 0) {
240 GUIEvent_Message* ec = static_cast<GUIEvent_Message*>(e);
241 myText->appendStyledText(ec->getMsg().c_str(), (int)ec->getMsg().length(), style, TRUE);
242 myText->layout();
243 myText->update();
244 }
245 delete e;
246 updateDialog();
247 }
248 return 1;
249}
250
251
253 myGNEApp(nullptr) {
254}
255
256/****************************************************************************/
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
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.
void runInternalTest(const InternalTestStep::DialogTest *modalArguments)
run internal test
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.
dialog arguments (used for certain functions that opens modal dialogs)
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