Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNETagProperties.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 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() || isMeanData()) {
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 integrity only in debug mode
93#ifdef DEBUG
94 // check that element must ist at least networkElement, Additional, or shape
96 throw ProcessError(TL("element must be at least networkElement, additional, TAZ, demandElement, dataElement or meanData"));
97 }
98 // check that element only is networkElement, Additional, or shape at the same time
100 throw ProcessError(TL("element can be only a networkElement, additional, demandElement, dataElement or meanData at the same time"));
101 }
102 // check that element only is shape, TAZ, or wire at the same time
103 if ((isShapeElement() + isTAZElement() + isWireElement()) > 1) {
104 throw ProcessError(TL("element can be only a shape, TAZ or wire element at the same time"));
105 }
106 // if element can mask the start and end position, check that bot attributes exist
108 throw ProcessError(TL("If attributes mask the start and end position, both attributes have to be defined"));
109 }
110 // check that master tag is valid
111 if (isChild() && myParentTags.empty()) {
112 throw FormatException("Master tags cannot be empty");
113 }
114 // check that master was defined
115 if (!isChild() && !myParentTags.empty()) {
116 throw FormatException("Tag doesn't support master elements");
117 }
118 // check reparent
119 if (!isChild() && canBeReparent()) {
120 throw FormatException("Only Child elements can be reparent");
121 }
122 // check vClass icons
124 throw FormatException("Tag require attribute SUMO_ATTR_VCLASS");
125 }
126 // check integrity of all attributes
127 for (const auto& attributeProperty : myAttributeProperties) {
128 attributeProperty.checkAttributeIntegrity();
129 // check that if attribute is vehicle classes, own a combination of Allow/disallow attribute
130 if (attributeProperty.isVClasses()) {
131 if ((attributeProperty.getAttr() != SUMO_ATTR_ALLOW) && (attributeProperty.getAttr() != SUMO_ATTR_DISALLOW) &&
132 (attributeProperty.getAttr() != SUMO_ATTR_CHANGE_LEFT) && (attributeProperty.getAttr() != SUMO_ATTR_CHANGE_RIGHT) &&
133 (attributeProperty.getAttr() != GNE_ATTR_STOPOEXCEPTION)) {
134 throw ProcessError(TL("Attributes aren't combinables"));
135 } else if ((attributeProperty.getAttr() == SUMO_ATTR_ALLOW) && !hasAttribute(SUMO_ATTR_DISALLOW)) {
136 throw ProcessError(TL("allow need a disallow attribute in the same tag"));
137 } else if ((attributeProperty.getAttr() == SUMO_ATTR_DISALLOW) && !hasAttribute(SUMO_ATTR_ALLOW)) {
138 throw ProcessError(TL("disallow need an allow attribute in the same tag"));
139 }
140 }
141 }
142#endif // DEBUG
143}
144
145
146const std::string&
148 // iterate over attribute properties
149 for (const auto& attributeProperty : myAttributeProperties) {
150 if (attributeProperty.getAttr() == attr) {
151 if (!attributeProperty.hasDefaultValue()) {
152 throw ProcessError(TLF("attribute '%' doesn't have a default value", attributeProperty.getAttrStr()));
153 } else {
154 return attributeProperty.getDefaultValue();
155 }
156 }
157 }
158 throw ProcessError(TLF("Attribute '%' not defined", toString(attr)));
159}
160
161
162void
164 if ((myAttributeProperties.size() + 1) >= MAXNUMBEROFATTRIBUTES) {
165 throw ProcessError(TLF("Maximum number of attributes for tag % exceeded", attributeProperty.getAttrStr()));
166 } else {
167 // Check that attribute wasn't already inserted
168 for (const auto& attrProperty : myAttributeProperties) {
169 if (attributeProperty.getAttr() == attrProperty.getAttr()) {
170 throw ProcessError(TLF("Attribute '%' already inserted", attributeProperty.getAttrStr()));
171 }
172 }
173 // insert AttributeProperties in vector
174 myAttributeProperties.push_back(attributeProperty);
175 myAttributeProperties.back().setTagPropertyParent(this);
176 }
177}
178
179
180const std::string&
184
185
186void
187GNETagProperties::setFieldString(const std::string& fieldString) {
188 myFieldString = fieldString;
189}
190
191
192unsigned int
196
197
200 // iterate over attribute properties
201 for (const auto& attributeProperty : myAttributeProperties) {
202 if ((attributeProperty.getAttr() == attr) || (attributeProperty.hasAttrSynonym() && (attributeProperty.getAttrSynonym() == attr))) {
203 return attributeProperty;
204 }
205 }
206 // throw error if these attribute doesn't exist
207 throw ProcessError(TLF("Attribute '%' doesn't exist", toString(attr)));
208}
209
210
211std::vector<GNEAttributeProperties>::const_iterator
213 return myAttributeProperties.begin();
214}
215
216
217std::vector<GNEAttributeProperties>::const_iterator
219 return myAttributeProperties.end();
220}
221
222
224GNETagProperties::at(int index) const {
225 return myAttributeProperties.at(index);
226}
227
228
229int
233
234
237 return myIcon;
238}
239
240
243 return myXMLTag;
244}
245
246
247const std::vector<SumoXMLTag>&
251
252
253bool
255 // iterate over attribute properties
256 for (const auto& attributeProperty : myAttributeProperties) {
257 if (attributeProperty.getAttr() == attr) {
258 return true;
259 }
260 }
261 return false;
262}
263
264
265bool
269
270
271bool
275
276
277bool
281
282
283bool
287
288
289bool
291 return (myTagType & DATAELEMENT) != 0;
292}
293
294
295bool
299
300
301bool
303 return (myTagType & DETECTOR) != 0;
304}
305
306
307bool
309 return (myTagType & CALIBRATOR) != 0;
310}
311
312
313bool
315 return (myTagType & SHAPE) != 0;
316}
317
318
319bool
321 return (myTagType & TAZELEMENT) != 0;
322}
323
324
325bool
327 return (myTagType & WIRE) != 0;
328}
329
330
331bool
333 return (myTagType & VTYPE) != 0;
334}
335
336
337bool
339 return (myTagType & VEHICLE) != 0;
340}
341
342
343bool
345 return (myTagType & ROUTE) != 0;
346}
347
348
349bool
351 return (myTagType & STOP) != 0;
352}
353
354
355bool
357 return (myTagType & WAYPOINT) != 0;
358}
359
360
361bool
363 return (myTagType & FLOW) != 0;
364}
365
366
367bool
369 return (myTagType & PERSON) != 0;
370}
371
372
373bool
375 return (myTagType & PERSONPLAN) != 0;
376}
377
378
379bool
381 return (myTagType & PERSONTRIP) != 0;
382}
383
384
385bool
387 return (myTagType & WALK) != 0;
388}
389
390
391bool
393 return (myTagType & RIDE) != 0;
394}
395
396
397bool
399 return (myTagType & STOPPERSON) != 0;
400}
401
402
403bool
405 return (myTagType & CONTAINER) != 0;
406}
407
408
409bool
413
414
415bool
417 return (myTagType & TRANSPORT) != 0;
418}
419
420bool
422 return (myTagType & TRANSHIP) != 0;
423}
424
425
426
427bool
431
432
433bool
435 return (myTagType & GENERICDATA) != 0;
436}
437
438
439bool
441 return (myTagType & MEANDATA) != 0;
442}
443
444
445bool
447 return (myTagProperty & CHILD) != 0;
448}
449
450
451bool
453 return (myTagType & SYMBOL) != 0;
454}
455
456
457bool
459 return (myTagType & INTERNALLANE) != 0;
460}
461
462
463bool
465 return (myTagProperty & NOTDRAWABLE) == 0;
466}
467
468
469bool
471 // note: By default all elements can be selected, except Tags with "NOTSELECTABLE"
472 return (myTagProperty & NOTSELECTABLE) == 0;
473}
474
475
476bool
478 return (myTagProperty & CLOSESHAPE) != 0;
479}
480
481
482bool
484 return (myTagProperty & GEOSHAPE) != 0;
485}
486
487
488bool
490 return (myTagProperty & DIALOG) != 0;
491}
492
493
494bool
496 // note: By default all elements support parameters, except Tags with "NOPARAMETERS"
497 return (myTagProperty & NOPARAMETERS) == 0;
498}
499
500
501bool
503 return (myTagProperty & RTREE) != 0;
504}
505
506
507bool
509 return (myTagProperty & REPARENT) != 0;
510}
511
512
513bool
517
518
519bool
523
524
525bool
529
530
531bool
533 return (myTagProperty & REQUIRE_PROJ) != 0;
534}
535
536
537bool
539 return (myTagProperty & VCLASS_ICON) != 0;
540}
541
542/****************************************************************************/
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
#define TL(string)
Definition MsgHandler.h:287
#define TLF(string,...)
Definition MsgHandler.h:288
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 isTransportPlan() const
return true if tag correspond to a transport
bool isMeanData() const
return true if tag correspond to a mean data element
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
bool isType() const
return true if tag correspond to a vehicle/person/container type 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