Skip to content

Commit

Permalink
Model validation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrouwerdigibase committed Oct 27, 2024
1 parent 8456c36 commit bb353eb
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 49 deletions.
50 changes: 50 additions & 0 deletions src/bt_ifcmanager/lib/lib_ifc/IfcBuildingElementProxy_su.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

# IfcBuildingElementProxy_su.rb
#
# Copyright 2024 Jan Brouwer <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#

module BimTools
module IfcBuildingElementProxy_su
VALID_COMPOSITION_TYPES = %i[COMPLEX ELEMENT PARTIAL].freeze

attr_reader :compositiontype

def initialize(ifc_model, sketchup, _total_transformation)
@ifc_version = ifc_model.ifc_version
super
end

# CompositionType attribute deprecated in IFC4
def compositiontype=(value)
return unless @ifc_version == 'IFC 2x3'

enum_value = if value.is_a?(String)
value.upcase.to_sym
elsif value.respond_to?(:value)
value.value.upcase.to_sym
else
value.to_sym
end

@compositiontype = VALID_COMPOSITION_TYPES.include?(enum_value) ? enum_value : nil
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

module BimTools
module IfcClassificationReference_su
def self.required_attributes
def self.required_attributes(_ifc_version)
[:ReferencedSource]
end
end
Expand Down
38 changes: 38 additions & 0 deletions src/bt_ifcmanager/lib/lib_ifc/IfcElementAssembly_su.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

# IfcElementAssembly_su.rb
#
# Copyright 2024 Jan Brouwer <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#

module BimTools
module IfcElementAssembly_su
attr_reader :assemblyplace

def assemblyplace=(value)
@assemblyplace = if value.is_a?(String)
value.to_sym
elsif value.respond_to?(:value)
value.value.to_sym
else
value.to_sym
end # TODO: hacky fix, should be part of PropertyReader
end
end
end
34 changes: 27 additions & 7 deletions src/bt_ifcmanager/lib/lib_ifc/IfcPile_su.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,36 @@

module BimTools
module IfcPile_su
@constructiontype = nil
VALID_CONSTRUCTION_TYPES = %i[
CAST_IN_PLACE
COMPOSITE
PRECAST_CONCRETE
PREFAB_STEEL
USERDEFINED
NOTDEFINED
].freeze

attr_reader :constructiontype

def initialize(ifc_model, sketchup, _total_transformation)
@ifc_version = ifc_model.ifc_version
super
end

# ConstructionType attribute deprecated in IFC4
def constructiontype=(value)
puts BimTools::IfcManager::Settings.ifc_version_compact
if BimTools::IfcManager::Settings.ifc_version_compact == 'IFC2X3'
@constructiontype = value.value.to_sym
else
puts 'ConstructionType attribute deprecated'
end
return unless @ifc_version == 'IFC 2x3'

# TODO: hacky fix, should be part of PropertyReader
enum_value = if value.is_a?(String)
value.upcase.to_sym
elsif value.respond_to?(:value)
value.value.upcase.to_sym
else
value.to_sym
end

@constructiontype = VALID_CONSTRUCTION_TYPES.include?(enum_value) ? enum_value : nil
end
end
end
4 changes: 3 additions & 1 deletion src/bt_ifcmanager/lib/lib_ifc/IfcProduct_su.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ def initialize(ifc_model, sketchup, total_transformation)
add_base_quantities
end

# Adds a surface feature to the IFC element.
# Adds a surface feature to the IFC element (not every IfcProduct).
#
# @param surface_feature [Object] The surface feature to be added.
# @return [void]
def add_surface_feature(surface_feature)
return unless is_a?(@ifc_module::IfcElement)

create_ifc_rel_adheres_to_element unless @has_surface_features
@has_surface_features.add_related_surface_feature(surface_feature)
end
Expand Down
5 changes: 4 additions & 1 deletion src/bt_ifcmanager/lib/lib_ifc/IfcRelAggregates_su.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

module BimTools
module IfcRelAggregates_su
def self.required_attributes
def self.required_attributes(ifc_version)
# In IFC2X3, the attribute 'RelatingObject' is part of its parent class 'IfcRelDecomposes'.
return [] if ifc_version == 'IFC 2x3'

[:RelatingObject]
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

module BimTools
module IfcRelContainedInSpatialStructure_su
def self.required_attributes
def self.required_attributes(_ifc_version)
[:RelatingStructure]
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

module BimTools
module IfcRelDefinesByProperties_su
def self.required_attributes
def self.required_attributes(ifc_version)
# In IFC2X3, the attribute 'RelatedObjects' is part of its parent class 'IfcRelDecomposes'.
return [] if ifc_version == 'IFC 2x3'

[:RelatedObjects]
end
end
Expand Down
5 changes: 4 additions & 1 deletion src/bt_ifcmanager/lib/lib_ifc/IfcRelDefinesByType_su.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

module BimTools
module IfcRelDefinesByType_su
def self.required_attributes
def self.required_attributes(ifc_version)
# In IFC2X3, the attribute 'RelatedObjects' is part of its parent class 'IfcRelDecomposes'.
return [] if ifc_version == 'IFC 2x3'

[:RelatedObjects]
end
end
Expand Down
50 changes: 50 additions & 0 deletions src/bt_ifcmanager/lib/lib_ifc/IfcSpace_su.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

# IfcSpace_su.rb
#
# Copyright 2024 Jan Brouwer <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#

module BimTools
module IfcSpace_su
VALID_ENUM_VALUES = %i[INTERNAL EXTERNAL NOTDEFINED].freeze

attr_reader :interiororexteriorspace

def initialize(ifc_model, sketchup, total_transformation)
@ifc_version = ifc_model.ifc_version
super
end

# InteriorOrExteriorSpace renamed to PredefinedType in IFC4
def interiororexteriorspace=(value)
return unless @ifc_version == 'IFC 2x3'

enum_value = if value.is_a?(String)
value.upcase.to_sym
elsif value.respond_to?(:value)
value.value.upcase.to_sym
else
value.to_sym
end

@interiororexteriorspace = VALID_ENUM_VALUES.include?(enum_value) ? enum_value : :NOTDEFINED
end
end
end
9 changes: 5 additions & 4 deletions src/bt_ifcmanager/lib/lib_ifc/definition_representation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DefinitionRepresentation
def initialize(ifc_model, geometry_type, faces, su_material, transformation)
@ifc_module = ifc_model.ifc_module
@ifc_model = ifc_model
@ifc_version = ifc_model.ifc_version
@geometry_type = geometry_type
@ifc_shape_representation_builder = nil
@representation = nil
Expand All @@ -53,13 +54,13 @@ def representations(extrusion = nil)
[create_extrusion(bottom_face, direction, @su_material, @transformation)]
end

# Set the definition-representations OWN representation using it's faces
# Set the definition-representations OWN representation using its faces
def create_meshes(ifc_model, faces, transformation, su_material = nil)
# if su_material
faces_by_material = faces.group_by { |face| [face.material, face.back_material] }
if faces_by_material.length > 0
return faces_by_material.map do |face_materials, face_group|
create_mesh(ifc_model, face_group, transformation, su_material, face_materials)
return faces_by_material.map do |face_materials, grouped_faces|
create_mesh(ifc_model, grouped_faces, transformation, su_material, face_materials)
end
end
# end
Expand Down Expand Up @@ -112,7 +113,7 @@ def style_item(ifc_model, item, su_material, front_material, back_material)
end

def get_surface_styles(ifc_model, parent_material = nil, front_material = nil, back_material = nil)
if Settings.ifc_version_compact == 'IFC2X3' || @double_sided_faces == false
if @ifc_version == 'IFC 2x3' || @double_sided_faces == false
return Types::Set.new([ifc_model.get_styling(front_material, :both)]) if front_material

Types::Set.new([ifc_model.get_styling(parent_material, :both)])
Expand Down
12 changes: 5 additions & 7 deletions src/bt_ifcmanager/lib/lib_ifc/entity_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ def initialize(
)
@ifc_module = ifc_model.ifc_module
@ifc_model = ifc_model
@ifc_version = ifc_model.ifc_version
@instance_path = Sketchup::InstancePath.new(instance_path.to_a + [su_instance])
@persistent_id_path = persistent_id_path(@instance_path)
@spatial_structure = SpatialStructureHierarchy.new(@ifc_model, spatial_structure)
@guid = IfcManager::IfcGloballyUniqueId.new(@ifc_model, @persistent_id_path)
entity_type_name = su_instance.definition.get_attribute(
'AppliedSchemaTypes',
ifc_model.ifc_version
@ifc_version
)
su_material = su_instance.material if su_instance.material
su_layer = su_instance.layer if su_instance.layer.name != 'Layer0' || su_layer.nil?
Expand Down Expand Up @@ -102,11 +103,8 @@ def persistent_id_path(instance_path)
# @return [IfcEntity] The created IFC entity.
def create_ifc_entity(entity_type_name, su_instance, placement_parent = nil, su_material = nil, su_layer = nil)
su_definition = su_instance.definition

entity_type_name = map_entity_type(entity_type_name)

entity_type = @ifc_module.const_get(entity_type_name) if entity_type_name

ifc_entity = determine_ifc_entity(entity_type, su_instance, placement_parent)

create_geometry(su_definition, ifc_entity, placement_parent, su_material, su_layer)
Expand Down Expand Up @@ -135,10 +133,10 @@ def map_entity_type(entity_type_name)
case entity_base_name
when 'IfcAirTerminal'
# Catch missing IfcAirTerminal in Ifc2x3
Settings.ifc_version_compact == 'IFC2X3' ? 'IfcFlowTerminal' : 'IfcAirTerminal'
@ifc_version == 'IFC 2x3' ? 'IfcFlowTerminal' : 'IfcAirTerminal'
when 'IfcPipeSegment'
# Catch missing IfcPipeSegment in Ifc2x3
Settings.ifc_version_compact == 'IFC2X3' ? 'IfcFlowSegment' : 'IfcPipeSegment'
@ifc_version == 'IFC 2x3' ? 'IfcFlowSegment' : 'IfcPipeSegment'
else
@ifc_module.const_defined?(entity_base_name) ? entity_base_name : entity_type_name
end
Expand Down Expand Up @@ -305,7 +303,7 @@ def assign_entity_attributes(ifc_entity, placement_parent)
# could be better set from within IfcBuildingStorey?
return unless ifc_entity.is_a?(@ifc_module::IfcBuildingStorey)

return unless %w[IFC2X3 IFC4].include?(Settings.ifc_version_compact)
return unless ['IFC 2x3', 'IFC 4'].include?(@ifc_version)

elevation = @objectplacement.ifc_total_transformation.origin.z
ifc_entity.elevation = Types::IfcLengthMeasure.new(@ifc_model, elevation)
Expand Down
2 changes: 1 addition & 1 deletion src/bt_ifcmanager/lib/lib_ifc/material_and_styling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def create_surface_styles(su_material, side = :both)
end

# Workaround for mandatory IfcPresentationStyleAssignment in IFC2x3
if Settings.ifc_version == 'IFC 2x3'
if @ifc_model.ifc_version == 'IFC 2x3'
style_assignment = @ifc_module::IfcPresentationStyleAssignment.new(@ifc_model)
style_assignment.styles = Types::Set.new([surface_style])
else
Expand Down
Loading

0 comments on commit bb353eb

Please sign in to comment.