mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
typing
This commit is contained in:
@@ -262,7 +262,8 @@ class AssignMaterial(bpy.types.Operator, tool.Ifc.Operator):
|
||||
if not (material_type := properties.material_type):
|
||||
if not (obj := context.active_object):
|
||||
return ""
|
||||
material_type = obj.BIMObjectMaterialProperties.material_type
|
||||
omprops = tool.Material.get_object_material_props(obj)
|
||||
material_type = omprops.material_type
|
||||
|
||||
description = "Assign current IfcMaterial to the selected objects"
|
||||
if material_type != "IfcMaterial":
|
||||
@@ -294,14 +295,12 @@ class AddConstituent(bpy.types.Operator, tool.Ifc.Operator):
|
||||
|
||||
def _execute(self, context):
|
||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||
omprops = tool.Material.get_object_material_props(obj)
|
||||
self.file = tool.Ifc.get()
|
||||
ifcopenshell.api.run(
|
||||
"material.add_constituent",
|
||||
ifcopenshell.api.material.add_constituent(
|
||||
self.file,
|
||||
**{
|
||||
"constituent_set": self.file.by_id(self.constituent_set),
|
||||
"material": self.file.by_id(int(obj.BIMObjectMaterialProperties.material)),
|
||||
},
|
||||
constituent_set=self.file.by_id(self.constituent_set),
|
||||
material=self.file.by_id(int(omprops.material)),
|
||||
)
|
||||
|
||||
|
||||
@@ -330,13 +329,14 @@ class AddProfile(bpy.types.Operator, tool.Ifc.Operator):
|
||||
|
||||
def _execute(self, context):
|
||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||
assert obj
|
||||
self.file = tool.Ifc.get()
|
||||
props = tool.Material.get_material_props()
|
||||
ifcopenshell.api.run(
|
||||
"material.add_profile",
|
||||
omprops = tool.Material.get_object_material_props(obj)
|
||||
ifcopenshell.api.material.add_profile(
|
||||
self.file,
|
||||
profile_set=self.file.by_id(self.profile_set),
|
||||
material=self.file.by_id(int(obj.BIMObjectMaterialProperties.material)),
|
||||
material=self.file.by_id(int(omprops.material)),
|
||||
profile=self.file.by_id(int(props.profiles)),
|
||||
)
|
||||
|
||||
@@ -367,11 +367,13 @@ class AddLayer(bpy.types.Operator, tool.Ifc.Operator):
|
||||
|
||||
def _execute(self, context):
|
||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||
assert obj
|
||||
omprops = tool.Material.get_object_material_props(obj)
|
||||
layer_set = tool.Ifc.get().by_id(self.layer_set)
|
||||
ifcopenshell.api.material.add_layer(
|
||||
tool.Ifc.get(),
|
||||
layer_set=layer_set,
|
||||
material=tool.Ifc.get().by_id(int(obj.BIMObjectMaterialProperties.material)),
|
||||
material=tool.Ifc.get().by_id(int(omprops.material)),
|
||||
)
|
||||
slab.DumbSlabPlaner().regenerate_from_layer_set(layer_set)
|
||||
wall.DumbWallPlaner().regenerate_from_layer_set(layer_set)
|
||||
@@ -445,12 +447,13 @@ class AddListItem(bpy.types.Operator, tool.Ifc.Operator):
|
||||
|
||||
def _execute(self, context):
|
||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||
assert obj
|
||||
omprops = tool.Material.get_object_material_props(obj)
|
||||
self.file = tool.Ifc.get()
|
||||
ifcopenshell.api.run(
|
||||
"material.add_list_item",
|
||||
ifcopenshell.api.material.add_list_item(
|
||||
self.file,
|
||||
material_list=self.file.by_id(self.list_item_set),
|
||||
material=self.file.by_id(int(obj.BIMObjectMaterialProperties.material)),
|
||||
material=self.file.by_id(int(omprops.material)),
|
||||
)
|
||||
|
||||
|
||||
@@ -484,10 +487,12 @@ class EnableEditingAssignedMaterial(bpy.types.Operator):
|
||||
|
||||
def execute(self, context):
|
||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||
props = obj.BIMObjectMaterialProperties
|
||||
assert obj
|
||||
props = tool.Material.get_object_material_props(obj)
|
||||
props.is_editing = True
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
material = ifcopenshell.util.element.get_material(element)
|
||||
assert material
|
||||
|
||||
if material.is_a("IfcMaterial"):
|
||||
props.material = str(material.id())
|
||||
@@ -545,7 +550,8 @@ class DisableEditingAssignedMaterial(bpy.types.Operator):
|
||||
def execute(self, context):
|
||||
bpy.ops.bim.disable_editing_material_set_item()
|
||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||
props = obj.BIMObjectMaterialProperties
|
||||
assert obj
|
||||
props = tool.Material.get_object_material_props(obj)
|
||||
props.is_editing = False
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -562,7 +568,7 @@ class EditAssignedMaterial(bpy.types.Operator, tool.Ifc.Operator):
|
||||
self.file = tool.Ifc.get()
|
||||
active_obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||
assert active_obj
|
||||
props = active_obj.BIMObjectMaterialProperties
|
||||
props = tool.Material.get_object_material_props(active_obj)
|
||||
element = tool.Ifc.get_entity(active_obj)
|
||||
assert element
|
||||
material = ifcopenshell.util.element.get_material(element)
|
||||
@@ -628,7 +634,8 @@ class EnableEditingMaterialSetItemProfile(bpy.types.Operator):
|
||||
|
||||
def execute(self, context):
|
||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||
self.props = obj.BIMObjectMaterialProperties
|
||||
assert obj
|
||||
self.props = tool.Material.get_object_material_props(obj)
|
||||
self.props.active_material_set_item_id = self.material_set_item
|
||||
self.props.material_set_item_profile_attributes.clear()
|
||||
profile = tool.Ifc.get().by_id(self.material_set_item).Profile
|
||||
@@ -644,7 +651,8 @@ class DisableEditingMaterialSetItemProfile(bpy.types.Operator):
|
||||
|
||||
def execute(self, context):
|
||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||
self.props = obj.BIMObjectMaterialProperties
|
||||
assert obj
|
||||
self.props = tool.Material.get_object_material_props(obj)
|
||||
self.props.active_material_set_item_id = 0
|
||||
self.props.material_set_item_profile_attributes.clear()
|
||||
return {"FINISHED"}
|
||||
@@ -659,7 +667,8 @@ class EditMaterialSetItemProfile(bpy.types.Operator, tool.Ifc.Operator):
|
||||
|
||||
def _execute(self, context):
|
||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||
self.props = obj.BIMObjectMaterialProperties
|
||||
assert obj
|
||||
self.props = tool.Material.get_object_material_props(obj)
|
||||
attributes = bonsai.bim.helper.export_attributes(self.props.material_set_item_profile_attributes)
|
||||
profile = tool.Ifc.get().by_id(self.material_set_item).Profile
|
||||
ifcopenshell.api.run("profile.edit_profile", tool.Ifc.get(), profile=profile, attributes=attributes)
|
||||
@@ -678,11 +687,13 @@ class EnableEditingMaterialSetItem(bpy.types.Operator):
|
||||
def execute(self, context):
|
||||
self.file = tool.Ifc.get()
|
||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||
assert obj
|
||||
self.mprops = tool.Material.get_material_props()
|
||||
self.props = obj.BIMObjectMaterialProperties
|
||||
self.props = tool.Material.get_object_material_props(obj)
|
||||
self.props.active_material_set_item_id = self.material_set_item
|
||||
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
assert element
|
||||
material = ifcopenshell.util.element.get_material(element, should_skip_usage=True)
|
||||
material_set_item = self.file.by_id(self.material_set_item)
|
||||
|
||||
@@ -706,7 +717,8 @@ class DisableEditingMaterialSetItem(bpy.types.Operator):
|
||||
|
||||
def execute(self, context):
|
||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||
props = obj.BIMObjectMaterialProperties
|
||||
assert obj
|
||||
props = tool.Material.get_object_material_props(obj)
|
||||
props.active_material_set_item_id = 0
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -721,10 +733,13 @@ class EditMaterialSetItem(bpy.types.Operator, tool.Ifc.Operator):
|
||||
def _execute(self, context):
|
||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||
self.file = tool.Ifc.get()
|
||||
props = obj.BIMObjectMaterialProperties
|
||||
assert obj
|
||||
props = tool.Material.get_object_material_props(obj)
|
||||
mprops = tool.Material.get_material_props()
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
assert element
|
||||
material = ifcopenshell.util.element.get_material(element, should_skip_usage=True)
|
||||
assert material
|
||||
|
||||
attributes = bonsai.bim.helper.export_attributes(props.material_set_item_attributes)
|
||||
|
||||
@@ -733,7 +748,7 @@ class EditMaterialSetItem(bpy.types.Operator, tool.Ifc.Operator):
|
||||
self.file,
|
||||
constituent=self.file.by_id(self.material_set_item),
|
||||
attributes=attributes,
|
||||
material=self.file.by_id(int(obj.BIMObjectMaterialProperties.material_set_item_material)),
|
||||
material=self.file.by_id(int(props.material_set_item_material)),
|
||||
)
|
||||
elif material.is_a("IfcMaterialLayerSet"):
|
||||
layer = self.file.by_id(self.material_set_item)
|
||||
@@ -741,7 +756,7 @@ class EditMaterialSetItem(bpy.types.Operator, tool.Ifc.Operator):
|
||||
self.file,
|
||||
layer=layer,
|
||||
attributes=attributes,
|
||||
material=self.file.by_id(int(obj.BIMObjectMaterialProperties.material_set_item_material)),
|
||||
material=self.file.by_id(int(props.material_set_item_material)),
|
||||
)
|
||||
slab.DumbSlabPlaner().regenerate_from_layer(layer)
|
||||
wall.DumbWallPlaner().regenerate_from_layer(layer)
|
||||
@@ -755,7 +770,7 @@ class EditMaterialSetItem(bpy.types.Operator, tool.Ifc.Operator):
|
||||
profile=self.file.by_id(self.material_set_item),
|
||||
attributes=attributes,
|
||||
profile_def=profile_def,
|
||||
material=self.file.by_id(int(obj.BIMObjectMaterialProperties.material_set_item_material)),
|
||||
material=self.file.by_id(int(props.material_set_item_material)),
|
||||
)
|
||||
else:
|
||||
pass
|
||||
|
||||
@@ -156,7 +156,7 @@ class BIM_PT_object_material(Panel):
|
||||
assert obj
|
||||
self.file = tool.Ifc.get()
|
||||
self.oprops = tool.Blender.get_object_bim_props(obj)
|
||||
self.props = obj.BIMObjectMaterialProperties
|
||||
self.props = tool.Material.get_object_material_props(obj)
|
||||
self.mprops = tool.Material.get_material_props()
|
||||
|
||||
if not ObjectMaterialData.data["materials"]:
|
||||
|
||||
@@ -21,6 +21,7 @@ import json
|
||||
import bmesh
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.geometry
|
||||
import ifcopenshell.util.element
|
||||
import ifcopenshell.util.placement
|
||||
import ifcopenshell.util.representation
|
||||
@@ -343,8 +344,7 @@ class DumbSlabPlaner:
|
||||
else:
|
||||
props = tool.Model.get_model_props()
|
||||
x_angle = 0 if tool.Cad.is_x(props.x_angle, 0, tolerance=0.001) else props.x_angle
|
||||
new_rep = ifcopenshell.api.run(
|
||||
"geometry.add_slab_representation",
|
||||
new_rep = ifcopenshell.api.geometry.add_slab_representation(
|
||||
tool.Ifc.get(),
|
||||
context=body_context,
|
||||
depth=thickness * self.unit_scale,
|
||||
@@ -368,15 +368,14 @@ class DumbSlabPlaner:
|
||||
else:
|
||||
props = tool.Model.get_model_props()
|
||||
x_angle = 0 if tool.Cad.is_x(props.x_angle, 0, tolerance=0.001) else props.x_angle
|
||||
representation = ifcopenshell.api.run(
|
||||
"geometry.add_slab_representation",
|
||||
representation = ifcopenshell.api.geometry.add_slab_representation(
|
||||
tool.Ifc.get(),
|
||||
context=body_context,
|
||||
depth=thickness * self.unit_scale,
|
||||
x_angle=x_angle,
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"geometry.assign_representation", tool.Ifc.get(), product=element, representation=representation
|
||||
ifcopenshell.api.geometry.assign_representation(
|
||||
tool.Ifc.get(), product=element, representation=representation
|
||||
)
|
||||
|
||||
bonsai.core.geometry.switch_representation(
|
||||
|
||||
@@ -37,7 +37,7 @@ from bpy.props import (
|
||||
from typing import TYPE_CHECKING, Union
|
||||
|
||||
|
||||
def get_profile_classes(self, context):
|
||||
def get_profile_classes(self: "BIMProfileProperties", context: bpy.types.Context) -> list[tuple[str, str, str]]:
|
||||
if not ProfileData.is_loaded:
|
||||
ProfileData.load()
|
||||
return ProfileData.data["profile_classes"]
|
||||
@@ -62,7 +62,7 @@ class Profile(PropertyGroup):
|
||||
ifc_definition_id: int
|
||||
|
||||
|
||||
def update_active_profile_index(self, context):
|
||||
def update_active_profile_index(self: "BIMProfileProperties", context: bpy.types.Context) -> None:
|
||||
ProfileData.data["active_profile_users"] = ProfileData.active_profile_users()
|
||||
|
||||
|
||||
|
||||
@@ -212,7 +212,9 @@ class MaterialSetItemPsetsData(Data):
|
||||
@classmethod
|
||||
def load(cls):
|
||||
psets = {}
|
||||
ifc_definition_id = bpy.context.active_object.BIMObjectMaterialProperties.active_material_set_item_id
|
||||
obj = bpy.context.active_object
|
||||
assert obj
|
||||
ifc_definition_id = tool.Material.get_object_material_props(obj).active_material_set_item_id
|
||||
if ifc_definition_id:
|
||||
psets = cls.psetqtos(tool.Ifc.get().by_id(ifc_definition_id))
|
||||
cls.data = {"psets": psets}
|
||||
|
||||
@@ -109,10 +109,12 @@ def get_material_set_pset_names(self, context):
|
||||
return psetnames[ifc_class]
|
||||
|
||||
|
||||
def get_material_set_item_pset_names(self, context):
|
||||
def get_material_set_item_pset_names(self, context) -> list[tuple[str, str, str]]:
|
||||
global psetnames
|
||||
ifc_definition_id = context.active_object.BIMObjectMaterialProperties.active_material_set_item_id
|
||||
if not ifc_definition_id:
|
||||
obj = context.active_object
|
||||
assert obj
|
||||
omprops = tool.Material.get_object_material_props(obj)
|
||||
if not omprops.active_material_set_item_id:
|
||||
return []
|
||||
ifc_class = tool.Ifc.get().by_id(ifc_definition_id).is_a()
|
||||
if ifc_class not in psetnames:
|
||||
|
||||
@@ -459,7 +459,8 @@ class BIM_PT_material_set_item_psets(Panel):
|
||||
|
||||
obj = context.active_object
|
||||
assert obj
|
||||
if not obj.BIMObjectMaterialProperties.active_material_set_item_id:
|
||||
omprops = tool.Material.get_object_material_props(obj)
|
||||
if not omprops.active_material_set_item_id:
|
||||
self.layout.label(text="No Material Set Item Edited.")
|
||||
return
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ from typing_extensions import assert_never
|
||||
if TYPE_CHECKING:
|
||||
from bonsai.bim.prop import BIMProperties, BIMObjectProperties
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
VIEWPORT_ATTRIBUTES = [
|
||||
"view_matrix",
|
||||
@@ -199,7 +200,9 @@ class Blender(bonsai.core.tool.Blender):
|
||||
props = tool.Material.get_material_props()
|
||||
return props.materials[props.active_material_index].ifc_definition_id
|
||||
elif obj_type == "MaterialSetItem":
|
||||
return bpy.data.objects.get(obj).BIMObjectMaterialProperties.active_material_set_item_id
|
||||
obj_ = bpy.data.objects[obj]
|
||||
omprops = tool.Material.get_object_material_props(obj_)
|
||||
return omprops.active_material_set_item_id
|
||||
elif obj_type == "Task":
|
||||
tprops = tool.Sequence.get_task_tree_props()
|
||||
return tprops.tasks[context.scene.BIMWorkScheduleProperties.active_task_index].ifc_definition_id
|
||||
@@ -1466,9 +1469,9 @@ class Blender(bonsai.core.tool.Blender):
|
||||
def set_prop_from_path(cls, bpy_object: bpy.types.bpy_struct, prop_path: str, value: Any) -> None:
|
||||
"""Set `data_block` property value using path from `path_from_id`."""
|
||||
|
||||
T = TypeVar("T", bound=bpy.types.bpy_struct)
|
||||
T_ = TypeVar("T_", bound=bpy.types.bpy_struct)
|
||||
|
||||
def path_resolve(obj: T, prop_path: str) -> tuple[T, str]:
|
||||
def path_resolve(obj: T_, prop_path: str) -> tuple[T_, str]:
|
||||
if "." in prop_path:
|
||||
extra_path, prop_path = prop_path.rsplit(".", 1)
|
||||
obj = obj.path_resolve(extra_path)
|
||||
@@ -1605,3 +1608,11 @@ class Blender(bonsai.core.tool.Blender):
|
||||
if isinstance(obj, bpy.types.Object):
|
||||
return tool.Blender.get_object_bim_props(obj).ifc_definition_id
|
||||
return tool.Style.get_material_style_props(obj).ifc_definition_id
|
||||
|
||||
@classmethod
|
||||
def get_active_uilist_element(
|
||||
cls, collection: bpy.types.bpy_prop_collection_idprop[T], index: int
|
||||
) -> Union[T, None]:
|
||||
if 0 <= index < len(collection):
|
||||
return collection[index]
|
||||
return None
|
||||
|
||||
@@ -33,7 +33,7 @@ from typing_extensions import assert_never
|
||||
if TYPE_CHECKING:
|
||||
# Avoid circular imports.
|
||||
from bonsai.bim.module.material.prop import Material as MaterialItem
|
||||
from bonsai.bim.module.material.prop import BIMMaterialProperties
|
||||
from bonsai.bim.module.material.prop import BIMMaterialProperties, BIMObjectMaterialProperties
|
||||
|
||||
|
||||
class Material(bonsai.core.tool.Material):
|
||||
@@ -41,6 +41,10 @@ class Material(bonsai.core.tool.Material):
|
||||
def get_material_props(cls) -> BIMMaterialProperties:
|
||||
return bpy.context.scene.BIMMaterialProperties
|
||||
|
||||
@classmethod
|
||||
def get_object_material_props(cls, obj: bpy.types.Object) -> BIMObjectMaterialProperties:
|
||||
return obj.BIMObjectMaterialProperties
|
||||
|
||||
@classmethod
|
||||
def disable_editing_materials(cls) -> None:
|
||||
props = tool.Material.get_material_props()
|
||||
@@ -203,11 +207,14 @@ class Material(bonsai.core.tool.Material):
|
||||
@classmethod
|
||||
def get_object_ui_material_type(cls) -> str:
|
||||
active_obj = bpy.context.active_object
|
||||
return active_obj.BIMObjectMaterialProperties.material_type
|
||||
assert active_obj
|
||||
return tool.Material.get_object_material_props(active_obj).material_type
|
||||
|
||||
@classmethod
|
||||
def get_object_ui_active_material(cls) -> ifcopenshell.entity_instance:
|
||||
return tool.Ifc.get().by_id(int(bpy.context.active_object.BIMObjectMaterialProperties.material))
|
||||
obj = bpy.context.active_object
|
||||
assert obj
|
||||
return tool.Ifc.get().by_id(int(tool.Material.get_object_material_props(obj).material))
|
||||
|
||||
@classmethod
|
||||
def get_material(
|
||||
|
||||
@@ -123,16 +123,13 @@ class Profile(bonsai.core.tool.Profile):
|
||||
@classmethod
|
||||
def get_active_profile_ui(cls) -> Union[bonsai.bim.module.profile.prop.Profile, None]:
|
||||
props = cls.get_profile_props()
|
||||
index = props.active_profile_index
|
||||
if len(props.profiles) > index >= 0:
|
||||
return props.profiles[index]
|
||||
return tool.Blender.get_active_uilist_element(props.profiles, props.active_profile_index)
|
||||
|
||||
# Lengths are in meters.
|
||||
DEFAULT_PROFILE_ATTRS = {
|
||||
"IfcCircleProfileDef": {
|
||||
"Radius": 0.05,
|
||||
},
|
||||
# TODO: test after debug
|
||||
"IfcAsymmetricIShapeProfileDef": {
|
||||
"BottomFlangeWidth": 0.1,
|
||||
"BottomFlangeThickness": 0.01,
|
||||
|
||||
Reference in New Issue
Block a user