Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
tools/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
22#include <netedit/tools/GNERunNetgenerate.h>
25
27
28// ===========================================================================
29// Defines
30// ===========================================================================
31
32#define MARGIN 4
33
34// ===========================================================================
35// FOX callback mapping
36// ===========================================================================
37
47
48// Object implementation
49FXIMPLEMENT(GNERunNetgenerateDialog, GNEDialog, GNERunNetgenerateDialogMap, ARRAYNUMBER(GNERunNetgenerateDialogMap))
50
51// ============================================-===============================
52// member method definitions
53// ===========================================================================
54
55GNERunNetgenerateDialog::GNERunNetgenerateDialog(GNEApplicationWindow* applicationWindow, const OptionsCont* netgenerateOptions) :
56 GNEDialog(applicationWindow, TL("Running netgenerate results"), GUIIcon::NETGENERATE,
57 GNEDialog::Buttons::ABORT_RERUN_BACK_CLOSE, OpenType::MODAL,
58 GNEDialog::ResizeMode::RESIZABLE, 640, 480) {
59 // build the thread - io
60 myThreadEvent.setTarget(this);
61 myThreadEvent.setSelector(ID_LOADTHREAD_EVENT);
62 // create run tool
63 myRunNetgenerate = new GNERunNetgenerate(this, myEvents, myThreadEvent);
64 // create header frame
65 auto headerFrame = new FXHorizontalFrame(myContentFrame, GUIDesignHorizontalFrame);
66 // adjust padding
67 headerFrame->setPadLeft(0);
68 headerFrame->setPadRight(0);
69 GUIDesigns::buildFXButton(headerFrame, "", "", + TL("Save output"),
71 new FXLabel(headerFrame, TL("Console output"), nullptr, GUIDesignLabelThick(JUSTIFY_LEFT));
72 // create text
73 auto textFrame = new FXVerticalFrame(myContentFrame, GUIDesignFrameThick);
74 myText = new FXText(textFrame, 0, 0, (TEXT_READONLY | LAYOUT_FILL_X | LAYOUT_FILL_Y));
75 // set styled
76 myText->setHiliteStyles(GUIMessageWindow::getStyles());
77 myText->setStyled(true);
78 // set netgenerate options
79 myNetgenerateOptions = netgenerateOptions;
80 // reset error flag
81 myError = false;
82 // open modal dialog before running netgenerate
83 openDialog();
84 // run tool
85 myRunNetgenerate->run(myNetgenerateOptions);
86}
87
88
90
91
92void
94 // nothing to do
95}
96
97
98void
100 /*
101 // update buttons
102 if (myRunNetgenerate->isRunning()) {
103 myAbortButton->enable();
104 myRerunButton->disable();
105 myBackButton->disable();
106 myCloseButton->disable();
107 } else {
108 myAbortButton->disable();
109 myRerunButton->enable();
110 myBackButton->enable();
111 myCloseButton->enable();
112 }
113 */
114 // update dialog
115 GNEDialog::update();
116}
117
118
119long
120GNERunNetgenerateDialog::onCmdSaveLog(FXObject*, FXSelector, void*) {
121 // get log file
122 const auto logFile = GNEApplicationWindowHelper::saveToolLog(this);
123 // check that file is valid
124 if (logFile.size() > 0) {
126 dev << myText->getText().text();
127 dev.close();
128 }
129 return 1;
130}
131
132
133long
134GNERunNetgenerateDialog::onCmdAbort(FXObject*, FXSelector, void*) {
135 // abort tool
136 myRunNetgenerate->abort();
137 return 1;
138}
139
140
141long
142GNERunNetgenerateDialog::onCmdRerun(FXObject*, FXSelector, void*) {
143 // add line and info
144 std::string line("-------------------------------------------\n");
145 myText->appendStyledText(line.c_str(), (int)line.length(), 4, TRUE);
146 myText->appendStyledText("rerun tool\n", 1, TRUE);
147 myText->layout();
148 myText->update();
149 myError = false;
150 // run tool
152 return 1;
153}
154
155
156long
157GNERunNetgenerateDialog::onCmdBack(FXObject*, FXSelector, void*) {
158 // close run dialog and open tool dialog
159 onCmdCancel(nullptr, 0, nullptr);
160 return myApplicationWindow->handle(this, FXSEL(SEL_COMMAND, MID_GNE_NETGENERATE), nullptr);
161}
162
163
164long
165GNERunNetgenerateDialog::onCmdAccept(FXObject*, FXSelector, void*) {
166 // close run dialog and call postprocessing
167 onCmdCancel(nullptr, 0, nullptr);
168 myText->setText("", 0);
169 // call postprocessing dialog
170 if (myError) {
171 return 1;
172 } else {
173 // don't run this again
174 myError = true;
175 return myApplicationWindow->handle(this, FXSEL(SEL_COMMAND, MID_GNE_POSTPROCESSINGNETGENERATE), nullptr);
176 }
177}
178
179
180long
181GNERunNetgenerateDialog::onCmdCancel(FXObject*, FXSelector, void*) {
182 // abort tool
183 myRunNetgenerate->abort();
184 // workaround race conditionat that prevents hiding
185 show();
186 hide();
187 return 1;
188}
189
190long
191GNERunNetgenerateDialog::onThreadEvent(FXObject*, FXSelector, void*) {
192 bool toolFinished = false;
193 while (!myEvents.empty()) {
194 // get the next event
195 GUIEvent* e = myEvents.top();
196 myEvents.pop();
197 // process
198 FXint style = -1;
199 switch (e->getOwnType()) {
201 toolFinished = true;
202 break;
204 style = 1;
205 break;
207 style = 2;
208 break;
210 style = 3;
211 myError = true;
212 break;
213 default:
214 break;
215 }
216 if (style >= 0) {
217 GUIEvent_Message* ec = static_cast<GUIEvent_Message*>(e);
218 myText->appendStyledText(ec->getMsg().c_str(), (int)ec->getMsg().length(), style, TRUE);
219 myText->layout();
220 myText->update();
221 }
222 delete e;
223 updateDialog();
224 }
225
226 if (toolFinished) {
227 // check if close dialog immediately after running
228 if (myText->getText().find("Error") != -1) {
229 myError = true;
230 } else if ((myText->getText().find("Success") != -1) && (myText->getText().find("Warning") == -1)) {
231 onCmdClose(nullptr, 0, nullptr);
232 }
233 }
234
235 return 1;
236}
237
238/****************************************************************************/
@ 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
#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:305
The main window of Netedit.
GNEApplicationWindow * myApplicationWindow
FOX needs this.
Definition GNEDialog.h:132
long onCmdAbort(FXObject *, FXSelector, void *)
event after press abort button
void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)
run internal test
MFXSynchQue< GUIEvent * > myEvents
List of received events.
long onCmdSaveLog(FXObject *, FXSelector, void *)
event after press save button
bool myError
flag to check if there is an error
GNERunNetgenerateDialog(GNEApplicationWindow *applicationWindow, const OptionsCont *netgenerateOptions)
Constructor.
long onCmdRerun(FXObject *, FXSelector, void *)
event after press rerun button
long onCmdAccept(FXObject *, FXSelector, void *)
event after press close button
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
GNERunNetgenerate * myRunNetgenerate
thread for running tool
long onThreadEvent(FXObject *, FXSelector, void *)
called when the thread signals an event
long onCmdBack(FXObject *, FXSelector, void *)
event after press back button
const OptionsCont * myNetgenerateOptions
netgenerate options
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
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
FXDEFMAP(GNERunNetgenerateDialog) GNERunNetgenerateDialogMap[]