ExpandedGroups - encapsulate in BIMGroupProperties

This commit is contained in:
Andrej
2025-06-09 16:25:36 +05:00
parent 32088fb95a
commit 24f693e0bb
3 changed files with 6 additions and 13 deletions
@@ -32,7 +32,6 @@ classes = (
operator.SetGroupVisibility,
operator.ToggleGroup,
operator.UnassignGroup,
prop.ExpandedGroups,
prop.Group,
prop.BIMGroupProperties,
ui.BIM_PT_groups,
@@ -43,9 +42,7 @@ classes = (
def register():
bpy.types.Scene.BIMGroupProperties = bpy.props.PointerProperty(type=prop.BIMGroupProperties)
bpy.types.Scene.ExpandedGroups = bpy.props.PointerProperty(type=prop.ExpandedGroups)
def unregister():
del bpy.types.Scene.BIMGroupProperties
del bpy.types.Scene.ExpandedGroups
@@ -32,7 +32,7 @@ class LoadGroups(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context):
self.props = tool.Blender.get_group_props()
self.expanded_groups = json.loads(context.scene.ExpandedGroups.json_string)
self.expanded_groups = json.loads(self.props.expanded_groups_json)
self.props.groups.clear()
groups = [
@@ -79,12 +79,13 @@ class ToggleGroup(bpy.types.Operator, tool.Ifc.Operator):
option: bpy.props.StringProperty(name="Expand or Collapse")
def _execute(self, context):
expanded_groups = set(json.loads(context.scene.ExpandedGroups.json_string))
props = tool.Blender.get_group_props()
expanded_groups = set(json.loads(props.expanded_groups_json))
if self.option == "Expand":
expanded_groups.add(self.ifc_definition_id)
elif self.ifc_definition_id in expanded_groups:
expanded_groups.remove(self.ifc_definition_id)
context.scene.ExpandedGroups.json_string = json.dumps(list(expanded_groups))
props.expanded_groups_json = json.dumps(list(expanded_groups))
bpy.ops.bim.load_groups()
return {"FINISHED"}
+2 -7
View File
@@ -38,13 +38,6 @@ def update_active_group_index(self, context):
refresh_pset()
class ExpandedGroups(StrProperty):
json_string: StringProperty(name="JSON String", default="[]")
if TYPE_CHECKING:
json_string: str
class Group(PropertyGroup):
name: StringProperty(name="Name")
ifc_definition_id: IntProperty(name="IFC Definition ID")
@@ -66,6 +59,7 @@ class BIMGroupProperties(PropertyGroup):
groups: CollectionProperty(name="Groups", type=Group)
active_group_index: IntProperty(name="Active Group Index", update=update_active_group_index)
active_group_id: IntProperty(name="Active Group Id")
expanded_groups_json: StringProperty(name="JSON String", default="[]")
if TYPE_CHECKING:
group_attributes: bpy.types.bpy_prop_collection_idprop[Attribute]
@@ -73,6 +67,7 @@ class BIMGroupProperties(PropertyGroup):
groups: bpy.types.bpy_prop_collection_idprop[Group]
active_group_index: int
active_group_id: int
expanded_groups_json: str
@property
def active_group(self) -> Union[Group, None]: