mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-15 18:14:08 +00:00
typing
This commit is contained in:
@@ -22,8 +22,12 @@ import bonsai.core.tool
|
||||
import bonsai.tool as tool
|
||||
import pytest
|
||||
from test.bim.bootstrap import NewFile
|
||||
from typing import TYPE_CHECKING
|
||||
from bonsai.tool.blender import Blender as subject
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import bpy._typing.rna_enums as rna_enums
|
||||
|
||||
|
||||
class TestImplementsTool(NewFile):
|
||||
def test_run(self):
|
||||
@@ -34,6 +38,7 @@ class TestCopyNodeGraph(NewFile):
|
||||
def test_run(self):
|
||||
material_to = bpy.data.materials.new("material_to")
|
||||
material_to.use_nodes = True
|
||||
assert material_to.node_tree
|
||||
material_to_nodes = material_to.node_tree.nodes
|
||||
assert len(material_to_nodes) == 2
|
||||
for node in material_to_nodes:
|
||||
@@ -70,7 +75,7 @@ class TestBlenderErrorMessageExtraction(NewFile):
|
||||
bl_idname = "object.test_fail_operator"
|
||||
bl_label = "Test Fail Operator"
|
||||
|
||||
def execute(self, context):
|
||||
def execute(self, context) -> "set[rna_enums.OperatorReturnItems]":
|
||||
self.report({"INFO"}, "Info message.")
|
||||
subject.report_operator_errors(self, ERROR_REPORTS)
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -138,6 +138,7 @@ class TestAddBrickifcProject(NewFile):
|
||||
class TestAddBrickifcReference(NewFile):
|
||||
def test_run(self):
|
||||
TestAddBrickifcProject().test_run()
|
||||
assert BrickStore.graph
|
||||
element = tool.Ifc.get().createIfcChiller(ifcopenshell.guid.new())
|
||||
element.Name = "Chiller"
|
||||
project = URIRef(f"http://example.org/digitaltwin#{tool.Ifc.get().by_type('IfcProject')[0].GlobalId}")
|
||||
@@ -173,6 +174,7 @@ class TestAddRelation(NewFile):
|
||||
class TestRemoveRelation(NewFile):
|
||||
def test_run(self):
|
||||
TestAddRelation().test_run()
|
||||
assert BrickStore.graph
|
||||
source, relation, destination = list(
|
||||
BrickStore.graph.triples((None, URIRef("https://brickschema.org/schema/Brick#feeds"), None))
|
||||
)[0]
|
||||
@@ -321,7 +323,7 @@ class TestGetConvertableBrickSystems(NewFile):
|
||||
|
||||
|
||||
class TestGetParentSpace(NewFile):
|
||||
def test_run(cls):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcBuildingStorey")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcSpace")
|
||||
@@ -333,17 +335,17 @@ class TestGetParentSpace(NewFile):
|
||||
|
||||
|
||||
class TestGetElementContainer(NewFile):
|
||||
def test_nothing(cls):
|
||||
def test_nothing(self):
|
||||
pass
|
||||
|
||||
|
||||
class TestGetElementSystems(NewFile):
|
||||
def test_nothing(cls):
|
||||
def test_nothing(self):
|
||||
pass
|
||||
|
||||
|
||||
class TestGetElementFeeds(NewFile):
|
||||
def test_run(cls):
|
||||
def test_run(self):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,9 @@ import bpy
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.aggregate
|
||||
import ifcopenshell.api.feature
|
||||
import ifcopenshell.api.group
|
||||
import ifcopenshell.api.spatial
|
||||
import ifcopenshell.util.element
|
||||
import bonsai.core.tool
|
||||
import bonsai.tool as tool
|
||||
@@ -34,6 +37,7 @@ class TestImplementsTool(NewFile):
|
||||
|
||||
class TestAssign(NewIfc):
|
||||
def test_walls_are_placed_in_its_spatial_collection(self):
|
||||
assert bpy.context.scene
|
||||
wall_obj = bpy.data.objects.new("Object", None)
|
||||
wall_element = tool.Ifc.get().createIfcWall()
|
||||
tool.Ifc.link(wall_element, wall_obj)
|
||||
@@ -48,6 +52,7 @@ class TestAssign(NewIfc):
|
||||
assert "IfcSite" in wall_obj.users_collection[0].name
|
||||
|
||||
def test_walls_are_unsorted_if_not_decomposes(self):
|
||||
assert bpy.context.scene
|
||||
wall_obj = bpy.data.objects.new("Object", None)
|
||||
wall_element = tool.Ifc.get().createIfcWall()
|
||||
tool.Ifc.link(wall_element, wall_obj)
|
||||
@@ -57,6 +62,7 @@ class TestAssign(NewIfc):
|
||||
assert "Unsorted" in wall_obj.users_collection[0].name
|
||||
|
||||
def test_spatial_structure_elements_are_placed_in_a_collection_of_the_same_name(self):
|
||||
assert bpy.context.scene
|
||||
building_obj = bpy.data.objects.new("IfcBuilding/Name", None)
|
||||
building_element = tool.Ifc.get().createIfcBuilding()
|
||||
tool.Ifc.link(building_element, building_obj)
|
||||
@@ -71,6 +77,7 @@ class TestAssign(NewIfc):
|
||||
assert building_obj.users_collection[0].name == building_obj.name
|
||||
|
||||
def test_spaces_are_special_and_are_placed_in_a_spaces_collection(self):
|
||||
assert bpy.context.scene
|
||||
space_obj = bpy.data.objects.new("IfcSpace/Name", None)
|
||||
space_element = tool.Ifc.get().createIfcSpace()
|
||||
tool.Ifc.link(space_element, space_obj)
|
||||
@@ -85,6 +92,7 @@ class TestAssign(NewIfc):
|
||||
assert space_obj.users_collection[0].name == "IfcSpace"
|
||||
|
||||
def test_multiple_assigns_do_not_create_duplicate_spatial_structure_collections(self):
|
||||
assert bpy.context.scene
|
||||
space_obj = bpy.data.objects.new("IfcSpace/Name", None)
|
||||
space_element = tool.Ifc.get().createIfcSpace()
|
||||
tool.Ifc.link(space_element, space_obj)
|
||||
@@ -102,6 +110,7 @@ class TestAssign(NewIfc):
|
||||
assert not bpy.data.collections.get("IfcSite/My Site.001")
|
||||
|
||||
def test_spatial_zone_elements_are_not_placed_in_a_collection_of_the_same_name(self):
|
||||
assert bpy.context.scene
|
||||
space_obj = bpy.data.objects.new("IfcSpaceZone/Name", None)
|
||||
space_element = tool.Ifc.get().createIfcSpatialZone()
|
||||
tool.Ifc.link(space_element, space_obj)
|
||||
@@ -116,6 +125,7 @@ class TestAssign(NewIfc):
|
||||
assert space_obj.users_collection[0].name != space_obj.name
|
||||
|
||||
def test_aggregates_are_also_placed_in_their_container(self):
|
||||
assert bpy.context.scene
|
||||
element_obj = bpy.data.objects.new("IfcElementAssembly/Name", None)
|
||||
element = tool.Ifc.get().createIfcElementAssembly()
|
||||
subelement_obj = bpy.data.objects.new("IfcBeam/Name", None)
|
||||
@@ -142,6 +152,7 @@ class TestAssign(NewIfc):
|
||||
assert "IfcSite" in subelement_obj.users_collection[0].name
|
||||
|
||||
def test_projects_are_placed_in_a_collection_of_the_same_name(self):
|
||||
assert bpy.context.scene
|
||||
tool.Ifc.set(ifcopenshell.file())
|
||||
element_obj = bpy.data.objects.new("IfcProject/Name", None)
|
||||
element = tool.Ifc.get().createIfcProject()
|
||||
@@ -152,6 +163,7 @@ class TestAssign(NewIfc):
|
||||
assert element_obj.users_collection[0].name == element_obj.name
|
||||
|
||||
def test_multiple_assigns_do_not_create_duplicate_collections(self):
|
||||
assert bpy.context.scene
|
||||
tool.Ifc.set(ifcopenshell.file())
|
||||
element_obj = bpy.data.objects.new("IfcProject/Name", None)
|
||||
element = tool.Ifc.get().createIfcProject()
|
||||
@@ -163,6 +175,7 @@ class TestAssign(NewIfc):
|
||||
assert not bpy.data.collections.get("IfcProject/Name.001")
|
||||
|
||||
def test_own_collections_are_retained_and_name_synced(self):
|
||||
assert bpy.context.scene
|
||||
building_obj = bpy.data.objects.new("IfcBuilding/Name", None)
|
||||
building_element = tool.Ifc.get().createIfcBuilding()
|
||||
tool.Ifc.link(building_element, building_obj)
|
||||
@@ -178,22 +191,24 @@ class TestAssign(NewIfc):
|
||||
)
|
||||
subject.assign(building_obj)
|
||||
assert bpy.context.scene.collection.children.find(building_collection.name) != -1
|
||||
assert bpy.data.collections.get("IfcSite/My Site").children.find(building_collection.name) == -1
|
||||
assert bpy.data.collections.get("IfcProject/My Project").children.find(building_collection.name) == -1
|
||||
assert bpy.data.collections["IfcSite/My Site"].children.find(building_collection.name) == -1
|
||||
assert bpy.data.collections["IfcProject/My Project"].children.find(building_collection.name) == -1
|
||||
assert bpy.context.scene.collection.children.find(building_collection.name) != -1
|
||||
assert building_collection.objects.find(building_obj.name) != -1
|
||||
assert building_collection.name == "IfcBuilding/Name"
|
||||
|
||||
def test_types_are_placed_in_the_types_collection(self):
|
||||
assert bpy.context.scene
|
||||
element_obj = bpy.data.objects.new("IfcWallType/Name", None)
|
||||
element = tool.Ifc.get().createIfcWallType()
|
||||
tool.Ifc.link(element, element_obj)
|
||||
bpy.context.scene.collection.objects.link(element_obj)
|
||||
subject.assign(element_obj)
|
||||
assert element_obj.users_collection[0].name == "IfcTypeProduct"
|
||||
assert bpy.data.collections.get("IfcProject/My Project").children.get("IfcTypeProduct")
|
||||
assert bpy.data.collections["IfcProject/My Project"].children.get("IfcTypeProduct")
|
||||
|
||||
def test_openings_are_placed_in_their_voided_elements_container(self):
|
||||
assert bpy.context.scene
|
||||
element_obj = bpy.data.objects.new("IfcOpeningElement/Name", None)
|
||||
element = tool.Ifc.get().createIfcOpeningElement()
|
||||
tool.Ifc.link(element, element_obj)
|
||||
@@ -210,6 +225,7 @@ class TestAssign(NewIfc):
|
||||
assert element_obj.users_collection[0].name == "IfcSite/My Site"
|
||||
|
||||
def test_grids_are_placed_in_their_container(self):
|
||||
assert bpy.context.scene
|
||||
element_obj = bpy.data.objects.new("IfcGrid/Name", None)
|
||||
element = tool.Ifc.get().createIfcGrid()
|
||||
tool.Ifc.link(element, element_obj)
|
||||
@@ -223,6 +239,7 @@ class TestAssign(NewIfc):
|
||||
assert element_obj.users_collection[0].name == "IfcSite/My Site"
|
||||
|
||||
def test_grids_axes_are_placed_in_the_grids_container(self):
|
||||
assert bpy.context.scene
|
||||
element_obj = bpy.data.objects.new("IfcGrid/Name", None)
|
||||
axis_obj = bpy.data.objects.new("IfcGrid/Name", None)
|
||||
axis = tool.Ifc.get().createIfcGridAxis()
|
||||
@@ -250,7 +267,7 @@ class TestAssign(NewIfc):
|
||||
|
||||
subject.assign(element_obj)
|
||||
assert element_obj.users_collection[0].name == "IfcAnnotation/DRAWING"
|
||||
assert bpy.data.collections.get("IfcProject/My Project").children.get("IfcAnnotation/DRAWING")
|
||||
assert bpy.data.collections["IfcProject/My Project"].children.get("IfcAnnotation/DRAWING")
|
||||
|
||||
def test_annotations_are_placed_in_their_drawings_collection(self):
|
||||
self.test_drawings_are_placed_in_their_own_collection()
|
||||
@@ -272,7 +289,7 @@ class TestAssign(NewIfc):
|
||||
tool.Ifc.link(element, element_obj)
|
||||
subject.assign(element_obj)
|
||||
assert element_obj.users_collection[0].name == "IfcStructuralItem"
|
||||
assert bpy.data.collections.get("IfcProject/My Project").children.get("IfcStructuralItem")
|
||||
assert bpy.data.collections["IfcProject/My Project"].children.get("IfcStructuralItem")
|
||||
|
||||
def test_structural_connections_are_placed_in_a_connections_collection(self):
|
||||
element_obj = bpy.data.objects.new("IfcStructuralCurveConnection/Name", None)
|
||||
@@ -280,7 +297,7 @@ class TestAssign(NewIfc):
|
||||
tool.Ifc.link(element, element_obj)
|
||||
subject.assign(element_obj)
|
||||
assert element_obj.users_collection[0].name == "IfcStructuralItem"
|
||||
assert bpy.data.collections.get("IfcProject/My Project").children.get("IfcStructuralItem")
|
||||
assert bpy.data.collections["IfcProject/My Project"].children.get("IfcStructuralItem")
|
||||
|
||||
|
||||
class TestAssignIFC4X3(NewIfc4X3):
|
||||
@@ -290,7 +307,7 @@ class TestAssignIFC4X3(NewIfc4X3):
|
||||
tool.Ifc.link(element, element_obj)
|
||||
subject.assign(element_obj)
|
||||
assert element_obj.users_collection[0].name == "IfcLinearPositioningElement"
|
||||
assert bpy.data.collections.get("IfcProject/My Project").children.get("IfcLinearPositioningElement")
|
||||
assert bpy.data.collections["IfcProject/My Project"].children.get("IfcLinearPositioningElement")
|
||||
|
||||
def test_referents_are_placed_in_a_special_collection(self):
|
||||
element_obj = bpy.data.objects.new("Name", None)
|
||||
@@ -298,4 +315,4 @@ class TestAssignIFC4X3(NewIfc4X3):
|
||||
tool.Ifc.link(element, element_obj)
|
||||
subject.assign(element_obj)
|
||||
assert element_obj.users_collection[0].name == "IfcReferent"
|
||||
assert bpy.data.collections.get("IfcProject/My Project").children.get("IfcReferent")
|
||||
assert bpy.data.collections["IfcProject/My Project"].children.get("IfcReferent")
|
||||
|
||||
@@ -34,7 +34,8 @@ class TestSetContext(test.bim.bootstrap.NewFile):
|
||||
ifc = ifcopenshell.file()
|
||||
context = ifc.createIfcGeometricRepresentationContext()
|
||||
subject.set_context(context)
|
||||
assert bpy.context.scene.BIMContextProperties.active_context_id == context.id()
|
||||
props = subject.get_context_props()
|
||||
assert props.active_context_id == context.id()
|
||||
|
||||
|
||||
class TestImportAttributes(test.bim.bootstrap.NewFile):
|
||||
@@ -48,11 +49,11 @@ class TestImportAttributes(test.bim.bootstrap.NewFile):
|
||||
context.Precision = 1
|
||||
subject.set_context(context)
|
||||
subject.import_attributes()
|
||||
props = bpy.context.scene.BIMContextProperties
|
||||
assert props.context_attributes.get("ContextIdentifier").string_value == "ContextIdentifier"
|
||||
assert props.context_attributes.get("ContextType").string_value == "ContextType"
|
||||
assert props.context_attributes.get("CoordinateSpaceDimension").int_value == 1
|
||||
assert props.context_attributes.get("Precision").string_value == "1.0"
|
||||
props = subject.get_context_props()
|
||||
assert props.context_attributes["ContextIdentifier"].string_value == "ContextIdentifier"
|
||||
assert props.context_attributes["ContextType"].string_value == "ContextType"
|
||||
assert props.context_attributes["CoordinateSpaceDimension"].int_value == 1
|
||||
assert props.context_attributes["Precision"].string_value == "1.0"
|
||||
|
||||
def test_importing_a_subcontext(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -63,11 +64,11 @@ class TestImportAttributes(test.bim.bootstrap.NewFile):
|
||||
subcontext.UserDefinedTargetView = "UserDefinedTargetView"
|
||||
subject.set_context(subcontext)
|
||||
subject.import_attributes()
|
||||
props = bpy.context.scene.BIMContextProperties
|
||||
assert props.context_attributes.get("TargetScale").float_value == 0.5
|
||||
assert props.context_attributes.get("TargetView").enum_value == "NOTDEFINED"
|
||||
assert props.context_attributes.get("UserDefinedTargetView").string_value == "UserDefinedTargetView"
|
||||
assert not props.context_attributes.get("Precision")
|
||||
props = subject.get_context_props()
|
||||
assert props.context_attributes["TargetScale"].float_value == 0.5
|
||||
assert props.context_attributes["TargetView"].enum_value == "NOTDEFINED"
|
||||
assert props.context_attributes["UserDefinedTargetView"].string_value == "UserDefinedTargetView"
|
||||
assert not props.context_attributes["Precision"]
|
||||
|
||||
def test_importing_twice(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -78,15 +79,16 @@ class TestImportAttributes(test.bim.bootstrap.NewFile):
|
||||
subject.import_attributes()
|
||||
context.ContextIdentifier = "ContextIdentifier2"
|
||||
subject.import_attributes()
|
||||
props = bpy.context.scene.BIMContextProperties
|
||||
assert props.context_attributes.get("ContextIdentifier").string_value == "ContextIdentifier2"
|
||||
props = subject.get_context_props()
|
||||
assert props.context_attributes["ContextIdentifier"].string_value == "ContextIdentifier2"
|
||||
|
||||
|
||||
class TestClearContext(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
TestSetContext().test_run()
|
||||
subject.clear_context()
|
||||
assert bpy.context.scene.BIMContextProperties.active_context_id == 0
|
||||
props = subject.get_context_props()
|
||||
assert props.active_context_id == 0
|
||||
|
||||
|
||||
class TestGetContext(test.bim.bootstrap.NewFile):
|
||||
|
||||
@@ -21,6 +21,7 @@ from pathlib import Path
|
||||
import bpy
|
||||
import mathutils
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.guid
|
||||
import ifcopenshell.util.element
|
||||
import bonsai.core.tool
|
||||
@@ -68,7 +69,7 @@ class TestCreateCamera(NewFile):
|
||||
class TestCreateSvgSheet(NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
|
||||
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
|
||||
tool.Ifc.set(ifc)
|
||||
ifc_path = Path("test/files/temp/test.ifc").absolute()
|
||||
bpy.ops.bim.save_project(filepath=str(ifc_path), should_save_as=True)
|
||||
@@ -92,6 +93,7 @@ class TestDeleteCollection(NewFile):
|
||||
|
||||
class TestDeleteDrawingElements(NewFile):
|
||||
def test_run(self):
|
||||
assert bpy.context.scene
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
|
||||
@@ -155,13 +157,15 @@ class TestDisableEditingText(NewFile):
|
||||
class TestDisableEditingAssignedProduct(NewFile):
|
||||
def test_run(self):
|
||||
obj = bpy.data.objects.new("Object", None)
|
||||
obj.BIMAssignedProductProperties.is_editing_product = True
|
||||
props = subject.get_object_assigned_product_props(obj)
|
||||
props.is_editing_product = True
|
||||
subject.disable_editing_assigned_product(obj)
|
||||
assert obj.BIMAssignedProductProperties.is_editing_product == False
|
||||
assert props.is_editing_product == False
|
||||
|
||||
|
||||
class TestEnableEditing(NewFile):
|
||||
def test_run(self):
|
||||
assert bpy.context.scene
|
||||
obj = bpy.data.objects.new("Object", None)
|
||||
bpy.context.scene.collection.objects.link(obj)
|
||||
subject.enable_editing(obj)
|
||||
@@ -211,8 +215,9 @@ class TestEnableEditingText(NewFile):
|
||||
class TestEnableEditingAssignedProduct(NewFile):
|
||||
def test_run(self):
|
||||
obj = bpy.data.objects.new("Object", None)
|
||||
props = subject.get_object_assigned_product_props(obj)
|
||||
subject.enable_editing_assigned_product(obj)
|
||||
assert obj.BIMAssignedProductProperties.is_editing_product == True
|
||||
assert props.is_editing_product == True
|
||||
|
||||
|
||||
class TestEnsureUniqueDrawingName(NewFile):
|
||||
@@ -314,6 +319,7 @@ class TestGetDocumentUri(NewFile):
|
||||
|
||||
class TestGetDrawingCollection(NewFile):
|
||||
def test_run(self):
|
||||
assert bpy.context.scene
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
obj = bpy.data.objects.new("Object", None)
|
||||
@@ -378,6 +384,7 @@ class TestGenerateDrawingMatrix(NewFile):
|
||||
assert subject.generate_drawing_matrix("PLAN_VIEW", 0) == mathutils.Matrix()
|
||||
|
||||
def test_creating_a_plan_view_at_the_cursor_at_a_storey(self):
|
||||
assert bpy.context.scene
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
obj = bpy.data.objects.new("Object", None)
|
||||
@@ -397,6 +404,7 @@ class TestGenerateDrawingMatrix(NewFile):
|
||||
)
|
||||
|
||||
def test_creating_an_rcp_at_the_cursor_at_a_storey(self):
|
||||
assert bpy.context.scene
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
obj = bpy.data.objects.new("Object", None)
|
||||
@@ -410,48 +418,56 @@ class TestGenerateDrawingMatrix(NewFile):
|
||||
)
|
||||
|
||||
def test_creating_a_north_elevation_at_the_cursor(self):
|
||||
assert bpy.context.scene
|
||||
bpy.context.scene.cursor.location = (1.0, 2.0, 3.0)
|
||||
assert subject.generate_drawing_matrix("ELEVATION_VIEW", "NORTH") == mathutils.Matrix(
|
||||
((-1, 0, 0, 1), (0, 0, 1, 2), (0, 1, 0, 3), (0, 0, 0, 1))
|
||||
)
|
||||
|
||||
def test_creating_a_south_elevation_at_the_cursor(self):
|
||||
assert bpy.context.scene
|
||||
bpy.context.scene.cursor.location = (1.0, 2.0, 3.0)
|
||||
assert subject.generate_drawing_matrix("ELEVATION_VIEW", "SOUTH") == mathutils.Matrix(
|
||||
((1, 0, 0, 1), (0, 0, -1, 2), (0, 1, 0, 3), (0, 0, 0, 1))
|
||||
)
|
||||
|
||||
def test_creating_an_east_elevation_at_the_cursor(self):
|
||||
assert bpy.context.scene
|
||||
bpy.context.scene.cursor.location = (1.0, 2.0, 3.0)
|
||||
assert subject.generate_drawing_matrix("ELEVATION_VIEW", "EAST") == mathutils.Matrix(
|
||||
((0, 0, 1, 1), (1, 0, 0, 2), (0, 1, 0, 3), (0, 0, 0, 1))
|
||||
)
|
||||
|
||||
def test_creating_a_west_elevation_at_the_cursor(self):
|
||||
assert bpy.context.scene
|
||||
bpy.context.scene.cursor.location = (1.0, 2.0, 3.0)
|
||||
assert subject.generate_drawing_matrix("ELEVATION_VIEW", "WEST") == mathutils.Matrix(
|
||||
((0, 0, -1, 1), (-1, 0, 0, 2), (0, 1, 0, 3), (0, 0, 0, 1))
|
||||
)
|
||||
|
||||
def test_creating_a_north_section_at_the_cursor(self):
|
||||
assert bpy.context.scene
|
||||
bpy.context.scene.cursor.location = (1.0, 2.0, 3.0)
|
||||
assert subject.generate_drawing_matrix("SECTION_VIEW", "NORTH") == mathutils.Matrix(
|
||||
((1, 0, 0, 1), (0, 0, -1, 2), (0, 1, 0, 3), (0, 0, 0, 1))
|
||||
)
|
||||
|
||||
def test_creating_a_south_section_at_the_cursor(self):
|
||||
assert bpy.context.scene
|
||||
bpy.context.scene.cursor.location = (1.0, 2.0, 3.0)
|
||||
assert subject.generate_drawing_matrix("SECTION_VIEW", "SOUTH") == mathutils.Matrix(
|
||||
((-1, 0, 0, 1), (0, 0, 1, 2), (0, 1, 0, 3), (0, 0, 0, 1))
|
||||
)
|
||||
|
||||
def test_creating_an_east_section_at_the_cursor(self):
|
||||
assert bpy.context.scene
|
||||
bpy.context.scene.cursor.location = (1.0, 2.0, 3.0)
|
||||
assert subject.generate_drawing_matrix("SECTION_VIEW", "EAST") == mathutils.Matrix(
|
||||
((0, 0, -1, 1), (-1, 0, 0, 2), (0, 1, 0, 3), (0, 0, 0, 1))
|
||||
)
|
||||
|
||||
def test_creating_a_west_section_at_the_cursor(self):
|
||||
assert bpy.context.scene
|
||||
bpy.context.scene.cursor.location = (1.0, 2.0, 3.0)
|
||||
assert subject.generate_drawing_matrix("SECTION_VIEW", "WEST") == mathutils.Matrix(
|
||||
((0, 0, 1, 1), (1, 0, 0, 2), (0, 1, 0, 3), (0, 0, 0, 1))
|
||||
@@ -598,9 +614,9 @@ class TestImportTextAttributes(NewFile):
|
||||
subject.import_text_attributes(obj)
|
||||
props = tool.Drawing.get_text_props(obj)
|
||||
literal_props = props.literals[0]
|
||||
assert literal_props.attributes.get("Literal").string_value == "Literal"
|
||||
assert literal_props.attributes.get("Path").enum_value == "RIGHT"
|
||||
assert literal_props.attributes.get("BoxAlignment").string_value == "bottom-left"
|
||||
assert literal_props.attributes["Literal"].string_value == "Literal"
|
||||
assert literal_props.attributes["Path"].enum_value == "RIGHT"
|
||||
assert literal_props.attributes["BoxAlignment"].string_value == "bottom-left"
|
||||
|
||||
|
||||
class TestImportAssignedProduct(NewFile):
|
||||
@@ -615,7 +631,8 @@ class TestImportAssignedProduct(NewFile):
|
||||
tool.Ifc.link(wall, wall_obj)
|
||||
tool.Ifc.link(label, label_obj)
|
||||
subject.import_assigned_product(label_obj)
|
||||
assert label_obj.BIMAssignedProductProperties.relating_product == wall_obj
|
||||
props = subject.get_object_assigned_product_props(label_obj)
|
||||
assert props.relating_product == wall_obj
|
||||
|
||||
def test_doing_nothing_if_no_product_to_import(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -624,7 +641,8 @@ class TestImportAssignedProduct(NewFile):
|
||||
label_obj = bpy.data.objects.new("Object", None)
|
||||
tool.Ifc.link(label, label_obj)
|
||||
subject.import_assigned_product(label_obj)
|
||||
assert label_obj.BIMAssignedProductProperties.relating_product is None
|
||||
props = subject.get_object_assigned_product_props(label_obj)
|
||||
assert props.relating_product is None
|
||||
|
||||
|
||||
class TestOpenSchedule(NewFile):
|
||||
|
||||
@@ -59,13 +59,13 @@ class TestImportProjectedCRS(NewFile):
|
||||
projected_crs.MapUnit = unit
|
||||
subject.import_projected_crs()
|
||||
props = tool.Georeference.get_georeference_props()
|
||||
assert props.projected_crs.get("Name").string_value == "Name"
|
||||
assert props.projected_crs.get("Description").string_value == "Description"
|
||||
assert props.projected_crs.get("GeodeticDatum").string_value == "GeodeticDatum"
|
||||
assert props.projected_crs.get("VerticalDatum").string_value == "VerticalDatum"
|
||||
assert props.projected_crs.get("MapProjection").string_value == "MapProjection"
|
||||
assert props.projected_crs.get("MapZone").string_value == "MapZone"
|
||||
assert props.projected_crs.get("MapUnit").enum_value == str(unit.id())
|
||||
assert props.projected_crs["Name"].string_value == "Name"
|
||||
assert props.projected_crs["Description"].string_value == "Description"
|
||||
assert props.projected_crs["GeodeticDatum"].string_value == "GeodeticDatum"
|
||||
assert props.projected_crs["VerticalDatum"].string_value == "VerticalDatum"
|
||||
assert props.projected_crs["MapProjection"].string_value == "MapProjection"
|
||||
assert props.projected_crs["MapZone"].string_value == "MapZone"
|
||||
assert props.projected_crs["MapUnit"].enum_value == str(unit.id())
|
||||
|
||||
def test_run_ifc2x3(self):
|
||||
ifc = ifcopenshell.file(schema="IFC2X3")
|
||||
@@ -100,13 +100,13 @@ class TestImportCoordinateOperation(NewFile):
|
||||
map_conversion.Scale = 6
|
||||
subject.import_coordinate_operation()
|
||||
props = tool.Georeference.get_georeference_props()
|
||||
assert props.coordinate_operation.get("Eastings").string_value == "1.0"
|
||||
assert props.coordinate_operation.get("Northings").string_value == "2.0"
|
||||
assert props.coordinate_operation.get("OrthogonalHeight").string_value == "3.0"
|
||||
assert props.coordinate_operation["Eastings"].string_value == "1.0"
|
||||
assert props.coordinate_operation["Northings"].string_value == "2.0"
|
||||
assert props.coordinate_operation["OrthogonalHeight"].string_value == "3.0"
|
||||
assert props.x_axis_abscissa == "4.0"
|
||||
assert props.x_axis_ordinate == "5.0"
|
||||
assert props.grid_north_angle == "-51.3401917"
|
||||
assert props.coordinate_operation.get("Scale").string_value == "6.0"
|
||||
assert props.coordinate_operation["Scale"].string_value == "6.0"
|
||||
|
||||
def test_run_ifc2x3(self):
|
||||
ifc = ifcopenshell.file(schema="IFC2X3")
|
||||
@@ -220,6 +220,7 @@ class TestGetCursorLocation(NewFile):
|
||||
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
|
||||
unit = ifcopenshell.api.run("unit.add_si_unit", ifc, unit_type="LENGTHUNIT", prefix="MILLI")
|
||||
ifcopenshell.api.run("unit.assign_unit", ifc, units=[unit])
|
||||
assert bpy.context.scene
|
||||
bpy.context.scene.cursor.location = (1.0, 2.0, 3.0)
|
||||
assert subject.get_cursor_location() == [1000.0, 2000.0, 3000.0]
|
||||
|
||||
@@ -229,7 +230,7 @@ class TestXyz2Enh(NewFile):
|
||||
ifc = ifcopenshell.file()
|
||||
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
|
||||
tool.Ifc.set(ifc)
|
||||
assert subject.xyz2enh([0.0, 0.0, 0.0]) == (0.0, 0.0, 0.0)
|
||||
assert subject.xyz2enh((0.0, 0.0, 0.0)) == (0.0, 0.0, 0.0)
|
||||
|
||||
def test_using_the_blender_offset(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -238,7 +239,7 @@ class TestXyz2Enh(NewFile):
|
||||
props = tool.Georeference.get_georeference_props()
|
||||
props.has_blender_offset = True
|
||||
props.blender_offset_x = "1.0"
|
||||
assert subject.xyz2enh([0.0, 0.0, 0.0]) == (1.0, 0.0, 0.0)
|
||||
assert subject.xyz2enh((0.0, 0.0, 0.0)) == (1.0, 0.0, 0.0)
|
||||
|
||||
def test_using_the_map_conversion(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -248,7 +249,7 @@ class TestXyz2Enh(NewFile):
|
||||
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
|
||||
map_conversion = ifc.by_type("IfcMapConversion")[0]
|
||||
map_conversion.Eastings = 1.0
|
||||
assert subject.xyz2enh([0.0, 0.0, 0.0]) == (1.0, 0.0, 0.0)
|
||||
assert subject.xyz2enh((0.0, 0.0, 0.0)) == (1.0, 0.0, 0.0)
|
||||
|
||||
def test_applying_both_blender_offset_and_map_conversion(self):
|
||||
props = tool.Georeference.get_georeference_props()
|
||||
@@ -261,7 +262,7 @@ class TestXyz2Enh(NewFile):
|
||||
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
|
||||
map_conversion = ifc.by_type("IfcMapConversion")[0]
|
||||
map_conversion.Northings = 1.0
|
||||
assert subject.xyz2enh([0.0, 0.0, 0.0]) == (1.0, 1.0, 0.0)
|
||||
assert subject.xyz2enh((0.0, 0.0, 0.0)) == (1.0, 1.0, 0.0)
|
||||
|
||||
|
||||
class TestEnh2Xyz(NewFile):
|
||||
@@ -269,7 +270,7 @@ class TestEnh2Xyz(NewFile):
|
||||
ifc = ifcopenshell.file()
|
||||
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
|
||||
tool.Ifc.set(ifc)
|
||||
assert subject.enh2xyz([0.0, 0.0, 0.0]) == (0.0, 0.0, 0.0)
|
||||
assert subject.enh2xyz((0.0, 0.0, 0.0)) == (0.0, 0.0, 0.0)
|
||||
|
||||
def test_using_the_blender_offset(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -278,7 +279,7 @@ class TestEnh2Xyz(NewFile):
|
||||
props = tool.Georeference.get_georeference_props()
|
||||
props.has_blender_offset = True
|
||||
props.blender_offset_x = "1.0"
|
||||
assert subject.enh2xyz([0.0, 0.0, 0.0]) == (-1.0, 0.0, 0.0)
|
||||
assert subject.enh2xyz((0.0, 0.0, 0.0)) == (-1.0, 0.0, 0.0)
|
||||
|
||||
def test_using_the_map_conversion(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -288,7 +289,7 @@ class TestEnh2Xyz(NewFile):
|
||||
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
|
||||
map_conversion = ifc.by_type("IfcMapConversion")[0]
|
||||
map_conversion.Eastings = 1.0
|
||||
assert subject.enh2xyz([0.0, 0.0, 0.0]) == (-1.0, 0.0, 0.0)
|
||||
assert subject.enh2xyz((0.0, 0.0, 0.0)) == (-1.0, 0.0, 0.0)
|
||||
|
||||
def test_applying_both_blender_offset_and_map_conversion(self):
|
||||
props = tool.Georeference.get_georeference_props()
|
||||
@@ -301,4 +302,4 @@ class TestEnh2Xyz(NewFile):
|
||||
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
|
||||
map_conversion = ifc.by_type("IfcMapConversion")[0]
|
||||
map_conversion.Northings = 1.0
|
||||
assert subject.enh2xyz([0.0, 0.0, 0.0]) == (-1.0, -1.0, 0.0)
|
||||
assert subject.enh2xyz((0.0, 0.0, 0.0)) == (-1.0, -1.0, 0.0)
|
||||
|
||||
@@ -79,11 +79,11 @@ class TestImportLibraryAttributes(NewFile):
|
||||
library = ifc.createIfcLibraryInformation("Name", "Version", None, "VersionDate", "Location", "Description")
|
||||
subject.import_library_attributes(library)
|
||||
props = tool.Library.get_library_props()
|
||||
assert props.library_attributes.get("Name").string_value == "Name"
|
||||
assert props.library_attributes.get("Version").string_value == "Version"
|
||||
assert props.library_attributes.get("VersionDate").string_value == "VersionDate"
|
||||
assert props.library_attributes.get("Location").string_value == "Location"
|
||||
assert props.library_attributes.get("Description").string_value == "Description"
|
||||
assert props.library_attributes["Name"].string_value == "Name"
|
||||
assert props.library_attributes["Version"].string_value == "Version"
|
||||
assert props.library_attributes["VersionDate"].string_value == "VersionDate"
|
||||
assert props.library_attributes["Location"].string_value == "Location"
|
||||
assert props.library_attributes["Description"].string_value == "Description"
|
||||
|
||||
|
||||
class TestImportReferenceAttributes(NewFile):
|
||||
@@ -92,11 +92,11 @@ class TestImportReferenceAttributes(NewFile):
|
||||
reference = ifc.createIfcLibraryReference("Location", "Identification", "Name", "Description", "Language")
|
||||
subject.import_reference_attributes(reference)
|
||||
props = tool.Library.get_library_props()
|
||||
assert props.reference_attributes.get("Location").string_value == "Location"
|
||||
assert props.reference_attributes.get("Identification").string_value == "Identification"
|
||||
assert props.reference_attributes.get("Name").string_value == "Name"
|
||||
assert props.reference_attributes.get("Description").string_value == "Description"
|
||||
assert props.reference_attributes.get("Language").string_value == "Language"
|
||||
assert props.reference_attributes["Location"].string_value == "Location"
|
||||
assert props.reference_attributes["Identification"].string_value == "Identification"
|
||||
assert props.reference_attributes["Name"].string_value == "Name"
|
||||
assert props.reference_attributes["Description"].string_value == "Description"
|
||||
assert props.reference_attributes["Language"].string_value == "Language"
|
||||
|
||||
|
||||
class TestImportReferences(NewFile):
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.material
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.style
|
||||
import ifcopenshell.api.type
|
||||
import ifcopenshell.util.element
|
||||
import ifcopenshell.util.representation
|
||||
import ifcopenshell.util.unit
|
||||
|
||||
@@ -36,7 +36,7 @@ class TestAddAddressAttribute(NewFile):
|
||||
subject().add_address_attribute("FacsimileNumbers")
|
||||
subject().add_address_attribute("ElectronicMailAddresses")
|
||||
subject().add_address_attribute("MessagingIDs")
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
props = subject.get_owner_props()
|
||||
assert len(props.address_lines) == 1
|
||||
assert len(props.telephone_numbers) == 1
|
||||
assert len(props.facsimile_numbers) == 1
|
||||
@@ -49,7 +49,7 @@ class TestAddPersonAttribute(NewFile):
|
||||
subject().add_person_attribute("MiddleNames")
|
||||
subject().add_person_attribute("PrefixTitles")
|
||||
subject().add_person_attribute("SuffixTitles")
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
props = subject.get_owner_props()
|
||||
assert len(props.middle_names) == 1
|
||||
assert len(props.prefix_titles) == 1
|
||||
assert len(props.suffix_titles) == 1
|
||||
@@ -61,7 +61,8 @@ class TestClearActor(NewFile):
|
||||
actor = ifc.createIfcActor()
|
||||
subject().set_actor(actor)
|
||||
subject().clear_actor()
|
||||
assert bpy.context.scene.BIMOwnerProperties.active_actor_id == 0
|
||||
props = subject.get_owner_props()
|
||||
assert props.active_actor_id == 0
|
||||
|
||||
|
||||
class TestClearAddress(NewFile):
|
||||
@@ -70,12 +71,13 @@ class TestClearAddress(NewFile):
|
||||
address = ifc.createIfcPostalAddress()
|
||||
subject().set_address(address)
|
||||
subject().clear_address()
|
||||
assert bpy.context.scene.BIMOwnerProperties.active_address_id == 0
|
||||
props = subject.get_owner_props()
|
||||
assert props.active_address_id == 0
|
||||
|
||||
|
||||
class TestClearOrganisation(NewFile):
|
||||
def test_run(self):
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
props = subject.get_owner_props()
|
||||
props.active_organisation_id = 1
|
||||
subject().clear_organisation()
|
||||
assert props.active_organisation_id == 0
|
||||
@@ -83,7 +85,7 @@ class TestClearOrganisation(NewFile):
|
||||
|
||||
class TestClearPerson(NewFile):
|
||||
def test_run(self):
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
props = subject.get_owner_props()
|
||||
props.active_person_id = 1
|
||||
subject().clear_person()
|
||||
assert props.active_person_id == 0
|
||||
@@ -94,14 +96,16 @@ class TestClearRole(NewFile):
|
||||
role = ifcopenshell.file().createIfcActorRole()
|
||||
subject().set_role(role)
|
||||
subject().clear_role()
|
||||
assert bpy.context.scene.BIMOwnerProperties.active_role_id == 0
|
||||
props = subject.get_owner_props()
|
||||
assert props.active_role_id == 0
|
||||
|
||||
|
||||
class TestClearUser(NewFile):
|
||||
def test_run(self):
|
||||
TestSetUser().test_run()
|
||||
subject.clear_user()
|
||||
assert bpy.context.scene.BIMOwnerProperties.active_user_id == 0
|
||||
props = subject.get_owner_props()
|
||||
assert props.active_user_id == 0
|
||||
|
||||
|
||||
class TestExportActorAttributes(NewFile):
|
||||
@@ -288,11 +292,11 @@ class TestImportActorAttributes(NewFile):
|
||||
actor.ObjectType = "ObjectType"
|
||||
subject.set_actor(actor)
|
||||
subject.import_actor_attributes(actor)
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.actor_attributes.get("GlobalId").string_value == "GlobalId"
|
||||
assert props.actor_attributes.get("Name").string_value == "Name"
|
||||
assert props.actor_attributes.get("Description").string_value == "Description"
|
||||
assert props.actor_attributes.get("ObjectType").string_value == "ObjectType"
|
||||
props = subject.get_owner_props()
|
||||
assert props.actor_attributes["GlobalId"].string_value == "GlobalId"
|
||||
assert props.actor_attributes["Name"].string_value == "Name"
|
||||
assert props.actor_attributes["Description"].string_value == "Description"
|
||||
assert props.actor_attributes["ObjectType"].string_value == "ObjectType"
|
||||
|
||||
def test_importing_an_occupant(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -305,12 +309,12 @@ class TestImportActorAttributes(NewFile):
|
||||
actor.PredefinedType = "TENANT"
|
||||
subject.set_actor(actor)
|
||||
subject.import_actor_attributes(actor)
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.actor_attributes.get("GlobalId").string_value == "GlobalId"
|
||||
assert props.actor_attributes.get("Name").string_value == "Name"
|
||||
assert props.actor_attributes.get("Description").string_value == "Description"
|
||||
assert props.actor_attributes.get("ObjectType").string_value == "ObjectType"
|
||||
assert props.actor_attributes.get("PredefinedType").enum_value == "TENANT"
|
||||
props = subject.get_owner_props()
|
||||
assert props.actor_attributes["GlobalId"].string_value == "GlobalId"
|
||||
assert props.actor_attributes["Name"].string_value == "Name"
|
||||
assert props.actor_attributes["Description"].string_value == "Description"
|
||||
assert props.actor_attributes["ObjectType"].string_value == "ObjectType"
|
||||
assert props.actor_attributes["PredefinedType"].enum_value == "TENANT"
|
||||
|
||||
|
||||
class TestImportAddressAttributes(NewFile):
|
||||
@@ -330,16 +334,16 @@ class TestImportAddressAttributes(NewFile):
|
||||
address.Country = "Country"
|
||||
subject().set_address(address)
|
||||
subject().import_address_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.address_attributes.get("Purpose").enum_value == "USERDEFINED"
|
||||
assert props.address_attributes.get("Description").string_value == "Description"
|
||||
assert props.address_attributes.get("UserDefinedPurpose").string_value == "UserDefinedPurpose"
|
||||
assert props.address_attributes.get("InternalLocation").string_value == "InternalLocation"
|
||||
assert props.address_attributes.get("PostalBox").string_value == "PostalBox"
|
||||
assert props.address_attributes.get("Town").string_value == "Town"
|
||||
assert props.address_attributes.get("Region").string_value == "Region"
|
||||
assert props.address_attributes.get("PostalCode").string_value == "PostalCode"
|
||||
assert props.address_attributes.get("Country").string_value == "Country"
|
||||
props = subject.get_owner_props()
|
||||
assert props.address_attributes["Purpose"].enum_value == "USERDEFINED"
|
||||
assert props.address_attributes["Description"].string_value == "Description"
|
||||
assert props.address_attributes["UserDefinedPurpose"].string_value == "UserDefinedPurpose"
|
||||
assert props.address_attributes["InternalLocation"].string_value == "InternalLocation"
|
||||
assert props.address_attributes["PostalBox"].string_value == "PostalBox"
|
||||
assert props.address_attributes["Town"].string_value == "Town"
|
||||
assert props.address_attributes["Region"].string_value == "Region"
|
||||
assert props.address_attributes["PostalCode"].string_value == "PostalCode"
|
||||
assert props.address_attributes["Country"].string_value == "Country"
|
||||
assert len(props.address_lines) == 2
|
||||
assert props.address_lines[0].name == "Address"
|
||||
assert props.address_lines[1].name == "Lines"
|
||||
@@ -351,8 +355,8 @@ class TestImportAddressAttributes(NewFile):
|
||||
address.Purpose = "OFFICE"
|
||||
subject().set_address(address)
|
||||
subject().import_address_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.address_attributes.get("Purpose").enum_value == "OFFICE"
|
||||
props = subject.get_owner_props()
|
||||
assert props.address_attributes["Purpose"].enum_value == "OFFICE"
|
||||
assert len(props.address_lines) == 0
|
||||
|
||||
def test_importing_a_telecom_address(self):
|
||||
@@ -370,10 +374,10 @@ class TestImportAddressAttributes(NewFile):
|
||||
address.MessagingIDs = ["Messaging", "IDs"]
|
||||
subject().set_address(address)
|
||||
subject().import_address_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.address_attributes.get("Purpose").enum_value == "USERDEFINED"
|
||||
assert props.address_attributes.get("Description").string_value == "Description"
|
||||
assert props.address_attributes.get("UserDefinedPurpose").string_value == "UserDefinedPurpose"
|
||||
props = subject.get_owner_props()
|
||||
assert props.address_attributes["Purpose"].enum_value == "USERDEFINED"
|
||||
assert props.address_attributes["Description"].string_value == "Description"
|
||||
assert props.address_attributes["UserDefinedPurpose"].string_value == "UserDefinedPurpose"
|
||||
assert [a.name for a in props.telephone_numbers] == ["Telephone", "Numbers"]
|
||||
assert [a.name for a in props.facsimile_numbers] == ["Facsimile", "Numbers"]
|
||||
assert [a.name for a in props.electronic_mail_addresses] == ["Electronic", "Mail", "Addresses"]
|
||||
@@ -386,8 +390,8 @@ class TestImportAddressAttributes(NewFile):
|
||||
address.Purpose = "OFFICE"
|
||||
subject().set_address(address)
|
||||
subject().import_address_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.address_attributes.get("Purpose").enum_value == "OFFICE"
|
||||
props = subject.get_owner_props()
|
||||
assert props.address_attributes["Purpose"].enum_value == "OFFICE"
|
||||
assert len(props.telephone_numbers) == 0
|
||||
assert len(props.facsimile_numbers) == 0
|
||||
assert len(props.electronic_mail_addresses) == 0
|
||||
@@ -404,10 +408,10 @@ class TestImportOrganisationAttributes(NewFile):
|
||||
organisation.Description = "Description"
|
||||
subject().set_organisation(organisation)
|
||||
subject().import_organisation_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.organisation_attributes.get("Identification").string_value == "Identification"
|
||||
assert props.organisation_attributes.get("Name").string_value == "Name"
|
||||
assert props.organisation_attributes.get("Description").string_value == "Description"
|
||||
props = subject.get_owner_props()
|
||||
assert props.organisation_attributes["Identification"].string_value == "Identification"
|
||||
assert props.organisation_attributes["Name"].string_value == "Name"
|
||||
assert props.organisation_attributes["Description"].string_value == "Description"
|
||||
|
||||
def test_overwriting_a_previous_import(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -420,9 +424,9 @@ class TestImportOrganisationAttributes(NewFile):
|
||||
organisation.Identification = "Identification2"
|
||||
organisation.Description = None
|
||||
subject().import_organisation_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.organisation_attributes.get("Identification").string_value == "Identification2"
|
||||
assert props.organisation_attributes.get("Description").string_value == ""
|
||||
props = subject.get_owner_props()
|
||||
assert props.organisation_attributes["Identification"].string_value == "Identification2"
|
||||
assert props.organisation_attributes["Description"].string_value == ""
|
||||
|
||||
|
||||
class TestImportPersonAttributes(NewFile):
|
||||
@@ -438,10 +442,10 @@ class TestImportPersonAttributes(NewFile):
|
||||
person.SuffixTitles = ("suffix", "titles")
|
||||
subject().set_person(person)
|
||||
subject().import_person_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.person_attributes.get("Identification").string_value == "identification"
|
||||
assert props.person_attributes.get("GivenName").string_value == "given_name"
|
||||
assert props.person_attributes.get("FamilyName").string_value == "family_name"
|
||||
props = subject.get_owner_props()
|
||||
assert props.person_attributes["Identification"].string_value == "identification"
|
||||
assert props.person_attributes["GivenName"].string_value == "given_name"
|
||||
assert props.person_attributes["FamilyName"].string_value == "family_name"
|
||||
assert len(props.middle_names) == 2
|
||||
assert props.middle_names[0].name == "middle"
|
||||
assert props.middle_names[1].name == "names"
|
||||
@@ -463,9 +467,9 @@ class TestImportPersonAttributes(NewFile):
|
||||
person.Identification = "identification2"
|
||||
person.GivenName = None
|
||||
subject().import_person_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.person_attributes.get("Identification").string_value == "identification2"
|
||||
assert props.person_attributes.get("GivenName").string_value == ""
|
||||
props = subject.get_owner_props()
|
||||
assert props.person_attributes["Identification"].string_value == "identification2"
|
||||
assert props.person_attributes["GivenName"].string_value == ""
|
||||
|
||||
|
||||
class TestImportRoleAttributes(NewFile):
|
||||
@@ -478,10 +482,10 @@ class TestImportRoleAttributes(NewFile):
|
||||
role.Description = "Description"
|
||||
subject().set_role(role)
|
||||
subject().import_role_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.role_attributes.get("Role").enum_value == "USERDEFINED"
|
||||
assert props.role_attributes.get("UserDefinedRole").string_value == "UserDefinedRole"
|
||||
assert props.role_attributes.get("Description").string_value == "Description"
|
||||
props = subject.get_owner_props()
|
||||
assert props.role_attributes["Role"].enum_value == "USERDEFINED"
|
||||
assert props.role_attributes["UserDefinedRole"].string_value == "UserDefinedRole"
|
||||
assert props.role_attributes["Description"].string_value == "Description"
|
||||
|
||||
def test_importing_twice(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -492,8 +496,8 @@ class TestImportRoleAttributes(NewFile):
|
||||
subject().import_role_attributes()
|
||||
role.Role = "ARCHITECT"
|
||||
subject().import_role_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.role_attributes.get("Role").enum_value == "ARCHITECT"
|
||||
props = subject.get_owner_props()
|
||||
assert props.role_attributes["Role"].enum_value == "ARCHITECT"
|
||||
|
||||
|
||||
class TestRemoveAddressAttribute(NewFile):
|
||||
@@ -503,7 +507,7 @@ class TestRemoveAddressAttribute(NewFile):
|
||||
subject().remove_address_attribute("FacsimileNumbers", 0)
|
||||
subject().remove_address_attribute("ElectronicMailAddresses", 0)
|
||||
subject().remove_address_attribute("MessagingIDs", 0)
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
props = subject.get_owner_props()
|
||||
assert len(props.address_lines) == 0
|
||||
assert len(props.telephone_numbers) == 0
|
||||
assert len(props.facsimile_numbers) == 0
|
||||
@@ -519,7 +523,7 @@ class TestRemovePersonAttribute(NewFile):
|
||||
subject().remove_person_attribute("PrefixTitles", 0)
|
||||
subject().add_person_attribute("SuffixTitles")
|
||||
subject().remove_person_attribute("SuffixTitles", 0)
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
props = subject.get_owner_props()
|
||||
assert len(props.middle_names) == 0
|
||||
assert len(props.prefix_titles) == 0
|
||||
assert len(props.suffix_titles) == 0
|
||||
@@ -530,7 +534,8 @@ class TestSetActor(NewFile):
|
||||
ifc = ifcopenshell.file()
|
||||
actor = ifc.createIfcActor()
|
||||
subject().set_actor(actor)
|
||||
assert bpy.context.scene.BIMOwnerProperties.active_actor_id == actor.id()
|
||||
props = subject.get_owner_props()
|
||||
assert props.active_actor_id == actor.id()
|
||||
|
||||
|
||||
class TestSetAddress(NewFile):
|
||||
@@ -538,28 +543,32 @@ class TestSetAddress(NewFile):
|
||||
ifc = ifcopenshell.file()
|
||||
address = ifc.createIfcPostalAddress()
|
||||
subject().set_address(address)
|
||||
assert bpy.context.scene.BIMOwnerProperties.active_address_id == address.id()
|
||||
props = subject.get_owner_props()
|
||||
assert props.active_address_id == address.id()
|
||||
|
||||
|
||||
class TestSetOrganisation(NewFile):
|
||||
def test_run(self):
|
||||
organisation = ifcopenshell.file().createIfcOrganization()
|
||||
subject().set_organisation(organisation)
|
||||
assert bpy.context.scene.BIMOwnerProperties.active_organisation_id == organisation.id()
|
||||
props = subject.get_owner_props()
|
||||
assert props.active_organisation_id == organisation.id()
|
||||
|
||||
|
||||
class TestSetPerson(NewFile):
|
||||
def test_run(self):
|
||||
person = ifcopenshell.file().createIfcPerson()
|
||||
subject().set_person(person)
|
||||
assert bpy.context.scene.BIMOwnerProperties.active_person_id == person.id()
|
||||
props = subject.get_owner_props()
|
||||
assert props.active_person_id == person.id()
|
||||
|
||||
|
||||
class TestSetRole(NewFile):
|
||||
def test_run(self):
|
||||
role = ifcopenshell.file().createIfcActorRole()
|
||||
subject().set_role(role)
|
||||
assert bpy.context.scene.BIMOwnerProperties.active_role_id == role.id()
|
||||
props = subject.get_owner_props()
|
||||
assert props.active_role_id == role.id()
|
||||
|
||||
|
||||
class TestSetUser(NewFile):
|
||||
@@ -568,4 +577,5 @@ class TestSetUser(NewFile):
|
||||
tool.Ifc.set(ifc)
|
||||
user = ifc.createIfcPersonAndOrganization()
|
||||
subject.set_user(user)
|
||||
assert bpy.context.scene.BIMOwnerProperties.active_user_id == user.id()
|
||||
props = subject.get_owner_props()
|
||||
assert props.active_user_id == user.id()
|
||||
|
||||
@@ -391,8 +391,8 @@ class TestImportSurfaceAttributes(NewFile):
|
||||
props = tool.Style.get_style_props()
|
||||
style = ifc.create_entity("IfcSurfaceStyle", "Name", "BOTH")
|
||||
subject.import_surface_attributes(style)
|
||||
assert props.attributes.get("Name").string_value == "Name"
|
||||
assert props.attributes.get("Side").enum_value == "BOTH"
|
||||
assert props.attributes["Name"].string_value == "Name"
|
||||
assert props.attributes["Side"].enum_value == "BOTH"
|
||||
|
||||
def test_importing_surface_attributes_twice(self):
|
||||
tool.Ifc.set(ifc := ifcopenshell.file())
|
||||
@@ -400,12 +400,12 @@ class TestImportSurfaceAttributes(NewFile):
|
||||
props = tool.Style.get_style_props()
|
||||
subject.import_surface_attributes(style)
|
||||
assert len(props.attributes) == 2
|
||||
assert props.attributes.get("Name").string_value == "Name"
|
||||
assert props.attributes.get("Side").enum_value == "BOTH"
|
||||
assert props.attributes["Name"].string_value == "Name"
|
||||
assert props.attributes["Side"].enum_value == "BOTH"
|
||||
subject.import_surface_attributes(style)
|
||||
assert len(props.attributes) == 2
|
||||
assert props.attributes.get("Name").string_value == "Name"
|
||||
assert props.attributes.get("Side").enum_value == "BOTH"
|
||||
assert props.attributes["Name"].string_value == "Name"
|
||||
assert props.attributes["Side"].enum_value == "BOTH"
|
||||
|
||||
|
||||
class TestImportPresentationStyles(NewFile):
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.util.unit
|
||||
import bonsai.core.tool
|
||||
import bonsai.tool as tool
|
||||
import numpy as np
|
||||
@@ -43,6 +44,7 @@ class TestAddPorts(NewFile):
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
obj.matrix_world = Euler((pi / 2, 0, pi / 2)).to_matrix().to_4x4() @ obj.matrix_world
|
||||
# move origin
|
||||
assert isinstance(obj.data, bpy.types.Mesh)
|
||||
for v in obj.data.vertices:
|
||||
v.co += Vector((0, 0, 2.5))
|
||||
return obj, element
|
||||
@@ -90,6 +92,7 @@ class TestAddPorts(NewFile):
|
||||
|
||||
class TestCreateEmptyAtCursorWithElementOrientation(NewFile):
|
||||
def test_run(self):
|
||||
assert bpy.context.scene
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
obj = bpy.data.objects.new("Object", None)
|
||||
@@ -175,10 +178,10 @@ class TestImportSystemAttributes(NewFile):
|
||||
system.ObjectType = "ObjectType"
|
||||
subject().import_system_attributes(system)
|
||||
props = tool.System.get_system_props()
|
||||
assert props.system_attributes.get("GlobalId").string_value == "GlobalId"
|
||||
assert props.system_attributes.get("Name").string_value == "Name"
|
||||
assert props.system_attributes.get("Description").string_value == "Description"
|
||||
assert props.system_attributes.get("ObjectType").string_value == "ObjectType"
|
||||
assert props.system_attributes["GlobalId"].string_value == "GlobalId"
|
||||
assert props.system_attributes["Name"].string_value == "Name"
|
||||
assert props.system_attributes["Description"].string_value == "Description"
|
||||
assert props.system_attributes["ObjectType"].string_value == "ObjectType"
|
||||
|
||||
def test_importing_a_building_system(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -192,12 +195,12 @@ class TestImportSystemAttributes(NewFile):
|
||||
system.LongName = "LongName"
|
||||
subject().import_system_attributes(system)
|
||||
props = tool.System.get_system_props()
|
||||
assert props.system_attributes.get("GlobalId").string_value == "GlobalId"
|
||||
assert props.system_attributes.get("Name").string_value == "Name"
|
||||
assert props.system_attributes.get("Description").string_value == "Description"
|
||||
assert props.system_attributes.get("ObjectType").string_value == "ObjectType"
|
||||
assert props.system_attributes.get("PredefinedType").enum_value == "SHADING"
|
||||
assert props.system_attributes.get("LongName").string_value == "LongName"
|
||||
assert props.system_attributes["GlobalId"].string_value == "GlobalId"
|
||||
assert props.system_attributes["Name"].string_value == "Name"
|
||||
assert props.system_attributes["Description"].string_value == "Description"
|
||||
assert props.system_attributes["ObjectType"].string_value == "ObjectType"
|
||||
assert props.system_attributes["PredefinedType"].enum_value == "SHADING"
|
||||
assert props.system_attributes["LongName"].string_value == "LongName"
|
||||
|
||||
def test_importing_a_distribution_system(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -211,12 +214,12 @@ class TestImportSystemAttributes(NewFile):
|
||||
system.LongName = "LongName"
|
||||
subject().import_system_attributes(system)
|
||||
props = tool.System.get_system_props()
|
||||
assert props.system_attributes.get("GlobalId").string_value == "GlobalId"
|
||||
assert props.system_attributes.get("Name").string_value == "Name"
|
||||
assert props.system_attributes.get("Description").string_value == "Description"
|
||||
assert props.system_attributes.get("ObjectType").string_value == "ObjectType"
|
||||
assert props.system_attributes.get("PredefinedType").enum_value == "ELECTRICAL"
|
||||
assert props.system_attributes.get("LongName").string_value == "LongName"
|
||||
assert props.system_attributes["GlobalId"].string_value == "GlobalId"
|
||||
assert props.system_attributes["Name"].string_value == "Name"
|
||||
assert props.system_attributes["Description"].string_value == "Description"
|
||||
assert props.system_attributes["ObjectType"].string_value == "ObjectType"
|
||||
assert props.system_attributes["PredefinedType"].enum_value == "ELECTRICAL"
|
||||
assert props.system_attributes["LongName"].string_value == "LongName"
|
||||
|
||||
|
||||
class TestImportSystems(NewFile):
|
||||
@@ -245,7 +248,7 @@ class TestLoadPorts(NewFile):
|
||||
port = ifc.create_entity("IfcDistributionPort")
|
||||
subject.load_ports(element, [port])
|
||||
obj = tool.Ifc.get_object(port)
|
||||
assert obj
|
||||
assert isinstance(obj, bpy.types.Object)
|
||||
assert obj.users_collection
|
||||
assert list(obj.location) == [0, 0, 0]
|
||||
|
||||
@@ -262,6 +265,7 @@ class TestRunRootAssignClass(NewFile):
|
||||
|
||||
class TestSelectSystemProducts(NewFile):
|
||||
def test_run(self):
|
||||
assert bpy.context.scene
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcPump")
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.type
|
||||
import bonsai.core.tool
|
||||
import bonsai.tool as tool
|
||||
from test.bim.bootstrap import NewFile
|
||||
@@ -153,9 +155,9 @@ class TestGetTypeOccurrences(NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
wall_type = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWallType")
|
||||
wall = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("type.assign_type", ifc, related_objects=[wall], relating_type=wall_type)
|
||||
wall_type = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWallType")
|
||||
wall = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
|
||||
ifcopenshell.api.type.assign_type(ifc, related_objects=[wall], relating_type=wall_type)
|
||||
assert subject.get_type_occurrences(wall_type) == (wall,)
|
||||
|
||||
|
||||
|
||||
@@ -104,6 +104,7 @@ class TestExportUnitAttributes(NewFile):
|
||||
|
||||
class TestGetSceneUnitName(NewFile):
|
||||
def test_getting_an_imperial_name(self):
|
||||
assert bpy.context.scene
|
||||
props = tool.Blender.get_bim_props()
|
||||
bpy.context.scene.unit_settings.system = "IMPERIAL"
|
||||
bpy.context.scene.unit_settings.length_unit = "MILES"
|
||||
@@ -130,12 +131,14 @@ class TestGetSceneUnitName(NewFile):
|
||||
assert subject.get_scene_unit_name("VOLUMEUNIT") == "cubic inch"
|
||||
|
||||
def test_getting_a_name_with_no_unit_system(self):
|
||||
assert bpy.context.scene
|
||||
bpy.context.scene.unit_settings.system = "NONE"
|
||||
assert subject.get_scene_unit_name("LENGTHUNIT") == "foot"
|
||||
|
||||
|
||||
class TestGetSceneUnitSIPrefix:
|
||||
def test_run(self):
|
||||
assert bpy.context.scene
|
||||
bpy.context.scene.unit_settings.system = "METRIC"
|
||||
bpy.context.scene.unit_settings.length_unit = "METERS"
|
||||
assert subject.get_scene_unit_si_prefix("LENGTHUNIT") is None
|
||||
@@ -298,6 +301,7 @@ class TestImportUnits(NewFile):
|
||||
|
||||
class TestIsSceneUnitMetric(NewFile):
|
||||
def test_run(self):
|
||||
assert bpy.context.scene
|
||||
props = bpy.context.scene.unit_settings
|
||||
props.system = "METRIC"
|
||||
assert subject.is_scene_unit_metric() is True
|
||||
|
||||
Reference in New Issue
Block a user