mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 02:47:48 +00:00
owner.ui - check props explicitly instead of relying on ifc data update
This commit is contained in:
@@ -35,30 +35,24 @@ def refresh():
|
||||
class RolesAddressesData:
|
||||
@classmethod
|
||||
def get_roles(cls, parent: ifcopenshell.entity_instance) -> list[dict[str, Any]]:
|
||||
props = tool.Owner.get_owner_props()
|
||||
results: list[dict[str, Any]] = []
|
||||
for role in parent.Roles or []:
|
||||
results.append(
|
||||
{
|
||||
"id": role.id(),
|
||||
"is_editing": props.active_role_id == role.id(),
|
||||
"label": role.UserDefinedRole or role.Role,
|
||||
"props": props.role_attributes,
|
||||
}
|
||||
)
|
||||
return results
|
||||
|
||||
@classmethod
|
||||
def get_addresses(cls, parent: ifcopenshell.entity_instance) -> list[dict[str, Any]]:
|
||||
props = tool.Owner.get_owner_props()
|
||||
results: list[dict[str, Any]] = []
|
||||
for address in parent.Addresses or []:
|
||||
results.append(
|
||||
{
|
||||
"id": address.id(),
|
||||
"is_editing": props.active_address_id == address.id(),
|
||||
"label": address.is_a(),
|
||||
"props": props.address_attributes,
|
||||
"list_attributes": cls.get_address_list_attributes(address),
|
||||
}
|
||||
)
|
||||
@@ -102,17 +96,14 @@ class PeopleData(RolesAddressesData):
|
||||
|
||||
@classmethod
|
||||
def get_people(cls) -> list[dict[str, Any]]:
|
||||
props = tool.Owner.get_owner_props()
|
||||
people: list[dict[str, Any]] = []
|
||||
for person in tool.Ifc.get().by_type("IfcPerson"):
|
||||
roles = cls.get_roles(person)
|
||||
people.append(
|
||||
{
|
||||
"id": person.id(),
|
||||
"props": props.person_attributes,
|
||||
"name": cls.get_person_name(person),
|
||||
"roles_label": ", ".join([r["label"] for r in roles]),
|
||||
"is_editing": cls.get_person_is_editing(person),
|
||||
"is_engaged": bool(person.EngagedIn),
|
||||
"list_attributes": cls.get_person_list_attributes(person),
|
||||
"roles": roles,
|
||||
@@ -133,11 +124,6 @@ class PeopleData(RolesAddressesData):
|
||||
name += f" ({full_name})"
|
||||
return name
|
||||
|
||||
@classmethod
|
||||
def get_person_is_editing(cls, person: ifcopenshell.entity_instance) -> bool:
|
||||
props = tool.Owner.get_owner_props()
|
||||
return props.active_person_id == person.id()
|
||||
|
||||
@classmethod
|
||||
def get_person_list_attributes(cls, person: ifcopenshell.entity_instance) -> list[dict[str, Any]]:
|
||||
results: list[dict[str, Any]] = []
|
||||
@@ -167,17 +153,14 @@ class OrganisationsData(RolesAddressesData):
|
||||
|
||||
@classmethod
|
||||
def get_organisations(cls) -> list[dict[str, Any]]:
|
||||
props = tool.Owner.get_owner_props()
|
||||
organisations: list[dict[str, Any]] = []
|
||||
for organisation in tool.Ifc.get().by_type("IfcOrganization"):
|
||||
roles = cls.get_roles(organisation)
|
||||
organisations.append(
|
||||
{
|
||||
"id": organisation.id(),
|
||||
"props": props.organisation_attributes,
|
||||
"name": organisation.Name,
|
||||
"roles_label": ", ".join([r["label"] for r in roles]),
|
||||
"is_editing": props.active_organisation_id == organisation.id(),
|
||||
"is_engaged": bool(organisation.Engages),
|
||||
"roles": roles,
|
||||
"addresses": cls.get_addresses(organisation),
|
||||
@@ -251,7 +234,6 @@ class ActorData:
|
||||
actors: list[dict[str, Any]] = []
|
||||
props = tool.Owner.get_owner_props()
|
||||
for actor in tool.Ifc.get().by_type(props.actor_class, include_subtypes=False):
|
||||
is_editing = props.active_actor_id == actor.id()
|
||||
the_actor: ifcopenshell.entity_instance = actor.TheActor
|
||||
if the_actor.is_a("IfcPerson"):
|
||||
the_actor_ = the_actor.Identification or "N/A"
|
||||
@@ -267,7 +249,6 @@ class ActorData:
|
||||
"id": actor.id(),
|
||||
"name": actor.Name or "Unnamed",
|
||||
"the_actor": the_actor_,
|
||||
"is_editing": is_editing,
|
||||
}
|
||||
)
|
||||
return actors
|
||||
|
||||
@@ -31,17 +31,18 @@ from bonsai.bim.module.owner.data import (
|
||||
|
||||
|
||||
def draw_roles(box: bpy.types.UILayout, parent: dict[str, Any]) -> None:
|
||||
props = tool.Owner.get_owner_props()
|
||||
row = box.row(align=True)
|
||||
row.label(text="Roles")
|
||||
op = row.operator("bim.add_role", icon="ADD", text="")
|
||||
op.parent = parent["id"]
|
||||
|
||||
for role in parent["roles"]:
|
||||
if role["is_editing"]:
|
||||
if props.active_role_id == role["id"]:
|
||||
row = box.row(align=True)
|
||||
row.operator("bim.edit_role", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_role", icon="CANCEL", text="")
|
||||
bonsai.bim.helper.draw_attributes(role["props"], box)
|
||||
bonsai.bim.helper.draw_attributes(props.role_attributes, box)
|
||||
else:
|
||||
row = box.row(align=True)
|
||||
row.label(text=role["label"])
|
||||
@@ -50,6 +51,7 @@ def draw_roles(box: bpy.types.UILayout, parent: dict[str, Any]) -> None:
|
||||
|
||||
|
||||
def draw_addresses(box: bpy.types.UILayout, parent: dict[str, Any]) -> None:
|
||||
props = tool.Owner.get_owner_props()
|
||||
row = box.row(align=True)
|
||||
row.label(text="Addresses")
|
||||
op = row.operator("bim.add_address", icon="LINK_BLEND", text="")
|
||||
@@ -60,11 +62,11 @@ def draw_addresses(box: bpy.types.UILayout, parent: dict[str, Any]) -> None:
|
||||
op.ifc_class = "IfcPostalAddress"
|
||||
|
||||
for address in parent["addresses"]:
|
||||
if address["is_editing"]:
|
||||
if props.active_address_id == address["id"]:
|
||||
row = box.row(align=True)
|
||||
row.operator("bim.edit_address", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_address", icon="CANCEL", text="")
|
||||
bonsai.bim.helper.draw_attributes(address["props"], box)
|
||||
bonsai.bim.helper.draw_attributes(props.address_attributes, box)
|
||||
for attribute in address["list_attributes"]:
|
||||
row = box.row(align=True)
|
||||
row.label(text=attribute["name"])
|
||||
@@ -113,12 +115,14 @@ class BIM_PT_people(bpy.types.Panel):
|
||||
|
||||
def draw_person(self, person: dict[str, Any]) -> None:
|
||||
assert self.layout
|
||||
if person["is_editing"]:
|
||||
props = tool.Owner.get_owner_props()
|
||||
|
||||
if props.active_person_id == person["id"]:
|
||||
box = self.layout.box()
|
||||
row = box.row(align=True)
|
||||
row.operator("bim.edit_person", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_person", icon="CANCEL", text="")
|
||||
bonsai.bim.helper.draw_attributes(person["props"], box)
|
||||
bonsai.bim.helper.draw_attributes(props.person_attributes, box)
|
||||
|
||||
for attribute in person["list_attributes"]:
|
||||
row = box.row(align=True)
|
||||
@@ -174,12 +178,13 @@ class BIM_PT_organisations(bpy.types.Panel):
|
||||
|
||||
def draw_organisation(self, organisation: dict[str, Any]) -> None:
|
||||
assert self.layout
|
||||
if organisation["is_editing"]:
|
||||
props = tool.Owner.get_owner_props()
|
||||
if props.active_organisation_id == organisation["id"]:
|
||||
box = self.layout.box()
|
||||
row = box.row(align=True)
|
||||
row.operator("bim.edit_organisation", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_organisation", icon="CANCEL", text="")
|
||||
bonsai.bim.helper.draw_attributes(organisation["props"], box)
|
||||
bonsai.bim.helper.draw_attributes(props.organisation_attributes, box)
|
||||
|
||||
draw_roles(box, organisation)
|
||||
draw_addresses(box, organisation)
|
||||
@@ -284,12 +289,14 @@ class BIM_PT_actor(bpy.types.Panel):
|
||||
|
||||
def draw_actor(self, actor: dict[str, Any]) -> None:
|
||||
assert self.layout
|
||||
if actor["is_editing"]:
|
||||
props = tool.Owner.get_owner_props()
|
||||
|
||||
if props.active_actor_id == actor["id"]:
|
||||
box = self.layout.box()
|
||||
row = box.row(align=True)
|
||||
row.operator("bim.edit_actor", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_actor", icon="CANCEL", text="")
|
||||
bonsai.bim.helper.draw_attributes(self.props.actor_attributes, box)
|
||||
bonsai.bim.helper.draw_attributes(props.actor_attributes, box)
|
||||
else:
|
||||
row = self.layout.row(align=True)
|
||||
row.label(text=actor["name"], icon="USER")
|
||||
|
||||
Reference in New Issue
Block a user