SUMO - Simulation of Urban MObility
GNEAttributeCarrier.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // Abstract Base class for gui objects which carry attributes
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <algorithm>
33 #include "GNEAttributeCarrier.h"
34 #include "GNEUndoList.h"
35 
36 #ifdef CHECK_MEMORY_LEAKS
37 #include <foreign/nvwa/debug_new.h>
38 #endif // CHECK_MEMORY_LEAKS
39 
40 // ===========================================================================
41 // static members
42 // ===========================================================================
43 std::map<SumoXMLTag, std::vector<SumoXMLAttr> > GNEAttributeCarrier::_allowedAttributes;
44 std::vector<SumoXMLTag> GNEAttributeCarrier::_allowedTags;
45 std::set<SumoXMLAttr> GNEAttributeCarrier::_numericalAttrs;
46 std::set<SumoXMLAttr> GNEAttributeCarrier::_uniqueAttrs;
47 std::map<SumoXMLTag, std::map<SumoXMLAttr, std::vector<std::string> > > GNEAttributeCarrier::_discreteChoices;
48 
49 const std::string GNEAttributeCarrier::LOADED = "loaded";
50 const std::string GNEAttributeCarrier::GUESSED = "guessed";
51 const std::string GNEAttributeCarrier::MODIFIED = "modified";
52 const std::string GNEAttributeCarrier::APPROVED = "approved";
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
58  myTag(tag) {
59 }
60 
61 
62 bool
63 GNEAttributeCarrier::isValid(SumoXMLAttr key, const std::string& value) {
64  UNUSED_PARAMETER(value);
65  return std::find(getAttrs().begin(), getAttrs().end(), key) != getAttrs().end();
66 }
67 
68 
69 bool
70 GNEAttributeCarrier::isValidID(const std::string& value) {
71  return value.find_first_of(" \t\n\r@$%^&/|\\{}*'\";:<>") == std::string::npos;
72 }
73 
74 // ===========================================================================
75 // static methods
76 // ===========================================================================
77 
78 const std::vector<SumoXMLAttr>&
80  // define on first access
81  if (!_allowedAttributes.count(tag)) {
82  std::vector<SumoXMLAttr>& attrs = _allowedAttributes[tag];
83  switch (tag) {
84  case SUMO_TAG_EDGE:
85  attrs.push_back(SUMO_ATTR_ID);
86  attrs.push_back(SUMO_ATTR_FROM);
87  attrs.push_back(SUMO_ATTR_TO);
88  attrs.push_back(SUMO_ATTR_SPEED);
89  attrs.push_back(SUMO_ATTR_PRIORITY);
90  attrs.push_back(SUMO_ATTR_NUMLANES);
91  attrs.push_back(SUMO_ATTR_TYPE);
92  attrs.push_back(SUMO_ATTR_ALLOW);
93  attrs.push_back(SUMO_ATTR_DISALLOW);
94  //attrs.push_back(SUMO_ATTR_PREFER);
95  attrs.push_back(SUMO_ATTR_SHAPE);
96  attrs.push_back(SUMO_ATTR_LENGTH);
97  attrs.push_back(SUMO_ATTR_SPREADTYPE);
98  attrs.push_back(SUMO_ATTR_NAME);
99  attrs.push_back(SUMO_ATTR_WIDTH);
100  attrs.push_back(SUMO_ATTR_ENDOFFSET);
101  break;
102  case SUMO_TAG_JUNCTION:
103  attrs.push_back(SUMO_ATTR_ID);
104  /* virtual attribute from the combination of the actuall
105  * attributes SUMO_ATTR_X, SUMO_ATTR_Y */
106  attrs.push_back(SUMO_ATTR_POSITION);
107  attrs.push_back(SUMO_ATTR_TYPE);
108  attrs.push_back(SUMO_ATTR_SHAPE);
109  attrs.push_back(SUMO_ATTR_RADIUS);
110  attrs.push_back(SUMO_ATTR_KEEP_CLEAR);
111  break;
112  case SUMO_TAG_LANE:
113  attrs.push_back(SUMO_ATTR_ID);
114  attrs.push_back(SUMO_ATTR_SPEED);
115  attrs.push_back(SUMO_ATTR_ALLOW);
116  attrs.push_back(SUMO_ATTR_DISALLOW);
117  //attrs.push_back(SUMO_ATTR_PREFER);
118  attrs.push_back(SUMO_ATTR_WIDTH);
119  attrs.push_back(SUMO_ATTR_ENDOFFSET);
120  attrs.push_back(SUMO_ATTR_INDEX); // read-only attribute
121  break;
122  case SUMO_TAG_POI:
123  attrs.push_back(SUMO_ATTR_ID);
124  /* virtual attribute from the combination of the actuall
125  * attributes SUMO_ATTR_X, SUMO_ATTR_Y */
126  attrs.push_back(SUMO_ATTR_POSITION);
127  attrs.push_back(SUMO_ATTR_TYPE);
128  break;
129  case SUMO_TAG_CROSSING:
130  attrs.push_back(SUMO_ATTR_ID);
131  attrs.push_back(SUMO_ATTR_PRIORITY);
132  attrs.push_back(SUMO_ATTR_WIDTH);
133  attrs.push_back(SUMO_ATTR_EDGES);
134  break;
135  default:
136  WRITE_WARNING("allowed attributes for tag '" +
137  toString(tag) + "' not defined");
138  }
139  }
140  return _allowedAttributes[tag];
141 }
142 
143 
144 const std::vector<SumoXMLTag>&
146  // define on first access
147  if (_allowedTags.empty()) {
148  _allowedTags.push_back(SUMO_TAG_JUNCTION);
149  _allowedTags.push_back(SUMO_TAG_EDGE);
150  _allowedTags.push_back(SUMO_TAG_LANE);
151  }
152  return _allowedTags;
153 }
154 
155 
156 bool
158  // define on first access
159  if (_numericalAttrs.empty()) {
168  }
169  return _numericalAttrs.count(attr) == 1;
170 }
171 
172 
173 bool
175  // define on first access
176  if (_uniqueAttrs.empty()) {
177  _uniqueAttrs.insert(SUMO_ATTR_ID);
179  _uniqueAttrs.insert(SUMO_ATTR_TO);
183  }
184  return _uniqueAttrs.count(attr) == 1;
185 }
186 
187 
188 const std::vector<std::string>&
190  // define on first access
191  if (_discreteChoices.empty()) {
192  std::vector<std::string> choices;
194  for (std::vector<std::string>::const_iterator it = choices.begin(); it != choices.end(); ++it) {
197  }
198  }
199 
202 
204  for (std::vector<std::string>::const_iterator it = choices.begin(); it != choices.end(); ++it) {
206  }
207 
208  choices = SumoVehicleClassStrings.getStrings();
209  for (std::vector<std::string>::const_iterator it = choices.begin(); it != choices.end(); ++it) {
214  }
215 
218  }
219  return _discreteChoices[tag][attr];
220 }
221 
222 
223 bool
225  return (attr == SUMO_ATTR_ALLOW || attr == SUMO_ATTR_DISALLOW);
226 }
227 
228 /****************************************************************************/
229 
The information about how to spread the lanes from the given position.
static std::set< SumoXMLAttr > _numericalAttrs
SumoXMLTag
Numbers representing SUMO-XML - element names.
static StringBijection< SumoXMLNodeType > NodeTypes
Whether vehicles must keep the junction clear.
static bool isNumerical(SumoXMLAttr attr)
whether an attribute is numerical
static StringBijection< LaneSpreadFunction > LaneSpreadFunctions
static const std::string LOADED
feature is still unchanged after being loaded (implies approval)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
std::vector< std::string > getStrings() const
static const std::vector< std::string > & discreteChoices(SumoXMLTag tag, SumoXMLAttr attr)
return a list of discrete choices for this attribute or an empty vector
static bool isValidID(const std::string &value)
true if value is a valid sumo ID
static const std::string MODIFIED
feature has been manually modified (implies approval)
The turning radius at an intersection in m.
the edges of a route
static const std::vector< SumoXMLTag > & allowedTags()
get all editable attributes for tag.
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
static std::set< SumoXMLAttr > _uniqueAttrs
GNEAttributeCarrier(SumoXMLTag tag)
Constructor.
const std::vector< SumoXMLAttr > & getAttrs() const
static std::vector< SumoXMLTag > _allowedTags
static const std::string APPROVED
feature has been approved but not changed (i.e. after being reguessed)
static const std::vector< SumoXMLAttr > & allowedAttributes(SumoXMLTag tag)
get all editable attributes for tag.
static bool discreteCombinableChoices(SumoXMLTag tag, SumoXMLAttr attr)
return whether the given attribute allows for a combination of discrete values
static const std::string GUESSED
feature has been reguessed (may still be unchanged be we can&#39;t tell (yet)
static bool isUnique(SumoXMLAttr attr)
whether an attribute is unique (may not be edited for a multi-selection)
static std::map< SumoXMLTag, std::vector< SumoXMLAttr > > _allowedAttributes
virtual bool isValid(SumoXMLAttr key, const std::string &value)
static std::map< SumoXMLTag, std::map< SumoXMLAttr, std::vector< std::string > > > _discreteChoices