mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Library UI - rename assets and libraries from UI
Example - https://imgur.com/a/0kcQrb2
This commit is contained in:
@@ -341,13 +341,12 @@ class ChangeLibraryElement(bpy.types.Operator):
|
||||
return {"FINISHED"}
|
||||
|
||||
def get_name(self, element: ifcopenshell.entity_instance) -> str:
|
||||
if element.is_a("IfcProfileDef"):
|
||||
return element.ProfileName or "Unnamed"
|
||||
return element.Name or "Unnamed"
|
||||
attr_name = tool.Project.get_library_element_attr_name(element)
|
||||
return getattr(element, attr_name) or "Unnamed"
|
||||
|
||||
def add_library_asset(self, name: str, ifc_definition_id: int) -> None:
|
||||
new = self.props.library_elements.add()
|
||||
new.name = name
|
||||
new["name"] = name
|
||||
new.ifc_definition_id = ifc_definition_id
|
||||
element = self.library_file.by_id(ifc_definition_id)
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ from bpy.props import (
|
||||
StringProperty,
|
||||
)
|
||||
from typing import TYPE_CHECKING, Literal, Union, get_args
|
||||
from typing_extensions import assert_never
|
||||
|
||||
|
||||
def get_export_schema(self: "BIMProjectProperties", context: bpy.types.Context) -> list[tuple[str, str, str]]:
|
||||
@@ -147,11 +148,35 @@ def update_filter_mode(self: "BIMProjectProperties", context: bpy.types.Context)
|
||||
new.total_elements = len(ifcopenshell.util.element.get_types(ifc_type))
|
||||
|
||||
|
||||
def update_library_element_name(self: "LibraryElement", context: bpy.types.Context) -> None:
|
||||
library_file = IfcStore.library_file
|
||||
assert library_file
|
||||
|
||||
if self.element_type == "CLASS":
|
||||
raise Exception("Unexpected element type for rename: 'CLASS'.")
|
||||
|
||||
def update_element_name(ifc_definition_id: int, name: str) -> None:
|
||||
element = library_file.by_id(ifc_definition_id)
|
||||
attr_name = tool.Project.get_library_element_attr_name(element)
|
||||
previous_name = getattr(element, attr_name)
|
||||
if name == previous_name:
|
||||
return
|
||||
setattr(element, attr_name, name)
|
||||
|
||||
if self.element_type == "ASSET":
|
||||
update_element_name(self.ifc_definition_id, self.name)
|
||||
elif self.element_type == "LIBRARY":
|
||||
assert self.ifc_definition_id, "Renaming for unassigned elements library is not supported."
|
||||
update_element_name(self.ifc_definition_id, self.name)
|
||||
else:
|
||||
assert_never(self.element_type)
|
||||
|
||||
|
||||
LibraryElementType = Literal["ASSET", "CLASS", "LIBRARY"]
|
||||
|
||||
|
||||
class LibraryElement(PropertyGroup):
|
||||
name: StringProperty(name="Name")
|
||||
name: StringProperty(name="Name", update=update_library_element_name)
|
||||
element_type: EnumProperty(items=[(i, i, "") for i in get_args(LibraryElementType)], name="Element Type")
|
||||
# Asset group.
|
||||
asset_count: IntProperty(name="Asset Count")
|
||||
@@ -372,7 +397,7 @@ class BIMProjectProperties(PropertyGroup):
|
||||
|
||||
def add_library_project_library(self, name: str, asset_count: int, ifc_definition_id: int) -> LibraryElement:
|
||||
new = self.library_elements.add()
|
||||
new.name = name
|
||||
new["name"] = name
|
||||
new.asset_count = asset_count
|
||||
new.element_type = "LIBRARY"
|
||||
new.ifc_definition_id = ifc_definition_id
|
||||
@@ -380,7 +405,7 @@ class BIMProjectProperties(PropertyGroup):
|
||||
|
||||
def add_library_asset_class(self, name: str, asset_count: int) -> LibraryElement:
|
||||
new = self.library_elements.add()
|
||||
new.name = name
|
||||
new["name"] = name
|
||||
new.asset_count = asset_count
|
||||
new.element_type = "CLASS"
|
||||
return new
|
||||
|
||||
@@ -517,7 +517,10 @@ class BIM_UL_library(UIList):
|
||||
op.element_name = item.name
|
||||
op.breadcrumb_type = item.element_type
|
||||
op.library_id = item.ifc_definition_id
|
||||
row.label(text=item.name)
|
||||
if item.ifc_definition_id:
|
||||
row.prop(item, "name", text="", emboss=False)
|
||||
else:
|
||||
row.label(text=item.name)
|
||||
if item.ifc_definition_id and item.is_declarable:
|
||||
if item.is_declared:
|
||||
op = row.operator("bim.unassign_library_declaration", text="", icon="KEYFRAME_HLT", emboss=False)
|
||||
|
||||
@@ -375,3 +375,9 @@ class Project(bonsai.core.tool.Project):
|
||||
props.add_library_project_library(
|
||||
project_library.Name or "Unnamed", len(library_elements), project_library.id()
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_library_element_attr_name(cls, library_element: ifcopenshell.entity_instance) -> str:
|
||||
if library_element.is_a("IfcProfileDef"):
|
||||
return "ProfileName"
|
||||
return "Name"
|
||||
|
||||
Reference in New Issue
Block a user