Skip to content

Commit e66ac3d

Browse files
committed
system.unassign_system - support batching IfcOpenShell#4474
1 parent 6b48e8b commit e66ac3d

File tree

6 files changed

+72
-21
lines changed

6 files changed

+72
-21
lines changed

src/blenderbim/blenderbim/core/system.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def assign_system(ifc, system=None, product=None):
5959

6060

6161
def unassign_system(ifc, system=None, product=None):
62-
ifc.run("system.unassign_system", product=product, system=system)
62+
ifc.run("system.unassign_system", products=[product], system=system)
6363

6464

6565
def select_system_products(system_tool, system=None):

src/blenderbim/test/core/test_system.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_run(self, ifc):
8080

8181
class TestUnassignSystem:
8282
def test_run(self, ifc):
83-
ifc.run("system.unassign_system", product="product", system="system").should_be_called()
83+
ifc.run("system.unassign_system", products=["product"], system="system").should_be_called()
8484
subject.unassign_system(ifc, system="system", product="product")
8585

8686

src/ifcopenshell-python/ifcopenshell/api/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def batching_argument_deprecation(
8282
"system.assign_system": partial(
8383
batching_argument_deprecation, prev_argument="product", new_argument="products"
8484
),
85+
"system.unassign_system": partial(
86+
batching_argument_deprecation, prev_argument="product", new_argument="products"
87+
),
8588
}
8689

8790

src/ifcopenshell-python/ifcopenshell/api/system/unassign_system.py

+14-19
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@
2222

2323

2424
class Usecase:
25-
def __init__(self, file, product=None, system=None):
26-
"""Unassigns a product from a system
25+
def __init__(
26+
self,
27+
file: ifcopenshell.entity_instance,
28+
products: list[ifcopenshell.entity_instance],
29+
system: ifcopenshell.entity_instance,
30+
):
31+
"""Unassigns list of products from a system
2732
28-
:param product: The IfcDistributionElement to unassign from the system.
29-
:type product: ifcopenshell.entity_instance.entity_instance
33+
:param products: The list of IfcDistributionElements to unassign from the system.
34+
:type products: list[ifcopenshell.entity_instance.entity_instance]
3035
:param system: The IfcSystem you want to unassign the element from.
3136
:type system: ifcopenshell.entity_instance.entity_instance
3237
:return: None
@@ -47,25 +52,15 @@ def __init__(self, file, product=None, system=None):
4752
ifcopenshell.api.run("system.assign_system", model, products=[duct], system=system)
4853
4954
# Not anymore!
50-
ifcopenshell.api.run("system.unassign_system", model, product=duct, system=system)
55+
ifcopenshell.api.run("system.unassign_system", model, products=[duct], system=system)
5156
"""
5257
self.file = file
5358
self.settings = {
54-
"product": product,
59+
"products": products,
5560
"system": system,
5661
}
5762

5863
def execute(self):
59-
if not self.settings["system"].IsGroupedBy:
60-
return
61-
rel = self.settings["system"].IsGroupedBy[0]
62-
related_objects = set(rel.RelatedObjects) or set()
63-
related_objects.remove(self.settings["product"])
64-
if len(related_objects):
65-
rel.RelatedObjects = list(related_objects)
66-
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
67-
else:
68-
history = rel.OwnerHistory
69-
self.file.remove(rel)
70-
if history:
71-
ifcopenshell.util.element.remove_deep2(self.file, history)
64+
ifcopenshell.api.run(
65+
"group.unassign_group", self.file, products=self.settings["products"], group=self.settings["system"]
66+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# IfcOpenShell - IFC toolkit and geometry engine
2+
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
3+
#
4+
# This file is part of IfcOpenShell.
5+
#
6+
# IfcOpenShell is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# IfcOpenShell is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
18+
19+
import pytest
20+
import test.bootstrap
21+
import ifcopenshell.api
22+
import ifcopenshell.util.system
23+
24+
25+
class TestUnassignSystem(test.bootstrap.IFC4):
26+
def test_unassign_system(self):
27+
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
28+
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
29+
element3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
30+
system = ifcopenshell.api.run("system.add_system", self.file)
31+
ifcopenshell.api.run("system.assign_system", self.file, products=[element, element2, element3], system=system)
32+
ifcopenshell.api.run("system.unassign_system", self.file, products=[element2, element3], system=system)
33+
assert ifcopenshell.util.system.get_system_elements(system) == [element]
34+
35+
ifcopenshell.api.run("system.unassign_system", self.file, products=[element], system=system)
36+
assert ifcopenshell.util.system.get_system_elements(system) == []
37+
38+
39+
class TestUnassignSystemIFC2X3(test.bootstrap.IFC2X3, TestUnassignSystem):
40+
pass

src/ifcopenshell-python/test/api/test_api.py

+13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import test.bootstrap
2020
import ifcopenshell.api
2121
import ifcopenshell.util.element
22+
import ifcopenshell.util.system
2223
from datetime import datetime
2324

2425

@@ -151,3 +152,15 @@ def test_assign_system(self):
151152
rel = rels[0]
152153
assert rel.RelatingGroup == system
153154
assert rel.RelatedObjects == (element,)
155+
156+
@deprecation_check
157+
def test_unassign_system(self):
158+
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
159+
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
160+
system = ifcopenshell.api.run("system.add_system", self.file)
161+
ifcopenshell.api.run("system.assign_system", self.file, products=[element, element2], system=system)
162+
ifcopenshell.api.run("system.unassign_system", self.file, product=element, system=system)
163+
assert ifcopenshell.util.system.get_system_elements(system) == [element2]
164+
165+
ifcopenshell.api.run("system.unassign_system", self.file, product=element2, system=system)
166+
assert ifcopenshell.util.system.get_system_elements(system) == []

0 commit comments

Comments
 (0)