From 67d62e5f21881e748c06fe7cdbd81e7b4738a3eb Mon Sep 17 00:00:00 2001 From: Vukas Pajic Date: Mon, 6 Dec 2021 12:58:08 +0100 Subject: [PATCH] type dropdown now references ifc data types --- .../blenderbim/bim/module/pset/operator.py | 7 +- .../blenderbim/bim/module/pset/prop.py | 25 ++-- .../blenderbim/bim/module/pset/ui.py | 2 +- .../bim/module/pset_template/prop.py | 113 +----------------- src/blenderbim/blenderbim/bim/prop.py | 111 +++++++++++++++++ 5 files changed, 133 insertions(+), 125 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/pset/operator.py b/src/blenderbim/blenderbim/bim/module/pset/operator.py index 52e445639f..0813a32739 100644 --- a/src/blenderbim/blenderbim/bim/module/pset/operator.py +++ b/src/blenderbim/blenderbim/bim/module/pset/operator.py @@ -394,7 +394,7 @@ class BIM_OT_remove_property_to_edit(bpy.types.Operator): option: bpy.props.StringProperty() def execute(self, context): - getattr(context.scene, self.option).remove() + getattr(context.scene, self.option).remove(self.index) return {"FINISHED"} @@ -469,6 +469,9 @@ class BIM_OT_add_edit_custom_property(bpy.types.Operator): for prop in props: value = getattr(prop, prop.get_value_name()) + primary_measure_type = prop.primary_measure_type + value_ifc_entity = getattr(self.file, f"create{primary_measure_type}")(value) + new_pset = ifcopenshell.api.run( "pset.add_pset", self.file, @@ -479,7 +482,7 @@ class BIM_OT_add_edit_custom_property(bpy.types.Operator): "pset.edit_pset", self.file, pset=new_pset, - properties={prop.property_name:value} + properties={prop.property_name:value_ifc_entity} ) self.report({'INFO'}, 'Finished applying changes') diff --git a/src/blenderbim/blenderbim/bim/module/pset/prop.py b/src/blenderbim/blenderbim/bim/module/pset/prop.py index b2e01515d9..153b89c4aa 100644 --- a/src/blenderbim/blenderbim/bim/module/pset/prop.py +++ b/src/blenderbim/blenderbim/bim/module/pset/prop.py @@ -18,7 +18,8 @@ import bpy import blenderbim.bim.schema -from blenderbim.bim.prop import Attribute +from blenderbim.bim.prop import Attribute, PRIMARY_MEASURE_TYPE +import ifcopenshell from ifcopenshell.api.pset.data import Data from blenderbim.bim.ifc import IfcStore from bpy.types import PropertyGroup @@ -188,23 +189,25 @@ class AddEditProperties(PropertyGroup): bool_value: BoolProperty(name="Value") int_value: IntProperty(name="Value") float_value: FloatProperty(name="Value") - data_type: EnumProperty( + primary_measure_type: EnumProperty( items=[ - ("string", "String", "" ), - ("boolean", "True/False", "" ), - ("integer", "Integer", "" ), - ("float", "Number", "" )], - default="string" + (x, x, "") + for x in PRIMARY_MEASURE_TYPE + ], + default="IfcLabel", + name="Primary Measure Type" ) def get_value_name(self): - if self.data_type == "string": + ifc_data_type = IfcStore.get_schema().declaration_by_name(self.primary_measure_type) + data_type = ifcopenshell.util.attribute.get_primitive_type(ifc_data_type) + if data_type == "string": return "string_value" - elif self.data_type == "boolean": + elif data_type == "boolean": return "bool_value" - elif self.data_type == "integer": + elif data_type == "integer": return "int_value" - elif self.data_type == "float": + elif data_type == "float": return "float_value" diff --git a/src/blenderbim/blenderbim/bim/module/pset/ui.py b/src/blenderbim/blenderbim/bim/module/pset/ui.py index a1cdf1b199..0beb3882f3 100644 --- a/src/blenderbim/blenderbim/bim/module/pset/ui.py +++ b/src/blenderbim/blenderbim/bim/module/pset/ui.py @@ -441,7 +441,7 @@ class BIM_PT_add_edit_custom_properties(Panel): row.prop(prop, "pset_name", text="") row.prop(prop, "property_name", text="") row.prop(prop, prop.get_value_name(), text="") - row.prop(prop, "data_type", text="") + row.prop(prop, "primary_measure_type", text="") op = row.operator("bim.remove_property_to_edit",icon="PANEL_CLOSE", text="") op.index = index op.option = "AddEditProperties" diff --git a/src/blenderbim/blenderbim/bim/module/pset_template/prop.py b/src/blenderbim/blenderbim/bim/module/pset_template/prop.py index 6f41a98a23..9ec6925cb5 100644 --- a/src/blenderbim/blenderbim/bim/module/pset_template/prop.py +++ b/src/blenderbim/blenderbim/bim/module/pset_template/prop.py @@ -19,7 +19,7 @@ import os import bpy import ifcopenshell -from blenderbim.bim.prop import StrProperty, Attribute +from blenderbim.bim.prop import StrProperty, Attribute, PRIMARY_MEASURE_TYPE from blenderbim.bim.ifc import IfcStore from bpy.types import PropertyGroup from bpy.props import ( @@ -146,116 +146,7 @@ class PropTemplate(PropertyGroup): 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", - ] + for x in PRIMARY_MEASURE_TYPE ], name="Primary Measure Type", ) diff --git a/src/blenderbim/blenderbim/bim/prop.py b/src/blenderbim/blenderbim/bim/prop.py index 8f8928f545..0cf62385f3 100644 --- a/src/blenderbim/blenderbim/bim/prop.py +++ b/src/blenderbim/blenderbim/bim/prop.py @@ -40,6 +40,117 @@ cwd = os.path.dirname(os.path.realpath(__file__)) materialpsetnames_enum = [] +PRIMARY_MEASURE_TYPE = [ + "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", + ] + def update_preset(self, context): from blenderbim.bim.data.ui.presets import presets