From c67de4bbb3296a5b452f35d39ab7a46e96874028 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Fri, 4 Aug 2017 16:29:26 +0200 Subject: [PATCH] Mark attributes as 'derived in supertype' also in getArgumentType() --- src/ifcexpressparser/header.py | 12 ++++++++++-- src/ifcparse/Ifc2x3.h | 6 +++--- src/ifcparse/Ifc4.h | 6 +++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ifcexpressparser/header.py b/src/ifcexpressparser/header.py index 4aa3bdf4b8..87090ceace 100644 --- a/src/ifcexpressparser/header.py +++ b/src/ifcexpressparser/header.py @@ -17,6 +17,8 @@ # # ############################################################################### +import operator + import codegen import templates import documentation @@ -106,8 +108,14 @@ class Header(codegen.Base): argument_name_function_body_tail = (" return %s::getArgumentName(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' (void)i; throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range"); ' argument_name_function_body = argument_name_function_body_switch_stmt + argument_name_function_body_tail - - argument_type_function_body_switch_stmt = " switch (i) {%s}"%("".join(['case %d: return %s; '%(i+argument_start, mapping.make_argument_type(attr)) for i, attr in enumerate(type.attributes)])) if len(type.attributes) else "" + + derived = mapping.derived_in_supertype(type) + attribute_names = list(map(operator.attrgetter('name'), mapping.arguments(type))) + derived_in_supertype = set(derived) & set(attribute_names) + derived_in_supertype_indices = sorted(attribute_names.index(nm) for nm in derived_in_supertype) + attribute_type_cases = ['case %d: return IfcUtil::Argument_DERIVED; ' % idx for idx in derived_in_supertype_indices] + attribute_type_cases += ['case %d: return %s; '%(i+argument_start, mapping.make_argument_type(attr)) for i, attr in enumerate(type.attributes)] + argument_type_function_body_switch_stmt = " switch (i) {%s}"%("".join(attribute_type_cases)) if len(type.attributes) else "" argument_type_function_body_tail = (" return %s::getArgumentType(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' (void)i; throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range"); ' argument_type_function_body = argument_type_function_body_switch_stmt + argument_type_function_body_tail diff --git a/src/ifcparse/Ifc2x3.h b/src/ifcparse/Ifc2x3.h index 4451c532b1..9572a870b7 100644 --- a/src/ifcparse/Ifc2x3.h +++ b/src/ifcparse/Ifc2x3.h @@ -10847,7 +10847,7 @@ public: IfcSIUnitName::IfcSIUnitName Name() const; void setName(IfcSIUnitName::IfcSIUnitName v); virtual unsigned int getArgumentCount() const { return 4; } - virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const { switch (i) {case 2: return IfcUtil::Argument_ENUMERATION; case 3: return IfcUtil::Argument_ENUMERATION; } return IfcNamedUnit::getArgumentType(i); } + virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const { switch (i) {case 0: return IfcUtil::Argument_DERIVED; case 2: return IfcUtil::Argument_ENUMERATION; case 3: return IfcUtil::Argument_ENUMERATION; } return IfcNamedUnit::getArgumentType(i); } virtual Type::Enum getArgumentEntity(unsigned int i) const { switch (i) {case 2: return Type::IfcSIPrefix; case 3: return Type::IfcSIUnitName; } return IfcNamedUnit::getArgumentEntity(i); } virtual const char* getArgumentName(unsigned int i) const { switch (i) {case 2: return "Prefix"; case 3: return "Name"; } return IfcNamedUnit::getArgumentName(i); } virtual Argument* getArgument(unsigned int i) const { return entity->getArgument(i); } @@ -14253,7 +14253,7 @@ public: std::string UserDefinedTargetView() const; void setUserDefinedTargetView(std::string v); virtual unsigned int getArgumentCount() const { return 10; } - virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const { switch (i) {case 6: return IfcUtil::Argument_ENTITY_INSTANCE; case 7: return IfcUtil::Argument_DOUBLE; case 8: return IfcUtil::Argument_ENUMERATION; case 9: return IfcUtil::Argument_STRING; } return IfcGeometricRepresentationContext::getArgumentType(i); } + virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const { switch (i) {case 2: return IfcUtil::Argument_DERIVED; case 3: return IfcUtil::Argument_DERIVED; case 4: return IfcUtil::Argument_DERIVED; case 5: return IfcUtil::Argument_DERIVED; case 6: return IfcUtil::Argument_ENTITY_INSTANCE; case 7: return IfcUtil::Argument_DOUBLE; case 8: return IfcUtil::Argument_ENUMERATION; case 9: return IfcUtil::Argument_STRING; } return IfcGeometricRepresentationContext::getArgumentType(i); } virtual Type::Enum getArgumentEntity(unsigned int i) const { switch (i) {case 6: return Type::IfcGeometricRepresentationContext; case 7: return Type::IfcPositiveRatioMeasure; case 8: return Type::IfcGeometricProjectionEnum; case 9: return Type::IfcLabel; } return IfcGeometricRepresentationContext::getArgumentEntity(i); } virtual const char* getArgumentName(unsigned int i) const { switch (i) {case 6: return "ParentContext"; case 7: return "TargetScale"; case 8: return "TargetView"; case 9: return "UserDefinedTargetView"; } return IfcGeometricRepresentationContext::getArgumentName(i); } virtual Argument* getArgument(unsigned int i) const { return entity->getArgument(i); } @@ -15142,7 +15142,7 @@ public: bool Orientation() const; void setOrientation(bool v); virtual unsigned int getArgumentCount() const { return 4; } - virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const { switch (i) {case 2: return IfcUtil::Argument_ENTITY_INSTANCE; case 3: return IfcUtil::Argument_BOOL; } return IfcEdge::getArgumentType(i); } + virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const { switch (i) {case 0: return IfcUtil::Argument_DERIVED; case 1: return IfcUtil::Argument_DERIVED; case 2: return IfcUtil::Argument_ENTITY_INSTANCE; case 3: return IfcUtil::Argument_BOOL; } return IfcEdge::getArgumentType(i); } virtual Type::Enum getArgumentEntity(unsigned int i) const { switch (i) {case 2: return Type::IfcEdge; case 3: return Type::UNDEFINED; } return IfcEdge::getArgumentEntity(i); } virtual const char* getArgumentName(unsigned int i) const { switch (i) {case 2: return "EdgeElement"; case 3: return "Orientation"; } return IfcEdge::getArgumentName(i); } virtual Argument* getArgument(unsigned int i) const { return entity->getArgument(i); } diff --git a/src/ifcparse/Ifc4.h b/src/ifcparse/Ifc4.h index c060f69fd4..29bf18f59f 100644 --- a/src/ifcparse/Ifc4.h +++ b/src/ifcparse/Ifc4.h @@ -11674,7 +11674,7 @@ public: IfcSIUnitName::IfcSIUnitName Name() const; void setName(IfcSIUnitName::IfcSIUnitName v); virtual unsigned int getArgumentCount() const { return 4; } - virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const { switch (i) {case 2: return IfcUtil::Argument_ENUMERATION; case 3: return IfcUtil::Argument_ENUMERATION; } return IfcNamedUnit::getArgumentType(i); } + virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const { switch (i) {case 0: return IfcUtil::Argument_DERIVED; case 2: return IfcUtil::Argument_ENUMERATION; case 3: return IfcUtil::Argument_ENUMERATION; } return IfcNamedUnit::getArgumentType(i); } virtual Type::Enum getArgumentEntity(unsigned int i) const { switch (i) {case 2: return Type::IfcSIPrefix; case 3: return Type::IfcSIUnitName; } return IfcNamedUnit::getArgumentEntity(i); } virtual const char* getArgumentName(unsigned int i) const { switch (i) {case 2: return "Prefix"; case 3: return "Name"; } return IfcNamedUnit::getArgumentName(i); } virtual Argument* getArgument(unsigned int i) const { return entity->getArgument(i); } @@ -15490,7 +15490,7 @@ public: std::string UserDefinedTargetView() const; void setUserDefinedTargetView(std::string v); virtual unsigned int getArgumentCount() const { return 10; } - virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const { switch (i) {case 6: return IfcUtil::Argument_ENTITY_INSTANCE; case 7: return IfcUtil::Argument_DOUBLE; case 8: return IfcUtil::Argument_ENUMERATION; case 9: return IfcUtil::Argument_STRING; } return IfcGeometricRepresentationContext::getArgumentType(i); } + virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const { switch (i) {case 2: return IfcUtil::Argument_DERIVED; case 3: return IfcUtil::Argument_DERIVED; case 4: return IfcUtil::Argument_DERIVED; case 5: return IfcUtil::Argument_DERIVED; case 6: return IfcUtil::Argument_ENTITY_INSTANCE; case 7: return IfcUtil::Argument_DOUBLE; case 8: return IfcUtil::Argument_ENUMERATION; case 9: return IfcUtil::Argument_STRING; } return IfcGeometricRepresentationContext::getArgumentType(i); } virtual Type::Enum getArgumentEntity(unsigned int i) const { switch (i) {case 6: return Type::IfcGeometricRepresentationContext; case 7: return Type::IfcPositiveRatioMeasure; case 8: return Type::IfcGeometricProjectionEnum; case 9: return Type::IfcLabel; } return IfcGeometricRepresentationContext::getArgumentEntity(i); } virtual const char* getArgumentName(unsigned int i) const { switch (i) {case 6: return "ParentContext"; case 7: return "TargetScale"; case 8: return "TargetView"; case 9: return "UserDefinedTargetView"; } return IfcGeometricRepresentationContext::getArgumentName(i); } virtual Argument* getArgument(unsigned int i) const { return entity->getArgument(i); } @@ -16924,7 +16924,7 @@ public: bool Orientation() const; void setOrientation(bool v); virtual unsigned int getArgumentCount() const { return 4; } - virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const { switch (i) {case 2: return IfcUtil::Argument_ENTITY_INSTANCE; case 3: return IfcUtil::Argument_BOOL; } return IfcEdge::getArgumentType(i); } + virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const { switch (i) {case 0: return IfcUtil::Argument_DERIVED; case 1: return IfcUtil::Argument_DERIVED; case 2: return IfcUtil::Argument_ENTITY_INSTANCE; case 3: return IfcUtil::Argument_BOOL; } return IfcEdge::getArgumentType(i); } virtual Type::Enum getArgumentEntity(unsigned int i) const { switch (i) {case 2: return Type::IfcEdge; case 3: return Type::IfcBoolean; } return IfcEdge::getArgumentEntity(i); } virtual const char* getArgumentName(unsigned int i) const { switch (i) {case 2: return "EdgeElement"; case 3: return "Orientation"; } return IfcEdge::getArgumentName(i); } virtual Argument* getArgument(unsigned int i) const { return entity->getArgument(i); }