This commit is contained in:
Andrej730
2025-06-18 11:37:20 +05:00
parent 8c5affaae6
commit c68b0c7280
25 changed files with 137 additions and 94 deletions
+2 -4
View File
@@ -300,10 +300,8 @@ class CostSchedulesData:
@classmethod
def quantity_types(cls) -> list[tuple[str, str, str]]:
return [
(t.name(), t.name(), "")
for t in tool.Ifc.schema().declaration_by_name("IfcPhysicalSimpleQuantity").subtypes()
]
assert (entity := tool.Ifc.schema().declaration_by_name("IfcPhysicalSimpleQuantity").as_entity())
return [(t.name(), t.name(), "") for t in entity.subtypes()]
@classmethod
def get_cost_schedule_types(cls) -> list[tuple[str, str, str]]:
@@ -918,7 +918,7 @@ class DebugActiveDrawing(bpy.types.Operator):
original_exclude = ifcopenshell.util.element.get_pset(drawing, "EPset_Drawing", "Exclude")
pset = tool.Pset.get_element_pset(drawing, "EPset_Drawing")
def drawing_fails_to_load(chunk_to_include: set) -> bool:
def drawing_fails_to_load(chunk_to_include: set[ifcopenshell.entity_instance]) -> bool:
current_elements = all_elements - chunk_to_include
excluded_guids = ", ".join([e.GlobalId for e in current_elements if hasattr(e, "GlobalId")])
new_exclude = "" if not original_exclude else f"{original_exclude}, "
@@ -54,7 +54,8 @@ class GeoreferenceData:
def coordinate_operation_class(cls):
if tool.Ifc.get_schema() == "IFC2X3":
return []
declaration = tool.Ifc.schema().declaration_by_name("IfcCoordinateOperation")
declaration = tool.Ifc.schema().declaration_by_name("IfcCoordinateOperation").as_entity()
assert declaration
declarations = ifcopenshell.util.schema.get_subtypes(declaration)
names = [d.name() for d in declarations]
version = tool.Ifc.get_schema()
+2 -1
View File
@@ -99,7 +99,8 @@ class AuthoringData:
@classmethod
def boundary_class(cls):
declaration = tool.Ifc.schema().declaration_by_name("IfcRelSpaceBoundary")
declaration = tool.Ifc.schema().declaration_by_name("IfcRelSpaceBoundary").as_entity()
assert declaration
declarations = ifcopenshell.util.schema.get_subtypes(declaration)
names = [d.name() for d in declarations]
version = tool.Ifc.get_schema()
+2 -1
View File
@@ -96,9 +96,10 @@ class ProfileData:
@classmethod
def profile_def_classes_enum(cls) -> list[tuple[str, str, str]]:
version = tool.Ifc.get_schema()
assert (entity := tool.Ifc.schema().declaration_by_name("IfcProfileDef").as_entity())
return [
(t.name(), t.name(), ifcopenshell.util.doc.get_entity_doc(version, t.name()).get("description", ""))
for t in tool.Ifc.schema().declaration_by_name("IfcProfileDef").subtypes()
for t in entity.subtypes()
]
@classmethod
@@ -98,7 +98,9 @@ class PsetTemplatesData:
pset_type = next(iter(pset_types)) if len(pset_types) == 1 else None
schema = ifcopenshell.schema_by_name(ifc_file.schema)
attribute = schema.declaration_by_name("IfcSimplePropertyTemplate").attributes()[0]
entity = schema.declaration_by_name("IfcSimplePropertyTemplate").as_entity()
assert entity
attribute = entity.attributes()[0]
enum_items = [
a
for a in ifcopenshell.util.attribute.get_enum_items(attribute)
+3 -3
View File
@@ -70,9 +70,9 @@ class IfcClassData:
if tool.Ifc.get_schema() in ("IFC2X3", "IFC4"):
names.extend(("IfcDoorStyle", "IfcWindowStyle"))
if ifc_product == "IfcElement":
feature_elements = ifcopenshell.util.schema.get_subtypes(
tool.Ifc.schema().declaration_by_name("IfcFeatureElement")
)
entity = tool.Ifc.schema().declaration_by_name("IfcFeatureElement").as_entity()
assert entity
feature_elements = ifcopenshell.util.schema.get_subtypes(entity)
for feature_element in feature_elements:
names.remove(feature_element.name())
version = tool.Ifc.get_schema()
@@ -247,7 +247,8 @@ class SequenceData:
@classmethod
def schedule_predefined_types_enum(cls) -> list[tuple[str, str, str]]:
results: list[tuple[str, str, str]] = []
declaration = tool.Ifc().schema().declaration_by_name("IfcWorkSchedule")
declaration = tool.Ifc().schema().declaration_by_name("IfcWorkSchedule").as_entity()
assert declaration
version = tool.Ifc.get_schema()
for attribute in declaration.attributes():
if attribute.name() == "PredefinedType":
@@ -265,7 +266,8 @@ class SequenceData:
def task_columns_enum(cls) -> list[tuple[str, str, str]]:
schema = tool.Ifc.schema()
taskcolumns_enum = []
for a in schema.declaration_by_name("IfcTask").all_attributes():
assert (entity := schema.declaration_by_name("IfcTask").as_entity())
for a in entity.all_attributes():
if (primitive_type := ifcopenshell.util.attribute.get_primitive_type(a)) not in (
"string",
"float",
@@ -281,7 +283,8 @@ class SequenceData:
def task_time_columns_enum(cls) -> list[tuple[str, str, str]]:
schema = tool.Ifc.schema()
tasktimecolumns_enum = []
for a in schema.declaration_by_name("IfcTaskTime").all_attributes():
assert (entity := schema.declaration_by_name("IfcTaskTime").as_entity())
for a in entity.all_attributes():
if (primitive_type := ifcopenshell.util.attribute.get_primitive_type(a)) not in (
"string",
"float",
@@ -290,7 +290,8 @@ class StructuralLoadsData:
@classmethod
def structural_load_types(cls):
declaration = tool.Ifc.schema().declaration_by_name("IfcStructuralLoadStatic")
declaration = tool.Ifc.schema().declaration_by_name("IfcStructuralLoadStatic").as_entity()
assert declaration
version = tool.Ifc.get_schema()
return [
(d.name(), d.name(), ifcopenshell.util.doc.get_entity_doc(version, d.name()).get("description", ""))
@@ -321,7 +322,8 @@ class BoundaryConditionsData:
@classmethod
def boundary_condition_types(cls):
declaration = tool.Ifc.schema().declaration_by_name("IfcBoundaryCondition")
declaration = tool.Ifc.schema().declaration_by_name("IfcBoundaryCondition").as_entity()
assert declaration
version = tool.Ifc.get_schema()
return [
(d.name(), d.name(), ifcopenshell.util.doc.get_entity_doc(version, d.name()).get("description", ""))
+6 -3
View File
@@ -44,12 +44,14 @@ class StylesData:
@classmethod
def reflectance_methods(cls):
declaration = tool.Ifc.schema().declaration_by_name("IfcReflectanceMethodEnum")
declaration = tool.Ifc.schema().declaration_by_name("IfcReflectanceMethodEnum").as_enumeration_type()
assert declaration
return [(i, i, "") for i in declaration.enumeration_items()]
@classmethod
def style_types(cls):
declaration = tool.Ifc.schema().declaration_by_name("IfcPresentationStyle")
declaration = tool.Ifc.schema().declaration_by_name("IfcPresentationStyle").as_entity()
assert declaration
declarations = ifcopenshell.util.schema.get_subtypes(declaration)
version = tool.Ifc.get_schema()
return [
@@ -66,7 +68,8 @@ class StylesData:
@classmethod
def get_presentation_style_declarations(cls):
declaration = tool.Ifc.schema().declaration_by_name("IfcPresentationStyle")
declaration = tool.Ifc.schema().declaration_by_name("IfcPresentationStyle").as_entity()
assert declaration
return ifcopenshell.util.schema.get_subtypes(declaration)
@@ -153,6 +153,7 @@ class ColourRgb(PropertyGroup):
color_name: StringProperty(name="Color Name")
if TYPE_CHECKING:
name: str
color_value: tuple[float, float, float]
color_name: str
+2 -1
View File
@@ -50,7 +50,8 @@ class SystemData:
@classmethod
def system_class(cls):
declaration = tool.Ifc.schema().declaration_by_name("IfcSystem")
declaration = tool.Ifc.schema().declaration_by_name("IfcSystem").as_entity()
assert declaration
declarations = ifcopenshell.util.schema.get_subtypes(declaration)
version = tool.Ifc.get_schema()
+4 -4
View File
@@ -62,7 +62,8 @@ class UnitsData:
@classmethod
def unit_classes(cls):
declarations = ifcopenshell.util.schema.get_subtypes(tool.Ifc.schema().declaration_by_name("IfcNamedUnit"))
assert (entity := tool.Ifc.schema().declaration_by_name("IfcNamedUnit").as_entity())
declarations = ifcopenshell.util.schema.get_subtypes(entity)
version = tool.Ifc.get_schema()
results = [
(c, c, get_entity_doc(version, c).get("description", "")) for c in sorted([d.name() for d in declarations])
@@ -81,9 +82,8 @@ class UnitsData:
@classmethod
def named_unit_types(cls):
values = ifcopenshell.util.attribute.get_enum_items(
tool.Ifc.schema().declaration_by_name("IfcNamedUnit").all_attributes()[1]
)
assert (entity := tool.Ifc.schema().declaration_by_name("IfcNamedUnit").as_entity())
values = ifcopenshell.util.attribute.get_enum_items(entity.all_attributes()[1])
return [(c, c, "") for c in sorted(values)]
@classmethod
+21 -15
View File
@@ -26,8 +26,8 @@ if TYPE_CHECKING:
def add_material(
ifc: tool.Ifc,
material: tool.Material,
ifc: type[tool.Ifc],
material: type[tool.Material],
name: str,
category: Optional[str] = None,
description: Optional[str] = None,
@@ -38,7 +38,7 @@ def add_material(
return ifc_material
def add_material_set(ifc: tool.Ifc, material: tool.Material, set_type: str) -> ifcopenshell.entity_instance:
def add_material_set(ifc: type[tool.Ifc], material: type[tool.Material], set_type: str) -> ifcopenshell.entity_instance:
ifc_material = ifc.run("material.add_material_set", name="Unnamed", set_type=set_type)
material.ensure_new_material_set_is_valid(ifc_material)
if material.is_editing_materials():
@@ -46,7 +46,9 @@ def add_material_set(ifc: tool.Ifc, material: tool.Material, set_type: str) -> i
return ifc_material
def remove_material(ifc: tool.Ifc, material_tool: tool.Material, material: ifcopenshell.entity_instance) -> bool:
def remove_material(
ifc: type[tool.Ifc], material_tool: type[tool.Material], material: ifcopenshell.entity_instance
) -> bool:
"""Remove an IFC material.
Return True if deletion succeeded,\n
@@ -60,33 +62,37 @@ def remove_material(ifc: tool.Ifc, material_tool: tool.Material, material: ifcop
return True
def remove_material_set(ifc: tool.Ifc, material_tool: tool.Material, material: ifcopenshell.entity_instance) -> None:
def remove_material_set(
ifc: type[tool.Ifc], material_tool: type[tool.Material], material: ifcopenshell.entity_instance
) -> None:
ifc.run("material.remove_material_set", material=material)
if material_tool.is_editing_materials():
material_tool.import_material_definitions(material_tool.get_active_material_type())
def load_materials(material: tool.Material, material_type: str) -> None:
def load_materials(material: type[tool.Material], material_type: str) -> None:
material.import_material_definitions(material_type)
material.enable_editing_materials()
def disable_editing_materials(material: tool.Material) -> None:
def disable_editing_materials(material: type[tool.Material]) -> None:
material.disable_editing_materials()
def select_by_material(
material_tool: tool.Material, spatial: tool.Spatial, material: ifcopenshell.entity_instance
material_tool: type[tool.Material], spatial: type[tool.Spatial], material: ifcopenshell.entity_instance
) -> None:
spatial.select_products(material_tool.get_elements_by_material(material))
def enable_editing_material(material_tool: tool.Material, material: ifcopenshell.entity_instance) -> None:
def enable_editing_material(material_tool: type[tool.Material], material: ifcopenshell.entity_instance) -> None:
material_tool.load_material_attributes(material)
material_tool.enable_editing_material(material)
def edit_material(ifc: tool.Ifc, material_tool: tool.Material, material: ifcopenshell.entity_instance) -> None:
def edit_material(
ifc: type[tool.Ifc], material_tool: type[tool.Material], material: ifcopenshell.entity_instance
) -> None:
attributes = material_tool.get_material_attributes()
ifc.run("material.edit_material", material=material, attributes=attributes)
material_tool.disable_editing_material()
@@ -95,13 +101,13 @@ def edit_material(ifc: tool.Ifc, material_tool: tool.Material, material: ifcopen
material_tool.enable_editing_materials()
def disable_editing_material(material_tool: tool.Material) -> None:
def disable_editing_material(material_tool: type[tool.Material]) -> None:
material_tool.disable_editing_material()
def assign_material(
ifc: tool.Ifc,
material_tool: tool.Material,
ifc: type[tool.Ifc],
material_tool: type[tool.Material],
material_type: Union[str, None],
objects: list[bpy.types.Object],
material: Optional[ifcopenshell.entity_instance] = None,
@@ -131,7 +137,7 @@ def assign_material(
material_tool.ensure_material_assigned(elements=[element], material_type=material_type, material=material)
def unassign_material(ifc: tool.Ifc, material_tool: tool.Material, objects: list[bpy.types.Object]) -> None:
def unassign_material(ifc: type[tool.Ifc], material_tool: type[tool.Material], objects: list[bpy.types.Object]) -> None:
for obj in objects:
element = ifc.get_entity(obj)
if not element:
@@ -158,7 +164,7 @@ def unassign_material(ifc: tool.Ifc, material_tool: tool.Material, objects: list
def patch_non_parametric_mep_segment(
ifc: tool.Ifc, material_tool: tool.Material, profile_tool: tool.Profile, obj: bpy.types.Object
ifc: type[tool.Ifc], material_tool: type[tool.Material], profile_tool: type[tool.Profile], obj: bpy.types.Object
) -> None:
element = ifc.get_entity(obj)
if not element:
+46 -38
View File
@@ -28,13 +28,13 @@ if TYPE_CHECKING:
import bonsai.tool as tool
def load_resources(resource: tool.Resource) -> None:
def load_resources(resource: type[tool.Resource]) -> None:
resource.load_resources()
def add_resource(
tool_ifc: tool.Ifc,
resource_tool: tool.Resource,
tool_ifc: type[tool.Ifc],
resource_tool: type[tool.Resource],
ifc_class,
parent_resource: Optional[ifcopenshell.entity_instance] = None,
) -> None:
@@ -42,33 +42,37 @@ def add_resource(
resource_tool.load_resources()
def disable_editing_resource(resource_tool: tool.Resource) -> None:
def disable_editing_resource(resource_tool: type[tool.Resource]) -> None:
resource_tool.disable_editing_resource()
def disable_resource_editing_ui(resource_tool: tool.Resource) -> None:
def disable_resource_editing_ui(resource_tool: type[tool.Resource]) -> None:
resource_tool.disable_resource_editing_ui()
def enable_editing_resource(resource_tool: tool.Resource, resource) -> None:
def enable_editing_resource(resource_tool: type[tool.Resource], resource) -> None:
resource_tool.enable_editing_resource(resource)
resource_tool.load_resource_attributes(resource)
def edit_resource(ifc: tool.Ifc, resource_tool: tool.Resource, resource: ifcopenshell.entity_instance) -> None:
def edit_resource(
ifc: type[tool.Ifc], resource_tool: type[tool.Resource], resource: ifcopenshell.entity_instance
) -> None:
attributes = resource_tool.get_resource_attributes()
ifc.run("resource.edit_resource", resource=resource, attributes=attributes)
resource_tool.load_resource_properties()
resource_tool.disable_editing_resource()
def remove_resource(ifc: tool.Ifc, resource_tool: tool.Resource, resource: ifcopenshell.entity_instance) -> None:
def remove_resource(
ifc: type[tool.Ifc], resource_tool: type[tool.Resource], resource: ifcopenshell.entity_instance
) -> None:
ifc.run("resource.remove_resource", resource=resource)
resource_tool.load_resources()
def enable_editing_resource_time(
ifc_tool, resource_tool: tool.Resource, resource: ifcopenshell.entity_instance
ifc_tool, resource_tool: type[tool.Resource], resource: ifcopenshell.entity_instance
) -> None:
resource_time = resource_tool.get_resource_time(resource)
if resource_time is None:
@@ -78,19 +82,19 @@ def enable_editing_resource_time(
def edit_resource_time(
ifc: tool.Ifc, resource_tool: tool.Resource, resource_time: ifcopenshell.entity_instance
ifc: type[tool.Ifc], resource_tool: type[tool.Resource], resource_time: ifcopenshell.entity_instance
) -> None:
attributes = resource_tool.get_resource_time_attributes()
ifc.run("resource.edit_resource_time", resource_time=resource_time, attributes=attributes)
resource_tool.disable_editing_resource()
def disable_editing_resource_time(resource_tool: tool.Resource) -> None:
def disable_editing_resource_time(resource_tool: type[tool.Resource]) -> None:
resource_tool.disable_editing_resource()
def calculate_resource_work(
ifc: tool.Ifc, resource_tool: tool.Resource, resource: ifcopenshell.entity_instance
ifc: type[tool.Ifc], resource_tool: type[tool.Resource], resource: ifcopenshell.entity_instance
) -> None:
if resource_tool.get_task_assignments(resource):
ifc.run("resource.calculate_resource_work", resource=resource)
@@ -101,28 +105,30 @@ def calculate_resource_work(
resource_tool.load_resources()
def enable_editing_resource_costs(resource_tool: tool.Resource, resource: ifcopenshell.entity_instance) -> None:
def enable_editing_resource_costs(resource_tool: type[tool.Resource], resource: ifcopenshell.entity_instance) -> None:
resource_tool.enable_editing_resource_costs(resource)
resource_tool.disable_editing_resource_cost_value()
def disable_editing_resource_cost_value(resource_tool: tool.Resource) -> None:
def disable_editing_resource_cost_value(resource_tool: type[tool.Resource]) -> None:
resource_tool.disable_editing_resource_cost_value()
def enable_editing_resource_cost_value(resource_tool: tool.Resource, cost_value: ifcopenshell.entity_instance) -> None:
def enable_editing_resource_cost_value(
resource_tool: type[tool.Resource], cost_value: ifcopenshell.entity_instance
) -> None:
resource_tool.enable_editing_cost_value_attributes(cost_value)
resource_tool.load_cost_value_attributes(cost_value)
def enable_editing_resource_cost_value_formula(
resource_tool: tool.Resource, cost_value: ifcopenshell.entity_instance
resource_tool: type[tool.Resource], cost_value: ifcopenshell.entity_instance
) -> None:
resource_tool.enable_editing_resource_cost_value_formula(cost_value)
def edit_resource_cost_value_formula(
ifc: tool.Ifc, resource_tool: tool.Resource, cost_value: ifcopenshell.entity_instance
ifc: type[tool.Ifc], resource_tool: type[tool.Resource], cost_value: ifcopenshell.entity_instance
) -> None:
formula = resource_tool.get_resource_cost_value_formula()
ifc.run("cost.edit_cost_value_formula", cost_value=cost_value, formula=formula)
@@ -130,65 +136,67 @@ def edit_resource_cost_value_formula(
def edit_resource_cost_value(
ifc: tool.Ifc, resource_tool: tool.Resource, cost_value: ifcopenshell.entity_instance
ifc: type[tool.Ifc], resource_tool: type[tool.Resource], cost_value: ifcopenshell.entity_instance
) -> None:
attributes = resource_tool.get_resource_cost_value_attributes()
ifc.run("cost.edit_cost_value", cost_value=cost_value, attributes=attributes)
resource_tool.disable_editing_resource_cost_value()
def enable_editing_resource_base_quantity(resource_tool: tool.Resource, resource: ifcopenshell.entity_instance) -> None:
def enable_editing_resource_base_quantity(
resource_tool: type[tool.Resource], resource: ifcopenshell.entity_instance
) -> None:
resource_tool.enable_editing_resource_base_quantity(resource)
def add_resource_quantity(ifc: tool.Ifc, ifc_class: str, resource: ifcopenshell.entity_instance) -> None:
def add_resource_quantity(ifc: type[tool.Ifc], ifc_class: str, resource: ifcopenshell.entity_instance) -> None:
ifc.run("resource.add_resource_quantity", resource=resource, ifc_class=ifc_class)
def remove_resource_quantity(ifc: tool.Ifc, resource: ifcopenshell.entity_instance) -> None:
def remove_resource_quantity(ifc: type[tool.Ifc], resource: ifcopenshell.entity_instance) -> None:
ifc.run("resource.remove_resource_quantity", resource=resource)
def enable_editing_resource_quantity(
resource_tool: tool.Resource, resource_quantity: ifcopenshell.entity_instance
resource_tool: type[tool.Resource], resource_quantity: ifcopenshell.entity_instance
) -> None:
resource_tool.enable_editing_resource_quantity(resource_quantity)
def disable_editing_resource_quantity(resource_tool: tool.Resource) -> None:
def disable_editing_resource_quantity(resource_tool: type[tool.Resource]) -> None:
resource_tool.disable_editing_resource_quantity()
def edit_resource_quantity(
resource_tool: tool.Resource, ifc: tool.Ifc, physical_quantity: ifcopenshell.entity_instance
resource_tool: type[tool.Resource], ifc: type[tool.Ifc], physical_quantity: ifcopenshell.entity_instance
) -> None:
attributes = resource_tool.get_resource_quantity_attributes()
ifc.run("resource.edit_resource_quantity", physical_quantity=physical_quantity, attributes=attributes)
resource_tool.disable_editing_resource_quantity()
def import_resources(resource_tool: tool.Resource, file_path: str) -> None:
def import_resources(resource_tool: type[tool.Resource], file_path: str) -> None:
resource_tool.import_resources(file_path)
resource_tool.load_resources()
def export_resources(resource_tool: tool.Resource, file_path: str) -> None:
def export_resources(resource_tool: type[tool.Resource], file_path: str) -> None:
resource_tool.export_resources(file_path)
def expand_resource(resource_tool: tool.Resource, resource: ifcopenshell.entity_instance) -> None:
def expand_resource(resource_tool: type[tool.Resource], resource: ifcopenshell.entity_instance) -> None:
resource_tool.expand_resource(resource)
resource_tool.load_resources()
def contract_resource(resource_tool: tool.Resource, resource: ifcopenshell.entity_instance) -> None:
def contract_resource(resource_tool: type[tool.Resource], resource: ifcopenshell.entity_instance) -> None:
resource_tool.contract_resource(resource)
resource_tool.load_resources()
def assign_resource(
ifc: tool.Ifc,
spatial: tool.Spatial,
ifc: type[tool.Ifc],
spatial: type[tool.Spatial],
resource: ifcopenshell.entity_instance,
products: Optional[Iterable[ifcopenshell.entity_instance]] = None,
) -> None:
@@ -199,8 +207,8 @@ def assign_resource(
def unassign_resource(
ifc: tool.Ifc,
spatial: tool.Spatial,
ifc: type[tool.Ifc],
spatial: type[tool.Spatial],
resource: ifcopenshell.entity_instance,
products: Optional[Iterable[ifcopenshell.entity_instance]] = None,
) -> None:
@@ -210,7 +218,7 @@ def unassign_resource(
ifc.run("resource.unassign_resource", relating_resource=resource, related_object=product)
def edit_productivity_pset(ifc: tool.Ifc, resource_tool: tool.Resource) -> None:
def edit_productivity_pset(ifc: type[tool.Ifc], resource_tool: type[tool.Resource]) -> None:
resource = resource_tool.get_highlighted_resource()
if resource is None:
return
@@ -223,7 +231,7 @@ def edit_productivity_pset(ifc: tool.Ifc, resource_tool: tool.Resource) -> None:
def add_usage_constraint(
ifc: tool.Ifc, resource_tool: tool.Resource, resource: ifcopenshell.entity_instance, reference_path: str
ifc: type[tool.Ifc], resource_tool: type[tool.Resource], resource: ifcopenshell.entity_instance, reference_path: str
) -> None:
metric = resource_tool.has_metric_constraint(resource, "Usage")
if metric:
@@ -245,7 +253,7 @@ def add_usage_constraint(
def remove_usage_constraint(
ifc: tool.Ifc, resource_tool: tool.Resource, resource: ifcopenshell.entity_instance, reference_path: str
ifc: type[tool.Ifc], resource_tool: type[tool.Resource], resource: ifcopenshell.entity_instance, reference_path: str
) -> None:
constraints = resource_tool.get_constraints(resource)
for constraint in constraints:
@@ -258,16 +266,16 @@ def remove_usage_constraint(
ifc.run("constraint.remove_constraint", constraint=constraint)
def go_to_resource(resource_tool: tool.Resource, resource: ifcopenshell.entity_instance) -> None:
def go_to_resource(resource_tool: type[tool.Resource], resource: ifcopenshell.entity_instance) -> None:
resource_tool.go_to_resource(resource)
def calculate_resource_usage(
ifc: tool.Resource, resource_tool: tool.Resource, resource: ifcopenshell.entity_instance
ifc: type[tool.Resource], resource_tool: type[tool.Resource], resource: ifcopenshell.entity_instance
) -> None:
ifc.run("resource.calculate_resource_usage", resource=resource)
resource_tool.load_resources()
def calculate_resource_quantity(resource_tool: tool.Resource, resource: ifcopenshell.entity_instance) -> None:
def calculate_resource_quantity(resource_tool: type[tool.Resource], resource: ifcopenshell.entity_instance) -> None:
resource_tool.calculate_resource_quantity(resource)
+7 -2
View File
@@ -206,16 +206,19 @@ class Drawing(bonsai.core.tool.Drawing):
if not related_object:
related_object = bpy.context.active_object
related_entity = tool.Ifc.get_entity(related_object)
if not related_entity:
if not related_object or not (related_entity := tool.Ifc.get_entity(related_object)):
return
obj_entity = tool.Ifc.get_entity(obj)
assert obj_entity
assign_product = False
if object_type == "STAIR_ARROW":
if related_entity.is_a("IfcStairFlight"):
stair, arrow = related_object, obj
assert isinstance(stair.data, bpy.types.Mesh)
assert isinstance(arrow.data, bpy.types.Mesh)
# place the arrow
# NOTE: may not work correctly in EDIT mode
@@ -239,6 +242,8 @@ class Drawing(bonsai.core.tool.Drawing):
elif object_type == "REVISION_CLOUD":
revised_object, cloud = related_object, obj
assert isinstance(revised_object.data, bpy.types.Mesh)
assert isinstance(obj.data, bpy.types.Mesh)
verts = [np.array(revised_object.matrix_world @ v.co) for v in revised_object.data.vertices]
verts = [(np.around(v[[0, 1]], decimals=3)).tolist() for v in verts]
+2
View File
@@ -1469,11 +1469,13 @@ class Geometry(bonsai.core.tool.Geometry):
ifc_file = tool.Ifc.get()
# as shape aspect might have multiple representations
# it's easier to find it from the item
representation = None
for inverse in ifc_file.get_inverse(representation_items[0]):
if inverse.is_a("IfcShapeRepresentation") and shape_aspect in inverse.OfShapeAspect:
representation = inverse
break
assert representation
# removing last item would make representation invalid
if len(representation.Items) == len(representation_items):
# removing last representation would make shape aspect invalid.
+2 -1
View File
@@ -146,7 +146,8 @@ class Structural(bonsai.core.tool.Structural):
props = cls.get_structural_props()
props.structural_analysis_model_attributes.clear()
schema = tool.Ifc.schema()
for attribute in schema.declaration_by_name("IfcStructuralAnalysisModel").all_attributes():
assert (entity := schema.declaration_by_name("IfcStructuralAnalysisModel").as_entity())
for attribute in entity.all_attributes():
data_type = str(attribute.type_of_attribute)
if "<entity" in data_type:
continue
+2 -1
View File
@@ -74,7 +74,8 @@ class TestPurgeHdf5Cache(NewFile):
class TestMergeIdenticalObject(NewFile):
def test_merge_identical_styles(self):
tool.Ifc.set(ifc := ifcopenshell.file())
declaration = tool.Ifc.schema().declaration_by_name("IfcPresentationStyle")
declaration = tool.Ifc.schema().declaration_by_name("IfcPresentationStyle").as_entity()
assert declaration
style_types = [d.name() for d in ifcopenshell.util.schema.get_subtypes(declaration)]
for style_type in style_types:
ifc.create_entity(style_type, Name=style_type)
@@ -708,7 +708,7 @@ class cylinder(surface):
def matrix(self): ...
class declaration:
def _is(self, *args: str) -> bool: ...
def _is(self, *args: Union[str, declaration]) -> bool: ...
def as_entity(self) -> Union[entity, None]: ...
def as_enumeration_type(self) -> Union[enumeration_type, None]: ...
def as_select_type(self) -> Union[select_type, None]: ...
@@ -25,7 +25,8 @@ import ifcopenshell.api.control
class TestAddCostItemQuantity(test.bootstrap.IFC4):
def test_run(self):
schema = ifcopenshell.schema_by_name(self.file.schema)
quantity_types = [t.name() for t in schema.declaration_by_name("IfcPhysicalSimpleQuantity").subtypes()]
assert (entity := schema.declaration_by_name("IfcPhysicalSimpleQuantity").as_entity())
quantity_types = [t.name() for t in entity.subtypes()]
schedule = ifcopenshell.api.cost.add_cost_schedule(self.file)
item = ifcopenshell.api.cost.add_cost_item(self.file, cost_schedule=schedule)
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
@@ -26,8 +26,10 @@ import ifcopenshell.util.resource
class TestAddResourceQuantity(test.bootstrap.IFC4):
def test_run(self):
schema = ifcopenshell.schema_by_name(self.file.schema)
quantity_types = [t.name() for t in schema.declaration_by_name("IfcPhysicalSimpleQuantity").subtypes()]
resource_types = [t.name() for t in schema.declaration_by_name("IfcConstructionResource").subtypes()]
assert (quantity_entity := schema.declaration_by_name("IfcPhysicalSimpleQuantity").as_entity())
quantity_types = [t.name() for t in quantity_entity.subtypes()]
assert (resource_entity := schema.declaration_by_name("IfcConstructionResource").as_entity())
resource_types = [t.name() for t in resource_entity.subtypes()]
self.file.create_entity("IfcProject") # add_resource
@@ -31,7 +31,8 @@ class TestValidateGroupTypes:
ifcsystem_classes = set()
for schema_name in get_args(ifcopenshell.util.schema.IFC_SCHEMA):
schema = ifcopenshell.schema_by_name(schema_name)
declaration = schema.declaration_by_name("IfcSystem")
declaration = schema.declaration_by_name("IfcSystem").as_entity()
assert declaration
declarations = ifcopenshell.util.schema.get_subtypes(declaration)
ifcsystem_classes.update(d.name() for d in declarations)
@@ -227,7 +227,8 @@ class TestFormatLength(test.bootstrap.IFC4):
class TestIsAttrType(test.bootstrap.IFC4):
def test_run(self):
schema = ifcopenshell.schema_by_name("IFC4")
declaration = schema.declaration_by_name("IfcPropertySingleValue")
declaration = schema.declaration_by_name("IfcPropertySingleValue").as_entity()
assert declaration
nominal_value = declaration.attribute_by_index(2).type_of_attribute()
assert subject.is_attr_type(nominal_value, "IfcValue")
assert subject.is_attr_type(nominal_value, "IfcLengthMeasure")
+8 -6
View File
@@ -38,7 +38,7 @@ from .facet import (
Cardinality,
FacetFailure,
)
from typing import Optional, Union
from typing import Optional, Union, Any
cwd = os.path.dirname(os.path.realpath(__file__))
schema = None
@@ -83,6 +83,8 @@ def get_schema():
class Ids:
info: dict[str, Any]
def __init__(
self,
title: Optional[str] = "Untitled",
@@ -119,12 +121,12 @@ class Ids:
if milestone:
self.info["milestone"] = milestone
def asdict(self):
info = {}
def asdict(self) -> dict[str, Any]:
info: dict[str, Any] = {}
for attr in ["title", "copyright", "version", "description", "author", "date", "purpose", "milestone"]:
if attr in self.info:
info[attr] = self.info[attr]
ids_dict = {
ids_dict: dict[str, Any] = {
"@xmlns": "http://standards.buildingsmart.org/IDS",
"@xmlns:xs": "http://www.w3.org/2001/XMLSchema",
"@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
@@ -202,8 +204,8 @@ class Specification:
self.status = None
self.is_ifc_version = None
def asdict(self):
results = {
def asdict(self) -> dict[str, Any]:
results: dict[str, Any] = {
"@name": self.name,
"@ifcVersion": self.ifcVersion,
"applicability": {},