Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEAttributeProperties.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-2025 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
22
23#include "GNETagProperties.h"
25
26// ===========================================================================
27// method definitions
28// ===========================================================================
29
30GNEAttributeProperties::GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const Property attributeProperty,
31 const Edit editProperty, const std::string& definition) :
32 myTagPropertyParent(tagProperties),
33 myAttribute(attribute),
34 myAttrStr(toString(attribute)),
35 myAttributeProperty(attributeProperty),
36 myEditProperty(editProperty),
37 myDefinition(definition) {
38 // check build conditions (only in debug mode)
40 // add attribute in tag properties vector
41 tagProperties->myAttributeProperties.push_back(this);
42}
43
44
45GNEAttributeProperties::GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const Property attributeProperty,
46 const Edit editProperty, const std::string& definition, const std::string& defaultValue) :
47 myTagPropertyParent(tagProperties),
48 myAttribute(attribute),
49 myAttrStr(toString(attribute)),
50 myAttributeProperty(attributeProperty),
51 myEditProperty(editProperty),
52 myDefinition(definition),
53 myDefaultStringValue(defaultValue) {
54 // check build conditions (only in debug mode)
56 // parse default values
57 parseDefaultValues(defaultValue, true);
58 // add attribute in tag properties vector
59 tagProperties->myAttributeProperties.push_back(this);
60}
61
62
63GNEAttributeProperties::GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const Property attributeProperty,
64 const Edit editProperty, const std::string& definition, const std::string& defaultValueMask, const std::string& defaultValue) :
65 myTagPropertyParent(tagProperties),
66 myAttribute(attribute),
67 myAttrStr(toString(attribute)),
68 myAttributeProperty(attributeProperty),
69 myEditProperty(editProperty),
70 myDefinition(definition),
71 myDefaultStringValue(defaultValueMask) {
72 // check build conditions (only in debug mode)
74 // parse default values
75 parseDefaultValues(defaultValue, false);
76 // add attribute in tag properties vector
77 tagProperties->myAttributeProperties.push_back(this);
78}
79
80
81GNEAttributeProperties::GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const std::string& definition) :
82 myTagPropertyParent(tagProperties),
83 myAttribute(attribute),
84 myAttrStr(toString(attribute)),
85 myDefinition(definition) {
86 // check build conditions (only in debug mode)
88 // add attribute in tag properties vector
89 tagProperties->myAttributeProperties.push_back(this);
90}
91
92
94
95
96void
98 // check integrity only in debug mode
99#ifdef DEBUG
100 // check that there are properties
102 throw FormatException("Attr properties cannot be empty");
103 }
104 // check that positive attributes correspond only to a int, floats or SUMOTimes
105 if (isPositive() && !isNumerical()) {
106 throw FormatException("Only int, floats or SUMOTimes can be positive");
107 }
108 // check that secuential attributes correspond to a list
109 if (isSecuential() && !isList()) {
110 throw FormatException("Secuential property only is compatible with list properties");
111 }
112 // check that synonym attribute isn't nothing
114 throw FormatException("synonym attribute cannot be nothing");
115 }
116 // check that synonym attribute isn't nothing
117 if ((isFileOpen() || isFileSave()) && myFilenameExtensions.empty()) {
118 throw FormatException("Files requieres at least one extension");
119 }
120 // check that attribute sortables appears always in dialog
121 if (isSortable() && !isDialogEditor()) {
122 throw FormatException("Sortable attributes must be a dialog editor attribute");
123 }
124 // check that ranges are valid
125 if (hasAttrRange()) {
127 throw FormatException("empty range");
128 } else if ((myMinimumRange == 0) && (myMaximumRange == 0)) {
129 throw FormatException("non-defined range");
130 } else if ((myMaximumRange - myMinimumRange) <= 0) {
131 throw FormatException("invalid range");
132 }
133 }
134 // check that unique attributes aren't copyables
135 if (isUnique() && isCopyable()) {
136 throw FormatException("Unique attributes aren't copyables");
137 }
138#endif // DEBUG
139}
140
141
142void
143GNEAttributeProperties::setDiscreteValues(const std::vector<std::string>& discreteValues) {
144 if (isDiscrete()) {
145 myDiscreteValues = discreteValues;
146 } else {
147 throw FormatException("AttributeProperty doesn't support discrete values");
148 }
149}
150
151
152void
153GNEAttributeProperties::setFilenameExtensions(const std::vector<std::string>& extensions) {
154 if (isFileOpen() || isFileSave()) {
155 myFilenameExtensions = extensions;
156 } else {
157 throw FormatException("AttributeProperty doesn't support extensions values");
158 }
159}
160
161
162void
164 if (isActivatable()) {
165 myDefaultActivated = value;
166 } else {
167 throw FormatException("AttributeProperty doesn't support default activated");
168 }
169}
170
171
172void
174 if (hasAttrSynonym()) {
175 myAttrSynonym = synonym;
176 } else {
177 throw FormatException("AttributeProperty doesn't support synonyms");
178 }
179}
180
181
182void
183GNEAttributeProperties::setRange(const double minimum, const double maximum) {
184 if (hasAttrRange()) {
185 myMinimumRange = minimum;
186 myMaximumRange = maximum;
187 // check that given range is valid
189 throw FormatException("empty range");
190 } else if ((myMinimumRange == 0) && (myMaximumRange == 0)) {
191 throw FormatException("non-defined range");
192 } else if ((myMaximumRange - myMinimumRange) <= 0) {
193 throw FormatException("invalid range");
194 }
195 } else {
196 throw FormatException("AttributeProperty doesn't support ranges");
197 }
198}
199
200
201void
205
206
207void
208GNEAttributeProperties::setAlternativeName(const std::string& newAttrName) {
209 myAttrStr = newAttrName;
210}
211
212
217
218
219const std::string&
223
224
225const GNETagProperties*
229
230
231int
233 for (auto it = myTagPropertyParent->getAttributeProperties().begin(); it != myTagPropertyParent->getAttributeProperties().end(); it++) {
234 if ((*it)->getAttr() == myAttribute) {
235 return (int)(it - myTagPropertyParent->getAttributeProperties().begin());
236 }
237 }
238 throw ProcessError("Attribute wasn't found in myTagPropertyParent");
239}
240
241
242const std::string&
246
247
248const std::string&
252
253
254int
258
259
260double
264
265
270
271
272bool
276
277
278const RGBColor&
282
283
284const Position&
288
289
290bool
294
295
296std::string
298 if (isExtendedEditor()) {
299 return TL("Extended");
300 } else if (isGeoEditor()) {
301 return TL("GEO");
302 } else if (isFlowEditor()) {
303 return TL("Flow");
304 } else if (isNeteditEditor()) {
305 return TL("Netedit");
306 } else {
307 return TL("Internal");
308 }
309}
310
311
312std::string
314 std::string pre;
315 std::string type;
316 std::string plural;
317 std::string last;
318 // pre type
319 if (isList()) {
320 pre += TL("list of ");
321 if (isVClass()) {
322 plural = "es";
323 } else {
324 plural = "s";
325 }
326 }
327 if (isPositive()) {
328 pre += TL("non-negative ");
329 }
330 if (isDiscrete()) {
331 pre += TL("discrete ");
332 }
333 if (isUnique()) {
334 pre += TL("unique ");
335 }
336 // type
337 if (isInt()) {
338 type = TL("integer");
339 }
340 if (isFloat()) {
341 type = TL("float");
342 }
343 if (isSUMOTime()) {
344 type = TL("SUMOTime");
345 }
346 if (isBool()) {
347 type = TL("boolean");
348 }
349 if (isString()) {
350 type = TL("string");
351 }
352 if (isPosition()) {
353 type = TL("position");
354 }
355 if (isColor()) {
356 type = TL("color");
357 }
358 if (isVClass()) {
359 type = TL("vClass");
360 }
361 if (isFileOpen()) {
362 type = TL("filename");
363 last = TL("(Existent)");
364 }
365 if (isFileSave()) {
366 type = TL("filename");
367 }
368 if (isProbability()) {
369 type = TL("probability");
370 last = TL("[0, 1]");
371 }
372 if (isAngle()) {
373 type = TL("angle");
374 last = TL("[0, 360]");
375 }
376 return pre + type + plural + last;
377}
378
379
380const std::vector<std::string>&
384
385
386const std::vector<std::string>&
390
391
394 if (hasAttrSynonym()) {
395 return myAttrSynonym;
396 } else {
397 throw ProcessError("Attr doesn't support synonym");
398 }
399}
400
401
402double
404 if (hasAttrRange()) {
405 return myMinimumRange;
406 } else {
407 throw ProcessError("Attr doesn't support range");
408 }
409}
410
411
412double
414 if (hasAttrRange()) {
415 return myMaximumRange;
416 } else {
417 throw ProcessError("Attr doesn't support range");
418 }
419}
420
421
422bool
426
427
428bool
432
433bool
437
438
439bool
443
444
445bool
449
450
451bool
455
456
457bool
461
462
463bool
467
468
469bool
473
474
475bool
479
480
481bool
485
486
487bool
489 return isInt() || isFloat() || isSUMOTime();
490}
491
492
493bool
497
498
499bool
503
504
505bool
509
510
511bool
515
516
517bool
521
522
523bool
527
528
529bool
533
534
535bool
539
540
541bool
545
546
547bool
551
552
553bool
557
558
559bool
563
564
565bool
569
570
571bool
575
576
577bool
581
582
583bool
587
588bool
592
593
594bool
598
599
600bool
604
605
606bool
610
611
612bool
616
617
618bool
622
623
624bool
628
629
630bool
634
635
636bool
640
641
642void
644// check integrity only in debug mode
645#ifdef DEBUG
646 // empty definition aren't valid
647 if (myDefinition.empty()) {
648 throw FormatException("Missing definition for AttributeProperty '" + toString(myAttribute) + "'");
649 }
650 // if default value isn't empty, but attribute doesn't support default values, throw exception.
652 throw FormatException("AttributeProperty for '" + toString(myAttribute) + "' doesn't support default values");
653 }
654 // Attributes cannot be flowdefinition and enabilitablet at the same time
656 throw FormatException("Attribute '" + toString(myAttribute) + "' cannot be flow definition and activatable at the same time");
657 }
658 // Check that attribute wasn't already inserted
659 for (const auto& attrProperty : myTagPropertyParent->myAttributeProperties) {
660 if (attrProperty->getAttr() == myAttribute) {
661 throw ProcessError(TLF("Attribute '%' already inserted", toString(myAttribute)));
662 }
663 }
664#endif // DEBUG
665}
666
667
668void
669GNEAttributeProperties::parseDefaultValues(const std::string& defaultValue, const bool overWritteDefaultString) {
670 // in every case parse default value back (to avoid problems during comparations)
671 if (isInt()) {
672 myDefaultIntValue = GNEAttributeCarrier::parse<int>(defaultValue);
673 if (overWritteDefaultString) {
675 }
676 } else if (isFloat()) {
677 myDefaultDoubleValue = GNEAttributeCarrier::parse<double>(defaultValue);
678 if (overWritteDefaultString) {
680 }
681 } else if (isSUMOTime()) {
682 myDefaultTimeValue = GNEAttributeCarrier::parse<SUMOTime>(defaultValue);
683 if (overWritteDefaultString) {
685 }
686 } else if (isBool()) {
687 myDefaultBoolValue = GNEAttributeCarrier::parse<bool>(defaultValue);
688 if (overWritteDefaultString) {
690 }
691 } else if (isColor()) {
692 myDefaultColorValue = GNEAttributeCarrier::parse<RGBColor>(defaultValue);
693 if (overWritteDefaultString) {
695 }
696 } else if (isPosition()) {
697 myDefaultPositionValue = GNEAttributeCarrier::parse<Position>(defaultValue);
698 if (overWritteDefaultString) {
700 }
701 }
702}
703
704/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define TL(string)
Definition MsgHandler.h:304
#define TLF(string,...)
Definition MsgHandler.h:306
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_NOTHING
invalid attribute, must be the last one
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
static const std::string FALSE_STR
true value in string format(used for comparing boolean values in getAttribute(...))
static const std::string TRUE_STR
true value in string format (used for comparing boolean values in getAttribute(......
double getMaximumRange() const
get maximum range
bool isBasicEditor() const
return true if this attribute can be edited in basic editor
bool isExtendedEditor() const
return true if this attribute cannot be edited in editor
bool isVClass() const
return true if attribute is a VehicleClass
void checkBuildConstraints() const
check build constraints
bool isProbability() const
return true if attribute is a probability
const std::string & getDefaultStringValue() const
get default value in string format
bool isFlowEditor() const
return true if this attribute can be edited only in flow editor
bool myDefaultBoolValue
default bool value
bool isColor() const
return true if attribute is a color
void setTagPropertyParent(GNETagProperties *tagPropertyParent)
set tag property parent
void setDiscreteValues(const std::vector< std::string > &discreteValues)
set discrete values
void setSynonym(const SumoXMLAttr synonym)
set synonim
Position myDefaultPositionValue
get default position value
double myMinimumRange
minimun Range
bool isSVCPermission() const
return true if attribute is a VehicleClass
void setAlternativeName(const std::string &alternativeName)
set alternative name
int getPositionListed() const
get position in list (used in frames for listing attributes with certain sort)
bool isBool() const
return true if attribute is boolean
const std::string & getAttrStr() const
get XML Attribute in string format (can be updated using alternative name)
std::string getDescription() const
return a description of attribute
Edit myEditProperty
edit properties
bool myDefaultActivated
default activated (by default false)
bool isPosition() const
return true if attribute is a position
bool hasAttrRange() const
return true if Attr correspond to an element that only accept a range of values
const std::vector< std::string > & getFilenameExtensions() const
get filename extensions in string format used in open dialogs
SUMOTime getDefaultTimeValue() const
get default time value
bool getDefaultActivated() const
get default active value
bool isList() const
return true if attribute is a list
double getDefaultDoubleValue() const
get default double value
bool isAngle() const
return true if attribute is an angle
SumoXMLAttr myAttrSynonym
Attribute written in XML (If is SUMO_ATTR_NOTHING), original Attribute will be written)
bool isNumerical() const
return true if attribute is numerical (int or float)
bool isInt() const
return true if attribute is an integer
bool isDiscrete() const
return true if attribute is discrete
void setDefaultActivated(const bool value)
set default activated value
void parseDefaultValues(const std::string &defaultValue, const bool overWritteDefaultString)
parse default values
bool isCopyable() const
return true if attribute is copyable
bool isFileOpen() const
return true if attribute is a filename open
int getDefaultIntValue() const
get default int value
void setFilenameExtensions(const std::vector< std::string > &extensions)
set discrete values
const GNETagProperties * myTagPropertyParent
pointer to tagProperty parent
const std::string & getDefinition() const
get default value
double getMinimumRange() const
get minimum range
bool hasAttrSynonym() const
return true if Attr correspond to an element that will be written in XML with another name
bool isVType() const
return true if attribute is a VType or vTypeDistribution
bool isGeoEditor() const
return true if this attribute can be edited only in GEO editor
bool isUnique() const
return true if attribute is unique
bool isEditMode() const
return true if attribute can be modified in edit mode
SUMOTime myDefaultTimeValue
default time value
bool isCreateMode() const
return true if attribute can be modified in create mode
GNEAttributeProperties()=delete
invalidate default constructor
bool isSortable() const
return true if attribute can be used for sorting elements in dialogs
double myMaximumRange
maxium Range
bool isString() const
return true if attribute is a string
double myDefaultDoubleValue
default double value
std::vector< std::string > myDiscreteValues
discrete values that can take this Attribute (by default empty)
int myDefaultIntValue
default int value
SumoXMLAttr getAttrSynonym() const
get tag synonym
bool isFloat() const
return true if attribute is a float
const RGBColor & getDefaultColorValue() const
get default bool value
void checkAttributeIntegrity() const
check Attribute integrity (For example, throw an exception if tag has a Float default value,...
void setRange(const double minimum, const double maximum)
set range
bool isDialogEditor() const
return true if attribute can be modified in dialog editor
SumoXMLAttr myAttribute
XML Attribute.
std::string myDefinition
text with a definition of attribute
const GNETagProperties * getTagPropertyParent() const
get reference to tagProperty parent
Property myAttributeProperty
attribute properties
bool isSUMOTime() const
return true if attribute is a SUMOTime
bool hasDefaultValue() const
return true if attribute owns a default value
bool isFileSave() const
return true if attribute is a filename save
bool isFlow() const
return true if attribute is part of a flow definition
bool isActivatable() const
return true if attribute is activatable
RGBColor myDefaultColorValue
get default bool value
std::string getCategory() const
return category (based on Edit)
bool getDefaultBoolValue() const
get default bool value
bool requireUpdateGeometry() const
return true if attribute requires a update geometry in setAttribute(...)
bool isPositive() const
return true if attribute is positive
std::vector< std::string > myFilenameExtensions
filename extensions used in open dialogs (by default empty)
bool isNeteditEditor() const
return true if this attribute can be edited only in netedit editor
Edit
enum class with all edit modes
const std::vector< std::string > & getDiscreteValues() const
get discrete values
const Position & getDefaultPositionValue() const
get default position value
bool isAlwaysEnabled() const
return true if attribute is always enabled
SumoXMLAttr getAttr() const
get XML Attribute
bool isSecuential() const
return true if attribute is sequential
Property
enum class with all attribute properties
std::string myAttrStr
string with the Attribute in text format (to avoid unnecesaries toStrings(...) calls)
std::string myDefaultStringValue
default string value
const std::vector< const GNEAttributeProperties * > & getAttributeProperties() const
get all attribute properties
std::vector< const GNEAttributeProperties * > myAttributeProperties
vector with the attribute values vinculated with this Tag
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37