From 9ad57d658ef2bbe460624dcf3a63ef975deaddd6 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 24 Apr 2020 17:14:07 +1000 Subject: [PATCH] New feature to read pset template files --- .../blenderbim/bim/__init__.py | 8 + .../bim/{schema => data/pset}/Pset_Custom.ifc | 0 .../bim/data/pset/Pset_DoorCommon/typical.csv | 5 - .../pset/Pset_FurnitureTypeCommon/monkey.csv | 8 - .../monkeyoverride.csv | 1 - .../blenderbim/bim/operator.py | 57 ++++++ src/ifcblenderexport/blenderbim/bim/prop.py | 164 +++++++++++++++++- src/ifcblenderexport/blenderbim/bim/ui.py | 44 +++++ 8 files changed, 268 insertions(+), 19 deletions(-) rename src/ifcblenderexport/blenderbim/bim/{schema => data/pset}/Pset_Custom.ifc (100%) delete mode 100644 src/ifcblenderexport/blenderbim/bim/data/pset/Pset_DoorCommon/typical.csv delete mode 100644 src/ifcblenderexport/blenderbim/bim/data/pset/Pset_FurnitureTypeCommon/monkey.csv delete mode 100644 src/ifcblenderexport/blenderbim/bim/data/pset/Pset_FurnitureTypeCommon/monkeyoverride.csv diff --git a/src/ifcblenderexport/blenderbim/bim/__init__.py b/src/ifcblenderexport/blenderbim/bim/__init__.py index 9f27e83bcf..b201f3ee49 100644 --- a/src/ifcblenderexport/blenderbim/bim/__init__.py +++ b/src/ifcblenderexport/blenderbim/bim/__init__.py @@ -99,10 +99,17 @@ if bpy is not None: operator.OpenUpstream, operator.BIM_OT_CopyAttributesToSelection, operator.BIM_OT_ChangeClassificationLevel, + operator.AddPropertySetTemplate, + operator.DeletePropertySetTemplate, + operator.EditPropertySetTemplate, + operator.SavePropertySetTemplate, + operator.AddPropertyTemplate, prop.StrProperty, prop.Classification, prop.ClassificationReference, prop.ClassificationView, + prop.PropertySetTemplate, + prop.PropertyTemplate, prop.BcfTopic, prop.BcfTopicLabel, prop.BcfTopicFile, @@ -128,6 +135,7 @@ if bpy is not None: prop.BIMCameraProperties, ui.BIM_PT_documentation, ui.BIM_PT_bim, + ui.BIM_PT_psets, ui.BIM_PT_classifications, ui.BIM_PT_search, ui.BIM_PT_bcf, diff --git a/src/ifcblenderexport/blenderbim/bim/schema/Pset_Custom.ifc b/src/ifcblenderexport/blenderbim/bim/data/pset/Pset_Custom.ifc similarity index 100% rename from src/ifcblenderexport/blenderbim/bim/schema/Pset_Custom.ifc rename to src/ifcblenderexport/blenderbim/bim/data/pset/Pset_Custom.ifc diff --git a/src/ifcblenderexport/blenderbim/bim/data/pset/Pset_DoorCommon/typical.csv b/src/ifcblenderexport/blenderbim/bim/data/pset/Pset_DoorCommon/typical.csv deleted file mode 100644 index a2fa3cfb5d..0000000000 --- a/src/ifcblenderexport/blenderbim/bim/data/pset/Pset_DoorCommon/typical.csv +++ /dev/null @@ -1,5 +0,0 @@ -Reference,myref -Status,TEMPORARY -FireRating,2HR -AcousticRating,0.5R -IsExternal,True diff --git a/src/ifcblenderexport/blenderbim/bim/data/pset/Pset_FurnitureTypeCommon/monkey.csv b/src/ifcblenderexport/blenderbim/bim/data/pset/Pset_FurnitureTypeCommon/monkey.csv deleted file mode 100644 index 94f2360060..0000000000 --- a/src/ifcblenderexport/blenderbim/bim/data/pset/Pset_FurnitureTypeCommon/monkey.csv +++ /dev/null @@ -1,8 +0,0 @@ -Reference,Some reference -Status,EXISTING -Style,Some style -NominalHeight,1.2 -NominalLength,1.3 -NominalDepth,1.5 -MainColor,Blue -IsBuiltIn,Uh-huh diff --git a/src/ifcblenderexport/blenderbim/bim/data/pset/Pset_FurnitureTypeCommon/monkeyoverride.csv b/src/ifcblenderexport/blenderbim/bim/data/pset/Pset_FurnitureTypeCommon/monkeyoverride.csv deleted file mode 100644 index 1276a61ef2..0000000000 --- a/src/ifcblenderexport/blenderbim/bim/data/pset/Pset_FurnitureTypeCommon/monkeyoverride.csv +++ /dev/null @@ -1 +0,0 @@ -MainColor,Red diff --git a/src/ifcblenderexport/blenderbim/bim/operator.py b/src/ifcblenderexport/blenderbim/bim/operator.py index d5c52effe9..ac1aaeb154 100644 --- a/src/ifcblenderexport/blenderbim/bim/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/operator.py @@ -1735,3 +1735,60 @@ class BIM_OT_ChangeClassificationLevel(bpy.types.Operator): else: lst.root = '' return {'FINISHED'} + + +class AddPropertySetTemplate(bpy.types.Operator): + bl_idname = 'bim.add_property_set_template' + bl_label = 'Add Property Set Template' + + def execute(self, context): + return {'FINISHED'} + + +class DeletePropertySetTemplate(bpy.types.Operator): + bl_idname = 'bim.delete_property_set_template' + bl_label = 'Delete Property Set Template' + + def execute(self, context): + return {'FINISHED'} + +class EditPropertySetTemplate(bpy.types.Operator): + bl_idname = 'bim.edit_property_set_template' + 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) + 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 + context.scene.BIMProperties.active_property_set_template.template_type = template.TemplateType + context.scene.BIMProperties.active_property_set_template.applicable_entity = template.ApplicableEntity + + 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 + return {'FINISHED'} + +class SavePropertySetTemplate(bpy.types.Operator): + bl_idname = 'bim.save_property_set_template' + bl_label = 'Save Property Set Template' + + def execute(self, context): + return {'FINISHED'} + + +class AddPropertyTemplate(bpy.types.Operator): + bl_idname = 'bim.add_property_template' + bl_label = 'Add Property Template' + + def execute(self, context): + return {'FINISHED'} diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index 9433c4a90b..28cfc59844 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -31,6 +31,8 @@ featuresfiles_enum = [] scenarios_enum = [] psetnames_enum = [] psetfiles_enum = [] +psettemplatefiles_enum = [] +propertysettemplates_enum = [] classification_enum = [] attributes_enum = [] overridepsetnames_enum = [] @@ -223,14 +225,32 @@ def refreshPsetFiles(self, context): def getPsetFiles(self, context): global psetfiles_enum - if len(psetfiles_enum) < 1: - if not self.pset_name.strip(): - return psetfiles_enum - files = os.listdir(os.path.join(self.data_dir, 'pset', self.pset_name.strip())) - psetfiles_enum.extend([(f.replace('.csv', ''), f.replace('.csv', ''), '') for f in files]) return psetfiles_enum +def getPsetTemplateFiles(self, context): + global psettemplatefiles_enum + if len(psettemplatefiles_enum) < 1: + files = os.listdir(os.path.join(self.data_dir, 'pset')) + psettemplatefiles_enum.extend([(f.replace('.ifc', ''), f.replace('.ifc', ''), '') for f in files]) + return psettemplatefiles_enum + + +def refreshPropertySetTemplates(self, context): + global propertysettemplates_enum + propertysettemplates_enum.clear() + getPropertySetTemplates(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') + propertysettemplates_enum.extend([(t.GlobalId, t.Name, '') for t in templates]) + return propertysettemplates_enum + + def getClassifications(self, context): global classification_enum if len(classification_enum) < 1: @@ -574,6 +594,136 @@ def getBcfViewpoints(self, context): return bcfviewpoints_enum +class PropertySetTemplate(PropertyGroup): + global_id: StringProperty(name="Global ID") + name: StringProperty(name="Name") + description: StringProperty(name="Description") + 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.'), + ], name="Template Type") + applicable_entity: StringProperty(name="Applicable Entity") + + +class PropertyTemplate(PropertyGroup): + name: StringProperty(name='Name') + description: StringProperty(name='Description') + primary_measure_type: EnumProperty(items=[ + (x, x, '') for x in [ + 'IfcInteger', + 'IfcReal', + 'IfcBoolean', + 'IfcIdentifier', + 'IfcText', + 'IfcLabel', + 'IfcLogical', + 'IfcDateTime', + 'IfcDate', + 'IfcTime', + 'IfcDuration', + 'IfcTimeStamp', + + 'IfcPositiveInteger', + 'IfcBinary', + 'IfcVolumeMeasure', + 'IfcTimeMeasure', + 'IfcThermodynamicTemperatureMeasure', + 'IfcSolidAngleMeasure', + 'IfcPositiveRatioMeasure', + 'IfcRatioMeasure', + 'IfcPositivePlaneAngleMeasure', + 'IfcPlaneAngleMeasure', + 'IfcParameterValue', + 'IfcNumericMeasure', + 'IfcMassMeasure', + 'IfcPositiveLengthMeasure', + 'IfcLengthMeasure', + 'IfcElectricCurrentMeasure', + 'IfcDescriptiveMeasure', + 'IfcCountMeasure', + 'IfcContextDependentMeasure', + 'IfcAreaMeasure', + 'IfcAmountOfSubstanceMeasure', + 'IfcLuminousIntensityMeasure', + 'IfcNormalisedRatioMeasure', + 'IfcComplexNumber', + 'IfcNonNegativeLengthMeasure', + + 'IfcAbsorbedDoseMeasure', + 'IfcAccelerationMeasure', + 'IfcAngularVelocityMeasure', + 'IfcAreaDensityMeasure', + 'IfcCompoundPlaneAngleMeasure', + 'IfcCurvatureMeasure', + 'IfcDoseEquivalentMeasure', + 'IfcDynamicViscosityMeasure', + 'IfcElectricCapacitanceMeasure', + 'IfcElectricChargeMeasure', + 'IfcElectricConductanceMeasure', + 'IfcElectricResistanceMeasure', + 'IfcElectricVoltageMeasure', + 'IfcEnergyMeasure', + 'IfcForceMeasure', + 'IfcFrequencyMeasure', + 'IfcHeatFluxDensityMeasure', + 'IfcHeatingValueMeasure', + 'IfcIlluminanceMeasure', + 'IfcInductanceMeasure', + 'IfcIntegerCountRateMeasure', + 'IfcIonConcentrationMeasure', + 'IfcIsothermalMoistureCapacityMeasure', + 'IfcKinematicViscosityMeasure', + 'IfcLinearForceMeasure', + 'IfcLinearMomentMeasure', + 'IfcLinearStiffnessMeasure', + 'IfcLinearVelocityMeasure', + 'IfcLuminousFluxMeasure', + 'IfcLuminousIntensityDistributionMeasure', + 'IfcMagneticFluxDensityMeasure', + 'IfcMagneticFluxMeasure', + 'IfcMassDensityMeasure', + 'IfcMassFlowRateMeasure', + 'IfcMassPerLengthMeasure', + 'IfcModulusOfElasticityMeasure', + 'IfcModulusOfLinearSubgradeReactionMeasure', + 'IfcModulusOfRotationalSubgradeReactionMeasure', + 'IfcModulusOfSubgradeReactionMeasure', + 'IfcMoistureDiffusivityMeasure', + 'IfcMolecularWeightMeasure', + 'IfcMomentOfInertiaMeasure', + 'IfcMonetaryMeasure', + 'IfcPHMeasure', + 'IfcPlanarForceMeasure', + 'IfcPowerMeasure', + 'IfcPressureMeasure', + 'IfcRadioActivityMeasure', + 'IfcRotationalFrequencyMeasure', + 'IfcRotationalMassMeasure', + 'IfcRotationalStiffnessMeasure', + 'IfcSectionModulusMeasure', + 'IfcSectionalAreaIntegralMeasure', + 'IfcShearModulusMeasure', + 'IfcSoundPowerLevelMeasure', + 'IfcSoundPowerMeasure', + 'IfcSoundPressureLevelMeasure', + 'IfcSoundPressureMeasure', + 'IfcSpecificHeatCapacityMeasure', + 'IfcTemperatureGradientMeasure', + 'IfcTemperatureRateOfChangeMeasure', + 'IfcThermalAdmittanceMeasure', + 'IfcThermalConductivityMeasure', + 'IfcThermalExpansionCoefficientMeasure', + 'IfcThermalResistanceMeasure', + 'IfcThermalTransmittanceMeasure', + 'IfcTorqueMeasure', + 'IfcVaporPermeabilityMeasure', + 'IfcVolumetricFlowRateMeasure', + 'IfcWarpingConstantMeasure', + 'IfcWarpingMomentMeasure', + ] + ], name='Primary Measure Type') + + class Classification(PropertyGroup): name: StringProperty(name="Name") source: StringProperty(name="Source") @@ -707,6 +857,10 @@ class BIMProperties(PropertyGroup): available_subcontexts: EnumProperty(items=getSubcontexts, name="Available Subcontexts") available_target_views: EnumProperty(items=getTargetViews, name="Available Target Views") classification_references: PointerProperty(type=ClassificationView) + pset_template_files: EnumProperty(items=getPsetTemplateFiles, name="Pset Template Files", update=refreshPropertySetTemplates) + property_set_templates: EnumProperty(items=getPropertySetTemplates, name="Pset Template Files") + active_property_set_template: PointerProperty(type=PropertySetTemplate) + property_templates: CollectionProperty(name='Property Templates', type=PropertyTemplate) class BCFProperties(PropertyGroup): diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index e5a31f5ea1..4409e04999 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -162,6 +162,50 @@ class BIM_PT_classification_references(Panel): row.prop(props, 'classifications') +class BIM_PT_psets(Panel): + bl_label = 'Psets' + bl_idname = 'BIM_PT_psets' + bl_options = {'DEFAULT_CLOSED'} + bl_space_type = 'PROPERTIES' + bl_region_type = 'WINDOW' + bl_context = 'scene' + + def draw(self, context): + layout = self.layout + props = context.scene.BIMProperties + + row = layout.row(align=True) + row.prop(props, 'pset_template_files', text='') + + 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.edit_property_set_template', text='', icon='IMPORT') + row.operator('bim.save_property_set_template', text='', icon='EXPORT') + + row = layout.row(align=True) + row.prop(props.active_property_set_template, 'name') + row = layout.row(align=True) + row.prop(props.active_property_set_template, 'description') + row = layout.row(align=True) + row.prop(props.active_property_set_template, 'template_type') + row = layout.row(align=True) + row.prop(props.active_property_set_template, 'applicable_entity') + + layout.label(text='Property Templates:') + + row = layout.row(align=True) + row.operator('bim.add_property_template') + + for index, template in enumerate(props.property_templates): + row = layout.row(align=True) + 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 + + class BIM_PT_classifications(Panel): bl_label = 'Classifications' bl_idname = 'BIM_PT_classifications'