Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNERunNetgenerateDialog.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
25
27
28// ===========================================================================
29// Defines
30// ===========================================================================
31
32#define MARGIN 4
33
34// ===========================================================================
35// FOX callback mapping
36// ===========================================================================
37
49
50// Object implementation
51FXIMPLEMENT(GNERunNetgenerateDialog, MFXDialogBox, GNERunNetgenerateDialogMap, ARRAYNUMBER(GNERunNetgenerateDialogMap))
52
53// ============================================-===============================
54// member method definitions
55// ===========================================================================
56
58 MFXDialogBox(GNEApp->getApp(), "", GUIDesignDialogBoxExplicit(0, 0)),
59 myGNEApp(GNEApp) {
60 // build the thread - io
61 myThreadEvent.setTarget(this);
62 myThreadEvent.setSelector(ID_LOADTHREAD_EVENT);
63 // create run tool
64 myRunNetgenerate = new GNERunNetgenerate(this, myEvents, myThreadEvent);
65 // set icon
67 // create content frame
68 auto contentFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
69 // create header frame
70 auto headerFrame = new FXHorizontalFrame(contentFrame, GUIDesignHorizontalFrame);
71 // adjust padding
72 headerFrame->setPadLeft(0);
73 headerFrame->setPadRight(0);
74 GUIDesigns::buildFXButton(headerFrame, "", "", + TL("Save output"),
76 new FXLabel(headerFrame, TL("Console output"), nullptr, GUIDesignLabelThick(JUSTIFY_LEFT));
77 // create text
78 auto textFrame = new FXVerticalFrame(contentFrame, GUIDesignFrameThick);
79 myText = new FXText(textFrame, 0, 0, (TEXT_READONLY | LAYOUT_FILL_X | LAYOUT_FILL_Y));
80 // set styled
81 myText->setHiliteStyles(GUIMessageWindow::getStyles());
82 myText->setStyled(true);
83 // create buttons Abort, rerun and back
84 auto buttonsFrame = new FXHorizontalFrame(contentFrame, GUIDesignHorizontalFrame);
85 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
86 myAbortButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Abort"), "", TL("abort running"),
88 myRerunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Rerun"), "", TL("rerun tool"),
90 myBackButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Back"), "", TL("back to tool dialog"),
92 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
93 // add separator
94 new FXSeparator(contentFrame);
95 // create button ok
96 buttonsFrame = new FXHorizontalFrame(contentFrame, GUIDesignHorizontalFrame);
97 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
98 myCloseButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Close"), "", TL("close dialog"),
100 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
101 // resize
102 resize(640, 480);
103}
104
105
107
108
109void
113
114
119
120
121void
122GNERunNetgenerateDialog::run(const OptionsCont* netgenerateOptions) {
123 // set title
124 setTitle("Netgenerate output");
125 // refresh APP
126 getApp()->refresh();
127 // clear text
128 myText->setText("");
129 // show dialog
130 MFXDialogBox::show(PLACEMENT_SCREEN);
131 // set netgenerate options
132 myNetgenerateOptions = netgenerateOptions;
133 // reset error flag
134 myError = false;
135 // run tool
137}
138
139
140void
142 // update buttons
144 myAbortButton->enable();
145 myRerunButton->disable();
146 myBackButton->disable();
147 myCloseButton->disable();
148 } else {
149 myAbortButton->disable();
150 myRerunButton->enable();
151 myBackButton->enable();
152 myCloseButton->enable();
153 }
154 // update dialog
155 MFXDialogBox::update();
156}
157
158
159long
160GNERunNetgenerateDialog::onCmdSaveLog(FXObject*, FXSelector, void*) {
161 // get log file
162 const auto logFile = GNEApplicationWindowHelper::saveToolLog(this);
163 // check that file is valid
164 if (logFile.size() > 0) {
166 dev << myText->getText().text();
167 dev.close();
168 }
169 return 1;
170}
171
172
173long
174GNERunNetgenerateDialog::onCmdAbort(FXObject*, FXSelector, void*) {
175 // abort tool
177 return 1;
178}
179
180
181long
182GNERunNetgenerateDialog::onCmdRerun(FXObject*, FXSelector, void*) {
183 // add line and info
184 std::string line("-------------------------------------------\n");
185 myText->appendStyledText(line.c_str(), (int)line.length(), 4, TRUE);
186 myText->appendStyledText("rerun tool\n", 1, TRUE);
187 myText->layout();
188 myText->update();
189 myError = false;
190 // run tool
192 return 1;
193}
194
195
196long
197GNERunNetgenerateDialog::onCmdBack(FXObject*, FXSelector, void*) {
198 // close run dialog and open tool dialog
199 onCmdCancel(nullptr, 0, nullptr);
200 return myGNEApp->handle(this, FXSEL(SEL_COMMAND, MID_GNE_NETGENERATE), nullptr);
201}
202
203
204long
205GNERunNetgenerateDialog::onCmdClose(FXObject*, FXSelector, void*) {
206 // close run dialog and call postprocessing
207 onCmdCancel(nullptr, 0, nullptr);
208 myText->setText("", 0);
209 // call postprocessing dialog
210 if (myError) {
211 return 1;
212 } else {
213 // don't run this again
214 myError = true;
215 return myGNEApp->handle(this, FXSEL(SEL_COMMAND, MID_GNE_POSTPROCESSINGNETGENERATE), nullptr);
216 }
217}
218
219
220long
221GNERunNetgenerateDialog::onCmdCancel(FXObject*, FXSelector, void*) {
222 // abort tool
224 // workaround race conditionat that prevents hiding
225 show();
226 hide();
227 return 1;
228}
229
230long
231GNERunNetgenerateDialog::onThreadEvent(FXObject*, FXSelector, void*) {
232 bool toolFinished = false;
233 while (!myEvents.empty()) {
234 // get the next event
235 GUIEvent* e = myEvents.top();
236 myEvents.pop();
237 // process
238 FXint style = -1;
239 switch (e->getOwnType()) {
241 toolFinished = true;
242 break;
244 style = 1;
245 break;
247 style = 2;
248 break;
250 style = 3;
251 myError = true;
252 break;
253 default:
254 break;
255 }
256 if (style >= 0) {
257 GUIEvent_Message* ec = static_cast<GUIEvent_Message*>(e);
258 myText->appendStyledText(ec->getMsg().c_str(), (int)ec->getMsg().length(), style, TRUE);
259 myText->layout();
260 myText->update();
261 }
262 delete e;
263 updateDialog();
264 }
265
266 if (toolFinished) {
267 // check if close dialog immediately after running
268 if (myText->getText().find("Error") != -1) {
269 myError = true;
270 } else if ((myText->getText().find("Success") != -1) && (myText->getText().find("Warning") == -1)) {
271 onCmdClose(nullptr, 0, nullptr);
272 }
273 }
274
275 return 1;
276}
277
281
282/****************************************************************************/
FXDEFMAP(GNERunNetgenerateDialog) GNERunNetgenerateDialogMap[]
@ MID_GNE_NETGENERATE
netgenerate dialog
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:346
@ MID_GNE_BUTTON_BACK
back button
@ MID_GNE_POSTPROCESSINGNETGENERATE
postprocesing netgenerate
Definition GUIAppEnum.h:775
@ MID_GNE_BUTTON_ACCEPT
accept button
#define GUIDesignDialogBoxExplicit(width, height)
design for dialog box with specific width and height (for example, additional dialogs)
Definition GUIDesigns.h:614
#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 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.
Abstract dialog for tools.
long onCmdAbort(FXObject *, FXSelector, void *)
event after press abort button
FXButton * myBackButton
back button
GNEApplicationWindow * getGNEApp() const
get to GNEApplicationWindow
MFXSynchQue< GUIEvent * > myEvents
List of received events.
FXButton * myAbortButton
abort button
long onCmdSaveLog(FXObject *, FXSelector, void *)
event after press save button
bool myError
flag to check if there is an error
FXButton * myCloseButton
close button
FXButton * myRerunButton
rerun button
void updateDialog()
update toolDialog
long onCmdRerun(FXObject *, FXSelector, void *)
event after press rerun button
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
long onCmdClose(FXObject *, FXSelector, void *)
event after press close button
GNERunNetgenerate * myRunNetgenerate
thread for running tool
void run(const OptionsCont *netgenerateOptions)
run tool (this open windows)
GNEApplicationWindow * myGNEApp
pointer to GNEApplicationWindow
long onThreadEvent(FXObject *, FXSelector, void *)
called when the thread signals an event
const OptionsCont * myNetgenerateOptions
netgenerate options
void runInternalTest(const InternalTestStep::DialogTest *modalArguments)
run internal test
long onCmdBack(FXObject *, FXSelector, void *)
event after press back button
thread for running netgenerate
void run(const OptionsCont *netgenerateOptions)
run netgenerate
void abort()
abort netgenerate running
bool isRunning() const
check if netgenerate is running
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)
A storage for options typed value containers)
Definition OptionsCont.h:89
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