From d419efb71fcef175be860ec80942002f02e61085 Mon Sep 17 00:00:00 2001 From: Jan Brouwer Date: Sun, 20 Oct 2024 23:42:59 +0200 Subject: [PATCH] Catch differences in IFC schema versions --- src/bt_ifcmanager/lib/lib_ifc/IfcProduct_su.rb | 5 +++-- src/bt_ifcmanager/lib/lib_ifc/PropertyReader.rb | 9 +++++---- src/bt_ifcmanager/lib/lib_ifc/entity_builder.rb | 12 ++++++------ src/bt_ifcmanager/lib/lib_ifc/spatial_structure.rb | 10 +++++++--- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/bt_ifcmanager/lib/lib_ifc/IfcProduct_su.rb b/src/bt_ifcmanager/lib/lib_ifc/IfcProduct_su.rb index 51e8dc1..15f72f4 100644 --- a/src/bt_ifcmanager/lib/lib_ifc/IfcProduct_su.rb +++ b/src/bt_ifcmanager/lib/lib_ifc/IfcProduct_su.rb @@ -97,10 +97,11 @@ def initialize(ifc_model, sketchup, total_transformation) (is_a? @ifc_module::IfcElement) && !(is_a? @ifc_module::IfcFeatureElementSubtraction) && !(is_a? @ifc_module::IfcVirtualElement) && - !(is_a? @ifc_module::IfcSpatialElement) && + !(is_a? @ifc_module::IfcSpatialStructureElement) && !(is_a? @ifc_module::IfcRoof) && !(is_a? @ifc_module::IfcElementAssembly) && - !(is_a? @ifc_module::IfcCurtainWall) + !(is_a? @ifc_module::IfcCurtainWall) && + !(defined?(@ifc_module::IfcSpatialZone) && is_a?(@ifc_module::IfcSpatialZone)) # collect dynamic component attributes if export option is set BimTools::DynamicAttributes.get_dynamic_attributes(ifc_model, self) if ifc_model.options[:dynamic_attributes] diff --git a/src/bt_ifcmanager/lib/lib_ifc/PropertyReader.rb b/src/bt_ifcmanager/lib/lib_ifc/PropertyReader.rb index e041365..238dfe1 100644 --- a/src/bt_ifcmanager/lib/lib_ifc/PropertyReader.rb +++ b/src/bt_ifcmanager/lib/lib_ifc/PropertyReader.rb @@ -77,16 +77,17 @@ def initialize(ifc_model, ifc_entity, entity_dict, instance_class = nil) @attributes end - @propertyset_names = names - @all_attributes - ifc_entity_inverse_attributes end def handle_predefined_type(value) - if value == :userdefined + if value == 'userdefined' object_type_or_element_type = @ifc_dict['ObjectType'] || @ifc_dict['ElementType'] return :notdefined if object_type_or_element_type end - value + return value if value.is_a?(Symbol) + + value.is_a?(String) ? value.to_sym : value.value.to_sym # TODO: hacky fix end # Set the IFC entity attributes using all combined attribute possibilitites from IfcProduct and IfcTypeProduct @@ -184,7 +185,7 @@ def set_attribute(attr_dict) return false if value.nil? || (value.is_a?(String) && value.empty?) ifc_value = determine_ifc_value(property, value) - ifc_value = handle_predefined_type(ifc_value) if ifc_value.is_a?(Symbol) && name == 'PredefinedType' + ifc_value = handle_predefined_type(ifc_value) if name == 'PredefinedType' @ifc_entity.send("#{name.downcase}=", ifc_value) if ifc_value end diff --git a/src/bt_ifcmanager/lib/lib_ifc/entity_builder.rb b/src/bt_ifcmanager/lib/lib_ifc/entity_builder.rb index 93ed7e7..c552152 100644 --- a/src/bt_ifcmanager/lib/lib_ifc/entity_builder.rb +++ b/src/bt_ifcmanager/lib/lib_ifc/entity_builder.rb @@ -526,14 +526,14 @@ def add_representation_to_parent(placement_parent, definition_manager, su_materi # @return [void] def add_placement_parent_relationships(ifc_entity, placement_parent) return unless placement_parent - return if ifc_entity == placement_parent - unless ifc_entity.is_a?(@ifc_module::IfcSurfaceFeature) && placement_parent.is_a?(@ifc_module::IfcProduct) - return - end # TODO: should be IfcElement - - placement_parent.add_surface_feature(ifc_entity) + if defined?(@ifc_module::IfcSurfaceFeature) && + defined?(@ifc_module::IfcRelAdheresToElement) && + ifc_entity.is_a?(@ifc_module::IfcSurfaceFeature) && + placement_parent.is_a?(@ifc_module::IfcProduct) # TODO: should be IfcElement + placement_parent.add_surface_feature(ifc_entity) + end end end end diff --git a/src/bt_ifcmanager/lib/lib_ifc/spatial_structure.rb b/src/bt_ifcmanager/lib/lib_ifc/spatial_structure.rb index 630c261..4a2dd08 100644 --- a/src/bt_ifcmanager/lib/lib_ifc/spatial_structure.rb +++ b/src/bt_ifcmanager/lib/lib_ifc/spatial_structure.rb @@ -93,7 +93,9 @@ def add(ifc_entity) add_default_spatialelement(@ifc_module::IfcBuildingStorey) end @spatial_structure << ifc_entity - when ->(entity) { entity.is_a?(@ifc_module::IfcProduct) && !entity.is_a?(@ifc_module::IfcSpatialElement) } + when lambda { |entity| + entity.is_a?(@ifc_module::IfcProduct) && !entity.is_a?(@ifc_module::IfcSpatialStructureElement) + } if (spatial_structure_types & [@ifc_module::IfcSpace, @ifc_module::IfcBuildingStorey, @ifc_module::IfcSite]).empty? add_default_spatialelement(@ifc_module::IfcBuildingStorey) @@ -220,9 +222,11 @@ def set_parent(ifc_entity) @spatial_structure[-1] end ifc_entity.parent = parent + + # IfcSurfaceFeature is not part of the normal spatial structure + return if defined?(@ifc_module::IfcSurfaceFeature) && ifc_entity.is_a?(@ifc_module::IfcSurfaceFeature) + case ifc_entity - when @ifc_module::IfcSurfaceFeature - # skip when @ifc_module::IfcSpatialStructureElement ifc_entity.parent.add_related_object(ifc_entity) else