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
49GNETagProperties::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
84const std::string&
86 return myTagStr;
87}
88
89
90void
92 // check that element must ist at least networkElement, Additional, or shape
94 throw ProcessError("element must be at leas networkElement, additional, TAZ, 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, demandElement or dataElement at the same time");
99 }
100 // check that element only is shape, TAZ, or wire at the same time
101 if ((isShapeElement() + isTAZElement() + isWireElement()) > 1) {
102 throw ProcessError("element can be only a shape, TAZ or wire element at the same time");
103 }
104 // if element can mask the start and end position, check that bot attributes exist
106 throw ProcessError("If attribute mask the start and end position, bot attribute has to be defined");
107 }
108 // check that master tag is valid
109 if (isChild() && myParentTags.empty()) {
110 throw FormatException("Master tags cannot be empty");
111 }
112 // check that master was defined
113 if (!isChild() && !myParentTags.empty()) {
114 throw FormatException("Tag doesn't support master elements");
115 }
116 // check reparent
117 if (!isChild() && canBeReparent()) {
118 throw FormatException("Only Child elements can be reparent");
119 }
120 // check vClass icons
122 throw FormatException("Tag require attribute SUMO_ATTR_VCLASS");
123 }
124 // check integrity of all attributes
125 for (const auto& attributeProperty : myAttributeProperties) {
126 attributeProperty.checkAttributeIntegrity();
127 // check that if attribute is vehicle classes, own a combination of Allow/disallow attribute
128 if (attributeProperty.isVClasses()) {
129 if ((attributeProperty.getAttr() != SUMO_ATTR_ALLOW) && (attributeProperty.getAttr() != SUMO_ATTR_DISALLOW) &&
130 (attributeProperty.getAttr() != SUMO_ATTR_CHANGE_LEFT) && (attributeProperty.getAttr() != SUMO_ATTR_CHANGE_RIGHT) &&
131 (attributeProperty.getAttr() != GNE_ATTR_STOPOEXCEPTION)) {
132 throw ProcessError("Attributes aren't combinables");
133 } else if ((attributeProperty.getAttr() == SUMO_ATTR_ALLOW) && !hasAttribute(SUMO_ATTR_DISALLOW)) {
134 throw ProcessError("allow need a disallow attribute in the same tag");
135 } else if ((attributeProperty.getAttr() == SUMO_ATTR_DISALLOW) && !hasAttribute(SUMO_ATTR_ALLOW)) {
136 throw ProcessError("disallow need an allow attribute in the same tag");
137 }
138 }
139 }
140}
141
142
143const std::string&
145 // iterate over attribute properties
146 for (const auto& attributeProperty : myAttributeProperties) {
147 if (attributeProperty.getAttr() == attr) {
148 if (!attributeProperty.hasDefaultValue()) {
149 throw ProcessError("attribute '" + attributeProperty.getAttrStr() + "' doesn't have a default value");
150 } else {
151 return attributeProperty.getDefaultValue();
152 }
153 }
154 }
155 throw ProcessError("Attribute '" + toString(attr) + "' not defined");
156}
157
158
159void
161 if ((myAttributeProperties.size() + 1) >= MAXNUMBEROFATTRIBUTES) {
162 throw ProcessError("Maximum number of attributes for tag " + attributeProperty.getAttrStr() + " exceeded");
163 } else {
164 // Check that attribute wasn't already inserted
165 for (const auto& attrProperty : myAttributeProperties) {
166 if (attributeProperty.getAttr() == attrProperty.getAttr()) {
167 throw ProcessError("Attribute '" + attributeProperty.getAttrStr() + "' already inserted");
168 }
169 }
170 // insert AttributeProperties in vector
171 myAttributeProperties.push_back(attributeProperty);
172 myAttributeProperties.back().setTagPropertyParent(this);
173 }
174}
175
176
177const std::string&
179 return myFieldString;
180}
181
182
183void
184GNETagProperties::setFieldString(const std::string& fieldString) {
185 myFieldString = fieldString;
186}
187
188
189unsigned int
191 return myBackgroundColor;
192}
193
194
197 // iterate over attribute properties
198 for (const auto& attributeProperty : myAttributeProperties) {
199 if ((attributeProperty.getAttr() == attr) || (attributeProperty.hasAttrSynonym() && (attributeProperty.getAttrSynonym() == attr))) {
200 return attributeProperty;
201 }
202 }
203 // throw error if these attribute doesn't exist
204 throw ProcessError("Attribute '" + toString(attr) + "' doesn't exist");
205}
206
207
208std::vector<GNEAttributeProperties>::const_iterator
210 return myAttributeProperties.begin();
211}
212
213
214std::vector<GNEAttributeProperties>::const_iterator
216 return myAttributeProperties.end();
217}
218
219
221GNETagProperties::at(int index) const {
222 return myAttributeProperties.at(index);
223}
224
225
226int
228 return (int)myAttributeProperties.size();
229}
230
231
234 return myIcon;
235}
236
237
240 return myXMLTag;
241}
242
243
244const std::vector<SumoXMLTag>&
246 return myParentTags;
247}
248
249
250bool
252 // iterate over attribute properties
253 for (const auto& attributeProperty : myAttributeProperties) {
254 if (attributeProperty.getAttr() == attr) {
255 return true;
256 }
257 }
258 return false;
259}
260
261
262bool
264 return (myTagType & NETWORKELEMENT) != 0;
265}
266
267
268bool
270 return (myTagType & ADDITIONALELEMENT) != 0;
271}
272
273
274bool
277}
278
279
280bool
282 return (myTagType & DEMANDELEMENT) != 0;
283}
284
285
286bool
288 return (myTagType & DATAELEMENT) != 0;
289}
290
291
292bool
294 return (myTagType & STOPPINGPLACE) != 0;
295}
296
297
298bool
300 return (myTagType & DETECTOR) != 0;
301}
302
303
304bool
306 return (myTagType & CALIBRATOR) != 0;
307}
308
309
310bool
312 return (myTagType & SHAPE) != 0;
313}
314
315
316bool
318 return (myTagType & TAZELEMENT) != 0;
319}
320
321
322bool
324 return (myTagType & WIRE) != 0;
325}
326
327
328bool
330 return (myTagType & VTYPE) != 0;
331}
332
333
334bool
336 return (myTagType & VEHICLE) != 0;
337}
338
339
340bool
342 return (myTagType & ROUTE) != 0;
343}
344
345
346bool
348 return (myTagType & STOP) != 0;
349}
350
351
352bool
354 return (myTagType & WAYPOINT) != 0;
355}
356
357
358bool
360 return (myTagType & FLOW) != 0;
361}
362
363
364bool
366 return (myTagType & PERSON) != 0;
367}
368
369
370bool
372 return (myTagType & PERSONPLAN) != 0;
373}
374
375
376bool
378 return (myTagType & PERSONTRIP) != 0;
379}
380
381
382bool
384 return (myTagType & WALK) != 0;
385}
386
387
388bool
390 return (myTagType & RIDE) != 0;
391}
392
393
394bool
396 return (myTagType & STOPPERSON) != 0;
397}
398
399
400bool
402 return (myTagType & CONTAINER) != 0;
403}
404
405
406bool
408 return (myTagType & CONTAINERPLAN) != 0;
409}
410
411
412bool
414 return (myTagType & TRANSPORT) != 0;
415}
416
417bool
419 return (myTagType & TRANSHIP) != 0;
420}
421
422
423
424bool
426 return (myTagType & STOPCONTAINER) != 0;
427}
428
429
430bool
432 return (myTagType & GENERICDATA) != 0;
433}
434
435
436bool
438 return (myTagProperty & CHILD) != 0;
439}
440
441
442bool
444 return (myTagType & SYMBOL) != 0;
445}
446
447
448bool
450 return (myTagType & INTERNALLANE) != 0;
451}
452
453
454bool
456 return (myTagProperty & NOTDRAWABLE) == 0;
457}
458
459
460bool
462 // note: By default all elements can be selected, except Tags with "NOTSELECTABLE"
463 return (myTagProperty & NOTSELECTABLE) == 0;
464}
465
466
467bool
469 return (myTagProperty & CLOSESHAPE) != 0;
470}
471
472
473bool
475 return (myTagProperty & GEOSHAPE) != 0;
476}
477
478
479bool
481 return (myTagProperty & DIALOG) != 0;
482}
483
484
485bool
487 // note: By default all elements support parameters, except Tags with "NOPARAMETERS"
488 return (myTagProperty & NOPARAMETERS) == 0;
489}
490
491
492bool
494 return (myTagProperty & RTREE) != 0;
495}
496
497
498bool
500 return (myTagProperty & REPARENT) != 0;
501}
502
503
504bool
506 return (myTagProperty & MASKSTARTENDPOS) != 0;
507}
508
509
510bool
512 return (myTagProperty & CENTERAFTERCREATION) != 0;
513}
514
515
516bool
518 return (myTagProperty & EMBEDDED_ROUTE) != 0;
519}
520
521
522bool
524 return (myTagProperty & REQUIRE_PROJ) != 0;
525}
526
527
528bool
530 return (myTagProperty & VCLASS_ICON) != 0;
531}
532
533/****************************************************************************/
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
@ SUMO_ATTR_VCLASS
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 isContainer() const
return true if tag correspond to a container element
bool canBeReparent() const
return true if tag correspond to an element that can be reparent
bool isShapeElement() const
return true if tag correspond to a shape
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 vClassIcon() const
return true if tag correspond to an element that has vClass icons
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 hasEmbeddedRoute() const
return true if tag correspond to an element that owns an embedded route
bool isGenericData() const
return true if tag correspond to a generic data element
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 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 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.
bool isCalibrator() const
return true if tag correspond to a calibrator (Only used to group all detectors in the XML)
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 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 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
bool isAdditionalPureElement() const
return true if tag correspond to a pure additional element
std::string myTagStr
Sumo XML Tag vinculated wit this tag Property in String format.
bool isWireElement() const
return true if tag correspond to a Wire element
bool isWaypoint() const
return true if tag correspond to a waypoint element
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 an internal lane
GUIIcon myIcon
icon associated to this Tag
bool isAdditionalElement() const
return true if tag correspond to an additional element (note: this include TAZ, shapes and wires)
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