diff --git a/src/blenderbim/blenderbim/core/system.py b/src/blenderbim/blenderbim/core/system.py index 1e5b026046..8015825f1b 100644 --- a/src/blenderbim/blenderbim/core/system.py +++ b/src/blenderbim/blenderbim/core/system.py @@ -59,7 +59,7 @@ def assign_system(ifc, system=None, product=None): def unassign_system(ifc, system=None, product=None): - ifc.run("system.unassign_system", product=product, system=system) + ifc.run("system.unassign_system", products=[product], system=system) def select_system_products(system_tool, system=None): diff --git a/src/blenderbim/test/core/test_system.py b/src/blenderbim/test/core/test_system.py index 82ef966b5c..51c4dc9bae 100644 --- a/src/blenderbim/test/core/test_system.py +++ b/src/blenderbim/test/core/test_system.py @@ -80,7 +80,7 @@ class TestAssignSystem: class TestUnassignSystem: def test_run(self, ifc): - ifc.run("system.unassign_system", product="product", system="system").should_be_called() + ifc.run("system.unassign_system", products=["product"], system="system").should_be_called() subject.unassign_system(ifc, system="system", product="product") diff --git a/src/ifcopenshell-python/ifcopenshell/api/__init__.py b/src/ifcopenshell-python/ifcopenshell/api/__init__.py index 10ade30ab8..9748c848a9 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/__init__.py +++ b/src/ifcopenshell-python/ifcopenshell/api/__init__.py @@ -82,6 +82,9 @@ ARGUMENTS_DEPRECATION = { "system.assign_system": partial( batching_argument_deprecation, prev_argument="product", new_argument="products" ), + "system.unassign_system": partial( + batching_argument_deprecation, prev_argument="product", new_argument="products" + ), } diff --git a/src/ifcopenshell-python/ifcopenshell/api/system/unassign_system.py b/src/ifcopenshell-python/ifcopenshell/api/system/unassign_system.py index 10383ffbbb..121939a251 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/system/unassign_system.py +++ b/src/ifcopenshell-python/ifcopenshell/api/system/unassign_system.py @@ -22,11 +22,16 @@ import ifcopenshell.util.element class Usecase: - def __init__(self, file, product=None, system=None): - """Unassigns a product from a system + def __init__( + self, + file: ifcopenshell.entity_instance, + products: list[ifcopenshell.entity_instance], + system: ifcopenshell.entity_instance, + ): + """Unassigns list of products from a system - :param product: The IfcDistributionElement to unassign from the system. - :type product: ifcopenshell.entity_instance.entity_instance + :param products: The list of IfcDistributionElements to unassign from the system. + :type products: list[ifcopenshell.entity_instance.entity_instance] :param system: The IfcSystem you want to unassign the element from. :type system: ifcopenshell.entity_instance.entity_instance :return: None @@ -47,25 +52,15 @@ class Usecase: ifcopenshell.api.run("system.assign_system", model, products=[duct], system=system) # Not anymore! - ifcopenshell.api.run("system.unassign_system", model, product=duct, system=system) + ifcopenshell.api.run("system.unassign_system", model, products=[duct], system=system) """ self.file = file self.settings = { - "product": product, + "products": products, "system": system, } def execute(self): - if not self.settings["system"].IsGroupedBy: - return - rel = self.settings["system"].IsGroupedBy[0] - related_objects = set(rel.RelatedObjects) or set() - related_objects.remove(self.settings["product"]) - if len(related_objects): - rel.RelatedObjects = list(related_objects) - ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel}) - else: - history = rel.OwnerHistory - self.file.remove(rel) - if history: - ifcopenshell.util.element.remove_deep2(self.file, history) + ifcopenshell.api.run( + "group.unassign_group", self.file, products=self.settings["products"], group=self.settings["system"] + ) diff --git a/src/ifcopenshell-python/test/api/system/test_unassign_system.py b/src/ifcopenshell-python/test/api/system/test_unassign_system.py new file mode 100644 index 0000000000..1bf3433825 --- /dev/null +++ b/src/ifcopenshell-python/test/api/system/test_unassign_system.py @@ -0,0 +1,40 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2022 Dion Moult +# +# This file is part of IfcOpenShell. +# +# IfcOpenShell is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# IfcOpenShell 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 Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with IfcOpenShell. If not, see . + +import pytest +import test.bootstrap +import ifcopenshell.api +import ifcopenshell.util.system + + +class TestUnassignSystem(test.bootstrap.IFC4): + def test_unassign_system(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment") + element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment") + element3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment") + system = ifcopenshell.api.run("system.add_system", self.file) + ifcopenshell.api.run("system.assign_system", self.file, products=[element, element2, element3], system=system) + ifcopenshell.api.run("system.unassign_system", self.file, products=[element2, element3], system=system) + assert ifcopenshell.util.system.get_system_elements(system) == [element] + + ifcopenshell.api.run("system.unassign_system", self.file, products=[element], system=system) + assert ifcopenshell.util.system.get_system_elements(system) == [] + + +class TestUnassignSystemIFC2X3(test.bootstrap.IFC2X3, TestUnassignSystem): + pass diff --git a/src/ifcopenshell-python/test/api/test_api.py b/src/ifcopenshell-python/test/api/test_api.py index 458691cc56..acd375b203 100644 --- a/src/ifcopenshell-python/test/api/test_api.py +++ b/src/ifcopenshell-python/test/api/test_api.py @@ -19,6 +19,7 @@ import test.bootstrap import ifcopenshell.api import ifcopenshell.util.element +import ifcopenshell.util.system from datetime import datetime @@ -151,3 +152,15 @@ class TestTemporarySupportForDeprecatedAPIArguments(test.bootstrap.IFC4): rel = rels[0] assert rel.RelatingGroup == system assert rel.RelatedObjects == (element,) + + @deprecation_check + def test_unassign_system(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment") + element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment") + system = ifcopenshell.api.run("system.add_system", self.file) + ifcopenshell.api.run("system.assign_system", self.file, products=[element, element2], system=system) + ifcopenshell.api.run("system.unassign_system", self.file, product=element, system=system) + assert ifcopenshell.util.system.get_system_elements(system) == [element2] + + ifcopenshell.api.run("system.unassign_system", self.file, product=element2, system=system) + assert ifcopenshell.util.system.get_system_elements(system) == []