17 #ifndef GNEAttributeCarrier_h 18 #define GNEAttributeCarrier_h 99 AttributeValues(
int attributeProperty,
int positionListed,
const std::string& definition,
const std::string& defaultValue,
const std::vector<std::string>& discreteValues,
SumoXMLAttr synonym);
235 void addAttribute(
SumoXMLAttr attr,
int attributeProperty,
const std::string& definition,
const std::string& defaultValue, std::vector<std::string> discreteValues = std::vector<std::string>(),
SumoXMLAttr synonym =
SUMO_ATTR_NOTHING);
238 void addAttribute(
SumoXMLAttr attr,
int attributeProperty,
const std::string& definition,
const std::string& defaultValue,
SumoXMLAttr synonym);
247 std::map<SumoXMLAttr, AttributeValues>::const_iterator begin()
const;
250 std::map<SumoXMLAttr, AttributeValues>::const_iterator end()
const;
253 int getNumberOfAttributes()
const;
274 bool isNetElement()
const;
277 bool isAdditional()
const;
280 bool isShape()
const;
283 bool isStoppingPlace()
const;
286 bool isDetector()
const;
289 bool isDrawable()
const;
292 bool isSelectable()
const;
295 bool canBlockMovement()
const;
298 bool canBlockShape()
const;
301 bool canCloseShape()
const;
304 bool hasGEOPosition()
const;
307 bool hasGEOShape()
const;
310 bool hasParent()
const;
313 bool hasTagSynonym()
const;
316 bool hasDialog()
const;
319 bool hasMinimumNumberOfChilds()
const;
322 bool canBeReparent()
const;
325 bool canAutomaticSortChilds()
const;
328 bool canWriteChildsSeparate()
const;
331 bool isAttributeDeprecated(
SumoXMLAttr attr)
const;
429 const std::string
getID()
const;
435 static std::vector<SumoXMLTag>
allowedTags(
bool onlyDrawables);
495 static T
parse(
const std::string&
string);
501 parse<T>(net, value);
513 static T
parse(
GNENet* net,
const std::string& value);
517 static std::string
parseIDs(
const std::vector<T>& ACs);
526 template <
typename T>
528 bool parsedOk =
true;
532 if (tagProperties.isAttributeDeprecated(attribute)) {
539 std::string defaultValue, parsedAttribute;
541 const auto& attrProperties = tagProperties.getAttribute(attribute);
543 std::string additionalOfWarningMessage;
544 if (objectID !=
"") {
545 additionalOfWarningMessage =
toString(tag) +
" with ID '" + objectID +
"'";
547 additionalOfWarningMessage =
toString(tag);
550 if (attrProperties.isNumerical() || attrProperties.isBool()) {
556 parsedAttribute = attrs.
get<std::string>(attribute, objectID.c_str(), parsedOk,
false);
558 if (parsedOk && !canParse<T>(parsedAttribute)) {
561 if (!attrProperties.isVClass()) {
562 parsedAttribute = defaultValue;
566 std::string errorFormat;
569 if (parsedAttribute.empty()) {
570 errorFormat =
"ID cannot be empty; ";
573 errorFormat =
"'" + parsedAttribute +
"' contains invalid characters; ";
578 if (attrProperties.isInt()) {
579 if (canParse<int>(parsedAttribute)) {
581 int parsedIntAttribute = parse<int>(parsedAttribute);
583 if (attrProperties.isPositive() && (parsedIntAttribute < 0)) {
584 errorFormat =
"Cannot be negative; ";
586 }
else if (attrProperties.isntZero() && (parsedIntAttribute == 0)) {
587 errorFormat =
"Cannot be zero; ";
590 }
else if (canParse<double>(parsedAttribute)) {
591 errorFormat =
"Float cannot be reinterpreted as int; ";
594 errorFormat =
"Cannot be parsed to int; ";
599 if (attrProperties.isFloat()) {
600 if (canParse<double>(parsedAttribute)) {
602 double parsedDoubleAttribute = parse<double>(parsedAttribute);
604 if (attrProperties.isPositive() && (parsedDoubleAttribute < 0)) {
605 errorFormat =
"Cannot be negative; ";
607 }
else if (attrProperties.isntZero() && (parsedDoubleAttribute == 0)) {
608 errorFormat =
"Cannot be zero; ";
612 errorFormat =
"Cannot be parsed to float; ";
617 if (attrProperties.isTime()) {
618 if (canParse<double>(parsedAttribute)) {
620 if (parse<double>(parsedAttribute) < 0) {
621 errorFormat =
"Time cannot be negative; ";
625 errorFormat =
"Cannot be parsed to time; ";
630 if (attrProperties.isProbability()) {
631 if (canParse<double>(parsedAttribute)) {
633 if (parse<double>(parsedAttribute) < 0) {
634 errorFormat =
"Probability cannot be smaller than 0; ";
636 }
else if (parse<double>(parsedAttribute) > 1) {
637 errorFormat =
"Probability cannot be greather than 1; ";
641 errorFormat =
"Cannot be parsed to probability; ";
646 if (attrProperties.isDiscrete()) {
648 auto finder = std::find(attrProperties.getDiscreteValues().begin(), attrProperties.getDiscreteValues().end(), parsedAttribute);
650 if (finder == attrProperties.getDiscreteValues().end()) {
651 errorFormat =
"value is not within the set of allowed values for attribute '" +
toString(attribute) +
"'";
656 if (attrProperties.isColor() && !canParse<RGBColor>(parsedAttribute)) {
657 errorFormat =
"Invalid RGB format or named color; ";
661 if (attrProperties.isFilename()) {
663 errorFormat =
"Filename contains invalid characters; ";
665 }
else if (parsedAttribute.empty()) {
666 errorFormat =
"Filename cannot be empty; ";
672 errorFormat =
"name contains invalid characters; ";
676 if (attrProperties.isVClass()) {
678 errorFormat =
"List of VClasses isn't valid; ";
679 parsedAttribute = defaultValue;
685 errorFormat =
"Is not a part of defined set of Vehicle Classes; ";
689 errorFormat =
"Is not a part of defined set of Gui Vehicle Shapes; ";
693 errorFormat =
"RouteProbe ID contains invalid characters; ";
698 errorFormat =
"List of edges cannot be empty; ";
703 errorFormat =
"List of lanes cannot be empty; ";
709 if (attrProperties.isOptional() && attrProperties.hasDefaultValue()) {
710 parsedAttribute = attrProperties.getDefaultValue();
712 WRITE_WARNING(
"Format of essential " + attrProperties.getDescription() +
" attribute '" +
toString(attribute) +
"' of " +
713 additionalOfWarningMessage +
" is invalid; " + errorFormat +
toString(tag) +
" cannot be created");
717 parsedAttribute = defaultValue;
722 if (attrProperties.isOptional() && attrProperties.hasDefaultValue()) {
723 parsedAttribute = attrProperties.getDefaultValue();
725 WRITE_WARNING(
"Essential " + attrProperties.getDescription() +
" attribute '" +
toString(attribute) +
"' of " +
726 additionalOfWarningMessage +
" is missing; " +
toString(tag) +
" cannot be created");
730 parsedAttribute = defaultValue;
734 return parse<T>(parsedAttribute);
bool mySelected
boolean to check if this AC is selected (instead of GUIGlObjectStorage)
static const std::string FEATURE_APPROVED
feature has been approved but not changed (i.e. after being reguessed)
bool isSVCPermission() const
return true if atribute is a VehicleClass
bool isOptional() const
return true if atribute is optional
std::map< SumoXMLAttr, AttributeValues > myAttributeValues
map with the attribute values vinculated with this Tag
static const std::string FEATURE_MODIFIED
feature has been manually modified (implies approval)
SumoXMLTag
Numbers representing SUMO-XML - element names.
AttributeValues()
default constructor
static std::vector< SumoXMLTag > allowedAdditionalTags(bool onlyDrawables)
get all editable for tag additional elements
int myAttributeProperty
Property of attribute.
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name) ...
const SumoXMLTag myTag
the xml tag to which this attribute carrier corresponds
virtual bool addGenericParameter(const std::string &key, const std::string &value)=0
add generic parameter
GNEAttributeCarrier & operator=(const GNEAttributeCarrier &src)=delete
Invalidated assignment operator.
bool isTime() const
return true if atribute is time
virtual bool updateGenericParameterValue(const std::string &key, const std::string &newValue)=0
update value generic parameter
GUIIcon
An enumeration of icons used by the gui applications.
SumoXMLTag myTagSynonym
Tag written in XML (If is SUMO_TAG_NOTHING), original Tag name will be written)
bool isBool() const
return true if atribute is boolean
Stores the information about how to visualize structures.
static std::map< SumoXMLTag, TagValues > myAllowedTags
map with the tags values
std::string getDescription() const
return a description of attribute
static std::string parseIDs(const std::vector< T > &ACs)
parses a list of specific Attribute Carriers into a string of IDs
static int getHigherNumberOfAttributes()
return the number of attributes of the tag with the most highter number of attributes ...
static T parseAttributeFromXML(const SUMOSAXAttributes &attrs, const std::string &objectID, const SumoXMLTag tag, const SumoXMLAttr attribute, bool &abort)
Parse attribute from XML and show warnings if there are problems parsing it.
bool hasAttrSynonym() const
return true if Attr correspond to an element that will be written in XML with another name ...
std::vector< std::string > myDiscreteValues
discrete values that can take this Attribute (by default empty)
FXIcon * getIcon() const
get FXIcon associated to this AC
A NBNetBuilder extended by visualisation and editing capabilities.
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
virtual std::string getAttribute(SumoXMLAttr key) const =0
virtual std::vector< std::pair< std::string, std::string > > getGenericParameters() const =0
return generic parameters as vector of pairs format
bool isString() const
return true if atribute is a string
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
bool isVClass() const
return true if atribute is a VehicleClass
bool isList() const
return true if atribute is a list
virtual void selectAttributeCarrier(bool changeFlag=true)=0
#define WRITE_WARNING(msg)
virtual bool removeGenericParameter(const std::string &key)=0
remove generic parameter
bool isNumerical() const
return true if atribute is numerical (int or float)
static std::vector< SumoXMLTag > allowedTags(bool onlyDrawables)
get all editable for tag elements of all types
SumoXMLAttr getAttrSynonym() const
get tag synonym
SumoXMLAttr myAttrSynonym
Attribute written in XML (If is SUMO_ATTR_NOTHING), original Attribute will be written) ...
the function-object for an editing operation (abstract base)
std::string myDefinition
text with a definition of attribute
virtual std::string getPopUpID() const =0
get PopPup ID (Used in AC Hierarchy)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
virtual bool isValid(SumoXMLAttr key, const std::string &value)=0
Encapsulated SAX-Attributes.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
static const double INVALID_POSITION
default value for invalid positions (used by POIs and Polygons)
static void fillAttributeCarriers()
fill Attribute Carriers
bool isPositive() const
return true if atribute is positive
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
static std::vector< SumoXMLTag > allowedShapeTags(bool onlyDrawables)
get all editable for tag shape elements
virtual bool isAttributeCarrierSelected() const =0
check if attribute carrier is selected
AttrProperty
struct with the tag Properties
static const std::string FEATURE_GUESSED
feature has been reguessed (may still be unchanged be we can't tell (yet)
int getPositionListed() const
get position in list (used in frames for listing attributes with certain sort)
static bool parseStringToANDBool(const std::string &string)
parse a string of booleans (1 0 1 1....) using AND operation
const std::string getID() const
function to support debugging
const std::string & getDefaultValue() const
get default value
virtual ~GNEAttributeCarrier()
Destructor.
bool isColor() const
return true if atribute is a color
static bool isValidNetID(const std::string &value)
whether the given string is a valid id for a network element
bool canParseVehicleClasses(const std::string &classes)
Checks whether the given string contains only known vehicle classes.
A road/street connecting two junctions (netedit-version)
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
GNEAttributeCarrier(SumoXMLTag tag)
Constructor.
SumoXMLTag myParentTag
parent tag
static bool canParse(GNENet *net, const std::string &value, bool report)
true if a value of type T can be parsed from string
virtual std::string getAttributeForSelection(SumoXMLAttr key) const
method for getting the attribute in the context of object selection
int myPositionListed
listed position
std::string myDefaultValue
default value (by default empty)
const std::vector< std::string > & getDiscreteValues() const
get discrete values
virtual std::string getGenericParametersStr() const =0
return generic parameters in string format
static int getCircleResolution(const GUIVisualizationSettings &settings)
function to calculate circle resolution for all circles drawn in drawGL(...) functions ...
bool isCombinable() const
return true if atribute is combinable with other Attribute
std::vector< SumoXMLAttr > myDeprecatedAttributes
List with the deprecated Attributes.
bool isntZero() const
return true if atribute cannot be zero
bool isInt() const
return true if atribute is an integer
int myPositionListed
listed position
static const std::string FEATURE_LOADED
virtual std::string getHierarchyName() const =0
get Hierarchy Name (Used in AC Hierarchy)
virtual void unselectAttributeCarrier(bool changeFlag=true)=0
unselect attribute carrier using GUIGlobalSelection
int myTagProperty
Property of attribute.
bool isFloat() const
return true if atribute is a float
bool isDiscrete() const
return true if atribute is discrete
static std::vector< SumoXMLTag > allowedNetElementsTags(bool onlyDrawables)
get all editable for tag net elements
static const TagValues & getTagProperties(SumoXMLTag tag)
get Tag Properties
bool isProbability() const
return true if atribute is a probability
bool isUnique() const
return true if atribute is unique
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name) ...
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc.)
const std::string & getDefinition() const
get default value
GUIIcon myIcon
icon associated to this Tag
struct with the attribute Properties
bool isNonEditable() const
return true if atribute isn't editable
struct with the attribute Properties
bool isFilename() const
return true if atribute is a filename
virtual bool updateGenericParameter(const std::string &oldKey, const std::string &newKey)=0
update generic parameter
bool hasDefaultValue() const
return true if attribute owns a default value
virtual void setGenericParametersStr(const std::string &value)=0
set generic parameters in string format
SumoXMLTag getTag() const
get XML Tag assigned to this object
virtual void mouseOverObject(const GUIVisualizationSettings &s) const =0
method for check if mouse is over objects