From dc92a8fd2784a1837f6f5b4491278f86a9d81496 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 10 Sep 2024 16:10:35 +0500 Subject: [PATCH] Bonsai - setup default values for new patametric profiles So there will be less invalid IFC and user will get a preview right away after creating a new profile. Example - https://imgur.com/a/GjkCql4 --- .../bonsai/bim/module/profile/operator.py | 1 + src/bonsai/bonsai/tool/profile.py | 101 ++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/src/bonsai/bonsai/bim/module/profile/operator.py b/src/bonsai/bonsai/bim/module/profile/operator.py index 2c0a7faee8..459f9bf1ce 100644 --- a/src/bonsai/bonsai/bim/module/profile/operator.py +++ b/src/bonsai/bonsai/bim/module/profile/operator.py @@ -149,6 +149,7 @@ class AddProfileDef(bpy.types.Operator, tool.Ifc.Operator): profile = ifcopenshell.api.run("profile.add_arbitrary_profile", tool.Ifc.get(), profile=points) else: profile = ifcopenshell.api.run("profile.add_parameterized_profile", tool.Ifc.get(), ifc_class=profile_class) + tool.Profile.set_default_profile_attrs(profile) profile.ProfileName = "New Profile" bpy.ops.bim.load_profiles() diff --git a/src/bonsai/bonsai/tool/profile.py b/src/bonsai/bonsai/tool/profile.py index ae1d9a45de..6a8d0a3b6d 100644 --- a/src/bonsai/bonsai/tool/profile.py +++ b/src/bonsai/bonsai/tool/profile.py @@ -116,3 +116,104 @@ class Profile(bonsai.core.tool.Profile): index = props.active_profile_index if len(props.profiles) > index >= 0: return props.profiles[index] + + # Lengths are in meters. + DEFAULT_PROFILE_ATTRS = { + "IfcCircleProfileDef": { + "Radius": 0.05, + }, + # TODO: test after debug + "IfcAsymmetricIShapeProfileDef": { + "BottomFlangeWidth": 0.1, + "BottomFlangeThickness": 0.01, + "BottomFlangeFilletRadius": 0.01, + "OverallDepth": 0.1, + "WebThickness": 0.005, + "TopFlangeWidth": 0.075, + "TopFlangeThickness": 0.01, + "TopFlangeFilletRadius": 0.01, + }, + "IfcCShapeProfileDef": { + "Depth": 0.1, + "Width": 0.05, + "WallThickness": 0.01, + "Girth": 0.01, + }, + # 101.6-10.0 + "IfcCircleHollowProfileDef": { + "WallThickness": 0.01, + }, + # TODO: check shape after fixing crash + # "IfcEllipseProfileDef": { + # "SemiAxis1": 0.1, + # "SemiAxis2": 0.1, + # }, + # HEA100 + "IfcIShapeProfileDef": { + "OverallWidth": 0.1, + "OverallDepth": 0.1, + "WebThickness": 0.005, + "FlangeThickness": 0.01, + "FilletRadius": 0.01, + }, + # LNP100x10 + "IfcLShapeProfileDef": { + "Depth": 0.1, + "Thickness": 0.01, + "FilletRadius": 0.012, + "EdgeRadius": 0.01, + }, + "IfcRectangleProfileDef": { + "XDim": 0.1, + "YDim": 0.1, + }, + "IfcRoundedRectangleProfileDef": { + "RoundingRadius": 0.01, + }, + # 100-10.0 + "IfcRectangleHollowProfileDef": { + "WallThickness": 0.01, + "InnerFilletRadius": 0.01, + "OuterFilletRadius": 0.01, + }, + "IfcTShapeProfileDef": { + "Depth": 0.1, + "FlangeWidth": 0.05, + "WebThickness": 0.005, + "FlangeThickness": 0.009, + }, + "IfcTrapeziumProfileDef": { + "BottomXDim": 0.1, + "TopXDim": 0.08, + "YDim": 0.05, + "TopXOffset": 0.01, + }, + # UAP100 + "IfcUShapeProfileDef": { + "Depth": 0.1, + "FlangeWidth": 0.05, + "WebThickness": 0.005, + "FlangeThickness": 0.009, + }, + # ZNP100 + "IfcZShapeProfileDef": { + "Depth": 0.1, + "FlangeWidth": 0.05, + "WebThickness": 0.007, + "FlangeThickness": 0.01, + }, + } + + @classmethod + def set_default_profile_attrs(cls, profile: ifcopenshell.entity_instance) -> None: + """Set default profile attributes to keep profile valid.""" + class_match = False + si_conversion = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) + for ifc_class, params in cls.DEFAULT_PROFILE_ATTRS.items(): + if profile.is_a(ifc_class): + class_match = True + for key, value in params.items(): + setattr(profile, key, value / si_conversion) + + if not class_match: + raise ValueError(f"Unable to set default profile parameters for {profile.is_a()}.")