Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/tools/GNEPythonToolDialogElements.cpp
169684 views
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
/****************************************************************************/
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->getSubTopic() == "output") {
211
if (myOption->getListSeparator() != "") {
212
openMode = GNEFileDialog::OpenMode::LOAD_MULTIPLE;
213
} else {
214
openMode = GNEFileDialog::OpenMode::LOAD_SINGLE;
215
}
216
}
217
// get file
218
const auto xmlFileDialog = GNEFileDialog(myToolDialogParent->getApplicationWindow(), TL("XML file"),
219
SUMOXMLDefinitions::XMLFileExtensions.getStrings(), openMode,
220
GNEFileDialog::ConfigType::NETEDIT);
221
// check that file is valid
222
if (xmlFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
223
myFilenameTextField->setText(xmlFileDialog.getFilename().c_str(), TRUE);
224
}
225
return 1;
226
}
227
228
229
long
230
GNEPythonToolDialogElements::FileNameArgument::onCmdSetValue(FXObject*, FXSelector, void*) {
231
myOption->resetWritable();
232
if (myFilenameTextField->getText().empty()) {
233
reset();
234
} else {
235
myOption->set(myFilenameTextField->getText().text(), myFilenameTextField->getText().text(), false);
236
}
237
return 1;
238
}
239
240
241
GNEPythonToolDialogElements::FileNameArgument::FileNameArgument() {}
242
243
244
GNEPythonToolDialogElements::FileNameArgument::FileNameArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
245
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option,
246
const std::string& useCurrent) :
247
Argument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option) {
248
// check if create current button
249
if (useCurrent.size() > 0) {
250
myCurrentButton = new MFXButtonTooltip(myElementsFrame, applicationWindow->getStaticTooltipMenu(), "",
251
GUIIconSubSys::getIcon(GUIIcon::CURRENT), this, MID_GNE_USE_CURRENT, GUIDesignButtonIcon);
252
myCurrentButton->setTipText(TLF("Use current % file", useCurrent).c_str());
253
}
254
// Create Open button
255
myOpenFilenameButton = new MFXButtonTooltip(myElementsFrame, applicationWindow->getStaticTooltipMenu(), "",
256
GUIIconSubSys::getIcon(GUIIcon::OPEN), this, MID_GNE_SELECT, GUIDesignButtonIcon);
257
myOpenFilenameButton->setTipText(TLF("Select % file", useCurrent).c_str());
258
// create text field for filename
259
myFilenameTextField = new FXTextField(myElementsFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
260
// set value
261
myFilenameTextField->setText(option->getValueString().c_str());
262
}
263
264
const std::string
265
GNEPythonToolDialogElements::FileNameArgument::getValue() const {
266
return myFilenameTextField->getText().text();
267
}
268
269
// ---------------------------------------------------------------------------
270
// GNEPythonToolDialogElements::EdgeVectorArgument - methods
271
// ---------------------------------------------------------------------------
272
273
GNEPythonToolDialogElements::EdgeVectorArgument::EdgeVectorArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
274
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
275
Argument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option) {
276
myCurrentEdgesButton = new MFXButtonTooltip(myElementsFrame, applicationWindow->getStaticTooltipMenu(), "",
277
GUIIconSubSys::getIcon(GUIIcon::EDGE), this, MID_GNE_USE_CURRENT, GUIDesignButtonIcon);
278
myCurrentEdgesButton->setTipText(TL("Use current selected edges"));
279
// create text field for string
280
myEdgeVectorTextField = new FXTextField(myElementsFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
281
// set value
282
myEdgeVectorTextField->setText(option->getValueString().c_str());
283
}
284
285
286
void
287
GNEPythonToolDialogElements::EdgeVectorArgument::reset() {
288
myEdgeVectorTextField->setText(myDefaultValue.c_str());
289
myOption->set(myDefaultValue, myDefaultValue, false);
290
myOption->resetDefault();
291
}
292
293
294
long
295
GNEPythonToolDialogElements::EdgeVectorArgument::onCmdSetValue(FXObject*, FXSelector, void*) {
296
myOption->resetWritable();
297
if (myEdgeVectorTextField->getText().empty()) {
298
reset();
299
} else {
300
myOption->set(myEdgeVectorTextField->getText().text(), myEdgeVectorTextField->getText().text(), false);
301
}
302
return 1;
303
}
304
305
306
long
307
GNEPythonToolDialogElements::EdgeVectorArgument::onCmdUseCurrent(FXObject*, FXSelector, void*) {
308
// obtain list of selected edges
309
const auto selectedEdges = myToolDialogParent->getApplicationWindow()->getViewNet()->getNet()->getAttributeCarriers()->getSelectedEdges();
310
// convert list to string
311
std::string selectedEdgesStr;
312
for (const auto& edge : selectedEdges) {
313
selectedEdgesStr.append(edge->getID());
314
if (edge != selectedEdges.back()) {
315
selectedEdgesStr.append(" ");
316
}
317
}
318
myEdgeVectorTextField->setText(selectedEdgesStr.c_str(), TRUE);
319
return 1;
320
}
321
322
323
long
324
GNEPythonToolDialogElements::EdgeVectorArgument::onUpdUseCurrent(FXObject* sender, FXSelector, void*) {
325
// get view net
326
const auto viewNet = myToolDialogParent->getApplicationWindow()->getViewNet();
327
if (viewNet == nullptr) {
328
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
329
} else if (viewNet->getNet()->getAttributeCarriers()->getNumberOfSelectedEdges() == 0) {
330
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
331
} else {
332
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
333
}
334
}
335
336
337
GNEPythonToolDialogElements::EdgeVectorArgument::EdgeVectorArgument() {}
338
339
340
const std::string
341
GNEPythonToolDialogElements::EdgeVectorArgument::getValue() const {
342
return myEdgeVectorTextField->getText().text();
343
}
344
345
// ---------------------------------------------------------------------------
346
// GNEPythonToolDialogElements::NetworkArgument - methods
347
// ---------------------------------------------------------------------------
348
349
GNEPythonToolDialogElements::NetworkArgument::NetworkArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
350
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
351
FileNameArgument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option, TL("network")) {
352
}
353
354
355
long
356
GNEPythonToolDialogElements::NetworkArgument::onCmdOpenFilename(FXObject*, FXSelector, void*) {
357
// get open mode
358
GNEFileDialog::OpenMode openMode = GNEFileDialog::OpenMode::SAVE;
359
if (myOption->getSubTopic() == "output") {
360
if (myOption->getListSeparator() != "") {
361
openMode = GNEFileDialog::OpenMode::LOAD_MULTIPLE;
362
} else {
363
openMode = GNEFileDialog::OpenMode::LOAD_SINGLE;
364
}
365
}
366
// get network file
367
const auto networkFileDialog = GNEFileDialog(myToolDialogParent->getApplicationWindow(), TL("network file"),
368
SUMOXMLDefinitions::NetFileExtensions.getStrings(), openMode,
369
GNEFileDialog::ConfigType::NETEDIT);
370
// check that file is valid
371
if (networkFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
372
myFilenameTextField->setText(networkFileDialog.getFilename().c_str(), TRUE);
373
}
374
return 1;
375
}
376
377
378
long
379
GNEPythonToolDialogElements::NetworkArgument::onCmdUseCurrentNetworkFile(FXObject*, FXSelector, void*) {
380
myFilenameTextField->setText(OptionsCont::getOptions().getString("sumo-net-file").c_str(), TRUE);
381
return 1;
382
}
383
384
385
long
386
GNEPythonToolDialogElements::NetworkArgument::onUpdUseCurrentNetworkFile(FXObject* sender, FXSelector, void*) {
387
if (myToolDialogParent->getApplicationWindow()->getViewNet() == nullptr) {
388
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
389
} else if (OptionsCont::getOptions().getString("sumo-net-file").empty()) {
390
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
391
} else {
392
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
393
}
394
}
395
396
397
GNEPythonToolDialogElements::NetworkArgument::NetworkArgument() {}
398
399
// ---------------------------------------------------------------------------
400
// GNEPythonToolDialogElements::AdditionalArgument - methods
401
// ---------------------------------------------------------------------------
402
403
GNEPythonToolDialogElements::AdditionalArgument::AdditionalArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
404
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
405
FileNameArgument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option, TL("additional")) {
406
}
407
408
409
long
410
GNEPythonToolDialogElements::AdditionalArgument::onCmdOpenFilename(FXObject*, FXSelector, void*) {
411
// get open mode
412
GNEFileDialog::OpenMode openMode = GNEFileDialog::OpenMode::SAVE;
413
if (myOption->getSubTopic() == "output") {
414
if (myOption->getListSeparator() != "") {
415
openMode = GNEFileDialog::OpenMode::LOAD_MULTIPLE;
416
} else {
417
openMode = GNEFileDialog::OpenMode::LOAD_SINGLE;
418
}
419
}
420
// get additional file
421
const auto additionalFileDialog = GNEFileDialog(myToolDialogParent->getApplicationWindow(), TL("Additional elements file"),
422
SUMOXMLDefinitions::AdditionalFileExtensions.getStrings(), openMode,
423
GNEFileDialog::ConfigType::NETEDIT);
424
// check that file is valid
425
if (additionalFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
426
myFilenameTextField->setText(additionalFileDialog.getFilename().c_str(), TRUE);
427
}
428
return 1;
429
}
430
431
432
long
433
GNEPythonToolDialogElements::AdditionalArgument::onCmdUseCurrentAdditionalFile(FXObject*, FXSelector, void*) {
434
myFilenameTextField->setText(OptionsCont::getOptions().getString("additional-files").c_str(), TRUE);
435
return 1;
436
}
437
438
439
long
440
GNEPythonToolDialogElements::AdditionalArgument::onUpdUseCurrentAdditionalFile(FXObject* sender, FXSelector, void*) {
441
if (myToolDialogParent->getApplicationWindow()->getViewNet() == nullptr) {
442
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
443
} else if (OptionsCont::getOptions().getString("additional-files").empty()) {
444
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
445
} else {
446
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
447
}
448
}
449
450
451
GNEPythonToolDialogElements::AdditionalArgument::AdditionalArgument() {}
452
453
// ---------------------------------------------------------------------------
454
// GNEPythonToolDialogElements::RouteArgument - methods
455
// ---------------------------------------------------------------------------
456
457
GNEPythonToolDialogElements::RouteArgument::RouteArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
458
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
459
FileNameArgument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option, TL("route")) {
460
}
461
462
463
long
464
GNEPythonToolDialogElements::RouteArgument::onCmdOpenFilename(FXObject*, FXSelector, void*) {
465
// get open mode
466
GNEFileDialog::OpenMode openMode = GNEFileDialog::OpenMode::SAVE;
467
if (myOption->getSubTopic() == "output") {
468
if (myOption->getListSeparator() != "") {
469
openMode = GNEFileDialog::OpenMode::LOAD_MULTIPLE;
470
} else {
471
openMode = GNEFileDialog::OpenMode::LOAD_SINGLE;
472
}
473
}
474
// get route file
475
const auto routeFileDialog = GNEFileDialog(myToolDialogParent->getApplicationWindow(), TL("Route elements file"),
476
SUMOXMLDefinitions::RouteFileExtensions.getStrings(), openMode,
477
GNEFileDialog::ConfigType::NETEDIT);
478
// check that file is valid
479
if (routeFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
480
myFilenameTextField->setText(routeFileDialog.getFilename().c_str(), TRUE);
481
}
482
return 1;
483
}
484
485
486
long
487
GNEPythonToolDialogElements::RouteArgument::onCmdUseCurrentRouteFile(FXObject*, FXSelector, void*) {
488
myFilenameTextField->setText(OptionsCont::getOptions().getString("route-files").c_str(), TRUE);
489
return 1;
490
}
491
492
493
long
494
GNEPythonToolDialogElements::RouteArgument::onUpdUseCurrentRouteFile(FXObject* sender, FXSelector, void*) {
495
if (myToolDialogParent->getApplicationWindow()->getViewNet() == nullptr) {
496
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
497
} else if (OptionsCont::getOptions().getString("route-files").empty()) {
498
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
499
} else {
500
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
501
}
502
}
503
504
505
GNEPythonToolDialogElements::RouteArgument::RouteArgument() {}
506
507
// ---------------------------------------------------------------------------
508
// GNEPythonToolDialogElements::DataArgument - methods
509
// ---------------------------------------------------------------------------
510
511
GNEPythonToolDialogElements::DataArgument::DataArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
512
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
513
FileNameArgument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option, TL("data")) {
514
}
515
516
517
long
518
GNEPythonToolDialogElements::DataArgument::onCmdOpenFilename(FXObject*, FXSelector, void*) {
519
// get open mode
520
GNEFileDialog::OpenMode openMode = GNEFileDialog::OpenMode::SAVE;
521
if (myOption->getSubTopic() == "output") {
522
if (myOption->getListSeparator() != "") {
523
openMode = GNEFileDialog::OpenMode::LOAD_MULTIPLE;
524
} else {
525
openMode = GNEFileDialog::OpenMode::LOAD_SINGLE;
526
}
527
}
528
// get data file
529
const auto dataFileDialog = GNEFileDialog(myToolDialogParent->getApplicationWindow(), TL("Data elements file"),
530
SUMOXMLDefinitions::EdgeDataFileExtensions.getStrings(), openMode,
531
GNEFileDialog::ConfigType::NETEDIT);
532
// check that file is valid
533
if (dataFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
534
myFilenameTextField->setText(dataFileDialog.getFilename().c_str(), TRUE);
535
}
536
return 1;
537
}
538
539
540
long
541
GNEPythonToolDialogElements::DataArgument::onCmdUseCurrentDataFile(FXObject*, FXSelector, void*) {
542
myFilenameTextField->setText(OptionsCont::getOptions().getString("data-files").c_str(), TRUE);
543
return 1;
544
}
545
546
547
long
548
GNEPythonToolDialogElements::DataArgument::onUpdUseCurrentDataFile(FXObject* sender, FXSelector, void*) {
549
if (myToolDialogParent->getApplicationWindow()->getViewNet() == nullptr) {
550
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
551
} else if (OptionsCont::getOptions().getString("data-files").empty()) {
552
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
553
} else {
554
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
555
}
556
}
557
558
559
GNEPythonToolDialogElements::DataArgument::DataArgument() {}
560
561
// ---------------------------------------------------------------------------
562
// GNEPythonToolDialogElements::SumoConfigArgument - methods
563
// ---------------------------------------------------------------------------
564
565
GNEPythonToolDialogElements::SumoConfigArgument::SumoConfigArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
566
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
567
FileNameArgument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option, TL("sumo config")) {
568
}
569
570
571
long
572
GNEPythonToolDialogElements::SumoConfigArgument::onCmdOpenFilename(FXObject*, FXSelector, void*) {
573
// get open mode
574
GNEFileDialog::OpenMode openMode = GNEFileDialog::OpenMode::SAVE;
575
if (myOption->getSubTopic() == "output") {
576
if (myOption->getListSeparator() != "") {
577
openMode = GNEFileDialog::OpenMode::LOAD_MULTIPLE;
578
} else {
579
openMode = GNEFileDialog::OpenMode::LOAD_SINGLE;
580
}
581
}
582
// get sumoConfig file
583
const auto sumoConfigFileDialog = GNEFileDialog(myToolDialogParent->getApplicationWindow(), TL("sumo config file"),
584
SUMOXMLDefinitions::SumoConfigFileExtensions.getStrings(), openMode,
585
GNEFileDialog::ConfigType::NETEDIT);
586
// check that file is valid
587
if (sumoConfigFileDialog.getResult() == GNEDialog::Result::ACCEPT) {
588
myFilenameTextField->setText(sumoConfigFileDialog.getFilename().c_str(), TRUE);
589
}
590
return 1;
591
}
592
593
594
long
595
GNEPythonToolDialogElements::SumoConfigArgument::onCmdUseCurrentSumoConfigFile(FXObject*, FXSelector, void*) {
596
myFilenameTextField->setText(OptionsCont::getOptions().getString("sumocfg-file").c_str(), TRUE);
597
return 1;
598
}
599
600
601
long
602
GNEPythonToolDialogElements::SumoConfigArgument::onUpdUseCurrentSumoConfigFile(FXObject* sender, FXSelector, void*) {
603
if (myToolDialogParent->getApplicationWindow()->getViewNet() == nullptr) {
604
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
605
} else if (OptionsCont::getOptions().getString("sumocfg-file").empty()) {
606
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
607
} else {
608
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
609
}
610
}
611
612
613
GNEPythonToolDialogElements::SumoConfigArgument::SumoConfigArgument() {}
614
615
// ---------------------------------------------------------------------------
616
// GNEPythonToolDialogElements::EdgeArgument - methods
617
// ---------------------------------------------------------------------------
618
619
GNEPythonToolDialogElements::EdgeArgument::EdgeArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
620
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
621
Argument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option) {
622
// create text field for int
623
myEdgeTextField = new FXTextField(myElementsFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
624
// set value
625
myEdgeTextField->setText(option->getValueString().c_str());
626
}
627
628
629
void
630
GNEPythonToolDialogElements::EdgeArgument::reset() {
631
myEdgeTextField->setText(myDefaultValue.c_str());
632
myOption->set(myDefaultValue, myDefaultValue, false);
633
myOption->resetDefault();
634
}
635
636
637
long
638
GNEPythonToolDialogElements::EdgeArgument::onCmdSetValue(FXObject*, FXSelector, void*) {
639
myOption->resetWritable();
640
if (myEdgeTextField->getText().empty()) {
641
reset();
642
} else {
643
myOption->set(myEdgeTextField->getText().text(), myEdgeTextField->getText().text(), false);
644
}
645
return 1;
646
}
647
648
649
const std::string
650
GNEPythonToolDialogElements::EdgeArgument::getValue() const {
651
return myEdgeTextField->getText().text();
652
}
653
654
// ---------------------------------------------------------------------------
655
// GNEPythonToolDialogElements::StringArgument - methods
656
// ---------------------------------------------------------------------------
657
658
GNEPythonToolDialogElements::StringArgument::StringArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
659
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
660
Argument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option) {
661
// create text field for string
662
myStringTextField = new FXTextField(myElementsFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
663
// set value
664
myStringTextField->setText(option->getValueString().c_str());
665
}
666
667
668
void
669
GNEPythonToolDialogElements::StringArgument::reset() {
670
myStringTextField->setText(myDefaultValue.c_str());
671
myOption->set(myDefaultValue, myDefaultValue, false);
672
myOption->resetDefault();
673
}
674
675
676
long
677
GNEPythonToolDialogElements::StringArgument::onCmdSetValue(FXObject*, FXSelector, void*) {
678
myOption->resetWritable();
679
if (myStringTextField->getText().empty()) {
680
reset();
681
} else {
682
myOption->set(myStringTextField->getText().text(), myStringTextField->getText().text(), false);
683
}
684
return 1;
685
}
686
687
688
const std::string
689
GNEPythonToolDialogElements::StringArgument::getValue() const {
690
return myStringTextField->getText().text();
691
}
692
693
// ---------------------------------------------------------------------------
694
// GNEPythonToolDialogElements::IntArgument - methods
695
// ---------------------------------------------------------------------------
696
697
GNEPythonToolDialogElements::IntArgument::IntArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
698
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
699
Argument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option) {
700
// create text field for int
701
myIntTextField = new FXTextField(myElementsFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextFieldRestricted(TEXTFIELD_INTEGER));
702
// set value
703
myIntTextField->setText(option->getValueString().c_str());
704
}
705
706
707
void
708
GNEPythonToolDialogElements::IntArgument::reset() {
709
myIntTextField->setText(myDefaultValue.c_str());
710
if (myDefaultValue.empty()) {
711
myOption->set(INVALID_INT_STR, "", false);
712
} else {
713
myOption->set(myDefaultValue, myDefaultValue, false);
714
}
715
myOption->resetDefault();
716
}
717
718
719
long
720
GNEPythonToolDialogElements::IntArgument::onCmdSetValue(FXObject*, FXSelector, void*) {
721
myOption->resetWritable();
722
if (myIntTextField->getText().empty()) {
723
reset();
724
} else {
725
myOption->set(myIntTextField->getText().text(), myIntTextField->getText().text(), false);
726
}
727
return 1;
728
}
729
730
731
const std::string
732
GNEPythonToolDialogElements::IntArgument::getValue() const {
733
return myIntTextField->getText().text();
734
}
735
736
// ---------------------------------------------------------------------------
737
// GNEPythonToolDialogElements::FloatArgument - methods
738
// ---------------------------------------------------------------------------
739
740
GNEPythonToolDialogElements::FloatArgument::FloatArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
741
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
742
Argument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option) {
743
// create text field for float
744
myFloatTextField = new FXTextField(myElementsFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextFieldRestricted(TEXTFIELD_REAL));
745
// set value
746
myFloatTextField->setText(option->getValueString().c_str());
747
}
748
749
750
void
751
GNEPythonToolDialogElements::FloatArgument::reset() {
752
myFloatTextField->setText(myDefaultValue.c_str());
753
if (myDefaultValue.empty()) {
754
myOption->set(INVALID_DOUBLE_STR, "", false);
755
} else {
756
myOption->set(myDefaultValue, myDefaultValue, false);
757
}
758
myOption->resetDefault();
759
}
760
761
762
long
763
GNEPythonToolDialogElements::FloatArgument::onCmdSetValue(FXObject*, FXSelector, void*) {
764
myOption->resetWritable();
765
if (myFloatTextField->getText().empty()) {
766
reset();
767
} else {
768
myOption->set(myFloatTextField->getText().text(), myFloatTextField->getText().text(), false);
769
}
770
return 1;
771
}
772
773
774
const std::string
775
GNEPythonToolDialogElements::FloatArgument::getValue() const {
776
return myFloatTextField->getText().text();
777
}
778
779
// ---------------------------------------------------------------------------
780
// GNEPythonToolDialogElements::BoolArgument - methods
781
// ---------------------------------------------------------------------------
782
783
GNEPythonToolDialogElements::BoolArgument::BoolArgument(GNEPythonToolDialog* toolDialogParent, const GNEPythonTool* pythonTool,
784
GNEApplicationWindow* applicationWindow, FXVerticalFrame* argumentFrame, const std::string name, Option* option) :
785
Argument(toolDialogParent, pythonTool, applicationWindow, argumentFrame, name, option) {
786
// create check button
787
myCheckButton = new FXCheckButton(myElementsFrame, "", this, MID_GNE_SET_ATTRIBUTE, GUIDesignCheckButton);
788
// set value
789
if (option->getBool()) {
790
myCheckButton->setCheck(TRUE);
791
myCheckButton->setText(TL("true"));
792
} else {
793
myCheckButton->setCheck(FALSE);
794
myCheckButton->setText(TL("false"));
795
}
796
}
797
798
799
void
800
GNEPythonToolDialogElements::BoolArgument::reset() {
801
if (myDefaultValue == "True") {
802
myCheckButton->setCheck(TRUE);
803
myCheckButton->setText(TL("true"));
804
} else {
805
myCheckButton->setCheck(FALSE);
806
myCheckButton->setText(TL("false"));
807
}
808
myOption->set(myDefaultValue, myDefaultValue, false);
809
myOption->resetDefault();
810
}
811
812
813
long
814
GNEPythonToolDialogElements::BoolArgument::onCmdSetValue(FXObject*, FXSelector, void*) {
815
myOption->resetWritable();
816
if (myCheckButton->getCheck() == TRUE) {
817
myCheckButton->setText(TL("true"));
818
myOption->set("True", "True", false);
819
if (myDefaultValue == "True") {
820
myOption->resetDefault();
821
}
822
} else {
823
myCheckButton->setText(TL("false"));
824
myOption->set("False", "False", false);
825
if (myDefaultValue == "False") {
826
myOption->resetDefault();
827
}
828
}
829
return 1;
830
}
831
832
833
const std::string
834
GNEPythonToolDialogElements::BoolArgument::getValue() const {
835
if (myCheckButton->getCheck() == TRUE) {
836
return "True";
837
} else {
838
return "False";
839
}
840
}
841
842
/****************************************************************************/
843
844