This commit is contained in:
Andrej730
2025-03-17 15:08:25 +05:00
parent 1f43f7f807
commit 0b4deee73f
6 changed files with 26 additions and 16 deletions
@@ -20,6 +20,7 @@ import bpy
import math import math
import mathutils.geometry import mathutils.geometry
import ifcopenshell import ifcopenshell
import ifcopenshell.util.unit
import bonsai.tool as tool import bonsai.tool as tool
from mathutils import Vector from mathutils import Vector
from typing import Union from typing import Union
@@ -157,15 +157,17 @@ class RepresentationsData:
if not cls.data["representations"]: if not cls.data["representations"]:
return [] return []
obj = tool.Geometry.get_active_or_representation_obj() obj = tool.Geometry.get_active_or_representation_obj()
assert obj
if not obj.data: if not obj.data:
return [] return []
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
assert element
base_representation = tool.Geometry.get_active_representation(obj) base_representation = tool.Geometry.get_active_representation(obj)
if not base_representation: if not base_representation:
return [] # Maybe in profile editing mode return [] # Maybe in profile editing mode
# shape aspects matching context of the active representation # shape aspects matching context of the active representation
matching_shape_aspects = [] matching_shape_aspects: list[ifcopenshell.entity_instance] = []
for shape_aspect in ifcopenshell.util.element.get_shape_aspects(element): for shape_aspect in ifcopenshell.util.element.get_shape_aspects(element):
matching_representation = tool.Geometry.get_shape_aspect_representation(shape_aspect, base_representation) matching_representation = tool.Geometry.get_shape_aspect_representation(shape_aspect, base_representation)
if matching_representation: if matching_representation:
@@ -121,7 +121,7 @@ def get_layers_no_active(self, context):
return LayersData.data["layers_enum_no_active"] return LayersData.data["layers_enum_no_active"]
def update_shape_aspect(self, context): def update_shape_aspect(self: "BIMObjectGeometryProperties", context: bpy.types.Context) -> None:
shape_aspect_id = self.representation_item_shape_aspect shape_aspect_id = self.representation_item_shape_aspect
attrs = self.shape_aspect_attrs attrs = self.shape_aspect_attrs
@@ -250,9 +250,8 @@ class BIMObjectGeometryProperties(PropertyGroup):
representation_item_layer: EnumProperty(items=get_layers, name="Representation Item's Layer") representation_item_layer: EnumProperty(items=get_layers, name="Representation Item's Layer")
@property @property
def active_item(self): def active_item(self) -> Union[RepresentationItem, None]:
if 0 <= self.active_item_index < len(self.items): return tool.Blender.get_active_uilist_element(self.items, self.active_item_index)
return self.items[self.active_item_index]
if TYPE_CHECKING: if TYPE_CHECKING:
contexts: str contexts: str
+2 -2
View File
@@ -24,7 +24,7 @@ from bpy.types import Panel, UIList
from bonsai.bim.helper import draw_attributes from bonsai.bim.helper import draw_attributes
from bonsai.bim.helper import prop_with_search from bonsai.bim.helper import prop_with_search
from bonsai.bim.module.material.data import MaterialsData, ObjectMaterialData from bonsai.bim.module.material.data import MaterialsData, ObjectMaterialData
from typing import TYPE_CHECKING from typing import TYPE_CHECKING, Any
if TYPE_CHECKING: if TYPE_CHECKING:
from bonsai.bim.module.material.prop import Material, BIMMaterialProperties from bonsai.bim.module.material.prop import Material, BIMMaterialProperties
@@ -289,7 +289,7 @@ class BIM_PT_object_material(Panel):
row = box.row() row = box.row()
prop_with_search(row, self.mprops, "profiles", icon="ITALIC", text="Profile") prop_with_search(row, self.mprops, "profiles", icon="ITALIC", text="Profile")
def draw_read_only_set_item_ui(self, box, set_item): def draw_read_only_set_item_ui(self, box: bpy.types.UILayout, set_item: dict[str, Any]) -> None:
if ObjectMaterialData.data["material_class"] == "IfcMaterialList": if ObjectMaterialData.data["material_class"] == "IfcMaterialList":
row = box.row(align=True) row = box.row(align=True)
row.label(text="IfcMaterial", icon="LAYER_ACTIVE") row.label(text="IfcMaterial", icon="LAYER_ACTIVE")
+12 -8
View File
@@ -237,7 +237,8 @@ class BIM_PT_object_psets(Panel):
def draw_header(self, context): def draw_header(self, context):
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.label(text="") # empty text occupies the left of the row row.label(text="") # empty text occupies the left of the row
row.prop(context.scene.GlobalPsetProperties, "pset_filter", text="", icon="VIEWZOOM") global_props = tool.Pset.get_global_pset_props()
row.prop(global_props, "pset_filter", text="", icon="VIEWZOOM")
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
@@ -261,6 +262,7 @@ class BIM_PT_object_psets(Panel):
op.obj = context.active_object.name op.obj = context.active_object.name
op.obj_type = "Object" op.obj_type = "Object"
global_props = tool.Pset.get_global_pset_props()
if not props.active_pset_id and props.active_pset_name and props.active_pset_type == "PSET": if not props.active_pset_id and props.active_pset_name and props.active_pset_type == "PSET":
draw_psetqto_ui( draw_psetqto_ui(
context, context,
@@ -269,7 +271,7 @@ class BIM_PT_object_psets(Panel):
props, props,
self.layout, self.layout,
"Object", "Object",
filter_keyword=context.scene.GlobalPsetProperties.pset_filter, filter_keyword=global_props.pset_filter,
) )
if ObjectPsetsData.data["psets"]: if ObjectPsetsData.data["psets"]:
@@ -285,7 +287,7 @@ class BIM_PT_object_psets(Panel):
props, props,
self.layout, self.layout,
"Object", "Object",
filter_keyword=context.scene.GlobalPsetProperties.pset_filter, filter_keyword=global_props.pset_filter,
) )
if ObjectPsetsData.data["inherited_psets"]: if ObjectPsetsData.data["inherited_psets"]:
@@ -299,7 +301,7 @@ class BIM_PT_object_psets(Panel):
self.layout, self.layout,
"Object", "Object",
allow_removing=False, allow_removing=False,
filter_keyword=context.scene.GlobalPsetProperties.pset_filter, filter_keyword=global_props.pset_filter,
) )
@@ -315,7 +317,8 @@ class BIM_PT_object_qtos(Panel):
def draw_header(self, context): def draw_header(self, context):
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.label(text="") # empty text occupies the left of the row row.label(text="") # empty text occupies the left of the row
row.prop(context.scene.GlobalPsetProperties, "qto_filter", text="", icon="VIEWZOOM") global_props = tool.Pset.get_global_pset_props()
row.prop(global_props, "qto_filter", text="", icon="VIEWZOOM")
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
@@ -339,6 +342,7 @@ class BIM_PT_object_qtos(Panel):
op.obj = context.active_object.name op.obj = context.active_object.name
op.obj_type = "Object" op.obj_type = "Object"
global_props = tool.Pset.get_global_pset_props()
if not props.active_pset_id and props.active_pset_name and props.active_pset_type == "QTO": if not props.active_pset_id and props.active_pset_name and props.active_pset_type == "QTO":
draw_psetqto_ui( draw_psetqto_ui(
context, context,
@@ -347,7 +351,7 @@ class BIM_PT_object_qtos(Panel):
props, props,
self.layout, self.layout,
"Object", "Object",
filter_keyword=context.scene.GlobalPsetProperties.qto_filter, filter_keyword=global_props.qto_filter,
) )
if ObjectQtosData.data["qtos"]: if ObjectQtosData.data["qtos"]:
@@ -363,7 +367,7 @@ class BIM_PT_object_qtos(Panel):
props, props,
self.layout, self.layout,
"Object", "Object",
filter_keyword=context.scene.GlobalPsetProperties.qto_filter, filter_keyword=global_props.qto_filter,
) )
if ObjectQtosData.data["inherited_qsets"]: if ObjectQtosData.data["inherited_qsets"]:
@@ -377,7 +381,7 @@ class BIM_PT_object_qtos(Panel):
self.layout, self.layout,
"Object", "Object",
allow_removing=False, allow_removing=False,
filter_keyword=context.scene.GlobalPsetProperties.qto_filter, filter_keyword=global_props.qto_filter,
) )
layout = self.layout layout = self.layout
qtoprops = tool.Qto.get_qto_props() qtoprops = tool.Qto.get_qto_props()
+5 -1
View File
@@ -31,12 +31,16 @@ from typing_extensions import assert_never
if TYPE_CHECKING: if TYPE_CHECKING:
from bonsai.bim.module.pset.prop import PsetProperties from bonsai.bim.module.pset.prop import PsetProperties, GlobalPsetProperties
class Pset(bonsai.core.tool.Pset): class Pset(bonsai.core.tool.Pset):
PSET_TYPE = Literal["PSET", "QTO"] PSET_TYPE = Literal["PSET", "QTO"]
@classmethod
def get_global_pset_props(cls) -> GlobalPsetProperties:
return bpy.context.scene.GlobalPsetProperties
@classmethod @classmethod
def get_element_pset( def get_element_pset(
cls, element: ifcopenshell.entity_instance, pset_name: str cls, element: ifcopenshell.entity_instance, pset_name: str