Skip to content

Commit

Permalink
Fix export classification attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrouwerdigibase committed May 7, 2024
1 parent ef8ad50 commit cbd2e18
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 108 deletions.
22 changes: 13 additions & 9 deletions src/bt_ifcmanager/lib/lib_ifc/PropertyReader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def initialize(ifc_model, ifc_entity, entity_dict, instance_class = nil)

# Skip IfcProduct-only attributes for IfcTypeProduct
@all_attributes = if instance_class
instance_class_attributes = instance_class.attributes.map { |x| x.to_s }
names & (ifc_entity_attributes + instance_class_attributes).uniq
else
@attributes
end
instance_class_attributes = instance_class.attributes.map { |x| x.to_s }
names & (ifc_entity_attributes + instance_class_attributes).uniq
else
@attributes
end

@propertyset_names = names - @all_attributes
end
Expand Down Expand Up @@ -114,10 +114,14 @@ def add_classifications
end

schema_types.each do |classification_name, classification_value|
unless Settings.ifc_version_names.include?(classification_name)
@ifc_model.classifications.add_classification_to_entity(@ifc_entity, classification_name,
classification_value, @entity_dict[classification_name])
end
next if Settings.ifc_version_names.include?(classification_name)

@ifc_model.classifications.add_classification_to_entity(
@ifc_entity,
classification_name,
classification_value,
@entity_dict[classification_name]
)
end
end

Expand Down
46 changes: 27 additions & 19 deletions src/bt_ifcmanager/lib/lib_ifc/classification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
module BimTools
module IfcManager
require_relative 'ifc_classification_builder'
require_relative 'classification_reference'
require_relative 'ifc_classification_reference_builder'
require File.join(PLUGIN_PATH_LIB, 'skc_reader')

class Classification
Expand All @@ -39,17 +39,19 @@ def initialize(ifc_model, classification_name, skc_file = nil)
@edition = nil
@editiondate = nil
@location = nil
# load_skc(skc_file)
load_skc(skc_file)
get_classifiction_details
end

# def load_skc(file_name = nil)
# file_name ||= "#{@name}.skc"
# properties = SKC.new(file_name).properties
# @source = properties[:creator]
# @edition = properties[:revision]
# @editiondate = properties[:modified]
# end
def load_skc(file_name = nil)
file_name ||= "#{@name}.skc"
properties = SKC.new(file_name).properties
@source = properties[:creator]
@edition = properties[:revision]
@editiondate = properties[:modified]
rescue StandardError => e
puts "Error: #{e.message}. Skipping SKC file: #{file_name}"
end

def get_ifc_classification
@ifc_classification ||= IfcClassificationBuilder.build(@ifc_model) do |builder|
Expand All @@ -63,20 +65,26 @@ def get_ifc_classification

def get_classifiction_details
su_model = @ifc_model.su_model
if project_data = su_model.attribute_dictionaries['IfcManager']
if classifications = project_data.attribute_dictionaries['Classifications']
@source = classifications.get_attribute(@name, 'source')
@edition = classifications.get_attribute(@name, 'edition')
@editiondate = classifications.get_attribute(@name, 'editiondate')
@location = classifications.get_attribute(@name, 'location')
end
end
return unless project_data = su_model.attribute_dictionaries['IfcManager']
return unless classifications = project_data.attribute_dictionaries['Classifications']

@source = classifications.get_attribute(@name, 'source')
@edition = classifications.get_attribute(@name, 'edition')
@editiondate = classifications.get_attribute(@name, 'editiondate')
@location = classifications.get_attribute(@name, 'location')
end

def add_classification_reference(ifc_entity, classification_value, identification = nil, location = nil)
def add_classification_reference(ifc_entity, classification_value, identification = nil, location = nil,
name = nil)
ifc_classification = get_ifc_classification
unless @classification_references.key? classification_value
@classification_references[classification_value] =
ClassificationReference.new(@ifc_model, self, classification_value, identification, location)
IfcClassificationReferenceBuilder.build(@ifc_model, @name) do |builder|
builder.set_location(location) if location
builder.set_referencedsource(ifc_classification)
builder.set_identification(identification) if identification
builder.set_name(name) if name
end
end
@classification_references[classification_value].add_ifc_entity(ifc_entity)
end
Expand Down
69 changes: 0 additions & 69 deletions src/bt_ifcmanager/lib/lib_ifc/classification_reference.rb

This file was deleted.

35 changes: 27 additions & 8 deletions src/bt_ifcmanager/lib/lib_ifc/classifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ def get_classification_by_name(name, skc_file = nil)

def add_classification_to_entity(ifc_entity, classification_name, classification_value, classification_dictionary)
classification = get_classification_by_name(classification_name)
classification.add_classification_reference(ifc_entity, classification_value,
get_identification(classification_dictionary), get_location(classification_dictionary))
classification.add_classification_reference(
ifc_entity,
classification_value,
get_identification(classification_dictionary),
get_location(classification_dictionary),
get_name(classification_dictionary, classification_value)
)
end

def get_identification(classification_dictionary)
if classification_dictionary
classification_dictionary.attribute_dictionaries.each do |dictionary|
if %w[identification itemreference class-codenotatie].include? dictionary.name.downcase
if %w[identification itemreference class-codenotatie din_code].include? dictionary.name.downcase
if value = dictionary['value']
return value
elsif value_dictionary = dictionary.attribute_dictionaries[dictionary.name]
Expand All @@ -66,15 +71,29 @@ def get_identification(classification_dictionary)
end

def get_location(classification_dictionary)
if classification_dictionary && dictionary = classification_dictionary.attribute_dictionary('Location')
if value = dictionary['value']
return value
elsif value_dictionary = dictionary.attribute_dictionaries[dictionary.name]
return value_dictionary['value']
end
end
nil
end

def get_name(classification_dictionary, classification_value)
if classification_dictionary
if dictionary = classification_dictionary.attribute_dictionary('Location')
if value = dictionary['value']
return value
elsif value_dictionary = dictionary.attribute_dictionaries[dictionary.name]
return value_dictionary['value']
classification_dictionary.attribute_dictionaries.each do |dictionary|
if %w[name tekst_nl-sfb din_text].include? dictionary.name.downcase
if value = dictionary['value']
return value
elsif value_dictionary = dictionary.attribute_dictionaries[dictionary.name]
return value_dictionary['value']
end
end
end
end
return classification_value
nil
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ module IfcManager
class IfcClassificationReferenceBuilder
attr_reader :ifc_classification_reference

def self.build(ifc_model)
builder = new(ifc_model)
def self.build(ifc_model, classification_name)
builder = new(ifc_model, classification_name)
yield(builder)
builder.ifc_classification_reference
builder
end

def initialize(ifc_model)
def initialize(ifc_model, classification_name)
@ifc = IfcManager::Settings.ifc_module
@ifc_model = ifc_model
@ifc_classification_reference = @ifc::IfcClassificationReference.new(ifc_model)
@classification_ref_for_objects = get_association(classification_name)
end

def set_location(location)
Expand Down Expand Up @@ -66,6 +68,25 @@ def set_name(name)
def set_referencedsource(ifc_classification)
@ifc_classification_reference.referencedsource = ifc_classification
end

def get_association(classification_name)
@ifc::IfcRelAssociatesClassification.new(@ifc_model).tap do |rel|
rel.name = get_rel_associates_classification_name(classification_name)
rel.relatedobjects = Types::Set.new
rel.relatingclassification = @ifc_classification_reference
end
end

def get_rel_associates_classification_name(classification_name)
# Revit compatibility setting
classification_name += ' Classification' if @ifc_model.options[:classification_suffix]

Types::IfcLabel.new(@ifc_model, classification_name)
end

def add_ifc_entity(ifc_entity)
@classification_ref_for_objects.relatedobjects.add(ifc_entity)
end
end
end
end

0 comments on commit cbd2e18

Please sign in to comment.