17 #ifndef GNEAttributeCarrier_h 18 #define GNEAttributeCarrier_h 93 AttributeProperties(
int attributeProperty,
int positionListed,
const std::string& definition,
const std::string& defaultValue,
const std::vector<std::string>& discreteValues,
SumoXMLAttr synonym,
double minimum = 0,
double maximum = 0);
275 void checkTagIntegrity()
const;
278 void addAttribute(
SumoXMLAttr attr,
const int attributeProperty,
const std::string& definition,
const std::string& defaultValue, std::vector<std::string> discreteValues = std::vector<std::string>(),
SumoXMLAttr synonym =
SUMO_ATTR_NOTHING);
281 void addAttribute(
SumoXMLAttr attr,
const int attributeProperty,
const std::string& definition,
const std::string& defaultValue,
SumoXMLAttr synonym);
284 void addAttribute(
SumoXMLAttr attr,
const int attributeProperty,
const std::string& definition,
const std::string& defaultValue,
double minimum,
double maximum);
293 std::map<SumoXMLAttr, AttributeProperties>::const_iterator begin()
const;
296 std::map<SumoXMLAttr, AttributeProperties>::const_iterator end()
const;
299 int getNumberOfAttributes()
const;
320 bool isNetElement()
const;
323 bool isAdditional()
const;
326 bool isShape()
const;
332 bool isStoppingPlace()
const;
335 bool isDetector()
const;
338 bool isDrawable()
const;
341 bool isSelectable()
const;
344 bool canBlockMovement()
const;
347 bool canBlockShape()
const;
350 bool canCloseShape()
const;
353 bool hasGEOPosition()
const;
356 bool hasGEOShape()
const;
359 bool hasParent()
const;
362 bool hasTagSynonym()
const;
365 bool hasDialog()
const;
368 bool hasMinimumNumberOfChilds()
const;
371 bool hasGenericParameters()
const;
374 bool canBeReparent()
const;
377 bool canAutomaticSortChilds()
const;
380 bool canWriteChildsSeparate()
const;
383 bool canBePlacedOverView()
const;
386 bool canBePlacedOverEdge()
const;
389 bool canBePlacedOverLane()
const;
392 bool canBePlacedOverJunction()
const;
395 bool canBePlacedOverEdges()
const;
398 bool canBePlacedOverLanes()
const;
401 bool canMaskStartEndPos()
const;
404 bool canMaskXYZPositions()
const;
407 bool isAttributeDeprecated(
SumoXMLAttr attr)
const;
514 const std::string
getID()
const;
520 static std::vector<SumoXMLTag>
allowedTags(
bool onlyDrawables);
562 static T
parse(
const std::string&
string);
568 parse<T>(net, value);
580 static T
parse(
GNENet* net,
const std::string& value);
584 static std::string
parseIDs(
const std::vector<T>& ACs);
590 template <
typename T>
592 bool parsedOk =
true;
594 std::string defaultValue, parsedAttribute, additionalOfWarningMessage;
598 if (tagProperties.isAttributeDeprecated(attribute)) {
601 WRITE_WARNING(
"Attribute " +
toString(attribute) +
"' of " + tagProperties.getTagStr() +
" is deprecated and will not be loaded.");
607 const auto& attrProperties = tagProperties.getAttributeProperties(attribute);
609 if (objectID !=
"") {
610 additionalOfWarningMessage = tagProperties.getTagStr() +
" with ID '" + objectID +
"'";
612 additionalOfWarningMessage = tagProperties.getTagStr();
615 if (attrProperties.isNumerical() || attrProperties.isBool()) {
617 }
else if (attrProperties.isColor()) {
618 defaultValue =
"black";
619 }
else if (attrProperties.isposition()) {
620 defaultValue =
"0,0";
625 parsedAttribute = attrs.
get<std::string>(attribute, objectID.c_str(), parsedOk,
false);
627 if (parsedOk && !canParse<T>(parsedAttribute)) {
631 std::string errorFormat;
634 if (parsedAttribute.empty()) {
635 errorFormat =
"ID cannot be empty; ";
637 }
else if (tagProperties.isDetector()) {
640 errorFormat =
"Detector ID contains invalid characters; ";
644 errorFormat =
"ID contains invalid characters; ";
649 if (attrProperties.isInt()) {
650 if (canParse<int>(parsedAttribute)) {
652 int parsedIntAttribute = parse<int>(parsedAttribute);
654 if (attrProperties.isPositive() && (parsedIntAttribute < 0)) {
655 errorFormat =
"Cannot be negative; ";
657 }
else if (attrProperties.cannotBeZero() && (parsedIntAttribute == 0)) {
658 errorFormat =
"Cannot be zero; ";
661 }
else if (canParse<double>(parsedAttribute)) {
662 errorFormat =
"Float cannot be reinterpreted as int; ";
665 errorFormat =
"Cannot be parsed to int; ";
670 if (attrProperties.isFloat()) {
671 if (canParse<double>(parsedAttribute)) {
673 double parsedDoubleAttribute = parse<double>(parsedAttribute);
675 if (attrProperties.isPositive() && (parsedDoubleAttribute < 0)) {
676 errorFormat =
"Cannot be negative; ";
678 }
else if (attrProperties.cannotBeZero() && (parsedDoubleAttribute == 0)) {
679 errorFormat =
"Cannot be zero; ";
683 errorFormat =
"Cannot be parsed to float; ";
688 if (attrProperties.isposition()) {
690 if (attrProperties.isList()) {
692 if(!canParse<PositionVector>(parsedAttribute)) {
693 errorFormat =
"List of Positions aren't neither x,y nor x,y,z; ";
696 }
else if (!canParse<Position>(parsedAttribute)) {
697 errorFormat =
"Position is neither x,y nor x,y,z; ";
702 if (attrProperties.isTime()) {
703 if (canParse<double>(parsedAttribute)) {
705 if (parse<double>(parsedAttribute) < 0) {
706 errorFormat =
"Time cannot be negative; ";
710 errorFormat =
"Cannot be parsed to time; ";
715 if (attrProperties.isProbability()) {
716 if (canParse<double>(parsedAttribute)) {
718 double probability = parse<double>(parsedAttribute);
719 if (probability < 0) {
720 errorFormat =
"Probability cannot be smaller than 0; ";
722 }
else if (probability > 1) {
723 errorFormat =
"Probability cannot be greather than 1; ";
727 errorFormat =
"Cannot be parsed to probability; ";
732 if (attrProperties.hasAttrRange()) {
733 if (canParse<double>(parsedAttribute)) {
735 double range = parse<double>(parsedAttribute);
736 if (range < attrProperties.getMinimumRange()) {
737 errorFormat =
"Float cannot be smaller than " +
toString(attrProperties.getMinimumRange())+
"; ";
739 }
else if (range > attrProperties.getMaximumRange()) {
740 errorFormat =
"Float cannot be greather than " +
toString(attrProperties.getMaximumRange())+
"; ";
744 errorFormat =
"Cannot be parsed to float; ";
749 if (attrProperties.isDiscrete()) {
751 auto finder = std::find(attrProperties.getDiscreteValues().begin(), attrProperties.getDiscreteValues().end(), parsedAttribute);
753 if (finder == attrProperties.getDiscreteValues().end()) {
754 errorFormat =
"value is not within the set of allowed values for attribute '" +
toString(attribute) +
"'";
759 if (attrProperties.isColor() && !canParse<RGBColor>(parsedAttribute)) {
760 errorFormat =
"Invalid RGB format or named color; ";
764 if (attrProperties.isFilename()) {
766 errorFormat =
"Filename contains invalid characters; ";
768 }
else if (parsedAttribute.empty()) {
769 errorFormat =
"Filename cannot be empty; ";
775 errorFormat =
"name contains invalid characters; ";
779 if (attrProperties.isVClass()) {
781 errorFormat =
"List of VClasses isn't valid; ";
782 parsedAttribute = defaultValue;
788 errorFormat =
"Is not a part of defined set of Vehicle Classes; ";
792 errorFormat =
"Is not a part of defined set of Gui Vehicle Shapes; ";
796 errorFormat =
"RouteProbe ID contains invalid characters; ";
801 errorFormat =
"List of edges cannot be empty; ";
806 errorFormat =
"List of lanes cannot be empty; ";
811 errorFormat =
"List of vTypes contains invalid characters; ";
816 errorFormat =
"RouteProbe ID contains invalid characters; ";
822 if (attrProperties.isOptional() && attrProperties.hasDefaultValue()) {
823 parsedAttribute = attrProperties.getDefaultValue();
825 WRITE_WARNING(
"Format of essential " + attrProperties.getDescription() +
" attribute '" +
toString(attribute) +
"' of " +
826 additionalOfWarningMessage +
" is invalid; " + errorFormat + tagProperties.getTagStr() +
" cannot be created");
830 parsedAttribute = defaultValue;
833 }
else if (tagProperties.canMaskXYZPositions() && (attribute ==
SUMO_ATTR_POSITION)) {
837 parsedAttribute=
"0,0";
839 x = attrs.
get<std::string>(
SUMO_ATTR_X, objectID.c_str(), parsedOk,
false);
841 if(!canParse<double>(x)) {
842 WRITE_WARNING(
"Format of essential " + attrProperties.getDescription() +
" attribute '" +
toString(SUMO_ATTR_X) +
"' of " +
843 additionalOfWarningMessage +
" is invalid; Cannot be parsed to float; " + tagProperties.getTagStr() +
" cannot be created");
849 additionalOfWarningMessage +
" is missing; " + tagProperties.getTagStr() +
" cannot be created");
854 y = attrs.
get<std::string>(
SUMO_ATTR_Y, objectID.c_str(), parsedOk,
false);
856 if(!canParse<double>(y)) {
857 WRITE_WARNING(
"Format of essential " + attrProperties.getDescription() +
" attribute '" +
toString(SUMO_ATTR_Y) +
"' of " +
858 additionalOfWarningMessage +
" is invalid; Cannot be parsed to float; " + tagProperties.getTagStr() +
" cannot be created");
864 additionalOfWarningMessage +
" is missing; " + tagProperties.getTagStr() +
" cannot be created");
870 z = attrs.
get<std::string>(
SUMO_ATTR_Z, objectID.c_str(), parsedOk,
false);
872 if(!canParse<double>(z)) {
873 WRITE_WARNING(
"Format of optional " + attrProperties.getDescription() +
" attribute '" +
toString(SUMO_ATTR_Z) +
"' of " +
874 additionalOfWarningMessage +
" is invalid; Cannot be parsed to float; " + tagProperties.getTagStr() +
" cannot be created");
882 parsedAttribute = x +
"," + y;
884 parsedAttribute = x +
"," + y +
"," + z;
889 if (attrProperties.isOptional() && attrProperties.hasDefaultValue()) {
890 parsedAttribute = attrProperties.getDefaultValue();
892 WRITE_WARNING(
"Essential " + attrProperties.getDescription() +
" attribute '" +
toString(attribute) +
"' of " +
893 additionalOfWarningMessage +
" is missing; " + tagProperties.getTagStr() +
" cannot be created");
897 parsedAttribute = defaultValue;
901 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)
const TagProperties & myTagProperty
the xml tag to which this attribute carrier corresponds
bool hasAttrRange() const
return true if Attr correspond to an element that only accept a range of values
static const std::string FEATURE_MODIFIED
feature has been manually modified (implies approval)
static const TagProperties & getTagProperties(SumoXMLTag tag)
get Tag Properties
SumoXMLTag
Numbers representing SUMO-XML - element names.
GUIIcon myIcon
icon associated to this Tag
SumoXMLTag myParentTag
parent tag
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name) ...
static bool isValidListOfTypeID(const std::string &value)
whether the given string is a valid list of ids for an edge or vehicle type (empty aren't allowed) ...
SumoXMLAttr getAttrSynonym() const
get tag synonym
GNEAttributeCarrier & operator=(const GNEAttributeCarrier &src)=delete
Invalidated assignment operator.
GUIIcon
An enumeration of icons used by the gui applications.
bool isCombinable() const
return true if atribute is combinable with other Attribute
Stores the information about how to visualize structures.
std::string myDefaultValue
default value (by default empty)
struct with the attribute Properties
bool isFilename() const
return true if atribute is a filename
bool isPositive() const
return true if atribute is positive
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.
void checkAttributeIntegrity()
check Attribute integrity (For example, throw an exception if tag has a Float default value...
bool isposition() const
return true if atribute is a position
static std::vector< SumoXMLTag > allowedTagsByCategory(int tagPropertyCategory, bool onlyDrawables)
get tags of all editable element types using TagProperty Type (TAGPROPERTY_NETELEMENT, TAGPROPERTY_ADDITIONAL, etc.)
FXIcon * getIcon() const
get FXIcon associated to this AC
~AttributeProperties()
destructor
A NBNetBuilder extended by visualisation and editing capabilities.
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
bool isNumerical() const
return true if atribute is numerical (int or float)
bool isSecuential() const
return true if atribute is sequential
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
SumoXMLAttr myAttrSynonym
Attribute written in XML (If is SUMO_ATTR_NOTHING), original Attribute will be written) ...
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
virtual std::string getAttribute(SumoXMLAttr key) const =0
bool cannotBeZero() const
return true if atribute cannot be zero
virtual std::vector< std::pair< std::string, std::string > > getGenericParameters() const =0
return generic parameters as vector of pairs format
int getPositionListed() const
get position in list (used in frames for listing attributes with certain sort)
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
SumoXMLTag myTag
Sumo XML Tag vinculated wit this tag Property.
bool isProbability() const
return true if atribute is a probability
bool isNonEditable() const
return true if atribute isn't editable
virtual void selectAttributeCarrier(bool changeFlag=true)=0
#define WRITE_WARNING(msg)
bool isInt() const
return true if atribute is an integer
static TagProperties dummyTagProperty
dummy TagProperty used for reference some elements (for Example, dummyEdge)
bool isList() const
return true if atribute is a list
bool isColor() const
return true if atribute is a color
static std::vector< SumoXMLTag > allowedTags(bool onlyDrawables)
get tags of all editable element types
the function-object for an editing operation (abstract base)
virtual std::string getPopUpID() const =0
get PopPup ID (Used in AC Hierarchy)
double myMaximumRange
maxium Range
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
double getMaximumRange() const
get maximum range
virtual bool isValid(SumoXMLAttr key, const std::string &value)=0
std::vector< std::string > myDiscreteValues
discrete values that can take this Attribute (by default empty)
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.
bool isBool() const
return true if atribute is boolean
std::string getDescription() const
return a description of attribute
static void fillAttributeCarriers()
fill Attribute Carriers
static bool lanesConsecutives(const std::vector< GNELane *> &lanes)
check if lanes are consecutives
double getMinimumRange() const
get minimum range
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
static bool isValidDetectorID(const std::string &value)
whether the given string is a valid id for an detector
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)
bool isUnique() const
return true if atribute is unique
std::map< SumoXMLAttr, AttributeProperties > myAttributeProperties
map with the attribute values vinculated with this Tag
bool isVClass() const
return true if atribute is a VehicleClass
bool isSVCPermission() const
return true if atribute is a VehicleClass
const std::string getID() const
function to support debugging
AttributeProperties()
default constructor
virtual ~GNEAttributeCarrier()
Destructor.
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
bool isDiscrete() const
return true if atribute is discrete
GNEAttributeCarrier(SumoXMLTag tag)
Constructor.
bool isFloat() const
return true if atribute is a float
double myMinimumRange
minimun Range
static bool canParse(GNENet *net, const std::string &value, bool report)
true if a value of type T can be parsed from string
int myTagProperty
Property of attribute.
virtual std::string getAttributeForSelection(SumoXMLAttr key) const
method for getting the attribute in the context of object selection
std::string myDefinition
text with a definition of attribute
struct with the attribute Properties
const std::vector< std::string > & getDiscreteValues() const
get discrete values
const std::string & getTagStr() const
get tag assigned to this object in string format
bool isString() const
return true if atribute is a string
bool hasAttrSynonym() const
return true if Attr correspond to an element that will be written in XML with another name ...
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 ...
int myPositionListed
listed position
bool hasDefaultValue() const
return true if attribute owns a default value
int myPositionListed
listed position
static const std::string FEATURE_LOADED
virtual std::string getHierarchyName() const =0
get Hierarchy Name (Used in AC Hierarchy)
const std::string & getDefaultValue() const
get default value
const TagProperties & getTagProperty() const
get Tag Property assigned to this object
virtual void unselectAttributeCarrier(bool changeFlag=true)=0
unselect attribute carrier using GUIGlobalSelection
bool isTime() const
return true if atribute is time
std::vector< SumoXMLAttr > myDeprecatedAttributes
List with the deprecated Attributes.
const std::string & getDefinition() const
get default value
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name) ...
SumoXMLTag myTagSynonym
Tag written in XML (If is SUMO_TAG_NOTHING), original Tag name will be written)
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc.)
static std::map< SumoXMLTag, TagProperties > myTagProperties
map with the tags properties
int myAttributeProperty
Property of attribute.
std::string myTagStr
Sumo XML Tag vinculated wit this tag Property in String format.
virtual void setGenericParametersStr(const std::string &value)=0
set generic parameters in string format
bool isOptional() const
return true if atribute is optional
virtual void mouseOverObject(const GUIVisualizationSettings &s) const =0
method for check if mouse is over objects