From 216029ea1086c3c29e6a50352a4e6337d5439a48 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 5 Oct 2021 09:51:51 +1100 Subject: [PATCH] Unlinking elements is now a bit more stable. Also simplify core tool namespace. --- src/blenderbim/blenderbim/bim/ifc.py | 8 + src/blenderbim/blenderbim/core/tool.py | 267 ++++++++++++++++++ .../blenderbim/core/tool/__init__.py | 27 -- .../blenderbim/core/tool/address_editor.py | 56 ---- .../blenderbim/core/tool/blender.py | 23 -- .../blenderbim/core/tool/context_editor.py | 46 --- src/blenderbim/blenderbim/core/tool/ifc.py | 31 -- .../core/tool/organisation_editor.py | 46 --- src/blenderbim/blenderbim/core/tool/owner.py | 18 -- .../blenderbim/core/tool/person_editor.py | 56 ---- .../blenderbim/core/tool/role_editor.py | 46 --- .../blenderbim/core/tool/surveyor.py | 8 - src/blenderbim/blenderbim/tool/__init__.py | 11 +- .../blenderbim/tool/context_editor.py | 4 +- src/blenderbim/blenderbim/tool/ifc.py | 14 +- .../blenderbim/tool/organisation_editor.py | 2 +- src/blenderbim/blenderbim/tool/owner.py | 2 +- .../blenderbim/tool/person_editor.py | 2 +- src/blenderbim/blenderbim/tool/role_editor.py | 2 +- src/blenderbim/blenderbim/tool/surveyor.py | 2 +- src/blenderbim/pytest.ini | 1 + src/blenderbim/test/core/bootstrap.py | 28 ++ .../test/tool/test_context_editor.py | 2 +- src/blenderbim/test/tool/test_ifc.py | 61 +++- .../test/tool/test_organisation_editor.py | 2 +- src/blenderbim/test/tool/test_owner.py | 2 +- .../test/tool/test_person_editor.py | 2 +- src/blenderbim/test/tool/test_role_editor.py | 2 +- src/blenderbim/test/tool/test_surveyor.py | 9 +- 29 files changed, 397 insertions(+), 383 deletions(-) create mode 100644 src/blenderbim/blenderbim/core/tool.py delete mode 100644 src/blenderbim/blenderbim/core/tool/__init__.py delete mode 100644 src/blenderbim/blenderbim/core/tool/address_editor.py delete mode 100644 src/blenderbim/blenderbim/core/tool/blender.py delete mode 100644 src/blenderbim/blenderbim/core/tool/context_editor.py delete mode 100644 src/blenderbim/blenderbim/core/tool/ifc.py delete mode 100644 src/blenderbim/blenderbim/core/tool/organisation_editor.py delete mode 100644 src/blenderbim/blenderbim/core/tool/owner.py delete mode 100644 src/blenderbim/blenderbim/core/tool/person_editor.py delete mode 100644 src/blenderbim/blenderbim/core/tool/role_editor.py delete mode 100644 src/blenderbim/blenderbim/core/tool/surveyor.py diff --git a/src/blenderbim/blenderbim/bim/ifc.py b/src/blenderbim/blenderbim/bim/ifc.py index b5879fce39..1170ee37c5 100644 --- a/src/blenderbim/blenderbim/bim/ifc.py +++ b/src/blenderbim/blenderbim/bim/ifc.py @@ -202,6 +202,14 @@ class IfcStore: except: pass + if obj is None: + try: + potential_obj = IfcStore.id_map[element.id()] + potential_obj.name + obj = potential_obj + except: + pass + try: if element: del IfcStore.id_map[element.id()] diff --git a/src/blenderbim/blenderbim/core/tool.py b/src/blenderbim/blenderbim/core/tool.py new file mode 100644 index 0000000000..fdbb7ceffa --- /dev/null +++ b/src/blenderbim/blenderbim/core/tool.py @@ -0,0 +1,267 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2021 Dion Moult +# +# This file is part of BlenderBIM Add-on. +# +# BlenderBIM Add-on is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# BlenderBIM Add-on is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with BlenderBIM Add-on. If not, see . + +import abc + + +class AddressEditor(abc.ABC): + @classmethod + @abc.abstractmethod + def set_address(cls, address): + pass + + @classmethod + @abc.abstractmethod + def import_attributes(cls): + pass + + @classmethod + @abc.abstractmethod + def clear_address(cls): + pass + + @classmethod + @abc.abstractmethod + def get_address(cls): + pass + + @classmethod + @abc.abstractmethod + def export_attributes(cls): + pass + + @classmethod + @abc.abstractmethod + def add_attribute(cls, name): + pass + + @classmethod + @abc.abstractmethod + def remove_attribute(cls, name, id): + pass + + +class Blender(abc.ABC): + pass + + +class Collector(abc.ABC): + @classmethod + @abc.abstractmethod + def assign(cls, obj): + pass + + +class Container(abc.ABC): + @classmethod + @abc.abstractmethod + def can_contain(cls, structure_obj, element_obj): + pass + + @classmethod + @abc.abstractmethod + def enable_editing(cls, obj): + pass + + @classmethod + @abc.abstractmethod + def disable_editing(cls, obj): + pass + + +class ContextEditor(abc.ABC): + @classmethod + @abc.abstractmethod + def set_context(cls, context): + pass + + @classmethod + @abc.abstractmethod + def import_attributes(cls): + pass + + @classmethod + @abc.abstractmethod + def clear_context(cls): + pass + + @classmethod + @abc.abstractmethod + def get_context(cls): + pass + + @classmethod + @abc.abstractmethod + def export_attributes(cls): + pass + + +class Ifc(abc.ABC): + @classmethod + @abc.abstractmethod + def run(cls, command, **kwargs): + pass + + @classmethod + @abc.abstractmethod + def get_entity(cls, obj): + pass + + +class OrganisationEditor(abc.ABC): + @classmethod + @abc.abstractmethod + def set_organisation(cls, organisation): + pass + + @classmethod + @abc.abstractmethod + def import_attributes(cls): + pass + + @classmethod + @abc.abstractmethod + def clear_organisation(cls): + pass + + @classmethod + @abc.abstractmethod + def get_organisation(cls): + pass + + @classmethod + @abc.abstractmethod + def export_attributes(cls): + pass + + +class Owner(abc.ABC): + @classmethod + @abc.abstractmethod + def set_user(cls, user): + pass + + @classmethod + @abc.abstractmethod + def get_user(cls): + pass + + @classmethod + @abc.abstractmethod + def clear_user(cls): + pass + + +class PersonEditor(abc.ABC): + @classmethod + @abc.abstractmethod + def set_person(cls, person): + pass + + @classmethod + @abc.abstractmethod + def import_attributes(cls): + pass + + @classmethod + @abc.abstractmethod + def clear_person(cls): + pass + + @classmethod + @abc.abstractmethod + def export_attributes(cls): + pass + + @classmethod + @abc.abstractmethod + def get_person(cls): + pass + + @classmethod + @abc.abstractmethod + def add_attribute(cls, name): + pass + + @classmethod + @abc.abstractmethod + def remove_attribute(cls, name, id): + pass + + +class RoleEditor(abc.ABC): + @classmethod + @abc.abstractmethod + def set_role(cls, role): + pass + + @classmethod + @abc.abstractmethod + def import_attributes(cls): + pass + + @classmethod + @abc.abstractmethod + def clear_role(cls): + pass + + @classmethod + @abc.abstractmethod + def get_role(cls): + pass + + @classmethod + @abc.abstractmethod + def export_attributes(cls): + pass + + +class Selector(abc.ABC): + @classmethod + @abc.abstractmethod + def set_active(cls, obj): + pass + + +class Surveyor(abc.ABC): + @classmethod + @abc.abstractmethod + def get_absolute_matrix(cls, obj): + pass + + +class Voider(abc.ABC): + @classmethod + @abc.abstractmethod + def can_void(cls, opening, element): + pass + + @classmethod + @abc.abstractmethod + def void(cls, opening_obj, building_obj): + pass + + @classmethod + @abc.abstractmethod + def unvoid(cls, opening_obj): + pass + + @classmethod + @abc.abstractmethod + def set_void_display(cls, opening_obj): + pass diff --git a/src/blenderbim/blenderbim/core/tool/__init__.py b/src/blenderbim/blenderbim/core/tool/__init__.py deleted file mode 100644 index 36768c367f..0000000000 --- a/src/blenderbim/blenderbim/core/tool/__init__.py +++ /dev/null @@ -1,27 +0,0 @@ -# BlenderBIM Add-on - OpenBIM Blender Add-on -# Copyright (C) 2021 Dion Moult -# -# This file is part of BlenderBIM Add-on. -# -# BlenderBIM Add-on is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# BlenderBIM Add-on is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with BlenderBIM Add-on. If not, see . - -from blenderbim.core.tool.ifc import Ifc -from blenderbim.core.tool.blender import Blender -from blenderbim.core.tool.person_editor import PersonEditor -from blenderbim.core.tool.role_editor import RoleEditor -from blenderbim.core.tool.address_editor import AddressEditor -from blenderbim.core.tool.organisation_editor import OrganisationEditor -from blenderbim.core.tool.context_editor import ContextEditor -from blenderbim.core.tool.owner import Owner -from blenderbim.core.tool.surveyor import Surveyor diff --git a/src/blenderbim/blenderbim/core/tool/address_editor.py b/src/blenderbim/blenderbim/core/tool/address_editor.py deleted file mode 100644 index b845b79119..0000000000 --- a/src/blenderbim/blenderbim/core/tool/address_editor.py +++ /dev/null @@ -1,56 +0,0 @@ -# BlenderBIM Add-on - OpenBIM Blender Add-on -# Copyright (C) 2021 Dion Moult -# -# This file is part of BlenderBIM Add-on. -# -# BlenderBIM Add-on is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# BlenderBIM Add-on is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with BlenderBIM Add-on. If not, see . - -import abc - - -class AddressEditor(abc.ABC): - @classmethod - @abc.abstractmethod - def set_address(cls, address): - pass - - @classmethod - @abc.abstractmethod - def import_attributes(cls): - pass - - @classmethod - @abc.abstractmethod - def clear_address(cls): - pass - - @classmethod - @abc.abstractmethod - def get_address(cls): - pass - - @classmethod - @abc.abstractmethod - def export_attributes(cls): - pass - - @classmethod - @abc.abstractmethod - def add_attribute(cls, name): - pass - - @classmethod - @abc.abstractmethod - def remove_attribute(cls, name, id): - pass diff --git a/src/blenderbim/blenderbim/core/tool/blender.py b/src/blenderbim/blenderbim/core/tool/blender.py deleted file mode 100644 index a061e9112e..0000000000 --- a/src/blenderbim/blenderbim/core/tool/blender.py +++ /dev/null @@ -1,23 +0,0 @@ -# BlenderBIM Add-on - OpenBIM Blender Add-on -# Copyright (C) 2021 Dion Moult -# -# This file is part of BlenderBIM Add-on. -# -# BlenderBIM Add-on is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# BlenderBIM Add-on is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with BlenderBIM Add-on. If not, see . - -import abc - - -class Blender(abc.ABC): - pass diff --git a/src/blenderbim/blenderbim/core/tool/context_editor.py b/src/blenderbim/blenderbim/core/tool/context_editor.py deleted file mode 100644 index 4748c4b2dc..0000000000 --- a/src/blenderbim/blenderbim/core/tool/context_editor.py +++ /dev/null @@ -1,46 +0,0 @@ -# BlenderBIM Add-on - OpenBIM Blender Add-on -# Copyright (C) 2021 Dion Moult -# -# This file is part of BlenderBIM Add-on. -# -# BlenderBIM Add-on is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# BlenderBIM Add-on is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with BlenderBIM Add-on. If not, see . - -import abc - - -class ContextEditor(abc.ABC): - @classmethod - @abc.abstractmethod - def set_context(cls, context): - pass - - @classmethod - @abc.abstractmethod - def import_attributes(cls): - pass - - @classmethod - @abc.abstractmethod - def clear_context(cls): - pass - - @classmethod - @abc.abstractmethod - def get_context(cls): - pass - - @classmethod - @abc.abstractmethod - def export_attributes(cls): - pass diff --git a/src/blenderbim/blenderbim/core/tool/ifc.py b/src/blenderbim/blenderbim/core/tool/ifc.py deleted file mode 100644 index 43b406338f..0000000000 --- a/src/blenderbim/blenderbim/core/tool/ifc.py +++ /dev/null @@ -1,31 +0,0 @@ -# BlenderBIM Add-on - OpenBIM Blender Add-on -# Copyright (C) 2021 Dion Moult -# -# This file is part of BlenderBIM Add-on. -# -# BlenderBIM Add-on is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# BlenderBIM Add-on is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with BlenderBIM Add-on. If not, see . - -import abc - - -class Ifc(abc.ABC): - @classmethod - @abc.abstractmethod - def run(cls, command, **kwargs): - pass - - @classmethod - @abc.abstractmethod - def get_entity(cls, obj): - pass diff --git a/src/blenderbim/blenderbim/core/tool/organisation_editor.py b/src/blenderbim/blenderbim/core/tool/organisation_editor.py deleted file mode 100644 index 85d73f8324..0000000000 --- a/src/blenderbim/blenderbim/core/tool/organisation_editor.py +++ /dev/null @@ -1,46 +0,0 @@ -# BlenderBIM Add-on - OpenBIM Blender Add-on -# Copyright (C) 2021 Dion Moult -# -# This file is part of BlenderBIM Add-on. -# -# BlenderBIM Add-on is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# BlenderBIM Add-on is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with BlenderBIM Add-on. If not, see . - -import abc - - -class OrganisationEditor(abc.ABC): - @classmethod - @abc.abstractmethod - def set_organisation(cls, organisation): - pass - - @classmethod - @abc.abstractmethod - def import_attributes(cls): - pass - - @classmethod - @abc.abstractmethod - def clear_organisation(cls): - pass - - @classmethod - @abc.abstractmethod - def get_organisation(cls): - pass - - @classmethod - @abc.abstractmethod - def export_attributes(cls): - pass diff --git a/src/blenderbim/blenderbim/core/tool/owner.py b/src/blenderbim/blenderbim/core/tool/owner.py deleted file mode 100644 index 9a6f421fb4..0000000000 --- a/src/blenderbim/blenderbim/core/tool/owner.py +++ /dev/null @@ -1,18 +0,0 @@ -import abc - - -class Owner(abc.ABC): - @classmethod - @abc.abstractmethod - def set_user(cls, user): - pass - - @classmethod - @abc.abstractmethod - def get_user(cls): - pass - - @classmethod - @abc.abstractmethod - def clear_user(cls): - pass diff --git a/src/blenderbim/blenderbim/core/tool/person_editor.py b/src/blenderbim/blenderbim/core/tool/person_editor.py deleted file mode 100644 index bd2bce4906..0000000000 --- a/src/blenderbim/blenderbim/core/tool/person_editor.py +++ /dev/null @@ -1,56 +0,0 @@ -# BlenderBIM Add-on - OpenBIM Blender Add-on -# Copyright (C) 2021 Dion Moult -# -# This file is part of BlenderBIM Add-on. -# -# BlenderBIM Add-on is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# BlenderBIM Add-on is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with BlenderBIM Add-on. If not, see . - -import abc - - -class PersonEditor(abc.ABC): - @classmethod - @abc.abstractmethod - def set_person(cls, person): - pass - - @classmethod - @abc.abstractmethod - def import_attributes(cls): - pass - - @classmethod - @abc.abstractmethod - def clear_person(cls): - pass - - @classmethod - @abc.abstractmethod - def export_attributes(cls): - pass - - @classmethod - @abc.abstractmethod - def get_person(cls): - pass - - @classmethod - @abc.abstractmethod - def add_attribute(cls, name): - pass - - @classmethod - @abc.abstractmethod - def remove_attribute(cls, name, id): - pass diff --git a/src/blenderbim/blenderbim/core/tool/role_editor.py b/src/blenderbim/blenderbim/core/tool/role_editor.py deleted file mode 100644 index 0107917948..0000000000 --- a/src/blenderbim/blenderbim/core/tool/role_editor.py +++ /dev/null @@ -1,46 +0,0 @@ -# BlenderBIM Add-on - OpenBIM Blender Add-on -# Copyright (C) 2021 Dion Moult -# -# This file is part of BlenderBIM Add-on. -# -# BlenderBIM Add-on is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# BlenderBIM Add-on is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with BlenderBIM Add-on. If not, see . - -import abc - - -class RoleEditor(abc.ABC): - @classmethod - @abc.abstractmethod - def set_role(cls, role): - pass - - @classmethod - @abc.abstractmethod - def import_attributes(cls): - pass - - @classmethod - @abc.abstractmethod - def clear_role(cls): - pass - - @classmethod - @abc.abstractmethod - def get_role(cls): - pass - - @classmethod - @abc.abstractmethod - def export_attributes(cls): - pass diff --git a/src/blenderbim/blenderbim/core/tool/surveyor.py b/src/blenderbim/blenderbim/core/tool/surveyor.py deleted file mode 100644 index 7d64571ee5..0000000000 --- a/src/blenderbim/blenderbim/core/tool/surveyor.py +++ /dev/null @@ -1,8 +0,0 @@ -import abc - - -class Surveyor(abc.ABC): - @classmethod - @abc.abstractmethod - def get_absolute_matrix(cls, obj): - pass diff --git a/src/blenderbim/blenderbim/tool/__init__.py b/src/blenderbim/blenderbim/tool/__init__.py index 15254bd9fb..71ef3e3b0f 100644 --- a/src/blenderbim/blenderbim/tool/__init__.py +++ b/src/blenderbim/blenderbim/tool/__init__.py @@ -16,12 +16,13 @@ # You should have received a copy of the GNU General Public License # along with BlenderBIM Add-on. If not, see . -from blenderbim.tool.ifc import Ifc +from blenderbim.tool.address_editor import AddressEditor from blenderbim.tool.blender import Blender +from blenderbim.tool.context_editor import ContextEditor +from blenderbim.tool.ifc import Ifc +from blenderbim.tool.organisation_editor import OrganisationEditor +from blenderbim.tool.owner import Owner from blenderbim.tool.person_editor import PersonEditor from blenderbim.tool.role_editor import RoleEditor -from blenderbim.tool.address_editor import AddressEditor -from blenderbim.tool.organisation_editor import OrganisationEditor -from blenderbim.tool.context_editor import ContextEditor -from blenderbim.tool.owner import Owner from blenderbim.tool.surveyor import Surveyor +from blenderbim.tool.container import Container diff --git a/src/blenderbim/blenderbim/tool/context_editor.py b/src/blenderbim/blenderbim/tool/context_editor.py index fb1edbab72..0414d09ede 100644 --- a/src/blenderbim/blenderbim/tool/context_editor.py +++ b/src/blenderbim/blenderbim/tool/context_editor.py @@ -19,10 +19,10 @@ import bpy import blenderbim.bim.helper import blenderbim.tool as tool -import blenderbim.core.tool.context_editor +import blenderbim.core.tool -class ContextEditor(blenderbim.core.tool.context_editor.ContextEditor): +class ContextEditor(blenderbim.core.tool.ContextEditor): @classmethod def set_context(cls, context): bpy.context.scene.BIMContextProperties.active_context_id = context.id() diff --git a/src/blenderbim/blenderbim/tool/ifc.py b/src/blenderbim/blenderbim/tool/ifc.py index a5bf1f2889..d05ddb21a6 100644 --- a/src/blenderbim/blenderbim/tool/ifc.py +++ b/src/blenderbim/blenderbim/tool/ifc.py @@ -22,7 +22,7 @@ import blenderbim.core.tool from blenderbim.bim.ifc import IfcStore -class Ifc(blenderbim.core.tool.ifc.Ifc): +class Ifc(blenderbim.core.tool.Ifc): @classmethod def run(cls, command, **kwargs): return ifcopenshell.api.run(command, IfcStore.get_file(), **kwargs) @@ -48,3 +48,15 @@ class Ifc(blenderbim.core.tool.ifc.Ifc): return IfcStore.get_file().by_id(props.ifc_definition_id) except: pass + + @classmethod + def get_object(cls, element): + return IfcStore.get_element(element.id()) + + @classmethod + def link(cls, element, obj): + IfcStore.link_element(element, obj) + + @classmethod + def unlink(cls, element=None, obj=None): + IfcStore.unlink_element(element, obj) diff --git a/src/blenderbim/blenderbim/tool/organisation_editor.py b/src/blenderbim/blenderbim/tool/organisation_editor.py index 0764447727..8158b0fcdf 100644 --- a/src/blenderbim/blenderbim/tool/organisation_editor.py +++ b/src/blenderbim/blenderbim/tool/organisation_editor.py @@ -23,7 +23,7 @@ import blenderbim.bim.helper import blenderbim.tool as tool -class OrganisationEditor(blenderbim.core.tool.organisation_editor.OrganisationEditor): +class OrganisationEditor(blenderbim.core.tool.OrganisationEditor): @classmethod def set_organisation(cls, organisation): bpy.context.scene.BIMOwnerProperties.active_organisation_id = organisation.id() diff --git a/src/blenderbim/blenderbim/tool/owner.py b/src/blenderbim/blenderbim/tool/owner.py index 898f291c29..4dce3f92fa 100644 --- a/src/blenderbim/blenderbim/tool/owner.py +++ b/src/blenderbim/blenderbim/tool/owner.py @@ -2,7 +2,7 @@ import bpy import blenderbim.core.tool import blenderbim.tool as tool -class Owner(blenderbim.core.tool.owner.Owner): +class Owner(blenderbim.core.tool.Owner): @classmethod def set_user(cls, user): bpy.context.scene.BIMOwnerProperties.active_user_id = user.id() diff --git a/src/blenderbim/blenderbim/tool/person_editor.py b/src/blenderbim/blenderbim/tool/person_editor.py index 31407a779e..7acacab0e2 100644 --- a/src/blenderbim/blenderbim/tool/person_editor.py +++ b/src/blenderbim/blenderbim/tool/person_editor.py @@ -23,7 +23,7 @@ import blenderbim.bim.helper import blenderbim.tool as tool -class PersonEditor(blenderbim.core.tool.person_editor.PersonEditor): +class PersonEditor(blenderbim.core.tool.PersonEditor): @classmethod def set_person(cls, person): bpy.context.scene.BIMOwnerProperties.active_person_id = person.id() diff --git a/src/blenderbim/blenderbim/tool/role_editor.py b/src/blenderbim/blenderbim/tool/role_editor.py index 4b214bff1e..cdd98acf1f 100644 --- a/src/blenderbim/blenderbim/tool/role_editor.py +++ b/src/blenderbim/blenderbim/tool/role_editor.py @@ -22,7 +22,7 @@ import blenderbim.tool as tool import blenderbim.bim.helper -class RoleEditor(blenderbim.core.tool.role_editor.RoleEditor): +class RoleEditor(blenderbim.core.tool.RoleEditor): @classmethod def set_role(cls, role): bpy.context.scene.BIMOwnerProperties.active_role_id = role.id() diff --git a/src/blenderbim/blenderbim/tool/surveyor.py b/src/blenderbim/blenderbim/tool/surveyor.py index b963733c42..a80ce4e2cb 100644 --- a/src/blenderbim/blenderbim/tool/surveyor.py +++ b/src/blenderbim/blenderbim/tool/surveyor.py @@ -5,7 +5,7 @@ import blenderbim.tool as tool import numpy as np -class Surveyor(blenderbim.core.tool.surveyor.Surveyor): +class Surveyor(blenderbim.core.tool.Surveyor): @classmethod def get_absolute_matrix(cls, obj): matrix = np.array(obj.matrix_world) diff --git a/src/blenderbim/pytest.ini b/src/blenderbim/pytest.ini index 1d2f3021f7..bf15c4038d 100644 --- a/src/blenderbim/pytest.ini +++ b/src/blenderbim/pytest.ini @@ -1,5 +1,6 @@ [pytest] markers = context + geometry owner void diff --git a/src/blenderbim/test/core/bootstrap.py b/src/blenderbim/test/core/bootstrap.py index d9ed0646a9..7b9a94d2b7 100644 --- a/src/blenderbim/test/core/bootstrap.py +++ b/src/blenderbim/test/core/bootstrap.py @@ -77,6 +77,20 @@ def owner(): prophet.verify() +@pytest.fixture +def voider(): + prophet = Prophecy(blenderbim.core.tool.Voider) + yield prophet + prophet.verify() + + +@pytest.fixture +def selector(): + prophet = Prophecy(blenderbim.core.tool.Selector) + yield prophet + prophet.verify() + + @pytest.fixture def surveyor(): prophet = Prophecy(blenderbim.core.tool.Surveyor) @@ -84,6 +98,20 @@ def surveyor(): prophet.verify() +@pytest.fixture +def collector(): + prophet = Prophecy(blenderbim.core.tool.Collector) + yield prophet + prophet.verify() + + +@pytest.fixture +def container(): + prophet = Prophecy(blenderbim.core.tool.Container) + yield prophet + prophet.verify() + + class Prophecy: def __init__(self, cls): self.subject = cls diff --git a/src/blenderbim/test/tool/test_context_editor.py b/src/blenderbim/test/tool/test_context_editor.py index 8a6af7b74d..9a13e56c46 100644 --- a/src/blenderbim/test/tool/test_context_editor.py +++ b/src/blenderbim/test/tool/test_context_editor.py @@ -26,7 +26,7 @@ from blenderbim.tool.context_editor import ContextEditor as subject class TestImplementsTool(test.bim.bootstrap.NewFile): def test_run(self): - assert isinstance(subject(), blenderbim.core.tool.context_editor.ContextEditor) + assert isinstance(subject(), blenderbim.core.tool.ContextEditor) class TestSetContext(test.bim.bootstrap.NewFile): diff --git a/src/blenderbim/test/tool/test_ifc.py b/src/blenderbim/test/tool/test_ifc.py index a24b15bb09..247694f815 100644 --- a/src/blenderbim/test/tool/test_ifc.py +++ b/src/blenderbim/test/tool/test_ifc.py @@ -19,13 +19,13 @@ import bpy import ifcopenshell import test.bim.bootstrap -import blenderbim.core.tool.ifc -from blenderbim.tool import Ifc as subject +import blenderbim.core.tool +from blenderbim.tool.ifc import Ifc as subject class TestImplementsTool(test.bim.bootstrap.NewFile): def test_run(self): - assert isinstance(subject(), blenderbim.core.tool.ifc.Ifc) + assert isinstance(subject(), blenderbim.core.tool.Ifc) class TestSet(test.bim.bootstrap.NewFile): @@ -64,7 +64,7 @@ class TestGetSchema(test.bim.bootstrap.NewFile): assert subject.get_schema() == "IFC4" -class TestGetElement(test.bim.bootstrap.NewFile): +class TestGetEntity(test.bim.bootstrap.NewFile): def test_run(self): ifc = ifcopenshell.file() subject.set(ifc) @@ -88,3 +88,56 @@ class TestGetElement(test.bim.bootstrap.NewFile): obj = bpy.data.objects.new("Object", None) obj.BIMObjectProperties.ifc_definition_id = 1 assert subject.get_entity(obj) is None + + +class TestGetObject(test.bim.bootstrap.NewFile): + def test_run(self): + ifc = ifcopenshell.file() + subject.set(ifc) + element = ifc.createIfcWall() + obj = bpy.data.objects.new("Object", None) + subject.link(element, obj) + assert subject.get_object(element) == obj + + +class TestLink(test.bim.bootstrap.NewFile): + def test_run(self): + ifc = ifcopenshell.file() + subject.set(ifc) + element = ifc.createIfcWall() + obj = bpy.data.objects.new("Object", None) + subject.link(element, obj) + assert subject.get_entity(obj) == element + assert subject.get_object(element) == obj + + +class TestUnlink(test.bim.bootstrap.NewFile): + def test_run(self): + ifc = ifcopenshell.file() + subject.set(ifc) + element = ifc.createIfcWall() + obj = bpy.data.objects.new("Object", None) + subject.link(element, obj) + subject.unlink(element, obj) + assert subject.get_entity(obj) is None + assert subject.get_object(element) is None + + def test_unlinking_using_an_object(self): + ifc = ifcopenshell.file() + subject.set(ifc) + element = ifc.createIfcWall() + obj = bpy.data.objects.new("Object", None) + subject.link(element, obj) + subject.unlink(obj=obj) + assert subject.get_entity(obj) is None + assert subject.get_object(element) is None + + def test_unlinking_using_an_element(self): + ifc = ifcopenshell.file() + subject.set(ifc) + element = ifc.createIfcWall() + obj = bpy.data.objects.new("Object", None) + subject.link(element, obj) + subject.unlink(element=element) + assert subject.get_entity(obj) is None + assert subject.get_object(element) is None diff --git a/src/blenderbim/test/tool/test_organisation_editor.py b/src/blenderbim/test/tool/test_organisation_editor.py index 6b4d338ea7..d6bcfb4334 100644 --- a/src/blenderbim/test/tool/test_organisation_editor.py +++ b/src/blenderbim/test/tool/test_organisation_editor.py @@ -26,7 +26,7 @@ from blenderbim.tool.organisation_editor import OrganisationEditor as subject class TestImplementsTool(test.bim.bootstrap.NewFile): def test_run(self): - assert isinstance(subject(), blenderbim.core.tool.organisation_editor.OrganisationEditor) + assert isinstance(subject(), blenderbim.core.tool.OrganisationEditor) class TestSetOrganisation(test.bim.bootstrap.NewFile): diff --git a/src/blenderbim/test/tool/test_owner.py b/src/blenderbim/test/tool/test_owner.py index 21377cf8e5..fdcffbd8e6 100644 --- a/src/blenderbim/test/tool/test_owner.py +++ b/src/blenderbim/test/tool/test_owner.py @@ -8,7 +8,7 @@ from blenderbim.tool.owner import Owner as subject class TestImplementsTool(test.bim.bootstrap.NewFile): def test_run(self): - assert isinstance(subject(), blenderbim.core.tool.owner.Owner) + assert isinstance(subject(), blenderbim.core.tool.Owner) class TestSetUser(test.bim.bootstrap.NewFile): diff --git a/src/blenderbim/test/tool/test_person_editor.py b/src/blenderbim/test/tool/test_person_editor.py index 50a6a78600..949a6f544c 100644 --- a/src/blenderbim/test/tool/test_person_editor.py +++ b/src/blenderbim/test/tool/test_person_editor.py @@ -26,7 +26,7 @@ from blenderbim.tool.person_editor import PersonEditor as subject class TestImplementsTool(test.bim.bootstrap.NewFile): def test_run(self): - assert isinstance(subject(), blenderbim.core.tool.person_editor.PersonEditor) + assert isinstance(subject(), blenderbim.core.tool.PersonEditor) class TestSetPerson(test.bim.bootstrap.NewFile): diff --git a/src/blenderbim/test/tool/test_role_editor.py b/src/blenderbim/test/tool/test_role_editor.py index 67d9fd014f..c9c77aab36 100644 --- a/src/blenderbim/test/tool/test_role_editor.py +++ b/src/blenderbim/test/tool/test_role_editor.py @@ -26,7 +26,7 @@ from blenderbim.tool.role_editor import RoleEditor as subject class TestImplementsTool(test.bim.bootstrap.NewFile): def test_run(self): - assert isinstance(subject(), blenderbim.core.tool.role_editor.RoleEditor) + assert isinstance(subject(), blenderbim.core.tool.RoleEditor) class TestSetRole(test.bim.bootstrap.NewFile): diff --git a/src/blenderbim/test/tool/test_surveyor.py b/src/blenderbim/test/tool/test_surveyor.py index 01003f1788..18bf47eef5 100644 --- a/src/blenderbim/test/tool/test_surveyor.py +++ b/src/blenderbim/test/tool/test_surveyor.py @@ -1,16 +1,17 @@ import bpy +import numpy as np import ifcopenshell import ifcopenshell.api -import blenderbim.tool as tool + import test.bim.bootstrap -import blenderbim.core.tool.surveyor -import numpy as np +import blenderbim.core.tool +import blenderbim.tool as tool from blenderbim.tool import Surveyor as subject class TestImplementsTool(test.bim.bootstrap.NewFile): def test_run(self): - assert isinstance(subject(), blenderbim.core.tool.surveyor.Surveyor) + assert isinstance(subject(), blenderbim.core.tool.Surveyor) class TestGetGlobalMatrix(test.bim.bootstrap.NewFile):