diff --git a/src/blenderbim/blenderbim/bim/helper.py b/src/blenderbim/blenderbim/bim/helper.py index 26bc940be4..5682f5ee37 100644 --- a/src/blenderbim/blenderbim/bim/helper.py +++ b/src/blenderbim/blenderbim/bim/helper.py @@ -245,7 +245,9 @@ def get_obj_ifc_definition_id(context, obj, obj_type): ].ifc_definition_id elif obj_type == "WorkSchedule": return context.scene.BIMWorkScheduleProperties.active_work_schedule_id - + elif obj_type == "Group": + prop = context.scene.BIMGroupProperties + return prop.groups[prop.active_group_index].ifc_definition_id # hack to close popup # https://blender.stackexchange.com/a/202576/130742 diff --git a/src/blenderbim/blenderbim/bim/module/group/prop.py b/src/blenderbim/blenderbim/bim/module/group/prop.py index c64c77814a..bec18bbdae 100644 --- a/src/blenderbim/blenderbim/bim/module/group/prop.py +++ b/src/blenderbim/blenderbim/bim/module/group/prop.py @@ -18,7 +18,7 @@ import bpy from blenderbim.bim.prop import StrProperty, Attribute -from blenderbim.bim.helper import import_attributes +from blenderbim.bim.module.pset.data import refresh as refresh_pset from bpy.types import PropertyGroup import json from bpy.props import ( @@ -33,6 +33,10 @@ from bpy.props import ( ) +def update_active_group_index(self, context): + refresh_pset() + + class ExpandedGroups(StrProperty): json_string: StringProperty(name="JSON String", default="[]") @@ -50,5 +54,5 @@ class BIMGroupProperties(PropertyGroup): group_attributes: CollectionProperty(name="Group Attributes", type=Attribute) is_editing: BoolProperty(name="Is Editing", default=False) groups: CollectionProperty(name="Groups", type=Group) - active_group_index: IntProperty(name="Active Group Index") + active_group_index: IntProperty(name="Active Group Index", update=update_active_group_index) active_group_id: IntProperty(name="Active Group Id") diff --git a/src/blenderbim/blenderbim/bim/module/pset/__init__.py b/src/blenderbim/blenderbim/bim/module/pset/__init__.py index ce6343975f..fd0bdcda57 100644 --- a/src/blenderbim/blenderbim/bim/module/pset/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/pset/__init__.py @@ -44,6 +44,7 @@ classes = ( prop.MaterialSetItemPsetProperties, prop.TaskPsetProperties, prop.ResourcePsetProperties, + prop.GroupPsetProperties, prop.ProfilePsetProperties, prop.WorkSchedulePsetProperties, prop.RenameProperties, @@ -57,6 +58,8 @@ classes = ( ui.BIM_PT_task_qtos, ui.BIM_PT_resource_qtos, ui.BIM_PT_resource_psets, + ui.BIM_PT_group_psets, + ui.BIM_PT_group_qtos, ui.BIM_PT_profile_psets, ui.BIM_PT_work_schedule_psets, ui.BIM_PT_bulk_property_editor, @@ -73,6 +76,7 @@ def register(): bpy.types.Material.PsetProperties = bpy.props.PointerProperty(type=prop.MaterialPsetProperties) bpy.types.Scene.TaskPsetProperties = bpy.props.PointerProperty(type=prop.TaskPsetProperties) bpy.types.Scene.ResourcePsetProperties = bpy.props.PointerProperty(type=prop.ResourcePsetProperties) + bpy.types.Scene.GroupPsetProperties = bpy.props.PointerProperty(type=prop.GroupPsetProperties) bpy.types.Scene.ProfilePsetProperties = bpy.props.PointerProperty(type=prop.ProfilePsetProperties) bpy.types.Scene.WorkSchedulePsetProperties = bpy.props.PointerProperty(type=prop.WorkSchedulePsetProperties) bpy.types.Scene.RenameProperties = bpy.props.CollectionProperty(type=prop.RenameProperties) @@ -85,6 +89,7 @@ def unregister(): del bpy.types.Material.PsetProperties del bpy.types.Scene.TaskPsetProperties del bpy.types.Scene.ResourcePsetProperties + del bpy.types.Scene.GroupPsetProperties del bpy.types.Scene.ProfilePsetProperties del bpy.types.Scene.WorkSchedulePsetProperties del bpy.types.Scene.RenameProperties diff --git a/src/blenderbim/blenderbim/bim/module/pset/data.py b/src/blenderbim/blenderbim/bim/module/pset/data.py index 344dcaeed4..a5f4d66311 100644 --- a/src/blenderbim/blenderbim/bim/module/pset/data.py +++ b/src/blenderbim/blenderbim/bim/module/pset/data.py @@ -36,6 +36,8 @@ def refresh(): TaskQtosData.is_loaded = False ResourceQtosData.is_loaded = False ResourcePsetsData.is_loaded = False + GroupQtosData.is_loaded = False + GroupPsetData.is_loaded = False ProfilePsetsData.is_loaded = False WorkSchedulePsetsData.is_loaded = False AddEditCustomPropertiesData.is_loaded = False @@ -205,6 +207,30 @@ class ResourcePsetsData(Data): cls.is_loaded = True +class GroupQtosData(Data): + data = {} + is_loaded = False + + @classmethod + def load(cls): + props = bpy.context.scene.BIMGroupProperties + ifc_definition_id = props.groups[props.active_group_index].ifc_definition_id + cls.data = {"qtos": cls.psetqtos(tool.Ifc.get_entity_by_id(ifc_definition_id), qtos_only=True)} + cls.is_loaded = True + + +class GroupPsetData(Data): + data = {} + is_loaded = False + + @classmethod + def load(cls): + props = bpy.context.scene.BIMGroupProperties + ifc_definition_id = props.groups[props.active_group_index].ifc_definition_id + cls.data = {"psets": cls.psetqtos(tool.Ifc.get_entity_by_id(ifc_definition_id), psets_only=True)} + cls.is_loaded = True + + class ProfilePsetsData(Data): data = {} is_loaded = False diff --git a/src/blenderbim/blenderbim/bim/module/pset/operator.py b/src/blenderbim/blenderbim/bim/module/pset/operator.py index 132844c7fd..66d0701697 100644 --- a/src/blenderbim/blenderbim/bim/module/pset/operator.py +++ b/src/blenderbim/blenderbim/bim/module/pset/operator.py @@ -58,7 +58,8 @@ def get_pset_props(context, obj, obj_type): return context.scene.ProfilePsetProperties elif obj_type == "WorkSchedule": return context.scene.WorkSchedulePsetProperties - + elif obj_type == "Group": + return context.scene.GroupPsetProperties class TogglePsetExpansion(bpy.types.Operator, Operator): bl_idname = "bim.toggle_pset_expansion" @@ -196,6 +197,7 @@ class EnablePsetEditing(bpy.types.Operator): new.is_selected = enum in selected_enum_items def load_from_pset_data(self, pset): + props = [] if pset.is_a("IfcElementQuantity"): props = pset.Quantities elif pset.is_a("IfcPropertySet"): diff --git a/src/blenderbim/blenderbim/bim/module/pset/prop.py b/src/blenderbim/blenderbim/bim/module/pset/prop.py index d60828a560..05b70a79d9 100644 --- a/src/blenderbim/blenderbim/bim/module/pset/prop.py +++ b/src/blenderbim/blenderbim/bim/module/pset/prop.py @@ -130,6 +130,23 @@ def get_resource_qto_names(self, context): return qtonames[ifc_class] +def get_group_pset_names(self, context): + global psetnames + ifc_class = "IfcGroup" + if ifc_class not in psetnames: + psets = blenderbim.bim.schema.ifc.psetqto.get_applicable(ifc_class, pset_only=True) + psetnames[ifc_class] = blender_formatted_enum_from_psets(psets) + return psetnames[ifc_class] + + +def get_group_qto_names(self, context): + global qtonames + ifc_class = "IfcGroup" + if ifc_class not in qtonames: + psets = blenderbim.bim.schema.ifc.psetqto.get_applicable(ifc_class, qto_only=True) + qtonames[ifc_class] = blender_formatted_enum_from_psets(psets) + return qtonames[ifc_class] + def get_profile_pset_names(self, context): global psetnames pprops = context.scene.BIMProfileProperties @@ -229,6 +246,14 @@ class ResourcePsetProperties(PropertyGroup): qto_name: EnumProperty(items=get_resource_qto_names, name="Qto Name") +class GroupPsetProperties(PropertyGroup): + active_pset_id: IntProperty(name="Active Pset ID") + active_pset_name: StringProperty(name="Pset Name") + active_pset_type: StringProperty(name="Active Pset Type") + properties: CollectionProperty(name="Properties", type=IfcProperty) + pset_name: EnumProperty(items=get_group_pset_names, name="Pset Name") + qto_name: EnumProperty(items=get_group_qto_names, name="Qto Name") + class ProfilePsetProperties(PropertyGroup): active_pset_id: IntProperty(name="Active Pset ID") active_pset_name: StringProperty(name="Pset Name") diff --git a/src/blenderbim/blenderbim/bim/module/pset/ui.py b/src/blenderbim/blenderbim/bim/module/pset/ui.py index b3296530d4..549a9fbe18 100644 --- a/src/blenderbim/blenderbim/bim/module/pset/ui.py +++ b/src/blenderbim/blenderbim/bim/module/pset/ui.py @@ -29,8 +29,11 @@ from blenderbim.bim.module.pset.data import ( TaskQtosData, ResourceQtosData, ResourcePsetsData, + GroupQtosData, + GroupPsetData, ProfilePsetsData, WorkSchedulePsetsData, + ) @@ -470,6 +473,76 @@ class BIM_PT_resource_psets(Panel): draw_psetqto_ui(context, pset["id"], pset, props, self.layout, "Resource") +class BIM_PT_group_qtos(Panel): + bl_label = "Group Quantity Sets" + bl_idname = "BIM_PT_group_qtos" + bl_options = {"DEFAULT_CLOSED"} + bl_space_type = "PROPERTIES" + bl_region_type = "WINDOW" + bl_context = "scene" + bl_parent_id = "BIM_PT_groups" + + @classmethod + def poll(cls, context): + props = context.scene.BIMGroupProperties + total_resources = len(props.groups) + if total_resources > 0 and props.active_group_index < total_resources: + return True + return False + + def draw(self, context): + if not GroupQtosData.is_loaded: + GroupQtosData.load() + + props = context.scene.GroupPsetProperties + row = self.layout.row(align=True) + row.prop(props, "qto_name", text="") + op = row.operator("bim.add_qto", icon="ADD", text="") + op.obj_type = "Group" + + if not props.active_pset_id and props.active_pset_name and props.active_pset_type == "QTO": + draw_psetqto_ui(context, 0, {}, props, self.layout, "Group") + + for qto in GroupQtosData.data["qtos"]: + draw_psetqto_ui(context, qto["id"], qto, props, self.layout, "Group") + + +class BIM_PT_group_psets(Panel): + bl_label = "Group Property Sets" + bl_idname = "BIM_PT_group_psets" + bl_options = {"DEFAULT_CLOSED"} + bl_space_type = "PROPERTIES" + bl_region_type = "WINDOW" + bl_context = "scene" + bl_parent_id = "BIM_PT_groups" + + @classmethod + def poll(cls, context): + props = context.scene.BIMGroupProperties + total_resources = len(props.groups) + if total_resources > 0 and props.active_group_index < total_resources: + return True + return False + + def draw(self, context): + if not GroupPsetData.is_loaded: + GroupPsetData.load() + + props = context.scene.GroupPsetProperties + row = self.layout.row(align=True) + prop_with_search(row, props, "pset_name", text="") + op = row.operator("bim.add_pset", icon="ADD", text="") + op.obj_type = "Group" + + if not props.active_pset_id and props.active_pset_name and props.active_pset_type == "PSET": + draw_psetqto_ui(context, 0, {}, props, self.layout, "Group") + + for pset in GroupPsetData.data["psets"]: + draw_psetqto_ui(context, pset["id"], pset, props, self.layout, "Group") + + + + class BIM_PT_profile_psets(Panel): bl_label = "Profile Property Sets" bl_idname = "BIM_PT_profile_psets" diff --git a/src/blenderbim/blenderbim/tool/blender.py b/src/blenderbim/blenderbim/tool/blender.py index 3332b35c3f..55ab0a456d 100644 --- a/src/blenderbim/blenderbim/tool/blender.py +++ b/src/blenderbim/blenderbim/tool/blender.py @@ -139,6 +139,9 @@ class Blender(blenderbim.core.tool.Blender): ].ifc_definition_id elif obj_type == "WorkSchedule": return bpy.context.scene.BIMWorkScheduleProperties.active_work_schedule_id + elif obj_type == "Group": + prop = bpy.context.scene.BIMGroupProperties + return prop.groups[prop.active_group_index].ifc_definition_id @classmethod def is_ifc_object(cls, obj):