Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNESingleParametersDialog.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 edit parameters
19/****************************************************************************/
20
24#include <netedit/GNENet.h>
25#include <netedit/GNEUndoList.h>
26#include <netedit/GNEViewNet.h>
29#include <utils/xml/XMLSubSys.h>
30
32
33
34// ===========================================================================
35// FOX callback mapping
36// ===========================================================================
37
38FXDEFMAP(GNESingleParametersDialog) GNESingleParametersDialogMap[] = {
42 FXMAPFUNC(SEL_CHORE, FXDialogBox::ID_CANCEL, GNESingleParametersDialog::onCmdCancel),
43 FXMAPFUNC(SEL_TIMEOUT, FXDialogBox::ID_CANCEL, GNESingleParametersDialog::onCmdCancel),
44 FXMAPFUNC(SEL_COMMAND, FXDialogBox::ID_CANCEL, GNESingleParametersDialog::onCmdCancel),
45 FXMAPFUNC(SEL_CLOSE, 0, GNESingleParametersDialog::onCmdCancel),
46};
47
53
61
62// Object implementation
63FXIMPLEMENT(GNESingleParametersDialog, FXDialogBox, GNESingleParametersDialogMap, ARRAYNUMBER(GNESingleParametersDialogMap))
64FXIMPLEMENT(GNESingleParametersDialog::ParametersValues, FXGroupBox, ParametersValuesMap, ARRAYNUMBER(ParametersValuesMap))
65FXIMPLEMENT(GNESingleParametersDialog::ParametersOperations, FXGroupBox, ParametersOperationsMap, ARRAYNUMBER(ParametersOperationsMap))
66
67// ===========================================================================
68// member method definitions
69// ===========================================================================
70
71// ---------------------------------------------------------------------------
72// GNESingleParametersDialog::ParametersValues - methods
73// ---------------------------------------------------------------------------
74
75GNESingleParametersDialog::ParametersValues::ParametersValues(FXHorizontalFrame* frame, const std::string& name) :
76 FXGroupBox(frame, name.c_str(), GUIDesignGroupBoxFrameFill) {
77 // create labels for keys and values
78 FXHorizontalFrame* horizontalFrameLabels = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
79 myKeyLabel = new FXLabel(horizontalFrameLabels, "key", nullptr, GUIDesignLabelThickedFixed(100));
80 new FXLabel(horizontalFrameLabels, "value", nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
81 // create scroll windows
82 FXScrollWindow* scrollWindow = new FXScrollWindow(this, LAYOUT_FILL);
83 // create vertical frame for rows
84 myVerticalFrameRow = new FXVerticalFrame(scrollWindow, GUIDesignAuxiliarFrame);
85}
86
87
89
90
91void
92GNESingleParametersDialog::ParametersValues::setParameters(const std::vector<std::pair<std::string, std::string> >& newParameters) {
93 // clear rows
94 clearParameters();
95 // iterate over parameteres
96 for (const auto& newParameter : newParameters) {
97 addParameter(newParameter);
98 }
99}
100
101
102void
103GNESingleParametersDialog::ParametersValues::addParameter(std::pair<std::string, std::string> newParameter) {
104 // enable last row
105 myParameterRows.back()->enableRow(newParameter.first, newParameter.second);
106 // add row
107 myParameterRows.push_back(new ParameterRow(this, myVerticalFrameRow));
108 // enable add button in the last row
109 myParameterRows.back()->toggleAddButton();
110}
111
112
113void
115 // iterate over all rows
116 for (const auto& parameterRow : myParameterRows) {
117 delete parameterRow;
118 }
119 //clear myParameterRows;
120 myParameterRows.clear();
121 // add row
122 myParameterRows.push_back(new ParameterRow(this, myVerticalFrameRow));
123 // enable add button in the last row
124 myParameterRows.back()->toggleAddButton();
125}
126
127
128const std::vector<GNESingleParametersDialog::ParametersValues::ParameterRow*>
130 return myParameterRows;
131}
132
133
134bool
136 // just interate over myParameterRows and compare key
137 for (const auto& row : myParameterRows) {
138 if (row->keyField->getText().text() == key) {
139 return true;
140 }
141 }
142 return false;
143}
144
145
146long
147GNESingleParametersDialog::ParametersValues::onPaint(FXObject* o, FXSelector f, void* p) {
148 // size of key label has to be updated in every interation
149 if (myParameterRows.size() > 0) {
150 myKeyLabel->setWidth(myParameterRows.front()->keyField->getWidth());
151 }
152 return FXGroupBox::onPaint(o, f, p);
153}
154
155
156long
158 // find what value was changed
159 for (int i = 0; i < (int)myParameterRows.size(); i++) {
160 if (myParameterRows.at(i)->keyField == obj) {
161 // change color of text field depending if key is valid or empty
162 if (myParameterRows.at(i)->keyField->getText().empty() || SUMOXMLDefinitions::isValidParameterKey(myParameterRows.at(i)->keyField->getText().text())) {
163 myParameterRows.at(i)->keyField->setTextColor(FXRGB(0, 0, 0));
164 } else {
165 myParameterRows.at(i)->keyField->setTextColor(FXRGB(255, 0, 0));
166 myParameterRows.at(i)->keyField->killFocus();
167 }
168 }
169 }
170 return 1;
171}
172
173
174long
176 // first check if add button was pressed
177 if (myParameterRows.back()->button == obj) {
178 // create new parameter
179 addParameter(std::make_pair("", ""));
180 return 1;
181 } else {
182 // in other case, button press was a "remove button". Find id and remove the Parameter
183 for (int i = 0; i < (int)myParameterRows.size(); i++) {
184 if (myParameterRows.at(i)->button == obj) {
185 // delete row
186 delete myParameterRows.at(i);
187 // just remove row
188 myParameterRows.erase(myParameterRows.begin() + i);
189 return 1;
190 }
191 }
192 }
193 // Nothing to do
194 return 1;
195}
196
197
199 horizontalFrame = new FXHorizontalFrame(verticalFrameParent, GUIDesignAuxiliarHorizontalFrame);
200 keyField = new FXTextField(horizontalFrame, GUIDesignTextFieldNCol, ParametersValues, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
201 valueField = new FXTextField(horizontalFrame, GUIDesignTextFieldNCol, ParametersValues, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
203 // only create elements if vertical frame was previously created
204 if (verticalFrameParent->id()) {
205 horizontalFrame->create();
206 }
207 // by defaults rows are disabled
208 disableRow();
209}
210
211
213 // simply delete horizontalFrame (rest of elements will be automatic deleted due they are children of horizontal frame)
214 delete horizontalFrame;
215}
216
217
218void
220 // hide all
221 keyField->setText("");
222 keyField->disable();
223 valueField->setText("");
224 valueField->disable();
225 button->disable();
226 button->setIcon(GUIIconSubSys::getIcon(GUIIcon::REMOVE));
227}
228
229
230void
231GNESingleParametersDialog::ParametersValues::ParameterRow::enableRow(const std::string& parameter, const std::string& value) const {
232 // restore color and enable key field
233 keyField->setText(parameter.c_str());
234 if (parameter.empty() || SUMOXMLDefinitions::isValidParameterKey(parameter)) {
235 keyField->setTextColor(FXRGB(0, 0, 0));
236 } else {
237 keyField->setTextColor(FXRGB(255, 0, 0));
238 }
239 keyField->enable();
240 // restore color and enable value field
241 valueField->setText(value.c_str());
242 valueField->enable();
243 // enable button and set icon remove
244 button->enable();
245 button->setIcon(GUIIconSubSys::getIcon(GUIIcon::REMOVE));
246}
247
248
249void
251 // clear and disable parameter and value fields
252 keyField->setText("");
253 keyField->disable();
254 valueField->setText("");
255 valueField->disable();
256 // enable remove button and set "add" icon and focus
257 button->enable();
258 button->setIcon(GUIIconSubSys::getIcon(GUIIcon::ADD));
259 button->setFocus();
260}
261
262
263bool
267
268
269void
271 keyField->setText(other.keyField->getText());
272 valueField->setText(other.valueField->getText());
273}
274
275// ---------------------------------------------------------------------------
276// GNESingleParametersDialog::ParametersOperations - methods
277// ---------------------------------------------------------------------------
278
289
290
292
293
294long
296 // get the Additional file name
297 FXFileDialog opendialog(this, TL("Open Parameter Template"));
299 opendialog.setSelectMode(SELECTFILE_EXISTING);
300 opendialog.setPatternList(" Parameter Template files (*.xml,*.xml.gz)\nAll files (*)");
301 if (gCurrentFolder.length() != 0) {
302 opendialog.setDirectory(gCurrentFolder);
303 }
304 if (opendialog.execute()) {
305 gCurrentFolder = opendialog.getDirectory();
306 std::string file = opendialog.getFilename().text();
307 // save current number of parameters
308 const int numberOfParametersbeforeLoad = (int)myParameterDialogParent->myParametersValues->getParameterRows().size();
309 // Create additional handler and run parser
310 GNEParameterHandler handler(this, file);
311 if (!XMLSubSys::runParser(handler, file, false)) {
312 WRITE_MESSAGEF(TL("Loading of Parameters From % failed."), file);
313 }
314 // show loaded attributes
315 WRITE_MESSAGEF(TL("Loaded % Parameters."), toString((int)myParameterDialogParent->myParametersValues->getParameterRows().size() - numberOfParametersbeforeLoad));
316 }
317 return 1;
318}
319
320
321long
323 // obtain file to save parameters
324 FXString file = MFXUtils::getFilename2Write(this,
325 TL("Save Parameter Template file"), ".xml",
328 if (file == "") {
329 // None parameter file was selected, then stop function
330 return 1;
331 } else {
332 // open device
333 OutputDevice& device = OutputDevice::getDevice(file.text());
334 // write header
335 device.writeXMLHeader("Parameter", "parameter_file.xsd");
336 // iterate over all parameters and save it in the filename
337 for (const auto& row : myParameterDialogParent->myParametersValues->getParameterRows()) {
338 // write all except last
339 if (row != myParameterDialogParent->myParametersValues->getParameterRows().back()) {
340 // open tag
341 device.openTag(SUMO_TAG_PARAM);
342 // write key
343 device.writeAttr(SUMO_ATTR_KEY, row->keyField->getText().text());
344 // write value
345 device.writeAttr(SUMO_ATTR_VALUE, row->valueField->getText().text());
346 // close tag
347 device.closeTag();
348 }
349 }
350 // close device
351 device.close();
352 }
353 return 1;
354}
355
356
357long
359 // simply clear parameters from ParametersValues
360 myParameterDialogParent->myParametersValues->clearParameters();
361 return 1;
362}
363
364
365long
367 // declare two containers for parameters
368 std::vector<std::pair<std::string, std::string> > nonEmptyKeyValues;
369 std::vector<std::string> emptyKeyValues;
370 // first extract empty values
371 for (const auto& parameterRow : myParameterDialogParent->myParametersValues->getParameterRows()) {
372 // check if key is empty
373 if (!parameterRow->keyField->getText().empty()) {
374 nonEmptyKeyValues.push_back(std::make_pair(parameterRow->keyField->getText().text(), parameterRow->valueField->getText().text()));
375 } else if (!parameterRow->valueField->getText().empty()) {
376 emptyKeyValues.push_back(parameterRow->valueField->getText().text());
377 }
378 }
379 // sort non-empty parameters
380 std::sort(nonEmptyKeyValues.begin(), nonEmptyKeyValues.end());
381 // sort non-empty parameters
382 std::sort(emptyKeyValues.begin(), emptyKeyValues.end());
383 // add values without key
384 for (const auto& emptyKeyValue : emptyKeyValues) {
385 nonEmptyKeyValues.push_back(std::make_pair("", emptyKeyValue));
386 }
387 // finally setparameters in myParametersValues
388 myParameterDialogParent->myParametersValues->setParameters(nonEmptyKeyValues);
389 return 1;
390}
391
392
393long
395 // Create dialog box
396 FXDialogBox* ParameterHelpDialog = new FXDialogBox(this, " Parameters Help", GUIDesignDialogBox);
397 ParameterHelpDialog->setIcon(GUIIconSubSys::getIcon(GUIIcon::APP_TABLE));
398 // set help text
399 std::ostringstream help;
400 help
401 << TL("- Parameters are defined by a Key and a Value.\n")
402 << TL("- In Netedit can be defined using format key1=parameter1|key2=parameter2|...\n")
403 << TL(" - Duplicated and empty Keys aren't valid.\n")
404 << TL(" - Whitespace and certain characters aren't allowed (@$%^&/|\\....)\n");
405 // Create label with the help text
406 new FXLabel(ParameterHelpDialog, help.str().c_str(), nullptr, GUIDesignLabelFrameInformation);
407 // Create horizontal separator
408 new FXHorizontalSeparator(ParameterHelpDialog, GUIDesignHorizontalSeparator);
409 // Create frame for OK Button
410 FXHorizontalFrame* myHorizontalFrameOKButton = new FXHorizontalFrame(ParameterHelpDialog, GUIDesignAuxiliarHorizontalFrame);
411 // Create Button Close (And two more horizontal frames to center it)
412 new FXHorizontalFrame(myHorizontalFrameOKButton, GUIDesignAuxiliarHorizontalFrame);
413 GUIDesigns::buildFXButton(myHorizontalFrameOKButton, TL("OK"), "", TL("close"), GUIIconSubSys::getIcon(GUIIcon::ACCEPT), ParameterHelpDialog, FXDialogBox::ID_ACCEPT, GUIDesignButtonOK);
414 new FXHorizontalFrame(myHorizontalFrameOKButton, GUIDesignAuxiliarHorizontalFrame);
415 // Write Warning in console if we're in testing mode
416 WRITE_DEBUG("Opening Parameter help dialog");
417 // create Dialog
418 ParameterHelpDialog->create();
419 // show in the given position
420 ParameterHelpDialog->show(PLACEMENT_CURSOR);
421 // refresh APP
422 getApp()->refresh();
423 // open as modal dialog (will block all windows until stop() or stopModal() is called)
424 getApp()->runModalFor(ParameterHelpDialog);
425 // Write Warning in console if we're in testing mode
426 WRITE_DEBUG("Closing Parameter help dialog");
427 return 1;
428}
429
430
432 SUMOSAXHandler(file),
433 myParametersOperationsParent(ParametersOperationsParent) {
434}
435
436
438
439
440void
442 // only continue if tag is valid
443 if (element != SUMO_TAG_NOTHING) {
444 // Call parse and build depending of tag
445 switch (element) {
446 case SUMO_TAG_PARAM:
447 // Check that format of Parameter is correct
448 if (!attrs.hasAttribute(SUMO_ATTR_KEY)) {
449 WRITE_WARNING(TL("Key of Parameter not defined"));
450 } else if (!attrs.hasAttribute(SUMO_ATTR_VALUE)) {
451 WRITE_WARNING(TL("Value of Parameter not defined"));
452 } else {
453 // obtain Key and value
454 std::string key = attrs.getString(SUMO_ATTR_KEY);
455 std::string value = attrs.getString(SUMO_ATTR_VALUE);
456 // check that parsed values are correct
458 if (key.size() == 0) {
459 WRITE_WARNING(TL("Key of Parameter cannot be empty"));
460 } else {
461 WRITE_WARNINGF(TL("Key '%' of Parameter contains invalid characters"), key);
462 }
463 } else if (myParametersOperationsParent->myParameterDialogParent->myParametersValues->keyExist(key)) {
464 WRITE_WARNINGF(TL("Key '%' already exist"), key);
465 } else {
466 // add parameter to vector of myParameterDialogParent
467 myParametersOperationsParent->myParameterDialogParent->myParametersValues->addParameter(std::make_pair(key, value));
468 }
469 }
470 break;
471 default:
472 break;
473 }
474 }
475}
476
477// ---------------------------------------------------------------------------
478// GNESingleParametersDialog - methods
479// ---------------------------------------------------------------------------
480
482 FXDialogBox(genericDataAttributes->getFrameParent()->getViewNet()->getApp(), "Edit attributes", GUIDesignDialogBoxExplicitStretchable(400, 300)),
483 myGenericDataAttributes(genericDataAttributes),
484 myParametersEditor(nullptr),
485 VTypeAttributeRow(nullptr),
486 myAttributeCarrier(nullptr),
487 myTLDef(nullptr) {
488 // call auxiliar constructor for elements
489 constructor("Attributes");
490 // fill myParametersValues
491 myParametersValues->setParameters(genericDataAttributes->getParameters());
492}
493
494
496 FXDialogBox(parametersEditor->getViewNet()->getApp(), "Edit parameters", GUIDesignDialogBoxExplicitStretchable(400, 300)),
497 myGenericDataAttributes(nullptr),
498 myParametersEditor(parametersEditor),
499 VTypeAttributeRow(nullptr),
500 myAttributeCarrier(nullptr),
501 myTLDef(nullptr) {
502 const auto& inspectedElements = parametersEditor->getViewNet()->getInspectedElements();
503 // call auxiliar constructor
504 constructor("Parameters");
505 // continue depending if we're in inspector frame
506 if (inspectedElements.getFirstAC() && parametersEditor->getInspectorFrameParent()) {
507 // fill myParametersValues
508 myParametersValues->setParameters(inspectedElements.getFirstAC()->getACParameters<std::vector<std::pair<std::string, std::string> > >());
509 } else if (parametersEditor->getTypeFrameParent()) {
510 // get type
511 const auto type = parametersEditor->getTypeFrameParent()->getTypeSelector()->getCurrentType();
512 // fill myParametersValues
513 myParametersValues->setParameters(type->getACParameters<std::vector<std::pair<std::string, std::string> > >());
514 }
515}
516
517
518
520 FXDialogBox(viewNet->getApp(), "Edit parameters", GUIDesignDialogBoxExplicitStretchable(400, 300)),
521 myGenericDataAttributes(nullptr),
522 myParametersEditor(nullptr),
523 VTypeAttributeRow(VTypeAttributeRow),
524 myAttributeCarrier(nullptr),
525 myTLDef(nullptr) {
526 // call auxiliar constructor
527 constructor("Parameters");
528 // fill myEditedParameters
530}
531
532
534 FXDialogBox(attributeCarrier->getNet()->getViewNet()->getApp(), "Edit parameters", GUIDesignDialogBoxExplicitStretchable(400, 300)),
535 myGenericDataAttributes(nullptr),
536 myParametersEditor(nullptr),
537 VTypeAttributeRow(nullptr),
538 myAttributeCarrier(attributeCarrier),
539 myTLDef(nullptr) {
540 // call auxiliar constructor
541 constructor("Parameters");
542 // fill myEditedParameters
543 myParametersValues->setParameters(myAttributeCarrier->getACParameters<std::vector<std::pair<std::string, std::string> > >());
544}
545
546
548 FXDialogBox(app, "Edit parameters", GUIDesignDialogBoxExplicitStretchable(400, 300)),
549 myGenericDataAttributes(nullptr),
550 myParametersEditor(nullptr),
551 VTypeAttributeRow(nullptr),
552 myAttributeCarrier(nullptr),
553 myTLDef(TLDef) {
554 // call auxiliar constructor
555 constructor("Parameters");
556 // transform parameters to a=b|c=d... format
557 std::vector<std::pair<std::string, std::string> > parametersStr;
558 // Generate a vector string using the following structure: "<key1,value1>, <key2, value2>,...
559 for (const auto& parameter : TLDef->getParametersMap()) {
560 parametersStr.push_back(std::make_pair(parameter.first, parameter.second));
561 }
562 // set parameters
563 myParametersValues->setParameters(parametersStr);
564}
565
566
568
569
570long
571GNESingleParametersDialog::onCmdAccept(FXObject*, FXSelector, void*) {
572 // declare vector for parameters in stringvector format
573 std::vector<std::pair<std::string, std::string> > parameters;
574 // check if all edited parameters are valid
575 for (const auto& parameterRow : myParametersValues->getParameterRows()) {
576 // ignore last row
577 if (parameterRow != myParametersValues->getParameterRows().back()) {
578 if (parameterRow->keyField->getText().empty()) {
579 // write warning if netedit is running in testing mode
580 WRITE_DEBUG("Opening FXMessageBox of type 'warning'");
581 // open warning Box
582 FXMessageBox::warning(getApp(), MBOX_OK, "Empty Parameter key", "%s", "Parameters with empty keys aren't allowed");
583 // write warning if netedit is running in testing mode
584 WRITE_DEBUG("Closed FXMessageBox of type 'warning' with 'OK'");
585 return 1;
586 } else if (!SUMOXMLDefinitions::isValidParameterKey(parameterRow->keyField->getText().text())) {
587 // write warning if netedit is running in testing mode
588 WRITE_DEBUG("Opening FXMessageBox of type 'warning'");
589 // open warning Box
590 FXMessageBox::warning(getApp(), MBOX_OK, "Invalid Parameter key", "%s", "There are keys with invalid characters");
591 // write warning if netedit is running in testing mode
592 WRITE_DEBUG("Closed FXMessageBox of type 'warning' with 'OK'");
593 return 1;
594 }
595 // insert in parameters
596 parameters.push_back(std::make_pair(parameterRow->keyField->getText().text(), parameterRow->valueField->getText().text()));
597 }
598 }
599 // sort sortedParameters
600 std::sort(parameters.begin(), parameters.end());
601 // check if there is duplicated keys
602 for (auto i = parameters.begin(); i != parameters.end(); i++) {
603 if (((i + 1) != parameters.end()) && (i->first) == (i + 1)->first) {
604 // write warning if netedit is running in testing mode
605 WRITE_DEBUG("Opening FXMessageBox of type 'warning'");
606 // open warning Box
607 FXMessageBox::warning(getApp(), MBOX_OK, "Duplicated Parameters", "%s", "Parameters with the same Key aren't allowed");
608 // write warning if netedit is running in testing mode
609 WRITE_DEBUG("Closed FXMessageBox of type 'warning' with 'OK'");
610 return 1;
611 }
612 }
613 // set parameters in Parameters editor parents
615 // set parameter in editor creator
617 } else if (myParametersEditor) {
618 const auto& inspectedElements = myParametersEditor->getViewNet()->getInspectedElements();
619 // continue depending if we're in inspector frame
620 if (inspectedElements.getFirstAC() && myParametersEditor->getInspectorFrameParent()) {
621 // set parameter in AC using undoList
622 myParametersEditor->getViewNet()->getUndoList()->begin(inspectedElements.getFirstAC(), "change parameters");
623 inspectedElements.getFirstAC()->setACParameters(parameters, myParametersEditor->getViewNet()->getUndoList());
626 // get type
628 // set parameter in AC using undoList
629 myParametersEditor->getViewNet()->getUndoList()->begin(type, "change parameters");
630 type->setACParameters(parameters, myParametersEditor->getViewNet()->getUndoList());
632 }
633 } else if (VTypeAttributeRow) {
634 // set parameter in VTypeAttributeRow
635 VTypeAttributeRow->setParameters(parameters);
636 } else if (myAttributeCarrier) {
637 // set parameter in AC using undoList
641 } else if (myTLDef) {
643 for (const auto& parameter : parameters) {
644 myTLDef->setParameter(parameter.first, parameter.second);
645 }
646 }
647 // all ok, then close dialog
648 getApp()->stopModal(this, TRUE);
649 return 1;
650}
651
652
653long
654GNESingleParametersDialog::onCmdCancel(FXObject*, FXSelector, void*) {
655 // Stop Modal
656 getApp()->stopModal(this, FALSE);
657 return 1;
658}
659
660
661long
662GNESingleParametersDialog::onCmdReset(FXObject*, FXSelector, void*) {
663 // restore original parameters
666 } else if (myParametersEditor) {
667 const auto& inspectedElements = myParametersEditor->getViewNet()->getInspectedElements();
668 // continue depending if we're in inspector frame
670 myParametersValues->setParameters(inspectedElements.getFirstAC()->getACParameters<std::vector<std::pair<std::string, std::string> > >());
673 myParametersValues->setParameters(type->getACParameters<std::vector<std::pair<std::string, std::string> > >());
674 }
675 } else if (VTypeAttributeRow) {
677 } else if (myAttributeCarrier) {
678 myParametersValues->setParameters(myAttributeCarrier->getACParameters<std::vector<std::pair<std::string, std::string> > >());
679 } else if (myTLDef) {
680 // transform parameters to a=b|c=d... format
681 std::vector<std::pair<std::string, std::string> > parametersStr;
682 // Generate a vector string using the following structure: "<key1,value1>, <key2, value2>,...
683 for (const auto& parameter : myTLDef->getParametersMap()) {
684 parametersStr.push_back(std::make_pair(parameter.first, parameter.second));
685 }
686 // set parameters
687 myParametersValues->setParameters(parametersStr);
688 }
689 return 1;
690}
691
692
693void
695 // set vehicle icon for this dialog
697 // create main frame
698 FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
699 // create frame for Parameters and operations
700 FXHorizontalFrame* horizontalFrameExtras = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarFrame);
701 // create parameters values
702 myParametersValues = new ParametersValues(horizontalFrameExtras, name);
703 // create parameters operations
704 myParametersOperations = new ParametersOperations(horizontalFrameExtras, this);
705 // add separator
706 new FXHorizontalSeparator(mainFrame, GUIDesignHorizontalSeparator);
707 // create dialog buttons bot centered
708 FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
709 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
713 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
714}
715
716/****************************************************************************/
FXDEFMAP(GNESingleParametersDialog) GNESingleParametersDialogMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition GUIAppEnum.h:939
@ MID_GNE_REMOVE_ATTRIBUTE
attribute removed
Definition GUIAppEnum.h:937
@ MID_GNE_BUTTON_CANCEL
cancel button
@ MID_GNE_BUTTON_RESET
reset button
@ MID_GNE_BUTTON_SAVE
save button
@ MID_GNE_BUTTON_SORT
sort button
@ MID_HELP
help button
Definition GUIAppEnum.h:653
@ MID_GNE_BUTTON_LOAD
load button
@ MID_GNE_BUTTON_CLEAR
clear button
@ MID_GNE_BUTTON_ACCEPT
accept button
#define GUIDesignGroupBoxFrame100
Group box design for elements of width 100.
Definition GUIDesigns.h:352
#define GUIDesignButtonIcon
button only with icon
Definition GUIDesigns.h:91
#define GUIDesignButtonAccept
Accept Button.
Definition GUIDesigns.h:156
#define GUIDesignButtonCancel
Cancel Button.
Definition GUIDesigns.h:162
#define GUIDesignTextField
Definition GUIDesigns.h:59
#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 GUIDesignButtonOK
Definition GUIDesigns.h:153
#define GUIDesignLabelThick(justify)
label extended over frame with thick and with text justify to left
Definition GUIDesigns.h:249
#define GUIDesignGroupBoxFrameFill
Group box design extended over frame (X and Y)
Definition GUIDesigns.h:349
#define GUIDesignButtonReset
Reset Button.
Definition GUIDesigns.h:165
#define GUIDesignHorizontalSeparator
Definition GUIDesigns.h:463
#define GUIDesignButtonFixed(width)
button rectangular with thick and raise frame with the given width
Definition GUIDesigns.h:97
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition GUIDesigns.h:390
#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
#define GUIDesignDialogBoxExplicitStretchable(width, height)
design for dialog box with specific width and height that can be stretched (But not shrunk)
Definition GUIDesigns.h:617
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition GUIDesigns.h:279
FXString gCurrentFolder
The folder used as last.
@ CLEANJUNCTIONS
@ GREENVEHICLE
@ OPEN
open icons
@ SAVE
save icons
#define WRITE_DEBUG(msg)
Definition MsgHandler.h:306
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:296
#define WRITE_MESSAGEF(...)
Definition MsgHandler.h:298
#define WRITE_WARNING(msg)
Definition MsgHandler.h:295
#define TL(string)
Definition MsgHandler.h:315
@ SUMO_TAG_NOTHING
invalid tag, must be the last one
@ SUMO_TAG_PARAM
parameter associated to a certain key
@ SUMO_ATTR_VALUE
@ SUMO_ATTR_KEY
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
void setACParameters(const std::string &parameters, GNEUndoList *undoList)
set parameters (string)
GNENet * getNet() const
get pointer to net
T getACParameters() const
get parameters
std::vector< std::pair< std::string, std::string > > getParameters() const
get parameters as vector of strings
void setParameters(const std::vector< std::pair< std::string, std::string > > &parameters)
set parameters
GNEInspectorFrame * getInspectorFrameParent() const
get inspector frame parent
GNETypeFrame * getTypeFrameParent() const
get type frame parent
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2163
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
GNEParameterHandler(ParametersOperations *ParametersOperationsParent, const std::string &file)
Constructor.
ParametersOperations(FXHorizontalFrame *frame, GNESingleParametersDialog *ParameterDialogParent)
FOX-declaration.
long onCmdSaveParameters(FXObject *, FXSelector, void *)
event when user press save parameters button
long onCmdClearParameters(FXObject *, FXSelector, void *)
event when user press clear parameters button
long onCmdSortParameters(FXObject *, FXSelector, void *)
event when user press sort parameters button
long onCmdHelpParameter(FXObject *, FXSelector, void *)
event when user press help parameters button
bool isButtonInAddMode() const
check if remove button is in mode "add"
ParameterRow(ParametersValues *ParametersValues, FXVerticalFrame *verticalFrameParent)
constructor
void copyValues(const ParameterRow &other)
copy values of other parameter Row
void enableRow(const std::string &parameter, const std::string &value) const
enable row
long onPaint(FXObject *o, FXSelector f, void *p)
long onCmdSetAttribute(FXObject *, FXSelector, void *)
event when user change an attribute
const std::vector< ParameterRow * > getParameterRows() const
get vector with the ParameterRows
void setParameters(const std::vector< std::pair< std::string, std::string > > &newParameters)
set parameters
bool keyExist(const std::string &key) const
check if given key exist already
long onCmdButtonPress(FXObject *, FXSelector, void *)
event when user press a remove (or add) button
void addParameter(std::pair< std::string, std::string > newParameter)
add a single parameter
Dialog for edit parameters.
FXButton * myResetButton
cancel button
ParametersValues * myParametersValues
pointer to parameters values
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
FXButton * myKeepOldButton
accept button
GNEVehicleTypeDialog::VTypeAttributes::VTypeAttributeRow * VTypeAttributeRow
pointer to VTypeAttributeRow
FXButton * myCancelButton
cancel button
void constructor(const std::string &name)
auxiliar constructor
ParametersOperations * myParametersOperations
pointer to parameters operations
GNEFrameAttributeModules::ParametersEditor * myParametersEditor
pointer to ParametersEditor
GNEAttributeCarrier * myAttributeCarrier
pointer to GNEAttributeCarrier
NBLoadedSUMOTLDef * myTLDef
pointer to TLDef
GNESingleParametersDialog(GNEFrameAttributeModules::GenericDataAttributes *genericDataAttributes)
Constructor for generic data attributes.
GNEFrameAttributeModules::GenericDataAttributes * myGenericDataAttributes
FOX need this.
long onCmdAccept(FXObject *, FXSelector, void *)
GNEDemandElement * getCurrentType() const
get current Vehicle Type
TypeSelector * getTypeSelector() const
get vehicle type selector
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
class used for represent rows with Vehicle Type parameters
std::vector< std::pair< std::string, std::string > > getParametersVectorStr() const
get parameters as vector of strings
void setParameters(const std::vector< std::pair< std::string, std::string > > &parameters)
set parameters
GNEViewNetHelper::InspectedElements & getInspectedElements()
get inspected elements
GNEUndoList * getUndoList() const
get the undoList object
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
static FXString getFilename2Write(FXWindow *parent, const FXString &header, const FXString &extension, FXIcon *icon, FXString &currentFolder)
Returns the file name to write.
Definition MFXUtils.cpp:82
A loaded (complete) traffic light logic.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
void close()
Closes the device and removes it from the dictionary.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static OutputDevice & getDevice(const std::string &name, bool usePrefix=true)
Returns the described OutputDevice.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >(), bool includeConfig=true)
Writes an XML header with optional configuration.
void clearParameter()
Clears the parameter map.
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
SAX-handler base for SUMO-files.
static bool isValidParameterKey(const std::string &value)
whether the given string is a valid key for a parameter
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false, const bool isRoute=false, const bool isExternal=false, const bool catchExceptions=true)
Runs the given handler on the given file; returns if everything's ok.
Definition json.hpp:4471