From 14dfa5ba79a6073210b93001d12c75ef212d5641 Mon Sep 17 00:00:00 2001 From: Jan Brouwer Date: Tue, 23 Apr 2024 18:45:24 +0200 Subject: [PATCH 1/2] Fix IfcSpace not being exported #59 --- .../lib/lib_ifc/spatial_structure.rb | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/bt_ifcmanager/lib/lib_ifc/spatial_structure.rb b/src/bt_ifcmanager/lib/lib_ifc/spatial_structure.rb index 116583c..010e6a5 100644 --- a/src/bt_ifcmanager/lib/lib_ifc/spatial_structure.rb +++ b/src/bt_ifcmanager/lib/lib_ifc/spatial_structure.rb @@ -68,13 +68,14 @@ def add(ifc_entity) # (!) Check!!! @spatial_structure[0] = ifc_entity when @ifc::IfcSite - add_spatialelement(ifc_entity, spatial_structure_types, @ifc::IfcSite, @ifc::IfcProject) + add_spatialelement(ifc_entity, spatial_structure_types, @ifc::IfcSite, [@ifc::IfcProject]) when @ifc::IfcBuilding - add_spatialelement(ifc_entity, spatial_structure_types, @ifc::IfcBuilding, @ifc::IfcSite) + add_spatialelement(ifc_entity, spatial_structure_types, @ifc::IfcBuilding, [@ifc::IfcSite]) when @ifc::IfcBuildingStorey - add_spatialelement(ifc_entity, spatial_structure_types, @ifc::IfcBuildingStorey, @ifc::IfcBuilding) + add_spatialelement(ifc_entity, spatial_structure_types, @ifc::IfcBuildingStorey, [@ifc::IfcBuilding]) when @ifc::IfcSpace - add_space(ifc_entity, spatial_structure_types) + add_spatialelement(ifc_entity, spatial_structure_types, @ifc::IfcSpace, + [@ifc::IfcBuildingStorey, @ifc::IfcSite]) when @ifc::IfcElementAssembly, @ifc::IfcCurtainWall, @ifc::IfcRoof # add to end but check for basic spatial hierarchy @@ -93,20 +94,26 @@ def add(ifc_entity) # Adds a spatial element to the project's spatial structure. # - # @param ifc_entity [Object] The IfcSpatialElement instance to be added to the spatial structure. + # @param ifc_entity [Object] The IFC entity to which the spatial element will be added. # @param spatial_structure_types [Array] An array of spatial structure types. # @param structure_type [Object] The structure type of the spatial element. - # @param parent_structure_type [Object] The structure type of the parent spatial element. + # @param parent_structure_types [Array] An array of parent structure types. # @return [void] - def add_spatialelement(ifc_entity, spatial_structure_types, structure_type, parent_structure_type) + def add_spatialelement(ifc_entity, spatial_structure_types, structure_type, parent_structure_types) complex_parent_index = spatial_structure_types.rindex(structure_type) if complex_parent_index add_complex_spatialelement(ifc_entity, structure_type, complex_parent_index) - elsif spatial_structure_types.include?(parent_structure_type) - insert_after(ifc_entity, parent_structure_type) else - add_default_spatialelement(parent_structure_type) - insert_after(ifc_entity, parent_structure_type) + parent_structure_type = parent_structure_types.find { |type| spatial_structure_types.include?(type) } + if parent_structure_type + insert_after(ifc_entity, parent_structure_type) + else + unless parent_structure_types.empty? + add_default_spatialelement(parent_structure_types.last) + add_spatialelement(ifc_entity, get_spatial_structure_types, structure_type, + parent_structure_types[0...-1]) + end + end end end From e6026f8ecd519ca93c2d936619ecedecc1950bc6 Mon Sep 17 00:00:00 2001 From: Jan Brouwer Date: Tue, 23 Apr 2024 18:48:14 +0200 Subject: [PATCH 2/2] Fix IfcTypeProduct persistent id based tag --- src/bt_ifcmanager/lib/lib_ifc/IfcTypeProduct_su.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/bt_ifcmanager/lib/lib_ifc/IfcTypeProduct_su.rb b/src/bt_ifcmanager/lib/lib_ifc/IfcTypeProduct_su.rb index 918c2bc..2a5fbd0 100644 --- a/src/bt_ifcmanager/lib/lib_ifc/IfcTypeProduct_su.rb +++ b/src/bt_ifcmanager/lib/lib_ifc/IfcTypeProduct_su.rb @@ -36,21 +36,22 @@ def initialize(ifc_model, definition, instance_class = nil) @definition = definition @type_properties = ifc_model.options[:type_properties] + persistent_id = definition.persistent_id.to_s + @rel_defines_by_type = @ifc::IfcRelDefinesByType.new(@ifc_model) @rel_defines_by_type.relatingtype = self @rel_defines_by_type.relatedobjects = IfcManager::Types::Set.new @rel_defines_by_type.globalid = IfcManager::IfcGloballyUniqueId.new(ifc_model, - "IfcTypeProduct.#{definition.name}") + "IfcRelDefinesByType.#{persistent_id}") @name = IfcManager::Types::IfcLabel.new(ifc_model, definition.name) - @globalid = IfcManager::IfcGloballyUniqueId.new(ifc_model, "IfcRelDefinesByType.#{definition.name}") + @globalid = IfcManager::IfcGloballyUniqueId.new(ifc_model, "IfcTypeProduct.#{persistent_id}") - # Set "tag" to component persistant_id like the other BIM Authoring Tools like Revit, Archicad and Tekla are doing - # (!) persistant_id in Sketchup is unique for the ComponentDefinition, but not within the IFC model due to scaled ComponentInstances - @tag = IfcManager::Types::IfcLabel.new(ifc_model, definition.persistent_id.to_s) + # Set "tag" to component persistent_id like the other BIM Authoring Tools like Revit, Archicad and Tekla do + @tag = IfcManager::Types::IfcLabel.new(ifc_model, persistent_id) # get attributes from su object and add them to IfcTypeProduct - if dicts = definition.attribute_dictionaries + if (dicts = definition.attribute_dictionaries) dict_reader = IfcManager::IfcDictionaryReader.new(ifc_model, self, dicts, instance_class) dict_reader.set_attributes if @type_properties