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-2024 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#define MARGIN 4
30
31// ===========================================================================
32// FOX callback mapping
33// ===========================================================================
34
46
47// Object implementation
48FXIMPLEMENT(GNERunPythonToolDialog, FXDialogBox, GNERunPythonToolDialogMap, ARRAYNUMBER(GNERunPythonToolDialogMap))
49
50// ============================================-===============================
51// member method definitions
52// ===========================================================================
53
55 FXDialogBox(GNEApp->getApp(), "Tool", GUIDesignAuxiliarDialogBoxResizable),
56 myGNEApp(GNEApp) {
57 // build the thread - io
58 myThreadEvent.setTarget(this);
59 myThreadEvent.setSelector(ID_LOADTHREAD_EVENT);
60 // create run tool
61 myRunTool = new GNERunPythonTool(this, myEvents, myThreadEvent);
62 // set icon
64 // create content frame
65 auto contentFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
66 // create header frame
67 auto headerFrame = new FXHorizontalFrame(contentFrame, GUIDesignHorizontalFrame);
68 // adjust padding
69 headerFrame->setPadLeft(0);
70 headerFrame->setPadRight(0);
71 GUIDesigns::buildFXButton(headerFrame, "", "", + TL("Save output"),
73 new FXLabel(headerFrame, TL("Console output"), nullptr, GUIDesignLabelThick(JUSTIFY_LEFT));
74 // create text
75 auto textFrame = new FXVerticalFrame(contentFrame, GUIDesignFrameThick);
76 myText = new FXText(textFrame, 0, 0, (TEXT_READONLY | LAYOUT_FILL_X | LAYOUT_FILL_Y));
77 // set styled
78 myText->setHiliteStyles(GUIMessageWindow::getStyles());
79 myText->setStyled(true);
80 // create buttons Abort, rerun and back
81 auto buttonsFrame = new FXHorizontalFrame(contentFrame, GUIDesignHorizontalFrame);
82 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
83 myAbortButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Abort"), "", TL("abort running"),
85 myRerunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Rerun"), "", TL("rerun tool"),
87 myBackButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Back"), "", TL("back to tool dialog"),
89 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
90 // add separator
91 new FXSeparator(contentFrame);
92 // create button ok
93 buttonsFrame = new FXHorizontalFrame(contentFrame, GUIDesignHorizontalFrame);
94 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
95 myCloseButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Close"), "", TL("close dialog"),
97 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
98 // resize
99 resize(640, 480);
100}
101
102
104
105
110
111
112void
114 // set title
115 setTitle((tool->getToolName() + " output").c_str());
116 // refresh APP
117 getApp()->refresh();
118 // clear text
119 myText->setText("");
120 // show dialog
121 FXDialogBox::show(PLACEMENT_SCREEN);
122 // set tool
123 myPythonTool = tool;
124 // run tool
125 myRunTool->runTool(tool);
126}
127
128
129void
131 // update buttons
132 if (myRunTool->isRunning()) {
133 myAbortButton->enable();
134 myRerunButton->disable();
135 myBackButton->disable();
136 myCloseButton->disable();
137 } else {
138 myAbortButton->disable();
139 myRerunButton->enable();
140 myBackButton->enable();
141 myCloseButton->enable();
142 }
143 // update dialog
144 FXDialogBox::update();
145}
146
147
148long
149GNERunPythonToolDialog::onCmdSaveLog(FXObject*, FXSelector, void*) {
150 // get log file
151 const auto logFile = GNEApplicationWindowHelper::saveToolLog(this);
152 // check that file is valid
153 if (logFile.size() > 0) {
155 dev << myText->getText().text();
156 dev.close();
157 }
158 return 1;
159}
160
161
162long
163GNERunPythonToolDialog::onCmdAbort(FXObject*, FXSelector, void*) {
164 // abort tool
166 return 1;
167}
168
169
170long
171GNERunPythonToolDialog::onCmdRerun(FXObject*, FXSelector, void*) {
172 // add line and info
173 std::string line("-------------------------------------------\n");
174 myText->appendStyledText(line.c_str(), (int)line.length(), 4, TRUE);
175 myText->appendStyledText("rerun tool\n", 1, TRUE);
176 myText->layout();
177 myText->update();
178 // run tool
180 return 1;
181}
182
183
184long
185GNERunPythonToolDialog::onCmdBack(FXObject*, FXSelector, void*) {
186 // close runTool dialog and open tool dialog
187 onCmdClose(nullptr, 0, nullptr);
188 return myGNEApp->handle(myPythonTool->getMenuCommand(), FXSEL(SEL_COMMAND, MID_GNE_OPENPYTHONTOOLDIALOG), nullptr);
189}
190
191
192long
193GNERunPythonToolDialog::onCmdClose(FXObject* obj, FXSelector, void*) {
194 // abort tool
196 // check if we're closing using "close" button
197 if (obj == myCloseButton) {
198 // execute post processing
199 myGNEApp->handle(myPythonTool->getMenuCommand(), FXSEL(SEL_COMMAND, MID_GNE_POSTPROCESSINGPYTHONTOOL), nullptr);
200 }
201 // hide dialog
202 hide();
203 return 1;
204}
205
206long
207GNERunPythonToolDialog::onThreadEvent(FXObject*, FXSelector, void*) {
208 while (!myEvents.empty()) {
209 // get the next event
210 GUIEvent* e = myEvents.top();
211 myEvents.pop();
212 // process
213 FXint style = -1;
214 switch (e->getOwnType()) {
216 break;
218 style = 1;
219 break;
221 style = 2;
222 break;
224 style = 3;
225 break;
226 default:
227 break;
228 }
229 if (style >= 0) {
230 GUIEvent_Message* ec = static_cast<GUIEvent_Message*>(e);
231 myText->appendStyledText(ec->getMsg().c_str(), (int)ec->getMsg().length(), style, TRUE);
232 myText->layout();
233 myText->update();
234 }
235 delete e;
236 updateDialog();
237 }
238 return 1;
239}
240
241
243 myGNEApp(nullptr) {
244}
245
246/****************************************************************************/
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:315
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