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-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 netgenerate
19/****************************************************************************/
20
23
25
26#define MARGIN 4
27#define MAXNUMCOLUMNS 4
28#define NUMROWSBYCOLUMN 20
29
30// ===========================================================================
31// FOX callback mapping
32// ===========================================================================
33
48
49// Object implementation
50FXIMPLEMENT(GNENetgenerateDialog, FXDialogBox, GNENetgenerateDialogMap, ARRAYNUMBER(GNENetgenerateDialogMap))
51
52// ============================================-===============================
53// member method definitions
54// ===========================================================================
55
57 FXDialogBox(GNEApp->getApp(), "Netgenerate", GUIDesignDialogBox),
58 myGNEApp(GNEApp) {
59 // set icon
61 // build labels
62 auto horizontalFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
63 myGridNetworkLabel = new FXLabel(horizontalFrame, TL("Grid"), nullptr, GUIDesignLabelThickedFixed(GUIDesignBigSizeElement));
64 mySpiderNetworkLabel = new FXLabel(horizontalFrame, TL("Spider"), nullptr, GUIDesignLabelThickedFixed(GUIDesignBigSizeElement));
65 myRandomGridNetworkLabel = new FXLabel(horizontalFrame, TL("Random grid"), nullptr, GUIDesignLabelThickedFixed(GUIDesignBigSizeElement));
66 myRandomNetworkLabel = new FXLabel(horizontalFrame, TL("Random"), nullptr, GUIDesignLabelThickedFixed(GUIDesignBigSizeElement));
67 // build buttons
68 horizontalFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
69 myGridNetworkButton = new MFXCheckableButton(false, horizontalFrame, GNEApp->getStaticTooltipMenu(), "",
71 mySpiderNetworkButton = new MFXCheckableButton(false, horizontalFrame, GNEApp->getStaticTooltipMenu(), "",
73 myRandomGridNetworkButton = new MFXCheckableButton(false, horizontalFrame, GNEApp->getStaticTooltipMenu(), "",
75 myRandomNetworkButton = new MFXCheckableButton(false, horizontalFrame, GNEApp->getStaticTooltipMenu(), "",
77 // add invisible separator
78 new FXSeparator(this, SEPARATOR_NONE);
79 // build output file elements
80 horizontalFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
81 new FXLabel(horizontalFrame, "output-file", nullptr, GUIDesignLabelThickedFixed(GUIDesignBigSizeElement));
82 GUIDesigns::buildFXButton(horizontalFrame, "", "", TL("Select filename"),
84 myOutputTextField = new FXTextField(horizontalFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
85 // add separator
86 new FXSeparator(this);
87 // create buttons centered
88 horizontalFrame = new FXHorizontalFrame(this, GUIDesignHorizontalFrame);
89 new FXHorizontalFrame(horizontalFrame, GUIDesignAuxiliarHorizontalFrame);
90 myRunButton = GUIDesigns::buildFXButton(horizontalFrame, TL("Run"), "", TL("close accepting changes"),
92 myAdvancedButton = GUIDesigns::buildFXButton(horizontalFrame, TL("Advanced"), "", TL("open advance netgenerate dialog"),
94 GUIDesigns::buildFXButton(horizontalFrame, TL("Cancel"), "", TL("Close dialog"),
96 new FXHorizontalFrame(horizontalFrame, GUIDesignAuxiliarHorizontalFrame);
97}
98
99
101
102
103void
105 auto& generateOptions = myGNEApp->getNetgenerateOptions();
106 // reset buttons
107 if (generateOptions.getBool("grid")) {
108 if (generateOptions.getBool("rand.grid")) {
110 onCmdSetRandomGrid(nullptr, 0, nullptr);
111 } else {
113 onCmdSetGrid(nullptr, 0, nullptr);
114 }
115 } else if (generateOptions.getBool("spider")) {
117 onCmdSetSpider(nullptr, 0, nullptr);
118 } else if (generateOptions.getBool("random")) {
120 onCmdSetRandom(nullptr, 0, nullptr);
121 }
122 // set output
123 myOutputTextField->setText(generateOptions.getValueString("output-file").c_str());
124 // show dialog
125 FXDialogBox::show(PLACEMENT_SCREEN);
126 // refresh APP
127 getApp()->refresh();
128}
129
130
131long
132GNENetgenerateDialog::onCmdOpenOutputFile(FXObject*, FXSelector, void*) {
133 // get output file
134 const auto outputFile = GNEApplicationWindowHelper::openNetworkFileDialog(this, true);
135 // check file
136 if (!outputFile.empty()) {
137 myOutputTextField->setText(outputFile.c_str(), TRUE);
138 }
139 return 1;
140}
141
142
143long
144GNENetgenerateDialog::onCmdSetOutput(FXObject*, FXSelector, void*) {
145 auto& generateOptions = myGNEApp->getNetgenerateOptions();
146 generateOptions.resetWritable();
147 // check if filename is valid
148 if (SUMOXMLDefinitions::isValidFilename(myOutputTextField->getText().text()) == false) {
149 myOutputTextField->setTextColor(FXRGB(255, 0, 0));
150 } else {
151 generateOptions.set("output-file", myOutputTextField->getText().text());
152 myOutputTextField->setTextColor(FXRGB(0, 0, 0));
153 }
154 return 1;
155}
156
157
158long
159GNENetgenerateDialog::onCmdSetGrid(FXObject*, FXSelector, void*) {
160 auto& generateOptions = myGNEApp->getNetgenerateOptions();
161 // reset all flags
162 generateOptions.resetWritable();
163 generateOptions.set("grid", "true");
164 generateOptions.set("spider", "false");
165 generateOptions.set("rand", "false");
166 generateOptions.set("rand.grid", "false");
167 // set buttons
168 myGridNetworkButton->setChecked(true, true);
169 mySpiderNetworkButton->setChecked(false, true);
171 myRandomNetworkButton->setChecked(false, true);
172 // set labels color
173 myGridNetworkLabel->setTextColor(FXRGB(0, 0, 255));
174 mySpiderNetworkLabel->setTextColor(FXRGB(0, 0, 0));
175 myRandomGridNetworkLabel->setTextColor(FXRGB(0, 0, 0));
176 myRandomNetworkLabel->setTextColor(FXRGB(0, 0, 0));
177 return 1;
178}
179
180
181long
182GNENetgenerateDialog::onCmdSetSpider(FXObject*, FXSelector, void*) {
183 auto& generateOptions = myGNEApp->getNetgenerateOptions();
184 // reset all flags
185 generateOptions.resetWritable();
186 generateOptions.set("grid", "false");
187 generateOptions.set("spider", "true");
188 generateOptions.set("spider.omit-center", "true");
189 generateOptions.set("rand", "false");
190 generateOptions.set("rand.grid", "false");
191 // set buttons
192 myGridNetworkButton->setChecked(false, true);
195 myRandomNetworkButton->setChecked(false, true);
196 // set labels color
197 myGridNetworkLabel->setTextColor(FXRGB(0, 0, 0));
198 mySpiderNetworkLabel->setTextColor(FXRGB(0, 0, 255));
199 myRandomGridNetworkLabel->setTextColor(FXRGB(0, 0, 0));
200 myRandomNetworkLabel->setTextColor(FXRGB(0, 0, 0));
201 return 1;
202}
203
204
205long
206GNENetgenerateDialog::onCmdSetRandomGrid(FXObject*, FXSelector, void*) {
207 auto& generateOptions = myGNEApp->getNetgenerateOptions();
208 // reset all flags
209 generateOptions.resetWritable();
210 generateOptions.set("grid", "false");
211 generateOptions.set("spider", "false");
212 generateOptions.set("rand", "true");
213 generateOptions.set("rand.grid", "true");
214 // set buttons
215 myGridNetworkButton->setChecked(false, true);
216 mySpiderNetworkButton->setChecked(false, true);
218 myRandomNetworkButton->setChecked(false, true);
219 // set labels color
220 myGridNetworkLabel->setTextColor(FXRGB(0, 0, 0));
221 mySpiderNetworkLabel->setTextColor(FXRGB(0, 0, 0));
222 myRandomGridNetworkLabel->setTextColor(FXRGB(0, 0, 255));
223 myRandomNetworkLabel->setTextColor(FXRGB(0, 0, 0));
224 return 1;
225}
226
227
228long
229GNENetgenerateDialog::onCmdSetRandom(FXObject*, FXSelector, void*) {
230 auto& generateOptions = myGNEApp->getNetgenerateOptions();
231 // reset all flags
232 generateOptions.resetWritable();
233 generateOptions.set("grid", "false");
234 generateOptions.set("spider", "false");
235 generateOptions.set("rand", "true");
236 generateOptions.set("rand.grid", "false");
237 // set buttons
238 myGridNetworkButton->setChecked(false, true);
239 mySpiderNetworkButton->setChecked(false, true);
242 // set labels color
243 myGridNetworkLabel->setTextColor(FXRGB(0, 0, 0));
244 mySpiderNetworkLabel->setTextColor(FXRGB(0, 0, 0));
245 myRandomGridNetworkLabel->setTextColor(FXRGB(0, 0, 0));
246 myRandomNetworkLabel->setTextColor(FXRGB(0, 0, 255));
247 return 1;
248}
249
250
251long
252GNENetgenerateDialog::onCmdRun(FXObject*, FXSelector, void*) {
253 // hide dialog
254 hide();
255 // run netgenerate
256 return myGNEApp->tryHandle(this, FXSEL(SEL_COMMAND, MID_GNE_RUNNETGENERATE), nullptr);
257}
258
259
260long
261GNENetgenerateDialog::onCmdAdvanced(FXObject*, FXSelector, void*) {
262 // hide dialog
263 hide();
264 // open netgenerate option dialog
265 return myGNEApp->tryHandle(this, FXSEL(SEL_COMMAND, MID_GNE_NETGENERATEOPTIONS), nullptr);
266}
267
268
269long
270GNENetgenerateDialog::onUpdSettingsConfigured(FXObject* sender, FXSelector, void*) {
271 auto& generateOptions = myGNEApp->getNetgenerateOptions();
272 // check conditions
273 if ((generateOptions.getBool("grid") == false) &&
274 (generateOptions.getBool("spider") == false) &&
275 (generateOptions.getBool("rand") == false)) {
276 return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
277 } else if (generateOptions.getValueString("output-file").empty()) {
278 return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
279 } else {
280 return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
281 }
282}
283
284
285long
286GNENetgenerateDialog::onCmdCancel(FXObject*, FXSelector, void*) {
287 // hide dialog
288 hide();
289 return 1;
290}
291
292
294 myGNEApp(nullptr) {
295}
296
297/****************************************************************************/
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:935
@ 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
Definition GUIAppEnum.h:951
#define GUIDesignButtonIcon
button only with icon
Definition GUIDesigns.h:97
#define GUIDesignButtonAccept
Accept Button.
Definition GUIDesigns.h:162
#define GUIDesignTextField
Definition GUIDesigns.h:65
#define GUIDesignButtonAdvanced
Advanced Button.
Definition GUIDesigns.h:174
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:405
#define GUIDesignDialogBox
Definition GUIDesigns.h:602
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition GUIDesigns.h:80
#define GUIDesignBigSizeElement
elements with big images
Definition GUIDesigns.h:44
#define GUIDesignMFXCheckableButtonBig
checkable button extended over frame
Definition GUIDesigns.h:152
#define GUIDesignButtonReset
Reset Button.
Definition GUIDesigns.h:171
#define GUIDesignLabelThickedFixed(width)
label thicked, icon before text, text centered and custom width
Definition GUIDesigns.h:258
#define GUIDesignHorizontalFrame
Horizontal frame extended over frame parent with padding and spacing.
Definition GUIDesigns.h:334
@ NETGENERATE_SPIDER
@ NETGENERATE_RANDOMGRID
@ NETGENERATE_GRID
@ NETGENERATE_RANDOM
#define TL(string)
Definition MsgHandler.h:315
The main window of Netedit.
OptionsCont & getNetgenerateOptions()
get netgenerate options container
Dialog for netgenerate tool dialog.
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
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
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