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 ranges are valid
121 if (hasAttrRange()) {
123 throw FormatException("empty range");
124 } else if ((myMinimumRange == 0) && (myMaximumRange == 0)) {
125 throw FormatException("non-defined range");
126 } else if ((myMaximumRange - myMinimumRange) <= 0) {
127 throw FormatException("invalid range");
128 }
129 }
130 // check that unique attributes aren't copyables
131 if (isUnique() && isCopyable()) {
132 throw FormatException("Unique attributes aren't copyables");
133 }
134#endif // DEBUG
135}
136
137
138void
139GNEAttributeProperties::setDiscreteValues(const std::vector<std::string>& discreteValues) {
140 if (isDiscrete()) {
141 myDiscreteValues = discreteValues;
142 } else {
143 throw FormatException("AttributeProperty doesn't support discrete values");
144 }
145}
146
147
148void
149GNEAttributeProperties::setFilenameExtensions(const std::vector<std::string>& extensions) {
150 if (isFileOpen() || isFileSave()) {
151 myFilenameExtensions = extensions;
152 } else {
153 throw FormatException("AttributeProperty doesn't support extensions values");
154 }
155}
156
157
158void
160 if (isActivatable()) {
161 myDefaultActivated = value;
162 } else {
163 throw FormatException("AttributeProperty doesn't support default activated");
164 }
165}
166
167
168void
170 if (hasAttrSynonym()) {
171 myAttrSynonym = synonym;
172 } else {
173 throw FormatException("AttributeProperty doesn't support synonyms");
174 }
175}
176
177
178void
179GNEAttributeProperties::setRange(const double minimum, const double maximum) {
180 if (hasAttrRange()) {
181 myMinimumRange = minimum;
182 myMaximumRange = maximum;
183 // check that given range is valid
185 throw FormatException("empty range");
186 } else if ((myMinimumRange == 0) && (myMaximumRange == 0)) {
187 throw FormatException("non-defined range");
188 } else if ((myMaximumRange - myMinimumRange) <= 0) {
189 throw FormatException("invalid range");
190 }
191 } else {
192 throw FormatException("AttributeProperty doesn't support ranges");
193 }
194}
195
196
197void
201
202
203void
204GNEAttributeProperties::setAlternativeName(const std::string& newAttrName) {
205 myAttrStr = newAttrName;
206}
207
208
213
214
215const std::string&
219
220
221const GNETagProperties*
225
226
227int
229 for (auto it = myTagPropertyParent->getAttributeProperties().begin(); it != myTagPropertyParent->getAttributeProperties().end(); it++) {
230 if ((*it)->getAttr() == myAttribute) {
231 return (int)(it - myTagPropertyParent->getAttributeProperties().begin());
232 }
233 }
234 throw ProcessError("Attribute wasn't found in myTagPropertyParent");
235}
236
237
238const std::string&
242
243
244const std::string&
248
249
250int
254
255
256double
260
261
266
267
268bool
272
273
274const RGBColor&
278
279
280const Position&
284
285
286bool
290
291
292std::string
294 if (isExtendedEditor()) {
295 return TL("Extended");
296 } else if (isGeoEditor()) {
297 return TL("GEO");
298 } else if (isFlowEditor()) {
299 return TL("Flow");
300 } else if (isNeteditEditor()) {
301 return TL("Netedit");
302 } else {
303 return TL("Internal");
304 }
305}
306
307
308std::string
310 std::string pre;
311 std::string type;
312 std::string plural;
313 std::string last;
314 // pre type
315 if (isList()) {
316 pre += TL("list of ");
317 if (isVClass()) {
318 plural = "es";
319 } else {
320 plural = "s";
321 }
322 }
323 if (isPositive()) {
324 pre += TL("non-negative ");
325 }
326 if (isDiscrete()) {
327 pre += TL("discrete ");
328 }
329 if (isUnique()) {
330 pre += TL("unique ");
331 }
332 // type
333 if (isInt()) {
334 type = TL("integer");
335 }
336 if (isFloat()) {
337 type = TL("float");
338 }
339 if (isSUMOTime()) {
340 type = TL("SUMOTime");
341 }
342 if (isBool()) {
343 type = TL("boolean");
344 }
345 if (isString()) {
346 type = TL("string");
347 }
348 if (isPosition()) {
349 type = TL("position");
350 }
351 if (isColor()) {
352 type = TL("color");
353 }
354 if (isVClass()) {
355 type = TL("vClass");
356 }
357 if (isFileOpen()) {
358 type = TL("filename");
359 last = TL("(Existent)");
360 }
361 if (isFileSave()) {
362 type = TL("filename");
363 }
364 if (isProbability()) {
365 type = TL("probability");
366 last = TL("[0, 1]");
367 }
368 if (isAngle()) {
369 type = TL("angle");
370 last = TL("[0, 360]");
371 }
372 return pre + type + plural + last;
373}
374
375
376const std::vector<std::string>&
380
381
382const std::vector<std::string>&
386
387
390 if (hasAttrSynonym()) {
391 return myAttrSynonym;
392 } else {
393 throw ProcessError("Attr doesn't support synonym");
394 }
395}
396
397
398double
400 if (hasAttrRange()) {
401 return myMinimumRange;
402 } else {
403 throw ProcessError("Attr doesn't support range");
404 }
405}
406
407
408double
410 if (hasAttrRange()) {
411 return myMaximumRange;
412 } else {
413 throw ProcessError("Attr doesn't support range");
414 }
415}
416
417
418bool
422
423
424bool
428
429bool
433
434
435bool
439
440
441bool
445
446
447bool
451
452
453bool
457
458
459bool
463
464
465bool
469
470
471bool
475
476
477bool
481
482
483bool
485 return isInt() || isFloat() || isSUMOTime();
486}
487
488
489bool
493
494
495bool
499
500
501bool
505
506
507bool
511
512
513bool
517
518
519bool
523
524
525bool
529
530
531bool
535
536
537bool
541
542
543bool
547
548
549bool
553
554
555bool
559
560
561bool
565
566
567bool
571
572
573bool
577
578
579bool
583
584
585bool
589
590
591bool
595
596
597bool
601
602
603bool
607
608
609bool
613
614
615bool
619
620
621bool
625
626
627bool
631
632
633void
635// check integrity only in debug mode
636#ifdef DEBUG
637 // empty definition aren't valid
638 if (myDefinition.empty()) {
639 throw FormatException("Missing definition for AttributeProperty '" + toString(myAttribute) + "'");
640 }
641 // if default value isn't empty, but attribute doesn't support default values, throw exception.
643 throw FormatException("AttributeProperty for '" + toString(myAttribute) + "' doesn't support default values");
644 }
645 // Attributes cannot be flowdefinition and enabilitablet at the same time
647 throw FormatException("Attribute '" + toString(myAttribute) + "' cannot be flow definition and activatable at the same time");
648 }
649 // Check that attribute wasn't already inserted
650 for (const auto& attrProperty : myTagPropertyParent->myAttributeProperties) {
651 if (attrProperty->getAttr() == myAttribute) {
652 throw ProcessError(TLF("Attribute '%' already inserted", toString(myAttribute)));
653 }
654 }
655#endif // DEBUG
656}
657
658
659void
660GNEAttributeProperties::parseDefaultValues(const std::string& defaultValue, const bool overWritteDefaultString) {
661 // in every case parse default value back (to avoid problems during comparations)
662 if (isInt()) {
663 myDefaultIntValue = GNEAttributeCarrier::parse<int>(defaultValue);
664 if (overWritteDefaultString) {
666 }
667 } else if (isFloat()) {
668 myDefaultDoubleValue = GNEAttributeCarrier::parse<double>(defaultValue);
669 if (overWritteDefaultString) {
671 }
672 } else if (isSUMOTime()) {
673 myDefaultTimeValue = GNEAttributeCarrier::parse<SUMOTime>(defaultValue);
674 if (overWritteDefaultString) {
676 }
677 } else if (isBool()) {
678 myDefaultBoolValue = GNEAttributeCarrier::parse<bool>(defaultValue);
679 if (overWritteDefaultString) {
681 }
682 } else if (isColor()) {
683 myDefaultColorValue = GNEAttributeCarrier::parse<RGBColor>(defaultValue);
684 if (overWritteDefaultString) {
686 }
687 } else if (isPosition()) {
688 myDefaultPositionValue = GNEAttributeCarrier::parse<Position>(defaultValue);
689 if (overWritteDefaultString) {
691 }
692 }
693}
694
695/****************************************************************************/
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
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