Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNENetgenerateDialog.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 netgenerate
19/****************************************************************************/
20
23
25
26// ===========================================================================
27// Defines
28// ===========================================================================
29
30#define MARGIN 4
31#define MAXNUMCOLUMNS 4
32#define NUMROWSBYCOLUMN 20
33
34// ===========================================================================
35// FOX callback mapping
36// ===========================================================================
37
52
53// Object implementation
54FXIMPLEMENT(GNENetgenerateDialog, MFXDialogBox, GNENetgenerateDialogMap, ARRAYNUMBER(GNENetgenerateDialogMap))
55
56// ============================================-===============================
57// member method definitions
58// ===========================================================================
59
61 MFXDialogBox(GNEApp->getApp(), "Netgenerate", GUIDesignDialogBox),
62 myGNEApp(GNEApp) {
63 // set icon
65 // build labels
66 auto horizontalFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
67 myGridNetworkLabel = new FXLabel(horizontalFrame, TL("Grid"), nullptr, GUIDesignLabelThickedFixed(GUIDesignBigSizeElement));
68 mySpiderNetworkLabel = new FXLabel(horizontalFrame, TL("Spider"), nullptr, GUIDesignLabelThickedFixed(GUIDesignBigSizeElement));
69 myRandomGridNetworkLabel = new FXLabel(horizontalFrame, TL("Random grid"), nullptr, GUIDesignLabelThickedFixed(GUIDesignBigSizeElement));
70 myRandomNetworkLabel = new FXLabel(horizontalFrame, TL("Random"), nullptr, GUIDesignLabelThickedFixed(GUIDesignBigSizeElement));
71 // build buttons
72 horizontalFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
73 myGridNetworkButton = new MFXCheckableButton(false, horizontalFrame, GNEApp->getStaticTooltipMenu(), "",
75 mySpiderNetworkButton = new MFXCheckableButton(false, horizontalFrame, GNEApp->getStaticTooltipMenu(), "",
77 myRandomGridNetworkButton = new MFXCheckableButton(false, horizontalFrame, GNEApp->getStaticTooltipMenu(), "",
79 myRandomNetworkButton = new MFXCheckableButton(false, horizontalFrame, GNEApp->getStaticTooltipMenu(), "",
81 // add invisible separator
82 new FXSeparator(this, SEPARATOR_NONE);
83 // build output file elements
84 horizontalFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
85 new FXLabel(horizontalFrame, "output-file", nullptr, GUIDesignLabelThickedFixed(GUIDesignBigSizeElement));
86 GUIDesigns::buildFXButton(horizontalFrame, "", "", TL("Select filename"),
88 myOutputTextField = new FXTextField(horizontalFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
89 // add separator
90 new FXSeparator(this);
91 // create buttons centered
92 horizontalFrame = new FXHorizontalFrame(this, GUIDesignHorizontalFrame);
93 new FXHorizontalFrame(horizontalFrame, GUIDesignAuxiliarHorizontalFrame);
94 myRunButton = GUIDesigns::buildFXButton(horizontalFrame, TL("Run"), "", TL("close accepting changes"),
96 myAdvancedButton = GUIDesigns::buildFXButton(horizontalFrame, TL("Advanced"), "", TL("open advance netgenerate dialog"),
98 GUIDesigns::buildFXButton(horizontalFrame, TL("Cancel"), "", TL("Close dialog"),
100 new FXHorizontalFrame(horizontalFrame, GUIDesignAuxiliarHorizontalFrame);
101}
102
103
105
106
107void
109 auto& generateOptions = myGNEApp->getNetgenerateOptions();
110 // reset buttons
111 if (generateOptions.getBool("grid")) {
112 if (generateOptions.getBool("rand.grid")) {
114 onCmdSetRandomGrid(nullptr, 0, nullptr);
115 } else {
117 onCmdSetGrid(nullptr, 0, nullptr);
118 }
119 } else if (generateOptions.getBool("spider")) {
121 onCmdSetSpider(nullptr, 0, nullptr);
122 } else if (generateOptions.getBool("random")) {
124 onCmdSetRandom(nullptr, 0, nullptr);
125 }
126 // set output
127 myOutputTextField->setText(generateOptions.getValueString("output-file").c_str());
128 // show dialog
129 MFXDialogBox::show(PLACEMENT_SCREEN);
130 // refresh APP
131 getApp()->refresh();
132}
133
134
135void
137 // finish
138}
139
140
141long
142GNENetgenerateDialog::onCmdOpenOutputFile(FXObject*, FXSelector, void*) {
143 // get output file
144 const auto outputFile = GNEApplicationWindowHelper::openNetworkFileDialog(this, true);
145 // check file
146 if (!outputFile.empty()) {
147 myOutputTextField->setText(outputFile.c_str(), TRUE);
148 }
149 return 1;
150}
151
152
153long
154GNENetgenerateDialog::onCmdSetOutput(FXObject*, FXSelector, void*) {
155 auto& generateOptions = myGNEApp->getNetgenerateOptions();
156 generateOptions.resetWritable();
157 // check if filename is valid
158 if (SUMOXMLDefinitions::isValidFilename(myOutputTextField->getText().text()) == false) {
159 myOutputTextField->setTextColor(FXRGB(255, 0, 0));
160 } else {
161 generateOptions.set("output-file", myOutputTextField->getText().text());
162 myOutputTextField->setTextColor(FXRGB(0, 0, 0));
163 }
164 return 1;
165}
166
167
168long
169GNENetgenerateDialog::onCmdSetGrid(FXObject*, FXSelector, void*) {
170 auto& generateOptions = myGNEApp->getNetgenerateOptions();
171 // reset all flags
172 generateOptions.resetWritable();
173 generateOptions.set("grid", "true");
174 generateOptions.set("spider", "false");
175 generateOptions.set("rand", "false");
176 generateOptions.set("rand.grid", "false");
177 // set buttons
178 myGridNetworkButton->setChecked(true, true);
179 mySpiderNetworkButton->setChecked(false, true);
181 myRandomNetworkButton->setChecked(false, true);
182 // set labels color
183 myGridNetworkLabel->setTextColor(FXRGB(0, 0, 255));
184 mySpiderNetworkLabel->setTextColor(FXRGB(0, 0, 0));
185 myRandomGridNetworkLabel->setTextColor(FXRGB(0, 0, 0));
186 myRandomNetworkLabel->setTextColor(FXRGB(0, 0, 0));
187 return 1;
188}
189
190
191long
192GNENetgenerateDialog::onCmdSetSpider(FXObject*, FXSelector, void*) {
193 auto& generateOptions = myGNEApp->getNetgenerateOptions();
194 // reset all flags
195 generateOptions.resetWritable();
196 generateOptions.set("grid", "false");
197 generateOptions.set("spider", "true");
198 generateOptions.set("spider.omit-center", "true");
199 generateOptions.set("rand", "false");
200 generateOptions.set("rand.grid", "false");
201 // set buttons
202 myGridNetworkButton->setChecked(false, true);
205 myRandomNetworkButton->setChecked(false, true);
206 // set labels color
207 myGridNetworkLabel->setTextColor(FXRGB(0, 0, 0));
208 mySpiderNetworkLabel->setTextColor(FXRGB(0, 0, 255));
209 myRandomGridNetworkLabel->setTextColor(FXRGB(0, 0, 0));
210 myRandomNetworkLabel->setTextColor(FXRGB(0, 0, 0));
211 return 1;
212}
213
214
215long
216GNENetgenerateDialog::onCmdSetRandomGrid(FXObject*, FXSelector, void*) {
217 auto& generateOptions = myGNEApp->getNetgenerateOptions();
218 // reset all flags
219 generateOptions.resetWritable();
220 generateOptions.set("grid", "false");
221 generateOptions.set("spider", "false");
222 generateOptions.set("rand", "true");
223 generateOptions.set("rand.grid", "true");
224 // set buttons
225 myGridNetworkButton->setChecked(false, true);
226 mySpiderNetworkButton->setChecked(false, true);
228 myRandomNetworkButton->setChecked(false, true);
229 // set labels color
230 myGridNetworkLabel->setTextColor(FXRGB(0, 0, 0));
231 mySpiderNetworkLabel->setTextColor(FXRGB(0, 0, 0));
232 myRandomGridNetworkLabel->setTextColor(FXRGB(0, 0, 255));
233 myRandomNetworkLabel->setTextColor(FXRGB(0, 0, 0));
234 return 1;
235}
236
237
238long
239GNENetgenerateDialog::onCmdSetRandom(FXObject*, FXSelector, void*) {
240 auto& generateOptions = myGNEApp->getNetgenerateOptions();
241 // reset all flags
242 generateOptions.resetWritable();
243 generateOptions.set("grid", "false");
244 generateOptions.set("spider", "false");
245 generateOptions.set("rand", "true");
246 generateOptions.set("rand.grid", "false");
247 // set buttons
248 myGridNetworkButton->setChecked(false, true);
249 mySpiderNetworkButton->setChecked(false, true);
252 // set labels color
253 myGridNetworkLabel->setTextColor(FXRGB(0, 0, 0));
254 mySpiderNetworkLabel->setTextColor(FXRGB(0, 0, 0));
255 myRandomGridNetworkLabel->setTextColor(FXRGB(0, 0, 0));
256 myRandomNetworkLabel->setTextColor(FXRGB(0, 0, 255));
257 return 1;
258}
259
260
261long
262GNENetgenerateDialog::onCmdRun(FXObject*, FXSelector, void*) {
263 // hide dialog
264 hide();
265 // run netgenerate
266 return myGNEApp->tryHandle(this, FXSEL(SEL_COMMAND, MID_GNE_RUNNETGENERATE), nullptr);
267}
268
269
270long
271GNENetgenerateDialog::onCmdAdvanced(FXObject*, FXSelector, void*) {
272 // hide dialog
273 hide();
274 // open netgenerate option dialog
275 return myGNEApp->tryHandle(this, FXSEL(SEL_COMMAND, MID_GNE_NETGENERATEOPTIONS), nullptr);
276}
277
278
279long
280GNENetgenerateDialog::onUpdSettingsConfigured(FXObject* sender, FXSelector, void*) {
281 auto& generateOptions = myGNEApp->getNetgenerateOptions();
282 // check conditions
283 if ((generateOptions.getBool("grid") == false) &&
284 (generateOptions.getBool("spider") == false) &&
285 (generateOptions.getBool("rand") == false)) {
286 return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
287 } else if (generateOptions.getValueString("output-file").empty()) {
288 return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
289 } else {
290 return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
291 }
292}
293
294
295long
296GNENetgenerateDialog::onCmdCancel(FXObject*, FXSelector, void*) {
297 // hide dialog
298 hide();
299 return 1;
300}
301
302
304 myGNEApp(nullptr) {
305}
306
307/****************************************************************************/
FXDEFMAP(GNENetgenerateDialog) GNENetgenerateDialogMap[]
@ MID_GNE_NETGENERATEOPTIONS
netgenerate options
Definition GUIAppEnum.h:763
@ MID_GNE_RUNNETGENERATE
run netgenerate tool
Definition GUIAppEnum.h:773
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition GUIAppEnum.h:991
@ MID_GNE_BUTTON_RUN
run button
@ MID_GNE_BUTTON_CANCEL
cancel button
@ MID_GNE_BUTTON_ADVANCED
advanced button
@ MID_GNE_NETGENERATE_SPIDER
netgenerate spider network
Definition GUIAppEnum.h:767
@ MID_GNE_NETGENERATE_RANDOM
netgenerate random network
Definition GUIAppEnum.h:771
@ MID_GNE_NETGENERATE_RANDOMGRID
netgenerate random grid network
Definition GUIAppEnum.h:769
@ MID_GNE_NETGENERATE_GRID
netgenerate grid network
Definition GUIAppEnum.h:765
@ MID_GNE_OPEN
open element
#define GUIDesignButtonIcon
button only with icon
Definition GUIDesigns.h:91
#define GUIDesignButtonAccept
Accept Button.
Definition GUIDesigns.h:156
#define GUIDesignTextField
Definition GUIDesigns.h:59
#define GUIDesignButtonAdvanced
Advanced Button.
Definition GUIDesigns.h:168
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:399
#define GUIDesignDialogBox
Definition GUIDesigns.h:599
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition GUIDesigns.h:74
#define GUIDesignBigSizeElement
elements with big images
Definition GUIDesigns.h:44
#define GUIDesignMFXCheckableButtonBig
checkable button extended over frame
Definition GUIDesigns.h:146
#define GUIDesignButtonReset
Reset Button.
Definition GUIDesigns.h:165
#define GUIDesignLabelThickedFixed(width)
label thicked, icon before text, text centered and custom width
Definition GUIDesigns.h:252
#define GUIDesignHorizontalFrame
Horizontal frame extended over frame parent with padding and spacing.
Definition GUIDesigns.h:328
@ NETGENERATE_SPIDER
@ NETGENERATE_RANDOMGRID
@ NETGENERATE_GRID
@ NETGENERATE_RANDOM
#define TL(string)
Definition MsgHandler.h:305
The main window of Netedit.
OptionsCont & getNetgenerateOptions()
get netgenerate options container
long onCmdSetRandom(FXObject *, FXSelector, void *)
set random
long onCmdSetRandomGrid(FXObject *, FXSelector, void *)
set random grid
FXLabel * mySpiderNetworkLabel
grid network
long onCmdSetOutput(FXObject *, FXSelector, void *)
set output file
MFXCheckableButton * myRandomNetworkButton
grid network
long onCmdOpenOutputFile(FXObject *, FXSelector, void *)
open output file
long onCmdSetGrid(FXObject *, FXSelector, void *)
set grid mode
long onCmdAdvanced(FXObject *, FXSelector, void *)
event after press advanced button
FXLabel * myGridNetworkLabel
grid network
long onCmdSetSpider(FXObject *, FXSelector, void *)
set spider
MFXCheckableButton * myGridNetworkButton
grid network
void runInternalTest(const InternalTestStep::DialogTest *modalArguments)
run internal test
MFXCheckableButton * mySpiderNetworkButton
grid network
long onCmdRun(FXObject *, FXSelector, void *)
event after press run button
GNEApplicationWindow * myGNEApp
pointer to GNEApplicationWindow
MFXCheckableButton * myRandomGridNetworkButton
random grid network
long onUpdSettingsConfigured(FXObject *, FXSelector, void *)
check if settings are enabled
FXLabel * myRandomGridNetworkLabel
random grid network
FXLabel * myRandomNetworkLabel
grid network
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
FXTextField * myOutputTextField
output text field
GNENetgenerateDialog()
FOX needs this.
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
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
dialog arguments (used for certain functions that opens modal dialogs)
void setChecked(bool val, const bool inform=false)
check or uncheck this MFXCheckableButton
void resetWritable()
Resets all options to be writeable.
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)
static std::string openNetworkFileDialog(FXWindow *window, bool save, bool multi=false)
open netconvert file dialog