Eclipse SUMO - Simulation of Urban MObility
GNESingleParametersDialog.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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 #include <config.h>
21 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
28 #include <utils/xml/XMLSubSys.h>
29 
31 
32 
33 // ===========================================================================
34 // FOX callback mapping
35 // ===========================================================================
36 
37 FXDEFMAP(GNESingleParametersDialog) GNESingleParametersDialogMap[] = {
41  FXMAPFUNC(SEL_CHORE, FXDialogBox::ID_CANCEL, GNESingleParametersDialog::onCmdCancel),
42  FXMAPFUNC(SEL_TIMEOUT, FXDialogBox::ID_CANCEL, GNESingleParametersDialog::onCmdCancel),
43  FXMAPFUNC(SEL_COMMAND, FXDialogBox::ID_CANCEL, GNESingleParametersDialog::onCmdCancel),
44  FXMAPFUNC(SEL_CLOSE, 0, GNESingleParametersDialog::onCmdCancel),
45 };
46 
51 };
52 
59 };
60 
61 // Object implementation
62 FXIMPLEMENT(GNESingleParametersDialog, FXDialogBox, GNESingleParametersDialogMap, ARRAYNUMBER(GNESingleParametersDialogMap))
63 FXIMPLEMENT(GNESingleParametersDialog::ParametersValues, FXGroupBox, ParametersValuesMap, ARRAYNUMBER(ParametersValuesMap))
64 FXIMPLEMENT(GNESingleParametersDialog::ParametersOperations, FXGroupBox, ParametersOperationsMap, ARRAYNUMBER(ParametersOperationsMap))
65 
66 // ===========================================================================
67 // member method definitions
68 // ===========================================================================
69 
70 // ---------------------------------------------------------------------------
71 // GNESingleParametersDialog::ParametersValues - methods
72 // ---------------------------------------------------------------------------
73 
74 GNESingleParametersDialog::ParametersValues::ParametersValues(FXHorizontalFrame* frame, const std::string& name) :
75  FXGroupBox(frame, name.c_str(), GUIDesignGroupBoxFrameFill) {
76  // create labels for keys and values
77  FXHorizontalFrame* horizontalFrameLabels = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
78  myKeyLabel = new FXLabel(horizontalFrameLabels, "key", nullptr, GUIDesignLabelThick100);
79  new FXLabel(horizontalFrameLabels, "value", nullptr, GUIDesignLabelCenterThick);
80  // create scroll windows
81  FXScrollWindow* scrollWindow = new FXScrollWindow(this, LAYOUT_FILL);
82  // create vertical frame for rows
83  myVerticalFrameRow = new FXVerticalFrame(scrollWindow, GUIDesignAuxiliarFrame);
84 }
85 
86 
88 
89 
90 void
91 GNESingleParametersDialog::ParametersValues::setParameters(const std::vector<std::pair<std::string, std::string> >& newParameters) {
92  // clear rows
93  clearParameters();
94  // iterate over parameteres
95  for (const auto& newParameter : newParameters) {
96  addParameter(newParameter);
97  }
98 }
99 
100 
101 void
102 GNESingleParametersDialog::ParametersValues::addParameter(std::pair<std::string, std::string> newParameter) {
103  // enable last row
104  myParameterRows.back()->enableRow(newParameter.first, newParameter.second);
105  // add row
106  myParameterRows.push_back(new ParameterRow(this, myVerticalFrameRow));
107  // enable add button in the last row
108  myParameterRows.back()->toggleAddButton();
109 }
110 
111 
112 void
114  // iterate over all rows
115  for (const auto& parameterRow : myParameterRows) {
116  delete parameterRow;
117  }
118  //clear myParameterRows;
119  myParameterRows.clear();
120  // add row
121  myParameterRows.push_back(new ParameterRow(this, myVerticalFrameRow));
122  // enable add button in the last row
123  myParameterRows.back()->toggleAddButton();
124 }
125 
126 
127 const std::vector<GNESingleParametersDialog::ParametersValues::ParameterRow*>
129  return myParameterRows;
130 }
131 
132 
133 bool
135  // just interate over myParameterRows and compare key
136  for (const auto& row : myParameterRows) {
137  if (row->keyField->getText().text() == key) {
138  return true;
139  }
140  }
141  return false;
142 }
143 
144 
145 long
146 GNESingleParametersDialog::ParametersValues::onPaint(FXObject* o, FXSelector f, void* p) {
147  // size of key label has to be updated in every interation
148  if (myParameterRows.size() > 0) {
149  myKeyLabel->setWidth(myParameterRows.front()->keyField->getWidth());
150  }
151  return FXGroupBox::onPaint(o, f, p);
152 }
153 
154 
155 long
157  // find what value was changed
158  for (int i = 0; i < (int)myParameterRows.size(); i++) {
159  if (myParameterRows.at(i)->keyField == obj) {
160  // change color of text field depending if key is valid or empty
161  if (myParameterRows.at(i)->keyField->getText().empty() || SUMOXMLDefinitions::isValidParameterKey(myParameterRows.at(i)->keyField->getText().text())) {
162  myParameterRows.at(i)->keyField->setTextColor(FXRGB(0, 0, 0));
163  } else {
164  myParameterRows.at(i)->keyField->setTextColor(FXRGB(255, 0, 0));
165  myParameterRows.at(i)->keyField->killFocus();
166  }
167  }
168  }
169  return 1;
170 }
171 
172 
173 long
175  // first check if add button was pressed
176  if (myParameterRows.back()->button == obj) {
177  // create new parameter
178  addParameter(std::make_pair("", ""));
179  return 1;
180  } else {
181  // in other case, button press was a "remove button". Find id and remove the Parameter
182  for (int i = 0; i < (int)myParameterRows.size(); i++) {
183  if (myParameterRows.at(i)->button == obj) {
184  // delete row
185  delete myParameterRows.at(i);
186  // just remove row
187  myParameterRows.erase(myParameterRows.begin() + i);
188  return 1;
189  }
190  }
191  }
192  // Nothing to do
193  return 1;
194 }
195 
196 
198  horizontalFrame = new FXHorizontalFrame(verticalFrameParent, GUIDesignAuxiliarHorizontalFrame);
199  keyField = new FXTextField(horizontalFrame, GUIDesignTextFieldNCol, ParametersValues, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
200  valueField = new FXTextField(horizontalFrame, GUIDesignTextFieldNCol, ParametersValues, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
202  // only create elements if vertical frame was previously created
203  if (verticalFrameParent->id()) {
204  horizontalFrame->create();
205  }
206  // by defaults rows are disabled
207  disableRow();
208 }
209 
210 
212  // simply delete horizontalFrame (rest of elements will be automatic deleted due they are children of horizontal frame)
213  delete horizontalFrame;
214 }
215 
216 
217 void
219  // hide all
220  keyField->setText("");
221  keyField->disable();
222  valueField->setText("");
223  valueField->disable();
224  button->disable();
225  button->setIcon(GUIIconSubSys::getIcon(GUIIcon::REMOVE));
226 }
227 
228 
229 void
230 GNESingleParametersDialog::ParametersValues::ParameterRow::enableRow(const std::string& parameter, const std::string& value) const {
231  // restore color and enable key field
232  keyField->setText(parameter.c_str());
233  if (parameter.empty() || SUMOXMLDefinitions::isValidParameterKey(parameter)) {
234  keyField->setTextColor(FXRGB(0, 0, 0));
235  } else {
236  keyField->setTextColor(FXRGB(255, 0, 0));
237  }
238  keyField->enable();
239  // restore color and enable value field
240  valueField->setText(value.c_str());
241  valueField->enable();
242  // enable button and set icon remove
243  button->enable();
244  button->setIcon(GUIIconSubSys::getIcon(GUIIcon::REMOVE));
245 }
246 
247 
248 void
250  // clear and disable parameter and value fields
251  keyField->setText("");
252  keyField->disable();
253  valueField->setText("");
254  valueField->disable();
255  // enable remove button and set "add" icon and focus
256  button->enable();
257  button->setIcon(GUIIconSubSys::getIcon(GUIIcon::ADD));
258  button->setFocus();
259 }
260 
261 
262 bool
264  return (button->getIcon() == GUIIconSubSys::getIcon(GUIIcon::ADD));
265 }
266 
267 
268 void
270  keyField->setText(other.keyField->getText());
271  valueField->setText(other.valueField->getText());
272 }
273 
274 // ---------------------------------------------------------------------------
275 // GNESingleParametersDialog::ParametersOperations - methods
276 // ---------------------------------------------------------------------------
277 
279  FXGroupBox(frame, "Operations", GUIDesignGroupBoxFrame100),
280  myParameterDialogParent(ParameterDialogParent) {
281  // create buttons
287 }
288 
289 
291 
292 
293 long
295  // get the Additional file name
296  FXFileDialog opendialog(this, "Open Parameter Template");
297  opendialog.setIcon(GUIIconSubSys::getIcon(GUIIcon::GREENVEHICLE));
298  opendialog.setSelectMode(SELECTFILE_EXISTING);
299  opendialog.setPatternList(" Parameter Template files (*.xml)\nAll files (*)");
300  if (gCurrentFolder.length() != 0) {
301  opendialog.setDirectory(gCurrentFolder);
302  }
303  if (opendialog.execute()) {
304  gCurrentFolder = opendialog.getDirectory();
305  std::string file = opendialog.getFilename().text();
306  // save current number of parameters
307  const int numberOfParametersbeforeLoad = (int)myParameterDialogParent->myParametersValues->getParameterRows().size();
308  // Create additional handler and run parser
309  GNEParameterHandler handler(this, file);
310  if (!XMLSubSys::runParser(handler, file, false)) {
311  WRITE_MESSAGE("Loading of Parameters From " + file + " failed.");
312  }
313  // show loaded attributes
314  WRITE_MESSAGE("Loaded " + toString((int)myParameterDialogParent->myParametersValues->getParameterRows().size() - numberOfParametersbeforeLoad) + " Parameters.");
315  }
316  return 1;
317 }
318 
319 
320 long
322  // obtain file to save parameters
323  FXString file = MFXUtils::getFilename2Write(this,
324  "Save Parameter Template file", ".xml",
327  if (file == "") {
328  // None parameter file was selected, then stop function
329  return 1;
330  } else {
331  // open device
332  OutputDevice& device = OutputDevice::getDevice(file.text());
333  // write header
334  device.writeXMLHeader("Parameter", "parameter_file.xsd");
335  // iterate over all parameters and save it in the filename
336  for (const auto& row : myParameterDialogParent->myParametersValues->getParameterRows()) {
337  // write all except last
338  if (row != myParameterDialogParent->myParametersValues->getParameterRows().back()) {
339  // open tag
340  device.openTag(SUMO_TAG_PARAM);
341  // write key
342  device.writeAttr(SUMO_ATTR_KEY, row->keyField->getText().text());
343  // write value
344  device.writeAttr(SUMO_ATTR_VALUE, row->valueField->getText().text());
345  // close tag
346  device.closeTag();
347  }
348  }
349  // close device
350  device.close();
351  }
352  return 1;
353 }
354 
355 
356 long
358  // simply clear parameters from ParametersValues
359  myParameterDialogParent->myParametersValues->clearParameters();
360  return 1;
361 }
362 
363 
364 long
366  // declare two containers for parameters
367  std::vector<std::pair<std::string, std::string> > nonEmptyKeyValues;
368  std::vector<std::string> emptyKeyValues;
369  // first extract empty values
370  for (const auto& parameterRow : myParameterDialogParent->myParametersValues->getParameterRows()) {
371  // check if key is empty
372  if (!parameterRow->keyField->getText().empty()) {
373  nonEmptyKeyValues.push_back(std::make_pair(parameterRow->keyField->getText().text(), parameterRow->valueField->getText().text()));
374  } else if (!parameterRow->valueField->getText().empty()) {
375  emptyKeyValues.push_back(parameterRow->valueField->getText().text());
376  }
377  }
378  // sort non-empty parameters
379  std::sort(nonEmptyKeyValues.begin(), nonEmptyKeyValues.end());
380  // sort non-empty parameters
381  std::sort(emptyKeyValues.begin(), emptyKeyValues.end());
382  // add values without key
383  for (const auto& emptyKeyValue : emptyKeyValues) {
384  nonEmptyKeyValues.push_back(std::make_pair("", emptyKeyValue));
385  }
386  // finally setparameters in myParametersValues
387  myParameterDialogParent->myParametersValues->setParameters(nonEmptyKeyValues);
388  return 1;
389 }
390 
391 
392 long
394  // Create dialog box
395  FXDialogBox* ParameterHelpDialog = new FXDialogBox(this, " Parameters Help", GUIDesignDialogBox);
396  ParameterHelpDialog->setIcon(GUIIconSubSys::getIcon(GUIIcon::APP_TABLE));
397  // set help text
398  std::ostringstream help;
399  help
400  << "- Parameters are defined by a Key and a Value.\n"
401  << "- In Netedit can be defined using format key1=parameter1|key2=parameter2|...\n"
402  << " - Duplicated and empty Keys aren't valid.\n"
403  << " - Certain characters aren't allowed (\t\n\r@$%^&/|\\....)\n";
404  // Create label with the help text
405  new FXLabel(ParameterHelpDialog, help.str().c_str(), nullptr, GUIDesignLabelFrameInformation);
406  // Create horizontal separator
407  new FXHorizontalSeparator(ParameterHelpDialog, GUIDesignHorizontalSeparator);
408  // Create frame for OK Button
409  FXHorizontalFrame* myHorizontalFrameOKButton = new FXHorizontalFrame(ParameterHelpDialog, GUIDesignAuxiliarHorizontalFrame);
410  // Create Button Close (And two more horizontal frames to center it)
411  new FXHorizontalFrame(myHorizontalFrameOKButton, GUIDesignAuxiliarHorizontalFrame);
412  new FXButton(myHorizontalFrameOKButton, "OK\t\tclose", GUIIconSubSys::getIcon(GUIIcon::ACCEPT), ParameterHelpDialog, FXDialogBox::ID_ACCEPT, GUIDesignButtonOK);
413  new FXHorizontalFrame(myHorizontalFrameOKButton, GUIDesignAuxiliarHorizontalFrame);
414  // Write Warning in console if we're in testing mode
415  WRITE_DEBUG("Opening Parameter help dialog");
416  // create Dialog
417  ParameterHelpDialog->create();
418  // show in the given position
419  ParameterHelpDialog->show(PLACEMENT_CURSOR);
420  // refresh APP
421  getApp()->refresh();
422  // open as modal dialog (will block all windows until stop() or stopModal() is called)
423  getApp()->runModalFor(ParameterHelpDialog);
424  // Write Warning in console if we're in testing mode
425  WRITE_DEBUG("Closing Parameter help dialog");
426  return 1;
427 }
428 
429 
431  SUMOSAXHandler(file),
432  myParametersOperationsParent(ParametersOperationsParent) {
433 }
434 
435 
437 
438 
439 void
441  // only continue if tag is valid
442  if (element != SUMO_TAG_NOTHING) {
443  // Call parse and build depending of tag
444  switch (element) {
445  case SUMO_TAG_PARAM:
446  // Check that format of Parameter is correct
447  if (!attrs.hasAttribute(SUMO_ATTR_KEY)) {
448  WRITE_WARNING("Key of Parameter not defined");
449  } else if (!attrs.hasAttribute(SUMO_ATTR_VALUE)) {
450  WRITE_WARNING("Value of Parameter not defined");
451  } else {
452  // obtain Key and value
453  std::string key = attrs.getString(SUMO_ATTR_KEY);
454  std::string value = attrs.getString(SUMO_ATTR_VALUE);
455  // check that parsed values are correct
457  if (key.size() == 0) {
458  WRITE_WARNING("Key of Parameter cannot be empty");
459  } else {
460  WRITE_WARNING("Key '" + key + "' of Parameter contains invalid characters");
461  }
462  } else if (myParametersOperationsParent->myParameterDialogParent->myParametersValues->keyExist(key)) {
463  WRITE_WARNING("Key '" + key + "' already exist");
464  } else {
465  // add parameter to vector of myParameterDialogParent
466  myParametersOperationsParent->myParameterDialogParent->myParametersValues->addParameter(std::make_pair(key, value));
467  }
468  }
469  break;
470  default:
471  break;
472  }
473  }
474 }
475 
476 // ---------------------------------------------------------------------------
477 // GNESingleParametersDialog - methods
478 // ---------------------------------------------------------------------------
479 
481  FXDialogBox(genericDataAttributes->getFrameParent()->getViewNet()->getApp(), "Edit attributes", GUIDesignDialogBoxExplicitStretchable(400, 300)),
482  myGenericDataAttributes(genericDataAttributes),
483  myParametersEditor(nullptr),
484  VTypeAttributeRow(nullptr),
485  myAttributeCarrier(nullptr),
486  myTLDef(nullptr) {
487  // call auxiliar constructor for elements
488  constructor("Attributes");
489  // fill myParametersValues
490  myParametersValues->setParameters(genericDataAttributes->getParameters());
491 }
492 
493 
495  FXDialogBox(parametersEditor->getInspectorFrameParent()->getViewNet()->getApp(), "Edit parameters", GUIDesignDialogBoxExplicitStretchable(400, 300)),
496  myGenericDataAttributes(nullptr),
497  myParametersEditor(parametersEditor),
498  VTypeAttributeRow(nullptr),
499  myAttributeCarrier(nullptr),
500  myTLDef(nullptr) {
501  // call auxiliar constructor
502  constructor("Parameters");
503  // get AC Front
504  const GNEAttributeCarrier* AC = parametersEditor->getInspectorFrameParent()->getViewNet()->getInspectedAttributeCarriers().front();
505  // fill myParametersValues
506  myParametersValues->setParameters(AC->getACParameters<std::vector<std::pair<std::string, std::string> > >());
507 }
508 
509 
510 
512  FXDialogBox(viewNet->getApp(), "Edit parameters", GUIDesignDialogBoxExplicitStretchable(400, 300)),
513  myGenericDataAttributes(nullptr),
514  myParametersEditor(nullptr),
515  VTypeAttributeRow(VTypeAttributeRow),
516  myAttributeCarrier(nullptr),
517  myTLDef(nullptr) {
518  // call auxiliar constructor
519  constructor("Parameters");
520  // fill myEditedParameters
522 }
523 
524 
526  FXDialogBox(attributeCarrier->getNet()->getViewNet()->getApp(), "Edit parameters", GUIDesignDialogBoxExplicitStretchable(400, 300)),
527  myGenericDataAttributes(nullptr),
528  myParametersEditor(nullptr),
529  VTypeAttributeRow(nullptr),
530  myAttributeCarrier(attributeCarrier),
531  myTLDef(nullptr) {
532  // call auxiliar constructor
533  constructor("Parameters");
534  // fill myEditedParameters
535  myParametersValues->setParameters(myAttributeCarrier->getACParameters<std::vector<std::pair<std::string, std::string> > >());
536 }
537 
538 
540  FXDialogBox(app, "Edit parameters", GUIDesignDialogBoxExplicitStretchable(400, 300)),
541  myGenericDataAttributes(nullptr),
542  myParametersEditor(nullptr),
543  VTypeAttributeRow(nullptr),
544  myAttributeCarrier(nullptr),
545  myTLDef(TLDef) {
546  // call auxiliar constructor
547  constructor("Parameters");
548  // transform parameters to a=b|c=d... format
549  std::vector<std::pair<std::string, std::string> > parametersStr;
550  // Generate a vector string using the following structure: "<key1,value1>, <key2, value2>,...
551  for (const auto& parameter : TLDef->getParametersMap()) {
552  parametersStr.push_back(std::make_pair(parameter.first, parameter.second));
553  }
554  // set parameters
555  myParametersValues->setParameters(parametersStr);
556 }
557 
558 
560 
561 
562 long
563 GNESingleParametersDialog::onCmdAccept(FXObject*, FXSelector, void*) {
564  // declare vector for parameters in stringvector format
565  std::vector<std::pair<std::string, std::string> > parameters;
566  // check if all edited parameters are valid
567  for (const auto& parameterRow : myParametersValues->getParameterRows()) {
568  // ignore last row
569  if (parameterRow != myParametersValues->getParameterRows().back()) {
570  if (parameterRow->keyField->getText().empty()) {
571  // write warning if netedit is running in testing mode
572  WRITE_DEBUG("Opening FXMessageBox of type 'warning'");
573  // open warning Box
574  FXMessageBox::warning(getApp(), MBOX_OK, "Empty Parameter key", "%s", "Parameters with empty keys aren't allowed");
575  // write warning if netedit is running in testing mode
576  WRITE_DEBUG("Closed FXMessageBox of type 'warning' with 'OK'");
577  return 1;
578  } else if (!SUMOXMLDefinitions::isValidParameterKey(parameterRow->keyField->getText().text())) {
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, "Invalid Parameter key", "%s", "There are keys with invalid characters");
583  // write warning if netedit is running in testing mode
584  WRITE_DEBUG("Closed FXMessageBox of type 'warning' with 'OK'");
585  return 1;
586  }
587  // insert in parameters
588  parameters.push_back(std::make_pair(parameterRow->keyField->getText().text(), parameterRow->valueField->getText().text()));
589  }
590  }
591  // sort sortedParameters
592  std::sort(parameters.begin(), parameters.end());
593  // check if there is duplicated keys
594  for (auto i = parameters.begin(); i != parameters.end(); i++) {
595  if (((i + 1) != parameters.end()) && (i->first) == (i + 1)->first) {
596  // write warning if netedit is running in testing mode
597  WRITE_DEBUG("Opening FXMessageBox of type 'warning'");
598  // open warning Box
599  FXMessageBox::warning(getApp(), MBOX_OK, "Duplicated Parameters", "%s", "Parameters with the same Key aren't allowed");
600  // write warning if netedit is running in testing mode
601  WRITE_DEBUG("Closed FXMessageBox of type 'warning' with 'OK'");
602  return 1;
603  }
604  }
605  // set parameters in Parameters editor parents
607  // set parameter in editor creator
609  } else if (myParametersEditor) {
610  // get inspected AC
612  // set parameter in AC using undoList
616  } else if (VTypeAttributeRow) {
617  // set parameter in VTypeAttributeRow
618  VTypeAttributeRow->setParameters(parameters);
619  } else if (myAttributeCarrier) {
620  // set parameter in AC using undoList
624  } else if (myTLDef) {
625  // declare parametersMap
626  std::map<std::string, std::string> parametersMap;
627  // Generate an string using the following structure: "key1=value1|key2=value2|...
628  for (const auto& parameter : parameters) {
629  parametersMap[parameter.first] = parameter.second;
630  }
631  // set setACParameters map
632  myTLDef->setParametersMap(parametersMap);
633  }
634  // all ok, then close dialog
635  getApp()->stopModal(this, TRUE);
636  return 1;
637 }
638 
639 
640 long
641 GNESingleParametersDialog::onCmdCancel(FXObject*, FXSelector, void*) {
642  // Stop Modal
643  getApp()->stopModal(this, FALSE);
644  return 1;
645 }
646 
647 
648 long
649 GNESingleParametersDialog::onCmdReset(FXObject*, FXSelector, void*) {
650  // restore original parameters
653  } else if (myParametersEditor) {
655  myParametersValues->setParameters(AC->getACParameters<std::vector<std::pair<std::string, std::string> > >());
656  } else if (VTypeAttributeRow) {
658  } else if (myAttributeCarrier) {
659  myParametersValues->setParameters(myAttributeCarrier->getACParameters<std::vector<std::pair<std::string, std::string> > >());
660  } else if (myTLDef) {
661  // transform parameters to a=b|c=d... format
662  std::vector<std::pair<std::string, std::string> > parametersStr;
663  // Generate a vector string using the following structure: "<key1,value1>, <key2, value2>,...
664  for (const auto& parameter : myTLDef->getParametersMap()) {
665  parametersStr.push_back(std::make_pair(parameter.first, parameter.second));
666  }
667  // set parameters
668  myParametersValues->setParameters(parametersStr);
669  }
670  return 1;
671 }
672 
673 
674 void
675 GNESingleParametersDialog::constructor(const std::string& name) {
676  // set vehicle icon for this dialog
678  // create main frame
679  FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
680  // create frame for Parameters and operations
681  FXHorizontalFrame* horizontalFrameExtras = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarFrame);
682  // create parameters values
683  myParametersValues = new ParametersValues(horizontalFrameExtras, name);
684  // create parameters operations
685  myParametersOperations = new ParametersOperations(horizontalFrameExtras, this);
686  // add separator
687  new FXHorizontalSeparator(mainFrame, GUIDesignHorizontalSeparator);
688  // create dialog buttons bot centered
689  FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
690  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
691  myAcceptButton = new FXButton(buttonsFrame, "accept\t\tclose", GUIIconSubSys::getIcon(GUIIcon::ACCEPT), this, MID_GNE_BUTTON_ACCEPT, GUIDesignButtonAccept);
692  myCancelButton = new FXButton(buttonsFrame, "cancel\t\tclose", GUIIconSubSys::getIcon(GUIIcon::CANCEL), this, MID_GNE_BUTTON_CANCEL, GUIDesignButtonCancel);
693  myResetButton = new FXButton(buttonsFrame, "reset\t\tclose", GUIIconSubSys::getIcon(GUIIcon::RESET), this, MID_GNE_BUTTON_RESET, GUIDesignButtonReset);
694  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
695 }
696 
697 /****************************************************************************/
FXDEFMAP(GNESingleParametersDialog) GNESingleParametersDialogMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition: GUIAppEnum.h:797
@ MID_GNE_REMOVE_ATTRIBUTE
attribute removed
Definition: GUIAppEnum.h:795
@ MID_GNE_BUTTON_CANCEL
cancel button
Definition: GUIAppEnum.h:1193
@ MID_GNE_BUTTON_RESET
reset button
Definition: GUIAppEnum.h:1195
@ MID_GNE_BUTTON_SAVE
save button
Definition: GUIAppEnum.h:1199
@ MID_GNE_BUTTON_SORT
sort button
Definition: GUIAppEnum.h:1203
@ MID_HELP
help button
Definition: GUIAppEnum.h:600
@ MID_GNE_BUTTON_LOAD
load button
Definition: GUIAppEnum.h:1197
@ MID_GNE_BUTTON_CLEAR
clear button
Definition: GUIAppEnum.h:1201
@ MID_GNE_BUTTON_ACCEPT
accept button
Definition: GUIAppEnum.h:1191
#define GUIDesignGroupBoxFrame100
Group box design for elements of width 100.
Definition: GUIDesigns.h:314
#define GUIDesignButtonIcon
button only with icon
Definition: GUIDesigns.h:77
#define GUIDesignButtonAccept
Accept Button.
Definition: GUIDesigns.h:127
#define GUIDesignButtonCancel
Cancel Button.
Definition: GUIDesigns.h:130
#define GUIDesignTextField
Definition: GUIDesigns.h:42
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:343
#define GUIDesignDialogBox
Definition: GUIDesigns.h:527
#define GUIDesignButtonRectangular100
button rectangular with thick and raise frame with a width of 100
Definition: GUIDesigns.h:83
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:60
#define GUIDesignButtonOK
Definition: GUIDesigns.h:124
#define GUIDesignLabelCenterThick
label extended over frame with thick and with text justify to center
Definition: GUIDesigns.h:211
#define GUIDesignGroupBoxFrameFill
Group box design extended over frame (X and Y)
Definition: GUIDesigns.h:311
#define GUIDesignButtonReset
Reset Button.
Definition: GUIDesigns.h:133
#define GUIDesignLabelThick100
label with thick, text justify to left and width of 100
Definition: GUIDesigns.h:250
#define GUIDesignHorizontalSeparator
Definition: GUIDesigns.h:395
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions
Definition: GUIDesigns.h:340
#define GUIDesignHorizontalFrame
Definition: GUIDesigns.h:293
#define GUIDesignDialogBoxExplicitStretchable(width, height)
design for dialog box with specift width and height that can be stretched (But not shrinked)
Definition: GUIDesigns.h:542
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition: GUIDesigns.h:244
FXString gCurrentFolder
The folder used as last.
@ CLEANJUNCTIONS
@ GREENVEHICLE
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:290
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:282
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
@ SUMO_TAG_NOTHING
invalid tag
@ 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)
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
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
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:133
GNEInspectorFrame * getInspectorFrameParent() const
get inspector frame parent
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
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 onCmdLoadParameters(FXObject *, FXSelector, void *)
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 rlow
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
GNEVehicleTypeDialog::VTypeAtributes::VTypeAttributeRow * VTypeAttributeRow
pointer to VTypeAttributeRow
FXButton * myAcceptButton
accept button
FXButton * myCancelButton
cancel button
void constructor(const std::string &name)
auxiliar constructor
ParametersOperations * myParametersOperations
pointer to parameters operations
GNEAttributeCarrier * myAttributeCarrier
pointer to GNEAttributeCarrier
NBLoadedSUMOTLDef * myTLDef
pointer to TLDef
GNESingleParametersDialog(GNEFrameAttributeModules::GenericDataAttributes *genericDataAttributes)
Constructor for generic data attributes.
GNEInspectorFrame::ParametersEditor * myParametersEditor
pointer to ParametersEditor
GNEFrameAttributeModules::GenericDataAttributes * myGenericDataAttributes
FOX need this.
long onCmdAccept(FXObject *, FXSelector, void *)
GUIIcon getGUIIcon() const
get GUI icon associated to this Tag
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
void setParameters(const std::vector< std::pair< std::string, std::string > > &parameters)
set parameters
std::vector< std::pair< std::string, std::string > > getParametersVectorStr() const
get parameters as vector of strings
GNEUndoList * getUndoList() const
get the undoList object
const std::vector< GNEAttributeCarrier * > & getInspectedAttributeCarriers() const
get inspected attribute carriers
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.
Definition: OutputDevice.h:61
void close()
Closes the device and removes it from the dictionary.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
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.
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
void setParametersMap(const std::map< std::string, std::string > &paramsMap)
set the inner key/value map in map<string, string> format
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
Encapsulated SAX-Attributes.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
virtual std::string getString(int id) const =0
Returns the string-value of the named (by its enum-value) attribute.
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)
Runs the given handler on the given file; returns if everything's ok.
Definition: XMLSubSys.cpp:149