fix tests after a9a4b0c

This commit is contained in:
Andrej730
2024-07-31 13:58:43 +05:00
parent 133494af97
commit d384aaeb9c
7 changed files with 36 additions and 80 deletions
@@ -167,7 +167,7 @@ class BIM_OT_add_aggregate(bpy.types.Operator, tool.Ifc.Operator):
tool.Ifc,
tool.Collector,
tool.Spatial,
structure_obj=tool.Ifc.get_object(current_container),
container=current_container,
element_obj=aggregate,
)
core.assign_object(tool.Ifc, tool.Aggregate, tool.Collector, relating_obj=aggregate, related_obj=obj)
@@ -225,9 +225,8 @@ class AddConstrTypeInstance(bpy.types.Operator):
else:
parent = ifcopenshell.util.element.get_container(building_element)
if parent:
parent_obj = tool.Ifc.get_object(parent)
blenderbim.core.spatial.assign_container(
tool.Ifc, tool.Collector, tool.Spatial, structure_obj=parent_obj, element_obj=obj
tool.Ifc, tool.Collector, tool.Spatial, container=parent, element_obj=obj
)
# set occurrences properties for the types defined with modifiers
+1 -1
View File
@@ -95,7 +95,7 @@ def copy_to_container(
copied_obj = spatial.duplicate_object_and_data(obj)
spatial.set_relative_object_matrix(copied_obj, to_container_obj, matrix)
result_objs.append(spatial.run_root_copy_class(obj=copied_obj))
spatial.run_spatial_assign_container(structure_obj=to_container_obj, element_obj=copied_obj)
spatial.run_spatial_assign_container(container=to_container, element_obj=copied_obj)
spatial.disable_editing(obj)
return result_objs
+19 -11
View File
@@ -846,11 +846,10 @@ class Sequence:
@interface
class Spatial:
def can_contain(cls, structure_obj, element_obj): pass
def can_contain(cls, container, element_obj): pass
def can_reference(cls, structure, element): pass
def contract_container(cls, container): pass
def copy_xy(cls, src_obj, destination_obj): pass
def import_spatial_element(cls, element, level_index): pass
def deselect_objects(cls): pass
def disable_editing(cls, obj): pass
def duplicate_object_and_data(cls, obj): pass
@@ -858,6 +857,9 @@ class Spatial:
def edit_container_name(cls, container, name): pass
def enable_editing(cls, obj): pass
def expand_container(cls, container): pass
def filter_elements_by_class(cls, elements, ifc_class): pass
def filter_elements_by_relating_type(cls, elements, relating_type): pass
def filter_elements_by_untyped(cls, elements): pass
def filter_products(cls, products, action): pass
def get_active_container(cls): pass
def get_container(cls, element): pass
@@ -866,21 +868,24 @@ class Spatial:
def get_relative_object_matrix(cls, target_obj, relative_to_obj): pass
def get_selected_product_types(cls): pass
def get_selected_products(cls): pass
def import_containers(cls, parent=None): pass
def import_spatial_decomposition(cls): pass
def run_root_copy_class(cls, obj=None): pass
def run_spatial_assign_container(cls, structure_obj=None, element_obj=None): pass
def import_spatial_element(cls, element, level_index): pass
def load_contained_elements(cls): pass
def run_root_copy_class(cls, obj): pass
def run_spatial_assign_container(cls, container, element_obj): pass
def run_spatial_import_spatial_decomposition(cls): pass
def select_object(cls, obj): pass
def select_products(cls, products, unhide=False): pass
def set_active_object(cls, obj): pass
def set_relative_object_matrix(cls, target_obj, relative_to_obj, matrix): pass
def set_default_container(cls, container): pass
def show_scene_objects(cls): pass
#HERE STARTS SPATIAL TOOL
# HERE STARTS SPATIAL TOOL
def is_bounding_class(cls, visible_element): pass
def get_space_polygon_from_context_visible_objects(cls, x, y): pass
def get_boundary_lines_from_context_visible_objects(cls, visible_objects): pass
def debug_shape(cls, foo): pass
def debug_line(cls, start, end): pass
def get_boundary_lines_from_context_visible_objects(cls): pass
def get_gross_mesh_from_element(cls, visible_element): pass
def create_mesh_from_shape(cls, shape): pass
def get_x_y_z_h_mat_from_active_obj(cls, active_obj): pass
@@ -907,17 +912,20 @@ class Spatial:
def get_active_obj_z(cls): pass
def get_active_obj_height(cls): pass
def get_relating_type_id(cls): pass
def translate_obj_to_z_location(cls, obj): pass
def translate_obj_to_z_location(cls, obj, z): pass
def get_2d_vertices_from_obj(cls, obj): pass
def get_scaled_2d_vertices(cls, points): pass
def assign_swept_area_outer_curve_from_2d_vertices(cls, obj, vertices): pass
def get_body_representation(cls, obj): pass
def assign_ifcspace_class_to_obj(cls, obj): pass
def assign_type_to_obj(cls, obj): pass
def assign_relating_type_to_element(cls, ifc, Type, element, relating_type): pass
def regen_obj_representation(cls, ifc, geometry, obj, body): pass
def assign_relating_type_to_element(cls, ifc, type, element, relating_type): pass
def regen_obj_representation(cls, obj, body): pass
def toggle_spaces_visibility_wired_and_textured(cls, spaces): pass
def toggle_hide_spaces(cls, spaces): pass
def set_default_container(cls, container): pass
def guess_default_container(cls): pass
def get_selected_containers(cls): pass
@interface
class Covering:
+2 -2
View File
@@ -114,10 +114,10 @@ class Spatial(blenderbim.core.tool.Spatial):
@classmethod
def run_spatial_assign_container(
cls, structure_obj: bpy.types.Object, element_obj: bpy.types.Object
cls, container: ifcopenshell.entity_instance, element_obj: bpy.types.Object
) -> Union[ifcopenshell.entity_instance, None]:
return blenderbim.core.spatial.assign_container(
tool.Ifc, tool.Collector, tool.Spatial, structure_obj=structure_obj, element_obj=element_obj
tool.Ifc, tool.Collector, tool.Spatial, container=container, element_obj=element_obj
)
@classmethod
+6 -17
View File
@@ -38,24 +38,21 @@ class TestDereferenceStructure:
class TestAssignContainer:
def test_run(self, ifc, collector, spatial):
spatial.can_contain("structure_obj", "element_obj").should_be_called().will_return(True)
ifc.get_entity("structure_obj").should_be_called().will_return("structure")
spatial.can_contain("container", "element_obj").should_be_called().will_return(True)
ifc.get_entity("element_obj").should_be_called().will_return("element")
ifc.run(
"spatial.assign_container", products=["element"], relating_structure="structure"
"spatial.assign_container", products=["element"], relating_structure="container"
).should_be_called().will_return("rel")
spatial.disable_editing("element_obj").should_be_called()
collector.assign("element_obj").should_be_called()
assert (
subject.assign_container(ifc, collector, spatial, structure_obj="structure_obj", element_obj="element_obj")
== "rel"
subject.assign_container(ifc, collector, spatial, container="container", element_obj="element_obj") == "rel"
)
class TestEnableEditingContainer:
def test_run(self, spatial):
spatial.enable_editing("obj").should_be_called()
spatial.import_containers().should_be_called()
subject.enable_editing_container(spatial, obj="obj")
@@ -65,12 +62,6 @@ class TestDisableEditingContainer:
subject.disable_editing_container(spatial, obj="obj")
class TestChangeSpatialLevel:
def test_run(self, spatial):
spatial.import_containers(parent="parent").should_be_called()
subject.change_spatial_level(spatial, parent="parent")
class TestRemoveContainer:
def test_run(self, ifc, collector):
ifc.get_entity("obj").should_be_called().will_return("element")
@@ -90,7 +81,7 @@ class TestCopyToContainer:
spatial.duplicate_object_and_data("obj").should_be_called().will_return("new_obj")
spatial.set_relative_object_matrix("new_obj", "to_container_obj", "matrix").should_be_called()
spatial.run_root_copy_class(obj="new_obj").should_be_called()
spatial.run_spatial_assign_container(structure_obj="to_container_obj", element_obj="new_obj").should_be_called()
spatial.run_spatial_assign_container(container="to_container", element_obj="new_obj").should_be_called()
spatial.disable_editing("obj").should_be_called()
@@ -105,7 +96,7 @@ class TestCopyToContainer:
spatial.duplicate_object_and_data("obj").should_be_called().will_return("new_obj")
spatial.set_relative_object_matrix("new_obj", "to_container_obj", "matrix").should_be_called()
spatial.run_root_copy_class(obj="new_obj").should_be_called()
spatial.run_spatial_assign_container(structure_obj="to_container_obj", element_obj="new_obj").should_be_called()
spatial.run_spatial_assign_container(container="to_container", element_obj="new_obj").should_be_called()
spatial.disable_editing("obj").should_be_called()
@@ -114,11 +105,9 @@ class TestCopyToContainer:
class TestSelectContainer:
def test_run(self, ifc, spatial):
ifc.get_entity("obj").should_be_called().will_return("element")
spatial.get_container("element").should_be_called().will_return("container")
ifc.get_object("container").should_be_called().will_return("container_obj")
spatial.set_active_object("container_obj").should_be_called()
subject.select_container(ifc, spatial, obj="obj")
subject.select_container(ifc, spatial, container="container")
class TestSelectSimilarContainer:
+6 -46
View File
@@ -40,7 +40,7 @@ class TestCanContain(NewFile):
element = ifc.createIfcWall()
element_obj = bpy.data.objects.new("Object", None)
tool.Ifc.link(element, element_obj)
assert subject.can_contain(structure_obj, element_obj) is True
assert subject.can_contain(structure, element_obj) is True
def test_a_spatial_structure_element_can_contain_an_element_ifc2x3(self):
ifc = ifcopenshell.file(schema="IFC2X3")
@@ -51,7 +51,7 @@ class TestCanContain(NewFile):
element = ifc.createIfcWall()
element_obj = bpy.data.objects.new("Object", None)
tool.Ifc.link(element, element_obj)
assert subject.can_contain(structure_obj, element_obj) is True
assert subject.can_contain(structure, element_obj) is True
def test_a_spatial_zone_element_cannot_contain_an_element(self):
ifc = ifcopenshell.file()
@@ -62,7 +62,7 @@ class TestCanContain(NewFile):
element = ifc.createIfcWall()
element_obj = bpy.data.objects.new("Object", None)
tool.Ifc.link(element, element_obj)
assert subject.can_contain(structure_obj, element_obj) is False
assert subject.can_contain(structure, element_obj) is False
def test_unlinked_elements_cannot_contain_anything(self):
structure_obj = bpy.data.objects.new("Object", None)
@@ -78,7 +78,7 @@ class TestCanContain(NewFile):
element = ifc.createIfcWall()
element_obj = bpy.data.objects.new("Object", None)
tool.Ifc.link(element, element_obj)
assert subject.can_contain(structure_obj, element_obj) is False
assert subject.can_contain(structure, element_obj) is False
def test_a_non_element_cannot_be_contained(self):
ifc = ifcopenshell.file()
@@ -89,7 +89,7 @@ class TestCanContain(NewFile):
element = ifc.createIfcTask()
element_obj = bpy.data.objects.new("Object", None)
tool.Ifc.link(element, element_obj)
assert subject.can_contain(structure_obj, element_obj) is False
assert subject.can_contain(structure, element_obj) is False
def test_other_non_elements_that_have_a_contained_in_structure_attribute_can_be_contained(self):
ifc = ifcopenshell.file()
@@ -100,7 +100,7 @@ class TestCanContain(NewFile):
element = ifc.createIfcGrid()
element_obj = bpy.data.objects.new("Object", None)
tool.Ifc.link(element, element_obj)
assert subject.can_contain(structure_obj, element_obj) is True
assert subject.can_contain(structure, element_obj) is True
class TestCanReference(NewFile):
@@ -181,46 +181,6 @@ class TestGetRelativeObjectMatrix(NewFile):
assert subject.get_relative_object_matrix(obj, relative_obj)[0][3] == -1
class TestImportContainers(NewFile):
def test_run(self):
bpy.ops.bim.create_project()
subject.import_containers()
props = bpy.context.scene.BIMSpatialProperties
assert len(props.containers) == 1
assert props.containers[0].name == "My Site"
assert props.containers[0].long_name == ""
assert props.containers[0].has_decomposition is True
assert props.containers[0].ifc_definition_id == tool.Ifc.get().by_type("IfcSite")[0].id()
assert props.active_container_id == tool.Ifc.get().by_type("IfcProject")[0].id()
def test_importing_with_a_specified_parent(self):
bpy.ops.bim.create_project()
site = tool.Ifc.get().by_type("IfcSite")[0]
subject.import_containers(site)
props = bpy.context.scene.BIMSpatialProperties
assert len(props.containers) == 1
assert props.containers[0].name == "My Building"
assert props.containers[0].long_name == ""
assert props.containers[0].has_decomposition is True
assert props.containers[0].ifc_definition_id == tool.Ifc.get().by_type("IfcBuilding")[0].id()
assert props.active_container_id == site.id()
def test_importing_sorted_by_z_placement(self):
bpy.ops.bim.create_project()
building = tool.Ifc.get().by_type("IfcBuilding")[0]
storey1 = tool.Ifc.get().by_type("IfcBuildingStorey")[0]
storey1.Name = "Higher"
bpy.ops.bim.copy_class(obj=tool.Ifc.get_object(storey1).name)
storey2 = tool.Ifc.get().by_type("IfcBuildingStorey")[1]
storey2.Name = "Lower"
storey2.ObjectPlacement.RelativePlacement.Location.Coordinates = (0.0, 0.0, -100.0)
subject.import_containers(building)
props = bpy.context.scene.BIMSpatialProperties
assert len(props.containers) == 2
assert props.containers[0].name == "Lower"
assert props.containers[1].name == "Higher"
class TestRunRootCopyClass(NewFile):
def test_nothing(self):
pass