Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/tools/GNEPythonToolDialogElements.cpp
193674 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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
/****************************************************************************/
14
/// @file GNEPythonToolDialogElements.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jun 2022
17
///
18
// Elements used in GNEPythonToolDialog
19
/****************************************************************************/
20
21
#include <netedit/GNEApplicationWindow.h>
22
#include <netedit/GNENet.h>
23
#include <netedit/tools/GNEPythonTool.h>
24
#include <utils/foxtools/MFXLabelTooltip.h>
25
#include <utils/gui/div/GUIDesigns.h>
26
27
#include "GNEPythonToolDialogElements.h"
28
#include "GNEPythonToolDialog.h"
29
30
// ===========================================================================
31
// static members
32
// ===========================================================================
33
34
const std::string GNEPythonToolDialogElements::IntArgument::INVALID_INT_STR = toString(INVALID_INT);
35
const std::string GNEPythonToolDialogElements::FloatArgument::INVALID_DOUBLE_STR = toString(INVALID_DOUBLE);
36
37
// ===========================================================================
38
// FOX callback mapping
39
// ===========================================================================
40
41
FXDEFMAP(GNEPythonToolDialogElements::Argument) ArgumentMap[] = {
42
FXMAPFUNC(SEL_COMMAND, MID_GNE_SET_ATTRIBUTE, GNEPythonToolDialogElements::Argument::onCmdSetValue),
43
FXMAPFUNC(SEL_COMMAND, MID_GNE_RESET, GNEPythonToolDialogElements::Argument::onCmdResetValue),
44
FXMAPFUNC(SEL_UPDATE, MID_GNE_RESET, GNEPythonToolDialogElements::Argument::onUpdResetValue)
45
};
46
47
FXDEFMAP(GNEPythonToolDialogElements::FileNameArgument) FileNameArgumentMap[] = {
48
FXMAPFUNC(SEL_COMMAND, MID_GNE_SELECT, GNEPythonToolDialogElements::FileNameArgument::onCmdOpenFilename)
49
};
50
51
FXDEFMAP(GNEPythonToolDialogElements::EdgeVectorArgument) EdgeVectorArgumentMap[] = {
52
FXMAPFUNC(SEL_COMMAND, MID_GNE_USE_CURRENT, GNEPythonToolDialogElements::EdgeVectorArgument::onCmdUseCurrent),
53
FXMAPFUNC(SEL_UPDATE, MID_GNE_USE_CURRENT, GNEPythonToolDialogElements::EdgeVectorArgument::onUpdUseCurrent)
54
};
55
56
FXDEFMAP(GNEPythonToolDialogElements::NetworkArgument) NetworkArgumentMap[] = {
57
FXMAPFUNC(SEL_COMMAND, MID_GNE_SELECT, GNEPythonToolDialogElements::NetworkArgument::onCmdOpenFilename),
58
FXMAPFUNC(SEL_COMMAND, MID_GNE_USE_CURRENT, GNEPythonToolDialogElements::NetworkArgument::onCmdUseCurrentNetworkFile),
59
FXMAPFUNC(SEL_UPDATE, MID_GNE_USE_CURRENT, GNEPythonToolDialogElements::NetworkArgument::onUpdUseCurrentNetworkFile)
60
};
61
62
FXDEFMAP(GNEPythonToolDialogElements::AdditionalArgument) AdditionalArgumentMap[] = {
63
FXMAPFUNC(SEL_COMMAND, MID_GNE_SELECT, GNEPythonToolDialogElements::AdditionalArgument::onCmdOpenFilename),
64
FXMAPFUNC(SEL_COMMAND, MID_GNE_USE_CURRENT, GNEPythonToolDialogElements::AdditionalArgument::onCmdUseCurrentAdditionalFile),
65
FXMAPFUNC(SEL_UPDATE, MID_GNE_USE_CURRENT, GNEPythonToolDialogElements::AdditionalArgument::onUpdUseCurrentAdditionalFile)
66
};
67
68
FXDEFMAP(GNEPythonToolDialogElements::RouteArgument) RouteArgumentMap[] = {
69
FXMAPFUNC(SEL_COMMAND, MID_GNE_SELECT, GNEPythonToolDialogElements::RouteArgument::onCmdOpenFilename),
70
FXMAPFUNC(SEL_COMMAND, MID_GNE_USE_CURRENT, GNEPythonToolDialogElements::RouteArgument::onCmdUseCurrentRouteFile),
71
FXMAPFUNC(SEL_UPDATE, MID_GNE_USE_CURRENT, GNEPythonToolDialogElements::RouteArgument::onUpdUseCurrentRouteFile)
72
};
73
74
FXDEFMAP(GNEPythonToolDialogElements::DataArgument) DataArgumentMap[] = {
75
FXMAPFUNC(SEL_COMMAND, MID_GNE_SELECT, GNEPythonToolDialogElements::DataArgument::onCmdOpenFilename),
76
FXMAPFUNC(SEL_COMMAND, MID_GNE_USE_CURRENT, GNEPythonToolDialogElements::DataArgument::onCmdUseCurrentDataFile),
77
FXMAPFUNC(SEL_UPDATE, MID_GNE_USE_CURRENT, GNEPythonToolDialogElements::DataArgument::onUpdUseCurrentDataFile)
78
};
79
80
FXDEFMAP(GNEPythonToolDialogElements::SumoConfigArgument) SumoConfigArgumentMap[] = {
81
FXMAPFUNC(SEL_COMMAND, MID_GNE_SELECT, GNEPythonToolDialogElements::SumoConfigArgument::onCmdOpenFilename),
82
FXMAPFUNC(SEL_COMMAND, MID_GNE_USE_CURRENT, GNEPythonToolDialogElements::SumoConfigArgument::onCmdUseCurrentSumoConfigFile),
83
FXMAPFUNC(SEL_UPDATE, MID_GNE_USE_CURRENT, GNEPythonToolDialogElements::SumoConfigArgument::onUpdUseCurrentSumoConfigFile)
84
};
85
86
// Object implementation
87
FXIMPLEMENT_ABSTRACT(GNEPythonToolDialogElements::Argument, FXHorizontalFrame, ArgumentMap, ARRAYNUMBER(ArgumentMap))
88
FXIMPLEMENT(GNEPythonToolDialogElements::EdgeVectorArgument, GNEPythonToolDialogElements::Argument, EdgeVectorArgumentMap, ARRAYNUMBER(EdgeVectorArgumentMap))
89
FXIMPLEMENT(GNEPythonToolDialogElements::FileNameArgument, GNEPythonToolDialogElements::Argument, FileNameArgumentMap, ARRAYNUMBER(FileNameArgumentMap))
90
FXIMPLEMENT(GNEPythonToolDialogElements::NetworkArgument, GNEPythonToolDialogElements::FileNameArgument, NetworkArgumentMap, ARRAYNUMBER(NetworkArgumentMap))
91
FXIMPLEMENT(GNEPythonToolDialogElements::AdditionalArgument, GNEPythonToolDialogElements::FileNameArgument, AdditionalArgumentMap, ARRAYNUMBER(AdditionalArgumentMap))
92
FXIMPLEMENT(GNEPythonToolDialogElements::RouteArgument, GNEPythonToolDialogElements::FileNameArgument, RouteArgumentMap, ARRAYNUMBER(RouteArgumentMap))
93
FXIMPLEMENT(GNEPythonToolDialogElements::DataArgument, GNEPythonToolDialogElements::FileNameArgument, DataArgumentMap, ARRAYNUMBER(DataArgumentMap))
94
FXIMPLEMENT(GNEPythonToolDialogElements::SumoConfigArgument, GNEPythonToolDialogElements::FileNameArgument, SumoConfigArgumentMap, ARRAYNUMBER(SumoConfigArgumentMap))
95
96
97
// ===========================================================================
98
// member method definitions
99
// ===========================================================================
100
101
// ---------------------------------------------------------------------------
102
// GNEPythonToolDialogElements::Category - methods
103
// ---------------------------------------------------------------------------
104
105
GNEPythonToolDialogElements::Category::Category(FXVerticalFrame* argumentFrame, const std::string& category) :
106
FXHorizontalFrame(argumentFrame, GUIDesignAuxiliarHorizontalFrame) {
107
// create category label
108
new FXLabel(this, category.c_str(), nullptr, GUIDesignLabel(JUSTIFY_NORMAL));
109
}
110
111
112
GNEPythonToolDialogElements::Category::~Category() {}
113
114
// ---------------------------------------------------------------------------
115
// GNEPythonToolDialogElements::Argument - methods
116
// ---------------------------------------------------------------------------
117
118
GNEPythonToolDialogElements::Argument::Argument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
119
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame,
120
const std::string& parameter, Option* option) :
121
FXHorizontalFrame(argumentFrame, GUIDesignAuxiliarHorizontalFrame),
122
myToolDialogParent(toolDialogParent),
123
myOption(option),
124
myDefaultValue(pythonTool->getDefaultValue(parameter)) {
125
// create parameter label
126
myParameterLabel = new MFXLabelTooltip(this, applicationWindow->getStaticTooltipMenu(), parameter.c_str(), nullptr, GUIDesignLabelThickedFixed(0));
127
myParameterLabel->setTipText((option->getTypeName() + ": " + option->getDescription()).c_str());
128
// set color if is required
129
if (option->isRequired()) {
130
myParameterLabel->setTextColor(GUIDesignTextColorBlue);
131
}
132
// create horizontal frame for textField
133
myElementsFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarFrame);
134
// Create reset button
135
myResetButton = GUIDesigns::buildFXButton(this, "", "", TL("Reset value"), GUIIconSubSys::getIcon(GUIIcon::RESET), this, MID_GNE_RESET, GUIDesignButtonIcon);
136
}
137
138
139
GNEPythonToolDialogElements::Argument::~Argument() {}
140
141
142
MFXLabelTooltip*
143
GNEPythonToolDialogElements::Argument::getParameterLabel() const {
144
return myParameterLabel;
145
}
146
147
148
const std::string
149
GNEPythonToolDialogElements::Argument::getArgument() const {
150
if (getValue() != myDefaultValue) {
151
return ("-" + std::string(myParameterLabel->getText().text()) + " " + getValue() + " ");
152
} else {
153
return "";
154
}
155
}
156
157
158
bool
159
GNEPythonToolDialogElements::Argument::requiredAttributeSet() const {
160
if (myOption->isRequired()) {
161
return getValue() != myDefaultValue;
162
} else {
163
return true;
164
}
165
}
166
167
168
long
169
GNEPythonToolDialogElements::Argument::onCmdResetValue(FXObject*, FXSelector, void*) {
170
// just reset value
171
reset();
172
return 1;
173
}
174
175
176
long
177
GNEPythonToolDialogElements::Argument::onUpdResetValue(FXObject*, FXSelector, void*) {
178
if (getValue() == myDefaultValue) {
179
return myResetButton->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
180
} else {
181
return myResetButton->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
182
}
183
}
184
185
186
GNEPythonToolDialogElements::Argument::Argument() {}
187
188
// ---------------------------------------------------------------------------
189
// GNEPythonToolDialogElements::FileNameArgument - methods
190
// ---------------------------------------------------------------------------
191
192
GNEPythonToolDialogElements::FileNameArgument::FileNameArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
193
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
194
FileNameArgument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option, "") {
195
}
196
197
198
void
199
GNEPythonToolDialogElements::FileNameArgument::reset() {
200
myFilenameTextField->setText(myDefaultValue.c_str());
201
myOption->set(myDefaultValue, myDefaultValue, false);
202
myOption->resetDefault();
203
}
204
205
206
long
207
GNEPythonToolDialogElements::FileNameArgument::onCmdOpenFilename(FXObject*, FXSelector, void*) {
208
// get open mode
209
GNEFileDialog::OpenMode openMode = GNEFileDialog::OpenMode::SAVE;
210
if (myOption->getListSeparator() != "") {
211
openMode = GNEFileDialog::OpenMode::LOAD_MULTIPLE;
212
}
213
// get file
214
const GNEFileDialog xmlFileDialog(myToolDialogParent->getApplicationWindow(), myToolDialogParent,
215
TL("XML file"),
216
SUMOXMLDefinitions::XMLFileExtensions.getStrings(), openMode,
217
GNEFileDialog::ConfigType::NETEDIT);
218
// check that file is valid
219
if (xmlFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
220
myFilenameTextField->setText(xmlFileDialog.getFilename().c_str(), TRUE);
221
}
222
return 1;
223
}
224
225
226
long
227
GNEPythonToolDialogElements::FileNameArgument::onCmdSetValue(FXObject*, FXSelector, void*) {
228
myOption->resetWritable();
229
if (myFilenameTextField->getText().empty()) {
230
reset();
231
} else {
232
myOption->set(myFilenameTextField->getText().text(), myFilenameTextField->getText().text(), false);
233
}
234
return 1;
235
}
236
237
238
GNEPythonToolDialogElements::FileNameArgument::FileNameArgument() {}
239
240
241
GNEPythonToolDialogElements::FileNameArgument::FileNameArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
242
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option,
243
const std::string& useCurrent) :
244
Argument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option) {
245
// check if create current button
246
if (useCurrent.size() > 0) {
247
myCurrentButton = new MFXButtonTooltip(myElementsFrame, applicationWindow->getStaticTooltipMenu(), "",
248
GUIIconSubSys::getIcon(GUIIcon::CURRENT), this, MID_GNE_USE_CURRENT, GUIDesignButtonIcon);
249
myCurrentButton->setTipText(TLF("Use current % file", useCurrent).c_str());
250
}
251
// Create Open button
252
myOpenFilenameButton = new MFXButtonTooltip(myElementsFrame, applicationWindow->getStaticTooltipMenu(), "",
253
GUIIconSubSys::getIcon(GUIIcon::OPEN), this, MID_GNE_SELECT, GUIDesignButtonIcon);
254
myOpenFilenameButton->setTipText(TLF("Select % file", useCurrent).c_str());
255
// create text field for filename
256
myFilenameTextField = new FXTextField(myElementsFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
257
// set value
258
myFilenameTextField->setText(option->getValueString().c_str());
259
}
260
261
const std::string
262
GNEPythonToolDialogElements::FileNameArgument::getValue() const {
263
return myFilenameTextField->getText().text();
264
}
265
266
// ---------------------------------------------------------------------------
267
// GNEPythonToolDialogElements::EdgeVectorArgument - methods
268
// ---------------------------------------------------------------------------
269
270
GNEPythonToolDialogElements::EdgeVectorArgument::EdgeVectorArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
271
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
272
Argument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option) {
273
myCurrentEdgesButton = new MFXButtonTooltip(myElementsFrame, applicationWindow->getStaticTooltipMenu(), "",
274
GUIIconSubSys::getIcon(GUIIcon::EDGE), this, MID_GNE_USE_CURRENT, GUIDesignButtonIcon);
275
myCurrentEdgesButton->setTipText(TL("Use current selected edges"));
276
// create text field for string
277
myEdgeVectorTextField = new FXTextField(myElementsFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
278
// set value
279
myEdgeVectorTextField->setText(option->getValueString().c_str());
280
}
281
282
283
void
284
GNEPythonToolDialogElements::EdgeVectorArgument::reset() {
285
myEdgeVectorTextField->setText(myDefaultValue.c_str());
286
myOption->set(myDefaultValue, myDefaultValue, false);
287
myOption->resetDefault();
288
}
289
290
291
long
292
GNEPythonToolDialogElements::EdgeVectorArgument::onCmdSetValue(FXObject*, FXSelector, void*) {
293
myOption->resetWritable();
294
if (myEdgeVectorTextField->getText().empty()) {
295
reset();
296
} else {
297
myOption->set(myEdgeVectorTextField->getText().text(), myEdgeVectorTextField->getText().text(), false);
298
}
299
return 1;
300
}
301
302
303
long
304
GNEPythonToolDialogElements::EdgeVectorArgument::onCmdUseCurrent(FXObject*, FXSelector, void*) {
305
// obtain list of selected edges
306
const auto selectedEdges = myToolDialogParent->getApplicationWindow()->getViewNet()->getNet()->getAttributeCarriers()->getSelectedEdges();
307
// convert list to string
308
std::string selectedEdgesStr;
309
for (const auto& edge : selectedEdges) {
310
selectedEdgesStr.append(edge->getID());
311
if (edge != selectedEdges.back()) {
312
selectedEdgesStr.append(" ");
313
}
314
}
315
myEdgeVectorTextField->setText(selectedEdgesStr.c_str(), TRUE);
316
return 1;
317
}
318
319
320
long
321
GNEPythonToolDialogElements::EdgeVectorArgument::onUpdUseCurrent(FXObject* sender, FXSelector, void*) {
322
// get view net
323
const auto viewNet = myToolDialogParent->getApplicationWindow()->getViewNet();
324
if (viewNet == nullptr) {
325
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
326
} else if (viewNet->getNet()->getAttributeCarriers()->getNumberOfSelectedEdges() == 0) {
327
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
328
} else {
329
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
330
}
331
}
332
333
334
GNEPythonToolDialogElements::EdgeVectorArgument::EdgeVectorArgument() {}
335
336
337
const std::string
338
GNEPythonToolDialogElements::EdgeVectorArgument::getValue() const {
339
return myEdgeVectorTextField->getText().text();
340
}
341
342
// ---------------------------------------------------------------------------
343
// GNEPythonToolDialogElements::NetworkArgument - methods
344
// ---------------------------------------------------------------------------
345
346
GNEPythonToolDialogElements::NetworkArgument::NetworkArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
347
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
348
FileNameArgument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option, TL("network")) {
349
}
350
351
352
long
353
GNEPythonToolDialogElements::NetworkArgument::onCmdOpenFilename(FXObject*, FXSelector, void*) {
354
// get open mode
355
GNEFileDialog::OpenMode openMode = GNEFileDialog::OpenMode::SAVE;
356
if (myOption->getListSeparator() != "") {
357
openMode = GNEFileDialog::OpenMode::LOAD_MULTIPLE;
358
}
359
// get network file
360
const GNEFileDialog networkFileDialog(myToolDialogParent->getApplicationWindow(), myToolDialogParent,
361
TL("network file"),
362
SUMOXMLDefinitions::NetFileExtensions.getStrings(), openMode,
363
GNEFileDialog::ConfigType::NETEDIT);
364
// check that file is valid
365
if (networkFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
366
myFilenameTextField->setText(networkFileDialog.getFilename().c_str(), TRUE);
367
}
368
return 1;
369
}
370
371
372
long
373
GNEPythonToolDialogElements::NetworkArgument::onCmdUseCurrentNetworkFile(FXObject*, FXSelector, void*) {
374
myFilenameTextField->setText(OptionsCont::getOptions().getString("sumo-net-file").c_str(), TRUE);
375
return 1;
376
}
377
378
379
long
380
GNEPythonToolDialogElements::NetworkArgument::onUpdUseCurrentNetworkFile(FXObject* sender, FXSelector, void*) {
381
if (myToolDialogParent->getApplicationWindow()->getViewNet() == nullptr) {
382
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
383
} else if (OptionsCont::getOptions().getString("sumo-net-file").empty()) {
384
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
385
} else {
386
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
387
}
388
}
389
390
391
GNEPythonToolDialogElements::NetworkArgument::NetworkArgument() {}
392
393
// ---------------------------------------------------------------------------
394
// GNEPythonToolDialogElements::AdditionalArgument - methods
395
// ---------------------------------------------------------------------------
396
397
GNEPythonToolDialogElements::AdditionalArgument::AdditionalArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
398
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
399
FileNameArgument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option, TL("additional")) {
400
}
401
402
403
long
404
GNEPythonToolDialogElements::AdditionalArgument::onCmdOpenFilename(FXObject*, FXSelector, void*) {
405
// get open mode
406
GNEFileDialog::OpenMode openMode = GNEFileDialog::OpenMode::SAVE;
407
if (myOption->getListSeparator() != "") {
408
openMode = GNEFileDialog::OpenMode::LOAD_MULTIPLE;
409
}
410
// get additional file
411
const GNEFileDialog additionalFileDialog(myToolDialogParent->getApplicationWindow(), myToolDialogParent,
412
TL("Additional elements file"),
413
SUMOXMLDefinitions::AdditionalFileExtensions.getStrings(), openMode,
414
GNEFileDialog::ConfigType::NETEDIT);
415
// check that file is valid
416
if (additionalFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
417
myFilenameTextField->setText(additionalFileDialog.getFilename().c_str(), TRUE);
418
}
419
return 1;
420
}
421
422
423
long
424
GNEPythonToolDialogElements::AdditionalArgument::onCmdUseCurrentAdditionalFile(FXObject*, FXSelector, void*) {
425
myFilenameTextField->setText(OptionsCont::getOptions().getString("additional-files").c_str(), TRUE);
426
return 1;
427
}
428
429
430
long
431
GNEPythonToolDialogElements::AdditionalArgument::onUpdUseCurrentAdditionalFile(FXObject* sender, FXSelector, void*) {
432
if (myToolDialogParent->getApplicationWindow()->getViewNet() == nullptr) {
433
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
434
} else if (OptionsCont::getOptions().getString("additional-files").empty()) {
435
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
436
} else {
437
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
438
}
439
}
440
441
442
GNEPythonToolDialogElements::AdditionalArgument::AdditionalArgument() {}
443
444
// ---------------------------------------------------------------------------
445
// GNEPythonToolDialogElements::RouteArgument - methods
446
// ---------------------------------------------------------------------------
447
448
GNEPythonToolDialogElements::RouteArgument::RouteArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
449
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
450
FileNameArgument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option, TL("route")) {
451
}
452
453
454
long
455
GNEPythonToolDialogElements::RouteArgument::onCmdOpenFilename(FXObject*, FXSelector, void*) {
456
// get open mode
457
GNEFileDialog::OpenMode openMode = GNEFileDialog::OpenMode::SAVE;
458
if (myOption->getListSeparator() != "") {
459
openMode = GNEFileDialog::OpenMode::LOAD_MULTIPLE;
460
}
461
// get route file
462
const GNEFileDialog routeFileDialog(myToolDialogParent->getApplicationWindow(), myToolDialogParent,
463
TL("Route elements file"),
464
SUMOXMLDefinitions::RouteFileExtensions.getStrings(), openMode,
465
GNEFileDialog::ConfigType::NETEDIT);
466
// check that file is valid
467
if (routeFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
468
myFilenameTextField->setText(routeFileDialog.getFilename().c_str(), TRUE);
469
}
470
return 1;
471
}
472
473
474
long
475
GNEPythonToolDialogElements::RouteArgument::onCmdUseCurrentRouteFile(FXObject*, FXSelector, void*) {
476
myFilenameTextField->setText(OptionsCont::getOptions().getString("route-files").c_str(), TRUE);
477
return 1;
478
}
479
480
481
long
482
GNEPythonToolDialogElements::RouteArgument::onUpdUseCurrentRouteFile(FXObject* sender, FXSelector, void*) {
483
if (myToolDialogParent->getApplicationWindow()->getViewNet() == nullptr) {
484
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
485
} else if (OptionsCont::getOptions().getString("route-files").empty()) {
486
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
487
} else {
488
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
489
}
490
}
491
492
493
GNEPythonToolDialogElements::RouteArgument::RouteArgument() {}
494
495
// ---------------------------------------------------------------------------
496
// GNEPythonToolDialogElements::DataArgument - methods
497
// ---------------------------------------------------------------------------
498
499
GNEPythonToolDialogElements::DataArgument::DataArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
500
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
501
FileNameArgument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option, TL("data")) {
502
}
503
504
505
long
506
GNEPythonToolDialogElements::DataArgument::onCmdOpenFilename(FXObject*, FXSelector, void*) {
507
// get open mode
508
GNEFileDialog::OpenMode openMode = GNEFileDialog::OpenMode::SAVE;
509
if (myOption->getListSeparator() != "") {
510
openMode = GNEFileDialog::OpenMode::LOAD_MULTIPLE;
511
}
512
// get data file
513
const GNEFileDialog dataFileDialog(myToolDialogParent->getApplicationWindow(), myToolDialogParent,
514
TL("Data elements file"),
515
SUMOXMLDefinitions::EdgeDataFileExtensions.getStrings(), openMode,
516
GNEFileDialog::ConfigType::NETEDIT);
517
// check that file is valid
518
if (dataFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
519
myFilenameTextField->setText(dataFileDialog.getFilename().c_str(), TRUE);
520
}
521
return 1;
522
}
523
524
525
long
526
GNEPythonToolDialogElements::DataArgument::onCmdUseCurrentDataFile(FXObject*, FXSelector, void*) {
527
myFilenameTextField->setText(OptionsCont::getOptions().getString("data-files").c_str(), TRUE);
528
return 1;
529
}
530
531
532
long
533
GNEPythonToolDialogElements::DataArgument::onUpdUseCurrentDataFile(FXObject* sender, FXSelector, void*) {
534
if (myToolDialogParent->getApplicationWindow()->getViewNet() == nullptr) {
535
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
536
} else if (OptionsCont::getOptions().getString("data-files").empty()) {
537
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
538
} else {
539
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
540
}
541
}
542
543
544
GNEPythonToolDialogElements::DataArgument::DataArgument() {}
545
546
// ---------------------------------------------------------------------------
547
// GNEPythonToolDialogElements::SumoConfigArgument - methods
548
// ---------------------------------------------------------------------------
549
550
GNEPythonToolDialogElements::SumoConfigArgument::SumoConfigArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
551
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
552
FileNameArgument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option, TL("sumo config")) {
553
}
554
555
556
long
557
GNEPythonToolDialogElements::SumoConfigArgument::onCmdOpenFilename(FXObject*, FXSelector, void*) {
558
// get open mode
559
GNEFileDialog::OpenMode openMode = GNEFileDialog::OpenMode::SAVE;
560
if (myOption->getListSeparator() != "") {
561
openMode = GNEFileDialog::OpenMode::LOAD_MULTIPLE;
562
}
563
// get sumoConfig file
564
const GNEFileDialog sumoConfigFileDialog(myToolDialogParent->getApplicationWindow(), myToolDialogParent,
565
TL("sumo config file"),
566
SUMOXMLDefinitions::SumoConfigFileExtensions.getStrings(), openMode,
567
GNEFileDialog::ConfigType::NETEDIT);
568
// check that file is valid
569
if (sumoConfigFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
570
myFilenameTextField->setText(sumoConfigFileDialog.getFilename().c_str(), TRUE);
571
}
572
return 1;
573
}
574
575
576
long
577
GNEPythonToolDialogElements::SumoConfigArgument::onCmdUseCurrentSumoConfigFile(FXObject*, FXSelector, void*) {
578
myFilenameTextField->setText(OptionsCont::getOptions().getString("sumocfg-file").c_str(), TRUE);
579
return 1;
580
}
581
582
583
long
584
GNEPythonToolDialogElements::SumoConfigArgument::onUpdUseCurrentSumoConfigFile(FXObject* sender, FXSelector, void*) {
585
if (myToolDialogParent->getApplicationWindow()->getViewNet() == nullptr) {
586
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
587
} else if (OptionsCont::getOptions().getString("sumocfg-file").empty()) {
588
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
589
} else {
590
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
591
}
592
}
593
594
595
GNEPythonToolDialogElements::SumoConfigArgument::SumoConfigArgument() {}
596
597
// ---------------------------------------------------------------------------
598
// GNEPythonToolDialogElements::EdgeArgument - methods
599
// ---------------------------------------------------------------------------
600
601
GNEPythonToolDialogElements::EdgeArgument::EdgeArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
602
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
603
Argument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option) {
604
// create text field for int
605
myEdgeTextField = new FXTextField(myElementsFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
606
// set value
607
myEdgeTextField->setText(option->getValueString().c_str());
608
}
609
610
611
void
612
GNEPythonToolDialogElements::EdgeArgument::reset() {
613
myEdgeTextField->setText(myDefaultValue.c_str());
614
myOption->set(myDefaultValue, myDefaultValue, false);
615
myOption->resetDefault();
616
}
617
618
619
long
620
GNEPythonToolDialogElements::EdgeArgument::onCmdSetValue(FXObject*, FXSelector, void*) {
621
myOption->resetWritable();
622
if (myEdgeTextField->getText().empty()) {
623
reset();
624
} else {
625
myOption->set(myEdgeTextField->getText().text(), myEdgeTextField->getText().text(), false);
626
}
627
return 1;
628
}
629
630
631
const std::string
632
GNEPythonToolDialogElements::EdgeArgument::getValue() const {
633
return myEdgeTextField->getText().text();
634
}
635
636
// ---------------------------------------------------------------------------
637
// GNEPythonToolDialogElements::StringArgument - methods
638
// ---------------------------------------------------------------------------
639
640
GNEPythonToolDialogElements::StringArgument::StringArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
641
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
642
Argument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option) {
643
// create text field for string
644
myStringTextField = new FXTextField(myElementsFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
645
// set value
646
myStringTextField->setText(option->getValueString().c_str());
647
}
648
649
650
void
651
GNEPythonToolDialogElements::StringArgument::reset() {
652
myStringTextField->setText(myDefaultValue.c_str());
653
myOption->set(myDefaultValue, myDefaultValue, false);
654
myOption->resetDefault();
655
}
656
657
658
long
659
GNEPythonToolDialogElements::StringArgument::onCmdSetValue(FXObject*, FXSelector, void*) {
660
myOption->resetWritable();
661
if (myStringTextField->getText().empty()) {
662
reset();
663
} else {
664
myOption->set(myStringTextField->getText().text(), myStringTextField->getText().text(), false);
665
}
666
return 1;
667
}
668
669
670
const std::string
671
GNEPythonToolDialogElements::StringArgument::getValue() const {
672
return myStringTextField->getText().text();
673
}
674
675
// ---------------------------------------------------------------------------
676
// GNEPythonToolDialogElements::IntArgument - methods
677
// ---------------------------------------------------------------------------
678
679
GNEPythonToolDialogElements::IntArgument::IntArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
680
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
681
Argument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option) {
682
// create text field for int
683
myIntTextField = new FXTextField(myElementsFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextFieldRestricted(TEXTFIELD_INTEGER));
684
// set value
685
myIntTextField->setText(option->getValueString().c_str());
686
}
687
688
689
void
690
GNEPythonToolDialogElements::IntArgument::reset() {
691
myIntTextField->setText(myDefaultValue.c_str());
692
if (myDefaultValue.empty()) {
693
myOption->set(INVALID_INT_STR, "", false);
694
} else {
695
myOption->set(myDefaultValue, myDefaultValue, false);
696
}
697
myOption->resetDefault();
698
}
699
700
701
long
702
GNEPythonToolDialogElements::IntArgument::onCmdSetValue(FXObject*, FXSelector, void*) {
703
myOption->resetWritable();
704
if (myIntTextField->getText().empty()) {
705
reset();
706
} else {
707
myOption->set(myIntTextField->getText().text(), myIntTextField->getText().text(), false);
708
}
709
return 1;
710
}
711
712
713
const std::string
714
GNEPythonToolDialogElements::IntArgument::getValue() const {
715
return myIntTextField->getText().text();
716
}
717
718
// ---------------------------------------------------------------------------
719
// GNEPythonToolDialogElements::FloatArgument - methods
720
// ---------------------------------------------------------------------------
721
722
GNEPythonToolDialogElements::FloatArgument::FloatArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
723
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
724
Argument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option) {
725
// create text field for float
726
myFloatTextField = new FXTextField(myElementsFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextFieldRestricted(TEXTFIELD_REAL));
727
// set value
728
myFloatTextField->setText(option->getValueString().c_str());
729
}
730
731
732
void
733
GNEPythonToolDialogElements::FloatArgument::reset() {
734
myFloatTextField->setText(myDefaultValue.c_str());
735
if (myDefaultValue.empty()) {
736
myOption->set(INVALID_DOUBLE_STR, "", false);
737
} else {
738
myOption->set(myDefaultValue, myDefaultValue, false);
739
}
740
myOption->resetDefault();
741
}
742
743
744
long
745
GNEPythonToolDialogElements::FloatArgument::onCmdSetValue(FXObject*, FXSelector, void*) {
746
myOption->resetWritable();
747
if (myFloatTextField->getText().empty()) {
748
reset();
749
} else {
750
myOption->set(myFloatTextField->getText().text(), myFloatTextField->getText().text(), false);
751
}
752
return 1;
753
}
754
755
756
const std::string
757
GNEPythonToolDialogElements::FloatArgument::getValue() const {
758
return myFloatTextField->getText().text();
759
}
760
761
// ---------------------------------------------------------------------------
762
// GNEPythonToolDialogElements::BoolArgument - methods
763
// ---------------------------------------------------------------------------
764
765
GNEPythonToolDialogElements::BoolArgument::BoolArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
766
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
767
Argument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option) {
768
// create check button
769
myCheckButton = new FXCheckButton(myElementsFrame, "", this, MID_GNE_SET_ATTRIBUTE, GUIDesignCheckButton);
770
// set value
771
if (option->getBool()) {
772
myCheckButton->setCheck(TRUE);
773
myCheckButton->setText(TL("true"));
774
} else {
775
myCheckButton->setCheck(FALSE);
776
myCheckButton->setText(TL("false"));
777
}
778
}
779
780
781
void
782
GNEPythonToolDialogElements::BoolArgument::reset() {
783
if (myDefaultValue == "True") {
784
myCheckButton->setCheck(TRUE);
785
myCheckButton->setText(TL("true"));
786
} else {
787
myCheckButton->setCheck(FALSE);
788
myCheckButton->setText(TL("false"));
789
}
790
myOption->set(myDefaultValue, myDefaultValue, false);
791
myOption->resetDefault();
792
}
793
794
795
long
796
GNEPythonToolDialogElements::BoolArgument::onCmdSetValue(FXObject*, FXSelector, void*) {
797
myOption->resetWritable();
798
if (myCheckButton->getCheck() == TRUE) {
799
myCheckButton->setText(TL("true"));
800
myOption->set("True", "True", false);
801
if (myDefaultValue == "True") {
802
myOption->resetDefault();
803
}
804
} else {
805
myCheckButton->setText(TL("false"));
806
myOption->set("False", "False", false);
807
if (myDefaultValue == "False") {
808
myOption->resetDefault();
809
}
810
}
811
return 1;
812
}
813
814
815
const std::string
816
GNEPythonToolDialogElements::BoolArgument::getValue() const {
817
if (myCheckButton->getCheck() == TRUE) {
818
return "True";
819
} else {
820
return "False";
821
}
822
}
823
824
/****************************************************************************/
825
826