Eclipse SUMO - Simulation of Urban MObility
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-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 
25 
27 
28 #define MARGING 4
29 
30 // ===========================================================================
31 // FOX callback mapping
32 // ===========================================================================
33 
34 FXDEFMAP(GNERunNetgenerateDialog) GNERunNetgenerateDialogMap[] = {
35  FXMAPFUNC(SEL_CLOSE, 0, GNERunNetgenerateDialog::onCmdCancel),
41  // threads events
44 };
45 
46 // Object implementation
47 FXIMPLEMENT(GNERunNetgenerateDialog, FXDialogBox, GNERunNetgenerateDialogMap, ARRAYNUMBER(GNERunNetgenerateDialogMap))
48 
49 // ============================================-===============================
50 // member method definitions
51 // ===========================================================================
52 
54  FXDialogBox(GNEApp->getApp(), "", GUIDesignDialogBoxExplicit(0, 0)),
55  myGNEApp(GNEApp) {
56  // build the thread - io
57  myThreadEvent.setTarget(this);
58  myThreadEvent.setSelector(ID_LOADTHREAD_EVENT);
59  // create run tool
60  myRunNetgenerate = new GNERunNetgenerate(this, myEvents, myThreadEvent);
61  // set icon
63  // create content frame
64  auto contentFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
65  // create header frame
66  auto headerFrame = new FXHorizontalFrame(contentFrame, 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(contentFrame, 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  // create buttons Abort, rerun and back
80  auto buttonsFrame = new FXHorizontalFrame(contentFrame, GUIDesignHorizontalFrame);
81  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
82  myAbortButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Abort"), "", TL("abort running"),
84  myRerunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Rerun"), "", TL("rerun tool"),
86  myBackButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Back"), "", TL("back to tool dialog"),
88  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
89  // add separator
90  new FXSeparator(contentFrame);
91  // create button ok
92  buttonsFrame = new FXHorizontalFrame(contentFrame, GUIDesignHorizontalFrame);
93  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
94  myCloseButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Close"), "", TL("close dialog"),
96  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
97  // resize
98  resize(640, 480);
99 }
100 
101 
103 
104 
107  return myGNEApp;
108 }
109 
110 
111 void
112 GNERunNetgenerateDialog::run(const OptionsCont* netgenerateOptions) {
113  // set title
114  setTitle("Netgenerate output");
115  // refresh APP
116  getApp()->refresh();
117  // clear text
118  myText->setText("");
119  // show dialog
120  FXDialogBox::show(PLACEMENT_SCREEN);
121  // set netgenerate options
122  myNetgenerateOptions = netgenerateOptions;
123  // reset error flag
124  myError = false;
125  // run tool
127 }
128 
129 
130 void
132  // update buttons
133  if (myRunNetgenerate->isRunning()) {
134  myAbortButton->enable();
135  myRerunButton->disable();
136  myBackButton->disable();
137  myCloseButton->disable();
138  } else {
139  myAbortButton->disable();
140  myRerunButton->enable();
141  myBackButton->enable();
142  myCloseButton->enable();
143  }
144  // update dialog
145  FXDialogBox::update();
146 }
147 
148 
149 long
150 GNERunNetgenerateDialog::onCmdSaveLog(FXObject*, FXSelector, void*) {
151  // get log file
152  const auto logFile = GNEApplicationWindowHelper::saveToolLog(this);
153  // check that file is valid
154  if (logFile.size() > 0) {
155  OutputDevice& dev = OutputDevice::getDevice(logFile);
156  dev << myText->getText().text();
157  dev.close();
158  }
159  return 1;
160 }
161 
162 
163 long
164 GNERunNetgenerateDialog::onCmdAbort(FXObject*, FXSelector, void*) {
165  // abort tool
167  return 1;
168 }
169 
170 
171 long
172 GNERunNetgenerateDialog::onCmdRerun(FXObject*, FXSelector, void*) {
173  // add line and info
174  std::string line("-------------------------------------------\n");
175  myText->appendStyledText(line.c_str(), (int)line.length(), 4, TRUE);
176  myText->appendStyledText("rerun tool\n", 1, TRUE);
177  myText->layout();
178  myText->update();
179  myError = false;
180  // run tool
182  return 1;
183 }
184 
185 
186 long
187 GNERunNetgenerateDialog::onCmdBack(FXObject*, FXSelector, void*) {
188  // close run dialog and open tool dialog
189  onCmdCancel(nullptr, 0, nullptr);
190  return myGNEApp->handle(this, FXSEL(SEL_COMMAND, MID_GNE_NETGENERATE), nullptr);
191 }
192 
193 
194 long
195 GNERunNetgenerateDialog::onCmdClose(FXObject*, FXSelector, void*) {
196  // close run dialog and call postprocessing
197  onCmdCancel(nullptr, 0, nullptr);
198  myText->setText("", 0);
199  // call postprocessing dialog
200  if (myError) {
201  return 1;
202  } else {
203  // don't run this again
204  myError = true;
205  return myGNEApp->handle(this, FXSEL(SEL_COMMAND, MID_GNE_POSTPROCESSINGNETGENERATE), nullptr);
206  }
207 }
208 
209 
210 long
211 GNERunNetgenerateDialog::onCmdCancel(FXObject*, FXSelector, void*) {
212  // abort tool
214  // workaround race conditionat that prevents hiding
215  show();
216  hide();
217  return 1;
218 }
219 
220 long
221 GNERunNetgenerateDialog::onThreadEvent(FXObject*, FXSelector, void*) {
222  bool toolFinished = false;
223  while (!myEvents.empty()) {
224  // get the next event
225  GUIEvent* e = myEvents.top();
226  myEvents.pop();
227  // process
228  FXint style = -1;
229  switch (e->getOwnType()) {
231  toolFinished = true;
232  break;
234  style = 1;
235  break;
237  style = 2;
238  break;
240  style = 3;
241  myError = true;
242  break;
243  default:
244  break;
245  }
246  if (style >= 0) {
247  GUIEvent_Message* ec = static_cast<GUIEvent_Message*>(e);
248  myText->appendStyledText(ec->getMsg().c_str(), (int)ec->getMsg().length(), style, TRUE);
249  myText->layout();
250  myText->update();
251  }
252  delete e;
253  updateDialog();
254  }
255 
256  if (toolFinished) {
257  // check if close dialog immediately after running
258  if (myText->getText().find("Error") != -1) {
259  myError = true;
260  } else if ((myText->getText().find("Success") != -1) && (myText->getText().find("Warning") == -1)) {
261  onCmdClose(nullptr, 0, nullptr);
262  }
263  }
264 
265  return 1;
266 }
267 
269  myGNEApp(nullptr) {
270 }
271 
272 /****************************************************************************/
FXDEFMAP(GNERunNetgenerateDialog) GNERunNetgenerateDialogMap[]
@ MID_GNE_NETGENERATE
netgenerate dialog
Definition: GUIAppEnum.h:756
@ MID_GNE_BUTTON_RERUN
rerun button
Definition: GUIAppEnum.h:1412
@ MID_GNE_BUTTON_ABORT
abort button
Definition: GUIAppEnum.h:1414
@ MID_GNE_BUTTON_SAVE
save button
Definition: GUIAppEnum.h:1400
@ ID_LOADTHREAD_EVENT
The loading thread.
Definition: GUIAppEnum.h:344
@ MID_GNE_BUTTON_BACK
back button
Definition: GUIAppEnum.h:1416
@ MID_GNE_POSTPROCESSINGNETGENERATE
postprocesing netgenerate
Definition: GUIAppEnum.h:770
@ MID_GNE_BUTTON_ACCEPT
accept button
Definition: GUIAppEnum.h:1392
#define GUIDesignDialogBoxExplicit(width, height)
design for dialog box with specific width and height (for example, additional dialogs)
Definition: GUIDesigns.h:617
#define GUIDesignFrameThick
Thick frame extended over frame parent.
Definition: GUIDesigns.h:331
#define GUIDesignButtonIcon
button only with icon
Definition: GUIDesigns.h:97
#define GUIDesignButtonAccept
Accept Button.
Definition: GUIDesigns.h:162
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:405
#define GUIDesignLabelThick(justify)
label extended over frame with thick and with text justify to left
Definition: GUIDesigns.h:255
#define GUIDesignButtonReset
Reset Button.
Definition: GUIDesigns.h:171
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition: GUIDesigns.h:396
#define GUIDesignHorizontalFrame
Horizontal frame extended over frame parent with padding and spacing.
Definition: GUIDesigns.h:334
@ 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.
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
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
Definition: GUIDesigns.cpp:128
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.
void pop()
Definition: MFXSynchQue.h:64
bool empty()
Definition: MFXSynchQue.h:127
A storage for options typed value containers)
Definition: OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
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