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-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 // 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  myXMLTag(SUMO_TAG_NOTHING),
45  myBackgroundColor(0) {
46 }
47 
48 
49 GNETagProperties::GNETagProperties(const SumoXMLTag tag, const int tagType, const int tagProperty, const GUIIcon icon, const SumoXMLTag XMLTag,
50  const std::vector<SumoXMLTag> parentTags, const unsigned int backgroundColor) :
51  myTag(tag),
52  myTagStr(toString(tag)),
53  myTagType(tagType),
54  myTagProperty(tagProperty),
55  myIcon(icon),
56  myXMLTag(XMLTag),
57  myParentTags(parentTags),
58  myFieldString(toString(tag)),
59  myBackgroundColor(backgroundColor) {
60 }
61 
62 
64 
65 
68  return myTag;
69 }
70 
71 
74  if (isDemandElement()) {
75  return Supermode::DEMAND;
76  } else if (isDataElement()) {
77  return Supermode::DATA;
78  } else {
79  return Supermode::NETWORK;
80  }
81 }
82 
83 
84 const std::string&
86  return myTagStr;
87 }
88 
89 
90 void
92  // check that element must ist at least networkElement, Additional, or shape
94  throw ProcessError("element must be at leas networkElement, additional, TAZ, shape, demandElement or dataElement");
95  }
96  // check that element only is networkElement, Additional, or shape at the same time
98  throw ProcessError("element can be only a networkElement, additional, TAZ, shape, demandElement or dataElement at the same time");
99  }
100  // if element can mask the start and end position, check that bot attributes exist
102  throw ProcessError("If attribute mask the start and end position, bot attribute has to be defined");
103  }
104  // check that master tag is valid
105  if (isChild() && myParentTags.empty()) {
106  throw FormatException("Master tags cannot be empty");
107  }
108  // check that master was defined
109  if (!isChild() && !myParentTags.empty()) {
110  throw FormatException("Tag doesn't support master elements");
111  }
112  // check reparent
113  if (!isChild() && canBeReparent()) {
114  throw FormatException("Only Child elements can be reparent");
115  }
116  // check integrity of all attributes
117  for (const auto& attributeProperty : myAttributeProperties) {
118  attributeProperty.checkAttributeIntegrity();
119  // check that if attribute is vehicle classes, own a combination of Allow/disallow attibute
120  if (attributeProperty.isVClasses()) {
121  if ((attributeProperty.getAttr() != SUMO_ATTR_ALLOW) && (attributeProperty.getAttr() != SUMO_ATTR_DISALLOW) &&
122  (attributeProperty.getAttr() != SUMO_ATTR_CHANGE_LEFT) && (attributeProperty.getAttr() != SUMO_ATTR_CHANGE_RIGHT) &&
123  (attributeProperty.getAttr() != GNE_ATTR_STOPOEXCEPTION)) {
124  throw ProcessError("Attributes aren't combinables");
125  } else if ((attributeProperty.getAttr() == SUMO_ATTR_ALLOW) && !hasAttribute(SUMO_ATTR_DISALLOW)) {
126  throw ProcessError("allow need a disallow attribute in the same tag");
127  } else if ((attributeProperty.getAttr() == SUMO_ATTR_DISALLOW) && !hasAttribute(SUMO_ATTR_ALLOW)) {
128  throw ProcessError("disallow need an allow attribute in the same tag");
129  }
130  }
131  }
132 }
133 
134 
135 const std::string&
137  // iterate over attribute properties
138  for (const auto& attributeProperty : myAttributeProperties) {
139  if (attributeProperty.getAttr() == attr) {
140  if (!attributeProperty.hasDefaultValue()) {
141  throw ProcessError("attribute '" + attributeProperty.getAttrStr() + "' doesn't have a default value");
142  } else {
143  return attributeProperty.getDefaultValue();
144  }
145  }
146  }
147  throw ProcessError("Attribute '" + toString(attr) + "' not defined");
148 }
149 
150 
151 void
153  if (isAttributeDeprecated(attributeProperty.getAttr())) {
154  throw ProcessError("Attribute '" + attributeProperty.getAttrStr() + "' is deprecated and cannot be inserted");
155  } else if ((myAttributeProperties.size() + 1) >= MAXNUMBEROFATTRIBUTES) {
156  throw ProcessError("Maximum number of attributes for tag " + attributeProperty.getAttrStr() + " exceeded");
157  } else {
158  // Check that attribute wasn't already inserted
159  for (const auto& attrProperty : myAttributeProperties) {
160  if (attributeProperty.getAttr() == attrProperty.getAttr()) {
161  throw ProcessError("Attribute '" + attributeProperty.getAttrStr() + "' already inserted");
162  }
163  }
164  // insert AttributeProperties in vector
165  myAttributeProperties.push_back(attributeProperty);
166  myAttributeProperties.back().setTagPropertyParent(this);
167  }
168 }
169 
170 
171 void
173  // Check that attribute wasn't already inserted
174  for (const auto& attributeProperty : myAttributeProperties) {
175  if (attributeProperty.getAttr() == attr) {
176  throw ProcessError("Attribute '" + toString(attr) + "' is deprecated but was inserted in list of attributes");
177  }
178  }
179  // add it into myDeprecatedAttributes
180  myDeprecatedAttributes.push_back(attr);
181 }
182 
183 
184 const std::string&
186  return myFieldString;
187 }
188 
189 
190 void
191 GNETagProperties::setFieldString(const std::string& fieldString) {
192  myFieldString = fieldString;
193 }
194 
195 
196 unsigned int
198  return myBackgroundColor;
199 }
200 
201 
204  // iterate over attribute properties
205  for (const auto& attributeProperty : myAttributeProperties) {
206  if ((attributeProperty.getAttr() == attr) || (attributeProperty.hasAttrSynonym() && (attributeProperty.getAttrSynonym() == attr))) {
207  return attributeProperty;
208  }
209  }
210  // throw error if these attribute doesn't exist
211  throw ProcessError("Attribute '" + toString(attr) + "' doesn't exist");
212 }
213 
214 
215 std::vector<GNEAttributeProperties>::const_iterator
217  return myAttributeProperties.begin();
218 }
219 
220 
221 std::vector<GNEAttributeProperties>::const_iterator
223  return myAttributeProperties.end();
224 }
225 
226 
228 GNETagProperties::at(int index) const {
229  return myAttributeProperties.at(index);
230 }
231 
232 
233 int
235  return (int)myAttributeProperties.size();
236 }
237 
238 
239 GUIIcon
241  return myIcon;
242 }
243 
244 
247  return myXMLTag;
248 }
249 
250 
251 const std::vector<SumoXMLTag>&
253  return myParentTags;
254 }
255 
256 
257 bool
259  // iterate over attribute properties
260  for (const auto& attributeProperty : myAttributeProperties) {
261  if (attributeProperty.getAttr() == attr) {
262  return true;
263  }
264  }
265  return false;
266 }
267 
268 
269 bool
271  return (myTagType & NETWORKELEMENT) != 0;
272 }
273 
274 
275 bool
277  return (myTagType & ADDITIONALELEMENT) != 0;
278 }
279 
280 
281 bool
283  return (myTagType & SHAPE) != 0;
284 }
285 
286 
287 bool
289  return (myTagType & TAZELEMENT) != 0;
290 }
291 
292 
293 bool
295  return (myTagType & DEMANDELEMENT) != 0;
296 }
297 
298 
299 bool
301  return (myTagType & DATAELEMENT) != 0;
302 }
303 
304 
305 bool
307  return (myTagType & STOPPINGPLACE) != 0;
308 }
309 
310 
311 bool
313  return (myTagType & DETECTOR) != 0;
314 }
315 
316 
317 bool
319  return (myTagType & VTYPE) != 0;
320 }
321 
322 
323 bool
325  return (myTagType & VEHICLE) != 0;
326 }
327 
328 
329 bool
331  return (myTagType & ROUTE) != 0;
332 }
333 
334 
335 bool
337  return (myTagType & STOP) != 0;
338 }
339 
340 
341 bool
343  return (myTagType & FLOW) != 0;
344 }
345 
346 
347 bool
349  return (myTagType & PERSON) != 0;
350 }
351 
352 
353 bool
355  return (myTagType & PERSONPLAN) != 0;
356 }
357 
358 
359 bool
361  return (myTagType & PERSONTRIP) != 0;
362 }
363 
364 
365 bool
367  return (myTagType & WALK) != 0;
368 }
369 
370 
371 bool
373  return (myTagType & RIDE) != 0;
374 }
375 
376 
377 bool
379  return (myTagType & STOPPERSON) != 0;
380 }
381 
382 
383 bool
385  return (myTagType & CONTAINER) != 0;
386 }
387 
388 
389 bool
391  return (myTagType & CONTAINERPLAN) != 0;
392 }
393 
394 
395 bool
397  return (myTagType & TRANSPORT) != 0;
398 }
399 
400 bool
402  return (myTagType & TRANSHIP) != 0;
403 }
404 
405 
406 
407 bool
409  return (myTagType & STOPCONTAINER) != 0;
410 }
411 
412 
413 bool
415  return (myTagType & GENERICDATA) != 0;
416 }
417 
418 
419 bool
421  return (myTagProperty & CHILD) != 0;
422 }
423 
424 
425 bool
427  return (myTagType & SYMBOL) != 0;
428 }
429 
430 
431 bool
433  return (myTagType & INTERNALLANE) != 0;
434 }
435 
436 
437 bool
439  return (myTagProperty & NOTDRAWABLE) == 0;
440 }
441 
442 
443 bool
445  // note: By default all elements can be selected, except Tags with "NOTSELECTABLE"
446  return (myTagProperty & NOTSELECTABLE) == 0;
447 }
448 
449 
450 bool
452  return (myTagProperty & CLOSESHAPE) != 0;
453 }
454 
455 
456 bool
458  return (myTagProperty & GEOSHAPE) != 0;
459 }
460 
461 
462 bool
464  return (myTagProperty & DIALOG) != 0;
465 }
466 
467 
468 bool
470  return (myTagProperty & MINIMUMCHILDREN) != 0;
471 }
472 
473 
474 bool
476  // note: By default all elements support parameters, except Tags with "NOPARAMETERS"
477  return (myTagProperty & NOPARAMETERS) == 0;
478 }
479 
480 
481 bool
483  return (myTagProperty & RTREE) != 0;
484 }
485 
486 
487 bool
489  return (myTagProperty & REPARENT) != 0;
490 }
491 
492 
493 bool
495  return (myTagProperty & WRITECHILDRENSEPARATE) != 0;
496 }
497 
498 
499 bool
501  return (myTagProperty & MASKSTARTENDPOS) != 0;
502 }
503 
504 
505 bool
507  return (myTagProperty & CENTERAFTERCREATION) != 0;
508 }
509 
510 
511 bool
513  return (myTagProperty & EMBEDDED_ROUTE) != 0;
514 }
515 
516 
517 bool
519  return (myTagProperty & REQUIERE_PROJ) != 0;
520 }
521 
522 
523 bool
525  return (std::find(myDeprecatedAttributes.begin(), myDeprecatedAttributes.end(), attr) != myDeprecatedAttributes.end());
526 }
527 
528 /****************************************************************************/
Supermode
@brie enum for supermodes
@ NETWORK
Network mode (Edges, junctions, etc..)
@ DATA
Data mode (edgeData, LaneData etc..)
@ DEMAND
Demand mode (Routes, Vehicles etc..)
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
@ GNE_ATTR_STOPOEXCEPTION
stop exceptions (virtual, used by edge and lanes)
@ SUMO_ATTR_CHANGE_LEFT
@ SUMO_ATTR_CHANGE_RIGHT
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
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
bool isTransportPlan() const
return true if tag correspond to a transport
bool isShape() const
return true if tag correspond to a shape
bool isContainer() const
return true if tag correspond to a container element
bool isAttributeDeprecated(SumoXMLAttr attr) const
return true if attribute of this tag is deprecated
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)
const std::vector< SumoXMLTag > & getParentTags() const
get parent tags
bool isTAZElement() const
return true if tag correspond to a TAZ element
bool isFlow() const
return true if tag correspond to a flow element
bool hasGEOShape() const
return true if tag correspond to an element that can use a geo shape
bool isGenericData() const
return true if tag correspond to a generic data element
void addDeprecatedAttribute(SumoXMLAttr attr)
add deprecated Attribute
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.
SumoXMLTag myXMLTag
Tag written in XML and used in GNENetHelper::AttributeCarriers.
bool embebbedRoute() const
return true if tag correspond to an element that owns a embebbed route
bool isChild() const
return true if tag correspond to an element child of another element (Example: E3->Entry/Exit)
bool isNetworkElement() const
return true if tag correspond to a network element
void addAttribute(const GNEAttributeProperties &attributeProperty)
add attribute (duplicated attributed aren't allowed)
const std::string & getFieldString() const
get field string (by default tag in string format)
bool isDataElement() const
return true if tag correspond to a data element
bool isTranshipPlan() const
return true if tag correspond to a tranship
bool isSelectable() const
return true if tag correspond to a selectable element
std::vector< SumoXMLTag > myParentTags
vector with master tags (used by child elements)
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 isPlacedInRTree() const
return true if Tag correspond to an element that has has to be placed in RTREE
std::string myFieldString
field string
const GNEAttributeProperties & at(int index) const
get attribute value
bool isPersonTrip() const
return true if tag correspond to a person trip
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.
unsigned int myBackgroundColor
background color (used in labels and textFields, by default white)
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...
Supermode getSupermode() const
get supermode associated with this tag
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
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.
int getNumberOfAttributes() const
get number of attributes
bool isStopPerson() const
return true if tag correspond to a person stop element
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
bool isContainerPlan() const
return true if tag correspond to a container plan
SumoXMLTag getXMLTag() const
get XML tag
bool isInternalLane() const
return true if tag correspond to a internal lane
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 isStopContainer() const
return true if tag correspond to a container stop element
bool hasAttribute(SumoXMLAttr attr) const
check if current TagProperties owns the attribute "attr"
unsigned int getBackGroundColor() const
get background color
bool isPerson() const
return true if tag correspond to a person element
~GNETagProperties()
destructor
bool requireProj() const
return true if tag correspond to an element that requires a geo projection
void setFieldString(const std::string &fieldString)
set field that will be drawn in TextFields/ComboBox/etc,
GNETagProperties()
default constructor