This commit is contained in:
Andrej730
2025-02-20 14:50:55 +05:00
parent b19ece18c6
commit 331f491d50
47 changed files with 577 additions and 330 deletions
+2 -3
View File
@@ -122,11 +122,10 @@ class TestAddBrickifcProject(NewFile):
result = subject.add_brickifc_project("http://example.org/digitaltwin#")
assert result == f"http://example.org/digitaltwin#{project.GlobalId}"
brick = URIRef(result)
props = tool.Blender.get_bim_props()
assert list(BrickStore.graph.triples((brick, A, REF.ifcProject)))
assert list(BrickStore.graph.triples((brick, REF.ifcProjectID, Literal(project.GlobalId))))
assert list(
BrickStore.graph.triples((brick, REF.ifcFileLocation, Literal(bpy.context.scene.BIMProperties.ifc_file)))
)
assert list(BrickStore.graph.triples((brick, REF.ifcFileLocation, Literal(props.ifc_file))))
assert list(
BrickStore.graph.triples(
(brick, URIRef("http://www.w3.org/2000/01/rdf-schema#label"), Literal("My Project"))
+2 -1
View File
@@ -55,7 +55,8 @@ class TestLoadExpress(NewFile):
class TestPurgeHdf5Cache(NewFile):
def test_run(self):
cache_dir = Path(bpy.context.scene.BIMProperties.cache_dir)
props = tool.Blender.get_bim_props()
cache_dir = Path(props.cache_dir)
test_file = cache_dir / "test.h5"
test_file.parent.mkdir(parents=True, exist_ok=True)
test_file.touch()
+39 -35
View File
@@ -36,13 +36,13 @@ class TestAddBreadcrumb(NewFile):
tool.Ifc().set(ifc)
document = ifc.createIfcDocumentInformation()
subject.add_breadcrumb(document)
props = bpy.context.scene.BIMDocumentProperties
props = tool.Document.get_document_props()
assert props.breadcrumbs[0].name == str(document.id())
class TestClearBreadcrumbs(NewFile):
def test_run(self):
props = bpy.context.scene.BIMDocumentProperties
props = tool.Document.get_document_props()
props.breadcrumbs.add()
subject.clear_breadcrumbs()
assert len(props.breadcrumbs) == 0
@@ -50,7 +50,7 @@ class TestClearBreadcrumbs(NewFile):
class TestClearDocumentTree(NewFile):
def test_run(self):
props = bpy.context.scene.BIMDocumentProperties
props = tool.Document.get_document_props()
new = props.documents.add()
subject.clear_document_tree()
assert len(props.documents) == 0
@@ -58,23 +58,26 @@ class TestClearDocumentTree(NewFile):
class TestDisableEditingDocument(NewFile):
def test_run(self):
bpy.context.scene.BIMDocumentProperties.active_document_id = 1
props = tool.Document.get_document_props()
props.active_document_id = 1
subject.disable_editing_document()
assert bpy.context.scene.BIMDocumentProperties.active_document_id == 0
assert props.active_document_id == 0
class TestDisableEditingUI(NewFile):
def test_run(self):
bpy.context.scene.BIMDocumentProperties.is_editing = True
props = tool.Document.get_document_props()
props.is_editing = True
subject.disable_editing_ui()
assert bpy.context.scene.BIMDocumentProperties.is_editing == False
assert props.is_editing == False
class TestEnableEditingUI(NewFile):
def test_run(self):
bpy.context.scene.BIMDocumentProperties.is_editing = False
props = tool.Document.get_document_props()
props.is_editing = False
subject.enable_editing_ui()
assert bpy.context.scene.BIMDocumentProperties.is_editing == True
assert props.is_editing == True
class TestExportDocumentAttributes(NewFile):
@@ -129,22 +132,22 @@ class TestImportDocumentAttributes(NewFile):
document.Confidentiality = "CONFIDENTIAL"
document.Status = "DRAFT"
subject().import_document_attributes(document)
props = bpy.context.scene.BIMDocumentProperties
assert props.document_attributes.get("Identification").string_value == "Identification"
assert props.document_attributes.get("Name").string_value == "Name"
assert props.document_attributes.get("Description").string_value == "Description"
assert props.document_attributes.get("Location").string_value == "Location"
assert props.document_attributes.get("Purpose").string_value == "Purpose"
assert props.document_attributes.get("IntendedUse").string_value == "IntendedUse"
assert props.document_attributes.get("Scope").string_value == "Scope"
assert props.document_attributes.get("Revision").string_value == "Revision"
assert props.document_attributes.get("CreationTime").string_value == "CreationTime"
assert props.document_attributes.get("LastRevisionTime").string_value == "LastRevisionTime"
assert props.document_attributes.get("ElectronicFormat").string_value == "ElectronicFormat"
assert props.document_attributes.get("ValidFrom").string_value == "ValidFrom"
assert props.document_attributes.get("ValidUntil").string_value == "ValidUntil"
assert props.document_attributes.get("Confidentiality").enum_value == "CONFIDENTIAL"
assert props.document_attributes.get("Status").enum_value == "DRAFT"
props = tool.Document.get_document_props()
assert props.document_attributes["Identification"].string_value == "Identification"
assert props.document_attributes["Name"].string_value == "Name"
assert props.document_attributes["Description"].string_value == "Description"
assert props.document_attributes["Location"].string_value == "Location"
assert props.document_attributes["Purpose"].string_value == "Purpose"
assert props.document_attributes["IntendedUse"].string_value == "IntendedUse"
assert props.document_attributes["Scope"].string_value == "Scope"
assert props.document_attributes["Revision"].string_value == "Revision"
assert props.document_attributes["CreationTime"].string_value == "CreationTime"
assert props.document_attributes["LastRevisionTime"].string_value == "LastRevisionTime"
assert props.document_attributes["ElectronicFormat"].string_value == "ElectronicFormat"
assert props.document_attributes["ValidFrom"].string_value == "ValidFrom"
assert props.document_attributes["ValidUntil"].string_value == "ValidUntil"
assert props.document_attributes["Confidentiality"].enum_value == "CONFIDENTIAL"
assert props.document_attributes["Status"].enum_value == "DRAFT"
def test_importing_reference(self):
ifc = ifcopenshell.file()
@@ -155,11 +158,11 @@ class TestImportDocumentAttributes(NewFile):
document.Name = "Name"
document.Description = "Description"
subject().import_document_attributes(document)
props = bpy.context.scene.BIMDocumentProperties
assert props.document_attributes.get("Location").string_value == "Location"
assert props.document_attributes.get("Identification").string_value == "Identification"
assert props.document_attributes.get("Name").string_value == "Name"
assert props.document_attributes.get("Description").string_value == "Description"
props = tool.Document.get_document_props()
assert props.document_attributes["Location"].string_value == "Location"
assert props.document_attributes["Identification"].string_value == "Identification"
assert props.document_attributes["Name"].string_value == "Name"
assert props.document_attributes["Description"].string_value == "Description"
class TestImportProjectDocuments(NewFile):
@@ -169,7 +172,7 @@ class TestImportProjectDocuments(NewFile):
ifc.createIfcProject()
document = ifcopenshell.api.run("document.add_information", ifc)
subject.import_project_documents()
props = bpy.context.scene.BIMDocumentProperties
props = tool.Document.get_document_props()
assert len(props.documents) == 1
assert props.documents[0].ifc_definition_id == document.id()
assert props.documents[0].name == "Unnamed"
@@ -185,7 +188,7 @@ class TestImportReferences(NewFile):
document = ifcopenshell.api.run("document.add_information", ifc)
reference = ifcopenshell.api.run("document.add_reference", ifc, information=document)
subject.import_references(document)
props = bpy.context.scene.BIMDocumentProperties
props = tool.Document.get_document_props()
assert len(props.documents) == 1
assert props.documents[0].ifc_definition_id == reference.id()
assert props.documents[0].name == "Unnamed"
@@ -201,7 +204,7 @@ class TestImportSubdocuments(NewFile):
document = ifcopenshell.api.run("document.add_information", ifc)
subdocument = ifcopenshell.api.run("document.add_information", ifc, parent=document)
subject.import_subdocuments(document)
props = bpy.context.scene.BIMDocumentProperties
props = tool.Document.get_document_props()
assert len(props.documents) == 1
assert props.documents[0].ifc_definition_id == subdocument.id()
assert props.documents[0].name == "Unnamed"
@@ -220,7 +223,7 @@ class TestIsDocumentInformation(NewFile):
class TestRemoveLatestBreadcrumb(NewFile):
def test_run(self):
props = bpy.context.scene.BIMDocumentProperties
props = tool.Document.get_document_props()
props.breadcrumbs.add()
props.breadcrumbs.add()
subject.remove_latest_breadcrumb()
@@ -232,4 +235,5 @@ class TestSetActiveDocument(NewFile):
ifc = ifcopenshell.file()
document = ifc.createIfcDocumentInformation()
subject.set_active_document(document)
assert bpy.context.scene.BIMDocumentProperties.active_document_id == document.id()
props = tool.Document.get_document_props()
assert props.active_document_id == document.id()
+4 -2
View File
@@ -40,12 +40,14 @@ class TestSet(test.bim.bootstrap.NewFile):
class TestGet(test.bim.bootstrap.NewFile):
def test_getting_an_ifc_dataset_from_a_ifc_spf_filepath(self):
assert subject.get() is None
bpy.context.scene.BIMProperties.ifc_file = "test/files/basic.ifc"
props = tool.Blender.get_bim_props()
props.ifc_file = "test/files/basic.ifc"
result = subject.get()
assert isinstance(result, ifcopenshell.file)
def test_getting_the_active_ifc_dataset_regardless_of_ifc_path(self):
bpy.context.scene.BIMProperties.ifc_file = "test/files/basic.ifc"
props = tool.Blender.get_bim_props()
props.ifc_file = "test/files/basic.ifc"
ifc = ifcopenshell.file()
subject.set(ifc)
assert subject.get() == ifc
+48 -39
View File
@@ -18,6 +18,9 @@
import bpy
import ifcopenshell
import ifcopenshell.api.project
import ifcopenshell.api.root
import ifcopenshell.api.unit
import bonsai.core.tool
import bonsai.tool as tool
from test.bim.bootstrap import NewFile
@@ -31,23 +34,26 @@ class TestImplementsTool(NewFile):
class TestClearActiveUnit(NewFile):
def test_run(self):
bpy.context.scene.BIMUnitProperties.active_unit_id = 1
props = tool.Unit.get_unit_props()
props.active_unit_id = 1
subject.clear_active_unit()
assert bpy.context.scene.BIMUnitProperties.active_unit_id == 0
assert props.active_unit_id == 0
class TestDisableEditingUnits(NewFile):
def test_run(self):
bpy.context.scene.BIMUnitProperties.is_editing = True
props = tool.Unit.get_unit_props()
props.is_editing = True
subject.disable_editing_units()
assert bpy.context.scene.BIMUnitProperties.is_editing == False
assert props.is_editing == False
class TestEnableEditingUnits(NewFile):
def test_run(self):
bpy.context.scene.BIMUnitProperties.is_editing = False
props = tool.Unit.get_unit_props()
props.is_editing = False
subject.enable_editing_units()
assert bpy.context.scene.BIMUnitProperties.is_editing == True
assert props.is_editing == True
class TestExportUnitAttributes(NewFile):
@@ -98,10 +104,11 @@ class TestExportUnitAttributes(NewFile):
class TestGetSceneUnitName(NewFile):
def test_getting_an_imperial_name(self):
props = tool.Blender.get_bim_props()
bpy.context.scene.unit_settings.system = "IMPERIAL"
bpy.context.scene.unit_settings.length_unit = "MILES"
bpy.context.scene.BIMProperties.area_unit = "square foot"
bpy.context.scene.BIMProperties.volume_unit = "cubic inch"
props.area_unit = "square foot"
props.volume_unit = "cubic inch"
assert subject.get_scene_unit_name("LENGTHUNIT") == "mile"
assert subject.get_scene_unit_name("AREAUNIT") == "square foot"
assert subject.get_scene_unit_name("VOLUMEUNIT") == "cubic inch"
@@ -142,13 +149,14 @@ class TestGetSceneUnitSIPrefix:
assert subject.get_scene_unit_si_prefix("LENGTHUNIT") == "KILO"
bpy.context.scene.unit_settings.length_unit = "ADAPTIVE"
assert subject.get_scene_unit_si_prefix("LENGTHUNIT") is None
bpy.context.scene.BIMProperties.area_unit = "SQUARE_METRE"
props = tool.Blender.get_bim_props()
props.area_unit = "SQUARE_METRE"
assert subject.get_scene_unit_si_prefix("AREAUNIT") is None
bpy.context.scene.BIMProperties.area_unit = "MILLI/SQUARE_METRE"
props.area_unit = "MILLI/SQUARE_METRE"
assert subject.get_scene_unit_si_prefix("AREAUNIT") == "MILLI"
bpy.context.scene.BIMProperties.volume_unit = "CUBIC_METRE"
props.volume_unit = "CUBIC_METRE"
assert subject.get_scene_unit_si_prefix("VOLUMEUNIT") is None
bpy.context.scene.BIMProperties.volume_unit = "MILLI/CUBIC_METRE"
props.volume_unit = "MILLI/CUBIC_METRE"
assert subject.get_scene_unit_si_prefix("VOLUMEUNIT") == "MILLI"
@@ -159,25 +167,25 @@ class TestImportUnitAttributes(NewFile):
unit.UnitType = "ANGULARVELOCITYUNIT"
unit.UserDefinedType = "UserDefinedType"
subject.import_unit_attributes(unit)
props = bpy.context.scene.BIMUnitProperties
assert props.unit_attributes.get("UnitType").enum_value == "ANGULARVELOCITYUNIT"
assert props.unit_attributes.get("UserDefinedType").string_value == "UserDefinedType"
props = tool.Unit.get_unit_props()
assert props.unit_attributes["UnitType"].enum_value == "ANGULARVELOCITYUNIT"
assert props.unit_attributes["UserDefinedType"].string_value == "UserDefinedType"
def test_importing_monetary_units(self):
tool.Ifc.set(ifc := ifcopenshell.file())
unit = ifc.createIfcMonetaryUnit()
unit.Currency = "Currency"
subject.import_unit_attributes(unit)
props = bpy.context.scene.BIMUnitProperties
assert props.unit_attributes.get("Currency").string_value == "Currency"
props = tool.Unit.get_unit_props()
assert props.unit_attributes["Currency"].string_value == "Currency"
def test_importing_monetary_units_ifc2x3(self):
tool.Ifc.set(ifc := ifcopenshell.file(schema="IFC2X3"))
unit = ifc.createIfcMonetaryUnit()
unit.Currency = "USD"
subject.import_unit_attributes(unit)
props = bpy.context.scene.BIMUnitProperties
assert props.unit_attributes.get("Currency").enum_value == "USD"
props = tool.Unit.get_unit_props()
assert props.unit_attributes["Currency"].enum_value == "USD"
def test_importing_context_dependent_units(self):
ifc = ifcopenshell.file()
@@ -187,10 +195,10 @@ class TestImportUnitAttributes(NewFile):
unit.Name = "Name"
unit.Dimensions = ifc.createIfcDimensionalExponents(1, 2, 3, 4, 5, 6, 7)
subject.import_unit_attributes(unit)
props = bpy.context.scene.BIMUnitProperties
assert props.unit_attributes.get("UnitType").enum_value == "ABSORBEDDOSEUNIT"
assert props.unit_attributes.get("Name").string_value == "Name"
assert props.unit_attributes.get("Dimensions").string_value == "[1, 2, 3, 4, 5, 6, 7]"
props = tool.Unit.get_unit_props()
assert props.unit_attributes["UnitType"].enum_value == "ABSORBEDDOSEUNIT"
assert props.unit_attributes["Name"].string_value == "Name"
assert props.unit_attributes["Dimensions"].string_value == "[1, 2, 3, 4, 5, 6, 7]"
def test_importing_conversion_based_units(self):
ifc = ifcopenshell.file()
@@ -200,10 +208,10 @@ class TestImportUnitAttributes(NewFile):
unit.Name = "Name"
unit.Dimensions = ifc.createIfcDimensionalExponents(1, 2, 3, 4, 5, 6, 7)
subject.import_unit_attributes(unit)
props = bpy.context.scene.BIMUnitProperties
assert props.unit_attributes.get("UnitType").enum_value == "ABSORBEDDOSEUNIT"
assert props.unit_attributes.get("Name").string_value == "Name"
assert props.unit_attributes.get("Dimensions").string_value == "[1, 2, 3, 4, 5, 6, 7]"
props = tool.Unit.get_unit_props()
assert props.unit_attributes["UnitType"].enum_value == "ABSORBEDDOSEUNIT"
assert props.unit_attributes["Name"].string_value == "Name"
assert props.unit_attributes["Dimensions"].string_value == "[1, 2, 3, 4, 5, 6, 7]"
def test_importing_conversion_based_with_offset_units(self):
ifc = ifcopenshell.file()
@@ -214,11 +222,11 @@ class TestImportUnitAttributes(NewFile):
unit.Dimensions = ifc.createIfcDimensionalExponents(1, 2, 3, 4, 5, 6, 7)
unit.ConversionOffset = 1
subject.import_unit_attributes(unit)
props = bpy.context.scene.BIMUnitProperties
assert props.unit_attributes.get("UnitType").enum_value == "ABSORBEDDOSEUNIT"
assert props.unit_attributes.get("Name").string_value == "Name"
assert props.unit_attributes.get("Dimensions").string_value == "[1, 2, 3, 4, 5, 6, 7]"
assert props.unit_attributes.get("ConversionOffset").float_value == 1
props = tool.Unit.get_unit_props()
assert props.unit_attributes["UnitType"].enum_value == "ABSORBEDDOSEUNIT"
assert props.unit_attributes["Name"].string_value == "Name"
assert props.unit_attributes["Dimensions"].string_value == "[1, 2, 3, 4, 5, 6, 7]"
assert props.unit_attributes["ConversionOffset"].float_value == 1
def test_importing_si_units(self):
ifc = ifcopenshell.file()
@@ -228,11 +236,11 @@ class TestImportUnitAttributes(NewFile):
unit.Prefix = "EXA"
unit.Name = "AMPERE"
subject.import_unit_attributes(unit)
props = bpy.context.scene.BIMUnitProperties
assert props.unit_attributes.get("UnitType").enum_value == "ABSORBEDDOSEUNIT"
assert props.unit_attributes.get("Prefix").enum_value == "EXA"
assert props.unit_attributes.get("Name").enum_value == "AMPERE"
assert props.unit_attributes.get("Dimensions") is None
props = tool.Unit.get_unit_props()
assert props.unit_attributes["UnitType"].enum_value == "ABSORBEDDOSEUNIT"
assert props.unit_attributes["Prefix"].enum_value == "EXA"
assert props.unit_attributes["Name"].enum_value == "AMPERE"
assert props.unit_attributes["Dimensions"] is None
class TestImportUnits(NewFile):
@@ -248,7 +256,7 @@ class TestImportUnits(NewFile):
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.unit.assign_unit(ifc, units=[unit2])
subject.import_units()
props = bpy.context.scene.BIMUnitProperties
props = tool.Unit.get_unit_props()
assert len(props.units) == 6
assert props.units[0].ifc_definition_id == unit1.id()
@@ -311,4 +319,5 @@ class TestSetActiveUnit(NewFile):
ifc = ifcopenshell.file()
unit = ifc.createIfcSIUnit()
subject.set_active_unit(unit)
assert bpy.context.scene.BIMUnitProperties.active_unit_id == unit.id()
props = tool.Unit.get_unit_props()
assert props.active_unit_id == unit.id()