diff --git a/src/ifcblenderexport/blenderbim/bim/__init__.py b/src/ifcblenderexport/blenderbim/bim/__init__.py index b201f3ee49..c909c450fd 100644 --- a/src/ifcblenderexport/blenderbim/bim/__init__.py +++ b/src/ifcblenderexport/blenderbim/bim/__init__.py @@ -100,10 +100,11 @@ if bpy is not None: operator.BIM_OT_CopyAttributesToSelection, operator.BIM_OT_ChangeClassificationLevel, operator.AddPropertySetTemplate, - operator.DeletePropertySetTemplate, + operator.RemovePropertySetTemplate, operator.EditPropertySetTemplate, operator.SavePropertySetTemplate, operator.AddPropertyTemplate, + operator.RemovePropertyTemplate, prop.StrProperty, prop.Classification, prop.ClassificationReference, diff --git a/src/ifcblenderexport/blenderbim/bim/ifc.py b/src/ifcblenderexport/blenderbim/bim/ifc.py index 9893a0b398..3eb6db8400 100644 --- a/src/ifcblenderexport/blenderbim/bim/ifc.py +++ b/src/ifcblenderexport/blenderbim/bim/ifc.py @@ -1,3 +1,5 @@ class IfcStore(): path = '' file = None + pset_template_path = '' + pset_template_file = None diff --git a/src/ifcblenderexport/blenderbim/bim/operator.py b/src/ifcblenderexport/blenderbim/bim/operator.py index ac1aaeb154..832f4dfd8a 100644 --- a/src/ifcblenderexport/blenderbim/bim/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/operator.py @@ -1742,14 +1742,26 @@ class AddPropertySetTemplate(bpy.types.Operator): bl_label = 'Add Property Set Template' def execute(self, context): + context.scene.BIMProperties.active_property_set_template.global_id = '' + context.scene.BIMProperties.active_property_set_template.name = 'New_Pset' + context.scene.BIMProperties.active_property_set_template.description = '' + context.scene.BIMProperties.active_property_set_template.template_type = 'PSET_TYPEDRIVENONLY' + context.scene.BIMProperties.active_property_set_template.applicable_entity = 'IfcTypeObject' + while len(bpy.context.scene.BIMProperties.property_templates) > 0: + bpy.context.scene.BIMProperties.property_templates.remove(0) return {'FINISHED'} -class DeletePropertySetTemplate(bpy.types.Operator): - bl_idname = 'bim.delete_property_set_template' - bl_label = 'Delete Property Set Template' +class RemovePropertySetTemplate(bpy.types.Operator): + bl_idname = 'bim.remove_property_set_template' + bl_label = 'Remove Property Set Template' def execute(self, context): + template = ifc.IfcStore.pset_template_file.by_guid(context.scene.BIMProperties.property_set_templates) + ifc.IfcStore.pset_template_file.remove(template) + ifc.IfcStore.pset_template_file.write(ifc.IfcStore.pset_template_path) + from . import prop + prop.refreshPropertySetTemplates(self, context) return {'FINISHED'} class EditPropertySetTemplate(bpy.types.Operator): @@ -1757,9 +1769,7 @@ class EditPropertySetTemplate(bpy.types.Operator): bl_label = 'Edit Property Set Template' def execute(self, context): - f = ifcopenshell.open(os.path.join(context.scene.BIMProperties.data_dir, - 'pset', context.scene.BIMProperties.pset_template_files + '.ifc')) - template = f.by_guid(context.scene.BIMProperties.property_set_templates) + template = ifc.IfcStore.pset_template_file.by_guid(context.scene.BIMProperties.property_set_templates) context.scene.BIMProperties.active_property_set_template.global_id = template.GlobalId context.scene.BIMProperties.active_property_set_template.name = template.Name context.scene.BIMProperties.active_property_set_template.description = template.Description @@ -1769,13 +1779,15 @@ class EditPropertySetTemplate(bpy.types.Operator): while len(bpy.context.scene.BIMProperties.property_templates) > 0: bpy.context.scene.BIMProperties.property_templates.remove(0) - for property_template in template.HasPropertyTemplates: - if not property_template.is_a('IfcSimplePropertyTemplate'): - continue - new = context.scene.BIMProperties.property_templates.add() - new.name = property_template.Name - new.description = property_template.Description - new.primary_measure_type = property_template.PrimaryMeasureType + if template.HasPropertyTemplates: + for property_template in template.HasPropertyTemplates: + if not property_template.is_a('IfcSimplePropertyTemplate'): + continue + new = context.scene.BIMProperties.property_templates.add() + new.global_id = property_template.GlobalId + new.name = property_template.Name + new.description = property_template.Description + new.primary_measure_type = property_template.PrimaryMeasureType return {'FINISHED'} class SavePropertySetTemplate(bpy.types.Operator): @@ -1783,6 +1795,45 @@ class SavePropertySetTemplate(bpy.types.Operator): bl_label = 'Save Property Set Template' def execute(self, context): + blender_property_set_template = context.scene.BIMProperties.active_property_set_template + if blender_property_set_template.global_id: + template = ifc.IfcStore.pset_template_file.by_guid(blender_property_set_template.global_id) + else: + template = ifc.IfcStore.pset_template_file.createIfcPropertySetTemplate() + template.GlobalId = ifcopenshell.guid.new() + template.Name = blender_property_set_template.name + template.Description = blender_property_set_template.description + template.TemplateType = blender_property_set_template.template_type + template.ApplicableEntity = blender_property_set_template.applicable_entity + + saved_global_ids = [] + + for blender_property_template in context.scene.BIMProperties.property_templates: + if blender_property_template.global_id: + property_template = ifc.IfcStore.pset_template_file.by_guid(blender_property_template.global_id) + else: + property_template = ifc.IfcStore.pset_template_file.createIfcSimplePropertyTemplate() + property_template.GlobalId = ifcopenshell.guid.new() + if template.HasPropertyTemplates: + has_property_templates = list(template.HasPropertyTemplates) + else: + has_property_templates = [] + has_property_templates.append(property_template) + template.HasPropertyTemplates = has_property_templates + property_template.Name = blender_property_template.name + property_template.Description = blender_property_template.description + property_template.PrimaryMeasureType = blender_property_template.primary_measure_type + property_template.TemplateType = 'P_SINGLEVALUE' + property_template.AccessState = 'READWRITE' + saved_global_ids.append(property_template.GlobalId) + + for element in template.HasPropertyTemplates: + if element.GlobalId not in saved_global_ids: + ifc.IfcStore.pset_template_file.remove(element) + + ifc.IfcStore.pset_template_file.write(ifc.IfcStore.pset_template_path) + from . import prop + prop.refreshPropertySetTemplates(self, context) return {'FINISHED'} @@ -1791,4 +1842,15 @@ class AddPropertyTemplate(bpy.types.Operator): bl_label = 'Add Property Template' def execute(self, context): + context.scene.BIMProperties.property_templates.add() + return {'FINISHED'} + + +class RemovePropertyTemplate(bpy.types.Operator): + bl_idname = 'bim.remove_property_template' + bl_label = 'Remove Property Template' + index: bpy.props.IntProperty() + + def execute(self, context): + bpy.context.scene.BIMProperties.property_templates.remove(self.index) return {'FINISHED'} diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index 28cfc59844..66963316db 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -6,6 +6,7 @@ from pathlib import Path from . import export_ifc from . import schema from . import bcf +from . import ifc import bpy from bpy.types import PropertyGroup from bpy.app.handlers import persistent @@ -245,8 +246,10 @@ def refreshPropertySetTemplates(self, context): def getPropertySetTemplates(self, context): global propertysettemplates_enum if len(propertysettemplates_enum) < 1: - f = ifcopenshell.open(os.path.join(self.data_dir, 'pset', self.pset_template_files + '.ifc')) - templates = f.by_type('IfcPropertySetTemplate') + ifc.IfcStore.pset_template_path = os.path.join( + context.scene.BIMProperties.data_dir, 'pset', context.scene.BIMProperties.pset_template_files + '.ifc') + ifc.IfcStore.pset_template_file = ifcopenshell.open(ifc.IfcStore.pset_template_path) + templates = ifc.IfcStore.pset_template_file.by_type('IfcPropertySetTemplate') propertysettemplates_enum.extend([(t.GlobalId, t.Name, '') for t in templates]) return propertysettemplates_enum @@ -601,11 +604,18 @@ class PropertySetTemplate(PropertyGroup): template_type: EnumProperty(items=[ ('PSET_TYPEDRIVENONLY', 'Pset - IfcTypeObject', 'The property sets defined by this IfcPropertySetTemplate can only be assigned to subtypes of IfcTypeObject.'), ('PSET_TYPEDRIVENOVERRIDE', 'Pset - IfcTypeObject - Override', 'The property sets defined by this IfcPropertySetTemplate can only be assigned to subtypes of IfcTypeObject.'), + ('PSET_OCCURRENCEDRIVEN', 'Pset - IfcObject', 'The property sets defined by this IfcPropertySetTemplate can only be assigned to subtypes of IfcObject.'), + ('PSET_PERFORMANCEDRIVEN', 'Pset - IfcPerformanceHistory', 'The property sets defined by this IfcPropertySetTemplate can only be assigned to IfcPerformanceHistory.'), + ('QTO_TYPEDRIVENONLY', 'Qto - IfcTypeObject', 'The element quantity defined by this IfcPropertySetTemplate can only be assigned to subtypes of IfcTypeObject.'), + ('QTO_TYPEDRIVENOVERRIDE', 'Qto - IfcTypeObject - Override', 'The element quantity defined by this IfcPropertySetTemplate can be assigned to subtypes of IfcTypeObject and can be overridden by an element quantity with same name at subtypes of IfcObject.'), + ('QTO_OCCURRENCEDRIVEN', 'Qto - IfcObject', 'The element quantity defined by this IfcPropertySetTemplate can only be assigned to subtypes of IfcObject.'), + ('NOTDEFINED', 'Not defined', 'No restriction provided, the property sets defined by this IfcPropertySetTemplate can be assigned to any entity, if not otherwise restricted by the ApplicableEntity attribute.') ], name="Template Type") applicable_entity: StringProperty(name="Applicable Entity") class PropertyTemplate(PropertyGroup): + global_id: StringProperty(name='Global ID') name: StringProperty(name='Name') description: StringProperty(name='Description') primary_measure_type: EnumProperty(items=[ diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index 4409e04999..12bc0fafbe 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -180,7 +180,7 @@ class BIM_PT_psets(Panel): row = layout.row(align=True) row.prop(props, 'property_set_templates', text='') row.operator('bim.add_property_set_template', text='', icon='ADD') - row.operator('bim.delete_property_set_template', text='', icon='PANEL_CLOSE') + row.operator('bim.remove_property_set_template', text='', icon='PANEL_CLOSE') row.operator('bim.edit_property_set_template', text='', icon='IMPORT') row.operator('bim.save_property_set_template', text='', icon='EXPORT') @@ -203,7 +203,7 @@ class BIM_PT_psets(Panel): row.prop(template, 'name', text='') row.prop(template, 'description', text='') row.prop(template, 'primary_measure_type', text='') - row.operator('bim.remove_classification', icon='X', text='').classification_index = index + row.operator('bim.remove_property_template', icon='X', text='').index = index class BIM_PT_classifications(Panel):