Eclipse SUMO - Simulation of Urban MObility
GNETagProperties.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-2020 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 // Abstract Base class for tag properties used in GNEAttributeCarrier
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 
26 #include "GNETagProperties.h"
27 
28 
29 // ===========================================================================
30 // static members
31 // ===========================================================================
32 
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
38 
40  myTag(SUMO_TAG_NOTHING),
41  myTagType(0),
42  myTagProperty(0),
43  myIcon(GUIIcon::EMPTY),
44  myTagSynonym(SUMO_TAG_NOTHING) {
45 }
46 
47 
48 GNETagProperties::GNETagProperties(SumoXMLTag tag, int tagType, int tagProperty, GUIIcon icon, const std::vector<SumoXMLTag>& masterTags, SumoXMLTag tagSynonym) :
49  myTag(tag),
50  myTagStr(toString(tag)),
51  myTagType(tagType),
52  myTagProperty(tagProperty),
53  myIcon(icon),
54  myMasterTags(masterTags),
55  myTagSynonym(tagSynonym) {
56 }
57 
58 
60 
61 
64  return myTag;
65 }
66 
67 
68 const std::string&
70  return myTagStr;
71 }
72 
73 
74 void
76  // check that element must ist at least networkElement, Additional, or shape
78  throw ProcessError("element must be at leas networkElement, additional, TAZ, shape, demandElement or dataElement");
79  }
80  // check that element only is networkElement, Additional, or shape at the same time
82  throw ProcessError("element can be only a networkElement, additional, TAZ, shape, demandElement or dataElement at the same time");
83  }
84  // if element can mask the start and end position, check that bot attributes exist
86  throw ProcessError("If attribute mask the start and end position, bot attribute has to be defined");
87  }
88  // check that synonym tag isn't nothing
90  throw FormatException("Synonym tag cannot be nothing");
91  }
92  // check that synonym was defined
94  throw FormatException("Tag doesn't support synonyms");
95  }
96  // check that master tag is valid
97  if (isSlave() && myMasterTags.empty()) {
98  throw FormatException("Master tags cannot be empty");
99  }
100  // check that master was defined
101  if (!isSlave() && !myMasterTags.empty()) {
102  throw FormatException("Tag doesn't support master elements");
103  }
104  // check integrity of all attributes
105  for (auto attributeProperty : myAttributeProperties) {
106  attributeProperty.checkAttributeIntegrity();
107  // check that if attribute is vehicle classes, own a combination of Allow/disallow attibute
108  if (attributeProperty.isVClasses()) {
109  if ((attributeProperty.getAttr() != SUMO_ATTR_ALLOW) && (attributeProperty.getAttr() != SUMO_ATTR_DISALLOW)) {
110  throw ProcessError("Attributes aren't combinables");
111  } else if ((attributeProperty.getAttr() == SUMO_ATTR_ALLOW) && !hasAttribute(SUMO_ATTR_DISALLOW)) {
112  throw ProcessError("allow need a disallow attribute in the same tag");
113  } else if ((attributeProperty.getAttr() == SUMO_ATTR_DISALLOW) && !hasAttribute(SUMO_ATTR_ALLOW)) {
114  throw ProcessError("disallow need an allow attribute in the same tag");
115  }
116  }
117  }
118 }
119 
120 
121 const std::string&
123  // iterate over attribute properties
124  for (const auto& i : myAttributeProperties) {
125  if (i.getAttr() == attr) {
126  if (!i.hasStaticDefaultValue()) {
127  throw ProcessError("attribute '" + i.getAttrStr() + "' doesn't have a default value");
128  } else {
129  return i.getDefaultValue();
130  }
131  }
132  }
133  throw ProcessError("Attribute '" + toString(attr) + "' not defined");
134 }
135 
136 
137 void
139  if (isAttributeDeprecated(attributeProperty.getAttr())) {
140  throw ProcessError("Attribute '" + attributeProperty.getAttrStr() + "' is deprecated and cannot be inserted");
141  } else if ((myAttributeProperties.size() + 1) >= MAXNUMBEROFATTRIBUTES) {
142  throw ProcessError("Maximum number of attributes for tag " + attributeProperty.getAttrStr() + " exceeded");
143  } else {
144  // Check that attribute wasn't already inserted
145  for (auto i : myAttributeProperties) {
146  if (i.getAttr() == attributeProperty.getAttr()) {
147  throw ProcessError("Attribute '" + attributeProperty.getAttrStr() + "' already inserted");
148  }
149  }
150  // insert AttributeProperties in vector
151  myAttributeProperties.push_back(attributeProperty);
152  myAttributeProperties.back().setTagPropertyParent(this);
153  }
154 }
155 
156 
157 void
159  // Check that attribute wasn't already inserted
160  for (auto i : myAttributeProperties) {
161  if (i.getAttr() == attr) {
162  throw ProcessError("Attribute '" + toString(attr) + "' is deprecated but was inserted in list of attributes");
163  }
164  }
165  // add it into myDeprecatedAttributes
166  myDeprecatedAttributes.push_back(attr);
167 }
168 
169 
172  // iterate over attribute properties
173  for (const auto& i : myAttributeProperties) {
174  if ((i.getAttr() == attr) || (i.hasAttrSynonym() && (i.getAttrSynonym() == attr))) {
175  return i;
176  }
177  }
178  // throw error if these attribute doesn't exist
179  throw ProcessError("Attribute '" + toString(attr) + "' doesn't exist");
180 }
181 
182 
183 std::vector<GNEAttributeProperties>::const_iterator
185  return myAttributeProperties.begin();
186 }
187 
188 
189 std::vector<GNEAttributeProperties>::const_iterator
191  return myAttributeProperties.end();
192 }
193 
194 
195 int
197  return (int)myAttributeProperties.size();
198 }
199 
200 
201 GUIIcon
203  return myIcon;
204 }
205 
206 
207 const std::vector<SumoXMLTag>&
209  return myMasterTags;
210 }
211 
212 
215  if (hasTagSynonym()) {
216  return myTagSynonym;
217  } else {
218  throw ProcessError("Tag doesn't have synonym");
219  }
220 }
221 
222 
223 bool
225  // iterate over attribute properties
226  for (const auto& i : myAttributeProperties) {
227  if (i.getAttr() == attr) {
228  return true;
229  }
230  }
231  return false;
232 }
233 
234 
235 bool
237  return (myTagType & NETWORKELEMENT) != 0;
238 }
239 
240 
241 bool
243  return (myTagType & ADDITIONALELEMENT) != 0;
244 }
245 
246 bool
248  return (myTagType & SHAPE) != 0;
249 }
250 
251 
252 bool
254  return (myTagType & TAZELEMENT) != 0;
255 }
256 
257 
258 bool
260  return (myTagType & DEMANDELEMENT) != 0;
261 }
262 
263 
264 bool
266  return (myTagType & DATAELEMENT) != 0;
267 }
268 
269 
270 bool
272  return (myTagType & STOPPINGPLACE) != 0;
273 }
274 
275 
276 bool
278  return (myTagType & DETECTOR) != 0;
279 }
280 
281 
282 bool
284  return (myTagType & VTYPE) != 0;
285 }
286 
287 
288 bool
290  return (myTagType & VEHICLE) != 0;
291 }
292 
293 bool
295  return (myTagType & ROUTE) != 0;
296 }
297 
298 
299 bool
301  return (myTagType & STOP) != 0;
302 }
303 
304 
305 bool
307  return (myTagType & PERSON) != 0;
308 }
309 
310 
311 bool
313  return (myTagType & PERSONPLAN) != 0;
314 }
315 
316 
317 bool
319  return (myTagType & PERSONTRIP) != 0;
320 }
321 
322 
323 bool
325  return (myTagType & WALK) != 0;
326 }
327 
328 
329 bool
331  return (myTagType & RIDE) != 0;
332 }
333 
334 
335 bool
337  return (myTagType & PERSONSTOP) != 0;
338 }
339 
340 
341 bool
343  return (myTagType & GENERICDATA) != 0;
344 }
345 
346 
347 bool
349  return (myTagProperty & SLAVE) != 0;
350 }
351 
352 
353 bool
355  return (myTagType & SYMBOL) != 0;
356 }
357 
358 
359 bool
361  return (myTagProperty & DRAWABLE) != 0;
362 }
363 
364 
365 bool
367  return (myTagProperty & SELECTABLE) != 0;
368 }
369 
370 
371 bool
373  return (myTagProperty & BLOCKMOVEMENT) != 0;
374 }
375 
376 
377 bool
379  return (myTagProperty & BLOCKSHAPE) != 0;
380 }
381 
382 
383 bool
385  return (myTagProperty & CLOSESHAPE) != 0;
386 }
387 
388 
389 bool
391  return (myTagProperty & GEOPOSITION) != 0;
392 }
393 
394 
395 bool
397  return (myTagProperty & GEOSHAPE) != 0;
398 }
399 
400 
401 bool
403  return (myTagProperty & SYNONYM) != 0;
404 }
405 
406 
407 bool
409  return (myTagProperty & DIALOG) != 0;
410 }
411 
412 
413 bool
415  return (myTagProperty & MINIMUMCHILDREN) != 0;
416 }
417 
418 
419 bool
421  // note: By default all Tags supports parameters, except Tags with "NOPARAMETERS"
422  return (myTagProperty & NOPARAMETERS) == 0;
423 }
424 
425 
426 bool
428  return (myTagProperty & PARAMETERSDOUBLE) != 0;
429 }
430 
431 
432 bool
434  return (myTagProperty & RTREE) != 0;
435 }
436 
437 
438 bool
440  return (myTagProperty & REPARENT) != 0;
441 }
442 
443 
444 bool
446  return (myTagProperty & WRITECHILDRENSEPARATE) != 0;
447 }
448 
449 
450 bool
452  return (myTagProperty & MASKSTARTENDPOS) != 0;
453 }
454 
455 
456 bool
458  return (myTagProperty & MASKXYZPOSITION) != 0;
459 }
460 
461 
462 bool
464  return (myTagProperty & CENTERAFTERCREATION) != 0;
465 }
466 
467 
468 bool
470  return (myTagProperty & PERSONPLAN_START_EDGE) != 0;
471 }
472 
473 
474 bool
476  return (myTagProperty & PERSONPLAN_END_EDGE) != 0;
477 }
478 
479 
480 bool
482  return (myTagProperty & PERSONPLAN_START_BUSSTOP) != 0;
483 }
484 
485 
486 bool
488  return (myTagProperty & PERSONPLAN_END_BUSSTOP) != 0;
489 }
490 
491 
492 bool
494  return (myTagProperty & PERSONPLAN_START_STOP) != 0;
495 }
496 
497 
498 bool
500  return (myTagProperty & PERSONPLAN_END_STOP) != 0;
501 }
502 
503 
504 bool
506  return (myTagProperty & EMBEDDED_ROUTE) != 0;
507 }
508 
509 
510 bool
512  return (std::find(myDeprecatedAttributes.begin(), myDeprecatedAttributes.end(), attr) != myDeprecatedAttributes.end());
513 }
514 
515 /****************************************************************************/
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_NOTHING
invalid tag
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_DISALLOW
@ SUMO_ATTR_ALLOW
@ SUMO_ATTR_ENDPOS
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
const std::string & getAttrStr() const
get XML Attribute
SumoXMLAttr getAttr() const
get XML Attribute
bool isVehicleType() const
return true if tag correspond to a vehicle type element
SumoXMLTag myTagSynonym
Tag written in XML (If is SUMO_TAG_NOTHING), original Tag name will be written)
bool hasDoubleParameters() const
return true if Tag correspond to an element that supports double parameters "key1=double1|key2=double...
bool isShape() const
return true if tag correspond to a shape
bool isAttributeDeprecated(SumoXMLAttr attr) const
return true if attribute of this tag is deprecated
bool canMaskXYZPositions() const
return true if tag correspond to an element that can mask the attributes "X", "Y" and "Z" position as...
std::vector< SumoXMLTag > myMasterTags
vector with master tags (used by slave elements)
bool personPlanEndBusStop() const
return true if tag correspond to a person plan that starts in a busStop
bool canBeReparent() const
return true if tag correspond to an element that can be reparent
std::vector< GNEAttributeProperties >::const_iterator end() const
get end of attribute values (used for iterate)
bool canBlockMovement() const
return true if tag correspond to an element that can block their movement
bool isPersonStop() const
return true if tag correspond to a person stop element
bool personPlanEndEdge() const
return true if tag correspond to a person plan that starts in an edge
bool hasTagSynonym() const
return true if tag correspond to an element that will be written in XML with another tag
bool hasGEOPosition() const
return true if tag correspond to an element that can use a geo position
bool isTAZElement() const
return true if tag correspond to a TAZ element
bool hasGEOShape() const
return true if tag correspond to an element that can use a geo shape
bool isSlave() const
return true if tag correspond to an element slave of another element (I.e. doesn't have their own ID)
bool isGenericData() const
return true if tag correspond to a generic data element
void addDeprecatedAttribute(SumoXMLAttr attr)
add deprecated Attribute
bool personPlanStartEdge() const
return true if tag correspond to a person plan that starts in an edge
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
bool isPersonPlan() const
return true if tag correspond to a person plan
const GNEAttributeProperties & getAttributeProperties(SumoXMLAttr attr) const
get attribute (throw error if doesn't exist)
int myTagType
Attribute Type.
bool embebbedRoute() const
return true if tag correspond to an element that owns a embebbed route
bool isNetworkElement() const
return true if tag correspond to a network element
void addAttribute(const GNEAttributeProperties &attributeProperty)
add attribute (duplicated attributed aren't allowed)
bool isDataElement() const
return true if tag correspond to a data element
bool isSelectable() const
return true if tag correspond to a selectable element
bool isRoute() const
return true if tag correspond to a route element
bool isVehicle() const
return true if tag correspond to a vehicle element
static const size_t MAXNUMBEROFATTRIBUTES
max number of attributes allowed for every tag
bool isStop() const
return true if tag correspond to a stop element
bool personPlanStartBusStop() const
return true if tag correspond to a person plan that starts in a busStop
bool isPlacedInRTree() const
return true if Tag correspond to an element that has has to be placed in RTREE
bool personPlanStartStop() const
return true if tag correspond to a person plan that starts in a Stop
bool isPersonTrip() const
return true if tag correspond to a person trip
bool canBlockShape() const
return true if tag correspond to an element that can block their shape
std::vector< GNEAttributeProperties > myAttributeProperties
vector with the attribute values vinculated with this Tag
GUIIcon getGUIIcon() const
get GUI icon associated to this Tag
bool hasParameters() const
return true if Tag correspond to an element that supports parameters "key1=value1|key2=value2|....
bool isStoppingPlace() const
return true if tag correspond to a detector (Only used to group all stoppingPlaces in the output XML)
SumoXMLTag myTag
Sumo XML Tag vinculated wit this tag Property.
bool isDrawable() const
return true if tag correspond to a drawable element
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
std::vector< GNEAttributeProperties >::const_iterator begin() const
get begin of attribute values (used for iterate)
bool hasMinimumNumberOfChildren() const
return true if tag correspond to an element that only have a limited number of children
bool canMaskStartEndPos() const
return true if tag correspond to an element that can mask the attributes "start" and "end" position a...
bool isDetector() const
return true if tag correspond to a shape (Only used to group all detectors in the XML)
void checkTagIntegrity() const
check Tag integrity (this include all their attributes)
bool canWriteChildrenSeparate() const
return true if tag correspond to an element that can write their child in a different file
bool canCenterCameraAfterCreation() const
return true if tag correspond to an element that center camera after creation
bool isRide() const
return true if tag correspond to a ride element
SumoXMLTag getTagSynonym() const
get tag synonym
bool hasDialog() const
return true if tag correspond to an element that can be edited using a dialog
std::vector< SumoXMLAttr > myDeprecatedAttributes
List with the deprecated Attributes.
std::string myTagStr
Sumo XML Tag vinculated wit this tag Property in String format.
const std::vector< SumoXMLTag > & getMasterTags() const
get master tags
int getNumberOfAttributes() const
get number of attributes
bool personPlanEndStop() const
return true if tag correspond to a person plan that starts in a Stop
bool canCloseShape() const
return true if tag correspond to an element that can close their shape
bool isDemandElement() const
return true if tag correspond to a demand element
const std::string & getDefaultValue(SumoXMLAttr attr) const
return the default value of the attribute of an element
int myTagProperty
Attribute properties.
bool isWalk() const
return true if tag correspond to a walk element
GUIIcon myIcon
icon associated to this Tag
bool isAdditionalElement() const
return true if tag correspond to an additional element
bool isSymbol() const
return true if tag correspond to a symbol element
bool hasAttribute(SumoXMLAttr attr) const
check if current TagProperties owns the attribute "attr"
bool isPerson() const
return true if tag correspond to a person element
~GNETagProperties()
destructor
GNETagProperties()
default constructor